diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2011-03-23 13:40:46 +0100 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2011-03-23 13:40:46 +0100 |
commit | 0aa88530ad3c58a6bdab886cabd9b2a4278486e8 (patch) | |
tree | 4ed5978852d806b49f013bb7bfb60ea843d5adc1 /filter/filter.c | |
parent | 26d92bb8921ac4e022cdc88bde8fc7bc617f8766 (diff) | |
download | bird-0aa88530ad3c58a6bdab886cabd9b2a4278486e8.tar bird-0aa88530ad3c58a6bdab886cabd9b2a4278486e8.zip |
Convert && and || to shortcut boolean operators.
Diffstat (limited to 'filter/filter.c')
-rw-r--r-- | filter/filter.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/filter/filter.c b/filter/filter.c index 8426a21..b804429 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -523,16 +523,21 @@ interpret(struct f_inst *what) break; case '&': - TWOARGS_C; - res.type = v1.type; - if (res.type != T_BOOL) runtime( "Can't do boolean operation on non-booleans" ); - res.val.i = v1.val.i && v2.val.i; - break; case '|': - TWOARGS_C; - res.type = v1.type; - if (res.type != T_BOOL) runtime( "Can't do boolean operation on non-booleans" ); - res.val.i = v1.val.i || v2.val.i; + ARG(v1, a1.p); + if (v1.type != T_BOOL) + runtime( "Can't do boolean operation on non-booleans" ); + if (v1.val.i == (what->code == '|')) { + res.type = T_BOOL; + res.val.i = v1.val.i; + break; + } + + ARG(v2, a2.p); + if (v2.type != T_BOOL) + runtime( "Can't do boolean operation on non-booleans" ); + res.type = T_BOOL; + res.val.i = v2.val.i; break; case P('m','p'): @@ -577,6 +582,7 @@ interpret(struct f_inst *what) res.val.i = val_in_range(v1, v2); if (res.val.i == CMP_ERROR) runtime( "~ applied on unknown type pair" ); + res.val.i = !!res.val.i; break; case P('d','e'): ONEARG; |