String subPort = t.size()<3 ? null : name(t.child(2));
Ship ship = shipMap.get(shipName);
if (ship==null) throw new RuntimeException("no such ship \""+shipName+"\"");
- BenkoBox ret = null;
+ Destination ret = null;
+ BenkoBox bb = null;
for(BenkoBox b : ship.getBenkoBoxes())
if (b.getName().equals(portName)) {
- ret = b;
+ bb = b;
}
- if (subPort != null)
- for(Destination d : ret.getDestinations())
- if (d.getDestinationName().equals(subPort))
- return d;
+ if (bb==null)
+ throw new RuntimeException("no such benkobox \""+portName+"\"");
+ if (subPort==null) subPort="";
+ for(Destination d : bb.getDestinations())
+ if (d.getDestinationName().equals(subPort))
+ return d;
if (ret==null)
throw new RuntimeException("no such benkobox \""+portName+"\" on ships of type \""+ship.getType()+"\"");
return ret;
}
+ BenkoBox benkoBox(Tree<String> t) {
+ if (!"Port".equals(t.head()) && !"SubPort".equals(t.head()) && !"ShipSpecificLiteral".equals(t.head())) return null;
+ String shipName = name(t.child(0));
+ String portName = name(t.child(1));
+ Ship ship = shipMap.get(shipName);
+ if (ship==null) throw new RuntimeException("no such ship \""+shipName+"\"");
+ BenkoBox bb = null;
+ for(BenkoBox b : ship.getBenkoBoxes())
+ if (b.getName().equals(portName))
+ return b;
+ throw new RuntimeException("no such benkobox \""+portName+"\"");
+ }
+
private HashMap<String,Integer> numAllocated = new HashMap<String,Integer>();
Ship allocateShip(String shipType) {
cb.add(new Instruction.Literal.CodeBagDescriptor(portReference(t.child(1)), cb2.getFakeAddress(), 0));
} else if (t.head().equals("Fiber")) {
- BenkoBox benkobox = (BenkoBox)portReference(t.child(0));
+ BenkoBox benkobox = (BenkoBox)benkoBox(t.child(0));
OUTER: for(Tree tt : t.child(1)) {
int count = 1;
public long getBoxInstAddr(BenkoBox box) { return ((SlipwayBenkoBox)box).instr_addr; }
public Destination getDestByAddr(long dest) {
for(Ship ship : Slipway.this)
- for(BenkoBox bb : ship.getBenkoBoxes()) {
- if (((SlipwayBenkoBox)bb).addr == dest)
- return bb;
+ for(BenkoBox bb : ship.getBenkoBoxes())
for(Destination d : bb.getDestinations())
if (getDestAddr(d)==dest)
return d;
- }
return null;
}
public BenkoBox getBoxByInstAddr(long dest) {