better colorization of interpreter logs
authorAdam Megacz <adam@megacz.com>
Sat, 22 Aug 2009 18:40:00 +0000 (11:40 -0700)
committerAdam Megacz <adam@megacz.com>
Sat, 22 Aug 2009 21:23:31 +0000 (14:23 -0700)
src/edu/berkeley/fleet/interpreter/Interpreter.java
src/edu/berkeley/fleet/interpreter/Log.java
src/edu/berkeley/fleet/interpreter/Packet.java

index e4cfb8a..c43ad40 100644 (file)
@@ -190,7 +190,6 @@ public class Interpreter extends FleetTwoFleet {
         }
         public Fleet getFleet() { return Interpreter.this; }
         public synchronized void sendInstruction(Instruction i) {
-            Log.dispatch(i);
             long il = writeInstruction(i, debugShip.getDock("in"));
             Path path = debugShip.getDock("in").getPath(i.dock.getInstructionDestination(), null);
             new Packet((InterpreterPath)path, new BitVector(getWordWidth()).set(il), false).send();
index a83d15c..914e524 100644 (file)
@@ -5,7 +5,6 @@ import java.io.*;
 
 public class Log {
 
-    public static boolean ansi_color = true;
     public static PrintWriter log = new PrintWriter(new OutputStreamWriter(System.out));
     public static boolean quiet = false;
 
@@ -13,9 +12,7 @@ public class Log {
         if (log==null || quiet) return;
         try {
             log.print(o);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+        } catch (Exception e) { throw new RuntimeException(e); }
     }
     public static void println() { println(""); }
     public static void println(Object o) {
@@ -23,31 +20,31 @@ public class Log {
         try {
             log.println(o);
             log.flush();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /*
-    public static void dispatch(Dispatchable d) {
-        println(ANSI.green("dispatch: " + indent(d+"", "          ")));
-    }
-    */
-    public static void dispatch(Instruction d) {
-        println(ANSI.green("dispatch: " + indent(d+"", "          ")));
-    }
-
-    public static void data(String data, Dock source, Destination dest) {
-        println(("    data: ") + indent(ANSI.purple(data) +
-                                        (source==null ? "" :
-                                         (" : " + source))+(" -> "+ANSI.purple(""+dest)), "          "));
+        } catch (Exception e) { throw new RuntimeException(e); }
     }
 
-    public static void token(Dock source, Destination dest) {
-        println(ANSI.purple("   token: ") + (source + " -> " + ANSI.purple(dest+"")));
+    public static void packet(Packet p) {
+        BitVector data = p.getValue();
+        Dock source = p.getSource();
+        Destination dest = p.getDestination();
+        if (dest.getDock().getInstructionDestination()==dest) {
+            if (p.isToken()) {
+                println(ANSI.yellow(ANSI.bold("  torpedo: ")) + (source + " -> " + ANSI.yellow(ANSI.bold(dest+""))));
+            } else {
+                Instruction d = source.getShip().getFleet().decodeInstruction(data, source);
+                println(ANSI.red("dispatch: " + indent(d+"", "          ")));
+            }
+        } else {
+            if (p.isToken()) {
+                println(ANSI.blue(ANSI.bold("   token: ")) + (source + " -> " + ANSI.blue(ANSI.bold(dest+""))));
+            } else {
+                println(indent(ANSI.cyan("    data: "+data) +
+                               (source==null ? "" :
+                                (" : " + source))+(" -> "+ANSI.cyan(""+dest)), "          "));
+            }
+        }
     }
 
-    public static String clreol() { return ""; }
     public static void error(Object o) { println(ANSI.red(o)); }
 
     public static String indent(String s, String indent) {
index 5f44da2..d26b894 100644 (file)
@@ -15,11 +15,7 @@ class Packet {
     }
 
     public void send() {
-        if (isToken) {
-            Log.token(path.getSource(), path.getDestination());
-        } else {
-            Log.data(value+"", path.getSource(), path.getDestination());
-        }
+        Log.packet(this);
         ((InterpreterDestination)path.getDestination()).addDataFromFabric(this);
     }
 
@@ -27,6 +23,10 @@ class Packet {
         return path.getDestination();
     }
 
+    public Dock getSource() {
+        return path.getSource();
+    }
+
     public BitVector getSignal() {
         return path.getSignal();
     }