changeset 59:89657cb3fdf8

Moved insn_rel.c to simplified expression evaluation
author lost
date Mon, 05 Jan 2009 00:40:58 +0000
parents b1d81800bc91
children 309810f39ab7
files src/insn_rel.c
diffstat 1 files changed, 4 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/insn_rel.c	Mon Jan 05 00:20:45 2009 +0000
+++ b/src/insn_rel.c	Mon Jan 05 00:40:58 2009 +0000
@@ -32,49 +32,29 @@
 
 OPFUNC(insn_rel8)
 {
-	lwasm_expr_stack_t *s;
 	int v;
 	
 	lwasm_emitop(as, l, instab[opnum].ops[0]);
 	
-	s = lwasm_evaluate_expr(as, l, *p, NULL);
-	if (!s)
+	if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v) < 0)
 	{
-		register_error(as, l, 1, "Bad operand");
-		lwasm_emitop(as, l, 0);
-		return;
+		v = 0;
 	}
-	if (lwasm_expr_is_constant(s))
-		register_error(as, l, 2, "Incomplete reference");
-	v = lwasm_expr_get_value(s);
 	v -= as -> addr + 1;
 	if (v < -128 || v > 127)
 		register_error(as, l, 2, "Byte overflow");
 	lwasm_emit(as, l, v & 0xff);
-	
-	lwasm_expr_stack_free(s);
 }
 
 OPFUNC(insn_rel16)
 {
-	lwasm_expr_stack_t *s;
 	int v;
 	
 	lwasm_emitop(as, l, instab[opnum].ops[0]);
 	
-	s = lwasm_evaluate_expr(as, l, *p, NULL);
-	if (!s)
-	{
-		register_error(as, l, 1, "Bad operand");
-		lwasm_emitop(as, l, 0);
-		return;
-	}
-	if (lwasm_expr_is_constant(s))
-		register_error(as, l, 2, "Incomplete reference");
-	v = lwasm_expr_get_value(s);
+	if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v) < 0)
+		v = 0;
 	v -= as -> addr + 2;
 	lwasm_emit(as, l, (v >> 8) & 0xff);
 	lwasm_emit(as, l, v & 0xff);
-	
-	lwasm_expr_stack_free(s);
 }