symbol assigment refactoring nearing completion...

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@217 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-06-05 15:15:12 +00:00
parent 02a35ac468
commit 77e945ce88
5 changed files with 19 additions and 13 deletions

View File

@ -59,14 +59,15 @@ void flow_forloop(struct for_loop *loop)
loop_counter.u.number.flags = NUMBER_IS_DEFINED;
loop_counter.u.number.val.intval = loop->counter.first;
loop_counter.u.number.addr_refs = loop->counter.addr_refs;
symbol_set_object(loop->symbol, &loop_counter, TRUE);
symbol_set_object2(loop->symbol, &loop_counter, loop->force_bit, TRUE);
loop_counter = loop->symbol->object; // update local copy with force bit
if (loop->use_old_algo) {
// old algo for old syntax:
// if count == 0, skip loop
if (loop->counter.last) {
do {
loop_counter.u.number.val.intval += loop->counter.increment;
symbol_set_object(loop->symbol, &loop_counter, TRUE);
loop->symbol->object = loop_counter; // overwrite whole struct, in case some joker has re-assigned loop counter var
parse_ram_block(&loop->block);
} while (loop_counter.u.number.val.intval < loop->counter.last);
}
@ -75,7 +76,7 @@ void flow_forloop(struct for_loop *loop)
do {
parse_ram_block(&loop->block);
loop_counter.u.number.val.intval += loop->counter.increment;
symbol_set_object(loop->symbol, &loop_counter, TRUE);
loop->symbol->object = loop_counter; // overwrite whole struct, in case some joker has re-assigned loop counter var
} while (loop_counter.u.number.val.intval != (loop->counter.last + loop->counter.increment));
}
// restore previous input:

View File

@ -19,6 +19,7 @@ struct block {
// struct to pass "!for" loop stuff from pseudoopcodes.c to flow.c
struct for_loop {
struct symbol *symbol;
int force_bit;
boolean use_old_algo;
struct {
intval_t first,

View File

@ -1030,17 +1030,15 @@ static enum eos po_ifndef(void) // now GotByte = illegal char
static enum eos po_for(void) // now GotByte = illegal char
{
scope_t scope;
int force_bit;
struct number intresult;
struct for_loop loop;
struct number intresult;
if (Input_read_scope_and_keyword(&scope) == 0) // skips spaces before
return SKIP_REMAINDER; // zero length
// now GotByte = illegal char
force_bit = Input_get_force_bit(); // skips spaces after
loop.force_bit = Input_get_force_bit(); // skips spaces after
loop.symbol = symbol_find(scope); // FIXME - if type is not NULL, complain if not number!
symbol_forcebit(loop.symbol, force_bit);
if (!Input_accept_comma()) {
Throw_error(exception_syntax);
return SKIP_REMAINDER;

View File

@ -136,7 +136,7 @@ struct symbol *symbol_find(scope_t scope)
// FIXME - temporary helper function during refactoring
void symbol_forcebit(struct symbol *symbol, int force_bit)
static void symbol_forcebit(struct symbol *symbol, int force_bit)
{
// if symbol has no object assigned to it, make it an int
if (symbol->object.type == NULL) {
@ -157,7 +157,7 @@ void symbol_forcebit(struct symbol *symbol, int force_bit)
// assign value to symbol. the function acts upon the symbol's flag bits and
// produces an error if needed.
// TODO - split checks into two parts: first deal with object type. in case of number, then check value/flags/whatever
void symbol_set_object(struct symbol *symbol, struct object *new_value, boolean change_allowed) // FIXME - does "change_allowed" refer to type change or number value change?
static void symbol_set_object(struct symbol *symbol, struct object *new_value, boolean change_allowed) // FIXME - does "change_allowed" refer to type change or number value change?
{
int flags; // for int/float re-definitions
@ -172,6 +172,8 @@ void symbol_set_object(struct symbol *symbol, struct object *new_value, boolean
return;
}
// FIXME - force bits assigned via !for or !set are lost, because due to "change_allowed", the new object struct is copied and that's it!
// both old and new are either int or float, so keep old algo:
// value stuff
@ -203,13 +205,19 @@ void symbol_set_object(struct symbol *symbol, struct object *new_value, boolean
symbol->object.u.number.flags = flags;
}
// FIXME - temporary helper function during refactoring
// used for:
// (implicit!) label definitions, including anons (FIXME - anons cannot have force bits. handle them elsewhere? change backward anons directly, no questions asked?)
// setting up loop counter for "!for" (actual incrementing is then done directly!)
// "change_allowed" is used by backward anons, but then force_bit is 0
// "change_allowed" is also used by "!for", then force_bit may be nonzero
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
// used for:
// explicit assignments, including "!set"
// "po_set" means "!set", so changes are allowed
void symbol_set_object3(struct symbol *symbol, struct object *result, int force_bit, boolean po_set)
{

View File

@ -29,15 +29,13 @@ 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);
//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 type object (CAUTION!).
// the symbol name must be held in GlobalDynaBuf.
extern struct symbol *symbol_find(scope_t scope);
// set global symbol to value, no questions asked (for "-D" switch)