/** ships must be returned in the same order every time -- ordering may be significant */
public abstract Iterator<Ship> iterator();
- /**
- * Compute the value that should go in the MACHINE-addressed
- * "offset" field of a literal given BYTE-addressed origin and
- * target
- */
- public abstract int computeOffset(int origin, int target);
-
- /**
- * Compute the value that should go in the "offset" field of a
- * literal given BYTE-addressed origin and MACHINE-addressed
- * target
- */
- 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()");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
+ int count = 0;
for(int i=0; i<codeBags.size(); i++) {
CodeBag c = codeBags.get(i);
dos.flush();
- codeBagMap[i] = cos.getCount();
- for(Instruction inst : c)
+ codeBagMap[i] = count;//cos.getCount();
+ for(Instruction inst : c) {
fleet.writeInstruction(dos, inst);
+ count++;
+ }
}
// now write for real
cos = new CountingOutputStream(out);
dos = new DataOutputStream(cos);
+ count = 0;
for(int i=0; i<codeBags.size(); i++) {
CodeBag c = codeBags.get(i);
dos.flush();
dos.flush();
cos.getCount();
Instruction.Literal.CodeBagDescriptor old = (Instruction.Literal.CodeBagDescriptor)inst;
- int offset = fleet.computeOffset(cos.getCount(), codeBagMap[(int)old.offset]);
+ int offset = codeBagMap[(int)old.offset] - count;
inst = new Instruction.Literal.CodeBagDescriptor(old.dest,
offset,
codeBags.get((int)old.offset).size());
}
fleet.writeInstruction(dos, inst);
+ count++;
}
}
dos.flush();