From a4afd81f42813216652fdd2e7ab60920b5d6ed07 Mon Sep 17 00:00:00 2001 From: marcobaye Date: Sun, 26 Apr 2020 16:24:34 +0000 Subject: [PATCH] some internal cleanup concerning empty expressions git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@123 4df02467-bbd4-4a76-a152-e7ce94205b78 --- src/alu.c | 20 +++++++++++++------- src/alu.h | 7 +++---- src/flow.c | 4 ++-- src/mnemo.c | 22 +++++++++++----------- src/output.c | 2 +- src/pseudoopcodes.c | 2 +- src/symbol.c | 2 +- src/version.h | 2 +- 8 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/alu.c b/src/alu.c index c1ce149..2467134 100644 --- a/src/alu.c +++ b/src/alu.c @@ -12,7 +12,7 @@ // give a warning). // 31 May 2014 Added "0b" binary number prefix as alternative to "%". // 28 Apr 2015 Added symbol name output to "value not defined" error. -// 1 Feb 2019 Prepared to make "honor leading zeroes" optionally later on. +// 1 Feb 2019 Prepared to make "honor leading zeroes" optionally (now done) #include "alu.h" #include #include // only for fp support @@ -778,6 +778,7 @@ static void expect_operand_or_monadic_operator(void) if (operator_stack[operator_sp - 1] == &ops_exprstart) { PUSH_OPERATOR(&ops_exprend); alu_state = STATE_TRY_TO_REDUCE_STACKS; + // TODO - return "there was nothing" to get rid of "EXISTS" flag? } else { Throw_error(exception_syntax); alu_state = STATE_ERROR; @@ -799,6 +800,7 @@ now_expect_dyadic: alu_state = STATE_EXPECT_DYADIC_OPERATOR; break; } + // TODO - return "there was something" to get rid of "EXISTS" flag? } @@ -1508,7 +1510,7 @@ static int parse_expression(struct result *result) // (currently LDA'' results in both "no string given" AND "illegal combination of command and addressing mode"!) } // return number of open (unmatched) parentheses - return open_parentheses; + return open_parentheses; // FIXME - move this into "expression struct flags", together with indirect flag and EXISTS flag } @@ -1528,9 +1530,9 @@ int ALU_optional_defined_int(intval_t *target) // ACCEPT_EMPTY if (parse_expression(&result)) Throw_error(exception_paren_open); // do not combine the next two checks, they were separated because EXISTS should move from result flags to expression flags... - if (result.flags & MVALUE_EXISTS) - if ((result.flags & MVALUE_DEFINED) == 0) - Throw_serious_error(value_not_defined()); + if ((result.flags & MVALUE_EXISTS) + && ((result.flags & MVALUE_DEFINED) == 0)) + Throw_serious_error(value_not_defined()); if ((result.flags & MVALUE_EXISTS) == 0) return 0; @@ -1616,11 +1618,13 @@ extern void ALU_defined_int(struct result *intresult) // no ACCEPT constants? // This function allows for one '(' too many. Needed when parsing indirect // addressing modes where internal indices have to be possible. Returns number // of parentheses still open (either 0 or 1). +// If the result's "exists" flag is clear (=empty expression), it throws an +// error. // OPEN_PARENTHESIS: allow // UNDEFINED: allow -// EMPTY: allow +// EMPTY: complain // FLOAT: convert to int -int ALU_liberal_int(struct result *intresult) // ACCEPT_EMPTY | ACCEPT_UNDEFINED | ACCEPT_OPENPARENTHESIS +int ALU_liberal_int(struct result *intresult) // ACCEPT_UNDEFINED | ACCEPT_OPENPARENTHESIS { int parentheses_still_open; @@ -1634,6 +1638,8 @@ int ALU_liberal_int(struct result *intresult) // ACCEPT_EMPTY | ACCEPT_UNDEFINED parentheses_still_open = 0; Throw_error(exception_paren_open); } + if ((intresult->flags & MVALUE_EXISTS) == 0) + Throw_error(exception_no_value); if ((intresult->flags & MVALUE_EXISTS) && ((intresult->flags & MVALUE_DEFINED) == 0)) result_is_undefined(); diff --git a/src/alu.h b/src/alu.h index 19dda47..a046803 100644 --- a/src/alu.h +++ b/src/alu.h @@ -12,10 +12,10 @@ // constants -// meaning of bits in "flags" of struct result: -// TODO - this is only for future "number" result type, so move EXISTS and INDIRECT somewhere else (expression flags? make "nothing" its own result type!) +// TODO - move EXISTS and INDIRECT to a new "expression flags" struct! make "nothing" its own result type? #define MVALUE_EXISTS (1u << 8) // 0: expression was empty. 1: there was *something* to parse. #define MVALUE_INDIRECT (1u << 7) // needless parentheses indicate use of indirect addressing modes +// meaning of bits in "flags" of struct result: #define MVALUE_IS_FP (1u << 6) // floating point value #define MVALUE_UNSURE (1u << 5) // value once was related to undefined // expression. Needed for producing the same addresses in all passes; because in @@ -26,8 +26,7 @@ #define MVALUE_FORCE24 (1u << 2) // value usage forces 24-bit usage #define MVALUE_FORCE16 (1u << 1) // value usage forces 16-bit usage #define MVALUE_FORCE08 (1u << 0) // value usage forces 8-bit usage -#define MVALUE_FORCEBITS (MVALUE_FORCE08|MVALUE_FORCE16|MVALUE_FORCE24) -//#define MVALUE_GIVEN (MVALUE_DEFINED | MVALUE_EXISTS) // bit mask for fixed values (defined and existing) TODO: remove this +#define MVALUE_FORCEBITS (MVALUE_FORCE08 | MVALUE_FORCE16 | MVALUE_FORCE24) // create dynamic buffer, operator/function trees and operator/operand stacks diff --git a/src/flow.c b/src/flow.c index 63695c1..fa0c7e2 100644 --- a/src/flow.c +++ b/src/flow.c @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2019 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // Flow control stuff (loops, conditional assembly etc.) @@ -55,7 +55,7 @@ void flow_forloop(struct for_loop *loop) // (not yet useable; pointer and line number are still missing) Input_now = &loop_input; // init counter - loop_counter.flags = MVALUE_DEFINED | MVALUE_EXISTS; // TODO - remove EXISTS, it is never checked + loop_counter.flags = MVALUE_DEFINED; loop_counter.val.intval = loop->counter.first; loop_counter.addr_refs = loop->counter.addr_refs; symbol_set_value(loop->symbol, &loop_counter, TRUE); diff --git a/src/mnemo.c b/src/mnemo.c index 64c29b8..1a1853e 100644 --- a/src/mnemo.c +++ b/src/mnemo.c @@ -528,28 +528,28 @@ static int get_argument(struct result *result) SKIPSPACE(); switch (GotByte) { + case CHAR_EOS: + address_mode_bits = AMB_IMPLIED; + break; + case '#': + GetByte(); // proceed with next char + address_mode_bits = AMB_IMMEDIATE; + ALU_int_result(result); + typesystem_want_imm(result); // FIXME - this is wrong for 65ce02's PHW# + break; case '[': GetByte(); // proceed with next char ALU_int_result(result); typesystem_want_addr(result); if (GotByte == ']') - address_mode_bits |= AMB_LONGINDIRECT | AMB_INDEX(get_index(TRUE)); + address_mode_bits = AMB_LONGINDIRECT | AMB_INDEX(get_index(TRUE)); else Throw_error(exception_syntax); break; - case '#': - GetByte(); // proceed with next char - address_mode_bits |= AMB_IMMEDIATE; - ALU_int_result(result); - typesystem_want_imm(result); // FIXME - this is wrong for 65ce02's PHW# - break; default: // liberal, to allow for "(...," open_paren = ALU_liberal_int(result); typesystem_want_addr(result); - // check for implied addressing - if ((result->flags & MVALUE_EXISTS) == 0) - address_mode_bits |= AMB_IMPLIED; // check for indirect addressing if (result->flags & MVALUE_INDIRECT) address_mode_bits |= AMB_INDIRECT; @@ -568,7 +568,7 @@ static int get_argument(struct result *result) } // ensure end of line Input_ensure_EOS(); - //printf("AM: %x\n", addressing_mode); + //printf("AM: %x\n", address_mode_bits); return address_mode_bits; } diff --git a/src/output.c b/src/output.c index 9feba09..bee2eee 100644 --- a/src/output.c +++ b/src/output.c @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2019 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // Output stuff diff --git a/src/pseudoopcodes.c b/src/pseudoopcodes.c index 3f40adb..97080ea 100644 --- a/src/pseudoopcodes.c +++ b/src/pseudoopcodes.c @@ -1,5 +1,5 @@ // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. -// Copyright (C) 1998-2017 Marco Baye +// Copyright (C) 1998-2020 Marco Baye // Have a look at "acme.c" for further info // // pseudo opcode stuff diff --git a/src/symbol.c b/src/symbol.c index 877ccb2..ab12a96 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -222,7 +222,7 @@ void symbol_define(intval_t value) struct result result; struct symbol *symbol; - result.flags = MVALUE_DEFINED | MVALUE_EXISTS; // TODO - remove EXISTS, it is never checked + result.flags = MVALUE_DEFINED; result.val.intval = value; symbol = symbol_find(SCOPE_GLOBAL, 0); symbol_set_value(symbol, &result, TRUE); diff --git a/src/version.h b/src/version.h index 6b88f41..675d86b 100644 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ #define RELEASE "0.96.5" // update before release FIXME #define CODENAME "Fenchurch" // update before release -#define CHANGE_DATE "25 Apr" // update before release FIXME +#define CHANGE_DATE "26 Apr" // update before release FIXME #define CHANGE_YEAR "2020" // update before release //#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" #define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME