mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 22:50:18 +00:00
Fix using par
after xor
: xor handled first now (#93)
* Script with crazy wrong output * Xor can be combined with Par
This commit is contained in:
parent
7991ab0b4d
commit
d88b3a561c
@ -1,15 +1,28 @@
|
||||
service Demo("demo"):
|
||||
get4: u64, u64, string -> u64
|
||||
bool: -> bool
|
||||
log: string, bool -> ()
|
||||
service Peer("peer"):
|
||||
is_connected: string -> bool
|
||||
|
||||
func initAfterJoin(users: []string) -> []string:
|
||||
for user <- users par:
|
||||
on user:
|
||||
isOnline <- Demo.bool()
|
||||
service Op("op"):
|
||||
identity: -> ()
|
||||
|
||||
data User:
|
||||
peer_id: string
|
||||
relay_id: string
|
||||
name: string
|
||||
|
||||
service Test("test"):
|
||||
getUserList: -> []User
|
||||
doSomething: -> bool
|
||||
|
||||
func initAfterJoin(me: User) -> []User:
|
||||
allUsers <- Test.getUserList()
|
||||
for user <- allUsers par:
|
||||
on user.relay_id:
|
||||
isOnline <- Peer.is_connected(user.peer_id)
|
||||
if isOnline:
|
||||
on user via "user relay":
|
||||
Demo.log("me", true)
|
||||
Demo.log(user, isOnline)
|
||||
par Demo.log(user, isOnline)
|
||||
<- users
|
||||
on user.peer_id via user.relay_id:
|
||||
Test.doSomething()
|
||||
else:
|
||||
on user.peer_id via user.relay_id:
|
||||
Op.identity()
|
||||
par Test.doSomething()
|
||||
<- allUsers
|
@ -92,6 +92,14 @@ object AirGen {
|
||||
Eval later opsToSingle(
|
||||
ops
|
||||
)
|
||||
case (XorParTag(opsx, opsy), ops) =>
|
||||
// TODO should be resolved
|
||||
println(
|
||||
Console.RED + "XorParTag reached AirGen, most likely it's an error" + Console.RESET
|
||||
)
|
||||
Eval later opsToSingle(
|
||||
Chain(apply(opsx.tree), apply(opsy.tree))
|
||||
)
|
||||
|
||||
}
|
||||
.value
|
||||
|
@ -11,7 +11,12 @@ import cats.syntax.functor._
|
||||
|
||||
case class FuncOp(tree: Cofree[Chain, OpTag]) extends Model {
|
||||
def head: OpTag = tree.head
|
||||
def isRightAssoc: Boolean = head == XorTag || head == ParTag
|
||||
|
||||
lazy val isRightAssoc: Boolean = head match {
|
||||
case XorTag | ParTag => true
|
||||
case _: XorParTag => true
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def cata[T](folder: (OpTag, Chain[T]) => Eval[T]): Eval[T] =
|
||||
Cofree.cata(tree)(folder)
|
||||
@ -70,8 +75,11 @@ object FuncOp {
|
||||
override def combine(x: FuncOp, y: FuncOp): FuncOp = (x.tree.head, y.tree.head) match {
|
||||
case (ParTag, ParTag) => FuncOp(y.tree.copy(tail = (x.tree.tail, y.tree.tail).mapN(_ ++ _)))
|
||||
case (XorTag, XorTag) => FuncOp(y.tree.copy(tail = (x.tree.tail, y.tree.tail).mapN(_ ++ _)))
|
||||
case (XorTag, ParTag) => FuncOp(Cofree[Chain, OpTag](XorParTag(x, y), Eval.now(Chain.empty)))
|
||||
case (_, ParTag | XorTag) =>
|
||||
wrap(SeqTag, FuncOp(y.tree.copy(tail = y.tree.tail.map(_.prepend(x.tree)))))
|
||||
case (_, XorParTag(xor, par)) =>
|
||||
combine(combine(x, xor), par)
|
||||
case _ => FuncOpSemigroup.combine(x, y)
|
||||
}
|
||||
}
|
||||
@ -79,6 +87,8 @@ object FuncOp {
|
||||
implicit object FuncOpSemigroup extends Semigroup[FuncOp] {
|
||||
|
||||
override def combine(x: FuncOp, y: FuncOp): FuncOp = (x.tree.head, y.tree.head) match {
|
||||
case (_, XorParTag(xor, par)) => combine(combine(x, xor), par)
|
||||
case (XorParTag(xor, par), _) => combine(combine(xor, par), y)
|
||||
case (SeqTag, SeqTag) => FuncOp(y.tree.copy(tail = (x.tree.tail, y.tree.tail).mapN(_ ++ _)))
|
||||
case (_, SeqTag) => FuncOp(y.tree.copy(tail = y.tree.tail.map(_.prepend(x.tree))))
|
||||
case (SeqTag, _) => FuncOp(x.tree.copy(tail = x.tree.tail.map(_.append(y.tree))))
|
||||
|
@ -31,6 +31,7 @@ sealed trait OpTag {
|
||||
case object SeqTag extends OpTag
|
||||
case object ParTag extends OpTag
|
||||
case object XorTag extends OpTag
|
||||
case class XorParTag(xor: FuncOp, par: FuncOp) extends OpTag
|
||||
case class OnTag(peerId: ValueModel, via: Chain[ValueModel]) extends OpTag
|
||||
case class NextTag(item: String) extends OpTag
|
||||
case class MatchMismatchTag(left: ValueModel, right: ValueModel, shouldMatch: Boolean) extends OpTag
|
||||
|
Loading…
Reference in New Issue
Block a user