Skip to content

Commit

Permalink
Replace noop with hop
Browse files Browse the repository at this point in the history
  • Loading branch information
InversionSpaces committed Jun 19, 2023
1 parent d54a5ca commit 580d2f2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
37 changes: 29 additions & 8 deletions compiler/src/test/scala/aqua/compiler/AquaCompilerSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package aqua.compiler

import aqua.model.{CallModel, ForModel, FunctorModel, IntoIndexModel, LiteralModel, ValueModel, VarModel}
import aqua.model.{
CallModel,
ForModel,
FunctorModel,
IntoIndexModel,
LiteralModel,
ValueModel,
VarModel
}
import aqua.model.transform.TransformConfig
import aqua.model.transform.Transform
import aqua.parser.ParserError
Expand All @@ -10,7 +18,20 @@ import aqua.parser.lift.Span
import aqua.parser.lift.Span.S
import aqua.raw.ConstantRaw
import aqua.raw.value.{LiteralRaw, ValueRaw, VarRaw}
import aqua.res.{ApRes, CallRes, CallServiceRes, CanonRes, FoldRes, MakeRes, MatchMismatchRes, NextRes, ParRes, RestrictionRes, SeqRes, XorRes}
import aqua.res.{
ApRes,
CallRes,
CallServiceRes,
CanonRes,
FoldRes,
MakeRes,
MatchMismatchRes,
NextRes,
ParRes,
RestrictionRes,
SeqRes,
XorRes
}
import aqua.types.{ArrayType, CanonStreamType, LiteralType, ScalarType, StreamType, Type}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
Expand Down Expand Up @@ -83,8 +104,8 @@ class AquaCompilerSpec extends AnyFlatSpec with Matchers {

}

def through(peer: ValueModel, log: String = null) =
MakeRes.noop(peer, log)
def through(peer: ValueModel) =
MakeRes.hop(peer)

val relay = VarRaw("-relay-", ScalarType.string)

Expand Down Expand Up @@ -203,10 +224,10 @@ class AquaCompilerSpec extends AnyFlatSpec with Matchers {
),
join(results, LiteralModel.fromRaw(LiteralRaw.number(2))),
CanonRes(results, init, CallModel.Export(canonResult.name, canonResult.`type`)).leaf,
ApRes(
canonResult,
CallModel.Export(flatResult.name, flatResult.`type`)
).leaf
ApRes(
canonResult,
CallModel.Export(flatResult.name, flatResult.`type`)
).leaf
)
),
CallServiceRes(
Expand Down
26 changes: 16 additions & 10 deletions model/res/src/main/scala/aqua/res/MakeRes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ import cats.data.{Chain, NonEmptyList}
import cats.free.Cofree
import aqua.raw.value.{LiteralRaw, ValueRaw}
import aqua.model.*
import aqua.types.ScalarType

// TODO docs
object MakeRes {
val op: ValueModel = LiteralModel.fromRaw(LiteralRaw.quote("op"))

def noop(onPeer: ValueModel, log: String = null): ResolvedOp.Tree =
CallServiceRes(
op,
"noop",
CallRes(
Option(log).filter(_ == "").map(LiteralRaw.quote).map(LiteralModel.fromRaw).toList,
None
),
onPeer
).leaf
def hop(onPeer: ValueModel): ResolvedOp.Tree = {
val streamName = "-hop-stream-"
val canonName = "-hop-canon-"
val elementType = ScalarType.u8

RestrictionRes(streamName, isStream = true).wrap(
RestrictionRes(canonName, isStream = false).wrap(
CanonRes(
operand = VarModel(streamName, StreamType(elementType)),
peerId = onPeer,
exportTo = CallModel.Export(canonName, CanonStreamType(elementType))
).leaf
)
)
}

def join(onPeer: ValueModel, operands: NonEmptyList[ValueModel]): ResolvedOp.Tree =
CallServiceRes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ object Topology extends Logging {

val chainZipperEv = resolved.traverse(cofree =>
(
rc.topology.pathBefore.map(through(_, s"before ${currI}")),
rc.topology.pathAfter.map(through(_, s"after ${currI}", reversed = true))
rc.topology.pathBefore.map(through(_)),
rc.topology.pathAfter.map(through(_, reversed = true))
).mapN { case (pathBefore, pathAfter) =>
val cz = ChainZipper(
pathBefore,
Expand Down Expand Up @@ -623,7 +623,6 @@ object Topology extends Logging {
// if there's a chain like a -> b -> c -> ... -> b -> g, remove everything between b and b
def through(
peerIds: Chain[ValueModel],
log: String = null,
reversed: Boolean = false
): Chain[Res] =
peerIds.map { v =>
Expand All @@ -635,16 +634,16 @@ object Topology extends Logging {
if (reversed)
SeqRes.wrap(
NextRes(itemName).leaf,
MakeRes.noop(VarModel(itemName, ScalarType.string, Chain.empty), log)
MakeRes.hop(VarModel(itemName, ScalarType.string, Chain.empty))
)
else
SeqRes.wrap(
MakeRes.noop(VarModel(itemName, ScalarType.string, Chain.empty), log),
MakeRes.hop(VarModel(itemName, ScalarType.string, Chain.empty)),
NextRes(itemName).leaf
)
)
case _ =>
MakeRes.noop(v, log)
MakeRes.hop(v)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ object ModelBuilder {
)
}

def through(peer: ValueModel, log: String = null) =
MakeRes.noop(peer, log)
def through(peer: ValueModel) =
MakeRes.hop(peer)
}

0 comments on commit 580d2f2

Please sign in to comment.