Mercurial > hg-old > index.cgi
comparison src/lwasm.c @ 55:8e32696380f3
added expression evaluation and checking function
author | lost |
---|---|
date | Sun, 04 Jan 2009 21:42:54 +0000 |
parents | b9856da2674a |
children | 035b95a3690f |
comparison
equal
deleted
inserted
replaced
54:360d53062bb9 | 55:8e32696380f3 |
---|---|
1 /* | 1 /* |
2 lwasm.c | 2 lwasm.c |
3 Copyright © 2008 William Astle | 3 Copyright © 2009 William Astle |
4 | 4 |
5 This file is part of LWASM. | 5 This file is part of LWASM. |
6 | 6 |
7 LWASM is free software: you can redistribute it and/or modify it under the | 7 LWASM is free software: you can redistribute it and/or modify it under the |
8 terms of the GNU General Public License as published by the Free Software | 8 terms of the GNU General Public License as published by the Free Software |
193 debug_message(2, "Evaluate expression: %s", inp); | 193 debug_message(2, "Evaluate expression: %s", inp); |
194 | 194 |
195 return(lwasm_expr_eval(inp, outp, lwasm_expr_lookup_symbol, &st)); | 195 return(lwasm_expr_eval(inp, outp, lwasm_expr_lookup_symbol, &st)); |
196 } | 196 } |
197 | 197 |
198 int lwasm_expr_result(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val) | |
199 { | |
200 lwasm_expr_stack_t *s; | |
201 char *ep; | |
202 int rval; | |
203 | |
204 s = lwasm_evaluate_expr(as, l, *inp, &ep); | |
205 if (!s) | |
206 { | |
207 register_error(as, l, 1, "Bad expression"); | |
208 *val = 0; | |
209 return -1; | |
210 } | |
211 *inp = ep; | |
212 | |
213 if (flag & EXPR_PASS1CONST && as -> passnum == 1 && !lwasm_expr_is_constant(s)) | |
214 { | |
215 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | |
216 *val = 0; | |
217 lwasm_expr_stack_free(s); | |
218 return -1; | |
219 } | |
220 if (flag & EXPR_PASS2CONST && as -> passnum == 2 && !lwasm_expr_is_constant(s)) | |
221 { | |
222 register_error(as, l, 2, "Incomplete reference (pass 2)"); | |
223 *val = 0; | |
224 lwasm_expr_stack_free(s); | |
225 return -1; | |
226 } | |
227 *val = lwasm_expr_get_value(s); | |
228 lwasm_expr_stack_free(s); | |
229 | |
230 if (flag & EXPR_BYTE && as -> passnum == 2 && (*val < -128 || *val > 255)) | |
231 { | |
232 register_error(as, l, 2, "Byte overflow"); | |
233 *val &= 0xff; | |
234 return -1; | |
235 } | |
236 if (flag & EXPR_BYTE) | |
237 { | |
238 *val &= 0xff; | |
239 } | |
240 | |
241 return 0; | |
242 } | |
243 | |
198 void debug_message(int level, const char *fmt, ...) | 244 void debug_message(int level, const char *fmt, ...) |
199 { | 245 { |
200 va_list args; | 246 va_list args; |
201 | 247 |
202 va_start(args, fmt); | 248 va_start(args, fmt); |