From 24f5d4f4456fce3a9e8cd5a7c1225facd60ae979 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 21 Jun 2024 18:59:44 +0100 Subject: put state and chunk into new compiler struct; refactor mildly --- vm.c | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index e3509c7..3410e1c 100644 --- a/vm.c +++ b/vm.c @@ -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 }; -- cgit v1.2.3