Mercurial > hg-old > index.cgi
comparison src/symbol.c @ 64:aaddd47219b4
Added the 'set' directive
author | lost |
---|---|
date | Mon, 05 Jan 2009 01:27:08 +0000 |
parents | d85ba47b1e8f |
children | 92eb93bffa28 |
comparison
equal
deleted
inserted
replaced
63:d85ba47b1e8f | 64:aaddd47219b4 |
---|---|
32 /* | 32 /* |
33 Note that this function may accept symbols that the expression evaluator doesn't | 33 Note that this function may accept symbols that the expression evaluator doesn't |
34 recognize because the expression evaluator must avoid all ambiguity in order | 34 recognize because the expression evaluator must avoid all ambiguity in order |
35 to achieve predictable results. The checks here are simply a fuzz check. | 35 to achieve predictable results. The checks here are simply a fuzz check. |
36 */ | 36 */ |
37 int lwasm_register_symbol(asmstate_t *as, lwasm_line_t *l, char *sym, int val) | 37 int lwasm_register_symbol(asmstate_t *as, lwasm_line_t *l, char *sym, int val, int flags) |
38 { | 38 { |
39 lwasm_symbol_ent_t *se, *se2; | 39 lwasm_symbol_ent_t *se, *se2; |
40 char *p; | 40 char *p; |
41 | 41 |
42 int scontext = -1; | 42 int scontext = -1; |
68 // flag local symbols while we're at it... | 68 // flag local symbols while we're at it... |
69 if (*p == '?' || *p == '@') | 69 if (*p == '?' || *p == '@') |
70 scontext = as -> context; | 70 scontext = as -> context; |
71 } | 71 } |
72 | 72 |
73 debug_message(3, "lwasm_register_symbol(): registering '%s' (%d) at %04X", sym, scontext, val); | 73 debug_message(3, "lwasm_register_symbol(): registering '%s' (%d) at %04X; flags=%d", sym, scontext, val, flags); |
74 | 74 |
75 // now look it for to see if it is a duplicate | 75 // now look it for to see if it is a duplicate |
76 se = lwasm_find_symbol(as, sym, scontext); | 76 se = lwasm_find_symbol(as, sym, scontext); |
77 if (se) | 77 if (se) |
78 { | 78 { |
79 register_error(as, l, 1, "Mulitply defined symbol: %s", sym); | 79 if (!(flags & SYMBOL_SET) || (flags & SYMBOL_SET && !(se -> flags & SYMBOL_SET))) |
80 return -1; | 80 { |
81 register_error(as, l, 1, "Mulitply defined symbol: %s", sym); | |
82 return -1; | |
83 } | |
81 } | 84 } |
82 | 85 if (se) |
86 { | |
87 se -> value = val; | |
88 return; | |
89 } | |
90 | |
83 // if not a duplicate, register it with the value | 91 // if not a duplicate, register it with the value |
84 se = lwasm_alloc(sizeof(lwasm_symbol_ent_t)); | 92 se = lwasm_alloc(sizeof(lwasm_symbol_ent_t)); |
85 if (as -> symhead) | 93 if (as -> symhead) |
86 { | 94 { |
87 se -> prev = NULL; | 95 se -> prev = NULL; |
97 as -> symtail = se; | 105 as -> symtail = se; |
98 } | 106 } |
99 se -> value = val; | 107 se -> value = val; |
100 se -> sym = lwasm_strdup(sym); | 108 se -> sym = lwasm_strdup(sym); |
101 se -> context = scontext; | 109 se -> context = scontext; |
110 se -> flags = flags; | |
102 | 111 |
103 return 0; | 112 return 0; |
104 } | 113 } |
105 | 114 |
106 lwasm_symbol_ent_t *lwasm_find_symbol(asmstate_t *as, char *sym, int scontext) | 115 lwasm_symbol_ent_t *lwasm_find_symbol(asmstate_t *as, char *sym, int scontext) |