diff src/pseudo.c @ 57:035b95a3690f

Added conditional assembly and macros
author lost
date Mon, 05 Jan 2009 00:01:21 +0000
parents 55260a178667
children d85ba47b1e8f
line wrap: on
line diff
--- a/src/pseudo.c	Sun Jan 04 21:43:05 2009 +0000
+++ b/src/pseudo.c	Mon Jan 05 00:01:21 2009 +0000
@@ -75,13 +75,13 @@
 {
 	int v1;
 	char *fn;
-
+	
 	// only include files on pass 1
 	// but make sure local include context is right
 	// for the next line...
 	if (as -> passnum != 1)
 	{
-		as -> context += 1;
+		as -> context = lwasm_next_context(as);
 		return;
 	}
 
@@ -118,7 +118,7 @@
 	fn[v1] = '\0';
 
 	// end local label context on include	
-	as -> context += 1;
+	as -> context = lwasm_next_context(as);
 	if (lwasm_read_file(as, fn) < 0)
 	{
 		register_error(as, l, 1, "File include error (%s)", fn);
@@ -573,137 +573,165 @@
 	}
 }
 
-/*
 // don't need to do anything if we are executing one of these
-void pseudo_endc(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_endc)
 {
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount -= 1;
+		if (as -> skipcount <= 0)
+		{
+			as -> skipcond = 0;
+		}
+	}
 	return;
 }
 
 // if "else" executes, we must be going into an "ignore" state
-void pseudo_else(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_else)
 {
+	if (as -> skipmacro)
+		return;
+	
+	if (as -> skipcond)
+	{
+		if (as -> skipcount == 1)
+		{
+			as -> skipcount = 0;
+			as -> skipcond = 0;
+		}
+		return;
+	}
+	
 	as -> skipcond = 1;
 	as -> skipcount = 1;
 }
 
-void pseudo_ifne(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_ifne)
 {
 	int v1;
 	int rval;
-//	printf("ifne %s\n", *optr);
-	rval = eval_expr(as, cl, optr, &v1);
-	if (rval < 0)
-	{
-		errorp1(ERR_BADCOND);
-	}
-	else
+
+	if (as -> skipcond && !(as -> skipmacro))
 	{
-//	printf("Condition value: %d\n", v1);
-		if (!v1)
-		{
-//		printf("condition no match\n");
-			as -> skipcond = 1;
-			as -> skipcount = 1;
-		}
+		as -> skipcount++;
+		return;
+	}
+
+	rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
+	if (rval < 0)
+		return;
+	if (!v1)
+	{
+		as -> skipcond = 1;
+		as -> skipcount = 1;
 	}
 }
-void pseudo_ifeq(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_ifeq)
 {
 	int v1;
 	int rval;
-	
-	rval = eval_expr(as, cl, optr, &v1);
-	if (rval < 0)
+
+	if (as -> skipcond && !(as -> skipmacro))
 	{
-		errorp1(ERR_BADCOND);
+		as -> skipcount++;
+		return;
 	}
-	else
+
+	rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
+	if (rval < 0)
+		return;
+	if (v1)
 	{
-		if (v1)
-		{
-			as -> skipcond = 1;
-			as -> skipcount = 1;
-		}
+		as -> skipcond = 1;
+		as -> skipcount = 1;
 	}
 }
-void pseudo_iflt(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_iflt)
 {
 	int v1;
 	int rval;
-	
-	rval = eval_expr(as, cl, optr, &v1);
-	if (rval < 0)
+
+	if (as -> skipcond && !(as -> skipmacro))
 	{
-		errorp1(ERR_BADCOND);
+		as -> skipcount++;
+		return;
 	}
-	else
+
+	rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
+	if (rval < 0)
+		return;
+	if (v1 >= 0)
 	{
-		if (v1 >= 0)
-		{
-			as -> skipcond = 1;
-			as -> skipcount = 1;
-		}
+		as -> skipcond = 1;
+		as -> skipcount = 1;
 	}
 }
-void pseudo_ifle(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_ifle)
 {
 	int v1;
 	int rval;
-	
-	rval = eval_expr(as, cl, optr, &v1);
-	if (rval < 0)
+
+	if (as -> skipcond && !(as -> skipmacro))
 	{
-		errorp1(ERR_BADCOND);
+		as -> skipcount++;
+		return;
 	}
-	else
+
+	rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
+	if (rval < 0)
+		return;
+	if (v1 > 0)
 	{
-		if (v1 > 0)
-		{
-			as -> skipcond = 1;
-			as -> skipcount = 1;
-		}
+		as -> skipcond = 1;
+		as -> skipcount = 1;
 	}
 }
-void pseudo_ifgt(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_ifgt)
 {
 	int v1;
 	int rval;
-	
-	rval = eval_expr(as, cl, optr, &v1);
-	if (rval < 0)
+
+	if (as -> skipcond && !(as -> skipmacro))
 	{
-		errorp1(ERR_BADCOND);
+		as -> skipcount++;
+		return;
 	}
-	else
+
+	rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
+	if (rval < 0)
+		return;
+	if (v1 <= 0)
 	{
-		if (v1 <= 0)
-		{
-			as -> skipcond = 1;
-			as -> skipcount = 1;
-		}
+		as -> skipcond = 1;
+		as -> skipcount = 1;
 	}
 }
-void pseudo_ifge(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_ifge)
 {
 	int v1;
 	int rval;
-	
-	rval = eval_expr(as, cl, optr, &v1);
-	if (rval < 0)
+
+	if (as -> skipcond && !(as -> skipmacro))
 	{
-		errorp1(ERR_BADCOND);
+		as -> skipcount++;
+		return;
 	}
-	else
+
+	rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
+	if (rval < 0)
+		return;
+	if (v1 < 0)
 	{
-		if (v1 < 0)
-		{
-			as -> skipcond = 1;
-			as -> skipcount = 1;
-		}
+		as -> skipcond = 1;
+		as -> skipcount = 1;
 	}
 }
-*/
 
 OPFUNC(pseudo_error)
 {