From 76cc61fa516e4c7ff4ebec6bb2832fff90c4d1a0 Mon Sep 17 00:00:00 2001 From: Jan Maria Matejka Date: Wed, 30 May 2018 17:18:56 +0200 Subject: [PATCH] Filter: Make the IF instruction three-args Dropping another old quirk. --- filter/config.Y | 8 +++----- filter/filter.c | 11 +++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/filter/config.Y b/filter/config.Y index bbb8a640..5d4372f6 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -989,12 +989,10 @@ cmd: $$->a2.p = $4; } | IF term THEN block ELSE block { - struct f_inst *i = f_new_inst(FI_CONDITION); - i->a1.p = $2; - i->a2.p = $4; $$ = f_new_inst(FI_CONDITION); - $$->a1.p = i; - $$->a2.p = $6; + $$->a1.p = $2; + $$->a2.p = $4; + $$->a3.p = $6; } | SYM '=' term ';' { DBG( "Ook, we'll set value\n" ); diff --git a/filter/filter.c b/filter/filter.c index 0a2c26b8..745fcf71 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -897,14 +897,13 @@ interpret(struct f_inst *what) ARG_ANY(1); val_format(v1, &f_buf); break; - case FI_CONDITION: /* ? has really strange error value, so we can implement if ... else nicely :-) */ + case FI_CONDITION: ARG(1, T_BOOL); if (v1.val.i) { ARG_ANY(2); - res.val.i = 0; - } else - res.val.i = 1; - res.type = T_BOOL; + } else { + ARG_ANY(3); + } break; case FI_NOP: debug( "No operation\n" ); @@ -1669,7 +1668,7 @@ i_same(struct f_inst *f1, struct f_inst *f2) return 0; break; case FI_PRINT: case FI_LENGTH: ONEARG; break; - case FI_CONDITION: TWOARGS; break; + case FI_CONDITION: THREEARGS; break; case FI_NOP: case FI_EMPTY: break; case FI_PRINT_AND_DIE: ONEARG; A2_SAME; break; case FI_PREF_GET: