From 60b3369ab24f9bd2a4a6d638ab1b3013ebc29814 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 20 Jun 2024 16:00:34 +0100 Subject: pass State *S everywhere contains changes from a million years ago that i don't remember much about --- vm.h | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'vm.h') diff --git a/vm.h b/vm.h index 9a17f77..4400564 100644 --- a/vm.h +++ b/vm.h @@ -5,30 +5,35 @@ #include #include +typedef struct _thread Thread; + #include "val.h" +#include "state.h" typedef struct { - // bytecode - size_t blen; - size_t bcap; - uint8_t *b; - // constants - size_t clen; - size_t ccap; - Val *c; + struct { + size_t len; + size_t cap; + uint8_t *d; + } bc; + struct { + size_t len; + size_t cap; + Val *d; + } consts; } Chunk; -Chunk chunk_new(); -size_t chunk_wbc(Chunk *ch, uint8_t byte); -size_t chunk_wconst(Chunk *ch, Val v); +Chunk chunk_new(State *S); +size_t chunk_wbc(State *S, Chunk *ch, uint8_t byte); +size_t chunk_wconst(State *S, Chunk *ch, Val v); #define STACKSIZE 128 -typedef struct { +typedef struct _thread { Chunk *ch; size_t ip; Val stack[STACKSIZE]; size_t sp; -} Vm; -Vm vm_new(Chunk *ch); +} Thread; +Thread thread_new(State *S); typedef enum { OP_RET, @@ -41,6 +46,6 @@ typedef enum { OP_DIV, } Op; -void runvm(Chunk *ch); +void runvm(State *S); #endif -- cgit v1.2.3