diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-20 21:45:57 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-20 21:45:57 +0100 |
commit | fa8891ffe017ae890f0ef07915cf8b52acd7304a (patch) | |
tree | 7478faee1981c1c98ee5e88e6c56529f83a64817 /com.c | |
parent | 9a7d1b1d41f4b3bb3387e7bbe77105d0089803d0 (diff) |
add true, false, nil keywords
Diffstat (limited to 'com.c')
-rw-r--r-- | com.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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); } |