add interpreter code and tests for loop counter instructions
[fleet.git] / src / edu / berkeley / fleet / interpreter / Inbox.java
index d9b9f29..a00be0f 100644 (file)
@@ -1,10 +1,11 @@
 package edu.berkeley.fleet.interpreter;
 import edu.berkeley.sbp.util.ANSI;
 import edu.berkeley.fleet.api.*;
+import static edu.berkeley.fleet.util.BitManipulations.*;
 import java.util.*;
 
 /** this is a generic inbox which stores <32-bit items (tokens or data) */
-public class Inbox extends InstructionBenkoBox {
+public class Inbox extends InstructionPump {
 
     public boolean dataReadyForShip()            { return itemReadyForShip; }
     public Packet removePacketForShip()          { remove(); return register; }
@@ -40,15 +41,32 @@ public class Inbox extends InstructionBenkoBox {
 
     //////////////////////////////////////////////////////////////////////////////
 
+    protected void setDataLatch(long value) { register = new Packet(getInterpreter(), null, value, null); }
+    protected long peekDataLatch() { return register.value; }
+
     /** invoked by superclass */
-    protected final boolean service(Instruction.Executable instruction) {
+    protected final boolean service(Instruction.Executable instruction_) {
 
         // if data is stuck on itemPresentedToShip, wait for it to go somewhere before
         // considering additional instructions
         if (itemReadyForShip) return false;
 
         // if no instruction waiting, do nothing
-        if (instruction == null) return false;
+        if (instruction_ == null) return false;
+
+        if (clogged>0) return false;
+        if (instruction_ instanceof Instruction.Clog) { clogged++; return true; }
+        if (instruction_ instanceof Instruction.LocalLiteral) {
+            Instruction.LocalLiteral ll = (Instruction.LocalLiteral)instruction_;
+            long val = (register==null) ? 0 : register.value;
+            val =
+                ll.high
+                ? setField(36, 19, ll.literal, val)
+                : setField(18,  0, ll.literal, val);
+            register = new Packet(getInterpreter(), null, val, null);
+            return true;
+        }
+        Instruction.Move instruction = (Instruction.Move)instruction_;
 
         // check firing conditions
         if (instruction.tokenIn)