added FleetProcess
authoradam <adam@megacz.com>
Mon, 12 Feb 2007 09:37:21 +0000 (10:37 +0100)
committeradam <adam@megacz.com>
Mon, 12 Feb 2007 09:37:21 +0000 (10:37 +0100)
src/edu/berkeley/fleet/api/Fleet.java
src/edu/berkeley/fleet/api/FleetProcess.java [new file with mode: 0644]

index c40b2db..991bd01 100644 (file)
@@ -1,4 +1,5 @@
 package edu.berkeley.fleet.api;
+import edu.berkeley.fleet.doc.*;
 import java.io.*;
 import java.util.*;
 
@@ -27,6 +28,16 @@ public abstract class Fleet implements Iterable<Ship> {
      */ 
     public abstract int computeTarget(int origin, int offset);
 
+    /** if possible, run the given code and create a FleetProcess */
+    public FleetProcess run(byte[] code) {
+        throw new RuntimeException("class " + this.getClass().getName() + " does not implement method run()");
+    }
+
+    /** extract the portion of ShipDescription which is specific to this fleet and generate any source code necessary */
+    public void expand(ShipDescription sd) {
+        throw new RuntimeException("class " + this.getClass().getName() + " does not implement method expand()");
+    }
+
     /**
      *  This interface marks Fleets which can create ships on the fly, like the fleeterpreter;
      *  if available, the parser will use this interface to create ships out of #ship definitions.
diff --git a/src/edu/berkeley/fleet/api/FleetProcess.java b/src/edu/berkeley/fleet/api/FleetProcess.java
new file mode 100644 (file)
index 0000000..c5aad72
--- /dev/null
@@ -0,0 +1,34 @@
+package edu.berkeley.fleet.api;
+import java.io.*;
+import java.util.*;
+
+/** represents a <i>running</i> "slave" fleet with a debug connection */
+public abstract class FleetProcess {
+
+    private boolean terminated = false;
+
+    /** dumps an instruction into the fetch unit */
+    public abstract void invokeInstruction(Instruction i);
+
+    /** reads a word back from the debug port */
+    public abstract long readWord();
+
+    /** subclasses may be assured that this will be called exactly once */
+    protected abstract void _terminate();
+
+    public synchronized void terminate() {
+        if (terminated) return;
+        terminated = true;
+        _terminate();
+    }
+
+    public boolean isTerminated() {
+        return terminated;
+    }
+
+    public synchronized void finalize() {
+        if (!terminated)
+            terminate();
+    }
+
+}