Mercurial > hg-old > index.cgi
diff src/expr.c @ 76:2fe5fd7d65a3
Checkpointing object target implementation
author | lost |
---|---|
date | Thu, 08 Jan 2009 02:57:24 +0000 |
parents | 73423b66e511 |
children | 718998b673ee |
line wrap: on
line diff
--- a/src/expr.c Thu Jan 08 01:32:49 2009 +0000 +++ b/src/expr.c Thu Jan 08 02:57:24 2009 +0000 @@ -654,7 +654,7 @@ contain the pointer to the next character after the expression if and only if there is no error. In the case of an error, *outp is undefined. */ -lwasm_expr_stack_t *lwasm_expr_eval(const char *inp, const char **outp, int (*sfunc)(char *sym, void *state, int *val), void *state) +lwasm_expr_stack_t *lwasm_expr_eval(const char *inp, const char **outp, lwasm_expr_stack_t *(*sfunc)(char *sym, void *state), void *state) { lwasm_expr_stack_t *s; const char *p; @@ -703,26 +703,54 @@ further operators or only a single term remains */ -int lwasm_expr_reval(lwasm_expr_stack_t *s, int (*sfunc)(char *sym, void *state, int *val), void *state) +int lwasm_expr_reval(lwasm_expr_stack_t *s, lwasm_expr_stack_t *(*sfunc)(char *sym, void *state), void *state) { - lwasm_expr_stack_node_t *n; - int sval; + lwasm_expr_stack_node_t *n, *n2; + lwasm_expr_stack_t *ss; + int c; +next_iter_sym: // resolve symbols - // symbols that do not resolve to a constant are left alone - for (n = s -> head; n; n = n -> next) + // symbols that do not resolve to an expression are left alone + for (c = 0, n = s -> head; n; n = n -> next) { if (n -> term -> term_type == LWASM_TERM_SYM) { - if (sfunc(n -> term -> symbol, state, &sval) == 0) + ss = sfunc(n -> term -> symbol, state); + if (ss) { - n -> term -> term_type = LWASM_TERM_INT; - n -> term -> value = sval; - lwasm_free(n -> term -> symbol); - n -> term -> symbol = NULL; + c++; + // splice in the result stack + if (n -> prev) + { + n -> prev -> next = ss -> head; + } + else + { + s -> head = ss -> head; + } + ss -> head -> prev = n -> prev; + ss -> tail -> next = n -> next; + if (n -> next) + { + n -> next -> prev = ss -> tail; + } + else + { + s -> tail = ss -> tail; + } + lwasm_expr_term_free(n -> term); + lwasm_free(n); + n = ss -> tail; + + ss -> head = NULL; + ss -> tail = NULL; + lwasm_expr_stack_free(ss); } } } + if (c) + goto next_iter_sym; next_iter: // a single term