#ifndef _vm_h #define _vm_h #include #include #include typedef struct _thread Thread; #include "val.h" #include "state.h" typedef struct { 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(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 _thread { Chunk *ch; size_t ip; Val stack[STACKSIZE]; size_t sp; } Thread; Thread thread_new(State *S); typedef enum { OP_RET, OP_LOADK, OP_PRINT, OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_DROP, OP_GETGLOBAL, OP_SETGLOBAL, OP_TRUE, OP_FALSE, OP_NIL, OP_0BRANCH, OP_SKIP, OP_REDO, } Op; int runvm(State *S); #endif