diff options
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 31 |
1 files changed, 1 insertions, 30 deletions
@@ -9,38 +9,9 @@ #include "vm.h" #include "mem.h" #include "dis.h" +#include "com.h" -Chunk chunk_new(State *S) { - return (Chunk){ 0 }; -} - -size_t chunk_wbc(State *S, Chunk *ch, uint8_t byte) { - if (ch->bc.len == ch->bc.cap) { - size_t newsz = (ch->bc.cap == 0 ? 8 : ch->bc.cap * 2); - ch->bc.d = RENEW_ARR(S, ch->bc.d, uint8_t, ch->bc.cap, newsz); - ch->bc.cap = newsz; - } - size_t ix = ch->bc.len; - ch->bc.d[ix] = byte; - ch->bc.len ++; - return ix; -} -size_t chunk_wconst(State *S, Chunk *ch, Val v) { - for (int i = 0; i < ch->consts.len; i ++) - if (val_equal(v, ch->consts.d[i])) return i; - - if (ch->consts.len == ch->consts.cap) { - size_t newsz = (ch->consts.cap == 0 ? 8 : ch->consts.cap *2); - ch->consts.d = RENEW_ARR(S, ch->consts.d, Val, ch->consts.cap, newsz); - ch->consts.cap = newsz; - } - - size_t ix = ch->consts.len; - ch->consts.d[ix] = v; - ch->consts.len ++; - return ix; -} Thread thread_new(State *S) { Thread th = (Thread){ 0 }; |