summaryrefslogtreecommitdiff
path: root/com.c
diff options
context:
space:
mode:
Diffstat (limited to 'com.c')
-rw-r--r--com.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/com.c b/com.c
index 64aee2e..b97ffc0 100644
--- a/com.c
+++ b/com.c
@@ -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
}
}
}