add interpreter code and tests for loop counter instructions
[fleet.git] / src / edu / berkeley / fleet / interpreter / Outbox.java
index 25b7f83..85b3926 100644 (file)
@@ -1,9 +1,13 @@
 package edu.berkeley.fleet.interpreter;
 import edu.berkeley.sbp.util.ANSI;
 import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.ies44.*;
+import edu.berkeley.sbp.util.*;
+import edu.berkeley.fleet.util.*;
+import static edu.berkeley.fleet.util.BitManipulations.*;
 import edu.berkeley.fleet.api.Instruction;
 
-public class Outbox extends InstructionBenkoBox {
+public class Outbox extends InstructionPump {
 
     /** are we ready to accept another item from the ship? */
     private boolean readyForDataFromShip = false;
@@ -23,7 +27,21 @@ public class Outbox extends InstructionBenkoBox {
     public Outbox(InterpreterShip ship, String name) { this(ship, name, new String[] { "" }); }
     public Outbox(InterpreterShip ship, String name, String[] ports) { super(ship, name, ports); }
 
-    protected final boolean service(Instruction.Executable instruction) {
+    protected void setDataLatch(long value) { register = value; }
+    protected long peekDataLatch() { return register; }
+
+    protected final boolean service(Instruction.Executable instruction_) {
+        if (clogged>0) return false;
+        if (instruction_ instanceof Instruction.Clog) { clogged++; return true; }
+        if (instruction_ instanceof Instruction.LocalLiteral) {
+            Instruction.LocalLiteral ll = (Instruction.LocalLiteral)instruction_;
+            register =
+                ll.high
+                ? setField(36, 19, ll.literal, register)
+                : setField(18,  0, ll.literal, register);
+            return true;
+        }
+        Instruction.Move instruction = (Instruction.Move)instruction_;
 
         // if no instruction waiting, do nothing
         if (instruction == null) return false;
@@ -47,14 +65,33 @@ public class Outbox extends InstructionBenkoBox {
         if (instruction.dataOut) {
 
             // if item to be transmitted, send it
-            new Packet(getInterpreter(), this, register, (InterpreterDestination)instruction.dest).send();
+            InterpreterDestination dest = (InterpreterDestination)instruction.dest;
+            if (instruction.dataOutDest) {
+                // FIXME: still not supported
+                long bits = BitManipulations.getField(InstructionEncoder.OFFSET_PUMP_ADDR+InstructionEncoder.WIDTH_PUMP_ADDR-1,
+                                                      InstructionEncoder.OFFSET_PUMP_ADDR,
+                                                      register);
+                getInterpreter().dispatch(((Interpreter)getInterpreter()).iie.readInstruction(register), bits);
+                /*
+                dest = (InterpreterDestination)(((Interpreter)getInterpreter()).iie.getDestByAddr(bits));
+                if (dest == null) {
+                    if (pump != null) {
+                        
+                Pump pump = ((Interpreter)getInterpreter()).iie.getDestByInstAddr(bits);
+                    }
+                }
+                */
+                //throw new RuntimeException();
+            } else {
+                new Packet(getInterpreter(), this, register, dest).send();
+            }
             if (instruction.tokenOut)
                 throw new RuntimeException("outboxes may not send acks!");
 
         } else if (instruction.tokenOut) {
 
             // if no item was sent, we might still send an ack
-            new Packet(getInterpreter(), this, 0, (InterpreterBenkoBox)instruction.dest).send();
+            new Packet(getInterpreter(), this, 0, (InterpreterDestination)instruction.dest).send();
         }
 
         return true;