Multireturn bugfix (#238)

This commit is contained in:
Dmitry Kurinskiy 2021-08-11 10:55:25 +03:00 committed by GitHub
parent 3eb3ecc221
commit f7aa118006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 20 deletions

View File

@ -1,15 +1,20 @@
service Getter("test"):
createStr: u32 -> string
service GetStr("multiret-test"):
retStr: string -> string
service OpO("op"):
identity: string -> string
service GetNum("multiret-num"):
retNum: -> u8
-- a question mark means that this constant could be rewritten before this definition
const anotherConst ?= "default-str"
const uniqueConst ?= 5
const someNum = 5
const someStr = "some-str"
func callConstant() -> []string, u8:
func tupleFunc() -> string, u8:
str <- GetStr.retStr(someStr)
n <- GetNum.retNum()
<- str, n
func multiReturnFunc(somethingToReturn: []u8, smthOption: ?string) -> []string, u8, string, []u8, ?string, u8:
res: *string
res <- Getter.createStr(uniqueConst)
res <- OpO.identity(anotherConst)
<- res, 5
res <- GetStr.retStr(someStr)
res <- GetStr.retStr("random-str")
res, tNum <- tupleFunc()
<- res, 5, someStr, somethingToReturn, smthOption, tNum

View File

@ -167,7 +167,7 @@ case class FuncCallable(
case ((ops, rets), (_, r)) => (ops, r :: rets)
}
FuncOps.seq(ops.reverse: _*) -> rets
FuncOps.seq(ops.reverse: _*) -> rets.reverse
}
}

View File

@ -44,6 +44,13 @@ case class ResolveFunc(
case t => t
}).toLabelledList(returnVar)
val retModel = returnType.map { case (l, t) => VarModel(l, t) }
val funcCall = Call(
func.arrowType.domain.toLabelledList().map(ad => VarModel(ad._1, ad._2)),
returnType.map { case (l, t) => Call.Export(l, t) }
)
FuncCallable(
wrapCallableName,
transform(
@ -51,13 +58,10 @@ case class ResolveFunc(
FuncOps
.callArrow(
func.funcName,
Call(
func.arrowType.domain.toLabelledList().map(ad => VarModel(ad._1, ad._2)),
returnType.map { case (l, t) => Call.Export(l, t) }
)
) :: returnType.headOption
.map(_ => returnCallback(returnType.map { case (l, t) => VarModel(l, t) }))
.toList: _*
funcCall
) :: (returnType.headOption
.map(_ => returnCallback(retModel))
.toList): _*
)
),
ArrowType(ConsType.cons(func.funcName, func.arrowType, NilType), NilType),

View File

@ -96,6 +96,7 @@ class FuncSem[F[_]](val expr: FuncExpr[F]) extends AnyVal {
.map(vs.prependedAll)
)
})
.map(_.reverse)
.flatMap(retModel =>
// Erase arguments and internal variables
A.endScope() >> N.endScope() >> (bodyGen match {

View File

@ -94,7 +94,7 @@ object ConsType {
}
case class LabelledConsType(label: String, `type`: Type, tail: ProductType) extends ConsType {
override def toString: String = s"($label: " + `type` + s" :: $tail"
override def toString: String = s"($label: " + `type` + s") :: $tail"
}
case class UnlabelledConsType(`type`: Type, tail: ProductType) extends ConsType {