From 21994864559386f1d11c001d6d27714cbf624a15 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 21 Jun 2024 12:56:30 +0100 Subject: add tests, and make dumping disasm optional --- com.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'com.c') diff --git a/com.c b/com.c index fbc93ac..93b0b59 100644 --- a/com.c +++ b/com.c @@ -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); } -- cgit v1.2.3