|
|
@@ -9,23 +9,27 @@ void initChunk(Chunk *chunk) {
|
|
|
chunk->count = 0;
|
|
|
chunk->capacity = 0;
|
|
|
chunk->code = NULL;
|
|
|
+ chunk->lines = NULL;
|
|
|
initValueArray(&chunk->constants);
|
|
|
}
|
|
|
void freeChunk(Chunk *chunk) {
|
|
|
FREE_ARRAY(uint8_t, chunk->code, chunk->capacity);
|
|
|
+ FREE_ARRAY(int, chunk->lines, chunk->capacity);
|
|
|
freeValueArray(&chunk->constants);
|
|
|
initChunk(chunk);
|
|
|
}
|
|
|
-void writeChunk(Chunk *chunk, uint8_t byte) {
|
|
|
+void writeChunk(Chunk *chunk, uint8_t byte, int line) {
|
|
|
// 容量不够
|
|
|
if (chunk->capacity < chunk->count + 1) {
|
|
|
int oldCapacity = chunk->capacity;
|
|
|
chunk->capacity = GROW_CAPACITY(oldCapacity);
|
|
|
chunk->code = GROW_ARRAY(uint8_t, chunk->code, oldCapacity, chunk->capacity);
|
|
|
+ chunk->lines = GROW_ARRAY(int, chunk->lines, oldCapacity, chunk->capacity);
|
|
|
}
|
|
|
|
|
|
// 赋值
|
|
|
chunk->code[chunk->count] = byte;
|
|
|
+ chunk->lines[chunk->count] = line;
|
|
|
chunk->count++;
|
|
|
}
|
|
|
int addConstant(Chunk *chunk, Value value) {
|