Comment = "//" ~[\n]* "\n"
| "/*" ~[\n]* "*/"
-// for some reason this causes major slowness!
ws = ([\r\n ] | Comment)* -> ~[\r\n ]
s = ws! Program ws!
(Directive ws!)*
CodeBagBody
-Directive = Memory:: "#memory" "{" (int +/ (ws! "," ws!)) "}" /ws
- | Import:: "#import" [A-Za-z_.]++ /ws
- | Ship:: "#ship" shipname ":" [A-Za-z_\.]++ /ws
-
-
Statement = Move ((ws ";")?)!
| NamedCodeBag:: name ":" "{" CodeBagBody "}" /ws
-// | ^"#define" Port Port /ws
-
-Move = Port ^"->" Destination /ws
- | Port ^"-(*)->" Destination /ws
- | Port ^"-(" int ")->" Destination /ws
- | LiteralMove:: int "->" Destination /ws
- | LiteralCountMove:: int "-(" int ")->" Destination /ws
- | CodeBagMove:: CodeBag "->" Port /ws
- | CodeBagMoveX:: Port "<-" CodeBag /ws
- | Port ^"<-" Port /ws
-
-Destination = Port +/ (ws! "," ws!)
+
+Move = Port ^"->" Destination /ws
+ | Port ^"+->" Destination /ws
+ | Port ^"-(*)->" Destination /ws
+ | Port ^"-(" int ")->" Destination /ws
+ | Port ^"+-(" int ")->" Destination /ws
+ | LiteralMove:: int "->" Destination /ws
+ | LiteralCountMove:: int "-(" int ")->" Destination /ws
+ | CodeBagMove:: CodeBag "->" Port /ws
+ | CodeBagMoveX:: Port "<-" CodeBag /ws
+ | Port ^"<-" Port /ws
+
+Destination = "":: Port
CodeBagBody = CodeBag:: (Statement +/ ws)
CodeBag = CodeBagRef:: CodeBagName
| "{" CodeBagBody "}" /ws
CodeBagName = name
-//Port = Port:: shipname ("." portname)*
Port = Port:: shipname "." portname
shipname = ShipName:: name
portname = PortName:: name
| [0-9]+
int = [\-0-9]++
+// the following are not part of the official FLEET syntax and are
+// specific to Adam's interpreter.
+
+Directive = Memory:: "#memory" "{" (int +/ (ws! "," ws!)) "}" /ws
+ | Import:: "#import" [A-Za-z_.]++ /ws
+ | Ship:: "#ship" shipname ":" [A-Za-z_\.]++ /ws
+
if ((i%10)==0) Log.println(" ");
Log.print(mem[i] + " ");
}
+ Log.println();
}
public Ship.Inbox getInbox(String ship, String port) {
public static @bind.as("->") Statement move(Port source, Port[] dest) {
return new Move(source, dest);
}
+ public static @bind.as("+->") Statement movex(Port source, Port[] dest) {
+ return new Move(source, dest, true);
+ }
public static @bind.as("CodeBagMove") Statement cbmove(CodeBag cb, Port dest) {
return new CodeBagMove(cb, new Port[] { dest });
public static @bind.as("-(") Statement smove(Port source, String count, Port[] dest) {
return new Move(source, dest, Integer.parseInt(count));
}
+ public static @bind.as("+-(") Statement smovex(Port source, String count, Port[] dest) {
+ return new Move(source, dest, Integer.parseInt(count), true);
+ }
public static @bind.as("<-") Statement gets(Port dest, Port source) {
return new Move(source, new Port[] { dest });
Port[] dest;
int count;
int val;
+ boolean copy;
public Move(Port source, Port[] dest) { this(source, dest, 1); }
- public Move(Port source, Port[] dest, int count) { this(0, source, dest, count); }
+ public Move(Port source, Port[] dest, boolean copy) { this(source, dest, 1, copy); }
+ public Move(Port source, Port[] dest, int count) { this(0, source, dest, count, false); }
+ public Move(Port source, Port[] dest, int count, boolean copy) { this(0, source, dest, count, copy); }
public Move(int val, Port[] dest) { this(val, dest, 1); }
public Move(int val, Port[] dest, int count) { this(val, null, dest, count); }
- public Move(int val, Port source, Port[] dest, int count) {
+ public Move(int val, Port source, Port[] dest, int count) { this(val, source, dest, count, false); }
+ public Move(int val, Port source, Port[] dest, int count, boolean copy) {
+ this.copy = copy;
this.source = source;
this.dest = dest;
this.count = count;
ib.add(val);
Log.println("instr: " + val + " -> " + ib);
} else {
- if (count==0) ob.addTokenDestination(ib);
+ if (count==0) ob.addTokenDestination(ib, copy);
else if (count==Integer.MAX_VALUE) ob.addStandingDestination(ib);
- else ob.addDestination(ib);
+ else ob.addDestination(ib, copy);
Log.println("instr: " + ob + " -> " + ib);
}
}
for(Outbox ob : outboxes.values()) {
if (ob.data.isEmpty()) continue;
if (!ob.destination.isEmpty()) {
- int data = ob.data.remove();
Inbox destination = ob.destination.remove();
+ boolean copy = ob.copy.remove();
+ int data = copy ? ob.data.peek() : ob.data.remove();
destination.add(data);
Log.println("data: " + ob + " ----("+data+")----> " + destination);
continue;
public Inbox standingDestination;
public Queue<Integer> data = new LinkedList<Integer>();
public Queue<Inbox> destination = new LinkedList<Inbox>();
+ public Queue<Boolean> copy = new LinkedList<Boolean>();
public void add(int data) { this.data.add(data); }
public void flush() { data.clear(); /* FIXME: risky */ }
- public void addTokenDestination(Inbox destination) {
+ public void addTokenDestination(Inbox destination, boolean copy) {
standingDestination = null;
this.destination.add(destination);
this.add(0);
+ this.copy.add(copy);
}
public void addStandingDestination(Inbox destination) {
standingDestination = destination;
}
- public void addDestination(Inbox destination) {
+ public void addDestination(Inbox destination, boolean copy) {
standingDestination = null;
this.destination.add(destination);
+ this.copy.add(copy);
}
public boolean empty() { return data.isEmpty(); }
public String toString() { return Ship.this.name+"."+name; }
--- /dev/null
+package edu.berkeley.fleet;
+
+import java.util.*;
+import java.io.*;
+
+public class TokenJoinShip extends Ship {
+
+ Inbox in1 = new Inbox("in1");
+ Inbox in2 = new Inbox("in2");
+ Outbox out = new Outbox("out");
+
+ public TokenJoinShip(Fleet fleet, String name) {
+ super(fleet, name);
+ }
+
+ public void service() {
+ if (!in1.empty() && !in2.empty()) {
+ in1.remove();
+ in2.remove();
+ out.add(0);
+ }
+ }
+
+}
--- /dev/null
+#import edu.berkeley.fleet
+
+// skeleton solution to problem #1 (fill in the XXX blanks)
+
+#memory { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+
+#ship memread : MemReadShip
+#ship memwrite1 : MemWriteShip
+#ship memwrite2 : MemWriteShip
+#ship bitbucket : BitBucketShip
+#ship halt : HaltShip
+#ship fetch : FetchShip
+#ship tokenjoin : TokenJoinShip
+
+top: {
+
+ 2 -> memread.count
+ 0 -(2)-> memread.token
+ 0 -> memread.addr
+ 1 -> memread.stride
+
+ memread.data +-(4)-> memwrite1.data
+ memread.data -> memwrite1.data
+ memread.data +-(4)-> memwrite1.data
+ memread.data -> memwrite1.data
+
+ 10 -> memwrite1.count
+ 5 -> memwrite1.addr
+ 1 -> memwrite1.stride
+ memwrite1.token -(9)-> bitbucket.in
+ memwrite1.token -> halt.in
+
+}
+
+top -> fetch.in
+