Source = Port
| CodeBag
| int
+ | ShipSpecific
Port = Port:: shipname "." portname
| ^"()"
name = Name:: [A-Za-z] [A-Za-z0-9\[\]_]**
index = "[" [0-9]+ "]" | [0-9]+
int = [\-0-9]++
+ShipSpecific = ShipSpecific:: "\"" ~[\"]++ "\""
// the following are not part of the official FLEET syntax and are
// specific to Adam's interpreter.
#import edu.berkeley.fleet.ships
+#ship math : ArithmeticShip
#ship helper : FifoShip
#ship source : FifoShip
#ship dest : FifoShip
// NOTE: "accept" is a synonym for "move" it is less confusing in the case
// of inboxes, but is otherwise identical
+"foo" -> math.din
//////////////////////////////////////////////////////////////////////////////
// The following three instructions simply produce one hundred "3"s
} else if ("CodeBagRef".equals(t.child(1).head())) {
cb.add(new Literal.CodeBagRef(name(t.child(1).child(0)), cb, d));
+ } else if ("ShipSpecific".equals(t.child(1).head())) {
+ cb.add(new Literal.ShipSpecific(string(t.child(1).child(0)), d, count));
+
} else {
PortReference s = portReference(t.child(1));
Instruction inst = null;
}
}
+ public static class ShipSpecific extends Dispatchable {
+ private String data;
+ private PortReference destination;
+ private int count;
+ public ShipSpecific(String data, PortReference destination, int count) {
+ this.data = data;
+ this.destination = destination;
+ this.count = count;
+ }
+ public void dispatch(Fleet fleet) {
+ for(int i=0; i<count; i++) {
+ Port port = destination.resolve(fleet);
+ Log.data("\""+data+"\"", null, port);
+ int dat = port.getShip().resolveShipSpecificConstant(data);
+ port.addDataFromFabric(dat);
+ }
+ }
+ public String toString() {
+ return ("\""+data+"\""+" -"+(count==1?"":("["+count+"]-"))+"> "+destination);
+ }
+ }
}
for(Port p : ports.values())
p.shutdown();
}
+
+ public int resolveShipSpecificConstant(String shipSpecificData) {
+ throw new RuntimeException("don't know how to resolve \""+shipSpecificData+"\"");
+ }
}
// here's some sample code snippets that should cover all the
// cases you need
+ if (!din.dataReadyForShip())
+ return;
+ /*
if (!tin.tokenReadyForShip())
return;
- tin.removeTokenForShip();
+ */
- if (!din.dataReadyForShip())
- return;
int mydat = din.removeDataForShip();
+ Log.println("ArithmeticShip: got a " + mydat);
+ /*
+ tin.removeTokenForShip();
+ */
+ /*
if (tout.readyForTokenFromShip())
tout.addTokenFromShip();
if (dout.readyForDataFromShip())
dout.addDataFromShip(123);
+ */
+ }
+ public int resolveShipSpecificConstant(String shipSpecificData) {
+ // normally you would want to parse shipSpecificData somehow
+ return shipSpecificData.length();
}
}