From 1bd87628c05e90b85a212816bfd7c33c5dbc2eb2 Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 3 Nov 2008 11:17:01 +0100 Subject: [PATCH] add Context.allocateShip() --- src/edu/berkeley/fleet/ir/Context.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/edu/berkeley/fleet/ir/Context.java b/src/edu/berkeley/fleet/ir/Context.java index 83a2806..616d25b 100644 --- a/src/edu/berkeley/fleet/ir/Context.java +++ b/src/edu/berkeley/fleet/ir/Context.java @@ -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 allocatedShips = new HashSet(); + + 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. -- 1.7.10.4