90 likes | 184 Views
This Java code implements rewrite rules directly while optimizing and simplifying intermediate structures. It includes implementations for instructions like Stop, Seq, Instant, Par, Await, Until, UntilStar, and more. The implementation aims to provide a reference guide and is not optimized, leading to unnecessary intermediate terms.
E N D
Implémentations de Junior • Rewrite : implémentation directe des règles de réécriture • Replace : Rewrite + optimisation des créations de structures intermédiaires • Storm, Simple : grand nombre d’événements • …
b t’, E’ t, E STOP Stop, E Nothing, E Réécritures MicroState s = t.rewrite(E); b = s.flag; t’ = s.term; E’ est la nouvelle valeur de E public class Stop extends Instruction { public MicroState rewrite(EnvironmentImpl env){ return new MicroState(STOP,new Nothing()); } }
TERM u’, E’’ u, E’ b t’, E’ t, E b b u’, E’’ t’, E’ b = STOP ou b = SUSP Seq(t,u), E t, E b Seq(t’,u), E’ Seq(t,u), E Séquence Création d’une nouvelle instruction public class Seq extends BinaryInstruction { public MicroState rewrite(EnvironmentImpl env){ MicroState s = left.rewrite(env); if (TERM == s.flag) return right.rewrite(env); return new MicroState(s.flag,new Seq(s.term,right)); } }
b SUSP t’, E’ t, E Instant(t’), E’[eoi = vrai] move(E’) = faux u, E’’ b u, E’’ Instant(t), E Instant public class Instant extends UnaryInstruction { public MicroState rewrite(EnvironmentImpl env){ MicroState s = body.rewrite(env) ; if (s.flag != SUSP) return new MicroState(s.flag,new Instant(s.term)); if (env.move) env.move = false; else env.eoi = true; return new Instant(s.term).rewrite(env); } }
b1 t’, E’ t, E C(b1,b2) Par d1,d2(t’,u), E’ Par SUSP,b2(t,u), E Parallélisme public class Par extends BinaryInstruction { final public byte leftFlag, rightFlag; public MicroState result(Instruction l, Instruction r, byte lf, byte rf){ byte b = SUSP, nlf = lf, nrf = rf; if (lf != SUSP && rf != SUSP){ b = (lf==TERM && rf==TERM) ? TERM : STOP; if (lf==STOP) nlf = SUSP; if (rf==STOP) nrf = SUSP; } return new MicroState(b, new Par(l,r,nlf,nrf)); }
b2 u’, E’ u, E C(b1,b2) Par d1,d2(t,u’), E’ Par b1,SUSP(t,u), E b2 b1 u’, E’’ u, E’ t’, E’ t, E C(b1,b2) Par d1,d2(t’,u’), E’’ Par SUSP,SUSP(t,u), E Parallélisme - 2 public MicroState rewrite(EnvironmentImpl env){ if (leftFlag == SUSP && rightFlag != SUSP){ MicroState s = left.rewrite(env); return result (s.term,right,s.flag,rightFlag); } if (leftFlag != SUSP && rightFlag == SUSP){ MicroState s = right.rewrite(env); return result (left,s.term,leftFlag,s.flag); } MicroState ls = left.rewrite(env), rs = right.rewrite(env); return result (ls.term,rs.term,ls.flag,rs.flag); }
Await public class Await extends Instruction { final public Config config; public MicroState rewrite(EnvironmentImpl env){ if (config.sat(env)) return new MicroState((env.eoi ? STOP : TERM), new Nothing()); if (config.unsat(env)) return new MicroState(STOP,this); return new MicroState(SUSP,this); } } Await(Not(S))
Until public class Until extends BinaryInstruction { final public Config config; public MicroState rewrite(EnvironmentImpl env){ MicroState s = left.rewrite(env); if (STOP != s.flag) return new MicroState(s.flag, new Until(config,s.term,right)); return new UntilStar(config,s.term,right).rewrite(env); } } public class UntilStar extends BinaryInstruction { final public Config config; public MicroState rewrite(EnvironmentImpl env){ if (config.sat(env)){ if (! env.eoi) return right.rewrite(env); else return new MicroState(STOP,right); } if (config.unsat(env)) return new MicroState(STOP,new Until(config,left,right)); return new MicroState(SUSP,this); } }
Conclusion • Rewrite = implémentation directe des règles de réécritures • Environ 500 lignes de code = implémentation de référence • Non optimisée : termes intermédiaires inutiles • Replace = Rewrite + changements d’états des instructions public class Stop extends Instruction { boolean b = false; public byte rewrite(){ if (b == false){ b = true; return STOP; } return TERM; } }