diff options
Diffstat (limited to 'com.c')
-rw-r--r-- | com.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -27,9 +27,15 @@ 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); } - CK(l.len == 3, "can only compile binary ops"); - CK(l.vals[0].ty == AST_IDENT, "can only call ops"); - #undef CK + CK(l.vals[0].ty == AST_IDENT, "can only call ops"); + + if (0 == strcmp(l.vals[0].as.str, "print")) { + CK(l.len == 2, "print requires exactly 1 argument"); + compile_node(S, ch, l.vals[1]); + chunk_wbc(S, ch, OP_PRINT); + break; + } + CK(l.len == 3, "can only compile binary ops"); char opchar = l.vals[0].as.str[0]; Op op; switch (opchar) { @@ -47,6 +53,7 @@ static void compile_node(State *S, Chunk *ch, AstNode a) { compile_node(S, ch, l.vals[1]); compile_node(S, ch, l.vals[2]); chunk_wbc(S, ch, op); + #undef CK } } } |