Separate Transform from Model (#244)

* Separate Result from Model

* Result->Transform, docs in README.md
This commit is contained in:
Dmitry Kurinskiy 2021-08-16 17:58:15 +03:00 committed by GitHub
parent 6c498b029b
commit 96bc76ef2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 107 additions and 106 deletions

View File

@ -32,6 +32,8 @@ Input directory should contain files with `aqua` scripts.
- **[types](./types)** data types, arrows, stream types definitions and variance - **[types](./types)** data types, arrows, stream types definitions and variance
- **[parser](./parser)** - parser, takes source text and produces a source AST - **[parser](./parser)** - parser, takes source text and produces a source AST
- **[model](./model)** - middle-end, internal representation of the code, optimizations and transfromations - **[model](./model)** - middle-end, internal representation of the code, optimizations and transfromations
- **[model/transform](./model/transform)** - optimizations and transfromations, converting model to the result, ready to be rendered
- **[model/test-kit](./model/test-kit)** - tests and test helpers for the model and transformations
- **[semantics](./semantics)** - rules to convert source AST into the model - **[semantics](./semantics)** - rules to convert source AST into the model
- **[linker](./linker)** - checks dependencies between modules, builds and combines an abstract dependencies tree - **[linker](./linker)** - checks dependencies between modules, builds and combines an abstract dependencies tree
- **[backend](./backend)** - compilation backend interface - **[backend](./backend)** - compilation backend interface

View File

@ -1,7 +1,7 @@
package aqua.backend.air package aqua.backend.air
import aqua.backend.{Backend, Generated} import aqua.backend.{Backend, Generated}
import aqua.model.res.AquaRes import aqua.model.transform.res.AquaRes
import cats.syntax.show.* import cats.syntax.show.*
object AirBackend extends Backend { object AirBackend extends Backend {

View File

@ -1,8 +1,8 @@
package aqua.backend.air package aqua.backend.air
import aqua.model._ import aqua.model.*
import aqua.model.func.Call import aqua.model.func.Call
import aqua.model.func.resolved._ import aqua.model.transform.res.*
import aqua.types.StreamType import aqua.types.StreamType
import cats.Eval import cats.Eval
import cats.data.Chain import cats.data.Chain

View File

@ -1,6 +1,6 @@
package aqua.backend.air package aqua.backend.air
import aqua.model.res.FuncRes import aqua.model.transform.res.FuncRes
case class FuncAirGen(func: FuncRes) { case class FuncAirGen(func: FuncRes) {

View File

@ -1,7 +1,7 @@
package aqua.backend.js package aqua.backend.js
import aqua.backend.{Backend, Generated} import aqua.backend.{Backend, Generated}
import aqua.model.res.AquaRes import aqua.model.transform.res.AquaRes
import cats.data.NonEmptyChain import cats.data.NonEmptyChain
object JavaScriptBackend extends Backend { object JavaScriptBackend extends Backend {

View File

@ -1,7 +1,7 @@
package aqua.backend.js package aqua.backend.js
import aqua.backend.air.FuncAirGen import aqua.backend.air.FuncAirGen
import aqua.model.res.FuncRes import aqua.model.transform.res.FuncRes
import aqua.types.* import aqua.types.*
import cats.syntax.show.* import cats.syntax.show.*

View File

@ -1,6 +1,6 @@
package aqua.backend package aqua.backend
import aqua.model.res.AquaRes import aqua.model.transform.res.AquaRes
/** /**
* Compiler backend generates output based on the processed model * Compiler backend generates output based on the processed model

View File

@ -1,7 +1,7 @@
package aqua.backend.ts package aqua.backend.ts
import aqua.backend.{Backend, Generated} import aqua.backend.{Backend, Generated}
import aqua.model.res.AquaRes import aqua.model.transform.res.AquaRes
import cats.data.NonEmptyChain import cats.data.NonEmptyChain
object TypeScriptBackend extends Backend { object TypeScriptBackend extends Backend {

View File

@ -1,7 +1,7 @@
package aqua.backend.ts package aqua.backend.ts
import aqua.backend.Version import aqua.backend.Version
import aqua.model.res.AquaRes import aqua.model.transform.res.AquaRes
case class TypeScriptFile(res: AquaRes) { case class TypeScriptFile(res: AquaRes) {

View File

@ -1,7 +1,7 @@
package aqua.backend.ts package aqua.backend.ts
import aqua.backend.air.FuncAirGen import aqua.backend.air.FuncAirGen
import aqua.model.res.FuncRes import aqua.model.transform.res.FuncRes
import aqua.types.* import aqua.types.*
import cats.syntax.show.* import cats.syntax.show.*

View File

@ -1,6 +1,6 @@
package aqua.backend.ts package aqua.backend.ts
import aqua.model.res.ServiceRes import aqua.model.transform.res.ServiceRes
case class TypeScriptService(srv: ServiceRes) { case class TypeScriptService(srv: ServiceRes) {

View File

@ -107,12 +107,19 @@ lazy val model = crossProject(JVMPlatform, JSPlatform)
) )
.dependsOn(types) .dependsOn(types)
lazy val transform = crossProject(JVMPlatform, JSPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("model/transform"))
.settings(commons: _*)
.dependsOn(model)
lazy val `test-kit` = crossProject(JVMPlatform, JSPlatform) lazy val `test-kit` = crossProject(JVMPlatform, JSPlatform)
.withoutSuffixFor(JVMPlatform) .withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure) .crossType(CrossType.Pure)
.in(file("model/test-kit")) .in(file("model/test-kit"))
.settings(commons: _*) .settings(commons: _*)
.dependsOn(model) .dependsOn(transform)
lazy val semantics = crossProject(JVMPlatform, JSPlatform) lazy val semantics = crossProject(JVMPlatform, JSPlatform)
.withoutSuffixFor(JVMPlatform) .withoutSuffixFor(JVMPlatform)
@ -138,7 +145,7 @@ lazy val backend = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure) .crossType(CrossType.Pure)
.in(file("backend")) .in(file("backend"))
.settings(commons: _*) .settings(commons: _*)
.dependsOn(model) .dependsOn(transform)
lazy val `backend-air` = crossProject(JVMPlatform, JSPlatform) lazy val `backend-air` = crossProject(JVMPlatform, JSPlatform)
.withoutSuffixFor(JVMPlatform) .withoutSuffixFor(JVMPlatform)

View File

@ -3,7 +3,7 @@ package aqua
import aqua.backend.Backend import aqua.backend.Backend
import aqua.backend.ts.TypeScriptBackend import aqua.backend.ts.TypeScriptBackend
import aqua.compiler.{AquaCompiler, AquaError, AquaSources} import aqua.compiler.{AquaCompiler, AquaError, AquaSources}
import aqua.model.transform.GenerationConfig import aqua.model.transform.TransformConfig
import cats.effect.IO import cats.effect.IO
import cats.effect.unsafe.implicits.global import cats.effect.unsafe.implicits.global
import cats.data.* import cats.data.*

View File

@ -1,12 +1,12 @@
package aqua package aqua
import aqua.model.LiteralModel import aqua.model.LiteralModel
import aqua.model.transform.GenerationConfig import aqua.model.transform.TransformConfig
import aqua.parser.expr.ConstantExpr import aqua.parser.expr.ConstantExpr
import aqua.parser.lift.LiftParser import aqua.parser.lift.LiftParser
import cats.data.Validated.{Invalid, Valid} import cats.data.Validated.{Invalid, Valid}
import cats.data.{NonEmptyList, Validated, ValidatedNel} import cats.data.{NonEmptyList, Validated, ValidatedNel}
import cats.effect.{unsafe, ExitCode, IO} import cats.effect.{ExitCode, IO, unsafe}
import cats.effect.std.Console import cats.effect.std.Console
import cats.syntax.functor.* import cats.syntax.functor.*
import cats.syntax.traverse.* import cats.syntax.traverse.*
@ -120,7 +120,7 @@ object AppOps {
} }
.withDefault(List.empty) .withDefault(List.empty)
def constantOpts[F[_]: LiftParser: Comonad]: Opts[List[GenerationConfig.Const]] = def constantOpts[F[_]: LiftParser: Comonad]: Opts[List[TransformConfig.Const]] =
Opts Opts
.options[String]("const", "Constant that will be used in an aqua code", "c") .options[String]("const", "Constant that will be used in an aqua code", "c")
.mapValidated { strs => .mapValidated { strs =>
@ -133,9 +133,9 @@ object AppOps {
NonEmptyList NonEmptyList
.fromList(errors) .fromList(errors)
.fold( .fold(
Validated.validNel[String, List[GenerationConfig.Const]](parsed.collect { Validated.validNel[String, List[TransformConfig.Const]](parsed.collect {
case Right(v) => case Right(v) =>
GenerationConfig.Const(v._1.value, LiteralModel(v._2.value, v._2.ts)) TransformConfig.Const(v._1.value, LiteralModel(v._2.value, v._2.ts))
}) })
) { errors => ) { errors =>
Validated.invalid(errors.map(_.toString)) Validated.invalid(errors.map(_.toString))

View File

@ -5,7 +5,7 @@ import aqua.backend.air.AirBackend
import aqua.backend.js.JavaScriptBackend import aqua.backend.js.JavaScriptBackend
import aqua.backend.ts.TypeScriptBackend import aqua.backend.ts.TypeScriptBackend
import aqua.files.AquaFilesIO import aqua.files.AquaFilesIO
import aqua.model.transform.GenerationConfig import aqua.model.transform.TransformConfig
import aqua.parser.lift.LiftParser.Implicits.idLiftParser import aqua.parser.lift.LiftParser.Implicits.idLiftParser
import cats.Id import cats.Id
import cats.data.Validated import cats.data.Validated
@ -74,7 +74,7 @@ object AquaCli extends IOApp with Logging {
else if (toJs) JavaScriptTarget else if (toJs) JavaScriptTarget
else TypescriptTarget else TypescriptTarget
val bc = { val bc = {
val bc = GenerationConfig(wrapWithXor = !noXor, constants = constants) val bc = TransformConfig(wrapWithXor = !noXor, constants = constants)
bc.copy(relayVarName = bc.relayVarName.filterNot(_ => noRelay)) bc.copy(relayVarName = bc.relayVarName.filterNot(_ => noRelay))
} }
logger.info(s"Aqua Compiler ${versionStr}") logger.info(s"Aqua Compiler ${versionStr}")

View File

@ -4,7 +4,7 @@ import aqua.backend.Backend
import aqua.compiler.{AquaCompiler, AquaError} import aqua.compiler.{AquaCompiler, AquaError}
import aqua.files.{AquaFileSources, FileModuleId} import aqua.files.{AquaFileSources, FileModuleId}
import aqua.io.* import aqua.io.*
import aqua.model.transform.GenerationConfig import aqua.model.transform.TransformConfig
import aqua.parser.lift.FileSpan import aqua.parser.lift.FileSpan
import cats.data.* import cats.data.*
import cats.syntax.functor.* import cats.syntax.functor.*
@ -20,7 +20,7 @@ object AquaPathCompiler extends Logging {
imports: List[Path], imports: List[Path],
targetPath: Path, targetPath: Path,
backend: Backend, backend: Backend,
bodyConfig: GenerationConfig bodyConfig: TransformConfig
): F[ValidatedNec[String, Chain[String]]] = { ): F[ValidatedNec[String, Chain[String]]] = {
import ErrorRendering.showError import ErrorRendering.showError
val sources = new AquaFileSources[F](srcPath, imports) val sources = new AquaFileSources[F](srcPath, imports)

View File

@ -2,10 +2,9 @@ package aqua
import aqua.backend.ts.TypeScriptBackend import aqua.backend.ts.TypeScriptBackend
import aqua.files.AquaFilesIO import aqua.files.AquaFilesIO
import aqua.model.transform.GenerationConfig import aqua.model.transform.TransformConfig
import cats.data.Validated import cats.data.Validated
import cats.effect.{IO, IOApp, Sync} import cats.effect.{IO, IOApp, Sync}
import fs2.io.file.Path import fs2.io.file.Path
object Test extends IOApp.Simple { object Test extends IOApp.Simple {
@ -19,7 +18,7 @@ object Test extends IOApp.Simple {
List(Path("./aqua")), List(Path("./aqua")),
Path("./target"), Path("./target"),
TypeScriptBackend, TypeScriptBackend,
GenerationConfig() TransformConfig()
) )
.map { .map {
case Validated.Invalid(errs) => case Validated.Invalid(errs) =>

View File

@ -2,12 +2,11 @@ import aqua.AquaPathCompiler
import aqua.backend.air.AirBackend import aqua.backend.air.AirBackend
import aqua.backend.js.JavaScriptBackend import aqua.backend.js.JavaScriptBackend
import aqua.backend.ts.TypeScriptBackend import aqua.backend.ts.TypeScriptBackend
import aqua.model.transform.GenerationConfig import aqua.model.transform.TransformConfig
import cats.effect.IO import cats.effect.IO
import cats.effect.unsafe.implicits.global import cats.effect.unsafe.implicits.global
import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import fs2.io.file.{Files, Path} import fs2.io.file.{Files, Path}
class WriteFileSpec extends AnyFlatSpec with Matchers { class WriteFileSpec extends AnyFlatSpec with Matchers {
@ -19,7 +18,7 @@ class WriteFileSpec extends AnyFlatSpec with Matchers {
import aqua.files.AquaFilesIO.summon import aqua.files.AquaFilesIO.summon
val bc = GenerationConfig() val bc = TransformConfig()
AquaPathCompiler AquaPathCompiler
.compileFilesTo[IO](src, List.empty, targetTs, TypeScriptBackend, bc) .compileFilesTo[IO](src, List.empty, targetTs, TypeScriptBackend, bc)
.unsafeRunSync() .unsafeRunSync()

View File

@ -3,11 +3,11 @@ package aqua.compiler
import aqua.backend.Backend import aqua.backend.Backend
import aqua.linker.Linker import aqua.linker.Linker
import aqua.model.AquaContext import aqua.model.AquaContext
import aqua.model.res.AquaRes import aqua.model.transform.TransformConfig
import aqua.model.transform.GenerationConfig import aqua.model.transform.res.AquaRes
import aqua.parser.lift.LiftParser import aqua.parser.lift.LiftParser
import aqua.semantics.Semantics import aqua.semantics.Semantics
import cats.data.Validated.{validNec, Invalid, Valid} import cats.data.Validated.{Invalid, Valid, validNec}
import cats.data.{Chain, NonEmptyChain, Validated, ValidatedNec} import cats.data.{Chain, NonEmptyChain, Validated, ValidatedNec}
import cats.syntax.applicative.* import cats.syntax.applicative.*
import cats.syntax.flatMap.* import cats.syntax.flatMap.*
@ -21,7 +21,7 @@ object AquaCompiler {
sources: AquaSources[F, E, I], sources: AquaSources[F, E, I],
liftI: (I, String) => LiftParser[S], liftI: (I, String) => LiftParser[S],
backend: Backend, backend: Backend,
config: GenerationConfig config: TransformConfig
): F[ValidatedNec[AquaError[I, E, S], Chain[AquaCompiled[I]]]] = { ): F[ValidatedNec[AquaError[I, E, S], Chain[AquaCompiled[I]]]] = {
import config.aquaContextMonoid import config.aquaContextMonoid
type Err = AquaError[I, E, S] type Err = AquaError[I, E, S]
@ -59,11 +59,11 @@ object AquaCompiler {
} }
def compileTo[F[_]: Monad, E, I, S[_]: Comonad, T]( def compileTo[F[_]: Monad, E, I, S[_]: Comonad, T](
sources: AquaSources[F, E, I], sources: AquaSources[F, E, I],
liftI: (I, String) => LiftParser[S], liftI: (I, String) => LiftParser[S],
backend: Backend, backend: Backend,
config: GenerationConfig, config: TransformConfig,
write: AquaCompiled[I] => F[Seq[Validated[E, T]]] write: AquaCompiled[I] => F[Seq[Validated[E, T]]]
): F[ValidatedNec[AquaError[I, E, S], Chain[T]]] = ): F[ValidatedNec[AquaError[I, E, S], Chain[T]]] =
compile[F, E, I, S](sources, liftI, backend, config).flatMap { compile[F, E, I, S](sources, liftI, backend, config).flatMap {
case Valid(compiled) => case Valid(compiled) =>

View File

@ -2,8 +2,9 @@ package aqua
import aqua.model.func.Call import aqua.model.func.Call
import aqua.model.func.raw.* import aqua.model.func.raw.*
import aqua.model.func.resolved.{CallRes, CallServiceRes, MakeRes, MatchMismatchRes, ResolvedOp} import aqua.model.transform.TransformConfig
import aqua.model.transform.{ErrorsCatcher, GenerationConfig} import aqua.model.transform.res.{CallRes, CallServiceRes, MakeRes, MatchMismatchRes, ResolvedOp}
import aqua.model.transform.funcop.ErrorsCatcher
import aqua.model.{LiteralModel, ValueModel, VarModel} import aqua.model.{LiteralModel, ValueModel, VarModel}
import aqua.types.{ArrayType, LiteralType, ScalarType} import aqua.types.{ArrayType, LiteralType, ScalarType}
import cats.Eval import cats.Eval
@ -88,7 +89,7 @@ object Node {
) )
) )
def errorCall(bc: GenerationConfig, i: Int, on: ValueModel = initPeer): Res = Node[ResolvedOp]( def errorCall(bc: TransformConfig, i: Int, on: ValueModel = initPeer): Res = Node[ResolvedOp](
CallServiceRes( CallServiceRes(
bc.errorHandlingCallback, bc.errorHandlingCallback,
bc.errorFuncName, bc.errorFuncName,
@ -103,7 +104,7 @@ object Node {
) )
) )
def respCall(bc: GenerationConfig, value: ValueModel, on: ValueModel = initPeer): Res = def respCall(bc: TransformConfig, value: ValueModel, on: ValueModel = initPeer): Res =
Node[ResolvedOp]( Node[ResolvedOp](
CallServiceRes( CallServiceRes(
bc.callbackSrvId, bc.callbackSrvId,
@ -113,7 +114,7 @@ object Node {
) )
) )
def dataCall(bc: GenerationConfig, name: String, on: ValueModel = initPeer): Res = def dataCall(bc: TransformConfig, name: String, on: ValueModel = initPeer): Res =
Node[ResolvedOp]( Node[ResolvedOp](
CallServiceRes( CallServiceRes(
bc.dataSrvId, bc.dataSrvId,

View File

@ -2,15 +2,16 @@ package aqua.model.transform
import aqua.Node import aqua.Node
import aqua.model.func.raw.{CallArrowTag, CallServiceTag, FuncOp, FuncOps} import aqua.model.func.raw.{CallArrowTag, CallServiceTag, FuncOp, FuncOps}
import aqua.model.func.resolved.{CallRes, CallServiceRes, MakeRes}
import aqua.model.func.{Call, FuncCallable} import aqua.model.func.{Call, FuncCallable}
import aqua.model.transform.res.{CallRes, CallServiceRes, MakeRes}
import aqua.model.transform.{Transform, TransformConfig}
import aqua.model.{LiteralModel, VarModel} import aqua.model.{LiteralModel, VarModel}
import aqua.types.{ArrowType, NilType, ProductType, ScalarType} import aqua.types.{ArrowType, NilType, ProductType, ScalarType}
import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
class TransformSpec extends AnyFlatSpec with Matchers { class TransformSpec extends AnyFlatSpec with Matchers {
import Node._ import Node.*
val stringArrow: ArrowType = ArrowType(NilType, ProductType(ScalarType.string :: Nil)) val stringArrow: ArrowType = ArrowType(NilType, ProductType(ScalarType.string :: Nil))
@ -28,7 +29,7 @@ class TransformSpec extends AnyFlatSpec with Matchers {
Map.empty Map.empty
) )
val bc = GenerationConfig() val bc = TransformConfig()
val fc = Transform.fn(func, bc) val fc = Transform.fn(func, bc)
@ -78,7 +79,7 @@ class TransformSpec extends AnyFlatSpec with Matchers {
Map.empty Map.empty
) )
val bc = GenerationConfig(wrapWithXor = false) val bc = TransformConfig(wrapWithXor = false)
val fc = Transform.fn(func, bc) val fc = Transform.fn(func, bc)
@ -139,7 +140,7 @@ class TransformSpec extends AnyFlatSpec with Matchers {
Map.empty Map.empty
) )
val bc = GenerationConfig(wrapWithXor = false) val bc = TransformConfig(wrapWithXor = false)
val res = Transform.fn(f2, bc).body: Node.Res val res = Transform.fn(f2, bc).body: Node.Res

View File

@ -1,10 +1,10 @@
package aqua.model.topology package aqua.model.transform.topology
import aqua.Node import aqua.Node
import aqua.model.VarModel import aqua.model.VarModel
import aqua.model.func.Call import aqua.model.func.Call
import aqua.model.func.raw.FuncOps import aqua.model.func.raw.FuncOps
import aqua.model.func.resolved.{MakeRes, ResolvedOp, XorRes} import aqua.model.transform.res.{MakeRes, ResolvedOp, XorRes}
import aqua.types.ScalarType import aqua.types.ScalarType
import cats.Eval import cats.Eval
import cats.data.Chain import cats.data.Chain

View File

@ -1,10 +1,10 @@
package aqua.model.transform package aqua.model.transform
import aqua.model.func.FuncCallable
import aqua.model.VarModel import aqua.model.VarModel
import aqua.model.func.resolved.{NoAir, ResolvedOp} import aqua.model.func.FuncCallable
import aqua.model.res.FuncRes import aqua.model.transform.res.{FuncRes, NoAir, ResolvedOp}
import aqua.model.topology.Topology import aqua.model.transform.topology.Topology
import aqua.model.transform.funcop.*
import aqua.types.ScalarType import aqua.types.ScalarType
import cats.data.Chain import cats.data.Chain
import cats.free.Cofree import cats.free.Cofree
@ -23,7 +23,7 @@ object Transform extends Logging {
): Cofree[Chain, ResolvedOp] = ): Cofree[Chain, ResolvedOp] =
tree.copy(tail = tree.tail.map(_.filter(t => filter(t.head)).map(clear(_, filter)))) tree.copy(tail = tree.tail.map(_.filter(t => filter(t.head)).map(clear(_, filter))))
def fn(func: FuncCallable, conf: GenerationConfig): FuncRes = { def fn(func: FuncCallable, conf: TransformConfig): FuncRes = {
val initCallable: InitPeerCallable = InitViaRelayCallable( val initCallable: InitPeerCallable = InitViaRelayCallable(
Chain.fromOption(conf.relayVarName).map(VarModel(_, ScalarType.string)) Chain.fromOption(conf.relayVarName).map(VarModel(_, ScalarType.string))
) )

View File

@ -4,7 +4,7 @@ import aqua.model.{AquaContext, LiteralModel, ValueModel, VarModel}
import aqua.types.ScalarType import aqua.types.ScalarType
import cats.kernel.Monoid import cats.kernel.Monoid
case class GenerationConfig( case class TransformConfig(
getDataService: String = "getDataSrv", getDataService: String = "getDataSrv",
callbackService: String = "callbackSrv", callbackService: String = "callbackSrv",
errorHandlingService: String = "errorHandlingSrv", errorHandlingService: String = "errorHandlingSrv",
@ -12,7 +12,7 @@ case class GenerationConfig(
respFuncName: String = "response", respFuncName: String = "response",
relayVarName: Option[String] = Some("-relay-"), relayVarName: Option[String] = Some("-relay-"),
wrapWithXor: Boolean = true, wrapWithXor: Boolean = true,
constants: List[GenerationConfig.Const] = Nil constants: List[TransformConfig.Const] = Nil
) { ) {
val errorId: ValueModel = LiteralModel.quote(errorFuncName) val errorId: ValueModel = LiteralModel.quote(errorFuncName)
@ -22,8 +22,8 @@ case class GenerationConfig(
// Host peer id holds %init_peer_id% in case Aqua is not compiled to be executed behind a relay, // Host peer id holds %init_peer_id% in case Aqua is not compiled to be executed behind a relay,
// or relay's variable otherwise // or relay's variable otherwise
val hostPeerId: GenerationConfig.Const = val hostPeerId: TransformConfig.Const =
GenerationConfig.Const( TransformConfig.Const(
"host_peer_id", "host_peer_id",
relayVarName.fold[ValueModel](LiteralModel.initPeerId)(r => VarModel(r, ScalarType.string)) relayVarName.fold[ValueModel](LiteralModel.initPeerId)(r => VarModel(r, ScalarType.string))
) )
@ -45,9 +45,9 @@ case class GenerationConfig(
} }
object GenerationConfig { object TransformConfig {
case class Const(name: String, value: ValueModel) case class Const(name: String, value: ValueModel)
def forHost: GenerationConfig = def forHost: TransformConfig =
GenerationConfig(wrapWithXor = false, relayVarName = None) TransformConfig(wrapWithXor = false, relayVarName = None)
} }

View File

@ -1,4 +1,4 @@
package aqua.model.cursor package aqua.model.transform.cursor
import cats.data.{Chain, NonEmptyList} import cats.data.{Chain, NonEmptyList}

View File

@ -1,4 +1,4 @@
package aqua.model.cursor package aqua.model.transform.cursor
import cats.data.Chain import cats.data.Chain
import cats.free.Cofree import cats.free.Cofree

View File

@ -1,4 +1,4 @@
package aqua.model.transform package aqua.model.transform.funcop
import aqua.model.{ValueModel, VarModel} import aqua.model.{ValueModel, VarModel}
import aqua.model.func.Call import aqua.model.func.Call

View File

@ -1,4 +1,4 @@
package aqua.model.transform package aqua.model.transform.funcop
import aqua.model.{LiteralModel, ValueModel, VarModel} import aqua.model.{LiteralModel, ValueModel, VarModel}
import aqua.model.func.Call import aqua.model.func.Call

View File

@ -1,4 +1,4 @@
package aqua.model.transform package aqua.model.transform.funcop
import aqua.model.{LiteralModel, ValueModel} import aqua.model.{LiteralModel, ValueModel}
import aqua.model.func.Call import aqua.model.func.Call

View File

@ -1,4 +1,4 @@
package aqua.model.transform package aqua.model.transform.funcop
import aqua.model.func.* import aqua.model.func.*
import aqua.model.func.raw.{FuncOp, FuncOps} import aqua.model.func.raw.{FuncOp, FuncOps}

View File

@ -1,7 +1,8 @@
package aqua.model.res package aqua.model.transform.res
import aqua.model.AquaContext import aqua.model.AquaContext
import aqua.model.transform.{GenerationConfig, Transform} import aqua.model.transform.{Transform, TransformConfig}
import aqua.model.transform.res._
import cats.data.Chain import cats.data.Chain
case class AquaRes(funcs: Chain[FuncRes], services: Chain[ServiceRes]) { case class AquaRes(funcs: Chain[FuncRes], services: Chain[ServiceRes]) {
@ -10,7 +11,7 @@ case class AquaRes(funcs: Chain[FuncRes], services: Chain[ServiceRes]) {
object AquaRes { object AquaRes {
def fromContext(ctx: AquaContext, conf: GenerationConfig): AquaRes = def fromContext(ctx: AquaContext, conf: TransformConfig): AquaRes =
AquaRes( AquaRes(
funcs = Chain.fromSeq(ctx.funcs.values.toSeq).map(Transform.fn(_, conf)), funcs = Chain.fromSeq(ctx.funcs.values.toSeq).map(Transform.fn(_, conf)),
services = Chain.fromSeq(ctx.services.values.toSeq).map(ServiceRes.fromModel(_)) services = Chain.fromSeq(ctx.services.values.toSeq).map(ServiceRes.fromModel(_))

View File

@ -1,4 +1,4 @@
package aqua.model.func.resolved package aqua.model.transform.res
import aqua.model.ValueModel import aqua.model.ValueModel
import aqua.model.func.Call import aqua.model.func.Call

View File

@ -1,18 +1,17 @@
package aqua.model.res package aqua.model.transform.res
import aqua.model.func.FuncCallable import aqua.model.func.FuncCallable
import aqua.model.func.resolved.ResolvedOp import aqua.model.transform.TransformConfig
import aqua.model.transform.GenerationConfig
import aqua.types.{ArrowType, Type} import aqua.types.{ArrowType, Type}
import cats.data.Chain import cats.data.Chain
import cats.free.Cofree import cats.free.Cofree
case class FuncRes( case class FuncRes(
source: FuncCallable, source: FuncCallable,
conf: GenerationConfig, conf: TransformConfig,
body: Cofree[Chain, ResolvedOp] body: Cofree[Chain, ResolvedOp]
) { ) {
import FuncRes._ import FuncRes.*
lazy val funcName = source.funcName lazy val funcName = source.funcName

View File

@ -1,18 +1,8 @@
package aqua.model.func.resolved package aqua.model.transform.res
import aqua.model.func.Call import aqua.model.func.Call
import aqua.model.func.raw.{ import aqua.model.func.raw.*
CallServiceTag, import aqua.model.transform.topology.Topology.Res
ForTag,
MatchMismatchTag,
NextTag,
OnTag,
ParTag,
RawTag,
SeqTag,
XorTag
}
import aqua.model.topology.Topology.Res
import aqua.model.{LiteralModel, ValueModel} import aqua.model.{LiteralModel, ValueModel}
import cats.Eval import cats.Eval
import cats.data.Chain import cats.data.Chain

View File

@ -1,4 +1,4 @@
package aqua.model.func.resolved package aqua.model.transform.res
import aqua.model.ValueModel import aqua.model.ValueModel
import aqua.model.func.Call import aqua.model.func.Call

View File

@ -1,8 +1,7 @@
package aqua.model.res package aqua.model.transform.res
import aqua.model.ServiceModel import aqua.model.{LiteralModel, ServiceModel}
import aqua.types.{ArrowType, ScalarType} import aqua.types.{ArrowType, ScalarType}
import aqua.model.LiteralModel
case class ServiceRes(name: String, members: List[(String, ArrowType)], defaultId: Option[String]) case class ServiceRes(name: String, members: List[(String, ArrowType)], defaultId: Option[String])

View File

@ -1,6 +1,7 @@
package aqua.model.func.raw package aqua.model.transform.topology
import aqua.model.ValueModel import aqua.model.ValueModel
import aqua.model.func.raw.{OnTag, ParGroupTag}
import cats.data.Chain import cats.data.Chain
import cats.data.Chain.{:==, ==:, nil} import cats.data.Chain.{:==, ==:, nil}
import scribe.Logging import scribe.Logging

View File

@ -1,11 +1,12 @@
package aqua.model.func.raw package aqua.model.transform.topology
import aqua.model.ValueModel import aqua.model.ValueModel
import aqua.model.cursor.{ChainCursor, ChainZipper} import aqua.model.func.raw.*
import cats.Eval import cats.Eval
import cats.data.{Chain, NonEmptyList, OptionT} import cats.data.{Chain, NonEmptyList, OptionT}
import cats.free.Cofree import aqua.model.transform.cursor._
import cats.syntax.traverse._ import cats.syntax.traverse._
import cats.free.Cofree
import scribe.Logging import scribe.Logging
// Can be heavily optimized by caching parent cursors, not just list of zippers // Can be heavily optimized by caching parent cursors, not just list of zippers

View File

@ -1,15 +1,15 @@
package aqua.model.topology package aqua.model.transform.topology
import aqua.model.cursor.ChainZipper import aqua.model.transform.cursor.ChainZipper
import aqua.model.func.raw._ import aqua.model.func.raw.*
import aqua.model.func.resolved._ import aqua.model.transform.res.*
import aqua.model.{LiteralModel, ValueModel, VarModel} import aqua.model.{LiteralModel, ValueModel, VarModel}
import aqua.types.{BoxType, ScalarType} import aqua.types.{BoxType, ScalarType}
import cats.Eval import cats.Eval
import cats.data.Chain.nil import cats.data.Chain.nil
import cats.data.{Chain, NonEmptyChain, NonEmptyList, OptionT} import cats.data.{Chain, NonEmptyChain, NonEmptyList, OptionT}
import cats.free.Cofree import cats.free.Cofree
import cats.syntax.traverse._ import cats.syntax.traverse.*
import scribe.Logging import scribe.Logging
object Topology extends Logging { object Topology extends Logging {

View File

@ -1,9 +1,10 @@
package aqua.semantics package aqua.semantics
import aqua.Node import aqua.Node
import aqua.Node._ import aqua.Node.*
import aqua.model.func.raw.{FuncOp, FuncOps, SeqTag} import aqua.model.func.raw.{FuncOp, FuncOps, SeqTag}
import aqua.model.transform._ import aqua.model.transform.TransformConfig
import aqua.model.transform.funcop.*
import aqua.model.{AquaContext, LiteralModel} import aqua.model.{AquaContext, LiteralModel}
import aqua.parser.Ast import aqua.parser.Ast
import aqua.parser.lift.{LiftParser, Span} import aqua.parser.lift.{LiftParser, Span}
@ -29,7 +30,7 @@ class SemanticsSpec extends AnyFlatSpec with Matchers {
val ast = Ast.fromString(script).toList.head val ast = Ast.fromString(script).toList.head
val ctx = AquaContext.blank val ctx = AquaContext.blank
val bc = GenerationConfig() val bc = TransformConfig()
import bc.aquaContextMonoid import bc.aquaContextMonoid
val p = Semantics.process(ast, ctx) val p = Semantics.process(ast, ctx)