comparison lwasm/main.c @ 249:1f1a28b797e1

Add trap for divide by zero in expression library Added a trap for division by zero in the expression library and adjusted lwasm to use it and report division by zero errors instead of crashing with a cryptic "arithmetic exception" or even more mysterious "floating point exception".
author William Astle <lost@l-w.ca>
date Fri, 25 Jan 2013 21:48:01 -0700
parents 164487152dd9
children 49010c6653e7
comparison
equal deleted inserted replaced
248:891bab942b5a 249:1f1a28b797e1
220 extern void do_output(asmstate_t *as); 220 extern void do_output(asmstate_t *as);
221 extern void do_list(asmstate_t *as); 221 extern void do_list(asmstate_t *as);
222 extern lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv); 222 extern lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv);
223 extern lw_expr_t lwasm_evaluate_var(char *var, void *priv); 223 extern lw_expr_t lwasm_evaluate_var(char *var, void *priv);
224 extern lw_expr_t lwasm_parse_term(char **p, void *priv); 224 extern lw_expr_t lwasm_parse_term(char **p, void *priv);
225 extern void lwasm_dividezero(void *priv);
225 226
226 struct passlist_s 227 struct passlist_s
227 { 228 {
228 char *passname; 229 char *passname;
229 void (*fn)(asmstate_t *as); 230 void (*fn)(asmstate_t *as);
249 program_name = argv[0]; 250 program_name = argv[0];
250 251
251 lw_expr_set_special_handler(lwasm_evaluate_special); 252 lw_expr_set_special_handler(lwasm_evaluate_special);
252 lw_expr_set_var_handler(lwasm_evaluate_var); 253 lw_expr_set_var_handler(lwasm_evaluate_var);
253 lw_expr_set_term_parser(lwasm_parse_term); 254 lw_expr_set_term_parser(lwasm_parse_term);
255 lw_expr_setdivzero(lwasm_dividezero);
254 256
255 /* initialize assembler state */ 257 /* initialize assembler state */
256 asmstate.include_list = lw_stringlist_create(); 258 asmstate.include_list = lw_stringlist_create();
257 asmstate.input_files = lw_stringlist_create(); 259 asmstate.input_files = lw_stringlist_create();
258 asmstate.nextcontext = 1; 260 asmstate.nextcontext = 1;