diff src/parse.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 99e3b3310bac
children 9bd584bb6296
line wrap: on
line diff
--- a/src/parse.c	Fri Jan 02 06:07:40 2009 +0000
+++ b/src/parse.c	Sat Jan 03 04:20:49 2009 +0000
@@ -37,17 +37,43 @@
 	char *p, *p2;
 	char *opc;
 	int opnum;
+	char *sym;
 	
 	p = l -> text;
 	
 	if (!*p)
+	{
+		as -> context += 1;
 		return 0;
+	}
 	
 	if (!isspace(*p) && *p != '*' && *p != ';')
 	{
 		// we have a symbol specified here
 		// parse it and define
 		// need to handle local symbols here...
+		for (p2 = p; *p2 && !isspace(*p2); p2++)
+			/* do nothing */ ;
+		
+		sym = lwasm_alloc((p2 - p) + 1);
+		sym[p2 - p] = '\0';
+		memcpy(sym, p, p2 - p);
+		
+		l -> sym = sym;
+		// have a symbol; now determine if it is valid and register it
+		// at the current address of the line
+		if (lwasm_register_symbol(as, l, sym, as -> addr) < 0)
+			l -> sym = NULL;
+	}
+	else
+	{
+		while (*p && isspace(*p))
+			(*p)++;
+		if (!*p)
+		{
+			as -> context += 1;
+			return 0;
+		}
 	}
 
 	// skip white space
@@ -56,7 +82,10 @@
 	
 	// if comment or end of line, return
 	if (!*p || *p == '*' || *p == ';')
+	{
+		lwasm_free(l -> sym);
 		return 0;
+	}
 	
 	// parse the opcode
 	for (p2 = p; *p2 && !isspace(*p2); p2++)
@@ -83,6 +112,7 @@
 	{
 		// invalid operation code, throw error
 		register_error(as, l, 1, "Invalid operation code '%s'", opc);
+		lwasm_free(l -> sym);
 		lwasm_free(opc);
 		return -1;
 	}
@@ -91,4 +121,5 @@
 	(instab[opnum].fn)(as, l, &p2, opnum);
 	
 	lwasm_free(opc);
+	lwasm_free(sym);
 }