--- a/objwriter.cxx Mon Jul 30 11:34:57 2012 +0300 +++ b/objwriter.cxx Sat Aug 11 19:35:47 2012 +0300 @@ -120,28 +120,34 @@ if (sizeof (unsigned char) != 1) error ("size of unsigned char isn't 1, but %d!\n", sizeof (unsigned char)); + unsigned int refpos = 0; for (unsigned int x = 0; x < MainBuffer->writesize; x++) { // Check if this position is a reference for (unsigned int r = 0; r < MAX_MARKS; r++) { if (MainBuffer->refs[r] && MainBuffer->refs[r]->pos == x) { - // All marks need their positions bumped up as the bytecode will gain - // 4 more bytes with the written reference. Other references do not - // need their positions bumped because they check against mainbuffer - // position (x), not written ones. - for (unsigned int s = 0; s < MAX_MARKS; s++) - if (MainBuffer->marks[s]) - MainBuffer->marks[s]->pos += sizeof (word); - word ref = static_cast<word> (MainBuffer->marks[MainBuffer->refs[r]->num]->pos); + printf ("insert reference to mark %d (%ld) refpos = %d\n", MainBuffer->refs[r]->num, ref, refpos); WriteDataToFile<word> (ref); // This reference is now used up - no need to keep it anymore. delete MainBuffer->refs[r]; MainBuffer->refs[r] = NULL; + + // All marks still ahead need their positions bumped up as the bytecode + // will gain 4 more bytes with the written reference. Other references + // do not need their positions bumped because they check against mainbuffer + // position (x), not written ones. + for (unsigned int s = 0; s < MAX_MARKS; s++) + if (MainBuffer->marks[s] && MainBuffer->marks[s]->pos > refpos) { + printf ("mark %u bumped\n", s); + MainBuffer->marks[s]->pos += sizeof (word); + } + refpos += sizeof (word); } } WriteDataToFile<unsigned char> (*(MainBuffer->buffer+x)); + refpos++; } printf ("-- %u byte%s written to %s\n", numWrittenBytes, PLURAL (numWrittenBytes), filepath.chars()); @@ -185,4 +191,8 @@ // Deletes a mark void ObjWriter::DeleteMark (unsigned int mark) { GetCurrentBuffer()->DeleteMark (mark); +} + +void ObjWriter::OffsetMark (unsigned int mark, int offset) { + GetCurrentBuffer()->OffsetMark (mark, offset); } \ No newline at end of file