summaryrefslogtreecommitdiff
path: root/vm.h
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-07-31 18:51:46 +0100
committerubq323 <ubq323@ubq323.website>2023-07-31 18:51:46 +0100
commitf80e73ee8d7f7b68f403033001c632e91cb5ac68 (patch)
tree359f785f785949191286214681b56058b4f025c4 /vm.h
parentcd6edc3cb4423672e92d3daaad8e12965ebc70e3 (diff)
bytecode vm start, can print constants currently
Diffstat (limited to 'vm.h')
-rw-r--r--vm.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/vm.h b/vm.h
new file mode 100644
index 0000000..7f76e05
--- /dev/null
+++ b/vm.h
@@ -0,0 +1,42 @@
+#ifndef _vm_h
+#define _vm_h
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#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;
+
+
+#endif