53 219 issues (#224)

* functions that only return literal, don't parse top-bottom

* empty funcOp to FuncOps

* version

* fix
This commit is contained in:
Dima 2021-08-04 13:16:42 +03:00 committed by GitHub
parent e3716f6f31
commit ee67d038ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 32 deletions

View File

@ -1,7 +1,11 @@
service Op("op"):
noop: -> ()
bz: string -> string
func return_none() -> ?string:
result: *string
Op.noop()
<- result
func return_none() -> string:
<- "some result in string"
func use() -> string:
res <- return_none()
res2 <- Op.bz(res)
<- res

View File

@ -28,7 +28,7 @@ val cats = "org.typelevel" %% "cats-core" % catsV
name := "aqua-hll"
val commons = Seq(
baseAquaVersion := "0.1.11",
baseAquaVersion := "0.1.12",
version := baseAquaVersion.value + "-" + sys.env.getOrElse("BUILD_NUMBER", "SNAPSHOT"),
scalaVersion := dottyVersion,
libraryDependencies ++= Seq(

View File

@ -14,6 +14,8 @@ object Model {
override def combine(x: Model, y: Model): Model = (x, y) match {
case (l: FuncOp, r: FuncOp) =>
FuncOp.FuncOpSemigroup.combine(l, r)
case (l: FuncOp, ReturnModel) =>
l
case (l: ScriptModel, r: ScriptModel) =>
ScriptModel.SMMonoid.combine(l, r)

View File

@ -0,0 +1,3 @@
package aqua.model
object ReturnModel extends Model {}

View File

@ -78,4 +78,8 @@ object FuncOps {
def next(item: String): FuncOp =
FuncOp.leaf(NextTag(item))
lazy val empty: FuncOp =
FuncOp.leaf(EmptyTag)
}

View File

@ -69,6 +69,8 @@ case class AssignmentTag(
assignTo: String
) extends NoExecTag
object EmptyTag extends NoExecTag
case class AbilityIdTag(
value: ValueModel,
service: String

View File

@ -120,7 +120,7 @@ object DataTypeToken {
P.defer(`arraytypedef`[F]) :: P.defer(StreamTypeToken.`streamtypedef`) :: P.defer(
OptionTypeToken.`optiontypedef`
) :: BasicTypeToken
.`basictypedef`[F] :: CustomTypeToken.ct[F] :: `topbottomdef` :: Nil
.`basictypedef`[F] :: CustomTypeToken.ct[F] :: Nil
)
}

View File

@ -1,8 +1,8 @@
package aqua.semantics.expr
import aqua.model.func.raw.FuncOp
import aqua.model.{Model, ValueModel}
import aqua.model.func.raw.{FuncOp, FuncOps}
import aqua.model.func.{ArgDef, ArgsDef, FuncModel}
import aqua.model.{Model, ReturnModel, ValueModel}
import aqua.parser.expr.FuncExpr
import aqua.parser.lexer.Arg
import aqua.semantics.Prog
@ -52,6 +52,32 @@ class FuncSem[F[_]](val expr: FuncExpr[F]) extends AnyVal {
)
.map(argsAndRes => ArrowType(argsAndRes._1, argsAndRes._2))
def generateFuncModel[Alg[_]](funcArrow: ArrowType, retModel: Option[ValueModel], body: FuncOp)(
implicit N: NamesAlgebra[F, Alg]
): Free[Alg, Model] = {
val argNames = args.map(_.name.value)
val model = FuncModel(
name = name.value,
args = ArgsDef(
argNames
.zip(funcArrow.args)
.map {
case (n, dt: DataType) => ArgDef.Data(n, dt)
case (n, at: ArrowType) => ArgDef.Arrow(n, at)
}
),
ret = retModel zip funcArrow.res,
body = body
)
N.defineArrow(
name,
funcArrow,
isRoot = true
) as (model: Model)
}
def after[Alg[_]](funcArrow: ArrowType, bodyGen: Model)(implicit
T: TypesAlgebra[F, Alg],
N: NamesAlgebra[F, Alg],
@ -71,28 +97,10 @@ class FuncSem[F[_]](val expr: FuncExpr[F]) extends AnyVal {
// Erase arguments and internal variables
}).flatMap(retModel =>
A.endScope() >> N.endScope() >> (bodyGen match {
case bg: FuncOp if ret.isDefined == retValue.isDefined =>
val argNames = args.map(_.name.value)
val model = FuncModel(
name = name.value,
args = ArgsDef(
argNames
.zip(funcArrow.args)
.map {
case (n, dt: DataType) => ArgDef.Data(n, dt)
case (n, at: ArrowType) => ArgDef.Arrow(n, at)
}
),
ret = retModel zip funcArrow.res,
body = bg
)
N.defineArrow(
name,
funcArrow,
isRoot = true
) as model
case body: FuncOp if ret.isDefined == retValue.isDefined =>
generateFuncModel[Alg](funcArrow, retModel, body)
case ReturnModel =>
generateFuncModel[Alg](funcArrow, retModel, FuncOps.empty)
case m => Free.pure[Alg, Model](Model.error("Function body is not a funcOp, it's " + m))
})
)

View File

@ -1,6 +1,6 @@
package aqua.semantics.expr
import aqua.model.Model
import aqua.model.{Model, ReturnModel}
import aqua.parser.expr.ReturnExpr
import aqua.semantics.Prog
import aqua.semantics.rules.ValuesAlgebra
@ -9,5 +9,5 @@ import cats.syntax.functor._
class ReturnSem[F[_]](val expr: ReturnExpr[F]) extends AnyVal {
def program[Alg[_]](implicit V: ValuesAlgebra[F, Alg]): Prog[Alg, Model] =
V.resolveType(expr.value) as Model.empty("Return makes no model")
V.resolveType(expr.value) as (ReturnModel: Model)
}