cleaner allocation of ships when a single InterpreterFleet is reused
authormegacz <adam@megacz.com>
Thu, 8 Jan 2009 10:35:36 +0000 (02:35 -0800)
committermegacz <adam@megacz.com>
Thu, 8 Jan 2009 10:35:36 +0000 (02:35 -0800)
src/edu/berkeley/fleet/assembler/Parser.java

index 57a557d..38f6c04 100644 (file)
@@ -198,16 +198,7 @@ public class Parser {
         } else if (head.equals("#ship")) {
             String name = name(t.child(0));
             String type = string(t.child(1));
-            Ship ship = null;
-
-            if (fleet instanceof FleetWithDynamicShips) {
-                FleetWithDynamicShips dyn = ((FleetWithDynamicShips)fleet);
-                ship = dyn.createShip(type, name);
-                if (ship==null)
-                    throw new RuntimeException("couldn't find a ship called \""+type+"\"");
-            } else {
-                ship = allocateShip(type);
-            }
+            Ship ship = allocateShip(type);
             shipMap.put(name, ship);
 
         } else if (head.equals("#expect")) {
@@ -289,7 +280,15 @@ public class Parser {
                 allocated--;
             }
         }
-        throw new RuntimeException("no more ships of type \""+shipType+"\"");
+        if (fleet instanceof FleetWithDynamicShips) {
+            FleetWithDynamicShips dyn = ((FleetWithDynamicShips)fleet);
+            Ship ship = dyn.createShip(shipType, shipType+allocated);
+            if (ship==null)
+                throw new RuntimeException("couldn't find a ship called \""+shipType+"\"");
+            return ship;
+        } else {
+            throw new RuntimeException("no more ships of type \""+shipType+"\"");
+        }
     }
 
     private long parseSSL(Tree t) {