add Context.allocateShip()
authoradam <adam@megacz.com>
Mon, 3 Nov 2008 10:17:01 +0000 (11:17 +0100)
committeradam <adam@megacz.com>
Mon, 3 Nov 2008 10:17:01 +0000 (11:17 +0100)
src/edu/berkeley/fleet/ir/Context.java

index 83a2806..616d25b 100644 (file)
@@ -46,6 +46,23 @@ public class Context {
     public final Fleet fleet;
     public Context(Fleet fleet) { this.fleet = fleet; }
 
+    // FIXME: ability for a group of Contexts to share an "allocation
+    // pool" because they will run concurrently.
+    public HashSet<Ship>             allocatedShips       = new HashSet<Ship>();
+
+    public Ship allocateShip(String name) {
+        for(int i=0; ; i++) {
+            Ship ship = fleet.getShip(name, i);
+            if (ship==null)
+                throw new RuntimeException("no more ships of type " + name);
+            if (allocatedShips.contains(ship)) continue;
+            allocatedShips.add(ship);
+            return ship;
+        }
+    }
+
+    // FIXME: is it legitimate to send a torpedo to a count==1 loop?
+    // FIXME: is it legitimate to send a torpedo to a count>1  loop?
     /**
      *
      *  A helper class for building loops of instructions.