consumer_effect_lexical_protocol.tri (2195B)
1 -- Two named operations, three receivers, changing retained environments, 2 -- and a worker-valued environment across the generic effect driver. 3 !import "consumers.structural" S 4 !import "consumers.lexical-worker" L 5 !import "consumers.effect" E 6 !import "prelude" !Local 7 !import "io" !Local 8 9 rule input state output = S.makeRule input state output 10 await operation argument receiver environment = (S.outFork (S.outLiteral 1) 11 (S.outFork (S.outLiteral operation) 12 (S.outFork argument (S.outFork (S.outLiteral receiver) environment)))) 13 done value = S.outFork (S.outLiteral 0) value 14 counterIR = S.makeConsumer 88 [(rule S.patAny S.patAny (S.outLiteral 88))] 15 counterWorker = resultOr t (L.lCompile counterIR) 16 entryIR = S.makeConsumer t [(rule S.patAny S.patAny 17 (await "One" (S.outLiteral 3) "second" (S.outLiteral 41)))] 18 secondIR worker = S.makeConsumer t [(rule 19 (S.patFork (S.patLiteral 1) (S.patCapture 0)) (S.patCapture 1) 20 (await "Two" (S.outFork (S.outCapture 0) (S.outCapture 1)) "third" 21 (S.outFork (S.outLiteral worker) (S.outLiteral 52))))] 22 thirdIR = S.makeConsumer t [(rule 23 (S.patFork (S.patLiteral 1) (S.patCapture 2)) 24 (S.patFork (S.patCapture 0) (S.patCapture 1)) 25 (S.outCall (S.outCapture 0) (S.outCapture 2) 3 26 (done (S.outFork (S.outCapture 3) (S.outCapture 1)))))] 27 entryWorker = resultOr t (L.lCompile entryIR) 28 secondWorker = resultOr t (L.lCompile (secondIR counterWorker)) 29 thirdWorker = resultOr t (L.lCompile thirdIR) 30 lexReceivers = [(pair "entry" (S.makeConsumer t entryWorker)) 31 (pair "second" (S.makeConsumer t secondWorker)) 32 (pair "third" (S.makeConsumer t thirdWorker))] 33 refReceivers = [(pair "entry" entryIR) (pair "second" (secondIR counterIR)) 34 (pair "third" thirdIR)] 35 one argument = pure (ok 7 t) 36 two argument = pure (ok argument t) 37 operations = [(pair "One" one) (pair "Two" two)] 38 lexRun = E.run L.lEffectStep lexReceivers operations "entry" 3 t 39 refRun = E.run S.runConsumer refReceivers operations "entry" 3 t 40 main = io (bind lexRun (compiled : bind refRun (reference : 41 putStrLn (matchBool "consumer-effect-lexical-ok" 42 "consumer-effect-lexical-DIFFER" 43 (and? (equal? compiled reference) 44 (equal? compiled (ok (pair 88 52) t))))))) 45 main