interpreter updates
authoradam <adam@megacz.com>
Thu, 26 Jun 2008 23:58:37 +0000 (00:58 +0100)
committeradam <adam@megacz.com>
Thu, 26 Jun 2008 23:58:37 +0000 (00:58 +0100)
src/edu/berkeley/fleet/interpreter/Interpreter.java
src/edu/berkeley/fleet/interpreter/Log.java
src/edu/berkeley/fleet/interpreter/Packet.java

index 2109085..208bc41 100644 (file)
@@ -18,11 +18,24 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami
     public Ship getShip(String type, int ordinal) {
         for(Ship s : this)
             if (s.getType().equals(type))
-                if (ordinal-- < 0)
+                if (ordinal-- <= 0)
                     return s;
         return null;
     }
 
+    /** do not use this; it is going to go away */
+    public Interpreter() {
+    }
+
+    public Interpreter(String[] ships, boolean logging) {
+        int i=0;
+        Log.quiet = !logging;
+        for(String s : ships) {
+            createShip(ships[i], ships[i]+"_"+i);
+            i++;
+        }
+    }
+
     void dispatch(Instruction i) {
         Log.dispatch(i);
         long il = writeInstruction(i, debugShip.getDock("in"));
@@ -30,6 +43,7 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami
         new Packet((InterpreterPath)path, new BitVector(getWordWidth()).set(il), false).send();
     }
 
+    /** do not use this; it is going to go away */
     public Ship createShip(String shipType, String shipname) {
         try {
             Class c = Class.forName("edu.berkeley.fleet.interpreter."+shipType);
index 9fbd93c..a83d15c 100644 (file)
@@ -7,9 +7,10 @@ public class Log {
 
     public static boolean ansi_color = true;
     public static PrintWriter log = new PrintWriter(new OutputStreamWriter(System.out));
+    public static boolean quiet = false;
 
     public static void print(Object o) {
-        if (log==null) return;
+        if (log==null || quiet) return;
         try {
             log.print(o);
         } catch (Exception e) {
@@ -18,7 +19,7 @@ public class Log {
     }
     public static void println() { println(""); }
     public static void println(Object o) {
-        if (log==null) return;
+        if (log==null || quiet) return;
         try {
             log.println(o);
             log.flush();
index a4a20a1..60a69e7 100644 (file)
@@ -14,6 +14,11 @@ class Packet {
     }
 
     public void send() {
+        if (isToken) {
+            Log.token(path.getSource(), path.getDestination());
+        } else {
+            Log.data(value+"", path.getSource(), path.getDestination());
+        }
         ((InterpreterDestination)path.getDestination()).addDataFromFabric(this);
     }