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
This commit is contained in:
marcobaye 2020-04-26 16:24:34 +00:00
parent c6f443d581
commit a4afd81f42
8 changed files with 33 additions and 28 deletions

View File

@ -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 <stdlib.h>
#include <math.h> // 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();

View File

@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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