diff src/lwasm.c @ 37:538e15927776

Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
author lost
date Sat, 03 Jan 2009 04:20:49 +0000
parents 9bd0fbfe7405
children 9bd584bb6296
line wrap: on
line diff
--- a/src/lwasm.c	Fri Jan 02 06:07:40 2009 +0000
+++ b/src/lwasm.c	Sat Jan 03 04:20:49 2009 +0000
@@ -29,6 +29,7 @@
 
 #include "lwasm.h"
 #include "util.h"
+#include "expr.h"
 
 int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...)
 {
@@ -147,3 +148,36 @@
 		(*str)+=3;
 	return rval;
 }
+
+struct symstateinfo
+{
+	asmstate_t *as;
+	lwasm_line_t *l;
+};	
+
+int lwasm_expr_lookup_symbol(char *sym, void *state, int *val)
+{
+	lwasm_symbol_ent_t *se;
+	struct symstateinfo *st;
+	
+	st = state;
+	
+	// look for local symbol first then global symbol
+	se = lwasm_find_symbol(st -> as, sym, st -> as -> context);
+	if (!se)
+		se = lwasm_find_symbol(st -> as, sym, -1);
+	if (!se)
+		return -1;
+	*val = se -> value;
+	return 0;
+}
+
+lwasm_expr_stack_t *lwasm_evaluate_expr(asmstate_t *as, lwasm_line_t *l, const char *inp, const char **outp)
+{
+	struct symstateinfo st;
+	
+	st.as = as;
+	st.l = l;
+	
+	return(lwasm_expr_eval(inp, outp, lwasm_expr_lookup_symbol, &st));
+}