diff lwasm/pseudo.c @ 349:dcd2978a7d18

More pseudo ops
author lost@starbug
date Sat, 27 Mar 2010 22:44:46 -0600
parents 11a95c6414b4
children f5666775d76f
line wrap: on
line diff
--- a/lwasm/pseudo.c	Sat Mar 27 22:15:07 2010 -0600
+++ b/lwasm/pseudo.c	Sat Mar 27 22:44:46 2010 -0600
@@ -24,6 +24,8 @@
 #include "lwasm.h"
 #include "instab.h"
 
+#include "lw_string.h"
+
 // for "end"
 PARSEFUNC(pseudo_parse_end)
 {
@@ -160,3 +162,347 @@
 		lwasm_emitexpr(l, e, 4);
 	}
 }
+
+PARSEFUNC(pseudo_parse_fcc)
+{
+	char delim;
+	int i;
+	
+	if (!**p)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	delim = **p;
+	(*p)++;
+	
+	for (i = 0; (*p)[i] && (*p)[i] != delim; i++)
+		/* do nothing */ ;
+	
+	if ((*p)[i] != delim)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	l -> lstr = lw_strndup(*p, i);
+	(*p) += i + 1;
+	
+	l -> len = i;
+}
+
+EMITFUNC(pseudo_emit_fcc)
+{
+	int i;
+	
+	for (i = 0; i < l -> len; i++)
+		lwasm_emit(l, l -> lstr[i]);
+}
+
+PARSEFUNC(pseudo_parse_fcs)
+{
+	char delim;
+	int i;
+	
+	if (!**p)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	delim = **p;
+	(*p)++;
+	
+	for (i = 0; (*p)[i] && (*p)[i] != delim; i++)
+		/* do nothing */ ;
+	
+	if ((*p)[i] != delim)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	l -> lstr = lw_strndup(*p, i);
+	(*p) += i + 1;
+	
+	l -> len = i;
+}
+
+EMITFUNC(pseudo_emit_fcs)
+{
+	int i;
+	
+	for (i = 0; i < l -> len - 1; i++)
+		lwasm_emit(l, l -> lstr[i]);
+	lwasm_emit(l, l -> lstr[i] | 0x80);
+}
+
+PARSEFUNC(pseudo_parse_fcn)
+{
+	char delim;
+	int i;
+	
+	if (!**p)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	delim = **p;
+	(*p)++;
+	
+	for (i = 0; (*p)[i] && (*p)[i] != delim; i++)
+		/* do nothing */ ;
+	
+	if ((*p)[i] != delim)
+	{
+		lwasm_register_error(as, l, "Bad operand");
+		return;
+	}
+	
+	l -> lstr = lw_strndup(*p, i);
+	(*p) += i + 1;
+	
+	l -> len = i;
+}
+
+EMITFUNC(pseudo_emit_fcn)
+{
+	int i;
+	
+	for (i = 0; i < l -> len; i++)
+		lwasm_emit(l, l -> lstr[i]);
+	lwasm_emit(l, 0);
+}
+
+PARSEFUNC(pseudo_parse_rmb)
+{
+	lw_expr_t expr;
+	
+	expr = lwasm_parse_expr(as, p);
+	if (!expr)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+	}
+	
+	lwasm_save_expr(l, 0, expr);
+}
+
+RESOLVEFUNC(pseudo_resolve_rmb)
+{
+	lw_expr_t expr;
+	
+	if (l -> len >= 0)
+		return;
+	
+	expr = lwasm_fetch_expr(l, 0);
+	
+	if (lw_expr_istype(expr, lw_expr_type_int))
+	{
+		l -> len = lw_expr_intval(expr);
+	}
+}
+
+EMITFUNC(pseudo_emit_rmb)
+{
+	if (l -> len < 0)
+		lwasm_register_error(as, l, "Expression not constant");
+}
+
+PARSEFUNC(pseudo_parse_rmd)
+{
+	lw_expr_t expr;
+	
+	expr = lwasm_parse_expr(as, p);
+	if (!expr)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+	}
+	
+	lwasm_save_expr(l, 0, expr);
+}
+
+RESOLVEFUNC(pseudo_resolve_rmd)
+{
+	lw_expr_t expr;
+	
+	if (l -> len >= 0)
+		return;
+	
+	expr = lwasm_fetch_expr(l, 0);
+	
+	if (lw_expr_istype(expr, lw_expr_type_int))
+	{
+		l -> len = lw_expr_intval(expr) * 2;
+	}
+}
+
+EMITFUNC(pseudo_emit_rmd)
+{
+	if (l -> len < 0)
+		lwasm_register_error(as, l, "Expression not constant");
+}
+
+
+PARSEFUNC(pseudo_parse_rmq)
+{
+	lw_expr_t expr;
+	
+	expr = lwasm_parse_expr(as, p);
+	if (!expr)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+	}
+	
+	lwasm_save_expr(l, 0, expr);
+}
+
+RESOLVEFUNC(pseudo_resolve_rmq)
+{
+	lw_expr_t expr;
+	
+	if (l -> len >= 0)
+		return;
+	
+	expr = lwasm_fetch_expr(l, 0);
+	
+	if (lw_expr_istype(expr, lw_expr_type_int))
+	{
+		l -> len = lw_expr_intval(expr) * 4;
+	}
+}
+
+EMITFUNC(pseudo_emit_rmq)
+{
+	if (l -> len < 0)
+		lwasm_register_error(as, l, "Expression not constant");
+}
+
+
+PARSEFUNC(pseudo_parse_zmq)
+{
+	lw_expr_t expr;
+	
+	expr = lwasm_parse_expr(as, p);
+	if (!expr)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+	}
+	
+	lwasm_save_expr(l, 0, expr);
+}
+
+RESOLVEFUNC(pseudo_resolve_zmq)
+{
+	lw_expr_t expr;
+	
+	if (l -> len >= 0)
+		return;
+	
+	expr = lwasm_fetch_expr(l, 0);
+	
+	if (lw_expr_istype(expr, lw_expr_type_int))
+	{
+		l -> len = lw_expr_intval(expr) * 4;
+	}
+}
+
+EMITFUNC(pseudo_emit_zmq)
+{
+	int i;
+
+	if (l -> len < 0)
+	{
+		lwasm_register_error(as, l, "Expression not constant");
+		return;
+	}
+
+	for (i = 0; i < l -> len; i++)
+		lwasm_emit(l, 0);	
+}
+
+
+PARSEFUNC(pseudo_parse_zmd)
+{
+	lw_expr_t expr;
+	
+	expr = lwasm_parse_expr(as, p);
+	if (!expr)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+	}
+	
+	lwasm_save_expr(l, 0, expr);
+}
+
+RESOLVEFUNC(pseudo_resolve_zmd)
+{
+	lw_expr_t expr;
+	
+	if (l -> len >= 0)
+		return;
+	
+	expr = lwasm_fetch_expr(l, 0);
+	
+	if (lw_expr_istype(expr, lw_expr_type_int))
+	{
+		l -> len = lw_expr_intval(expr) * 2;
+	}
+}
+
+EMITFUNC(pseudo_emit_zmd)
+{
+	int i;
+
+	if (l -> len < 0)
+	{
+		lwasm_register_error(as, l, "Expression not constant");
+		return;
+	}
+
+	for (i = 0; i < l -> len; i++)
+		lwasm_emit(l, 0);	
+}
+
+PARSEFUNC(pseudo_parse_zmb)
+{
+	lw_expr_t expr;
+	
+	expr = lwasm_parse_expr(as, p);
+	if (!expr)
+	{
+		lwasm_register_error(as, l, "Bad expression");
+	}
+	
+	lwasm_save_expr(l, 0, expr);
+}
+
+RESOLVEFUNC(pseudo_resolve_zmb)
+{
+	lw_expr_t expr;
+	
+	if (l -> len >= 0)
+		return;
+	
+	expr = lwasm_fetch_expr(l, 0);
+	
+	if (lw_expr_istype(expr, lw_expr_type_int))
+	{
+		l -> len = lw_expr_intval(expr);
+	}
+}
+
+EMITFUNC(pseudo_emit_zmb)
+{
+	int i;
+
+	if (l -> len < 0)
+	{
+		lwasm_register_error(as, l, "Expression not constant");
+		return;
+	}
+
+	for (i = 0; i < l -> len; i++)
+		lwasm_emit(l, 0);	
+}