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"): service GetStr("multiret-test"):
createStr: u32 -> string retStr: string -> string
service OpO("op"): service GetNum("multiret-num"):
identity: string -> string retNum: -> u8
-- a question mark means that this constant could be rewritten before this definition const someNum = 5
const anotherConst ?= "default-str" const someStr = "some-str"
const uniqueConst ?= 5
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: *string
res <- Getter.createStr(uniqueConst) res <- GetStr.retStr(someStr)
res <- OpO.identity(anotherConst) res <- GetStr.retStr("random-str")
<- res, 5 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) 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 case t => t
}).toLabelledList(returnVar) }).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( FuncCallable(
wrapCallableName, wrapCallableName,
transform( transform(
@ -51,13 +58,10 @@ case class ResolveFunc(
FuncOps FuncOps
.callArrow( .callArrow(
func.funcName, func.funcName,
Call( funcCall
func.arrowType.domain.toLabelledList().map(ad => VarModel(ad._1, ad._2)), ) :: (returnType.headOption
returnType.map { case (l, t) => Call.Export(l, t) } .map(_ => returnCallback(retModel))
) .toList): _*
) :: returnType.headOption
.map(_ => returnCallback(returnType.map { case (l, t) => VarModel(l, t) }))
.toList: _*
) )
), ),
ArrowType(ConsType.cons(func.funcName, func.arrowType, NilType), NilType), 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(vs.prependedAll)
) )
}) })
.map(_.reverse)
.flatMap(retModel => .flatMap(retModel =>
// Erase arguments and internal variables // Erase arguments and internal variables
A.endScope() >> N.endScope() >> (bodyGen match { 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 { 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 { case class UnlabelledConsType(`type`: Type, tail: ProductType) extends ConsType {