136 // Merge another data buffer into this one. |
136 // Merge another data buffer into this one. |
137 void Merge (DataBuffer* other) { |
137 void Merge (DataBuffer* other) { |
138 if (!other) |
138 if (!other) |
139 return; |
139 return; |
140 |
140 |
141 for (unsigned int x = 0; x < other->writesize; x++) { |
141 for (unsigned int x = 0; x < other->writesize; x++) |
142 unsigned char c = *(other->buffer+x); |
142 Write<unsigned char> (*(other->buffer+x)); |
143 Write<unsigned char> (c); |
|
144 } |
|
145 |
143 |
146 // Merge its marks and references |
144 // Merge its marks and references |
147 unsigned int u = 0; |
145 unsigned int u = 0; |
148 for (u = 0; u < MAX_MARKS; u++) { |
146 for (u = 0; u < MAX_MARKS; u++) { |
149 if (other->marks[u]) { |
147 if (other->marks[u]) { |
158 refs[r]->pos += other->writesize; |
156 refs[r]->pos += other->writesize; |
159 } |
157 } |
160 } |
158 } |
161 |
159 |
162 delete other; |
160 delete other; |
|
161 } |
|
162 |
|
163 // Clones this databuffer to a new one and returns it. |
|
164 DataBuffer* Clone () { |
|
165 DataBuffer* other = new DataBuffer; |
|
166 for (unsigned int x = 0; x < writesize; x++) |
|
167 other->Write<unsigned char> (*(buffer+x)); |
|
168 return other; |
163 } |
169 } |
164 |
170 |
165 // ==================================================================== |
171 // ==================================================================== |
166 // Adds a mark to the buffer. A mark is a reference to a particular |
172 // Adds a mark to the buffer. A mark is a reference to a particular |
167 // position in the bytecode. The actual permanent position cannot |
173 // position in the bytecode. The actual permanent position cannot |
227 void MoveMark (unsigned int mark) { |
233 void MoveMark (unsigned int mark) { |
228 if (!marks[mark]) |
234 if (!marks[mark]) |
229 return; |
235 return; |
230 marks[mark]->pos = writesize; |
236 marks[mark]->pos = writesize; |
231 } |
237 } |
|
238 |
|
239 // Dump the buffer (for debugging purposes) |
|
240 void Dump() { |
|
241 for (unsigned int x = 0; x < writesize; x++) |
|
242 printf ("%d. [%d]\n", x, *(buffer+x)); |
|
243 } |
232 }; |
244 }; |
233 |
245 |
234 #endif // __DATABUFFER_H__ |
246 #endif // __DATABUFFER_H__ |