summaryrefslogtreecommitdiff
path: root/com.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-20 17:23:01 +0100
committerubq323 <ubq323@ubq323.website>2024-06-20 17:23:01 +0100
commitb8d0ee2e105727021f9466790ec07ecbfee8dff6 (patch)
treefe151cdbd4e0ca61a491f2f2fd01afc6448bc124 /com.c
parent60b3369ab24f9bd2a4a6d638ab1b3013ebc29814 (diff)
string interning and print statement
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
}
}
}