final pass to update instruction encoding; should now match the spec
[fleet.git] / src / edu / berkeley / fleet / interpreter / Interpreter.java
index 59b1575..ad49c87 100644 (file)
@@ -82,23 +82,21 @@ public class Interpreter extends Fleet implements Fleet.WithDynamicShips {
     public void dispatch(Instruction i, long address) {
         Log.dispatch(i);
         if (i instanceof Instruction.Executable) {
-            InterpreterBenkoBox sourceBenkoBox = (InterpreterBenkoBox)(((Instruction.Executable)i).benkoBox);
-            ((InstructionBenkoBox)sourceBenkoBox).addInstruction(((Instruction.Executable)i));
+            InterpreterPump sourcePump = (InterpreterPump)(((Instruction.Executable)i).pump);
+            ((InstructionPump)sourcePump).addInstruction(((Instruction.Executable)i));
 
-        } else if (i instanceof Instruction.Literal.CodeBagDescriptor) {
-            Instruction.Literal.CodeBagDescriptor cbd = (Instruction.Literal.CodeBagDescriptor)i;
+        } else if (i instanceof Instruction.CodeBagDescriptor) {
+            Instruction.CodeBagDescriptor cbd = (Instruction.CodeBagDescriptor)i;
             long absolute_cbd = ((cbd.offset+address) << 6) | cbd.size;
-            new Packet(this, null, (int)absolute_cbd, (InterpreterDestination)cbd.dest).send();
+            throw new RuntimeException();
+            //new Packet(this, null, (int)absolute_cbd, (InterpreterDestination)cbd.pump).send();
             
-        } else if (i instanceof Instruction.Literal.Absolute) {
-            new Packet(this, null,
-                       (int)((Instruction.Literal.Absolute)i).value,
-                       (InterpreterDestination)(((Instruction.Literal.Absolute)i).dest)).send();
-
+        } else if (i instanceof Instruction.UnClog) {
+            //FIXME
         } else if (i instanceof Instruction.Kill) {
-            InterpreterBenkoBox benkoBox = (InterpreterBenkoBox)(((Instruction.Kill)i).benkoBox);
-            ((InstructionBenkoBox)benkoBox).kill(((Instruction.Kill)i).count,
-                                             ((Instruction.Kill)i).killOnlyStandingInstructions);
+            InterpreterPump pump = (InterpreterPump)(((Instruction.Kill)i).pump);
+            ((InstructionPump)pump).kill(((Instruction.Kill)i).count, false);
+                   
 
         } else {
             throw new Error("unsupported: " + i.getClass().getName());
@@ -112,6 +110,9 @@ public class Interpreter extends Fleet implements Fleet.WithDynamicShips {
             Class c = Class.forName("edu.berkeley.fleet.interpreter."+shipType);
             Constructor con = c.getConstructor(new Class[] { Interpreter.class, String.class });
             InterpreterShip ret = (InterpreterShip)con.newInstance(new Object[] { this, shipname });
+            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("ships/"+shipType+".ship")));
+            ShipDescription sd = new ShipDescription(shipname, br);
+            ret.setShipDescription(sd);
             ships.put(shipname, ret);
             return ret;
         } catch (Exception e) {
@@ -137,18 +138,18 @@ public class Interpreter extends Fleet implements Fleet.WithDynamicShips {
     public void writeInstruction(DataOutputStream os, Instruction d) throws IOException { iie.writeInstruction(os, d); }
     public class InterpreterInstructionEncoder extends InstructionEncoder {
         public long getDestAddr(Destination box) { return ((InterpreterDestination)box).getDestAddr(); }
-        public long getBoxInstAddr(BenkoBox box) { return ((InterpreterBenkoBox)box).getDestAddr(); }
+        public long getBoxInstAddr(Pump box) { return ((InterpreterPump)box).getDestAddr(); }
         public Destination getDestByAddr(long dest) {
             for(Ship ship : Interpreter.this)
-                for(BenkoBox bb : ship.getBenkoBoxes())
+                for(Pump bb : ship.getPumps())
                     for(Destination d : bb.getDestinations())
                         if (getDestAddr(d)==dest)
                             return d;
             return null;
         }
-        public BenkoBox getBoxByInstAddr(long dest) {
+        public Pump getBoxByInstAddr(long dest) {
             for(Ship ship : Interpreter.this)
-                for(BenkoBox bb : ship.getBenkoBoxes())
+                for(Pump bb : ship.getPumps())
                     if (getBoxInstAddr(bb) == dest)
                         return bb;
             return null;
@@ -176,7 +177,7 @@ public class Interpreter extends Fleet implements Fleet.WithDynamicShips {
             pw.println("");
             pw.println("public class "+filename+" extends InterpreterShip {");
             pw.println("");
-            for(BenkoBoxDescription b : sd) {
+            for(PumpDescription b : sd) {
                 String name = b.getName();
                 pw.print("    ");
                 if ( b.isInbox()) pw.print("Inbox");
@@ -198,8 +199,8 @@ public class Interpreter extends Fleet implements Fleet.WithDynamicShips {
             pw.println("");
             pw.println("    public "+filename+"(Interpreter fleet, String name) {");
             pw.println("       super(fleet, name, \""+filename+"\");");
-            for(BenkoBoxDescription b : sd)
-                pw.println("       addBenkoBox(\""+b.getName()+"\", box_"+b.getName()+");");
+            for(PumpDescription b : sd)
+                pw.println("       addPump(\""+b.getName()+"\", box_"+b.getName()+");");
             pw.println("    }");
             pw.println("");
             pw.println(sd.getSection("fleeterpreter"));