more refactoring

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@216 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-06-05 09:51:10 +00:00
parent 61d5144faa
commit 02a35ac468
3 changed files with 40 additions and 26 deletions

View File

@ -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 // 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! 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 number pc;
struct object result; struct object result;
struct symbol *symbol;
if ((stat_flags & SF_FOUND_BLANK) && config.warn_on_indented_labels) if ((stat_flags & SF_FOUND_BLANK) && config.warn_on_indented_labels)
Throw_first_pass_warning("Label name not in leftmost column."); Throw_first_pass_warning("Label name not in leftmost column.");
symbol = symbol_find(scope); 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.type = &type_int;
result.u.number.flags = pc.flags & NUMBER_IS_DEFINED; result.u.number.flags = pc.flags & NUMBER_IS_DEFINED;
result.u.number.val.intval = pc.val.intval; result.u.number.val.intval = pc.val.intval;
result.u.number.addr_refs = pc.addr_refs; 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_object2(symbol, &result, force_bit, change_allowed);
symbol_set_object(symbol, &result, change_allowed); // FIXME - "backward anon allows number redef" is different from "!set allows object redef"!
symbol->pseudopc = pseudopc_get_context(); symbol->pseudopc = pseudopc_get_context();
// global labels must open new scope for cheap locals // global labels must open new scope for cheap locals
if (scope == SCOPE_GLOBAL) 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.type == &type_float))
result.u.number.addr_refs = 1; result.u.number.addr_refs = 1;
} }
// FIXME - force bit can only be used if result is number! check! symbol_set_object3(symbol, &result, force_bit, po_set);
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);
} }

View File

@ -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) void symbol_forcebit(struct symbol *symbol, int force_bit)
{ {
// if symbol has no object assigned to it, make it an int // 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; 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) // set global symbol to integer value, no questions asked (for "-D" switch)

View File

@ -29,13 +29,17 @@ struct symbol {
extern struct rwnode *symbols_forest[]; // trees (because of 8-bit hash) 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. // 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); 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!). // search for symbol. if it does not exist, create with NULL object (CAUTION!).
// the symbol name must be held in GlobalDynaBuf. // the symbol name must be held in GlobalDynaBuf.
extern struct symbol *symbol_find(scope_t scope); 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) // set global symbol to value, no questions asked (for "-D" switch)
// name must be held in GlobalDynaBuf. // name must be held in GlobalDynaBuf.
extern void symbol_define(intval_t value); extern void symbol_define(intval_t value);