updated to AM14, AM15
[fleet.git] / src / edu / berkeley / fleet / interpreter / Outbox.java
similarity index 73%
rename from src/edu/berkeley/fleet/Outbox.java
rename to src/edu/berkeley/fleet/interpreter/Outbox.java
index f6fa424..21914cf 100644 (file)
@@ -1,4 +1,6 @@
-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.Instruction;
 
 public abstract class Outbox extends InstructionPort {
 
@@ -11,7 +13,9 @@ public abstract class Outbox extends InstructionPort {
     /** number of tokens queued on the trigger input */
     private int     triggersReceived = 0;
 
-    protected Outbox(Ship ship, String name) {
+    private Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
+
+    protected Outbox(InterpreterShip ship, String name) {
         super(ship, name);
     }
 
@@ -24,17 +28,17 @@ public abstract class Outbox extends InstructionPort {
     }
 
     int register;
-    protected final boolean service(Instruction instruction) {
+    protected final boolean service(Instruction.Executable instruction) {
 
         // if no instruction waiting, do nothing
         if (instruction == null) return false;
 
         // check firing conditions
-        if (instruction.trigger && triggersReceived <= 0) return false;
+        if (instruction.tokenIn && triggersReceived <= 0) return false;
         if (instruction.dataIn && readyForItemFromShip) return false;
         
         // consume trigger
-        if (instruction.trigger) triggersReceived--;
+        if (instruction.tokenIn) triggersReceived--;
 
         // consume item
         if (instruction.dataIn) {
@@ -46,21 +50,21 @@ public abstract class Outbox extends InstructionPort {
         if (instruction.dataOut) {
 
             // if item to be transmitted, send it
-            send(instruction.destination.resolve(getShip().getFleet()), register);
-            if (instruction.ack)
+            send((InterpreterBenkoBox)instruction.dest, register);
+            if (instruction.tokenOut)
                 throw new RuntimeException("outboxes may not send acks!");
 
-        } else if (instruction.ack) {
+        } else if (instruction.tokenOut) {
 
             // if no item was sent, we might still send an ack
-            getFleet().sendToken(this, instruction.destination.resolve(getShip().getFleet()));
+            getInterpreter().sendToken(this, (InterpreterBenkoBox)instruction.dest);
         }
 
         return true;
     }
 
     /** this is invoked to transmit data; the subclass decides if it is a token or not */
-    protected abstract void send(Port port, int data);
+    protected abstract void send(InterpreterBenkoBox port, int data);
 
     /** subclass invokes this to add an item from the ship */
     protected final void addItemFromShip(int data) {