This commit is contained in:
Dmitry Kurinskiy 2021-05-04 12:09:27 +03:00 committed by GitHub
parent 85cc40fa5e
commit 450fe4e142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 34 deletions

View File

@ -40,41 +40,33 @@ object AirGen {
case list => list.reduceLeft(SeqGen) case list => list.reduceLeft(SeqGen)
} }
def wrapMatchWithXor(ag: AirGen): AirGen = ag match {
case mmg: MatchMismatchGen =>
XorGen(mmg, NullGen)
case g => g
}
def apply(op: Cofree[Chain, OpTag]): AirGen = def apply(op: Cofree[Chain, OpTag]): AirGen =
Cofree Cofree
.cata[Chain, OpTag, AirGen](op) { .cata[Chain, OpTag, AirGen](op) {
case (SeqTag, ops) =>
case (SeqTag, ops) => Eval later ops.toList.reduceLeftOption(SeqGen).getOrElse(NullGen) Eval later ops.map(wrapMatchWithXor).toList.reduceLeftOption(SeqGen).getOrElse(NullGen)
case (ParTag, ops) => Eval later ops.toList.reduceLeftOption(ParGen).getOrElse(NullGen) case (ParTag, ops) =>
case (XorTag, ops) => Eval later ops.toList.reduceLeftOption(XorGen).getOrElse(NullGen) Eval later ops.map(wrapMatchWithXor).toList.reduceLeftOption(ParGen).getOrElse(NullGen)
case (NextTag(item), ops) => case (XorTag, ops) =>
Eval later new AirGen { Eval later ops.toList.reduceLeftOption(XorGen).getOrElse(NullGen)
case (NextTag(item), _) =>
override def generate: Air = Eval later NextGen(item)
Air.Next(item)
}
case (MatchMismatchTag(left, right, shouldMatch), ops) => case (MatchMismatchTag(left, right, shouldMatch), ops) =>
Eval later new AirGen { Eval later MatchMismatchGen(
valueToData(left),
valueToData(right),
shouldMatch,
opsToSingle(ops)
)
override def generate: Air = {
val l = valueToData(left)
val r = valueToData(right)
val resAir = opsToSingle(ops).generate
if (shouldMatch) Air.Match(l, r, resAir) else Air.Mismatch(l, r, resAir)
}
}
case (ForTag(item, iterable), ops) => case (ForTag(item, iterable), ops) =>
Eval later new AirGen { Eval later ForGen(valueToData(iterable), item, opsToSingle(ops.map(wrapMatchWithXor)))
override def generate: Air = {
val iterData = valueToData(iterable)
val resAir = opsToSingle(ops).generate
Air.Fold(iterData, item, resAir)
}
}
case (CallServiceTag(serviceId, funcName, Call(args, exportTo), peerId), _) => case (CallServiceTag(serviceId, funcName, Call(args, exportTo), peerId), _) =>
Eval.later( Eval.later(
ServiceCallGen( ServiceCallGen(
@ -89,18 +81,19 @@ object AirGen {
) )
) )
case (CallArrowTag(funcName, Call(args, exportTo)), ops) => case (CallArrowTag(funcName, _), _) =>
// TODO: should be already resolved & removed from tree // TODO: should be already resolved & removed from tree
Eval later opsToSingle( println(
ops Console.RED + s"Unresolved arrow in AirGen: $funcName" + Console.RESET
) )
Eval later NullGen
case (OnTag(_, _), ops) => case (OnTag(_, _), ops) =>
// TODO should be resolved // TODO should be resolved
Eval later opsToSingle( Eval later opsToSingle(
ops ops
) )
case (XorParTag(opsx, opsy), ops) => case (XorParTag(opsx, opsy), _) =>
// TODO should be resolved // TODO should be resolved
println( println(
Console.RED + "XorParTag reached AirGen, most likely it's an error" + Console.RESET Console.RED + "XorParTag reached AirGen, most likely it's an error" + Console.RESET
@ -124,6 +117,26 @@ case class SeqGen(left: AirGen, right: AirGen) extends AirGen {
} }
case class MatchMismatchGen(
left: DataView,
right: DataView,
shouldMatch: Boolean,
body: AirGen
) extends AirGen {
override def generate: Air =
if (shouldMatch) Air.Match(left, right, body.generate)
else Air.Mismatch(left, right, body.generate)
}
case class ForGen(iterable: DataView, item: String, body: AirGen) extends AirGen {
override def generate: Air = Air.Fold(iterable, item, body.generate)
}
case class NextGen(item: String) extends AirGen {
override def generate: Air = Air.Next(item)
}
case class ServiceCallGen( case class ServiceCallGen(
peerId: DataView, peerId: DataView,
srvId: DataView, srvId: DataView,

View File

@ -51,7 +51,7 @@ object Topology {
Cursor Cursor
.transform(op) { .transform(op) {
case c @ Cursor( case c @ Cursor(
cz @ `current`(cf), `current`(cf),
loc @ `head`(parent: GroupTag) /: _ loc @ `head`(parent: GroupTag) /: _
) => ) =>
val cfu = cf.copy(mapTag(cf.head, loc)) val cfu = cf.copy(mapTag(cf.head, loc))