summaryrefslogtreecommitdiff
path: root/com.c
diff options
context:
space:
mode:
Diffstat (limited to 'com.c')
-rw-r--r--com.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/com.c b/com.c
index 4252ecd..3d891f7 100644
--- a/com.c
+++ b/com.c
@@ -10,10 +10,18 @@
static void compile_node(State *S, Chunk *ch, AstNode a) {
switch (a.ty) {
case AST_IDENT:;
- size_t len = strlen(a.as.str);
- ObjString *o = objstring_copy(S, a.as.str, len);
- chunk_wbc(S, ch, OP_GETGLOBAL);
- chunk_wbc(S, ch, chunk_wconst(S, ch, VAL_OBJ(o)));
+ char *ident = a.as.str;
+
+ if (0 == strcmp(ident, "true")) chunk_wbc(S, ch, OP_TRUE);
+ else if (0 == strcmp(ident, "false")) chunk_wbc(S, ch, OP_FALSE);
+ else if (0 == strcmp(ident, "nil")) chunk_wbc(S, ch, OP_NIL);
+ else {
+ // global read
+ size_t len = strlen(a.as.str);
+ ObjString *o = objstring_copy(S, a.as.str, len);
+ chunk_wbc(S, ch, OP_GETGLOBAL);
+ chunk_wbc(S, ch, chunk_wconst(S, ch, VAL_OBJ(o)));
+ }
break;
case AST_NUM:
chunk_wbc(S, ch, OP_LOADK);
@@ -104,6 +112,6 @@ int main() {
chunk_wbc(S, &ch, OP_PRINT);
chunk_wbc(S, &ch, OP_RET);
- runvm(S);
+ return runvm(S);
}