diff options
Diffstat (limited to 'com.c')
-rw-r--r-- | com.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -1,4 +1,5 @@ #include <stdlib.h> +#include <string.h> #include <stdio.h> #include "vm.h" @@ -11,15 +12,18 @@ static void compile_node(Chunk *ch, AstNode a) { printf("can't compile ident\n"); exit(1); break; - case AST_STRING: - printf("can't compile strings yet\n"); - exit(1); - break; case AST_NUM: chunk_wbc(ch, OP_LOADK); chunk_wbc(ch, chunk_wconst(ch, VAL_NUM(a.as.num))); break; - case AST_LIST:; + case AST_STRING: { + size_t len = strlen(a.as.str); + ObjString *o = objstring_new(a.as.str, len); + chunk_wbc(ch, OP_LOADK); + chunk_wbc(ch, chunk_wconst(ch, VAL_OBJ(o))); + break; + } + case AST_LIST: { AstVec l = a.as.list; #define CK(cond, msg) if (!(cond)) { puts(msg); exit(1); } CK(l.len == 3, "can only compile binary ops"); @@ -43,6 +47,7 @@ static void compile_node(Chunk *ch, AstNode a) { compile_node(ch, l.vals[2]); chunk_wbc(ch, op); } + } } |