comparison src/lwasm.c @ 37:538e15927776

Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
author lost
date Sat, 03 Jan 2009 04:20:49 +0000
parents 9bd0fbfe7405
children 9bd584bb6296
comparison
equal deleted inserted replaced
36:99e3b3310bac 37:538e15927776
27 #include <stdlib.h> 27 #include <stdlib.h>
28 #include <stdio.h> 28 #include <stdio.h>
29 29
30 #include "lwasm.h" 30 #include "lwasm.h"
31 #include "util.h" 31 #include "util.h"
32 #include "expr.h"
32 33
33 int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...) 34 int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...)
34 { 35 {
35 lwasm_error_t *e; 36 lwasm_error_t *e;
36 va_list args; 37 va_list args;
145 (*str) += 2; 146 (*str) += 2;
146 else 147 else
147 (*str)+=3; 148 (*str)+=3;
148 return rval; 149 return rval;
149 } 150 }
151
152 struct symstateinfo
153 {
154 asmstate_t *as;
155 lwasm_line_t *l;
156 };
157
158 int lwasm_expr_lookup_symbol(char *sym, void *state, int *val)
159 {
160 lwasm_symbol_ent_t *se;
161 struct symstateinfo *st;
162
163 st = state;
164
165 // look for local symbol first then global symbol
166 se = lwasm_find_symbol(st -> as, sym, st -> as -> context);
167 if (!se)
168 se = lwasm_find_symbol(st -> as, sym, -1);
169 if (!se)
170 return -1;
171 *val = se -> value;
172 return 0;
173 }
174
175 lwasm_expr_stack_t *lwasm_evaluate_expr(asmstate_t *as, lwasm_line_t *l, const char *inp, const char **outp)
176 {
177 struct symstateinfo st;
178
179 st.as = as;
180 st.l = l;
181
182 return(lwasm_expr_eval(inp, outp, lwasm_expr_lookup_symbol, &st));
183 }