#ifndef _vm_h #define _vm_h #include #include #include #include "val.h" void *M(void *p, size_t sz); typedef struct { // bytecode size_t blen; size_t bcap; uint8_t *b; // constants size_t clen; size_t ccap; Val *c; } Chunk; Chunk chunk_new(); size_t chunk_wbc(Chunk *ch, uint8_t byte); size_t chunk_wconst(Chunk *ch, Val v); #define STACKSIZE 128 typedef struct { Chunk *ch; size_t ip; Val stack[STACKSIZE]; size_t sp; } Vm; Vm vm_new(Chunk *ch); typedef enum { OP_RET, OP_LOADK, OP_PRINT, OP_ADD, OP_SUB, OP_MUL, OP_DIV, } Op; #endif