summaryrefslogtreecommitdiff
path: root/com.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-20 16:00:34 +0100
committerubq323 <ubq323@ubq323.website>2024-06-20 16:00:34 +0100
commit60b3369ab24f9bd2a4a6d638ab1b3013ebc29814 (patch)
tree3ff8ec7e95ef314266673b1b3d7bedb880a4a5b0 /com.c
parent9ee73a8459eb2bb58adc29da02de312b7e4e7dca (diff)
pass State *S everywhere
contains changes from a million years ago that i don't remember much about
Diffstat (limited to 'com.c')
-rw-r--r--com.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/com.c b/com.c
index e371e6d..64aee2e 100644
--- a/com.c
+++ b/com.c
@@ -5,22 +5,23 @@
#include "vm.h"
#include "ast.h"
#include "read.h"
+#include "state.h"
-static void compile_node(Chunk *ch, AstNode a) {
+static void compile_node(State *S, Chunk *ch, AstNode a) {
switch (a.ty) {
case AST_IDENT:
printf("can't compile ident\n");
exit(1);
break;
case AST_NUM:
- chunk_wbc(ch, OP_LOADK);
- chunk_wbc(ch, chunk_wconst(ch, VAL_NUM(a.as.num)));
+ chunk_wbc(S, ch, OP_LOADK);
+ chunk_wbc(S, ch, chunk_wconst(S, ch, VAL_NUM(a.as.num)));
break;
case AST_STRING: {
size_t len = strlen(a.as.str);
- ObjString *o = objstring_copy(a.as.str, len);
- chunk_wbc(ch, OP_LOADK);
- chunk_wbc(ch, chunk_wconst(ch, VAL_OBJ(o)));
+ ObjString *o = objstring_copy(S, a.as.str, len);
+ chunk_wbc(S, ch, OP_LOADK);
+ chunk_wbc(S, ch, chunk_wconst(S, ch, VAL_OBJ(o)));
break;
}
case AST_LIST: {
@@ -43,22 +44,28 @@ static void compile_node(Chunk *ch, AstNode a) {
exit(1);
break;
}
- compile_node(ch, l.vals[1]);
- compile_node(ch, l.vals[2]);
- chunk_wbc(ch, op);
+ compile_node(S, ch, l.vals[1]);
+ compile_node(S, ch, l.vals[2]);
+ chunk_wbc(S, ch, op);
}
}
}
int main() {
- Chunk ch = chunk_new();
+ State st = state_new();
+ State *S = &st;
+ Thread th = thread_new(S);
+ st.th = &th;
+ Chunk ch = chunk_new(S);
+ th.ch = &ch;
+
AstNode an = read();
- compile_node(&ch, an);
+ compile_node(S, &ch, an);
- chunk_wbc(&ch, OP_PRINT);
- chunk_wbc(&ch, OP_RET);
+ chunk_wbc(S, &ch, OP_PRINT);
+ chunk_wbc(S, &ch, OP_RET);
- runvm(&ch);
+ runvm(S);
}