Skip to content

Commit

Permalink
53 219 issues (#224)
Browse files Browse the repository at this point in the history
* functions that only return literal, don't parse top-bottom

* empty funcOp to FuncOps

* version

* fix
  • Loading branch information
DieMyst authored Aug 4, 2021
1 parent e3716f6 commit ee67d03
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 32 deletions.
12 changes: 8 additions & 4 deletions aqua-src/test.aqua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions model/src/main/scala/aqua/model/Model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions model/src/main/scala/aqua/model/ReturnModel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package aqua.model

object ReturnModel extends Model {}
4 changes: 4 additions & 0 deletions model/src/main/scala/aqua/model/func/raw/FuncOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ object FuncOps {

def next(item: String): FuncOp =
FuncOp.leaf(NextTag(item))

lazy val empty: FuncOp =
FuncOp.leaf(EmptyTag)

}
2 changes: 2 additions & 0 deletions model/src/main/scala/aqua/model/func/raw/RawTag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ case class AssignmentTag(
assignTo: String
) extends NoExecTag

object EmptyTag extends NoExecTag

case class AbilityIdTag(
value: ValueModel,
service: String
Expand Down
2 changes: 1 addition & 1 deletion parser/src/main/scala/aqua/parser/lexer/TypeToken.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

}
Expand Down
56 changes: 32 additions & 24 deletions semantics/src/main/scala/aqua/semantics/expr/FuncSem.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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],
Expand All @@ -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))
})
)
Expand Down
4 changes: 2 additions & 2 deletions semantics/src/main/scala/aqua/semantics/expr/ReturnSem.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}

0 comments on commit ee67d03

Please sign in to comment.