change build machine, use /usr/bin/tclsh instead of /usr/bin/tcl
[fleet.git] / src / edu / berkeley / fleet / interpreter / Packet.java
1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.sbp.util.ANSI;
4
5 class Packet {
6
7     private final InterpreterPath path;
8     private final BitVector value;
9     private final boolean isToken;
10
11     public Packet(InterpreterPath path, BitVector value, boolean isToken) {
12         this.value = value;
13         this.path = path;
14         this.isToken = isToken;
15         this.value.setImmutable();
16     }
17
18     public void send() {
19         Log.packet(this);
20         ((InterpreterDestination)path.getDestination()).addDataFromFabric(this);
21     }
22
23     public Destination getDestination() {
24         return path.getDestination();
25     }
26
27     public Dock getSource() {
28         return path.getSource();
29     }
30
31     public BitVector getSignal() {
32         return path.getSignal();
33     }
34
35     public BitVector getValue() {
36         return value;
37     }
38
39     public boolean isToken() {
40         return isToken;
41     }
42
43     public String toString() {
44         Packet p = this;
45         BitVector data = p.getValue();
46         Dock source = p.getSource();
47         Destination dest = p.getDestination();
48         if (dest.getDock().getInstructionDestination()==dest) {
49             if (p.isToken()) {
50                 return (ANSI.yellow(ANSI.bold(" torpedo: ")) + (source + " -> " + ANSI.yellow(ANSI.bold(dest+""))));
51             } else {
52                 Instruction d = source.getShip().getFleet().decodeInstruction(data, source);
53                 return (ANSI.red("dispatch: " + d));
54             }
55         } else {
56             if (p.isToken()) {
57                 return (ANSI.blue(ANSI.bold("   token: ")) + (source + " -> " + ANSI.blue(ANSI.bold(dest+""))));
58             } else {
59                 return (ANSI.cyan("    data: "+data) +
60                                (source==null ? "" :
61                                 (" : " + source))+(" -> "+ANSI.cyan(""+dest)));
62             }
63         }
64     }
65
66 }