PK (junior/PK (Kttjunior/Action.javapackage junior; public interface Action extends java.io.Serializable { public void execute(Environment env); } PK (v)Fzzjunior/BooleanWrapper.javapackage junior; public interface BooleanWrapper extends java.io.Serializable { boolean evaluate(Environment env); } PK (byMlljunior/Configuration.javapackage junior; public interface Configuration extends java.io.Serializable { Configuration copy (); }PK (- "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 (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 (?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 (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 (`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 (%߆junior/Identifier.javapackage junior; public interface Identifier extends java.io.Serializable { boolean equals(Object object); public int hashCode(); }PK ( qjunior/IdentifierWrapper.javapackage junior; public interface IdentifierWrapper extends java.io.Serializable { Identifier evaluate(Environment env); } PK (,!I{{junior/IntegerWrapper.javapackage junior; public interface IntegerWrapper extends java.io.Serializable { public int evaluate(Environment env); } PK (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 (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 (!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 (:syyjunior/ObjectWrapper.javapackage junior; public interface ObjectWrapper extends java.io.Serializable { Object evaluate(Environment env); } PK (M``junior/Program.javapackage junior; public interface Program extends java.io.Serializable { Program copy (); }PK (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 ( kkjunior/SyncMachine.javapackage junior; public interface SyncMachine extends Machine { // generate is now for next instant only } PK (oqrrjunior/UnSyncMachine.javapackage junior; public interface UnSyncMachine extends Machine { // generate is for current or next instant } PK ( junior/core/PK ()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 (Wjunior/core/Atom.javapackage junior.core; import junior.Action; public class Atom extends Instruction { final public Action action; public boolean terminated = false; public Atom(Action action){ this.action = action; } public void reset(){ terminated = false; } public String toString(){ return terminated ? PrintInstruction.Nothing() : PrintInstruction.Action(action); } public boolean equals(Instruction inst){ return super.equals(inst) && action == ((Atom)inst).action && terminated == ((Atom)inst).terminated; } public byte rewrite(){ if (terminated == false){ action.execute(env); terminated = true; } return TERM; } } PK (9--junior/core/Await.javapackage junior.core; import junior.*; public class Await extends Instruction { public Config config; public boolean terminated = false; public Await(Configuration config){ this.config = (Config)config; } public String toString(){ return (terminated) ? PrintInstruction.Nothing() : PrintInstruction.Await(""+config); } public void reset(){ terminated = false; config.reset(); } public boolean equals(Instruction inst){ return super.equals(inst) && terminated == ((Await)inst).terminated && config.equals(((Await)inst).config); } public byte rewrite(){ if (terminated) return TERM; if (config.sat(env)){ terminated = true; return env.eoi ? STOP : TERM; } if (config.unsat(env)) return STOP; return SUSP; } public Object clone(){ Await res = (Await)super.clone(); res.config = (Config)config.copy(); return res; } public Instruction residual(){ if (terminated) return new Nothing(); else return (Instruction)clone(); } } PK (_)junior/core/BasicContext.javapackage junior.core; import junior.*; public class BasicContext implements Flags, UnSyncMachine { public boolean terminated = false; public Instant instant; public EnvironmentImpl env; public Program toAdd = Jr.Nothing(); public boolean somethingToAdd = false; // constructor public BasicContext(Program program){ buildEnvironment(); this.instant = new Instant(program); instant.bind(env); } // 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.body = (Instruction)Jr.Par(toAdd,instant.body); instant.bind(env); toAdd = Jr.Nothing(); terminated = 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(); if (terminated == false){ byte res = instant.rewrite(); env.newInstant(); terminated = (TERM == res); } return terminated; } }PK (#+,,"junior/core/BinaryInstruction.javapackage junior.core; abstract public class BinaryInstruction extends Instruction { public Instruction left, right; public BinaryInstruction(junior.Program left,junior.Program right){ this.left = (Instruction)left; this.right = (Instruction)right; } public void bind(EnvironmentImpl e){ super.bind(e); left.bind(e); right.bind(e); } public void reset(){ left.reset(); right.reset(); } public boolean equals(Instruction inst){ return super.equals(inst) && left.equals(((BinaryInstruction)inst).left) && right.equals(((BinaryInstruction)inst).right); } public Object clone(){ BinaryInstruction res = (BinaryInstruction)super.clone(); res.left = (Instruction)left.clone(); res.right = (Instruction)right.clone(); return res; } } PK (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 (Zjqqjunior/core/Control.javapackage junior.core; import junior.*; public class Control extends UnaryInstruction { public Presence presence; public Control(Presence presence, Program body){ super(body); this.presence = presence; } public void reset(){ super.reset(); presence.reset(); } public String toString(){ return PrintInstruction.Control(""+presence,""+body); } public boolean equals(Instruction inst){ return super.equals(inst) && presence.equals(((Control)inst).presence); } public byte rewrite(){ if (presence.sat(env)) return body.rewrite(); if (presence.unsat(env)) return STOP; return SUSP; } public Object clone(){ Control res = (Control)super.clone(); res.presence = (Presence)presence.copy(); return res; } public Instruction residual(){ return new Control((Presence)presence.copy(),body.residual()); } }PK ('Njjunior/core/DummyValues.javapackage junior.core; public class DummyValues implements java.io.Serializable { public static DummyValues NONE = new DummyValues(), NULL = new DummyValues(); }PK (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 ('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 (*&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 (]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 (TTTjunior/core/Flags.javapackage junior.core; public interface Flags { byte STOP = 0, TERM = 1, SUSP = 2; } PK (֬cjunior/core/Freezable.javapackage junior.core; import junior.*; public class Freezable extends UnaryInstruction { public Presence presence; public boolean bodyStopped = false, terminated = false; public Freezable(Presence presence,Program body){ super(body); this.presence = presence; } public void reset(){ super.reset(); presence.reset(); bodyStopped = terminated = false; } public String toString(){ return PrintInstruction.Freezable(""+presence,""+body); } public boolean equals(Instruction inst){ return super.equals(inst) && bodyStopped == ((Freezable)inst).bodyStopped && terminated == ((Freezable)inst).terminated && presence.equals(((Freezable)inst).presence); } public byte rewrite(){ if (terminated) return TERM; if (bodyStopped) return rewriteStar(); byte s = body.rewrite(); if (STOP != s) return s; bodyStopped = true; return rewriteStar(); } public byte rewriteStar(){ if (presence.sat(env)){ env.storeFrozen(presence.event,body.residual()); terminated = true; return (env.eoi) ? STOP : TERM; } if (presence.unsat(env)){ bodyStopped = false; return STOP; } return SUSP; } public Object clone(){ Freezable res = (Freezable)super.clone(); res.presence = (Presence)presence.copy(); return res; } public Instruction residual(){ if (terminated) return new Nothing(); else return new Freezable((Presence)presence.copy(),body.residual()); } } PK (>Oqjunior/core/Generate.javapackage junior.core; import junior.*; public class Generate extends Instruction { final public IdentifierWrapper idwrap; final public ObjectWrapper objwrap; public boolean terminated = false; public Generate(IdentifierWrapper idwrap, ObjectWrapper objwrap){ this.idwrap = idwrap; this.objwrap = objwrap; } public void reset(){ terminated = false; } public String toString(){ return terminated ? PrintInstruction.Nothing() : PrintInstruction.Generate(idwrap); } public boolean equals(Instruction inst){ return super.equals(inst) && terminated == ((Generate)inst).terminated && idwrap == ((Generate)inst).idwrap && objwrap == ((Generate)inst).objwrap; } public byte rewrite(){ if (terminated == false){ env.generate(idwrap.evaluate(env),objwrap.evaluate(env)); terminated = true; } return TERM; } public Instruction residual(){ if (terminated) return new Nothing(); else return (Instruction)clone(); } } PK (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 ((2bjunior/core/IODecl.javapackage junior.core; import junior.*; public class IODecl extends Local { final public IdentifierWrapper wrapper; public boolean evaluated = false; public Identifier extern; public IODecl(IdentifierWrapper wrapper, Identifier local, EventData localEvent, Program body){ super(local,localEvent,body); this.wrapper = wrapper; } public IODecl(IdentifierWrapper wrapper, Identifier local, Program body){ this(wrapper,local,new EventDataImpl(),body); } public void reset(){ super.reset(); evaluated = false; } public String toString(){ return PrintInstruction.IODecl(wrapper,""+local,""+body); } public boolean equals(Instruction inst){ return super.equals(inst) && wrapper == ((IODecl)inst).wrapper && (!evaluated || extern.equals(((IODecl)inst).extern)); } protected void swapIn(){ if (evaluated == false){ extern = wrapper.evaluate(env); evaluated = true; } if (extern.equals(local)) return; save = env.getEventData(local); env.eventSet.put(local,env.getEventData(extern)); } protected void swapOut(){ if (extern.equals(local)) return; env.eventSet.put(extern,env.getEventData(local)); localEvent = env.getEventData(local); env.eventSet.put(local,save); } public Object clone(){ IODecl res = (IODecl)super.clone(); if (localEvent != null) res.localEvent = (EventData)localEvent.copy(); if (save != null) res.save = (EventData)save.copy(); return res; } public Instruction residual(){ if (evaluated == false) return (Instruction)clone(); return new IODecl(wrapper,local,localEvent.copy(),body.residual()); } } PK ($junior/core/If.javapackage junior.core; import junior.*; public class If extends BinaryInstruction { final public BooleanWrapper wrapper; public boolean condEvaluated = false; public boolean condition; public If(BooleanWrapper wrapper,Program thenInst, Program elseInst){ super(thenInst,elseInst); this.wrapper = wrapper; } public void reset(){ super.reset(); condEvaluated = false; } public String toString(){ return PrintInstruction.If(wrapper,""+left,""+right); } public boolean equals(Instruction inst){ return super.equals(inst) && wrapper == ((If)inst).wrapper && (!condEvaluated || (condition == ((If)inst).condition)); } public byte rewrite(){ if(condEvaluated == false){ condition = wrapper.evaluate(env); condEvaluated = true; } return (condition ? left : right).rewrite(); } public Instruction residual(){ if(condEvaluated == false) return (Instruction)clone(); return (condition ? left : right).residual(); } } PK (Zqjunior/core/Instant.javapackage junior.core; import junior.Program; public class Instant extends UnaryInstruction { public Instant(Program body){ super(body); } public byte rewrite(){ byte s = body.rewrite(); if (SUSP != s) return s; if (env.move) env.move = false; else env.eoi = true; return rewrite(); } public Instruction residual(){ return new Instant(body.residual()); } } PK (_A'junior/core/Instruction.javapackage junior.core; import junior.*; abstract public class Instruction implements Flags, Program, Cloneable, java.io.Serializable { public EnvironmentImpl env; public void bind(EnvironmentImpl env){ this.env = env; } abstract public byte rewrite(); abstract public void reset(); public boolean equals(Instruction inst){ return getClass() == inst.getClass(); } public Object clone(){ try{ return (Instruction)super.clone(); } catch(CloneNotSupportedException e){ throw new InternalError(""+e); } } public Program copy(){ return (Instruction)clone(); } public Instruction residual(){ return (Instruction)clone(); } } PK (?junior/core/Link.javapackage junior.core; import junior.*; public class Link extends UnaryInstruction { final public ObjectWrapper wrapper; public boolean evaluated = false; public Object self; public Link(ObjectWrapper wrapper, Program body){ super(body); this.wrapper = wrapper; } public void reset(){ super.reset(); evaluated = false; } public String toString(){ return PrintInstruction.Link(wrapper,""+body); } public boolean equals(Instruction inst){ return super.equals(inst) && wrapper == ((Link)inst).wrapper && (!evaluated || self == ((Link)inst).self); } public byte rewrite(){ if (evaluated == false){ self = wrapper.evaluate(env); evaluated = true; } Object save = env.linkedObject; env.linkedObject = self; byte res = body.rewrite(); env.linkedObject = save; return res; } public Instruction residual(){ if (evaluated == false) return (Instruction)clone(); return new Link(wrapper,body.residual()); } }PK (/Tjunior/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 boolean equals(Instruction inst){ return super.equals(inst) && local.equals(((Local)inst).local); } protected void swapIn(){ save = env.getEventData(local); env.eventSet.put(local,localEvent); } protected void swapOut(){ localEvent = env.getEventData(local); env.eventSet.put(local,save); } public byte rewrite(){ swapIn(); byte res = body.rewrite(); swapOut(); return res; } public Object clone(){ Local res = (Local)super.clone(); if (localEvent != null) res.localEvent = (EventData)localEvent.copy(); if (save != null) res.save = (EventData)save.copy(); return res; } public Instruction residual(){ return new Local(local,localEvent.copy(),body.residual()); } } PK (wAjunior/core/Loop.javapackage junior.core; import junior.Program; public class Loop extends UnaryInstruction { public Loop(Program body){ super(body); } public String toString(){ return PrintInstruction.Loop(""+body); } public byte rewrite(){ byte s = body.rewrite(); if (s != TERM) return s; body.reset(); return rewrite(); } public Instruction residual(){ Instruction newBody = (Instruction)body.clone(); newBody.reset(); return new Seq(body.residual(),new Loop(newBody)); } } PK (i|junior/core/Merge.javapackage junior.core; import junior.Program; public class Merge extends BinaryInstruction { public byte leftFlag = SUSP, rightFlag = SUSP; public Merge(Program left,Program right){ super(left,right); } public void reset(){ super.reset(); leftFlag = rightFlag = SUSP; } public String toString(){ return PrintInstruction.Merge(""+left,""+right); } public boolean equals(Instruction inst){ return super.equals(inst) && leftFlag == ((Merge)inst).leftFlag && rightFlag == ((Merge)inst).rightFlag; } public byte result(){ byte b = SUSP; if(leftFlag!=SUSP && rightFlag!=SUSP){ b = (leftFlag==TERM && rightFlag==TERM) ? TERM : STOP; if (leftFlag==STOP) leftFlag = SUSP; if (rightFlag==STOP) rightFlag = SUSP; } return b; } public byte rewrite(){ if (leftFlag == SUSP && rightFlag != SUSP) leftFlag = left.rewrite(); else if (rightFlag == SUSP && leftFlag != SUSP) rightFlag = right.rewrite(); else{ leftFlag = left.rewrite(); rightFlag = right.rewrite(); } return result(); } public Instruction residual(){ return new Merge(left.residual(),right.residual()); } } PK (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 (9w>(junior/core/Nothing.javapackage junior.core; public class Nothing extends Instruction { public void reset(){} public String toString(){ return PrintInstruction.Nothing(); } public byte rewrite(){ return TERM; } } PK (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 (%'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 (Ʈ!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 (vԂttjunior/core/Repeat.javapackage junior.core; import junior.*; public class Repeat extends UnaryInstruction { final public IntegerWrapper wrapper; public boolean evaluated = false; public int num, count; public Repeat(IntegerWrapper wrapper,Program body){ super(body); this.wrapper = wrapper; } public void reset(){ super.reset(); evaluated = false; } public String toString(){ return PrintInstruction.Repeat(num,""+body); } public boolean equals(Instruction inst){ return super.equals(inst) && wrapper == ((Repeat)inst).wrapper && (!evaluated || (count == ((Repeat)inst).count && num == ((Repeat)inst).num)); } public byte rewrite(){ if(evaluated == false){ num = count = wrapper.evaluate(env); evaluated = true; } if (num <= 0) return TERM; byte s = body.rewrite(); if (s != TERM) return s; body.reset(); num = num-1; return rewrite(); } public Instruction residual(){ if (evaluated == false) return (Instruction)clone(); return new Seq(body.residual(), new Repeat(new ConstIntegerWrapper(num-1),(Instruction)body.clone())); } } PK (ߋjunior/core/Seq.javapackage junior.core; import junior.Program; public class Seq extends BinaryInstruction { public boolean leftTerminated = false; public Seq(Program left,Program right){ super(left,right); } public void reset(){ super.reset(); leftTerminated = false; } public String toString(){ return (leftTerminated) ? (""+right) : PrintInstruction.Seq(""+left,""+right); } public boolean equals(Instruction inst){ return (getClass() == inst.getClass()) && (leftTerminated == ((Seq)inst).leftTerminated) && (right.equals(((Seq)inst).right)) && (leftTerminated || left.equals(((Seq)inst).left)); } public byte rewrite(){ if (leftTerminated) return right.rewrite(); byte s = left.rewrite(); if (s == TERM){ leftTerminated = true; return right.rewrite(); } return s; } public Instruction residual(){ if(leftTerminated) return right.residual(); else return new Seq(left.residual(),(Instruction)right.clone()); } } PK (/MMjunior/core/Stop.javapackage junior.core; public class Stop extends Instruction { public boolean terminated = false; public void reset(){ terminated = false; } public String toString(){ return (terminated) ? PrintInstruction.Nothing() : PrintInstruction.Stop(); } public boolean equals(Instruction inst){ return super.equals(inst) && terminated == ((Stop)inst).terminated; } public byte rewrite(){ if (terminated) return TERM; terminated = true; return STOP; } public Instruction residual(){ if (terminated) return new Nothing(); else return new Stop(); } } PK (D^^!junior/core/UnaryInstruction.javapackage junior.core; import junior.Program; abstract public class UnaryInstruction extends Instruction { public Instruction body; public UnaryInstruction(Program body){ this.body = (Instruction)body; } public void reset(){ body.reset(); } public void bind(EnvironmentImpl e){ super.bind(e); body.bind(e); } public boolean equals(Instruction inst){ return super.equals(inst) && body.equals(((UnaryInstruction)inst).body); } public Object clone(){ UnaryInstruction res = (UnaryInstruction)super.clone(); res.body = (Instruction)body.clone(); return res; } } PK (Sjunior/core/Until.javapackage junior.core; import junior.*; public class Until extends BinaryInstruction { public Config config; public boolean runHandler = false, bodyStopped = false; public Until(Configuration config,Program body, Program handler){ super(body,handler); this.config = (Config)config; } public void reset(){ super.reset(); config.reset(); runHandler = bodyStopped = false; } public String toString(){ return PrintInstruction.Until(""+config,""+left,""+right); } public boolean equals(Instruction inst){ return super.equals(inst) && runHandler == ((Until)inst).runHandler && bodyStopped == ((Until)inst).bodyStopped && config.equals(((Until)inst).config); } public byte rewrite(){ if (runHandler) return right.rewrite(); if (bodyStopped) return rewriteStar(); byte s = left.rewrite(); if (STOP != s) return s; bodyStopped = true; return rewriteStar(); } public byte rewriteStar(){ if (config.sat(env)){ runHandler = true; return (env.eoi) ? STOP : right.rewrite(); } if (config.unsat(env)){ bodyStopped = false; return STOP; } return SUSP; } public Object clone(){ Until res = (Until)super.clone(); res.config = (Config)config.copy(); return res; } public Instruction residual(){ if(runHandler) return right.residual(); return new Until(config.copy(),left.residual(),(Instruction)right.clone()); } } PK (|ZZjunior/core/When.javapackage junior.core; import junior.*; public class When extends BinaryInstruction { public Config config; public boolean evaluated = false, value = false; public When(Configuration config,Program thenInst, Program elseInst){ super(thenInst,elseInst); this.config = (Config)config; } public void reset(){ super.reset(); config.reset(); evaluated = false; } public String toString(){ return PrintInstruction.When(""+config,""+left,""+right); } public boolean equals(Instruction inst){ return super.equals(inst) && evaluated == ((When)inst).evaluated && (!evaluated || (value == ((When)inst).value)) && config.equals(((When)inst).config); } public byte rewrite(){ if (evaluated) return (value ? left : right).rewrite(); if (config.sat(env)){ evaluated = true; value = true; if (env.eoi) return STOP; else return left.rewrite(); } if (config.unsat(env)){ evaluated = true; value = false; if (env.eoi) return STOP; else return right.rewrite(); } return SUSP; } public Object clone(){ When res = (When)super.clone(); res.config = (Config)config.copy(); return res; } public Instruction residual(){ if(evaluated == false) return (Instruction)clone(); return (value ? left : right).residual(); } } PK (junior/extended/PK (V["PPjunior/extended/Macro.javapackage junior.extended; import junior.Program; import junior.core.*; abstract public class Macro extends UnaryInstruction { public Macro(Program body){ super(body); } public byte rewrite(){ return body.rewrite(); } public Program copy(){ return body.copy(); } public Instruction residual(){ return body.residual(); } } PK (P+j11junior/extended/Print.javapackage junior.extended; import junior.*; import junior.core.*; public class Print implements Action { public String msg; public Print(String msg){ this.msg = msg; } public String toString(){ return PrintInstruction.Print(msg); } public void execute(Environment env){ System.out.print(msg); } } PK (junior/PK (Ktt%junior/Action.javaPK (v)Fzzjunior/BooleanWrapper.javaPK (byMll{junior/Configuration.javaPK (- "junior/ConstBooleanWrapper.javaPK (nȭ("tjunior/ConstIdentifierWrapper.javaPK (?T?junior/ConstIntegerWrapper.javaPK (4\#junior/ConstObjectWrapper.javaPK (`q  ~junior/Environment.javaPK (%߆junior/Identifier.javaPK ( q{ junior/IdentifierWrapper.javaPK (,!I{{7 junior/IntegerWrapper.javaPK (S۪II junior/Jr.javaPK (auu6 _junior/JrBase.javaPK (!"*junior/Machine.javaPK (:syy ,junior/ObjectWrapper.javaPK (M``,junior/Program.javaPK (FZa-junior/StringIdentifier.javaPK ( kk5/junior/SyncMachine.javaPK (oqrr/junior/UnSyncMachine.javaPK ( ~0junior/core/PK ()a0junior/core/And.javaPK (W4junior/core/Atom.javaPK (9--o7junior/core/Await.javaPK (_);junior/core/BasicContext.javaPK (#+,,"Ajunior/core/BinaryInstruction.javaPK (lv((:Ejunior/core/Config.javaPK (ZjqqGjunior/core/Control.javaPK ('Nj>Kjunior/core/DummyValues.javaPK (m& Ljunior/core/EnvironmentImpl.javaPK ('00VTjunior/core/EventData.javaPK (*&Ujunior/core/EventDataImpl.javaPK (]6VV\junior/core/ExecContext.javaPK (TTTbjunior/core/Flags.javaPK (֬cbjunior/core/Freezable.javaPK (>Oqhjunior/core/Generate.javaPK (5mjunior/core/GenerateOrder.javaPK ((2b njunior/core/IODecl.javaPK ($&ujunior/core/If.javaPK (ZqCyjunior/core/Instant.javaPK (_A'{junior/core/Instruction.javaPK (?}junior/core/Link.javaPK (/T,junior/core/Local.javaPK (wA&junior/core/Loop.javaPK (i|hjunior/core/Merge.javaPK (pkkZjunior/core/Not.javaPK (9w>(junior/core/Nothing.javaPK (w?junior/core/Or.javaPK (%'awwʕjunior/core/Presence.javaPK (Ʈ!xjunior/core/PrintInstruction.javaPK (vԂttjunior/core/Repeat.javaPK (ߋcjunior/core/Seq.javaPK (/MMjunior/core/Stop.javaPK (D^^!junior/core/UnaryInstruction.javaPK (Sjunior/core/Until.javaPK (|ZZjunior/core/When.javaPK ()junior/extended/PK (V["PPWjunior/extended/Macro.javaPK (P+j11߼junior/extended/Print.javaPK;; H