1 package edu.berkeley.fleet.api;
2 import edu.berkeley.fleet.doc.*;
6 public abstract class Fleet implements Iterable<Ship> {
8 /** read a machine-formatted instruction from a file (into a Java object) */
9 public abstract Instruction readInstruction(DataInputStream is) throws IOException;
11 /** write a machine-formatted instruction to a file (from a Java object) */
12 public abstract void writeInstruction(DataOutputStream os, Instruction instr) throws IOException;
14 /** ships must be returned in the same order every time -- ordering may be significant */
15 public abstract Iterator<Ship> iterator();
18 * Compute the value that should go in the MACHINE-addressed
19 * "offset" field of a literal given BYTE-addressed origin and
22 public abstract int computeOffset(int origin, int target);
25 * Compute the value that should go in the "offset" field of a
26 * literal given BYTE-addressed origin and MACHINE-addressed
29 public abstract int computeTarget(int origin, int offset);
31 /** if possible, run the given code and create a FleetProcess */
32 public FleetProcess run(byte[] code) {
33 throw new RuntimeException("class " + this.getClass().getName() + " does not implement method run()");
36 /** extract the portion of ShipDescription which is specific to this fleet and generate any source code necessary */
37 public void expand(ShipDescription sd) {
38 throw new RuntimeException("class " + this.getClass().getName() + " does not implement method expand()");
42 * This interface marks Fleets which can create ships on the fly, like the fleeterpreter;
43 * if available, the parser will use this interface to create ships out of #ship definitions.
45 public static interface WithDynamicShips {
46 public Ship createShip(String shiptype, String shipname);