- public int getWordWidth() { return 37; }
- /** some "halt ship" can turn this on to stop the interpreter */
- private HashMap<String,InterpreterShip> ships = new HashMap<String,InterpreterShip>();
- private BlockingQueue<Long> debugStream = new LinkedBlockingQueue<Long>();
-
- public int getWordSize() { return 37; }
-
- public FleetProcess run(final byte[] instructions) {
- try {
- final FleetProcess fp = new FleetProcess() {
- public void dispatchInstruction(Instruction i) { throw new RuntimeException(); }
- public void invokeInstruction(Instruction i) { throw new RuntimeException("not supported"); }
- public Dock getDebugInputDock() { return null; }
- public BitVector readWord() {
- /*
- try {
- return debugStream.take();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }*/
- throw new RuntimeException();
- }
- protected void _terminate() {
- // FIXME: hack
- ships = new HashMap<String,InterpreterShip>();
- debugStream = new LinkedBlockingQueue<Long>();
- }
- };
- new Thread() {
- public void run() {
- try {
- // find the first icache
- InterpreterShip iscratch = null;
- for(Ship ship : Interpreter.this)
- if (ship.getClass().getSimpleName().equals("Memory")) {
- iscratch = (InterpreterShip)ship;
- break;
- }
- if (iscratch==null) {
- BufferedReader br =
- new BufferedReader(new InputStreamReader(new FileInputStream("ships/Memory.ship")));
- ShipDescription sd = new ShipDescription("Memory", br);
- iscratch = (InterpreterShip)Class.forName("edu.berkeley.fleet.interpreter.Memory")
- .getConstructor(new Class[] { Interpreter.class, String.class, ShipDescription.class })
- .newInstance(new Object[] { Interpreter.this, "memory", sd });
- }
- iscratch
- .getClass()
- .getMethod("boot", new Class[] { byte[].class })
- .invoke(iscratch, new Object[] { instructions });
-
- while(!fp.isTerminated())
- for(InterpreterShip ship : ships.values())
- for(int j=0; j<10; j++)
- ship._service();
-
- // run the ships a bit longer for good measure
- for(int i=0; i<100; i++)
- for(InterpreterShip ship : ships.values())
- for(int j=0; j<10; j++)
- ship._service();
-
- // check the state of the ships
- for(InterpreterShip ship : ships.values())
- ship.shutdown();
-
- Log.println(ANSI.yellow(" DONE: ====== FLEET is halted. Have a nice day. ======"));
-
- } catch (Exception e) {
- if (fp.isTerminated()) return;
- throw new RuntimeException(e);
- }
- }
- }.start();
- return fp;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }