- public FleetProcess run(final byte[] instructions) {
- try {
- final FleetProcess fp = new FleetProcess() {
- public void invokeInstruction(Instruction i) { throw new RuntimeException("not supported"); }
- public long readWord() {
- try {
- return debugStream.take();
- } catch (Exception e) {
- throw new RuntimeException(e);
- } }
- protected void _terminate() {
- shiplist = new ArrayList<InterpreterShip>();
- ships = new HashMap<String,InterpreterShip>();
- debugStream = new LinkedBlockingQueue<Long>();
- mem = new int[0];
- }
- };
- new Thread() {
- public void run() {
- try {
- go(fp, instructions);
- } catch (Exception e) {
- if (fp.isTerminated()) return;
- throw new RuntimeException(e);
- }
- }
- }.start();
- return fp;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public void go(FleetProcess fp, byte[] instructions) {
- try {
- // find the first icache
- InterpreterShip iscratch = null;
- for(Ship ship : this)
- if (ship.getClass().getSimpleName().equals("Iscratch")) {
- iscratch = (InterpreterShip)ship;
- break;
- }
- if (iscratch==null)
- iscratch = (InterpreterShip)Class.forName("edu.berkeley.fleet.interpreter.ships.Iscratch")
- .getConstructor(new Class[] { Interpreter.class, String.class })
- .newInstance(new Object[] { this, "iscratch" });
- iscratch
- .getClass()
- .getMethod("boot", new Class[] { byte[].class })
- .invoke(iscratch, new Object[] { instructions });
-
- while(!halt && !fp.isTerminated())
- for(InterpreterShip ship : ships.values())
- for(int j=0; j<10; j++)
- ship._service();