// the grammar. An equivalent lex+yacc grammar and support code would
// be several times as long.
-w = " " | "\n" | "\r"
-ws = w**
- | w** "//" (~[\n])*! "\n" ws!
+Comment = "//" ~[\n]* "\n"
+ | "/*" ~[\n]* "*/"
+ws = ([\r\n ] | Comment)* -> ~[\r\n ]
s = ws! Program ws!
Program = Program::
Port = Port:: shipname "." portname
| ^"()"
-CodeBagBody = Statement +/ (ws (";" ws)?!)
+CodeBagBody = Statement */ (ws (";" ws)?!)
CodeBag = CodeBagRef:: CodeBagName
| AnonymousCodeBag:: "{" CodeBagBody "}" /ws
// issue here; this is just setup for the rest of the code.
3 -> helper.in
- copy helper.out -[10]-> source.in
+ copy helper.out -[10]-> source.in
discard helper.out -> ()
// which are sent back to the source outbox
nop+ack dest.in -[3]-> source.out
- accept+ack dest.in -[10]-> source.out
+ accept+ack dest.in -[7]-> source.out
+ accept dest.in -[3]-> source.out
nop+ack dest.in -> fetch.release // then release the fetch
accept dest.in -[*]-> () // and return the fabric to normal
+++ /dev/null
-#import edu.berkeley.fleet.ships
-
-#memory { 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
- 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
- 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
- 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
- 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- }
-
-#ship fifo : FifoShip
-
-#ship halt : HaltShip
-#ship fetch : FetchShip
-#ship tokensource : TokenSourceShip
-
-
-
-{ tokensource.out -> halt.in } -> fetch.codebag
-tokensource.out -> fetch.release
-
public void go() {
while(!halt)
for(Ship ship : ships.values())
- ship._service();
+ for(int j=0; j<10; j++)
+ ship._service();
+
+ // run the ships a bit longer for good measure
+ for(int i=0; i<100; i++)
+ for(Ship ship : ships.values())
+ for(int j=0; j<10; j++)
+ ship._service();
+
+ // check the state of the ships
+ for(Ship ship : ships.values())
+ ship.shutdown();
+
+ Log.println(Log.yellow(" DONE: ====== FLEET is halted. Have a nice day. ======"));
}
public void dumpMem() {
PortReference d = portReference(t.child(3));
if (t.child(1).head() == null) {
int literal = Integer.parseInt(string(t.child(1)));
- cb.add(new Literal.LiteralDatum(literal, d, false));
+ cb.add(new Literal.LiteralDatum(literal, d, false, count));
} else if ("AnonymousCodeBag".equals(t.child(1).head())) {
CodeBag cb3 = new CodeBag(cb, null);
public class InboxPort extends InstructionPort {
+ public static final Instruction defaultInstruction =
+ new Instruction(null, null, Integer.MAX_VALUE, TAKE, false, false, true);
+
public InboxPort(Ship ship, String name) {
super(ship, name);
// default standing move
- addInstruction(new Instruction(null,
- null,
- Integer.MAX_VALUE,
- TAKE,
- false,
- false,
- true
- ));
+ addInstruction(defaultInstruction);
}
// data in from the switch fabric
if (tokenDestination != null) {
Log.token(this, tokenDestination);
tokenDestination.addToken();
+ tokenDestination = null;
}
return dataOut;
}
case TAKE:
dataOut = dataIn.remove();
break;
+
}
if (instruction.dataOut) {
}
return true;
}
+
+ public void shutdown() {
+ if (!empty)
+ Log.println(Log.red(" WARNING: a datum ("+dataOut+") was left in inbox " + this + " -- the ship has not consumed it"));
+
+ if (dataIn.size() > 0) {
+ Log.println(Log.red(" WARNING: you left data on the input to inbox " + this + ":"));
+ for(int i : dataIn)
+ Log.println(" " + i);
+ }
+ super.shutdown(true);
+ }
}
// inherited from Port
public abstract void addData(int data);
- private Instruction currentlyExecuting = null;
- private Queue<Instruction> instructions = new LinkedList<Instruction>();
- private int currentlyExecutingCount;
+ Instruction currentlyExecuting = null;
+ Queue<Instruction> instructions = new LinkedList<Instruction>();
+ int currentlyExecutingCount;
+
+
+ protected void shutdown(boolean leaveAsInbox) {
+ if (leaveAsInbox) {
+ if (currentlyExecuting == null) {
+ Log.println(Log.red(" WARNING: you did not leave a standing move on inbox-port " + this));
+ return;
+ } else {
+ if (currentlyExecuting.count != Integer.MAX_VALUE
+ || currentlyExecuting.dataIn != Instruction.IgnoreCopyTake.TAKE
+ || currentlyExecuting.ack
+ || currentlyExecuting.trigger
+ || !currentlyExecuting.dataOut) {
+ Log.println(Log.red(" WARNING: you did not leave the correct standing move on inbox-port " + this)+
+ "\n found: " + currentlyExecuting
+ );
+ return;
+ }
+ }
+ currentlyExecuting = null;
+ }
+ if (currentlyExecuting != null || instructions.size() > 0) {
+ Log.println(Log.red(" WARNING: you left instructions on the instruction queue of port " + this + "; they are:"));
+ if (currentlyExecuting != null)
+ Log.println(" " + currentlyExecuting);
+ for(Instruction i : instructions)
+ Log.println(" " + i);
+ }
+ }
// interface to subclass ///////////////////////////////////////////////////////////////////////
private int data;
private PortReference destination;
private boolean isCodeBag;
- public LiteralDatum(int data, PortReference destination, boolean isCodeBag) {
+ private int count;
+ public LiteralDatum(int data, PortReference destination, boolean isCodeBag) { this(data, destination, isCodeBag, 1); }
+ public LiteralDatum(int data, PortReference destination, boolean isCodeBag, int count) {
this.data = data;
this.destination = destination;
this.isCodeBag = isCodeBag;
+ this.count = count;
}
protected int getData() { return data; }
public void dispatch(Fleet fleet) {
- Port port = destination.resolve(fleet);
- Log.data((isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+"")), null, port);
- port.addData(getData());
+ for(int i=0; i<count; i++) {
+ Port port = destination.resolve(fleet);
+ Log.data((isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+"")), null, port);
+ port.addData(getData());
+ }
}
public String toString() {
- return (isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+""))+" -> "+destination;
+ return (isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+""))+" -"+(count==1?"":("["+count+"]-"))+"> "+destination;
}
}
this.name = name;
}
protected int getData() {
+ if (parent.getCodeBag(name)==null)
+ throw new RuntimeException("[invalid codebag, name="+name+"]");
return parent.getCodeBag(name).getDescriptor();
}
}
Port port = instruction.destination.resolve(getShip().getFleet());
Log.data(data+"", this, port);
port.addData(data);
+ if (instruction.ack)
+ throw new RuntimeException("outboxes may not send acks!");
+
+ } else if (instruction.ack) {
+ Port p = instruction.destination.resolve(getShip().getFleet());
+ Log.token(this, p);
+ p.addToken();
}
- if (instruction.ack)
- throw new RuntimeException("outboxes may not send acks!");
return true;
}
+
+ public void shutdown() {
+ if (!empty)
+ Log.println(Log.red(" WARNING: you left a value ("+dataIn+") on outbox port " + this));
+ if (trigger > 0)
+ Log.println(Log.red(" WARNING: you left a token on the trigger input to port " + this));
+ super.shutdown(false);
+ }
}
public String toString() { return ship+"."+name; }
+ public abstract void shutdown();
}
public void addPort(String name, Port port) {
ports.put(name, port);
}
+
+ public void shutdown() {
+ for(Port p : ports.values())
+ p.shutdown();
+ }
}
tokens--;
}
+ public void shutdown() {
+ if (tokens > 0)
+ Log.println(Log.red(" WARNING: tokens were left on the input to " + this));
+ }
}
switch(instruction.dataIn) {
case COPY:
+ if (empty) return false;
break;
case TAKE:
+ if (empty) return false;
empty = true;
break;
}
public void addData(int data) {
throw new RuntimeException("invalid!");
}
+
+ public void shutdown() {
+ if (!empty)
+ Log.println(Log.red(" WARNING: you left a token on token-output port " + this));
+ super.shutdown(false);
+ }
}
if (in.empty()) return;
in.remove();
getFleet().halt = true;
- Log.println(Log.red(" HALT: ====== halt ship got a token; halting the fleet ======"));
+ Log.println(Log.yellow(" HALT: ====== halt ship got a token; halting the fleet ======"));
}
}
out.addToken();
}
+ public void shutdown() {
+ }
+
}