diff options
Diffstat (limited to 'bytecode/oper.c')
| -rw-r--r-- | bytecode/oper.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/bytecode/oper.c b/bytecode/oper.c index ed4a681..fcb7d77 100644 --- a/bytecode/oper.c +++ b/bytecode/oper.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include "encoding.h" +#include "heap.h" #include "panic.h" #include "slice.h" #include "value.h" @@ -10,7 +11,8 @@ struct st { size_t i; - value locals[8]; + value locals[NUM_LOCALS]; + struct heap heap; }; static value read_arg(struct st *s, struct arg arg) @@ -21,9 +23,9 @@ static value read_arg(struct st *s, struct arg arg) return s->locals[arg.local]; } -static void alloc(struct st *s, struct op oper) +static void oalloc(struct st *s, struct op oper) { - s->locals[oper.alloc.out] = from_pointer(calloc(to_int(read_arg(s, oper.alloc.size)), sizeof(value))); + s->locals[oper.alloc.out] = from_pointer(alloc(&s->heap, to_int(read_arg(s, oper.alloc.size)))); } static void call(struct st *s) @@ -57,7 +59,7 @@ static void op(struct st *s, struct op oper) { switch (oper.code) { case OALLOC: - alloc(s, oper); + oalloc(s, oper); break; case OCALL: call(s); @@ -85,6 +87,7 @@ void run(struct slice prog) .i = 0, .locals = { 0 }, }; + s.heap = new_heap((struct val_slice) { .size = NUM_LOCALS, .buf = s.locals }); while (true) { struct result oper = parse(slice1(prog, s.i)); s.i += oper.n; |
