Mercurial > hg-old > index.cgi
comparison src/expr.c @ 76:2fe5fd7d65a3
Checkpointing object target implementation
author | lost |
---|---|
date | Thu, 08 Jan 2009 02:57:24 +0000 |
parents | 73423b66e511 |
children | 718998b673ee |
comparison
equal
deleted
inserted
replaced
75:92eb93bffa28 | 76:2fe5fd7d65a3 |
---|---|
652 | 652 |
653 Returns NULL on a parse error or otherwise invalid expression. *outp will | 653 Returns NULL on a parse error or otherwise invalid expression. *outp will |
654 contain the pointer to the next character after the expression if and only | 654 contain the pointer to the next character after the expression if and only |
655 if there is no error. In the case of an error, *outp is undefined. | 655 if there is no error. In the case of an error, *outp is undefined. |
656 */ | 656 */ |
657 lwasm_expr_stack_t *lwasm_expr_eval(const char *inp, const char **outp, int (*sfunc)(char *sym, void *state, int *val), void *state) | 657 lwasm_expr_stack_t *lwasm_expr_eval(const char *inp, const char **outp, lwasm_expr_stack_t *(*sfunc)(char *sym, void *state), void *state) |
658 { | 658 { |
659 lwasm_expr_stack_t *s; | 659 lwasm_expr_stack_t *s; |
660 const char *p; | 660 const char *p; |
661 int rval; | 661 int rval; |
662 | 662 |
701 | 701 |
702 repeat the scan until no futher simplications are found or if there are no | 702 repeat the scan until no futher simplications are found or if there are no |
703 further operators or only a single term remains | 703 further operators or only a single term remains |
704 | 704 |
705 */ | 705 */ |
706 int lwasm_expr_reval(lwasm_expr_stack_t *s, int (*sfunc)(char *sym, void *state, int *val), void *state) | 706 int lwasm_expr_reval(lwasm_expr_stack_t *s, lwasm_expr_stack_t *(*sfunc)(char *sym, void *state), void *state) |
707 { | 707 { |
708 lwasm_expr_stack_node_t *n; | 708 lwasm_expr_stack_node_t *n, *n2; |
709 int sval; | 709 lwasm_expr_stack_t *ss; |
710 | 710 int c; |
711 | |
712 next_iter_sym: | |
711 // resolve symbols | 713 // resolve symbols |
712 // symbols that do not resolve to a constant are left alone | 714 // symbols that do not resolve to an expression are left alone |
713 for (n = s -> head; n; n = n -> next) | 715 for (c = 0, n = s -> head; n; n = n -> next) |
714 { | 716 { |
715 if (n -> term -> term_type == LWASM_TERM_SYM) | 717 if (n -> term -> term_type == LWASM_TERM_SYM) |
716 { | 718 { |
717 if (sfunc(n -> term -> symbol, state, &sval) == 0) | 719 ss = sfunc(n -> term -> symbol, state); |
720 if (ss) | |
718 { | 721 { |
719 n -> term -> term_type = LWASM_TERM_INT; | 722 c++; |
720 n -> term -> value = sval; | 723 // splice in the result stack |
721 lwasm_free(n -> term -> symbol); | 724 if (n -> prev) |
722 n -> term -> symbol = NULL; | 725 { |
726 n -> prev -> next = ss -> head; | |
727 } | |
728 else | |
729 { | |
730 s -> head = ss -> head; | |
731 } | |
732 ss -> head -> prev = n -> prev; | |
733 ss -> tail -> next = n -> next; | |
734 if (n -> next) | |
735 { | |
736 n -> next -> prev = ss -> tail; | |
737 } | |
738 else | |
739 { | |
740 s -> tail = ss -> tail; | |
741 } | |
742 lwasm_expr_term_free(n -> term); | |
743 lwasm_free(n); | |
744 n = ss -> tail; | |
745 | |
746 ss -> head = NULL; | |
747 ss -> tail = NULL; | |
748 lwasm_expr_stack_free(ss); | |
723 } | 749 } |
724 } | 750 } |
725 } | 751 } |
752 if (c) | |
753 goto next_iter_sym; | |
726 | 754 |
727 next_iter: | 755 next_iter: |
728 // a single term | 756 // a single term |
729 if (s -> head == s -> tail) | 757 if (s -> head == s -> tail) |
730 return 0; | 758 return 0; |