diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-21 12:56:30 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-21 12:56:30 +0100 |
commit | 21994864559386f1d11c001d6d27714cbf624a15 (patch) | |
tree | b9a5e76bdc8be9a41970cd6620aab7a3637b7e6a /com.c | |
parent | 671645c370498955eb101695bd9099bf4caf5aea (diff) |
add tests, and make dumping disasm optional
Diffstat (limited to 'com.c')
-rw-r--r-- | com.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -47,7 +47,7 @@ static void compile_node(State *S, Chunk *ch, AstNode a) { } case AST_LIST: { AstVec l = a.as.list; - #define CK(cond, msg) if (!(cond)) { puts(msg); exit(1); } + #define CK(cond, msg) if (!(cond)) { fputs(msg "\n", stderr); exit(1); } CK(l.len > 0, "can't handle empty list"); CK(l.vals[0].ty == AST_IDENT, "can only call ops"); @@ -150,7 +150,7 @@ static void compile_node(State *S, Chunk *ch, AstNode a) { } -int main() { +int main(int argc, char **argv) { State st = state_new(); State *S = &st; Thread th = thread_new(S); @@ -158,12 +158,14 @@ int main() { Chunk ch = chunk_new(S); th.ch = &ch; + S->do_disasm = (argc > 1 && 0 == strcmp(argv[1], "-l")); + char n1[] = "foo"; char n2[] = "bar"; char n3[] = "baz"; - ObjString *o1 = objstring_copy(S, n1, 3); - ObjString *o2 = objstring_copy(S, n2, 3); - ObjString *o3 = objstring_copy(S, n3, 3); + ObjString *o1 = objstring_copy_cstr(S, n1); + ObjString *o2 = objstring_copy_cstr(S, n2); + ObjString *o3 = objstring_copy_cstr(S, n3); ht_put(S, &st.globals, o1, VAL_NUM(69)); ht_put(S, &st.globals, o2, VAL_NUM(2)); @@ -175,7 +177,6 @@ int main() { chunk_wbc(S, &ch, OP_PRINT); chunk_wbc(S, &ch, OP_RET); - puts("compile done"); return runvm(S); } |