From d130e5aab078bc959d398a3d95e1289179b92c97 Mon Sep 17 00:00:00 2001 From: DieMyst Date: Thu, 2 Nov 2023 09:23:50 +0700 Subject: [PATCH] build[S] --- aqua-src/antithesis.aqua | 16 ++++++++++++---- .../aqua/model/inline/ArrowInliner.scala | 3 +-- .../scala/aqua/model/inline/TagInliner.scala | 19 ++++++++++++++++--- .../transform/pre/FuncPreTransformer.scala | 10 ++++------ .../rules/names/NamesInterpreter.scala | 10 +++++----- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/aqua-src/antithesis.aqua b/aqua-src/antithesis.aqua index 731efd5b..4b4ab872 100644 --- a/aqua-src/antithesis.aqua +++ b/aqua-src/antithesis.aqua @@ -1,6 +1,14 @@ -alias Troll: u32 +aqua A -func test() -> i8: - MyAbility = Troll(f = "sf") +export newFunc - <- 42 \ No newline at end of file +func returnNil() -> *string: + someStr: *string + <- someStr + +func newFunc() -> []string: + -- new stream + stream <- returnNil() -- stream -> someStr: *str + stream <<- "asd" + <- stream + -- end \ No newline at end of file diff --git a/model/inline/src/main/scala/aqua/model/inline/ArrowInliner.scala b/model/inline/src/main/scala/aqua/model/inline/ArrowInliner.scala index 6ffae791..701146a2 100644 --- a/model/inline/src/main/scala/aqua/model/inline/ArrowInliner.scala +++ b/model/inline/src/main/scala/aqua/model/inline/ArrowInliner.scala @@ -317,7 +317,7 @@ object ArrowInliner extends Logging { ) defineRenames <- Mangler[S].findAndForbidNames(defineNames) - renaming = ( + renaming = data.renames ++ streamRenames ++ arrowRenames ++ @@ -325,7 +325,6 @@ object ArrowInliner extends Logging { capturedValues.renames ++ capturedArrows.renames ++ defineRenames - ) /** * TODO: Optimize resolve. diff --git a/model/inline/src/main/scala/aqua/model/inline/TagInliner.scala b/model/inline/src/main/scala/aqua/model/inline/TagInliner.scala index daa7a0ff..2f5e954c 100644 --- a/model/inline/src/main/scala/aqua/model/inline/TagInliner.scala +++ b/model/inline/src/main/scala/aqua/model/inline/TagInliner.scala @@ -68,13 +68,15 @@ object TagInliner extends Logging { prefix: Option[OpModel.Tree] = None ) extends TagInlined(prefix) +// case After(process: () => State[S, TagInlined[S]], prefix: Option[OpModel.Tree] = None) extends TagInlined(prefix) + /** * Finalize inlining, construct a tree * * @param children Children results * @return Result of inlining */ - def build(children: Chain[OpModel.Tree]): OpModel.Tree = { + def build[S](children: Chain[OpModel.Tree]): State[S, OpModel.Tree] = { val inlined = this match { case Empty(_) => children case Single(model, _) => @@ -83,7 +85,7 @@ object TagInliner extends Logging { Chain.one(toModel(children)) } - SeqModel.wrap(Chain.fromOption(prefix) ++ inlined) + State.pure(SeqModel.wrap(Chain.fromOption(prefix) ++ inlined)) } } @@ -371,6 +373,16 @@ object TagInliner extends Logging { } yield model.fold(TagInlined.Empty())(m => TagInlined.Single(model = m)) case RestrictionTag(name, typ) => + // for { + // exps <- Exports[S].exports + // _ = println(s"exps for restriction tag $name: " + exps) + // } yield TagInlined.Single(model = RestrictionModel(name, typ)) + // ...after( + // for { + // // exps <- Exports[S].exports + // // _ = println(s"exps for restriction tag $name: " + exps) + // // } yield TagInlined.Single(model = RestrictionModel(name, typ)) + // ) pure(RestrictionModel(name, typ)) case DeclareStreamTag(value) => @@ -444,7 +456,8 @@ object TagInliner extends Logging { headInlined <- f(cf.head) tail <- StateT.liftF(cf.tail) children <- tail.traverse(traverseS[S](_, f)) - } yield headInlined.build(children) + inlined <- headInlined.build(children) + } yield inlined def handleTree[S: Exports: Mangler: Arrows]( tree: RawTag.Tree diff --git a/model/transform/src/main/scala/aqua/model/transform/pre/FuncPreTransformer.scala b/model/transform/src/main/scala/aqua/model/transform/pre/FuncPreTransformer.scala index 145a1c57..b3eea8ff 100644 --- a/model/transform/src/main/scala/aqua/model/transform/pre/FuncPreTransformer.scala +++ b/model/transform/src/main/scala/aqua/model/transform/pre/FuncPreTransformer.scala @@ -1,12 +1,10 @@ package aqua.model.transform.pre -import aqua.model.FuncArrow -import aqua.model.ArgsCall -import aqua.raw.ops.{Call, CallArrowRawTag, RawTag, SeqTag, TryTag} -import aqua.raw.value.{ValueRaw, VarRaw} +import aqua.model.{ArgsCall, FuncArrow} +import aqua.raw.ops.* +import aqua.raw.value.VarRaw import aqua.types.* -import cats.syntax.show.* import cats.syntax.option.* /** @@ -47,7 +45,7 @@ case class FuncPreTransformer( * @return FuncArrow that can be called and delegates the call to a client-registered callback */ private def arrowToCallback(name: String, arrowType: ArrowType): FuncArrow = { - val (args, call, ret) = ArgsCall.arrowToArgsCallRet(arrowType) + val (_, call, ret) = ArgsCall.arrowToArgsCallRet(arrowType) FuncArrow( arrowCallbackPrefix + name, callback(name, call), diff --git a/semantics/src/main/scala/aqua/semantics/rules/names/NamesInterpreter.scala b/semantics/src/main/scala/aqua/semantics/rules/names/NamesInterpreter.scala index bd718aea..b55b53a7 100644 --- a/semantics/src/main/scala/aqua/semantics/rules/names/NamesInterpreter.scala +++ b/semantics/src/main/scala/aqua/semantics/rules/names/NamesInterpreter.scala @@ -3,15 +3,15 @@ package aqua.semantics.rules.names import aqua.parser.lexer.{Name, Token} import aqua.semantics.Levenshtein import aqua.semantics.rules.StackInterpreter -import aqua.semantics.rules.report.ReportAlgebra import aqua.semantics.rules.locations.LocationsAlgebra -import aqua.types.{AbilityType, ArrowType, StreamType, Type} +import aqua.semantics.rules.report.ReportAlgebra +import aqua.types.{ArrowType, StreamType, Type} import cats.data.{OptionT, State} +import cats.syntax.all.* +import cats.syntax.applicative.* import cats.syntax.flatMap.* import cats.syntax.functor.* -import cats.syntax.applicative.* -import cats.syntax.all.* import monocle.Lens import monocle.macros.GenLens @@ -160,7 +160,7 @@ class NamesInterpreter[S[_], X](using mapStackHead(Map.empty) { frame => frame -> frame.names.collect { case (n, st @ StreamType(_)) => n -> st - }.toMap + } } override def beginScope(token: Token[S]): SX[Unit] =