1 package edu.berkeley.fleet;
3 /** represents a literal; currently handled in an extremely hoakey fashion */
6 public static class LiteralDatum extends Dispatchable {
8 PortReference destination;
9 private boolean isCodeBag;
11 public LiteralDatum(int data, PortReference destination, boolean isCodeBag) { this(data, destination, isCodeBag, 1); }
12 public LiteralDatum(int data, PortReference destination, boolean isCodeBag, int count) {
14 this.destination = destination;
15 this.isCodeBag = isCodeBag;
18 protected int getData() { return data; }
19 public void dispatch(Fleet fleet) {
20 for(int i=0; i<count; i++) {
21 Port port = destination.resolve(fleet);
22 Log.data((isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+"")), null, port);
23 port.addDataFromFabric(getData());
26 public String toString() {
27 return (isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+""))+" -"+(count==1?"":("["+count+"]-"))+"> "+destination;
31 public static class CodeBagRef extends LiteralDatum {
33 private CodeBag parent;
34 public CodeBagRef(String name, CodeBag parent, PortReference destination) {
35 super(0, destination, true);
39 protected int getData() {
40 if (parent.getCodeBag(name)==null)
41 throw new RuntimeException("[invalid codebag, name="+name+"]");
42 return parent.getCodeBag(name).getDescriptor();
46 public static class LiteralToken extends Dispatchable {
47 private PortReference destination;
48 public LiteralToken(PortReference destination) {
49 this.destination = destination;
51 public void dispatch(Fleet fleet) {
52 destination.resolve(fleet).addTokenFromFabric();
54 public String toString() {
55 return "token -> "+destination;
59 public static class ShipSpecific extends Dispatchable {
61 private PortReference destination;
63 public ShipSpecific(String data, PortReference destination, int count) {
65 this.destination = destination;
68 public void dispatch(Fleet fleet) {
69 for(int i=0; i<count; i++) {
70 Port port = destination.resolve(fleet);
71 Log.data("\""+data+"\"", null, port);
72 int dat = port.getShip().resolveShipSpecificConstant(data);
73 port.addDataFromFabric(dat);
76 public String toString() {
77 return ("\""+data+"\""+" -"+(count==1?"":("["+count+"]-"))+"> "+destination);