comparison src/lwasm.c @ 79:d0ce3f5f6797

Checkpointing deployment of non-constant expression handling
author lost
date Sat, 10 Jan 2009 07:09:14 +0000
parents 121bf4a588ea
children e12edcfbebd5
comparison
equal deleted inserted replaced
78:121bf4a588ea 79:d0ce3f5f6797
382 return 0; 382 return 0;
383 } 383 }
384 */ 384 */
385 int lwasm_expr_result2(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val, int slot) 385 int lwasm_expr_result2(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val, int slot)
386 { 386 {
387 lwasm_expr_stack_t *s; 387 lwasm_expr_stack_t *s = NULL;
388 const char *ep; 388 const char *ep;
389 int rval; 389 int rval;
390 390
391 if (as -> passnum == 1) 391 if (as -> passnum == 1 || slot < 0)
392 { 392 {
393 s = lwasm_evaluate_expr(as, l, *inp, &ep); 393 s = lwasm_evaluate_expr(as, l, *inp, &ep);
394 l -> exprs[slot] = s; 394 if (slot >= 0)
395 l -> exprs[slot] = s;
395 if (!s) 396 if (!s)
396 { 397 {
397 register_error(as, l, 1, "Bad expression"); 398 register_error(as, l, 1, "Bad expression");
398 *val = 0; 399 *val = 0;
399 return -1; 400 return -1;
400 } 401 }
401 *inp = (char *)ep; 402 *inp = (char *)ep;
402 l -> exprends[slot] = *inp; 403 if (slot >= 0)
403 l -> exprvals[slot] = lwasm_expr_get_value(s); 404 {
405 l -> exprends[slot] = *inp;
406 l -> exprvals[slot] = lwasm_expr_get_value(s);
407 }
404 } 408 }
405 else if (l -> exprs[slot]) 409 else if (l -> exprs[slot])
406 { 410 {
407 s = l -> exprs[slot]; 411 s = l -> exprs[slot];
408 *inp = l -> exprends[slot]; 412 *inp = l -> exprends[slot];
415 lwasm_expr_stack_free(s); 419 lwasm_expr_stack_free(s);
416 l -> exprs[slot] = NULL; 420 l -> exprs[slot] = NULL;
417 s = NULL; 421 s = NULL;
418 } 422 }
419 423
420 if (!s) 424 if (!s && slot >= 0)
421 { 425 {
422 *val = l -> exprvals[slot]; 426 *val = l -> exprvals[slot];
427 return 0;
428 }
429 else if (!s)
430 {
431 *val = 0;
423 return 0; 432 return 0;
424 } 433 }
425 434
426 // was a constant result on pass 1 requested? 435 // was a constant result on pass 1 requested?
427 // that means we must have a constant on either pass 436 // that means we must have a constant on either pass
428 if (flag & EXPR_PASS1CONST) 437 if (flag & EXPR_PASS1CONST)
429 { 438 {
430 *val = 0; 439 *val = 0;
431 l -> exprvals[slot] = 0; 440 if (slot >= 0)
441 l -> exprvals[slot] = 0;
432 register_error(as, l, 1, "Illegal forward, external, or inter-section reference"); 442 register_error(as, l, 1, "Illegal forward, external, or inter-section reference");
433 lwasm_expr_stack_free(s); 443 lwasm_expr_stack_free(s);
434 l -> exprs[slot] = NULL; 444 if (slot >= 0)
445 l -> exprs[slot] = NULL;
435 return -1; 446 return -1;
436 } 447 }
437 448
438 return 1; 449 return 1;
439 } 450 }