Move from Jansson to JV - everything but the interpreter loop

Passes valgrind --leak-check=full.
This commit is contained in:
Stephen Dolan committed 2012-09-02 16:31:59 +01:00
1 parent 22f8aed31e
commit 2cb9a6e61d
12 files changed
+170 -123

No files matched your search

+19 -3
View File
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdint.h>
#include <jansson.h>
#include <stdlib.h>
#include "bytecode.h"
#include "opcode.h"
@@ -57,8 +58,7 @@ void dump_operation(struct bytecode* bc, uint16_t* codeptr) {
printf(" %04d", pc + imm);
} else if (op->flags & OP_HAS_CONSTANT) {
printf(" ");
json_dumpf(json_array_get(bc->constants, imm),
stdout, JSON_ENCODE_ANY);
jv_dump(jv_array_get(jv_copy(bc->constants), imm));
} else if (op->flags & OP_HAS_VARIABLE) {
uint16_t v = bc->code[pc++];
printf(" v%d", v);
@@ -70,3 +70,19 @@ void dump_operation(struct bytecode* bc, uint16_t* codeptr) {
}
}
}
void symbol_table_free(struct symbol_table* syms) {
free(syms->cfunctions);
free(syms);
}
void bytecode_free(struct bytecode* bc) {
free(bc->code);
jv_free(bc->constants);
for (int i=0; i<bc->nsubfunctions; i++)
bytecode_free(bc->subfunctions[i]);
if (!bc->parent)
symbol_table_free(bc->globals);
free(bc->subfunctions);
free(bc);
}