diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-20 16:00:34 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-20 16:00:34 +0100 |
commit | 60b3369ab24f9bd2a4a6d638ab1b3013ebc29814 (patch) | |
tree | 3ff8ec7e95ef314266673b1b3d7bedb880a4a5b0 /vm.h | |
parent | 9ee73a8459eb2bb58adc29da02de312b7e4e7dca (diff) |
pass State *S everywhere
contains changes from a million years ago that i don't remember much about
Diffstat (limited to 'vm.h')
-rw-r--r-- | vm.h | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -5,30 +5,35 @@ #include <stdlib.h> #include <stdint.h> +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 |