label.hs (1366B)
1 module Label where 2 3 import Esterel 4 5 addLabel :: Int -> (Scope, Scope) -> PExp2 ((Scope, Scope), Int) -> ScopeLabelExp 6 addLabel i a x = Annotated x (a, i) 7 8 doBinop i e1 e2 = 9 let (ni1, ne1) = doLabel i e1 in 10 let (ni2, ne2) = doLabel ni1 e2 in 11 (ni2, ne1, ne2) 12 13 doLabel :: Int -> ScopeExp -> (Int, ScopeLabelExp) 14 doLabel i (Annotated x a) = case x of 15 Esterel.Nothing -> (i+1, addLabel i a Esterel.Nothing) 16 Pause -> (i+1, addLabel i a Pause) 17 Loop e -> 18 let (ni, ne) = doLabel (i+1) e in 19 (ni, addLabel i a (Loop ne)) 20 Present s e1 e2 -> 21 let (ni, ne1, ne2) = doBinop (i+1) e1 e2 in 22 (ni, addLabel i a (Present s ne1 ne2)) 23 Seq e1 e2 -> 24 let (ni, ne1, ne2) = doBinop (i+1) e1 e2 in 25 (ni, addLabel i a (Seq ne1 ne2)) 26 Par e1 e2 -> 27 let (ni, ne1, ne2) = doBinop (i+1) e1 e2 in 28 (ni, addLabel i a (Par ne1 ne2)) 29 Suspend e s -> 30 let (ni, ne) = doLabel (i+1) e in 31 (ni, addLabel i a (Suspend ne s)) 32 Signal s e -> 33 let (ni, ne) = doLabel (i+1) e in 34 (ni, addLabel i a (Signal s ne)) 35 Trap t e -> 36 let (ni, ne) = doLabel (i+1) e in 37 (ni, addLabel i a (Trap t ne)) 38 Emit s -> 39 (i+1, addLabel i a (Emit s)) 40 Exit t -> 41 (i+1, addLabel i a (Exit t)) 42 43 label :: ScopeExp -> ScopeLabelExp 44 label e = let (_, r) = doLabel 0 e in r 45