PK S(junior/PK S(Kttjunior/Action.javapackage junior; public interface Action extends java.io.Serializable { public void execute(Environment env); } PK S(v)Fzzjunior/BooleanWrapper.javapackage junior; public interface BooleanWrapper extends java.io.Serializable { boolean evaluate(Environment env); } PK S(byMlljunior/Configuration.javapackage junior; public interface Configuration extends java.io.Serializable { Configuration copy (); }PK S(- "junior/ConstBooleanWrapper.javapackage junior; public class ConstBooleanWrapper implements BooleanWrapper { public boolean bool; public ConstBooleanWrapper(boolean bool){ this.bool = bool; } public String toString(){ return ""+bool; } public boolean evaluate(Environment env){ return bool; } } PK S(nȭ("junior/ConstIdentifierWrapper.javapackage junior; public class ConstIdentifierWrapper implements IdentifierWrapper { public Identifier id; public ConstIdentifierWrapper(Identifier id){ this.id = id; } public String toString(){ return ""+id; } public Identifier evaluate(Environment env){ return id; } } PK S(?T?junior/ConstIntegerWrapper.javapackage junior; public class ConstIntegerWrapper implements IntegerWrapper { public int value; public ConstIntegerWrapper(int value){ this.value = value; } public String toString(){ return ""+value; } public int evaluate(Environment env){ return value; } } PK S(4\junior/ConstObjectWrapper.javapackage junior; public class ConstObjectWrapper implements ObjectWrapper { public Object object; public ConstObjectWrapper(Object object){ this.object = object; } public String toString(){ return ""+object; } public Object evaluate(Environment env){ return object; } } PK S(`q  junior/Environment.javapackage junior; public interface Environment { // null: not generated event; otherwise, array of generated values Object[] currentValues (Identifier id); Object[] previousValues (Identifier id); Program getFrozen (Identifier id); Object linkedObject(); } PK S(G2(OOjunior/Flags.javapackage junior; public interface Flags { byte STOP = 0, TERM = 1, SUSP = 2; } PK S(%߆junior/Identifier.javapackage junior; public interface Identifier extends java.io.Serializable { boolean equals(Object object); public int hashCode(); }PK S( qjunior/IdentifierWrapper.javapackage junior; public interface IdentifierWrapper extends java.io.Serializable { Identifier evaluate(Environment env); } PK S(,!I{{junior/IntegerWrapper.javapackage junior; public interface IntegerWrapper extends java.io.Serializable { public int evaluate(Environment env); } PK S(S۪IIjunior/Jr.javapackage junior; import junior.core.*; public class Jr extends JrBase { static public Identifier StringIdentifier(String str){ return new StringIdentifier(str); } static public IdentifierWrapper StringWrapper(String str){ return ConstWrapper(StringIdentifier(str)); } static public Configuration StringConfig(String str){ return new Presence(StringWrapper(str)); } // Machines static public SyncMachine SyncMachine(){ return JrBase.SyncMachine(Nothing()); } static public UnSyncMachine UnSyncMachine(){ return JrBase.UnSyncMachine(Nothing()); } // Repeat static public Program Repeat(int count, Program body){ return JrBase.Repeat(ConstWrapper(count),body); } // if static public Program If(BooleanWrapper cond,Program thenInst){ return JrBase.If(cond,thenInst,Nothing()); } // Generate static public Program Generate(Identifier event,ObjectWrapper owrap){ return JrBase.Generate(ConstWrapper(event),owrap); } static public Program Generate(IdentifierWrapper iwrap,Object value){ return JrBase.Generate(iwrap,ConstWrapper(value)); } static public Program Generate(Identifier event,Object value){ return JrBase.Generate(ConstWrapper(event),ConstWrapper(value)); } static public Program Generate(IdentifierWrapper iwrap){ return JrBase.Generate(iwrap,ConstWrapper(Jr.NO_VALUE)); } static public Program Generate(Identifier event){ return Generate(event,ConstWrapper(Jr.NO_VALUE)); } // Await static public Program Await(IdentifierWrapper wrapper){ return JrBase.Await(Presence(wrapper)); } static public Program Await(Identifier event){ return JrBase.Await(Presence(event)); } // Until static public Program Until(Configuration config, Program body){ return JrBase.Until(config,body,Nothing()); } static public Program Until(IdentifierWrapper wrapper, Program body, Program handler){ return JrBase.Until(Presence(wrapper),body,handler); } static public Program Until(IdentifierWrapper wrapper, Program body){ return Until(wrapper,body,Nothing()); } static public Program Until(Identifier event, Program body, Program handler){ return Until(ConstWrapper(event),body,handler); } static public Program Until(Identifier event, Program body){ return Until(ConstWrapper(event),body,Nothing()); } // When static public Program When(Configuration config,Program thenInst){ return JrBase.When(config,thenInst,Nothing()); } static public Program When(IdentifierWrapper wrapper,Program thenInst,Program elseInst){ return JrBase.When(Presence(wrapper),thenInst,elseInst); } static public Program When(IdentifierWrapper wrapper,Program thenInst){ return When(wrapper,thenInst,Nothing()); } static public Program When(Identifier event, Program thenInst, Program elseInst){ return When(ConstWrapper(event),thenInst,elseInst); } static public Program When(Identifier event, Program thenInst){ return When(ConstWrapper(event),thenInst,Nothing()); } // Control static public Program Control(Identifier event, Program body){ return JrBase.Control(ConstWrapper(event),body); } // Freezable static public Program Freezable(Identifier event, Program body){ return JrBase.Freezable(ConstWrapper(event),body); } // Link static public Program Link(Object object, Program body){ return JrBase.Link(ConstWrapper(object),body); } // Configurations static public Configuration Presence(Identifier event){ return JrBase.Presence(ConstWrapper(event)); } /********* STRINGS *********************/ static public Program Generate(String event,Object val){ return JrBase.Generate(StringWrapper(event),ConstWrapper(val)); } static public Program Generate(String event){ return Generate(StringWrapper(event)); } static public Program Await(String event){ return JrBase.Await(StringConfig(event)); } static public Program Control(String event, Program body){ return JrBase.Control(StringWrapper(event),body); } static public Program Local(String event, Program body){ return JrBase.Local(StringIdentifier(event),body); } static public Program Freezable(String event, Program body){ return JrBase.Freezable(StringWrapper(event),body); } // until static public Program Until(String event, Program body, Program handler){ return JrBase.Until(StringConfig(event),body,handler); } static public Program Until(String event, Program body){ return JrBase.Until(StringConfig(event),body,Nothing()); } // when static public Program When(String event,Program thenInst, Program elseInst){ return JrBase.When(StringConfig(event),thenInst,elseInst); } static public Program When(String event,Program thenInst){ return JrBase.When(StringConfig(event),thenInst,Nothing()); } // configurations static public Configuration Presence(String event){ return JrBase.Presence(StringWrapper(event)); } static public Configuration Not(String event){ return JrBase.Not(Presence(event)); } } PK S(auu6 junior/JrBase.javapackage junior; import junior.core.*; public class JrBase { final static public Object NO_VALUE = DummyValues.NONE; final static public Object NULL_VALUE = DummyValues.NULL; // Constant wrappers static public IdentifierWrapper ConstWrapper(Identifier id){ return new ConstIdentifierWrapper(id); } static public ObjectWrapper ConstWrapper(Object obj){ return new ConstObjectWrapper(obj); } static public IntegerWrapper ConstWrapper(int n){ return new ConstIntegerWrapper(n); } static public BooleanWrapper ConstWrapper(boolean b){ return new ConstBooleanWrapper(b); } // Machines static public UnSyncMachine UnSyncMachine(Program p) { return new BasicContext(p); } static public SyncMachine SyncMachine(Program p) { return new ExecContext(p); } // Atom static public Program Atom(Action action){ return new Atom(action); } // Nothing, Stop, Seq, Par, Loop static public Program Nothing(){ return new Nothing(); } static public Program Stop(){ return new Stop(); } static public Program Seq(Program first, Program second){ return new Seq(first,second); } static public Program Par(Program left, Program right){ return new Merge(left,right); } static public Program Loop(Program body){ return new Loop(body); } // Repeat static public Program Repeat(IntegerWrapper wrapper, Program body){ return new Repeat(wrapper,body); } // If static public Program If(BooleanWrapper cond, Program thenInst, Program elseInst){ return new If(cond,thenInst,elseInst); } // Generate static public Program Generate(IdentifierWrapper iwrap,ObjectWrapper owrap){ return new Generate(iwrap,owrap); } // Await, Until, When static public Program Await(Configuration config){ return new Await(config); } static public Program Until(Configuration config, Program body, Program handler){ return new Until(config,body,handler); } static public Program When(Configuration config, Program thenInst, Program elseInst){ return new When(config,thenInst,elseInst); } // Local static public Program Local(Identifier event, Program body){ return new Local(event,new EventDataImpl(),body); } // Control static public Program Control(IdentifierWrapper wrapper, Program body){ return new Control(new Presence(wrapper),body); } // Freezable static public Program Freezable(IdentifierWrapper wrapper, Program body){ return new Freezable(new Presence(wrapper),body); } // Link static public Program Link(ObjectWrapper wrapper, Program body){ return new Link(wrapper,body); } // Configurations static public Configuration Presence(IdentifierWrapper wrapper){ return new Presence(wrapper); } static public Configuration And(Configuration c1, Configuration c2){ return new And(c1,c2); } static public Configuration Or(Configuration c1, Configuration c2){ return new Or(c1,c2); } static public Configuration Not(Configuration c){ return new Not(c); } } PK S(!junior/Machine.javapackage junior; public interface Machine { boolean react(); // react = instant void add(Program program); // for next instant // proper semantics of 'generate' will depend on effective implementation void generate(Identifier event); // for current or/and next instant void generate(Identifier event, Object val); // for current or/and next instant Program getFrozen (Identifier event); // from previous instant } PK S(:syyjunior/ObjectWrapper.javapackage junior; public interface ObjectWrapper extends java.io.Serializable { Object evaluate(Environment env); } PK S(M``junior/Program.javapackage junior; public interface Program extends java.io.Serializable { Program copy (); }PK S(FZjunior/StringIdentifier.javapackage junior; public class StringIdentifier implements Identifier { public String id; public StringIdentifier(String id){ this.id = id; } public int hashCode(){ return id.hashCode(); } public String toString(){ return id; } public boolean equals(Object object){ if (object instanceof StringIdentifier) return id.equals(((StringIdentifier)object).id); return false; } } PK S( kkjunior/SyncMachine.javapackage junior; public interface SyncMachine extends Machine { // generate is now for next instant only } PK T(oqrrjunior/UnSyncMachine.javapackage junior; public interface UnSyncMachine extends Machine { // generate is for current or next instant } PK T( junior/core/PK T()ajunior/core/And.javapackage junior.core; import junior.Configuration; public class And extends Config { final public Config config1,config2; public And(Configuration c1, Configuration c2){ config1 = (Config)c1; config2 = (Config)c2; } public void reset(){ config1.reset(); config2.reset(); } public String toString(){ return "("+config1+" and "+config2+")"; } public boolean equals(Config other){ return super.equals(other) && config1.equals(((And)other).config1) && config2.equals(((And)other).config2); } public boolean fixed(EnvironmentImpl env){ boolean b1 = config1.fixed(env), b2 = config2.fixed(env); if (b1 && !config1.eval(env)) return true; if (b2 && !config2.eval(env)) return true; return b1 && b2; } public boolean eval(EnvironmentImpl env){ return config1.eval(env) && config2.eval(env); } public Configuration copy(){ return new And(config1.copy(),config2.copy()); } } PK T(Tjunior/core/Atom.javapackage junior.core; import junior.*; public class Atom extends Instruction { final public Action action; public Atom(Action action){ this.action = action; } public String toString(){ return PrintInstruction.Action(action); } public MicroState rewrite(EnvironmentImpl env){ action.execute(env); return new MicroState(TERM,new Nothing()); } public Program copy(){ return new Atom(action); } } PK T(#Ќ]00junior/core/Await.javapackage junior.core; import junior.*; public class Await extends Instruction { final public Config config; public Await(Configuration config){ this.config = (Config)config; } public String toString(){ return PrintInstruction.Await(""+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 unknown(); } public Program copy(){ return new Await(config.copy()); } } PK T(433junior/core/BasicContext.javapackage junior.core; import junior.*; public class BasicContext implements Flags, UnSyncMachine { public Instant instant; public EnvironmentImpl env; public Program toAdd = Jr.Nothing(); public boolean somethingToAdd = false; // constructor public BasicContext(Program program){ this.instant = new Instant(program); buildEnvironment(); } // building the environment public void buildEnvironment(){ env = new EnvironmentImpl(); } // dynamic add method for next instant public void add(Program inst){ toAdd = Jr.Par(toAdd,inst); somethingToAdd = true; } protected void performAddings(){ if (somethingToAdd == false) return; instant = new Instant(Jr.Par(toAdd,instant.body)); toAdd = Jr.Nothing(); somethingToAdd = false; } // generate methods public void generate(Identifier event){ this.generate(event,Jr.NO_VALUE); } public void generate(Identifier event, Object obj){ env.generate(event,obj); } // get frozen programs public Program getFrozen (Identifier event){ return env.getFrozen(event); } // react method public boolean react(){ performAddings(); MicroState s = instant.rewrite(env); instant = (Instant)s.term; env.newInstant(); return (TERM == s.flag); } }PK T(&"junior/core/BinaryInstruction.javapackage junior.core; import junior.*; public abstract class BinaryInstruction extends Instruction { final public Instruction left,right; public BinaryInstruction(Program left,Program right){ this.left = (Instruction)left; this.right = (Instruction)right; } }PK T(lv((junior/core/Config.javapackage junior.core; import junior.Configuration; abstract public class Config implements Configuration, java.io.Serializable { abstract public boolean fixed(EnvironmentImpl env); abstract public boolean eval(EnvironmentImpl env); abstract public void reset(); abstract public Configuration copy(); public boolean sat(EnvironmentImpl env){ return fixed(env) && eval(env); } public boolean unsat(EnvironmentImpl env){ return fixed(env) && !eval(env); } public boolean equals(Config config){ return getClass() == config.getClass(); } } PK T(Vjunior/core/Control.javapackage junior.core; import junior.*; public class Control extends UnaryInstruction { final public Presence presence; public Control(Presence presence, Program body){ super(body); this.presence = presence; } public String toString(){ return PrintInstruction.Control(""+presence,""+body); } public MicroState rewrite(EnvironmentImpl env){ if (presence.sat(env)){ MicroState s = body.rewrite(env); return new MicroState(s.flag,new Control(presence,s.term)); } if (presence.unsat(env)) return new MicroState(STOP,this); return unknown(); } public Program copy(){ return new Control((Presence)presence.copy(),body.copy()); } } PK T('Njjunior/core/DummyValues.javapackage junior.core; public class DummyValues implements java.io.Serializable { public static DummyValues NONE = new DummyValues(), NULL = new DummyValues(); }PK T(m& junior/core/EnvironmentImpl.javapackage junior.core; import java.util.*; import junior.*; public class EnvironmentImpl implements Environment, Cloneable { public long instant = 1; public boolean eoi, move; // end of instants public Hashtable eventSet = new Hashtable(); // events public Hashtable frozen = new Hashtable(), tempFrozen = new Hashtable(); // frozen programs public Object linkedObject; // implicit object // for debug public String toString(){ return ""+eventSet; } //linked object public Object linkedObject(){ return linkedObject; } // event values public Object[] currentValues (Identifier event){ return getEventData(event).currentValues(instant); } public Object[] previousValues (Identifier event){ return getEventData(event).previousValues(instant); } // events public EventDataImpl getEventData(Identifier event){ EventDataImpl eventData = (EventDataImpl)eventSet.get(event); if (eventData == null){ eventData = new EventDataImpl(); eventSet.put(event,eventData); } return eventData; } public boolean isGenerated(Identifier event){ return getEventData(event).isGenerated(instant); } public void generate(Identifier event,Object val){ EventDataImpl eventData = getEventData(event); if (!eventData.isGenerated(instant)) move = true; eventData.generate(instant,val); } // frozen instructions public void storeFrozen(Identifier event,Program program){ Program old = (Program)tempFrozen.get(event); Program actual = (old == null) ? program : Jr.Par(old,program); System.out.println("STORE "+actual+" ASSOCIATED TO "+event); tempFrozen.put(event,actual); } public Program getFrozen(Identifier event){ return (Program)frozen.remove(event); } // new instant public void newInstant(){ instant++; eoi = move = false; //System.out.println("SWAP "); frozen = tempFrozen; tempFrozen = new Hashtable(); } } PK T('00junior/core/EventData.javapackage junior.core; public interface EventData extends java.io.Serializable { void generate (long instant); void generate (long instant, Object val); boolean isGenerated (long instant); Object[] currentValues (long instant); Object[] previousValues (long instant); EventData copy(); }PK T(*&junior/core/EventDataImpl.javapackage junior.core; import junior.*; import java.util.*; public class EventDataImpl implements EventData, Cloneable { public long generated = 0, lastActualization = 0; public Vector current = null, previous = null; public void actualize(long instant){ if (lastActualization == instant) return; previous = (instant == lastActualization+1) ? current : null; current = null; lastActualization = instant; } public Object[] currentValues (long instant){ actualize(instant); if (current == null) return null; Object[] res = new Object[current.size()]; current.copyInto(res); return res; } public Object[] previousValues (long instant){ actualize(instant); if (previous == null) return null; Object[] res = new Object[previous.size()]; previous.copyInto(res); return res; } public void generate(long instant){ this.generate(instant,Jr.NO_VALUE); } public void generate(long instant,Object val){ actualize(instant); this.generated = instant; if (val == null) val = Jr.NULL_VALUE; if (current == null) current = new Vector(); current.addElement(val); } public boolean isGenerated(long instant){ actualize(instant); return instant == generated; } public EventData copy(){ EventDataImpl res; try{ res = (EventDataImpl)clone(); res.current = (current == null) ? null : (Vector)current.clone(); res.previous = (previous == null) ? null : (Vector)previous.clone(); }catch(CloneNotSupportedException e){ throw new InternalError(""+e); } return res; } }PK T(]6VVjunior/core/ExecContext.javapackage junior.core; import java.util.*; import junior.*; public class ExecContext extends BasicContext implements Machine, SyncMachine { public Vector toGenerate = new Vector(); // constructor public ExecContext(Program program){ super(program); } // synchronized dynamic add method for next instant public void add(Program inst){ synchronized(toAdd){ super.add(inst); } } protected void performAddings(){ synchronized(toAdd){ super.performAddings(); } } // synchronized generate methods for next instant public void generate(Identifier event, Object obj){ synchronized(toGenerate){ toGenerate.addElement(new GenerateOrder(event,obj)); } } public void generate(Identifier event){ this.generate(event,Jr.NO_VALUE); } protected void performGenerations(){ synchronized(toGenerate){ if (toGenerate.size() > 0){ Enumeration list = toGenerate.elements(); while (list.hasMoreElements()){ GenerateOrder order = (GenerateOrder)list.nextElement(); super.generate(order.identifier,order.value); } toGenerate.removeAllElements(); } } } // react method public synchronized boolean react(){ performGenerations(); return super.react(); } } PK T(dƸjunior/core/Freezable.javapackage junior.core; import junior.*; public class Freezable extends UnaryInstruction { final public Presence presence; public Freezable(Presence presence,Program body){ super(body); this.presence = presence; } public String toString(){ return PrintInstruction.Freezable(""+presence,""+body); } public MicroState rewrite(EnvironmentImpl env){ MicroState s = body.rewrite(env); if (STOP != s.flag) return new MicroState(s.flag, new Freezable(presence,s.term)); return new FreezableStar(presence,s.term).rewrite(env); } public Program copy(){ return new Freezable((Presence)presence.copy(),body.copy()); } } PK T(6ajunior/core/FreezableStar.javapackage junior.core; import junior.*; public class FreezableStar extends UnaryInstruction { final public Presence presence; public FreezableStar(Presence presence,Program body){ super(body); this.presence = presence; } public MicroState rewrite(EnvironmentImpl env){ if (presence.sat(env)){ env.storeFrozen(presence.event,body.copy()); // the body is copied return new MicroState(((env.eoi) ? STOP : TERM),new Nothing()); } if (presence.unsat(env)) return new MicroState(STOP,new Freezable(presence,body)); return unknown(); } public Program copy(){ return new FreezableStar((Presence)presence.copy(),body.copy()); } }PK T(|[[junior/core/Generate.javapackage junior.core; import junior.*; public class Generate extends Instruction { final public IdentifierWrapper idwrap; final public ObjectWrapper objwrap; public Generate(IdentifierWrapper idwrap, ObjectWrapper objwrap){ this.idwrap = idwrap; this.objwrap = objwrap; } public String toString(){ return PrintInstruction.Generate(idwrap); } public MicroState rewrite(EnvironmentImpl env){ env.generate(idwrap.evaluate(env),objwrap.evaluate(env)); return new MicroState(TERM,new Nothing()); } public Program copy(){ return new Generate(idwrap,objwrap); } } PK T(5junior/core/GenerateOrder.javapackage junior.core; import junior.*; class GenerateOrder { final Identifier identifier; final Object value; GenerateOrder(Identifier id, Object obj){ identifier = id; value = obj; } } PK T(BJ(jjjunior/core/IODecl.javapackage junior.core; import junior.*; public class IODecl extends UnaryInstruction { final public IdentifierWrapper wrapper; final public Identifier local; public IODecl(IdentifierWrapper wrapper, Identifier local, Program body){ super(body); this.wrapper = wrapper; this.local = local; } public String toString(){ return PrintInstruction.IODecl(wrapper,""+local,""+body); } public MicroState rewrite(EnvironmentImpl env){ return new IODeclStatic(wrapper.evaluate(env),local,body).rewrite(env); } public Program copy(){ return new IODecl(wrapper,local,body.copy()); } }PK T(h3>junior/core/IODeclStatic.javapackage junior.core; import junior.*; public class IODeclStatic extends UnaryInstruction { final public Identifier extern; final public Identifier local; public EventData localEvent, save; public IODeclStatic(Identifier extern, Identifier local, EventData localEvent, Program body){ super(body); this.local = local; this.localEvent = localEvent; this.extern = extern; } public IODeclStatic(Identifier extern, Identifier intern, Program body){ this(extern,intern,new EventDataImpl(),body); } public String toString(){ return "inputoutput "+extern+" is "+local+" in "+body+" end"; } public void swapIn(EnvironmentImpl env){ if (extern.equals(local)) return; save = env.getEventData(local); env.eventSet.put(local,env.getEventData(extern)); } public void swapOut(EnvironmentImpl env){ if (extern.equals(local)) return; env.eventSet.put(extern,env.getEventData(local)); localEvent = env.getEventData(local); env.eventSet.put(local,save); } public MicroState rewrite(EnvironmentImpl env){ swapIn(env); MicroState res = body.rewrite(env); swapOut(env); return new MicroState(res.flag,new IODeclStatic(extern,local,localEvent.copy(),res.term)); } public Program copy(){ return new IODeclStatic(extern,local,localEvent.copy(),body.copy()); } } PK T(X--junior/core/If.javapackage junior.core; import junior.*; public class If extends BinaryInstruction { final public BooleanWrapper wrapper; public If(BooleanWrapper wrapper,Program thenInst, Program elseInst){ super(thenInst,elseInst); this.wrapper = wrapper; } public String toString(){ return PrintInstruction.If(wrapper,""+left,""+right); } public MicroState rewrite(EnvironmentImpl env){ return (wrapper.evaluate(env) ? left : right).rewrite(env); } public Program copy(){ return new If(wrapper,left.copy(),right.copy()); } } PK T(\ /junior/core/Instant.javapackage junior.core; import junior.*; public class Instant extends UnaryInstruction { public Instant(Program body){ super(body); } 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); } public Program copy(){ return new Instant(body.copy()); } } PK T(Pjunior/core/Instruction.javapackage junior.core; import junior.*; abstract public class Instruction implements Flags, Program, java.io.Serializable { abstract public MicroState rewrite(EnvironmentImpl env); public MicroState unknown(){ return new MicroState(SUSP,this); } } PK T(BAjunior/core/Link.javapackage junior.core; import junior.*; public class Link extends UnaryInstruction { final public ObjectWrapper wrapper; public Link(ObjectWrapper wrapper, Program body){ super(body); this.wrapper = wrapper; } public String toString(){ return PrintInstruction.Link(wrapper,""+body); } public MicroState rewrite(EnvironmentImpl env){ return new LinkStatic(wrapper.evaluate(env),body).rewrite(env); } public Program copy(){ return new Link(wrapper,body.copy()); } }PK T((n[''junior/core/LinkStatic.javapackage junior.core; import junior.*; public class LinkStatic extends UnaryInstruction { final public Object self; public LinkStatic(Object self, Program body){ super(body); this.self = self; } public MicroState rewrite(EnvironmentImpl env){ Object save = env.linkedObject; env.linkedObject = self; MicroState res = body.rewrite(env); env.linkedObject = save; return new MicroState(res.flag,new LinkStatic(self,res.term)); } public Program copy(){ return new LinkStatic(self,body.copy()); } }PK T(junior/core/Local.javapackage junior.core; import junior.*; public class Local extends UnaryInstruction { final public Identifier local; public EventData localEvent, save; public Local(Identifier local, EventData localEvent, Program body){ super(body); this.local = local; this.localEvent = localEvent; } public String toString(){ return PrintInstruction.Local(""+local,""+body); } public void swapIn(EnvironmentImpl env){ save = env.getEventData(local); env.eventSet.put(local,localEvent); } public void swapOut(EnvironmentImpl env){ localEvent = env.getEventData(local); env.eventSet.put(local,save); } public MicroState rewrite(EnvironmentImpl env){ swapIn(env); MicroState res = body.rewrite(env); swapOut(env); return new MicroState(res.flag,new Local(local,localEvent.copy(),res.term)); } public Program copy(){ return new Local(local,localEvent.copy(),body.copy()); } } PK T(wjunior/core/Loop.javapackage junior.core; import junior.*; public class Loop extends UnaryInstruction { public Loop(Program body){ super(body); } public String toString(){ return PrintInstruction.Loop(""+body); } public MicroState rewrite(EnvironmentImpl env){ MicroState s = body.rewrite(env); if (TERM == s.flag) return new Loop(body).rewrite(env); return new MicroState(s.flag,new Seq(s.term,new Loop(body))); } public Program copy(){ return new Loop(body.copy()); } } PK T(^ BBjunior/core/Merge.javapackage junior.core; import junior.*; public class Merge extends BinaryInstruction { final public byte leftFlag, rightFlag; // constructors public Merge(Program left, Program right, byte leftFlag, byte rightFlag){ super(left,right); this.leftFlag = leftFlag; this.rightFlag = rightFlag; } public Merge(Program left,Program right){ this(left,right,SUSP,SUSP); } public String toString(){ return PrintInstruction.Merge(""+left,""+right); } // determine the result public Instruction newTerm(Instruction l, Instruction r, byte lf, byte rf){ return new Merge(l,r,lf,rf); } 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,newTerm(l,r,nlf,nrf)); } // rewriting 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); } // Both branches are suspended MicroState ls = left.rewrite(env), rs = right.rewrite(env); return result(ls.term,rs.term,ls.flag,rs.flag); } // copy; don't forget the flags ! public Program copy(){ return new Merge(left.copy(),right.copy(),leftFlag,rightFlag); } } PK T(j junior/core/MicroState.javapackage junior.core; public class MicroState { final public byte flag; final public Instruction term; public MicroState(byte flag, Instruction term){ this.flag = flag; this.term = term; } } PK T(pkkjunior/core/Not.javapackage junior.core; import junior.Configuration; public class Not extends Config { final public Config config; public Not(Configuration config){ this.config = (Config)config; } public void reset(){ config.reset(); } public String toString(){ return "not "+config; } public boolean equals(Config other){ return super.equals(other) && config.equals(((Not)other).config); } public boolean fixed(EnvironmentImpl env){ return config.fixed(env); } public boolean eval(EnvironmentImpl env){ return ! config.eval(env); } public Configuration copy(){ return new Not(config.copy()); } } PK T( <&&junior/core/Nothing.javapackage junior.core; import junior.*; public class Nothing extends Instruction { public String toString(){ return PrintInstruction.Nothing(); } public MicroState rewrite(EnvironmentImpl env){ return new MicroState(TERM,this); } public Program copy(){ return new Nothing(); } } PK T(w?junior/core/Or.javapackage junior.core; import junior.Configuration; public class Or extends Config { final public Config config1,config2; public Or(Configuration c1, Configuration c2){ config1 = (Config)c1; config2 = (Config)c2; } public void reset(){ config1.reset(); config2.reset(); } public String toString(){ return "("+config1+" or "+config2+")"; } public boolean equals(Config other){ return super.equals(other) && config1.equals(((Or)other).config1) && config2.equals(((Or)other).config2); } public boolean fixed(EnvironmentImpl env){ boolean b1 = config1.fixed(env), b2 = config2.fixed(env); if (b1 && config1.eval(env)) return true; if (b2 && config2.eval(env)) return true; return b1 && b2; } public boolean eval(EnvironmentImpl env){ return config1.eval(env) || config2.eval(env); } public Configuration copy(){ return new Or(config1.copy(),config2.copy()); } } PK T(%'awwjunior/core/Presence.javapackage junior.core; import junior.*; public class Presence extends Config { final public IdentifierWrapper wrapper; public boolean evaluated = false; public Identifier event; public Presence(IdentifierWrapper wrapper){ this.wrapper = wrapper; } public void reset(){ evaluated = false; } public String toString(){ return ""+wrapper; } public boolean equals(Config config){ return super.equals(config) && wrapper == ((Presence)config).wrapper && (!evaluated || event.equals(((Presence)config).event)); } public boolean fixed(EnvironmentImpl env){ if(evaluated == false){ event = wrapper.evaluate(env); evaluated = true; } return env.isGenerated(event) || env.eoi; } public boolean eval(EnvironmentImpl env){ return env.isGenerated(event); } public Configuration copy(){ return new Presence(wrapper); } } PK T(Ʈ!junior/core/PrintInstruction.javapackage junior.core; import junior.*; public class PrintInstruction { static public String Nothing(){ return "nothing"; } static public String Stop(){ return "stop"; } static public String Action(Action action){ return ""+action; } static public String Await(String config){ return "await "+config; } static public String Control(String presence, String body){ return "control "+body+" by "+presence; } static public String Freezable(String presence, String body){ return "freeze "+body+" on "+presence; } static public String Generate(IdentifierWrapper idwrap){ return "generate "+idwrap; } static public String If(BooleanWrapper wrapper, String left, String right){ return "if "+wrapper+" then "+left+" else "+right+" end"; } static public String Local(String local, String body){ return "event "+local+" in "+body+" end"; } static public String IODecl(IdentifierWrapper wrapper, String local, String body){ return "inputoutput "+wrapper+" is "+local+" in "+body+" end"; } static public String Link(ObjectWrapper wrapper, String body){ return "link "+wrapper+" in "+body+" end"; } static public String Loop(String body){ return "loop\n"+body+"\nend"; } static public String Merge(String left, String right){ return "("+left+" || "+right+")"; } static public String Repeat(IntegerWrapper exp, String body){ return "loop {"+exp+"} "+body+" end"; } static public String Repeat(int exp, String body){ return "loop {"+exp+"} "+body+" end"; } static public String Seq(String left, String right){ return left+"; "+right; } static public String Until(String config, String left, String right){ return "do\n"+left+"\nuntil "+config+"\nhandle "+right+"\nend"; } static public String When(String config, String left, String right){ return "when "+config+" then "+left+" else "+right+" end"; } static public String Print(String msg){ return "System.out.print(\""+msg+"\")"; } }PK T(Yf( junior/core/Repeat.javapackage junior.core; import junior.*; public class Repeat extends UnaryInstruction { final public IntegerWrapper wrapper; public Repeat(IntegerWrapper wrapper,Program body){ super(body); this.wrapper = wrapper; } public String toString(){ return PrintInstruction.Repeat(wrapper,""+body); } public MicroState rewrite(EnvironmentImpl env){ return new RepeatStatic(wrapper.evaluate(env),body).rewrite(env); } public Program copy(){ return new Repeat(wrapper,body.copy()); } }PK T(_H""junior/core/RepeatStatic.javapackage junior.core; import junior.*; public class RepeatStatic extends UnaryInstruction { final public int count; public RepeatStatic(int count,Program body){ super(body); this.count = count; } public String toString(){ return "loop {"+count+"} "+body+" end"; } public MicroState rewrite(EnvironmentImpl env){ if (count <= 0) return new MicroState(TERM,new Nothing()); return new Seq(body,new RepeatStatic(count-1,body)).rewrite(env); } public Program copy(){ return new RepeatStatic(count,body.copy()); } } PK T(junior/core/BinaryInstruction.javaPK T(lv(( @junior/core/Config.javaPK T(VgBjunior/core/Control.javaPK T('NjJEjunior/core/DummyValues.javaPK T(m& *Fjunior/core/EnvironmentImpl.javaPK T('00bNjunior/core/EventData.javaPK T(*&Ojunior/core/EventDataImpl.javaPK T(]6VVVjunior/core/ExecContext.javaPK T(dƸ$\junior/core/Freezable.javaPK T(6a^junior/core/FreezableStar.javaPK T(|[[ajunior/core/Generate.javaPK T(5Odjunior/core/GenerateOrder.javaPK T(BJ(jjZejunior/core/IODecl.javaPK T(h3>gjunior/core/IODeclStatic.javaPK T(X--mjunior/core/If.javaPK T(\ /pjunior/core/Instant.javaPK T(P?rjunior/core/Instruction.javaPK T(BA{sjunior/core/Link.javaPK T((n[''ujunior/core/LinkStatic.javaPK T(xjunior/core/Local.javaPK T(w|junior/core/Loop.javaPK T(^ BB0~junior/core/Merge.javaPK T(j junior/core/MicroState.javaPK T(pkkjunior/core/Not.javaPK T( <&&Rjunior/core/Nothing.javaPK T(w?junior/core/Or.javaPK T(%'awwjunior/core/Presence.javaPK T(Ʈ!5junior/core/PrintInstruction.javaPK T(Yf( wjunior/core/Repeat.javaPK T(_H""junior/core/RepeatStatic.javaPK T(