summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-21 18:59:44 +0100
committerubq323 <ubq323@ubq323.website>2024-06-21 18:59:44 +0100
commit24f5d4f4456fce3a9e8cd5a7c1225facd60ae979 (patch)
tree095ff7ea3e3620402a9346ae5a9b2817de72c436 /vm.c
parentfbdfd9bf74b178a34543e0e347f441d689f73438 (diff)
put state and chunk into new compiler struct; refactor mildly
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c31
1 files changed, 1 insertions, 30 deletions
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 };