diff options
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 |