Make "not" a builtin function rather than syntax.

Fixes a really awkward grammar issue.
This commit is contained in:
Stephen Dolan committed 2012-09-17 21:08:43 +01:00
1 parent 297a0679d1
commit 830610cef8
6 files changed
+10 -14

No files matched your search

+7
View File
@@ -159,6 +159,12 @@ static block j_null() {
gen_op_simple(RET))); gen_op_simple(RET)));
} }
static block j_not() {
return gen_op_block_defn(CLOSURE_CREATE, "not",
block_join(gen_condbranch(gen_op_const(LOADK, jv_false()),
gen_op_const(LOADK, jv_true())),
gen_op_simple(RET)));
}
static struct cfunction function_list[] = { static struct cfunction function_list[] = {
{f_plus, "_plus", CALL_BUILTIN_3_1}, {f_plus, "_plus", CALL_BUILTIN_3_1},
@@ -179,6 +185,7 @@ static bytecoded_builtin bytecoded_builtins[] = {
j_false, j_false,
j_true, j_true,
j_null, j_null,
j_not,
}; };
+1 -6
View File
@@ -361,7 +361,7 @@ block gen_definedor(block a, block b) {
return c; return c;
} }
static block gen_condbranch(block iftrue, block iffalse) { block gen_condbranch(block iftrue, block iffalse) {
block b = gen_noop(); block b = gen_noop();
block_append(&iftrue, gen_op_target(JUMP, iffalse)); block_append(&iftrue, gen_op_target(JUMP, iffalse));
block_append(&b, gen_op_target(JUMP_F, iftrue)); block_append(&b, gen_op_target(JUMP_F, iftrue));
@@ -398,11 +398,6 @@ block gen_or(block a, block b) {
return code; return code;
} }
block gen_not(block a) {
return block_join(a, gen_condbranch(gen_op_const(LOADK, jv_false()),
gen_op_const(LOADK, jv_true())));
}
block gen_cond(block cond, block iftrue, block iffalse) { block gen_cond(block cond, block iftrue, block iffalse) {
block b = gen_op_simple(DUP); block b = gen_op_simple(DUP);
block_append(&b, cond); block_append(&b, cond);
+1 -1
View File
@@ -32,9 +32,9 @@ block gen_both(block a, block b);
block gen_collect(block expr); block gen_collect(block expr);
block gen_assign(block expr); block gen_assign(block expr);
block gen_definedor(block a, block b); block gen_definedor(block a, block b);
block gen_condbranch(block iftrue, block iffalse);
block gen_and(block a, block b); block gen_and(block a, block b);
block gen_or(block a, block b); block gen_or(block a, block b);
block gen_not(block a);
block gen_cond(block cond, block iftrue, block iffalse); block gen_cond(block cond, block iftrue, block iffalse);
-1
View File
@@ -40,7 +40,6 @@
"elif" { return ELSE_IF; } "elif" { return ELSE_IF; }
"and" { return AND; } "and" { return AND; }
"or" { return OR; } "or" { return OR; }
"not" { return NOT; }
"end" { return END; } "end" { return END; }
"//" { return DEFINEDOR; } "//" { return DEFINEDOR; }
"|=" { return SETPIPE; } "|=" { return SETPIPE; }
-5
View File
@@ -53,7 +53,6 @@
%token END "end" %token END "end"
%token AND "and" %token AND "and"
%token OR "or" %token OR "or"
%token NOT "not"
%token SETPIPE "|=" %token SETPIPE "|="
%token SETPLUS "+=" %token SETPLUS "+="
%token SETMINUS "-=" %token SETMINUS "-="
@@ -210,10 +209,6 @@ Exp "and" Exp {
$$ = gen_and($1, $3); $$ = gen_and($1, $3);
} | } |
"not" Exp {
$$ = gen_not($2);
} |
Exp "//" Exp { Exp "//" Exp {
$$ = gen_definedor($1, $3); $$ = gen_definedor($1, $3);
} | } |
+1 -1
View File
@@ -331,6 +331,6 @@ def inc(x): x |= .+1; inc(.[].a)
[false,true] [false,true]
[false,false] [false,false]
[.[] | not .] [.[] | not]
[1,0,false,null,true,"hello"] [1,0,false,null,true,"hello"]
[false,false,true,true,false,false] [false,false,true,true,false,false]