add interpreter code and tests for loop counter instructions
[fleet.git] / src / edu / berkeley / fleet / assembler / Parser.java
index aa9bab4..0e58b3f 100644 (file)
@@ -266,9 +266,27 @@ public class Parser {
                     count = tt.size()==0 ? 1 : (int)number(tt.child(0));
                     cb.add(new Instruction.Kill(pump, count));
                     continue;
-                } else if ("massacre".equals(tt.head()))    {
+                } else if ("loop".equals(tt.head()))    {
+                    cb.add(new Instruction.Counter(pump, Instruction.Counter.LOOP_COUNTER, Instruction.Counter.DATA_LATCH));
+                    continue;
+                } else if ("load".equals(tt.head()) && "loop".equals(tt.child(0).head()))    {
+                    cb.add(new Instruction.Counter(pump, Instruction.Counter.DATA_LATCH, Instruction.Counter.LOOP_COUNTER));
+                    continue;
+                } else if ("load".equals(tt.head()) && "repeat".equals(tt.child(0).head()))    {
+                    cb.add(new Instruction.Counter(pump, Instruction.Counter.DATA_LATCH, Instruction.Counter.REPEAT_COUNTER));
+                    continue;
+                } else if ("with".equals(tt.head()) && "loop".equals(tt.child(0).head()))    {
+                    cb.add(new Instruction.Counter(pump, (int)number(tt.child(1)), Instruction.Counter.LOOP_COUNTER));
+                    continue;
+                } else if ("with".equals(tt.head()) && "repeat".equals(tt.child(0).head()))    {
+                    cb.add(new Instruction.Counter(pump, (int)number(tt.child(1)), Instruction.Counter.REPEAT_COUNTER));
+                    continue;
+                } else if ("massacre".equals(tt.head())) {
                     cb.add(new Instruction.Massacre(pump));
                     continue;
+                } else if ("decrement".equals(tt.head())) {
+                    cb.add(new Instruction.DecrLoop(pump));
+                    continue;
                 } else if ("literal".equals(tt.head())) {
                     long literal = 0;
                     if (tt.child(0).head().equals("CodeBagBody")) {