changeset 40:d2cee0c335e7

adjusted symbol rules to accept symbols starting with @ but not @<digit>
author lost
date Sat, 03 Jan 2009 19:41:39 +0000
parents efa19ec69df9
children 7eafdb3a8074
files src/expr.c src/symbol.c
diffstat 2 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/expr.c	Sat Jan 03 19:20:44 2009 +0000
+++ b/src/expr.c	Sat Jan 03 19:41:39 2009 +0000
@@ -30,9 +30,7 @@
 
 #include "expr.h"
 #include "util.h"
-
-// this definition is in lwasm.h but we don't need the whole file here
-extern void debug_message(int level, const char *fmt, ...);
+#include "lwasm.h"
 
 lwasm_expr_stack_t *lwasm_expr_stack_create(void)
 {
@@ -365,7 +363,9 @@
 		lwasm_expr_term_free(t);
 		return 0;
 	}
-	else if (**p == '@')
+	// an @ followed by a digit is an octal number
+	// but if it's followed by anything else, it is a symbol
+	else if (**p == '@' && isdigit(*(*p + 1)))
 	{
 		// octal constant
 		int val = 0;
--- a/src/symbol.c	Sat Jan 03 19:20:44 2009 +0000
+++ b/src/symbol.c	Sat Jan 03 19:41:39 2009 +0000
@@ -29,6 +29,11 @@
 #include "lwasm.h"
 #include "util.h"
 
+/*
+Note that this function may accept symbols that the expression evaluator doesn't
+recognize because the expression evaluator must avoid all ambiguity in order
+to achieve predictable results. The checks here are simply a fuzz check.
+*/
 int lwasm_register_symbol(asmstate_t *as, lwasm_line_t *l, char *sym, int val)
 {
 	lwasm_symbol_ent_t *se, *se2;
@@ -47,6 +52,12 @@
 		return -1;
 	}
 	
+	if (*sym == '@' && isdigit(sym[1]))
+	{
+		register_error(as, l, 1, "Bad symbol: %s", sym);
+		return -1;
+	}
+	
 	for (p = sym; *p; p++)
 	{
 		if (!strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._$?@0123456789", *sym) && (unsigned char)*sym < 0x80)