allow constants in literal clauses
authoradam <adam@megacz.com>
Sat, 25 Aug 2007 15:17:06 +0000 (16:17 +0100)
committeradam <adam@megacz.com>
Sat, 25 Aug 2007 15:17:06 +0000 (16:17 +0100)
src/edu/berkeley/fleet/assembler/Parser.java
src/edu/berkeley/fleet/assembler/fleet.g

index fbca63d..29fe1ad 100644 (file)
@@ -212,6 +212,26 @@ public class Parser {
         throw new RuntimeException("no more ships of type \""+shipType+"\"");
     }
 
+    private long parseSSL(Tree t) {
+        String shipType = name(t.child(0));
+        String portName = name(t.child(1));
+        Ship chosenship = null;
+        for(Ship ship : fleet) {
+            if (ship.getType().equals(shipType)) {
+                chosenship = ship;
+                break;
+            }
+        }
+        Pump chosenport = chosenship.getPump(portName);
+        Tree specs = t.child(2);
+        long literal = 0;
+        for(int i=0; i<specs.size(); i++) {
+            Tree tt = specs.child(i);
+            literal |= chosenport.resolveLiteral(string(tt));
+        }
+        return literal;
+    }
+
     void fillCodeBag(Tree<String> t, CodeBag cb) {
         if (t.head()==null) return;
         else if (t.head().equals("NamedCodeBag")) {
@@ -220,22 +240,7 @@ public class Parser {
                 fillCodeBag(statement, cb2);
 
         } else if (t.head().equals("ShipSpecificLiteral")) {
-            String shipType = name(t.child(0).child(0));
-            String portName = name(t.child(0).child(1));
-            Ship chosenship = null;
-            for(Ship ship : fleet) {
-                if (ship.getType().equals(shipType)) {
-                    chosenship = ship;
-                    break;
-                }
-            }
-            Pump chosenport = chosenship.getPump(portName);
-            Tree specs = t.child(0).child(2);
-            long literal = 0;
-            for(int i=0; i<specs.size(); i++) {
-                Tree tt = specs.child(i);
-                literal |= chosenport.resolveLiteral(string(tt));
-            }
+            long literal = parseSSL(t.child(0));
             cb.add(new Instruction.Literal.Absolute(portReference(t.child(1)), literal));
 
         } else if (t.head().equals("Literal")) {
@@ -295,6 +300,10 @@ public class Parser {
                     else if ("Take".equals(ttt.head()))    { dataIn = true; latch = true; }
                     else if ("SendTo".equals(ttt.head()))  { dataOut = true; dest = portReference(ttt.child(0)); }
                     else if ("LocalLiteral".equals(ttt.head()))  { localLiteral = true; literal = Long.parseLong(string(ttt.child(0))); }
+                    else if ("LocalLiteralConst".equals(ttt.head()))  {
+                        localLiteral = true;
+                        literal = parseSSL(ttt.child(0));
+                    }
                     else if ("DataOutDest".equals(ttt.head()))  { dataOutDest = true; }
                     else if ("Deliver".equals(ttt.head())) { dataOut = true;  }
                     else if ("Ack".equals(ttt.head()))     { tokenOut = true; dest = portReference(ttt.child(0)); }
index e4f5387..f4b1b4e 100644 (file)
@@ -30,13 +30,14 @@ Command         = Nop::      "nop"
                 | Kill::     "kill"
                 | KillStar:: "kill*"
                 | Wait::     "wait"
-                | Discard::  "dismiss"
-                | Take::     ("take"|"receive")
-                | SendTo::   "sendto" ws! Port
-                | DataOutDest::   "send"
-                | Deliver::  "deliver"
-                | LocalLiteral:: "literal" ws! int
-                | Ack::      "notify" ws! Port
+                | Discard::           "dismiss"
+                | Take::              ("take"|"receive")
+                | SendTo::            "sendto" ws! Port
+                | DataOutDest::       "send"
+                | Deliver::           "deliver"
+                | LocalLiteral::      "literal" ws! int
+                | LocalLiteralConst:: "literal" ws! SSL
+                | Ack::               "notify" ws! Port
 
 Source         = Port
                | ShipSpecific