From d5d7b8b5fd6970c4fff85a05f234be2a8287f1c6 Mon Sep 17 00:00:00 2001 From: Dmitry Kurinskiy Date: Wed, 2 Feb 2022 19:06:35 +0300 Subject: [PATCH] Fix for greedy XOR tags (#412) --- aqua-src/test.aqua | 20 +++++++++++++++++++ .../scala/aqua/model/inline/TagInliner.scala | 3 +-- .../src/main/scala/aqua/raw/ops/RawTag.scala | 4 ++++ .../scala/aqua/raw/ops/RawTagGivens.scala | 2 +- npm/error.js | 0 npm/index.js | 0 .../scala/aqua/semantics/SemanticsSpec.scala | 3 ++- 7 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 aqua-src/test.aqua mode change 100644 => 100755 npm/error.js mode change 100644 => 100755 npm/index.js diff --git a/aqua-src/test.aqua b/aqua-src/test.aqua new file mode 100644 index 00000000..45e79365 --- /dev/null +++ b/aqua-src/test.aqua @@ -0,0 +1,20 @@ +import "@fluencelabs/aqua-ipfs/ipfs.aqua" + +service Console("run-console"): + print(res: IpfsGetResult) + +service ConsoleOp("run-console"): + print(arr: []string) + + +func something(node: string) -> string: + service_id: *string + on HOST_PEER_ID: + res <- Ipfs.get("1234") + if res.error == "": + service_id <<- "0x" + else: + service_id <<- "1x" + ConsoleOp.print(service_id) + Console.print(res) + <- service_id! \ No newline at end of file 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 1b287d7d..ae0d6675 100644 --- a/model/inline/src/main/scala/aqua/model/inline/TagInliner.scala +++ b/model/inline/src/main/scala/aqua/model/inline/TagInliner.scala @@ -129,11 +129,10 @@ object TagInliner extends Logging { case RestrictionTag(name, isStream) => pure(RestrictionModel(name, isStream)) - case SeqTag => pure(SeqModel) + case _: SeqGroupTag => pure(SeqModel) case ParTag.Detach => pure(DetachModel) case _: ParGroupTag => pure(ParModel) case XorTag | XorTag.LeftBiased => - // TODO should we do smth with XorTag.LeftBiased? pure(XorModel) case _: NoExecTag => none case _ => diff --git a/model/raw/src/main/scala/aqua/raw/ops/RawTag.scala b/model/raw/src/main/scala/aqua/raw/ops/RawTag.scala index 759531cd..a2ed9df9 100644 --- a/model/raw/src/main/scala/aqua/raw/ops/RawTag.scala +++ b/model/raw/src/main/scala/aqua/raw/ops/RawTag.scala @@ -42,6 +42,10 @@ sealed trait GroupTag extends RawTag sealed trait SeqGroupTag extends GroupTag +object SeqGroupTag extends SeqGroupTag { + override def toString: String = "SeqGroup" +} + sealed trait ParGroupTag extends GroupTag case object SeqTag extends SeqGroupTag { diff --git a/model/raw/src/main/scala/aqua/raw/ops/RawTagGivens.scala b/model/raw/src/main/scala/aqua/raw/ops/RawTagGivens.scala index e68c17f0..f678d5a6 100644 --- a/model/raw/src/main/scala/aqua/raw/ops/RawTagGivens.scala +++ b/model/raw/src/main/scala/aqua/raw/ops/RawTagGivens.scala @@ -48,7 +48,7 @@ trait RawTagGivens { case (XorTag, XorTag) => y.copy(tail = (x.tail, y.tail).mapN(_ ++ _)) case (XorTag.LeftBiased, XorTag) => - SeqTag.wrap(y.copy(tail = (x.tail, y.tail).mapN(_ ++ _))) + SeqGroupTag.wrap(y.copy(tail = (x.tail, y.tail).mapN(_ ++ _))) case (XorTag, ParTag) => XorParTag(x, y).leaf case (_, ParTag | XorTag) => SeqTag.wrap(y.copy(tail = y.tail.map(_.prepend(x)))) diff --git a/npm/error.js b/npm/error.js old mode 100644 new mode 100755 diff --git a/npm/index.js b/npm/index.js old mode 100644 new mode 100755 diff --git a/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala b/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala index 88d12338..4de43cd3 100644 --- a/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala +++ b/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala @@ -2,7 +2,7 @@ package aqua.semantics import aqua.raw.RawContext import aqua.parser.Ast -import aqua.raw.ops.{Call, CallServiceTag, FuncOp, OnTag, ParTag, RawTag, SeqTag} +import aqua.raw.ops.{Call, CallServiceTag, FuncOp, OnTag, ParTag, RawTag, SeqGroupTag, SeqTag} import aqua.parser.Parser import aqua.parser.lift.{LiftParser, Span} import aqua.raw.value.{LiteralRaw, ValueRaw} @@ -11,6 +11,7 @@ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import cats.~> import cats.data.Chain +import cats.syntax.show.* class SemanticsSpec extends AnyFlatSpec with Matchers {