Implemented boolean shortcuts for ALLOF and ANYOF
Showing
1 changed file
with
15 additions
and
11 deletions
... | @@ -39,6 +39,10 @@ static void branch_fixup __P((size_t start, size_t end)); | ... | @@ -39,6 +39,10 @@ static void branch_fixup __P((size_t start, size_t end)); |
39 | list_t list; | 39 | list_t list; |
40 | size_t pc; | 40 | size_t pc; |
41 | struct { | 41 | struct { |
42 | size_t start; | ||
43 | size_t end; | ||
44 | } pclist; | ||
45 | struct { | ||
42 | char *ident; | 46 | char *ident; |
43 | list_t args; | 47 | list_t args; |
44 | } command; | 48 | } command; |
... | @@ -57,7 +61,7 @@ static void branch_fixup __P((size_t start, size_t end)); | ... | @@ -57,7 +61,7 @@ static void branch_fixup __P((size_t start, size_t end)); |
57 | %type <value> arg | 61 | %type <value> arg |
58 | %type <list> slist stringlist stringorlist arglist maybe_arglist | 62 | %type <list> slist stringlist stringorlist arglist maybe_arglist |
59 | %type <command> command | 63 | %type <command> command |
60 | %type <number> testlist | 64 | %type <pclist> testlist |
61 | %type <pc> action test statement list elsif else cond begin if block | 65 | %type <pc> action test statement list elsif else cond begin if block |
62 | %type <branch> elsif_branch maybe_elsif else_part | 66 | %type <branch> elsif_branch maybe_elsif else_part |
63 | 67 | ||
... | @@ -171,15 +175,19 @@ block : '{' list '}' | ... | @@ -171,15 +175,19 @@ block : '{' list '}' |
171 | 175 | ||
172 | testlist : cond_expr | 176 | testlist : cond_expr |
173 | { | 177 | { |
174 | if (sieve_code_instr (instr_push)) | 178 | $$.start = $$.end = sieve_machine->pc; |
179 | if (sieve_code_instr (instr_brz) | ||
180 | || sieve_code_number (0)) | ||
175 | YYERROR; | 181 | YYERROR; |
176 | $$ = 1; | ||
177 | } | 182 | } |
178 | | testlist ',' cond_expr | 183 | | testlist ',' cond_expr |
179 | { | 184 | { |
180 | if (sieve_code_instr (instr_push)) | 185 | sieve_machine->prog[$1.end+1].pc = sieve_machine->pc; |
186 | $1.end = sieve_machine->pc; | ||
187 | if (sieve_code_instr (instr_brz) | ||
188 | || sieve_code_number (0)) | ||
181 | YYERROR; | 189 | YYERROR; |
182 | $$ = $1 + 1; | 190 | $$ = $1; |
183 | } | 191 | } |
184 | ; | 192 | ; |
185 | 193 | ||
... | @@ -195,15 +203,11 @@ cond_expr : test | ... | @@ -195,15 +203,11 @@ cond_expr : test |
195 | { /* to placate bison */ } | 203 | { /* to placate bison */ } |
196 | | ANYOF '(' testlist ')' | 204 | | ANYOF '(' testlist ')' |
197 | { | 205 | { |
198 | if (sieve_code_instr (instr_anyof) | 206 | sieve_code_anyof ($3.start); |
199 | || sieve_code_number ($3)) | ||
200 | YYERROR; | ||
201 | } | 207 | } |
202 | | ALLOF '(' testlist ')' | 208 | | ALLOF '(' testlist ')' |
203 | { | 209 | { |
204 | if (sieve_code_instr (instr_allof) | 210 | sieve_code_allof ($3.start); |
205 | || sieve_code_number ($3)) | ||
206 | YYERROR; | ||
207 | } | 211 | } |
208 | | NOT cond_expr | 212 | | NOT cond_expr |
209 | { | 213 | { | ... | ... |
-
Please register or sign in to post a comment