Interp.agda 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. open import Proc
  2. module Interp (param : Param) where
  3. import Hear
  4. open import Basics
  5. private
  6. open module P = Process param
  7. open module H = Hear param
  8. open Tran
  9. data Result {a : U}(p : Proc a) : Set where
  10. speak : forall {w q} -> p -! w !-> q -> Result p
  11. refuse : Silent p -> Result p
  12. upR : {a b : U}{p : Proc b}(φ : Tran a b) -> Result p -> Result (φ /| p)
  13. upR φ (speak s) = speak (tx-/| s)
  14. upR φ (refuse s) = refuse (silent-/| s)
  15. Oracle : Set
  16. Oracle = Nat -> LR
  17. prophecy : Oracle -> LR
  18. prophecy ol = ol zero
  19. nextOracle : Oracle -> Oracle
  20. nextOracle ol = ol % suc
  21. anyOracle : Oracle
  22. anyOracle _ = left
  23. ocons : LR -> Oracle -> Oracle
  24. ocons l or zero = l
  25. ocons l or (suc n) = or n
  26. step : {a : U}{p : Proc a} -> Guard p -> Oracle -> Result p
  27. step og _ = refuse silent-o
  28. step (>g _) _ = refuse silent->
  29. step (w !g p) _ = speak tx-!
  30. step (w ! p +g f) _ = speak tx-+
  31. step (defg x g) ol with step g ol
  32. ... | refuse s1 = refuse (silent-def s1)
  33. ... | speak s1 = speak (tx-def s1)
  34. step (g1 ||g g2) ol with step g1 (nextOracle ol)
  35. | step g2 (nextOracle ol)
  36. | prophecy ol
  37. ... | refuse s1 | refuse s2 | _ = refuse (silent-|| s1 s2)
  38. ... | speak s1 | refuse s2 | _ = speak (tx-!| s1 (sound g2))
  39. ... | refuse s1 | speak s2 | _ = speak (tx-|! (sound g1) s2)
  40. ... | speak s1 | speak _ | left = speak (tx-!| s1 (sound g2))
  41. ... | speak _ | speak s2 | right = speak (tx-|! (sound g1) s2)
  42. step (φ /|g g) ol = upR φ (step g ol)