summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-08-01 22:37:26 +0100
committerubq323 <ubq323@ubq323.website>2023-08-01 22:37:26 +0100
commit9e555bc2bf618148929e52ccd0efdb1b752bdcac (patch)
tree5e6f01123d795624c0093df6e08307be2b2c8cd0 /vm.c
parent24fb17017e9d6238488c9827da0ee6d0f4f84356 (diff)
compilation of basic arithmetic exprs to bytecode
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/vm.c b/vm.c
index 72f69fa..70f065b 100644
--- a/vm.c
+++ b/vm.c
@@ -60,22 +60,22 @@ Vm vm_new(Chunk *ch) {
}
-static void runvm() {
- Chunk ch = chunk_new();
+void runvm(Chunk *ch) {
+ // Chunk ch = chunk_new();
- chunk_wbc(&ch, OP_LOADK);
- chunk_wbc(&ch, chunk_wconst(&ch, VAL_NUM(10.0)));
- chunk_wbc(&ch, OP_LOADK);
- chunk_wbc(&ch, chunk_wconst(&ch, VAL_NUM(3.0)));
- chunk_wbc(&ch, OP_DIV);
- chunk_wbc(&ch, OP_PRINT);
+ // chunk_wbc(&ch, OP_LOADK);
+ // chunk_wbc(&ch, chunk_wconst(&ch, VAL_NUM(10.0)));
+ // chunk_wbc(&ch, OP_LOADK);
+ // chunk_wbc(&ch, chunk_wconst(&ch, VAL_NUM(3.0)));
+ // chunk_wbc(&ch, OP_DIV);
+ // chunk_wbc(&ch, OP_PRINT);
- chunk_wbc(&ch, OP_RET);
+ // chunk_wbc(&ch, OP_RET);
- disasm_chunk(&ch);
+ disasm_chunk(ch);
- Vm vm = vm_new(&ch);
+ Vm vm = vm_new(ch);
#define RBYTE() (vm.ch->b[vm.ip++])
#define PUSH(v) vm.stack[vm.sp++] = v;
@@ -126,6 +126,5 @@ static void runvm() {
done:;
}
-int main() { runvm(); }