summaryrefslogtreecommitdiffhomepage
path: root/mixlib
diff options
context:
space:
mode:
Diffstat (limited to 'mixlib')
-rw-r--r--mixlib/mix_parser.c19
-rw-r--r--mixlib/mix_scanner.l4
-rw-r--r--mixlib/xmix_parser.h6
3 files changed, 23 insertions, 6 deletions
diff --git a/mixlib/mix_parser.c b/mixlib/mix_parser.c
index 74317ac..36d5b3a 100644
--- a/mixlib/mix_parser.c
+++ b/mixlib/mix_parser.c
@@ -192,12 +192,14 @@ undef_warning_ (gpointer symbol, gpointer value, gpointer data)
}
static void
-update_future_refs_ (mix_parser_t *parser, const gchar *name)
+update_future_refs_value_ (mix_parser_t *parser, const gchar *name,
+ mix_short_t value)
{
GSList *list = NULL;
gpointer key;
g_assert (parser != NULL && name != NULL);
+ printf ("Updating future %s\n", name);
if ( g_hash_table_lookup_extended (parser->future_refs, name, &key,
(gpointer *)&list) )
@@ -209,7 +211,7 @@ update_future_refs_ (mix_parser_t *parser, const gchar *name)
node =
(ins_node_ *)g_tree_lookup (parser->ins_table,tmp->data);
g_assert (node);
- mix_word_set_address (node->ins, parser->loc_count);
+ mix_word_set_address (node->ins, value);
g_tree_insert (parser->ins_table, tmp->data, (gpointer)node);
tmp = g_slist_next (tmp);
}
@@ -219,6 +221,9 @@ update_future_refs_ (mix_parser_t *parser, const gchar *name)
}
}
+#define update_future_refs_(parser,name) \
+ update_future_refs_value_(parser, name, (parser)->loc_count);
+
static void
update_ls_ (gpointer symbol, gpointer value, gpointer parser)
{ /* add an instruction on current location and update refs to it */
@@ -392,14 +397,20 @@ mix_parser_err_t
mix_parser_define_symbol_here (mix_parser_t *parser, const gchar *name)
{
mix_word_t value = mix_short_to_word_fast (parser->loc_count);
-
+ return mix_parser_define_symbol_value (parser, name, value);
+}
+
+mix_parser_err_t
+mix_parser_define_symbol_value (mix_parser_t *parser, const gchar *name,
+ mix_word_t value)
+{
g_assert (parser != NULL && name != NULL);
switch (mix_symbol_table_add (parser->symbol_table, name, value))
{
case MIX_SYM_OK:
if ( parser->status == MIX_PERR_NOCOMP )
- update_future_refs_ (parser, name);
+ update_future_refs_value_ (parser, name, value);
return MIX_PERR_OK;
case MIX_SYM_LONG: return MIX_PERR_LONG_SYMBOL;
case MIX_SYM_DUP: return MIX_PERR_DUP_SYMBOL;
diff --git a/mixlib/mix_scanner.l b/mixlib/mix_scanner.l
index f740d10..b1d4a13 100644
--- a/mixlib/mix_scanner.l
+++ b/mixlib/mix_scanner.l
@@ -176,7 +176,7 @@ wexpr {expr}({fpart})?(,{expr}({fpart})?)*
BEGIN (OP);
}
{flocsymbol}|{blocsymbol} RETURN_ERROR (MIX_PERR_UNEX_LOC, yytext);
- {symbol}/{ws}+EQU { /* store symbol name for future definition */
+ {symbol}/({ws}+EQU) { /* store symbol name for future definition */
symbol = g_strdup (yytext);
if ( symbol == NULL ) {
mix_parser_log_error (parser, MIX_PERR_INTERNAL, lineno, NULL, FALSE);
@@ -263,7 +263,7 @@ wexpr {expr}({fpart})?(,{expr}({fpart})?)*
gint def;
if ( symbol == NULL ) RETURN_ERROR (MIX_PERR_MIS_SYM, NULL);
value = mix_word_new (atol (yytext));
- def = mix_symbol_table_add (parser->symbol_table, symbol, value);
+ def = mix_parser_define_symbol_value (parser, symbol, value);
if ( def == MIX_SYM_DUP ) RETURN_ERROR (MIX_PERR_DUP_SYMBOL, symbol);
if ( def == MIX_SYM_LONG ) RETURN_ERROR (MIX_PERR_LONG_SYMBOL, symbol);
++lineno;
diff --git a/mixlib/xmix_parser.h b/mixlib/xmix_parser.h
index fee385c..bbcd108 100644
--- a/mixlib/xmix_parser.h
+++ b/mixlib/xmix_parser.h
@@ -57,6 +57,12 @@ typedef struct ins_node_
/* functions to manipulate mix_parser_t during compilation */
/* symbol table */
+/* Define a new symbol with given value
+ * and update previously set refs to this symbol
+ */
+extern mix_parser_err_t
+mix_parser_define_symbol_value (mix_parser_t *parser, const gchar *name,
+ mix_word_t value);
/* Define a new symbol with value equal to the current loc_count
* and update previously set refs to this symbol