Skip to content

Commit

Permalink
Fix: resolve function return name (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
alari authored Jun 4, 2021
1 parent 0e2ea88 commit 15f582e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
14 changes: 10 additions & 4 deletions aqua-src/demo.aqua
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
service Demo("demo"):
get4() -> u64
get5(arg: u32)
get6(a: string) -> bool
service OpH("op"):
puk(s: string) -> string

func a(b: string) -> string:
c <- OpH.puk(b)
<- c

func d(e: string) -> string:
f <- a(e)
<- f
File renamed without changes.
23 changes: 13 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ val slf4jV = "1.7.30"
val declineV = "2.0.0-RC1" // Scala3 issue: https://github.com/bkirwi/decline/issues/260
val declineEnumV = "1.3.0"

val airframeLog = "org.wvlet.airframe" %% "airframe-log" % airframeLogV

name := "aqua-hll"

val commons = Seq(
Expand All @@ -41,16 +43,16 @@ lazy val cli = project
assembly / mainClass := Some("aqua.AquaCli"),
assembly / assemblyJarName := "aqua-cli-" + version.value + ".jar",
libraryDependencies ++= Seq(
"com.monovore" %% "decline" % declineV,
"com.monovore" %% "decline-effect" % declineV,
"org.typelevel" %% "cats-effect" % catsEffectV,
"co.fs2" %% "fs2-core" % fs2V,
"co.fs2" %% "fs2-io" % fs2V,
"org.typelevel" %% "log4cats-slf4j" % log4catsV,
"org.wvlet.airframe" %% "airframe-log" % airframeLogV,
"com.beachape" %% "enumeratum" % enumeratumV,
"org.slf4j" % "slf4j-jdk14" % slf4jV,
"com.monovore" %% "decline-enumeratum" % declineEnumV
"com.monovore" %% "decline" % declineV,
"com.monovore" %% "decline-effect" % declineV,
"org.typelevel" %% "cats-effect" % catsEffectV,
"co.fs2" %% "fs2-core" % fs2V,
"co.fs2" %% "fs2-io" % fs2V,
"org.typelevel" %% "log4cats-slf4j" % log4catsV,
airframeLog,
"com.beachape" %% "enumeratum" % enumeratumV,
"org.slf4j" % "slf4j-jdk14" % slf4jV,
"com.monovore" %% "decline-enumeratum" % declineEnumV
)
)
.dependsOn(semantics, `backend-air`, `backend-ts`, linker)
Expand Down Expand Up @@ -86,6 +88,7 @@ lazy val model = project
.settings(commons: _*)
.settings(
libraryDependencies ++= Seq(
airframeLog,
"org.typelevel" %% "cats-free" % catsV
)
)
Expand Down
12 changes: 8 additions & 4 deletions model/src/main/scala/aqua/model/func/FuncCallable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package aqua.model.func

import aqua.model.func.body.{CallArrowTag, FuncOp, OpTag}
import aqua.model.{ValueModel, VarModel}
import aqua.types.{ArrowType, DataType, Type}
import aqua.types.{ArrowType, Type}
import cats.Eval
import cats.data.Chain
import cats.free.Cofree
import wvlet.log.Logger

case class FuncCallable(
funcName: String,
Expand All @@ -16,6 +17,9 @@ case class FuncCallable(
capturedValues: Map[String, ValueModel]
) {

private val logger = Logger.of[FuncCallable]
import logger._

def arrowType: ArrowType =
ArrowType(
args.types,
Expand All @@ -38,6 +42,8 @@ case class FuncCallable(
forbiddenNames: Set[String]
): Eval[(FuncOp, Option[ValueModel])] = {

debug("Call: " + call)

// Collect all arguments: what names are used inside the function, what values are received
val argsFull = args.call(call)
// DataType arguments
Expand Down Expand Up @@ -99,9 +105,7 @@ case class FuncCallable(
case (acc @ (_, resolvedExports), tag) =>
tag match {
case CallArrowTag(fn, _) if !allArrows.contains(fn) =>
println(
Console.RED + s"UNRESOLVED $fn in $funcName, skipping, will become (null) in AIR!" + Console.RESET
)
error(s"UNRESOLVED $fn in $funcName, skipping, will become (null) in AIR!")
case _ =>
}

Expand Down
23 changes: 17 additions & 6 deletions model/src/main/scala/aqua/model/transform/ResolveFunc.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package aqua.model.transform

import aqua.model.VarModel
import aqua.model.{ValueModel, VarModel}
import aqua.model.func.{ArgDef, ArgsCall, ArgsDef, Call, FuncCallable}
import aqua.model.func.body.{FuncOp, FuncOps}
import aqua.types.ArrowType
import cats.Eval
import cats.syntax.apply._
import cats.syntax.functor._
import wvlet.log.Logger

case class ResolveFunc(
transform: FuncOp => FuncOp,
Expand All @@ -15,15 +17,17 @@ case class ResolveFunc(
arrowCallbackPrefix: String = "init_peer_callable_"
) {

def returnCallback(func: FuncCallable): Option[FuncOp] = func.ret.map { case (retModel, _) =>
private val logger = Logger.of[ResolveFunc]
import logger._

def returnCallback(retModel: ValueModel): FuncOp =
callback(
respFuncName,
Call(
retModel :: Nil,
None
)
)
}

def arrowToCallback(name: String, arrowType: ArrowType): FuncCallable = {
val (args, call, ret) = ArgsCall.arrowToArgsCallRet(arrowType)
Expand All @@ -47,10 +51,14 @@ case class ResolveFunc(
func.funcName,
Call(
func.args.toCallArgs,
None
func.ret.map(rmv => Call.Export("-return-", rmv._1.lastType))
)
) ::
returnCallback(func).toList: _*
func.ret
.map(_._1)
.map(rmv => VarModel("-return-", rmv.lastType))
.map(returnCallback)
.toList: _*
)
),
ArgsDef(ArgDef.Arrow(func.funcName, func.arrowType) :: Nil),
Expand All @@ -61,7 +69,10 @@ case class ResolveFunc(
Map.empty
)

def resolve(func: FuncCallable, funcArgName: String = "_func"): Eval[FuncOp] =
def resolve(
func: FuncCallable,
funcArgName: String = "_func"
): Eval[FuncOp] =
wrap(func)
.resolve(
Call(VarModel(funcArgName, func.arrowType) :: Nil, None),
Expand Down

0 comments on commit 15f582e

Please sign in to comment.