From 02a35ac468304292f1107f061607a1bd405ecf31 Mon Sep 17 00:00:00 2001 From: marcobaye Date: Fri, 5 Jun 2020 09:51:10 +0000 Subject: [PATCH] more refactoring git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@216 4df02467-bbd4-4a76-a152-e7ce94205b78 --- src/global.c | 27 ++++----------------------- src/symbol.c | 31 ++++++++++++++++++++++++++++++- src/symbol.h | 8 ++++++-- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/global.c b/src/global.c index 418d74e..ce3561b 100644 --- a/src/global.c +++ b/src/global.c @@ -164,22 +164,19 @@ static int first_label_of_statement(int *statement_flags) // called by parse_symbol_definition, parse_backward_anon_def, parse_forward_anon_def static void set_label(scope_t scope, int stat_flags, int force_bit, boolean change_allowed) // "change_allowed" is used by backward anons! { + struct symbol *symbol; struct number pc; struct object result; - struct symbol *symbol; if ((stat_flags & SF_FOUND_BLANK) && config.warn_on_indented_labels) Throw_first_pass_warning("Label name not in leftmost column."); symbol = symbol_find(scope); - // label definition - vcpu_read_pc(&pc); - // FIXME - if undefined, check pass.complain_about_undefined and maybe throw "value not defined"! + vcpu_read_pc(&pc); // FIXME - if undefined, check pass.complain_about_undefined and maybe throw "value not defined"! result.type = &type_int; result.u.number.flags = pc.flags & NUMBER_IS_DEFINED; result.u.number.val.intval = pc.val.intval; result.u.number.addr_refs = pc.addr_refs; - symbol_forcebit(symbol, force_bit); // TODO - "if NULL object, make int" and "if not int, complain" - symbol_set_object(symbol, &result, change_allowed); // FIXME - "backward anon allows number redef" is different from "!set allows object redef"! + symbol_set_object2(symbol, &result, force_bit, change_allowed); symbol->pseudopc = pseudopc_get_context(); // global labels must open new scope for cheap locals if (scope == SCOPE_GLOBAL) @@ -204,23 +201,7 @@ void parse_assignment(scope_t scope, int force_bit, boolean po_set) || (result.type == &type_float)) result.u.number.addr_refs = 1; } - // FIXME - force bit can only be used if result is number! check! - symbol_forcebit(symbol, force_bit); - // if this was called by !set, new force bit replaces old one: - if (po_set) { - // clear symbol's force bits and set new ones - // (but only do this for numbers!) - if (((symbol->object.type == &type_int) || (symbol->object.type == &type_float)) - && ((result.type == &type_int) || (result.type == &type_float))) { - symbol->object.u.number.flags &= ~(NUMBER_FORCEBITS | NUMBER_FITS_BYTE); - if (force_bit) { - symbol->object.u.number.flags |= force_bit; - result.u.number.flags &= ~(NUMBER_FORCEBITS | NUMBER_FITS_BYTE); - } - } - // FIXME - take a good look at the flags handling above and in the fn called below and clean this up! - } - symbol_set_object(symbol, &result, po_set); + symbol_set_object3(symbol, &result, force_bit, po_set); } diff --git a/src/symbol.c b/src/symbol.c index 97ac2ad..eadc855 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -135,7 +135,7 @@ struct symbol *symbol_find(scope_t scope) } -// FIXME - merge with function below! +// FIXME - temporary helper function during refactoring void symbol_forcebit(struct symbol *symbol, int force_bit) { // if symbol has no object assigned to it, make it an int @@ -202,6 +202,35 @@ void symbol_set_object(struct symbol *symbol, struct object *new_value, boolean } symbol->object.u.number.flags = flags; } +// FIXME - temporary helper function during refactoring +// "change_allowed" is used by backward anons, but then force_bit is 0 +void symbol_set_object2(struct symbol *symbol, struct object *result, int force_bit, boolean change_allowed) +{ + symbol_forcebit(symbol, force_bit); // TODO - "if NULL object, make int" and "if not int, complain" + symbol_set_object(symbol, result, change_allowed); // FIXME - "backward anon allows number redef" is different from "!set allows object redef"! +} +// FIXME - temporary helper function during refactoring +// "po_set" means "!set", so changes are allowed +void symbol_set_object3(struct symbol *symbol, struct object *result, int force_bit, boolean po_set) +{ + // FIXME - force bit can only be used if result is number! check! + symbol_forcebit(symbol, force_bit); + // if this was called by !set, new force bit replaces old one: + if (po_set) { + // clear symbol's force bits and set new ones + // (but only do this for numbers!) + if (((symbol->object.type == &type_int) || (symbol->object.type == &type_float)) + && ((result->type == &type_int) || (result->type == &type_float))) { + symbol->object.u.number.flags &= ~(NUMBER_FORCEBITS | NUMBER_FITS_BYTE); + if (force_bit) { + symbol->object.u.number.flags |= force_bit; + result->u.number.flags &= ~(NUMBER_FORCEBITS | NUMBER_FITS_BYTE); + } + } + // FIXME - take a good look at the flags handling above and in the fn called below and clean this up! + } + symbol_set_object(symbol, result, po_set); +} // set global symbol to integer value, no questions asked (for "-D" switch) diff --git a/src/symbol.h b/src/symbol.h index 3dc7447..cc5cb72 100644 --- a/src/symbol.h +++ b/src/symbol.h @@ -29,13 +29,17 @@ struct symbol { extern struct rwnode *symbols_forest[]; // trees (because of 8-bit hash) +// FIXME - temporary helper function during refactoring +extern void symbol_forcebit(struct symbol *symbol, int force_bit); // function acts upon the symbol's flag bits and produces an error if needed. extern void symbol_set_object(struct symbol *symbol, struct object *new_obj, boolean change_allowed); +// FIXME - temporary helper function during refactoring +extern void symbol_set_object2(struct symbol *symbol, struct object *new_obj, int force_bit, boolean change_allowed); +// FIXME - temporary helper function during refactoring +extern void symbol_set_object3(struct symbol *symbol, struct object *new_obj, int force_bit, boolean change_allowed); // search for symbol. if it does not exist, create with NULL object (CAUTION!). // the symbol name must be held in GlobalDynaBuf. extern struct symbol *symbol_find(scope_t scope); -// FIXME -extern void symbol_forcebit(struct symbol *symbol, int force_bit); // set global symbol to value, no questions asked (for "-D" switch) // name must be held in GlobalDynaBuf. extern void symbol_define(intval_t value);