summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2014-08-09 19:05:15 -0500
committerNicolas Williams <nico@cryptonector.com>2014-08-09 19:15:50 -0500
commit8a561120c41969439f786ee133d7d699ee8edd1b (patch)
tree463dc8101b83bf78e29a770a2edbf7c89ea7cb33
parent20ca21cb0d0025c69b8bf41d4d93541c289a8ddf (diff)
More constant folding: null, true, and false
A step towards doing constant folding for arrays and objects.
-rw-r--r--builtin.c3
-rw-r--r--parser.y10
2 files changed, 9 insertions, 4 deletions
diff --git a/builtin.c b/builtin.c
index 79f89af0..a526e40f 100644
--- a/builtin.c
+++ b/builtin.c
@@ -868,9 +868,6 @@ static block bind_bytecoded_builtins(block b) {
{
struct bytecoded_builtin builtin_defs[] = {
{"empty", gen_op_simple(BACKTRACK)},
- {"false", gen_const(jv_false())},
- {"true", gen_const(jv_true())},
- {"null", gen_const(jv_null())},
{"not", gen_condbranch(gen_const(jv_false()),
gen_const(jv_true()))}
};
diff --git a/parser.y b/parser.y
index 73fee5fa..8fffb7cc 100644
--- a/parser.y
+++ b/parser.y
@@ -638,7 +638,15 @@ FORMAT {
jv_free($2);
} |
IDENT {
- $$ = gen_location(@$, locations, gen_call(jv_string_value($1), gen_noop()));
+ const char *s = jv_string_value($1);
+ if (strcmp(s, "false") == 0)
+ $$ = gen_const(jv_false());
+ else if (strcmp(s, "true") == 0)
+ $$ = gen_const(jv_true());
+ else if (strcmp(s, "null") == 0)
+ $$ = gen_const(jv_null());
+ else
+ $$ = gen_location(@$, locations, gen_call(s, gen_noop()));
jv_free($1);
} |
IDENT '(' Args ')' {