diff --git a/src/alu.c b/src/alu.c index 79152ee..0e9d9aa 100644 --- a/src/alu.c +++ b/src/alu.c @@ -313,18 +313,16 @@ static intval_t my_asr(intval_t left, intval_t right) // if wanted, throw "Value not defined" error // This function is not allowed to change DynaBuf because the symbol's name // might be stored there! -static void is_not_defined(struct symbol *optional_symbol, char *name, size_t length) +static void is_not_defined(struct symbol *symbol, char *name, size_t length) { if (!pass.flags.complain_about_undefined) return; // only complain once per symbol - if (optional_symbol) { - if (optional_symbol->has_been_reported) - return; + if (symbol->has_been_reported) + return; - optional_symbol->has_been_reported = TRUE; - } + symbol->has_been_reported = TRUE; dynabuf_clear(errormsg_dyna_buf); dynabuf_add_string(errormsg_dyna_buf, "Symbol not defined ("); @@ -397,10 +395,7 @@ static void parse_program_counter(void) // now GotByte = "*" struct object *arg; GetByte(); - programcounter_read(&pc); - // if needed, output "value not defined" error - if (pc.ntype == NUMTYPE_UNDEFINED) - is_not_defined(NULL, "*", 1); + programcounter_read_asterisk(&pc); // push to arg stack arg = &arg_stack[arg_sp++]; arg->type = &type_number; diff --git a/src/global.c b/src/global.c index 4c7a291..8fed22d 100644 --- a/src/global.c +++ b/src/global.c @@ -220,7 +220,7 @@ static void set_label(scope_t scope, bits force_bit, bits powers) } symbol = symbol_find(scope); result.type = &type_number; - programcounter_read(&result.u.number); // FIXME - if undefined, check pass.flags.complain_about_undefined and maybe throw "value not defined"! + programcounter_read_asterisk(&result.u.number); symbol_set_object(symbol, &result, powers); if (force_bit) symbol_set_force_bit(symbol, force_bit); diff --git a/src/mnemo.c b/src/mnemo.c index c22951f..2901882 100644 --- a/src/mnemo.c +++ b/src/mnemo.c @@ -812,7 +812,7 @@ static void near_branch(int preoffset) struct number target; intval_t offset = 0; // dummy value, to not throw more errors than necessary - programcounter_read(&pc); + programcounter_read_pc(&pc); get_int_arg(&target, TRUE); typesystem_want_addr(&target); if ((pc.ntype == NUMTYPE_INT) && (target.ntype == NUMTYPE_INT)) { @@ -847,7 +847,7 @@ static void far_branch(int preoffset) struct number target; intval_t offset = 0; // dummy value, to not throw more errors than necessary - programcounter_read(&pc); + programcounter_read_pc(&pc); get_int_arg(&target, TRUE); typesystem_want_addr(&target); if ((pc.ntype == NUMTYPE_INT) && (target.ntype == NUMTYPE_INT)) { diff --git a/src/output.c b/src/output.c index 1f90627..58757c9 100644 --- a/src/output.c +++ b/src/output.c @@ -454,8 +454,8 @@ void programcounter_set(intval_t new_pc, bits segment_flags) } -// read program counter -void programcounter_read(struct number *target) +// get program counter value +void programcounter_read_pc(struct number *target) { // check whether ptr undefined if (PC_NOT_SET) { @@ -467,6 +467,25 @@ void programcounter_read(struct number *target) target->val.intval = program_counter; target->addr_refs = 1; // program counter is an address } +// get program counter and check if defined +void programcounter_read_asterisk(struct number *target) +{ + programcounter_read_pc(target); + + // defined? + if (target->ntype != NUMTYPE_UNDEFINED) + return; + + // either complain or count + if (pass.flags.complain_about_undefined) + throw_error("Symbol not defined (*)."); + else + ++pass.counters.undefineds; + // counting is not needed when called by expression parser, because that + // will count undefined _results_ on its own. + // but if this was called by implicit label definition, we want to count + // undefined pc to make sure "label" throws the same error as "label=*" +} // get size of current statement (until now) - needed for "!bin" verbose output diff --git a/src/output.h b/src/output.h index 4a87b2d..a32af4f 100644 --- a/src/output.h +++ b/src/output.h @@ -49,8 +49,10 @@ extern void output_set_xor(char xor); // this will in turn set the outbuf index according to the current pseudopc offset. extern void programcounter_set(intval_t new_pc, bits segment_flags); -// get program counter -extern void programcounter_read(struct number *target); +// get program counter value +extern void programcounter_read_pc(struct number *target); +// get program counter and check if defined +extern void programcounter_read_asterisk(struct number *target); // get size of current statement (until now) - needed for "!bin" verbose output extern int output_get_statement_size(void); diff --git a/src/pseudoopcodes.c b/src/pseudoopcodes.c index 6633f13..12fb93d 100644 --- a/src/pseudoopcodes.c +++ b/src/pseudoopcodes.c @@ -651,7 +651,7 @@ static enum eos po_align(void) fill = cpu_current_type->default_align_value; // make sure PC is defined - programcounter_read(&pc); + programcounter_read_pc(&pc); if (pc.ntype == NUMTYPE_UNDEFINED) { throw_error(exception_pc_undefined); return SKIP_REMAINDER; diff --git a/src/version.h b/src/version.h index 242ef4c..1a3ef81 100644 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ #define RELEASE "0.97" // update before release FIXME #define CODENAME "Zem" // update before release -#define CHANGE_DATE "16 Aug" // update before release FIXME +#define CHANGE_DATE "17 Aug" // update before release FIXME #define CHANGE_YEAR "2024" // update before release //#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" #define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME diff --git a/testing/errors/valuenotdefined7.a b/testing/errors/valuenotdefined7.a new file mode 100644 index 0000000..5f2f0c7 --- /dev/null +++ b/testing/errors/valuenotdefined7.a @@ -0,0 +1,2 @@ +undef=* ; -> "Symbol not defined(*)." + *=$1000 diff --git a/testing/errors/valuenotdefined8.a b/testing/errors/valuenotdefined8.a new file mode 100644 index 0000000..b7f1331 --- /dev/null +++ b/testing/errors/valuenotdefined8.a @@ -0,0 +1,2 @@ +undef ; -> "Symbol not defined (*)." + *=$1000