-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.Instruction;
public abstract class Outbox extends InstructionPort {
/** number of tokens queued on the trigger input */
private int triggersReceived = 0;
- protected Outbox(Ship ship, String name) {
+ private Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
+
+ protected Outbox(InterpreterShip ship, String name) {
super(ship, name);
}
}
int register;
- protected final boolean service(Instruction instruction) {
+ protected final boolean service(Instruction.Executable instruction) {
// if no instruction waiting, do nothing
if (instruction == null) return false;
// check firing conditions
- if (instruction.trigger && triggersReceived <= 0) return false;
+ if (instruction.tokenIn && triggersReceived <= 0) return false;
if (instruction.dataIn && readyForItemFromShip) return false;
// consume trigger
- if (instruction.trigger) triggersReceived--;
+ if (instruction.tokenIn) triggersReceived--;
// consume item
if (instruction.dataIn) {
if (instruction.dataOut) {
// if item to be transmitted, send it
- send(instruction.destination.resolve(getShip().getFleet()), register);
- if (instruction.ack)
+ send((InterpreterBenkoBox)instruction.dest, register);
+ if (instruction.tokenOut)
throw new RuntimeException("outboxes may not send acks!");
- } else if (instruction.ack) {
+ } else if (instruction.tokenOut) {
// if no item was sent, we might still send an ack
- getFleet().sendToken(this, instruction.destination.resolve(getShip().getFleet()));
+ getInterpreter().sendToken(this, (InterpreterBenkoBox)instruction.dest);
}
return true;
}
/** this is invoked to transmit data; the subclass decides if it is a token or not */
- protected abstract void send(Port port, int data);
+ protected abstract void send(InterpreterBenkoBox port, int data);
/** subclass invokes this to add an item from the ship */
protected final void addItemFromShip(int data) {