diff src/pseudo.c @ 56:55260a178667

Added from f* pseudo ops
author lost
date Sun, 04 Jan 2009 21:43:05 +0000
parents 360d53062bb9
children 035b95a3690f
line wrap: on
line diff
--- a/src/pseudo.c	Sun Jan 04 21:42:54 2009 +0000
+++ b/src/pseudo.c	Sun Jan 04 21:43:05 2009 +0000
@@ -308,29 +308,50 @@
 	}
 }
 
-/*
-void pseudo_align(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_align)
 {
-	int rval, v1;
+	int rval;
+	lwasm_expr_stack_t *s;
 	int cn;
 
-	rval = eval_expr(as, cl, optr, &v1);
-	if (rval < 0)
+	if (as -> passnum == 2)
 	{
-		errorp1(ERR_FORWARD);
+		while (as -> addr < l -> symaddr)
+			lwasm_emit(as, l, 0);
+		return;
+	}
+	
+	s = lwasm_evaluate_expr(as, l, *p, NULL);
+	if (!s)
+	{
+		register_error(as, l, 1, "Bad expression");
 		return;
 	}
-	cn = cl -> addr % v1;
-	if (cn)
-	cn = v1 - cn; 
+	if (!lwasm_expr_is_constant(s))
+	{
+		register_error(as, l, 1, "Illegal incomplete reference (pass 1)");
+	}
+	rval = lwasm_expr_get_value(s);
+	lwasm_expr_stack_free(s);
 
-	while (cn)
+	if (rval < 1)
 	{
-		emit(0);
-		cn--;
+		register_error(as, l, 1, "Illegal alignment %d", rval);
+		return;
 	}
+	
+	cn = l -> codeaddr % rval;
+	if (cn)
+		cn = rval - cn; 
+
+	while (cn--)
+	{
+		lwasm_emit(as, l, 0);
+	}
+	l -> symaddr = as -> addr;
 }
-*/
+
 OPFUNC(pseudo_equ)
 {
 	lwasm_expr_stack_t *s;
@@ -433,125 +454,126 @@
 	cl -> numcodebytes = 0;
 //printf("%s\n", "SETDP2");
 }
+*/
 
-void pseudo_fcc(asmstate_t *as, sourceline_t *cl, char **optr)
-{		
-	int cn = 0;
+OPFUNC(pseudo_fcc)
+{
 	int delim = 0;
 				
-	delim = *(*optr)++;
+	delim = **p;
 	if (!delim)
 	{
-		errorp1(ERR_BADOPER);
+		register_error(as, l, 1, "Bad operand");
+		return;
 	}
-	else
+	*p += 1;
+	while (**p && **p != delim)
 	{
-		while (**optr && **optr != delim)
-		{
-			emit(**optr);
-			(*optr)++;
-			cn += 1;
-		}
+		lwasm_emit(as, l, **p);
+		(*p)++;
 	}
-	cl -> len = cn;
+	if (**p)
+		(*p)++;
 }
 		
-void pseudo_fcs(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_fcs)
 {
-	int cn = 0;
 	int delim = 0;
-				
-	delim = *(*optr)++;
+
+	delim = **p;
 	if (!delim)
 	{
-		errorp1(ERR_BADOPER);
+		register_error(as, l, 1, "Bad operand");
+		return;
 	}
-	else
+	*p += 1;
+	while (**p && **p != delim)
 	{
-		while (**optr && **optr != delim)
-		{
-			if (!*((*optr) + 1) || *((*optr) + 1) == delim)
-				emit((**optr) | 0x80);
-			else
-				emit(**optr);
-			(*optr)++;
-			cn += 1;
-		}
+		if (!*((*p) + 1) || *((*p) + 1) == delim)
+			lwasm_emit(as, l, **p | 0x80);
+		else
+			lwasm_emit(as, l, **p);
+		(*p)++;
 	}
-	cl -> len = cn;
+	if (**p)
+		(*p)++;
 }
 
-void pseudo_fcn(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_fcn)
 {		
-	int cn = 0;
 	int delim = 0;
 				
-	delim = *(*optr)++;
+	delim = **p;
 	if (!delim)
 	{
-		errorp1(ERR_BADOPER);
+		register_error(as, l, 1, "Bad operand");
+		return;
 	}
-	else
+	*p += 1;
+	while (**p && **p != delim)
 	{
-		while (**optr && **optr != delim)
-		{
-			emit(**optr);
-			(*optr)++;
-			cn += 1;
-		}
+		lwasm_emit(as, l, **p);
+		(*p)++;
 	}
-	emit(0);
-	cl -> len = cn + 1;
+	if (**p)
+		(*p)++;
+	lwasm_emit(as, l, 0);
 }
-		
-void pseudo_fcb(asmstate_t *as, sourceline_t *cl, char **optr)
+
+OPFUNC(pseudo_fcb)
 {
-	int rval, v1;
+	int v1;
 	
 fcb_again:
-	rval = eval_expr(as, cl, optr, &v1);
-	if (v1 < -127 || v1 > 0xff)
-		errorp2(ERR_OVERFLOW);
-	emit(v1 & 0xff);
-	if (**optr == ',')
+	if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST | EXPR_BYTE, &v1) < 0)
+		return;
+	
+	lwasm_emit(as, l, v1);
+	if (**p == ',')
 	{
-		(*optr)++;
+		(*p)++;
 		goto fcb_again;
 	}
 }
 
-void pseudo_fdb(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_fdb)
 {			
-	int rval, v1;
+	int v1;
 	
 fdb_again:
-	rval = eval_expr(as, cl, optr, &v1);
-	emit((v1 >> 8) & 0xff);
-	emit(v1 & 0xff);
-	if (**optr == ',')
+	if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0)
+		return;
+	
+	lwasm_emit(as, l, v1 >> 8);
+	lwasm_emit(as, l, v1 & 0xff);
+	if (**p == ',')
 	{
-		(*optr)++;
+		(*p)++;
 		goto fdb_again;
 	}
 }
 
-void pseudo_fqb(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_fqb)
 {	
-	int rval, v1;
-
+	int v1;
+	
 fqb_again:
-	rval = eval_expr(as, cl, optr, &v1);
-	emit((v1 >> 24) & 0xff);
-	emit((v1 >> 16) & 0xff);
-	emit((v1 >> 8) & 0xff);
-	emit(v1 & 0xff);
-	if (**optr == ',')
+	if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0)
+		return;
+	
+	lwasm_emit(as, l, v1 >> 24);
+	lwasm_emit(as, l, v1 >> 16);
+	lwasm_emit(as, l, v1 >> 8);
+	lwasm_emit(as, l, v1 & 0xff);
+	if (**p == ',')
 	{
-		(*optr)++;
+		(*p)++;
 		goto fqb_again;
 	}
 }
 
+/*
 // don't need to do anything if we are executing one of these
 void pseudo_endc(asmstate_t *as, sourceline_t *cl, char **optr)
 {
@@ -681,10 +703,10 @@
 		}
 	}
 }
+*/
 
-void pseudo_error(asmstate_t *as, sourceline_t *cl, char **optr)
+OPFUNC(pseudo_error)
 {
-	cl -> user_error = strdup(*optr);
-	errorp1(ERR_USER);
+	register_error(as, l, 1, "User error: %s", *p);
 }
-*/
+