diff --git a/README.md b/README.md index e508a61c..b9559642 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ Input directory should contain files with `aqua` scripts. - **[types](./types)** – data types, arrows, stream types definitions and variance - **[parser](./parser)** - parser, takes source text and produces a source AST - **[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 - **[linker](./linker)** - checks dependencies between modules, builds and combines an abstract dependencies tree - **[backend](./backend)** - compilation backend interface diff --git a/backend/air/src/main/scala/aqua/backend/air/AirBackend.scala b/backend/air/src/main/scala/aqua/backend/air/AirBackend.scala index 2eefe52a..8197e708 100644 --- a/backend/air/src/main/scala/aqua/backend/air/AirBackend.scala +++ b/backend/air/src/main/scala/aqua/backend/air/AirBackend.scala @@ -1,7 +1,7 @@ package aqua.backend.air import aqua.backend.{Backend, Generated} -import aqua.model.res.AquaRes +import aqua.model.transform.res.AquaRes import cats.syntax.show.* object AirBackend extends Backend { diff --git a/backend/air/src/main/scala/aqua/backend/air/AirGen.scala b/backend/air/src/main/scala/aqua/backend/air/AirGen.scala index e7d49dd1..8ce57a55 100644 --- a/backend/air/src/main/scala/aqua/backend/air/AirGen.scala +++ b/backend/air/src/main/scala/aqua/backend/air/AirGen.scala @@ -1,8 +1,8 @@ package aqua.backend.air -import aqua.model._ +import aqua.model.* import aqua.model.func.Call -import aqua.model.func.resolved._ +import aqua.model.transform.res.* import aqua.types.StreamType import cats.Eval import cats.data.Chain diff --git a/backend/air/src/main/scala/aqua/backend/air/FuncAirGen.scala b/backend/air/src/main/scala/aqua/backend/air/FuncAirGen.scala index cfd6a2d3..a2acf300 100644 --- a/backend/air/src/main/scala/aqua/backend/air/FuncAirGen.scala +++ b/backend/air/src/main/scala/aqua/backend/air/FuncAirGen.scala @@ -1,6 +1,6 @@ package aqua.backend.air -import aqua.model.res.FuncRes +import aqua.model.transform.res.FuncRes case class FuncAirGen(func: FuncRes) { diff --git a/backend/js/src/main/scala/aqua/backend/js/JavaScriptBackend.scala b/backend/js/src/main/scala/aqua/backend/js/JavaScriptBackend.scala index 661e3a9c..a3cfd456 100644 --- a/backend/js/src/main/scala/aqua/backend/js/JavaScriptBackend.scala +++ b/backend/js/src/main/scala/aqua/backend/js/JavaScriptBackend.scala @@ -1,7 +1,7 @@ package aqua.backend.js import aqua.backend.{Backend, Generated} -import aqua.model.res.AquaRes +import aqua.model.transform.res.AquaRes import cats.data.NonEmptyChain object JavaScriptBackend extends Backend { diff --git a/backend/js/src/main/scala/aqua/backend/js/JavaScriptFunc.scala b/backend/js/src/main/scala/aqua/backend/js/JavaScriptFunc.scala index 09204d36..d282cf72 100644 --- a/backend/js/src/main/scala/aqua/backend/js/JavaScriptFunc.scala +++ b/backend/js/src/main/scala/aqua/backend/js/JavaScriptFunc.scala @@ -1,7 +1,7 @@ package aqua.backend.js import aqua.backend.air.FuncAirGen -import aqua.model.res.FuncRes +import aqua.model.transform.res.FuncRes import aqua.types.* import cats.syntax.show.* diff --git a/backend/src/main/scala/aqua/backend/Backend.scala b/backend/src/main/scala/aqua/backend/Backend.scala index bf2003be..c97fcb53 100644 --- a/backend/src/main/scala/aqua/backend/Backend.scala +++ b/backend/src/main/scala/aqua/backend/Backend.scala @@ -1,6 +1,6 @@ package aqua.backend -import aqua.model.res.AquaRes +import aqua.model.transform.res.AquaRes /** * Compiler backend generates output based on the processed model diff --git a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptBackend.scala b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptBackend.scala index c4687f4e..cfbdf74f 100644 --- a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptBackend.scala +++ b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptBackend.scala @@ -1,7 +1,7 @@ package aqua.backend.ts import aqua.backend.{Backend, Generated} -import aqua.model.res.AquaRes +import aqua.model.transform.res.AquaRes import cats.data.NonEmptyChain object TypeScriptBackend extends Backend { diff --git a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFile.scala b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFile.scala index aee2531c..172289b3 100644 --- a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFile.scala +++ b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFile.scala @@ -1,7 +1,7 @@ package aqua.backend.ts import aqua.backend.Version -import aqua.model.res.AquaRes +import aqua.model.transform.res.AquaRes case class TypeScriptFile(res: AquaRes) { diff --git a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFunc.scala b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFunc.scala index 4e80ad35..7ddfce3b 100644 --- a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFunc.scala +++ b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptFunc.scala @@ -1,7 +1,7 @@ package aqua.backend.ts import aqua.backend.air.FuncAirGen -import aqua.model.res.FuncRes +import aqua.model.transform.res.FuncRes import aqua.types.* import cats.syntax.show.* diff --git a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptService.scala b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptService.scala index 541f696d..349cdc7e 100644 --- a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptService.scala +++ b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptService.scala @@ -1,6 +1,6 @@ package aqua.backend.ts -import aqua.model.res.ServiceRes +import aqua.model.transform.res.ServiceRes case class TypeScriptService(srv: ServiceRes) { diff --git a/build.sbt b/build.sbt index 7d76c3af..041735a3 100644 --- a/build.sbt +++ b/build.sbt @@ -107,12 +107,19 @@ lazy val model = crossProject(JVMPlatform, JSPlatform) ) .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) .withoutSuffixFor(JVMPlatform) .crossType(CrossType.Pure) .in(file("model/test-kit")) .settings(commons: _*) - .dependsOn(model) + .dependsOn(transform) lazy val semantics = crossProject(JVMPlatform, JSPlatform) .withoutSuffixFor(JVMPlatform) @@ -138,7 +145,7 @@ lazy val backend = crossProject(JVMPlatform, JSPlatform) .crossType(CrossType.Pure) .in(file("backend")) .settings(commons: _*) - .dependsOn(model) + .dependsOn(transform) lazy val `backend-air` = crossProject(JVMPlatform, JSPlatform) .withoutSuffixFor(JVMPlatform) diff --git a/cli/.js/src/main/scala/aqua/JsApp.scala b/cli/.js/src/main/scala/aqua/JsApp.scala index 76f9be26..5a9bf21b 100644 --- a/cli/.js/src/main/scala/aqua/JsApp.scala +++ b/cli/.js/src/main/scala/aqua/JsApp.scala @@ -3,7 +3,7 @@ package aqua import aqua.backend.Backend import aqua.backend.ts.TypeScriptBackend import aqua.compiler.{AquaCompiler, AquaError, AquaSources} -import aqua.model.transform.GenerationConfig +import aqua.model.transform.TransformConfig import cats.effect.IO import cats.effect.unsafe.implicits.global import cats.data.* diff --git a/cli/.jvm/src/main/scala/aqua/AppOps.scala b/cli/.jvm/src/main/scala/aqua/AppOps.scala index c4633607..8b5ddd6b 100644 --- a/cli/.jvm/src/main/scala/aqua/AppOps.scala +++ b/cli/.jvm/src/main/scala/aqua/AppOps.scala @@ -1,12 +1,12 @@ package aqua import aqua.model.LiteralModel -import aqua.model.transform.GenerationConfig +import aqua.model.transform.TransformConfig import aqua.parser.expr.ConstantExpr import aqua.parser.lift.LiftParser import cats.data.Validated.{Invalid, Valid} 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.syntax.functor.* import cats.syntax.traverse.* @@ -120,7 +120,7 @@ object AppOps { } .withDefault(List.empty) - def constantOpts[F[_]: LiftParser: Comonad]: Opts[List[GenerationConfig.Const]] = + def constantOpts[F[_]: LiftParser: Comonad]: Opts[List[TransformConfig.Const]] = Opts .options[String]("const", "Constant that will be used in an aqua code", "c") .mapValidated { strs => @@ -133,9 +133,9 @@ object AppOps { NonEmptyList .fromList(errors) .fold( - Validated.validNel[String, List[GenerationConfig.Const]](parsed.collect { + Validated.validNel[String, List[TransformConfig.Const]](parsed.collect { 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 => Validated.invalid(errors.map(_.toString)) diff --git a/cli/.jvm/src/main/scala/aqua/AquaCli.scala b/cli/.jvm/src/main/scala/aqua/AquaCli.scala index 4bab5013..4c6d155a 100644 --- a/cli/.jvm/src/main/scala/aqua/AquaCli.scala +++ b/cli/.jvm/src/main/scala/aqua/AquaCli.scala @@ -5,7 +5,7 @@ import aqua.backend.air.AirBackend import aqua.backend.js.JavaScriptBackend import aqua.backend.ts.TypeScriptBackend import aqua.files.AquaFilesIO -import aqua.model.transform.GenerationConfig +import aqua.model.transform.TransformConfig import aqua.parser.lift.LiftParser.Implicits.idLiftParser import cats.Id import cats.data.Validated @@ -74,7 +74,7 @@ object AquaCli extends IOApp with Logging { else if (toJs) JavaScriptTarget else TypescriptTarget val bc = { - val bc = GenerationConfig(wrapWithXor = !noXor, constants = constants) + val bc = TransformConfig(wrapWithXor = !noXor, constants = constants) bc.copy(relayVarName = bc.relayVarName.filterNot(_ => noRelay)) } logger.info(s"Aqua Compiler ${versionStr}") diff --git a/cli/.jvm/src/main/scala/aqua/AquaPathCompiler.scala b/cli/.jvm/src/main/scala/aqua/AquaPathCompiler.scala index 160223e2..7b0490d2 100644 --- a/cli/.jvm/src/main/scala/aqua/AquaPathCompiler.scala +++ b/cli/.jvm/src/main/scala/aqua/AquaPathCompiler.scala @@ -4,7 +4,7 @@ import aqua.backend.Backend import aqua.compiler.{AquaCompiler, AquaError} import aqua.files.{AquaFileSources, FileModuleId} import aqua.io.* -import aqua.model.transform.GenerationConfig +import aqua.model.transform.TransformConfig import aqua.parser.lift.FileSpan import cats.data.* import cats.syntax.functor.* @@ -20,7 +20,7 @@ object AquaPathCompiler extends Logging { imports: List[Path], targetPath: Path, backend: Backend, - bodyConfig: GenerationConfig + bodyConfig: TransformConfig ): F[ValidatedNec[String, Chain[String]]] = { import ErrorRendering.showError val sources = new AquaFileSources[F](srcPath, imports) diff --git a/cli/.jvm/src/main/scala/aqua/Test.scala b/cli/.jvm/src/main/scala/aqua/Test.scala index 3bdd6bb3..b999b59a 100644 --- a/cli/.jvm/src/main/scala/aqua/Test.scala +++ b/cli/.jvm/src/main/scala/aqua/Test.scala @@ -2,10 +2,9 @@ package aqua import aqua.backend.ts.TypeScriptBackend import aqua.files.AquaFilesIO -import aqua.model.transform.GenerationConfig +import aqua.model.transform.TransformConfig import cats.data.Validated import cats.effect.{IO, IOApp, Sync} - import fs2.io.file.Path object Test extends IOApp.Simple { @@ -19,7 +18,7 @@ object Test extends IOApp.Simple { List(Path("./aqua")), Path("./target"), TypeScriptBackend, - GenerationConfig() + TransformConfig() ) .map { case Validated.Invalid(errs) => diff --git a/cli/.jvm/src/test/scala/WriteFileSpec.scala b/cli/.jvm/src/test/scala/WriteFileSpec.scala index f0134d32..76d3b013 100644 --- a/cli/.jvm/src/test/scala/WriteFileSpec.scala +++ b/cli/.jvm/src/test/scala/WriteFileSpec.scala @@ -2,12 +2,11 @@ import aqua.AquaPathCompiler import aqua.backend.air.AirBackend import aqua.backend.js.JavaScriptBackend import aqua.backend.ts.TypeScriptBackend -import aqua.model.transform.GenerationConfig +import aqua.model.transform.TransformConfig import cats.effect.IO import cats.effect.unsafe.implicits.global import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers - import fs2.io.file.{Files, Path} class WriteFileSpec extends AnyFlatSpec with Matchers { @@ -19,7 +18,7 @@ class WriteFileSpec extends AnyFlatSpec with Matchers { import aqua.files.AquaFilesIO.summon - val bc = GenerationConfig() + val bc = TransformConfig() AquaPathCompiler .compileFilesTo[IO](src, List.empty, targetTs, TypeScriptBackend, bc) .unsafeRunSync() diff --git a/compiler/src/main/scala/aqua/compiler/AquaCompiler.scala b/compiler/src/main/scala/aqua/compiler/AquaCompiler.scala index add06840..863e6d2a 100644 --- a/compiler/src/main/scala/aqua/compiler/AquaCompiler.scala +++ b/compiler/src/main/scala/aqua/compiler/AquaCompiler.scala @@ -3,11 +3,11 @@ package aqua.compiler import aqua.backend.Backend import aqua.linker.Linker import aqua.model.AquaContext -import aqua.model.res.AquaRes -import aqua.model.transform.GenerationConfig +import aqua.model.transform.TransformConfig +import aqua.model.transform.res.AquaRes import aqua.parser.lift.LiftParser 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.syntax.applicative.* import cats.syntax.flatMap.* @@ -21,7 +21,7 @@ object AquaCompiler { sources: AquaSources[F, E, I], liftI: (I, String) => LiftParser[S], backend: Backend, - config: GenerationConfig + config: TransformConfig ): F[ValidatedNec[AquaError[I, E, S], Chain[AquaCompiled[I]]]] = { import config.aquaContextMonoid type Err = AquaError[I, E, S] @@ -59,11 +59,11 @@ object AquaCompiler { } def compileTo[F[_]: Monad, E, I, S[_]: Comonad, T]( - sources: AquaSources[F, E, I], - liftI: (I, String) => LiftParser[S], - backend: Backend, - config: GenerationConfig, - write: AquaCompiled[I] => F[Seq[Validated[E, T]]] + sources: AquaSources[F, E, I], + liftI: (I, String) => LiftParser[S], + backend: Backend, + config: TransformConfig, + write: AquaCompiled[I] => F[Seq[Validated[E, T]]] ): F[ValidatedNec[AquaError[I, E, S], Chain[T]]] = compile[F, E, I, S](sources, liftI, backend, config).flatMap { case Valid(compiled) => diff --git a/model/test-kit/src/main/scala/aqua/Node.scala b/model/test-kit/src/main/scala/aqua/Node.scala index ddf7b16e..d7d855e5 100644 --- a/model/test-kit/src/main/scala/aqua/Node.scala +++ b/model/test-kit/src/main/scala/aqua/Node.scala @@ -2,8 +2,9 @@ package aqua import aqua.model.func.Call import aqua.model.func.raw.* -import aqua.model.func.resolved.{CallRes, CallServiceRes, MakeRes, MatchMismatchRes, ResolvedOp} -import aqua.model.transform.{ErrorsCatcher, GenerationConfig} +import aqua.model.transform.TransformConfig +import aqua.model.transform.res.{CallRes, CallServiceRes, MakeRes, MatchMismatchRes, ResolvedOp} +import aqua.model.transform.funcop.ErrorsCatcher import aqua.model.{LiteralModel, ValueModel, VarModel} import aqua.types.{ArrayType, LiteralType, ScalarType} 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( bc.errorHandlingCallback, 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]( CallServiceRes( 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]( CallServiceRes( bc.dataSrvId, diff --git a/model/test-kit/src/test/scala/aqua/model/transform/TransformSpec.scala b/model/test-kit/src/test/scala/aqua/model/transform/TransformSpec.scala index 51e17c3d..51a07a57 100644 --- a/model/test-kit/src/test/scala/aqua/model/transform/TransformSpec.scala +++ b/model/test-kit/src/test/scala/aqua/model/transform/TransformSpec.scala @@ -2,15 +2,16 @@ package aqua.model.transform import aqua.Node 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.transform.res.{CallRes, CallServiceRes, MakeRes} +import aqua.model.transform.{Transform, TransformConfig} import aqua.model.{LiteralModel, VarModel} import aqua.types.{ArrowType, NilType, ProductType, ScalarType} import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers class TransformSpec extends AnyFlatSpec with Matchers { - import Node._ + import Node.* val stringArrow: ArrowType = ArrowType(NilType, ProductType(ScalarType.string :: Nil)) @@ -28,7 +29,7 @@ class TransformSpec extends AnyFlatSpec with Matchers { Map.empty ) - val bc = GenerationConfig() + val bc = TransformConfig() val fc = Transform.fn(func, bc) @@ -78,7 +79,7 @@ class TransformSpec extends AnyFlatSpec with Matchers { Map.empty ) - val bc = GenerationConfig(wrapWithXor = false) + val bc = TransformConfig(wrapWithXor = false) val fc = Transform.fn(func, bc) @@ -139,7 +140,7 @@ class TransformSpec extends AnyFlatSpec with Matchers { Map.empty ) - val bc = GenerationConfig(wrapWithXor = false) + val bc = TransformConfig(wrapWithXor = false) val res = Transform.fn(f2, bc).body: Node.Res diff --git a/model/test-kit/src/test/scala/aqua/model/topology/TopologySpec.scala b/model/test-kit/src/test/scala/aqua/model/transform/topology/TopologySpec.scala similarity index 98% rename from model/test-kit/src/test/scala/aqua/model/topology/TopologySpec.scala rename to model/test-kit/src/test/scala/aqua/model/transform/topology/TopologySpec.scala index 968c34ef..73053e86 100644 --- a/model/test-kit/src/test/scala/aqua/model/topology/TopologySpec.scala +++ b/model/test-kit/src/test/scala/aqua/model/transform/topology/TopologySpec.scala @@ -1,10 +1,10 @@ -package aqua.model.topology +package aqua.model.transform.topology import aqua.Node import aqua.model.VarModel import aqua.model.func.Call 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 cats.Eval import cats.data.Chain diff --git a/model/src/main/scala/aqua/model/transform/Transform.scala b/model/transform/src/main/scala/aqua/model/transform/Transform.scala similarity index 87% rename from model/src/main/scala/aqua/model/transform/Transform.scala rename to model/transform/src/main/scala/aqua/model/transform/Transform.scala index 969a2196..f70486f0 100644 --- a/model/src/main/scala/aqua/model/transform/Transform.scala +++ b/model/transform/src/main/scala/aqua/model/transform/Transform.scala @@ -1,10 +1,10 @@ package aqua.model.transform -import aqua.model.func.FuncCallable import aqua.model.VarModel -import aqua.model.func.resolved.{NoAir, ResolvedOp} -import aqua.model.res.FuncRes -import aqua.model.topology.Topology +import aqua.model.func.FuncCallable +import aqua.model.transform.res.{FuncRes, NoAir, ResolvedOp} +import aqua.model.transform.topology.Topology +import aqua.model.transform.funcop.* import aqua.types.ScalarType import cats.data.Chain import cats.free.Cofree @@ -23,7 +23,7 @@ object Transform extends Logging { ): Cofree[Chain, ResolvedOp] = 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( Chain.fromOption(conf.relayVarName).map(VarModel(_, ScalarType.string)) ) diff --git a/model/src/main/scala/aqua/model/transform/GenerationConfig.scala b/model/transform/src/main/scala/aqua/model/transform/TransformConfig.scala similarity index 84% rename from model/src/main/scala/aqua/model/transform/GenerationConfig.scala rename to model/transform/src/main/scala/aqua/model/transform/TransformConfig.scala index 5e575f5f..54dff453 100644 --- a/model/src/main/scala/aqua/model/transform/GenerationConfig.scala +++ b/model/transform/src/main/scala/aqua/model/transform/TransformConfig.scala @@ -4,7 +4,7 @@ import aqua.model.{AquaContext, LiteralModel, ValueModel, VarModel} import aqua.types.ScalarType import cats.kernel.Monoid -case class GenerationConfig( +case class TransformConfig( getDataService: String = "getDataSrv", callbackService: String = "callbackSrv", errorHandlingService: String = "errorHandlingSrv", @@ -12,7 +12,7 @@ case class GenerationConfig( respFuncName: String = "response", relayVarName: Option[String] = Some("-relay-"), wrapWithXor: Boolean = true, - constants: List[GenerationConfig.Const] = Nil + constants: List[TransformConfig.Const] = Nil ) { 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, // or relay's variable otherwise - val hostPeerId: GenerationConfig.Const = - GenerationConfig.Const( + val hostPeerId: TransformConfig.Const = + TransformConfig.Const( "host_peer_id", 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) - def forHost: GenerationConfig = - GenerationConfig(wrapWithXor = false, relayVarName = None) + def forHost: TransformConfig = + TransformConfig(wrapWithXor = false, relayVarName = None) } diff --git a/model/src/main/scala/aqua/model/cursor/ChainCursor.scala b/model/transform/src/main/scala/aqua/model/transform/cursor/ChainCursor.scala similarity index 97% rename from model/src/main/scala/aqua/model/cursor/ChainCursor.scala rename to model/transform/src/main/scala/aqua/model/transform/cursor/ChainCursor.scala index e05e1b3a..4c059f1f 100644 --- a/model/src/main/scala/aqua/model/cursor/ChainCursor.scala +++ b/model/transform/src/main/scala/aqua/model/transform/cursor/ChainCursor.scala @@ -1,4 +1,4 @@ -package aqua.model.cursor +package aqua.model.transform.cursor import cats.data.{Chain, NonEmptyList} diff --git a/model/src/main/scala/aqua/model/cursor/ChainZipper.scala b/model/transform/src/main/scala/aqua/model/transform/cursor/ChainZipper.scala similarity index 98% rename from model/src/main/scala/aqua/model/cursor/ChainZipper.scala rename to model/transform/src/main/scala/aqua/model/transform/cursor/ChainZipper.scala index f1e49393..1139eb3b 100644 --- a/model/src/main/scala/aqua/model/cursor/ChainZipper.scala +++ b/model/transform/src/main/scala/aqua/model/transform/cursor/ChainZipper.scala @@ -1,4 +1,4 @@ -package aqua.model.cursor +package aqua.model.transform.cursor import cats.data.Chain import cats.free.Cofree diff --git a/model/src/main/scala/aqua/model/transform/ArgsProvider.scala b/model/transform/src/main/scala/aqua/model/transform/funcop/ArgsProvider.scala similarity index 97% rename from model/src/main/scala/aqua/model/transform/ArgsProvider.scala rename to model/transform/src/main/scala/aqua/model/transform/funcop/ArgsProvider.scala index 159b03d0..4690e2b9 100644 --- a/model/src/main/scala/aqua/model/transform/ArgsProvider.scala +++ b/model/transform/src/main/scala/aqua/model/transform/funcop/ArgsProvider.scala @@ -1,4 +1,4 @@ -package aqua.model.transform +package aqua.model.transform.funcop import aqua.model.{ValueModel, VarModel} import aqua.model.func.Call diff --git a/model/src/main/scala/aqua/model/transform/ErrorsCatcher.scala b/model/transform/src/main/scala/aqua/model/transform/funcop/ErrorsCatcher.scala similarity index 97% rename from model/src/main/scala/aqua/model/transform/ErrorsCatcher.scala rename to model/transform/src/main/scala/aqua/model/transform/funcop/ErrorsCatcher.scala index a7855d55..0af7e103 100644 --- a/model/src/main/scala/aqua/model/transform/ErrorsCatcher.scala +++ b/model/transform/src/main/scala/aqua/model/transform/funcop/ErrorsCatcher.scala @@ -1,4 +1,4 @@ -package aqua.model.transform +package aqua.model.transform.funcop import aqua.model.{LiteralModel, ValueModel, VarModel} import aqua.model.func.Call diff --git a/model/src/main/scala/aqua/model/transform/InitPeerCallable.scala b/model/transform/src/main/scala/aqua/model/transform/funcop/InitPeerCallable.scala similarity index 94% rename from model/src/main/scala/aqua/model/transform/InitPeerCallable.scala rename to model/transform/src/main/scala/aqua/model/transform/funcop/InitPeerCallable.scala index 8f8c7d9b..c435c254 100644 --- a/model/src/main/scala/aqua/model/transform/InitPeerCallable.scala +++ b/model/transform/src/main/scala/aqua/model/transform/funcop/InitPeerCallable.scala @@ -1,4 +1,4 @@ -package aqua.model.transform +package aqua.model.transform.funcop import aqua.model.{LiteralModel, ValueModel} import aqua.model.func.Call diff --git a/model/src/main/scala/aqua/model/transform/ResolveFunc.scala b/model/transform/src/main/scala/aqua/model/transform/funcop/ResolveFunc.scala similarity index 98% rename from model/src/main/scala/aqua/model/transform/ResolveFunc.scala rename to model/transform/src/main/scala/aqua/model/transform/funcop/ResolveFunc.scala index dd5614ac..8e7aeb0a 100644 --- a/model/src/main/scala/aqua/model/transform/ResolveFunc.scala +++ b/model/transform/src/main/scala/aqua/model/transform/funcop/ResolveFunc.scala @@ -1,4 +1,4 @@ -package aqua.model.transform +package aqua.model.transform.funcop import aqua.model.func.* import aqua.model.func.raw.{FuncOp, FuncOps} diff --git a/model/src/main/scala/aqua/model/res/AquaRes.scala b/model/transform/src/main/scala/aqua/model/transform/res/AquaRes.scala similarity index 67% rename from model/src/main/scala/aqua/model/res/AquaRes.scala rename to model/transform/src/main/scala/aqua/model/transform/res/AquaRes.scala index 9e42fe88..f7a49a4b 100644 --- a/model/src/main/scala/aqua/model/res/AquaRes.scala +++ b/model/transform/src/main/scala/aqua/model/transform/res/AquaRes.scala @@ -1,7 +1,8 @@ -package aqua.model.res +package aqua.model.transform.res 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 case class AquaRes(funcs: Chain[FuncRes], services: Chain[ServiceRes]) { @@ -10,7 +11,7 @@ case class AquaRes(funcs: Chain[FuncRes], services: Chain[ServiceRes]) { object AquaRes { - def fromContext(ctx: AquaContext, conf: GenerationConfig): AquaRes = + def fromContext(ctx: AquaContext, conf: TransformConfig): AquaRes = AquaRes( funcs = Chain.fromSeq(ctx.funcs.values.toSeq).map(Transform.fn(_, conf)), services = Chain.fromSeq(ctx.services.values.toSeq).map(ServiceRes.fromModel(_)) diff --git a/model/src/main/scala/aqua/model/func/resolved/CallRes.scala b/model/transform/src/main/scala/aqua/model/transform/res/CallRes.scala similarity index 80% rename from model/src/main/scala/aqua/model/func/resolved/CallRes.scala rename to model/transform/src/main/scala/aqua/model/transform/res/CallRes.scala index 0031d227..eaa06ebb 100644 --- a/model/src/main/scala/aqua/model/func/resolved/CallRes.scala +++ b/model/transform/src/main/scala/aqua/model/transform/res/CallRes.scala @@ -1,4 +1,4 @@ -package aqua.model.func.resolved +package aqua.model.transform.res import aqua.model.ValueModel import aqua.model.func.Call diff --git a/model/src/main/scala/aqua/model/res/FuncRes.scala b/model/transform/src/main/scala/aqua/model/transform/res/FuncRes.scala similarity index 89% rename from model/src/main/scala/aqua/model/res/FuncRes.scala rename to model/transform/src/main/scala/aqua/model/transform/res/FuncRes.scala index 238fe5fe..ebab4d8a 100644 --- a/model/src/main/scala/aqua/model/res/FuncRes.scala +++ b/model/transform/src/main/scala/aqua/model/transform/res/FuncRes.scala @@ -1,18 +1,17 @@ -package aqua.model.res +package aqua.model.transform.res import aqua.model.func.FuncCallable -import aqua.model.func.resolved.ResolvedOp -import aqua.model.transform.GenerationConfig +import aqua.model.transform.TransformConfig import aqua.types.{ArrowType, Type} import cats.data.Chain import cats.free.Cofree case class FuncRes( source: FuncCallable, - conf: GenerationConfig, + conf: TransformConfig, body: Cofree[Chain, ResolvedOp] ) { - import FuncRes._ + import FuncRes.* lazy val funcName = source.funcName diff --git a/model/src/main/scala/aqua/model/func/resolved/MakeRes.scala b/model/transform/src/main/scala/aqua/model/transform/res/MakeRes.scala similarity index 88% rename from model/src/main/scala/aqua/model/func/resolved/MakeRes.scala rename to model/transform/src/main/scala/aqua/model/transform/res/MakeRes.scala index e86b369a..30a967c9 100644 --- a/model/src/main/scala/aqua/model/func/resolved/MakeRes.scala +++ b/model/transform/src/main/scala/aqua/model/transform/res/MakeRes.scala @@ -1,18 +1,8 @@ -package aqua.model.func.resolved +package aqua.model.transform.res import aqua.model.func.Call -import aqua.model.func.raw.{ - CallServiceTag, - ForTag, - MatchMismatchTag, - NextTag, - OnTag, - ParTag, - RawTag, - SeqTag, - XorTag -} -import aqua.model.topology.Topology.Res +import aqua.model.func.raw.* +import aqua.model.transform.topology.Topology.Res import aqua.model.{LiteralModel, ValueModel} import cats.Eval import cats.data.Chain diff --git a/model/src/main/scala/aqua/model/func/resolved/ResolvedOp.scala b/model/transform/src/main/scala/aqua/model/transform/res/ResolvedOp.scala similarity index 96% rename from model/src/main/scala/aqua/model/func/resolved/ResolvedOp.scala rename to model/transform/src/main/scala/aqua/model/transform/res/ResolvedOp.scala index 403f4c9c..0964c0e6 100644 --- a/model/src/main/scala/aqua/model/func/resolved/ResolvedOp.scala +++ b/model/transform/src/main/scala/aqua/model/transform/res/ResolvedOp.scala @@ -1,4 +1,4 @@ -package aqua.model.func.resolved +package aqua.model.transform.res import aqua.model.ValueModel import aqua.model.func.Call diff --git a/model/src/main/scala/aqua/model/res/ServiceRes.scala b/model/transform/src/main/scala/aqua/model/transform/res/ServiceRes.scala similarity index 83% rename from model/src/main/scala/aqua/model/res/ServiceRes.scala rename to model/transform/src/main/scala/aqua/model/transform/res/ServiceRes.scala index bba1fd3f..4cf8def7 100644 --- a/model/src/main/scala/aqua/model/res/ServiceRes.scala +++ b/model/transform/src/main/scala/aqua/model/transform/res/ServiceRes.scala @@ -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.model.LiteralModel case class ServiceRes(name: String, members: List[(String, ArrowType)], defaultId: Option[String]) diff --git a/model/src/main/scala/aqua/model/func/raw/PathFinder.scala b/model/transform/src/main/scala/aqua/model/transform/topology/PathFinder.scala similarity index 97% rename from model/src/main/scala/aqua/model/func/raw/PathFinder.scala rename to model/transform/src/main/scala/aqua/model/transform/topology/PathFinder.scala index 728564b2..caf5e6b6 100644 --- a/model/src/main/scala/aqua/model/func/raw/PathFinder.scala +++ b/model/transform/src/main/scala/aqua/model/transform/topology/PathFinder.scala @@ -1,6 +1,7 @@ -package aqua.model.func.raw +package aqua.model.transform.topology import aqua.model.ValueModel +import aqua.model.func.raw.{OnTag, ParGroupTag} import cats.data.Chain import cats.data.Chain.{:==, ==:, nil} import scribe.Logging diff --git a/model/src/main/scala/aqua/model/func/raw/RawCursor.scala b/model/transform/src/main/scala/aqua/model/transform/topology/RawCursor.scala similarity index 97% rename from model/src/main/scala/aqua/model/func/raw/RawCursor.scala rename to model/transform/src/main/scala/aqua/model/transform/topology/RawCursor.scala index b276434c..8cfaa392 100644 --- a/model/src/main/scala/aqua/model/func/raw/RawCursor.scala +++ b/model/transform/src/main/scala/aqua/model/transform/topology/RawCursor.scala @@ -1,11 +1,12 @@ -package aqua.model.func.raw +package aqua.model.transform.topology import aqua.model.ValueModel -import aqua.model.cursor.{ChainCursor, ChainZipper} +import aqua.model.func.raw.* import cats.Eval import cats.data.{Chain, NonEmptyList, OptionT} -import cats.free.Cofree +import aqua.model.transform.cursor._ import cats.syntax.traverse._ +import cats.free.Cofree import scribe.Logging // Can be heavily optimized by caching parent cursors, not just list of zippers diff --git a/model/src/main/scala/aqua/model/topology/Topology.scala b/model/transform/src/main/scala/aqua/model/transform/topology/Topology.scala similarity index 95% rename from model/src/main/scala/aqua/model/topology/Topology.scala rename to model/transform/src/main/scala/aqua/model/transform/topology/Topology.scala index 528907b3..f50d1ee6 100644 --- a/model/src/main/scala/aqua/model/topology/Topology.scala +++ b/model/transform/src/main/scala/aqua/model/transform/topology/Topology.scala @@ -1,15 +1,15 @@ -package aqua.model.topology +package aqua.model.transform.topology -import aqua.model.cursor.ChainZipper -import aqua.model.func.raw._ -import aqua.model.func.resolved._ +import aqua.model.transform.cursor.ChainZipper +import aqua.model.func.raw.* +import aqua.model.transform.res.* import aqua.model.{LiteralModel, ValueModel, VarModel} import aqua.types.{BoxType, ScalarType} import cats.Eval import cats.data.Chain.nil import cats.data.{Chain, NonEmptyChain, NonEmptyList, OptionT} import cats.free.Cofree -import cats.syntax.traverse._ +import cats.syntax.traverse.* import scribe.Logging object Topology extends Logging { diff --git a/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala b/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala index 7e0da597..b62d0bdf 100644 --- a/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala +++ b/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala @@ -1,9 +1,10 @@ package aqua.semantics import aqua.Node -import aqua.Node._ +import aqua.Node.* 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.parser.Ast import aqua.parser.lift.{LiftParser, Span} @@ -29,7 +30,7 @@ class SemanticsSpec extends AnyFlatSpec with Matchers { val ast = Ast.fromString(script).toList.head val ctx = AquaContext.blank - val bc = GenerationConfig() + val bc = TransformConfig() import bc.aquaContextMonoid val p = Semantics.process(ast, ctx)