1 package edu.berkeley.fleet.interpreter.ships;
2 import edu.berkeley.fleet.interpreter.*;
3 import edu.berkeley.fleet.*;
8 public class Mux extends InterpreterShip {
10 DataInbox ap = new DataInbox(this, "a");
11 DataInbox bp = new DataInbox(this, "b");
12 DataInbox choicep = new DataInbox(this, "select");
13 DataOutbox out = new DataOutbox(this, "out");
15 public Mux(Interpreter fleet, String name) { super(fleet, name); }
17 public String getBalsaName() { return "mux"; }
19 public void service() {
20 if (ap.dataReadyForShip() && bp.dataReadyForShip() && choicep.dataReadyForShip()) {
21 int a = ap.removeDataForShip();
22 int b = bp.removeDataForShip();
23 int choice = choicep.removeDataForShip();
24 out.addDataFromShip(choice==0 ? a : b);