diff options
Diffstat (limited to 'mixlib')
-rw-r--r-- | mixlib/mix_parser.c | 7 | ||||
-rw-r--r-- | mixlib/mix_scanner.l | 43 | ||||
-rw-r--r-- | mixlib/xmix_parser.h | 7 |
3 files changed, 44 insertions, 13 deletions
diff --git a/mixlib/mix_parser.c b/mixlib/mix_parser.c index 82dd692..1b876ad 100644 --- a/mixlib/mix_parser.c +++ b/mixlib/mix_parser.c @@ -442,7 +442,8 @@ mix_parser_set_future_ref (mix_parser_t *parser, const gchar *name) /* Redefine the value of a local symbol as the current loc_count */ void -mix_parser_manage_local_symbol (mix_parser_t *parser, const gchar *name) +mix_parser_manage_local_symbol (mix_parser_t *parser, const gchar *name, + mix_short_t value) { gchar ref[3]; ref[2] = 0; @@ -459,10 +460,10 @@ mix_parser_manage_local_symbol (mix_parser_t *parser, const gchar *name) ref[0] = name[0]; ref[1] = 'F'; if ( parser->status == MIX_PERR_NOCOMP ) - update_future_refs_ (parser, ref); + update_future_refs_value_ (parser, ref, value); ref[1] = 'B'; mix_symbol_table_insert (parser->symbol_table, ref, - mix_short_to_word_fast (parser->loc_count)); + mix_short_to_word_fast (value)); break; default: return; diff --git a/mixlib/mix_scanner.l b/mixlib/mix_scanner.l index c6ed5d8..c5529da 100644 --- a/mixlib/mix_scanner.l +++ b/mixlib/mix_scanner.l @@ -37,20 +37,28 @@ g_free (symbol); \ symbol = NULL; \ } \ + if (lsymbol != NULL) \ + { \ + g_free (lsymbol); \ + lsymbol = NULL; \ + } \ } while (FALSE) -#define NEXT() \ - do { \ - parser->loc_count++; \ - RESET (); \ - ++lineno; \ - BEGIN (INITIAL); \ +#define NEXT() \ + do { \ + if (lsymbol != NULL) \ + mix_parser_manage_local_symbol (parser,lsymbol, \ + loc); \ + parser->loc_count++; \ + RESET (); \ + ++lineno; \ + BEGIN (INITIAL); \ } while (FALSE) #define ADD_INS() \ do { \ mix_parser_add_ins (parser, &ins, lineno); \ - NEXT (); \ + NEXT (); \ } while (FALSE) #define ADD_RAW(value) \ @@ -140,7 +148,8 @@ wexpr {expr}({fpart})?(,{expr}({fpart})?)* gboolean nof = FALSE, is_fp = FALSE, end = FALSE, lsf = FALSE; mix_word_t expr_val = MIX_WORD_ZERO, wexpr_val = MIX_WORD_ZERO, wexpr_val_tmp = MIX_WORD_ZERO; - gchar *symbol = NULL; + gchar *symbol = NULL, *lsymbol = NULL; + mix_address_t loc = MIX_SHORT_ZERO; guint lineno = 1; mix_ins_fill_from_id (ins, mix_NOP); ins.address = 0; @@ -172,9 +181,25 @@ wexpr {expr}({fpart})?(,{expr}({fpart})?)* <LOC>{ {ws}+ BEGIN (OP); /* LOC field is empty */ {locsymbol} { /* manage local symbol */ - mix_parser_manage_local_symbol (parser,yytext); + loc = get_ploc_ (parser); + lsymbol = g_strdup (yytext); + if ( lsymbol == NULL ) { + mix_parser_log_error (parser, MIX_PERR_INTERNAL, lineno, NULL, FALSE); + return MIX_PERR_INTERNAL; + } BEGIN (OP); } + {locsymbol}/({ws}+EQU) {/* local symbol with value */ + loc = get_ploc_ (parser); + symbol = g_strdup (yytext); + lsymbol = g_strdup (yytext); + if ( symbol == NULL || lsymbol == NULL) { + mix_parser_log_error (parser, MIX_PERR_INTERNAL, lineno, NULL, FALSE); + return MIX_PERR_INTERNAL; + } + symbol[1] = 'B'; /* this will be referred as nB afterwards */ + BEGIN (OP); + } {flocsymbol}|{blocsymbol} RETURN_ERROR (MIX_PERR_UNEX_LOC, yytext); {symbol}/({ws}+EQU) { /* store symbol name for future definition */ symbol = g_strdup (yytext); diff --git a/mixlib/xmix_parser.h b/mixlib/xmix_parser.h index bbcd108..2584be7 100644 --- a/mixlib/xmix_parser.h +++ b/mixlib/xmix_parser.h @@ -56,6 +56,10 @@ typedef struct ins_node_ /* functions to manipulate mix_parser_t during compilation */ + +/* access loc counter */ +#define get_ploc_(parser) ((parser)->loc_count) + /* symbol table */ /* Define a new symbol with given value * and update previously set refs to this symbol @@ -76,7 +80,8 @@ mix_parser_set_future_ref(mix_parser_t *parser, const gchar *name); /* Redefine the value of a local symbol as the current loc_count */ extern void -mix_parser_manage_local_symbol(mix_parser_t *parser, const gchar *name); +mix_parser_manage_local_symbol(mix_parser_t *parser, const gchar *name, + mix_short_t value); /* Literal strings symbols */ extern void |