Reflect change of sieve_machine_t type.
Showing
2 changed files
with
90 additions
and
38 deletions
... | @@ -26,11 +26,13 @@ | ... | @@ -26,11 +26,13 @@ |
26 | #define SIEVE_ARG(m,n,t) ((m)->prog[(m)->pc+(n)].t) | 26 | #define SIEVE_ARG(m,n,t) ((m)->prog[(m)->pc+(n)].t) |
27 | #define SIEVE_ADJUST(m,n) (m)->pc+=(n) | 27 | #define SIEVE_ADJUST(m,n) (m)->pc+=(n) |
28 | 28 | ||
29 | #define INSTR_DEBUG(m) ((m)->debug_level > 90 && (m)->debug_printer) | 29 | #define INSTR_DEBUG(m) \ |
30 | #define INSTR_DISASS(m) ((m)->debug_level == 100) | 30 | (((m)->debug_level & (MU_SIEVE_DEBUG_INSTR|MU_SIEVE_DEBUG_DISAS)) \ |
31 | && (m)->debug_printer) | ||
32 | #define INSTR_DISASS(m) ((m)->debug_level & MU_SIEVE_DEBUG_DISAS) | ||
31 | 33 | ||
32 | static int | 34 | static int |
33 | instr_run (sieve_machine_t *mach) | 35 | instr_run (sieve_machine_t mach) |
34 | { | 36 | { |
35 | sieve_handler_t han = SIEVE_ARG (mach, 0, handler); | 37 | sieve_handler_t han = SIEVE_ARG (mach, 0, handler); |
36 | list_t arg_list = SIEVE_ARG (mach, 1, list); | 38 | list_t arg_list = SIEVE_ARG (mach, 1, list); |
... | @@ -52,7 +54,7 @@ instr_run (sieve_machine_t *mach) | ... | @@ -52,7 +54,7 @@ instr_run (sieve_machine_t *mach) |
52 | } | 54 | } |
53 | 55 | ||
54 | void | 56 | void |
55 | instr_action (sieve_machine_t *mach) | 57 | instr_action (sieve_machine_t mach) |
56 | { | 58 | { |
57 | if (INSTR_DEBUG (mach)) | 59 | if (INSTR_DEBUG (mach)) |
58 | sieve_debug (mach, "%4lu: ACTION: %s\n", | 60 | sieve_debug (mach, "%4lu: ACTION: %s\n", |
... | @@ -62,7 +64,7 @@ instr_action (sieve_machine_t *mach) | ... | @@ -62,7 +64,7 @@ instr_action (sieve_machine_t *mach) |
62 | } | 64 | } |
63 | 65 | ||
64 | void | 66 | void |
65 | instr_test (sieve_machine_t *mach) | 67 | instr_test (sieve_machine_t mach) |
66 | { | 68 | { |
67 | if (INSTR_DEBUG (mach)) | 69 | if (INSTR_DEBUG (mach)) |
68 | sieve_debug (mach, "%4lu: TEST: %s\n", | 70 | sieve_debug (mach, "%4lu: TEST: %s\n", |
... | @@ -72,7 +74,7 @@ instr_test (sieve_machine_t *mach) | ... | @@ -72,7 +74,7 @@ instr_test (sieve_machine_t *mach) |
72 | } | 74 | } |
73 | 75 | ||
74 | void | 76 | void |
75 | instr_push (sieve_machine_t *mach) | 77 | instr_push (sieve_machine_t mach) |
76 | { | 78 | { |
77 | if (INSTR_DEBUG (mach)) | 79 | if (INSTR_DEBUG (mach)) |
78 | { | 80 | { |
... | @@ -90,7 +92,7 @@ instr_push (sieve_machine_t *mach) | ... | @@ -90,7 +92,7 @@ instr_push (sieve_machine_t *mach) |
90 | } | 92 | } |
91 | 93 | ||
92 | void | 94 | void |
93 | instr_pop (sieve_machine_t *mach) | 95 | instr_pop (sieve_machine_t mach) |
94 | { | 96 | { |
95 | if (INSTR_DEBUG (mach)) | 97 | if (INSTR_DEBUG (mach)) |
96 | { | 98 | { |
... | @@ -109,7 +111,7 @@ instr_pop (sieve_machine_t *mach) | ... | @@ -109,7 +111,7 @@ instr_pop (sieve_machine_t *mach) |
109 | } | 111 | } |
110 | 112 | ||
111 | void | 113 | void |
112 | instr_allof (sieve_machine_t *mach) | 114 | instr_allof (sieve_machine_t mach) |
113 | { | 115 | { |
114 | int num = SIEVE_ARG (mach, 0, number); | 116 | int num = SIEVE_ARG (mach, 0, number); |
115 | int val = 1; | 117 | int val = 1; |
... | @@ -133,7 +135,7 @@ instr_allof (sieve_machine_t *mach) | ... | @@ -133,7 +135,7 @@ instr_allof (sieve_machine_t *mach) |
133 | } | 135 | } |
134 | 136 | ||
135 | void | 137 | void |
136 | instr_anyof (sieve_machine_t *mach) | 138 | instr_anyof (sieve_machine_t mach) |
137 | { | 139 | { |
138 | int num = SIEVE_ARG (mach, 0, number); | 140 | int num = SIEVE_ARG (mach, 0, number); |
139 | int val = 0; | 141 | int val = 0; |
... | @@ -151,13 +153,13 @@ instr_anyof (sieve_machine_t *mach) | ... | @@ -151,13 +153,13 @@ instr_anyof (sieve_machine_t *mach) |
151 | while (num-- > 0) | 153 | while (num-- > 0) |
152 | { | 154 | { |
153 | instr_pop (mach); | 155 | instr_pop (mach); |
154 | val &= mach->reg; | 156 | val |= mach->reg; |
155 | } | 157 | } |
156 | mach->reg = val; | 158 | mach->reg = val; |
157 | } | 159 | } |
158 | 160 | ||
159 | void | 161 | void |
160 | instr_not (sieve_machine_t *mach) | 162 | instr_not (sieve_machine_t mach) |
161 | { | 163 | { |
162 | if (INSTR_DEBUG (mach)) | 164 | if (INSTR_DEBUG (mach)) |
163 | { | 165 | { |
... | @@ -169,7 +171,7 @@ instr_not (sieve_machine_t *mach) | ... | @@ -169,7 +171,7 @@ instr_not (sieve_machine_t *mach) |
169 | } | 171 | } |
170 | 172 | ||
171 | void | 173 | void |
172 | instr_branch (sieve_machine_t *mach) | 174 | instr_branch (sieve_machine_t mach) |
173 | { | 175 | { |
174 | long num = SIEVE_ARG (mach, 0, number); | 176 | long num = SIEVE_ARG (mach, 0, number); |
175 | 177 | ||
... | @@ -187,7 +189,7 @@ instr_branch (sieve_machine_t *mach) | ... | @@ -187,7 +189,7 @@ instr_branch (sieve_machine_t *mach) |
187 | } | 189 | } |
188 | 190 | ||
189 | void | 191 | void |
190 | instr_brz (sieve_machine_t *mach) | 192 | instr_brz (sieve_machine_t mach) |
191 | { | 193 | { |
192 | long num = SIEVE_ARG (mach, 0, number); | 194 | long num = SIEVE_ARG (mach, 0, number); |
193 | SIEVE_ADJUST (mach, 1); | 195 | SIEVE_ADJUST (mach, 1); |
... | @@ -201,24 +203,24 @@ instr_brz (sieve_machine_t *mach) | ... | @@ -201,24 +203,24 @@ instr_brz (sieve_machine_t *mach) |
201 | return; | 203 | return; |
202 | } | 204 | } |
203 | 205 | ||
204 | if (mach->reg) | 206 | if (!mach->reg) |
205 | mach->pc += num; | 207 | mach->pc += num; |
206 | } | 208 | } |
207 | 209 | ||
208 | void | 210 | void |
209 | sieve_abort (sieve_machine_t *mach) | 211 | sieve_abort (sieve_machine_t mach) |
210 | { | 212 | { |
211 | longjmp (mach->errbuf, 1); | 213 | longjmp (mach->errbuf, 1); |
212 | } | 214 | } |
213 | 215 | ||
214 | void * | 216 | void * |
215 | sieve_get_data (sieve_machine_t *mach) | 217 | sieve_get_data (sieve_machine_t mach) |
216 | { | 218 | { |
217 | return mach->data; | 219 | return mach->data; |
218 | } | 220 | } |
219 | 221 | ||
220 | message_t | 222 | message_t |
221 | sieve_get_message (sieve_machine_t *mach) | 223 | sieve_get_message (sieve_machine_t mach) |
222 | { | 224 | { |
223 | if (!mach->msg) | 225 | if (!mach->msg) |
224 | mailbox_get_message (mach->mailbox, mach->msgno, &mach->msg); | 226 | mailbox_get_message (mach->mailbox, mach->msgno, &mach->msg); |
... | @@ -226,19 +228,25 @@ sieve_get_message (sieve_machine_t *mach) | ... | @@ -226,19 +228,25 @@ sieve_get_message (sieve_machine_t *mach) |
226 | } | 228 | } |
227 | 229 | ||
228 | size_t | 230 | size_t |
229 | sieve_get_message_num (sieve_machine_t *mach) | 231 | sieve_get_message_num (sieve_machine_t mach) |
230 | { | 232 | { |
231 | return mach->msgno; | 233 | return mach->msgno; |
232 | } | 234 | } |
233 | 235 | ||
234 | int | 236 | int |
235 | sieve_get_debug_level (sieve_machine_t *mach) | 237 | sieve_get_debug_level (sieve_machine_t mach) |
236 | { | 238 | { |
237 | return mach->debug_level; | 239 | return mach->debug_level; |
238 | } | 240 | } |
239 | 241 | ||
240 | int | 242 | int |
241 | sieve_run (sieve_machine_t *mach) | 243 | sieve_is_dry_run (sieve_machine_t mach) |
244 | { | ||
245 | return mach->debug_level & MU_SIEVE_DRY_RUN; | ||
246 | } | ||
247 | |||
248 | int | ||
249 | sieve_run (sieve_machine_t mach) | ||
242 | { | 250 | { |
243 | if (setjmp (mach->errbuf)) | 251 | if (setjmp (mach->errbuf)) |
244 | return 1; | 252 | return 1; |
... | @@ -253,12 +261,12 @@ sieve_run (sieve_machine_t *mach) | ... | @@ -253,12 +261,12 @@ sieve_run (sieve_machine_t *mach) |
253 | } | 261 | } |
254 | 262 | ||
255 | int | 263 | int |
256 | sieve_disass (sieve_machine_t *mach) | 264 | sieve_disass (sieve_machine_t mach) |
257 | { | 265 | { |
258 | int level = mach->debug_level; | 266 | int level = mach->debug_level; |
259 | int rc; | 267 | int rc; |
260 | 268 | ||
261 | mach->debug_level = 100; | 269 | mach->debug_level = MU_SIEVE_DEBUG_INSTR | MU_SIEVE_DEBUG_DISAS; |
262 | rc = sieve_run (mach); | 270 | rc = sieve_run (mach); |
263 | mach->debug_level = level; | 271 | mach->debug_level = level; |
264 | return rc; | 272 | return rc; |
... | @@ -267,7 +275,7 @@ sieve_disass (sieve_machine_t *mach) | ... | @@ -267,7 +275,7 @@ sieve_disass (sieve_machine_t *mach) |
267 | static int | 275 | static int |
268 | _sieve_action (observer_t obs, size_t type) | 276 | _sieve_action (observer_t obs, size_t type) |
269 | { | 277 | { |
270 | sieve_machine_t *mach; | 278 | sieve_machine_t mach; |
271 | 279 | ||
272 | if (type != MU_EVT_MESSAGE_ADD) | 280 | if (type != MU_EVT_MESSAGE_ADD) |
273 | return 0; | 281 | return 0; |
... | @@ -280,7 +288,7 @@ _sieve_action (observer_t obs, size_t type) | ... | @@ -280,7 +288,7 @@ _sieve_action (observer_t obs, size_t type) |
280 | } | 288 | } |
281 | 289 | ||
282 | int | 290 | int |
283 | sieve_mailbox (sieve_machine_t *mach, mailbox_t mbox) | 291 | sieve_mailbox (sieve_machine_t mach, mailbox_t mbox) |
284 | { | 292 | { |
285 | int rc; | 293 | int rc; |
286 | size_t total; | 294 | size_t total; |
... | @@ -291,7 +299,7 @@ sieve_mailbox (sieve_machine_t *mach, mailbox_t mbox) | ... | @@ -291,7 +299,7 @@ sieve_mailbox (sieve_machine_t *mach, mailbox_t mbox) |
291 | return EINVAL; | 299 | return EINVAL; |
292 | 300 | ||
293 | observer_create (&observer, mach); | 301 | observer_create (&observer, mach); |
294 | observer_set_action (observer, _sieve_action, mbox); | 302 | observer_set_action (observer, _sieve_action, mach); |
295 | mailbox_get_observable (mbox, &observable); | 303 | mailbox_get_observable (mbox, &observable); |
296 | observable_attach (observable, MU_EVT_MESSAGE_ADD, observer); | 304 | observable_attach (observable, MU_EVT_MESSAGE_ADD, observer); |
297 | 305 | ... | ... |
... | @@ -24,7 +24,7 @@ | ... | @@ -24,7 +24,7 @@ |
24 | #include <assert.h> | 24 | #include <assert.h> |
25 | #include <sieve.h> | 25 | #include <sieve.h> |
26 | 26 | ||
27 | sieve_machine_t *sieve_machine; | 27 | sieve_machine_t sieve_machine; |
28 | int sieve_error_count; | 28 | int sieve_error_count; |
29 | 29 | ||
30 | static void branch_fixup __P((size_t start, size_t end)); | 30 | static void branch_fixup __P((size_t start, size_t end)); |
... | @@ -336,42 +336,80 @@ yyerror (char *s) | ... | @@ -336,42 +336,80 @@ yyerror (char *s) |
336 | return 0; | 336 | return 0; |
337 | } | 337 | } |
338 | 338 | ||
339 | void | 339 | int |
340 | sieve_machine_init (sieve_machine_t *mach, void *data) | 340 | sieve_machine_init (sieve_machine_t *pmach, void *data) |
341 | { | 341 | { |
342 | int rc; | ||
343 | sieve_machine_t mach; | ||
344 | |||
345 | mach = malloc (sizeof (*mach)); | ||
346 | if (!mach) | ||
347 | return ENOMEM; | ||
342 | memset (mach, 0, sizeof (*mach)); | 348 | memset (mach, 0, sizeof (*mach)); |
349 | rc = list_create (&mach->memory_pool); | ||
350 | if (rc) | ||
351 | { | ||
352 | free (mach); | ||
353 | return NULL; | ||
354 | } | ||
355 | list_append (mach->memory_pool, mach); | ||
356 | |||
343 | mach->data = data; | 357 | mach->data = data; |
344 | mach->error_printer = _sieve_default_error_printer; | 358 | mach->error_printer = _sieve_default_error_printer; |
345 | mach->parse_error_printer = _sieve_default_parse_error; | 359 | mach->parse_error_printer = _sieve_default_parse_error; |
360 | *pmach = mach; | ||
361 | return 0; | ||
346 | } | 362 | } |
347 | 363 | ||
348 | void | 364 | void |
349 | sieve_machine_set_error (sieve_machine_t *mach, sieve_printf_t error_printer) | 365 | sieve_machine_set_error (sieve_machine_t mach, sieve_printf_t error_printer) |
350 | { | 366 | { |
351 | mach->error_printer = error_printer ? | 367 | mach->error_printer = error_printer ? |
352 | error_printer : _sieve_default_error_printer; | 368 | error_printer : _sieve_default_error_printer; |
353 | } | 369 | } |
354 | 370 | ||
355 | void | 371 | void |
356 | sieve_machine_set_parse_error (sieve_machine_t *mach, sieve_parse_error_t p) | 372 | sieve_machine_set_parse_error (sieve_machine_t mach, sieve_parse_error_t p) |
357 | { | 373 | { |
358 | mach->parse_error_printer = p ? p : _sieve_default_parse_error; | 374 | mach->parse_error_printer = p ? p : _sieve_default_parse_error; |
359 | } | 375 | } |
360 | 376 | ||
361 | void | 377 | void |
362 | sieve_machine_set_debug (sieve_machine_t *mach, | 378 | sieve_machine_set_debug (sieve_machine_t mach, sieve_printf_t debug) |
363 | sieve_printf_t debug, int level) | ||
364 | { | 379 | { |
365 | if (debug) | 380 | mach->debug_printer = debug; |
366 | mach->debug_printer = debug; | 381 | } |
382 | |||
383 | void | ||
384 | sieve_machine_set_debug_level (sieve_machine_t mach, mu_debug_t dbg, int level) | ||
385 | { | ||
386 | mach->mu_debug = dbg; | ||
367 | mach->debug_level = level; | 387 | mach->debug_level = level; |
368 | } | 388 | } |
369 | 389 | ||
390 | void | ||
391 | sieve_machine_set_logger (sieve_machine_t mach, sieve_action_log_t logger) | ||
392 | { | ||
393 | mach->logger = logger; | ||
394 | } | ||
395 | |||
396 | void | ||
397 | sieve_machine_set_ticket (sieve_machine_t mach, ticket_t ticket) | ||
398 | { | ||
399 | mach->ticket = ticket; | ||
400 | } | ||
401 | |||
402 | ticket_t | ||
403 | sieve_get_ticket (sieve_machine_t mach) | ||
404 | { | ||
405 | return mach->ticket; | ||
406 | } | ||
407 | |||
370 | /* FIXME: When posix thread support is added, sieve_machine_begin() should | 408 | /* FIXME: When posix thread support is added, sieve_machine_begin() should |
371 | acquire the global mutex, locking the current compilation session, and | 409 | acquire the global mutex, locking the current compilation session, and |
372 | sieve_machine_finish() should release it */ | 410 | sieve_machine_finish() should release it */ |
373 | void | 411 | void |
374 | sieve_machine_begin (sieve_machine_t *mach) | 412 | sieve_machine_begin (sieve_machine_t mach) |
375 | { | 413 | { |
376 | sieve_machine = mach; | 414 | sieve_machine = mach; |
377 | sieve_error_count = 0; | 415 | sieve_error_count = 0; |
... | @@ -379,22 +417,28 @@ sieve_machine_begin (sieve_machine_t *mach) | ... | @@ -379,22 +417,28 @@ sieve_machine_begin (sieve_machine_t *mach) |
379 | } | 417 | } |
380 | 418 | ||
381 | void | 419 | void |
382 | sieve_machine_finish (sieve_machine_t *mach) | 420 | sieve_machine_finish (sieve_machine_t mach) |
383 | { | 421 | { |
384 | sieve_code_instr (NULL); | 422 | sieve_code_instr (NULL); |
385 | } | 423 | } |
386 | 424 | ||
387 | int | 425 | int |
388 | sieve_compile (sieve_machine_t *mach, const char *name) | 426 | sieve_compile (sieve_machine_t mach, const char *name) |
389 | { | 427 | { |
390 | int rc; | 428 | int rc; |
391 | 429 | ||
392 | sieve_machine_begin (mach); | 430 | sieve_machine_begin (mach); |
393 | sieve_register_standard_actions (); | 431 | sieve_register_standard_actions (); |
394 | sieve_register_standard_tests (); | 432 | sieve_register_standard_tests (); |
395 | sieve_lex_begin (name); | 433 | if (sieve_lex_begin (name) == 0) |
434 | { | ||
435 | sieve_machine->filename = sieve_pstrdup (&sieve_machine->memory_pool, | ||
436 | name); | ||
396 | rc = yyparse (); | 437 | rc = yyparse (); |
397 | sieve_lex_finish (); | 438 | sieve_lex_finish (); |
439 | } | ||
440 | else | ||
441 | rc = 1; | ||
398 | sieve_machine_finish (mach); | 442 | sieve_machine_finish (mach); |
399 | if (sieve_error_count) | 443 | if (sieve_error_count) |
400 | rc = 1; | 444 | rc = 1; | ... | ... |
-
Please register or sign in to post a comment