minor refactoring

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@183 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-05-20 16:39:19 +00:00
parent f5e7f23311
commit c1d8f90fae
4 changed files with 23 additions and 24 deletions

View File

@ -1935,7 +1935,8 @@ static void try_to_reduce_stacks(struct expression *expression)
// this is what the exported functions call
static void parse_expression(struct expression *expression)
// returns nonzero on parse error
static int parse_expression(struct expression *expression)
{
struct object *result = &expression->result;
@ -1997,6 +1998,7 @@ static void parse_expression(struct expression *expression)
}
// do some checks depending on int/float
result->type->fix_result(result);
return 0; // ok
} else {
// State is STATE_ERROR. Errors have already been reported,
// but we must make sure not to pass bogus data to caller.
@ -2010,6 +2012,7 @@ static void parse_expression(struct expression *expression)
// FIXME - remove this when new function interface gets used:
// callers must decide for themselves what to do when expression parser returns error
// (currently LDA'' results in both "no string given" AND "illegal combination of command and addressing mode"!)
return 1; // error
}
}
@ -2024,7 +2027,7 @@ intval_t ALU_any_int(void) // ACCEPT_UNDEFINED
{
struct expression expression;
parse_expression(&expression);
parse_expression(&expression); // FIXME - check return value and pass to caller!
if (expression.open_parentheses)
Throw_error(exception_paren_open);
if (expression.is_empty)
@ -2035,7 +2038,7 @@ intval_t ALU_any_int(void) // ACCEPT_UNDEFINED
if (expression.result.type == &type_float)
return expression.result.u.number.val.fpval;
Bug_found("Unhandled object type!", 0);
Throw_error("Expression did not return a number."); // TODO - add to docs!
return 0; // inhibit compiler warning
}
@ -2052,7 +2055,7 @@ void ALU_defined_int(struct number *intresult) // no ACCEPT constants?
boolean buf = pass.complain_about_undefined;
pass.complain_about_undefined = TRUE;
parse_expression(&expression);
parse_expression(&expression); // FIXME - check return value and pass to caller!
pass.complain_about_undefined = buf;
if (expression.open_parentheses)
Throw_error(exception_paren_open);
@ -2063,7 +2066,7 @@ void ALU_defined_int(struct number *intresult) // no ACCEPT constants?
} else if (expression.result.type == &type_float) {
float_to_int(&expression.result);
} else {
Bug_found("Unhandled object type!", 1);
Throw_serious_error("Expression did not return a number.");
}
if (!(expression.result.u.number.flags & NUMBER_IS_DEFINED))
Throw_serious_error(exception_value_not_defined);
@ -2081,12 +2084,12 @@ void ALU_defined_int(struct number *intresult) // no ACCEPT constants?
// FLOAT: convert to int
void ALU_addrmode_int(struct expression *expression, int paren) // ACCEPT_UNDEFINED | ACCEPT_OPENPARENTHESIS
{
parse_expression(expression);
parse_expression(expression); // FIXME - check return value and pass to caller!
// convert float to int
if (expression->result.type == &type_float)
float_to_int(&(expression->result));
if (expression->result.type != &type_int)
Bug_found("Unhandled object type!", 2);
Throw_error("Expression did not return a number.");
if (expression->open_parentheses > paren) {
expression->open_parentheses = 0;
Throw_error(exception_paren_open);
@ -2096,7 +2099,7 @@ void ALU_addrmode_int(struct expression *expression, int paren) // ACCEPT_UNDEFI
}
// Store value and flags (result may be either int or float)
// Store resulting object
// For empty expressions, an error is thrown.
// OPEN_PARENTHESIS: complain
// EMPTY: complain
@ -2106,7 +2109,7 @@ void ALU_any_result(struct object *result) // ACCEPT_UNDEFINED | ACCEPT_FLOAT
{
struct expression expression;
parse_expression(&expression);
parse_expression(&expression); // FIXME - check return value and pass to caller!
*result = expression.result;
if (expression.open_parentheses)
Throw_error(exception_paren_open);
@ -2117,8 +2120,7 @@ void ALU_any_result(struct object *result) // ACCEPT_UNDEFINED | ACCEPT_FLOAT
/* TODO
change parse_expression() to return error/ok.
after that, move
maybe move
if (expression.is_empty)
Throw_error(exception_no_value);
to end of parse_expression()
@ -2129,7 +2131,7 @@ void ALU_addrmode_int(struct expression *expression, int paren)
mnemo.c
when parsing addressing modes needvalue!
// stores value and flags (result may be either int or float)
// store resulting object
void ALU_any_result(struct object *result)
macro.c
macro call, when parsing call-by-value arg don't care

View File

@ -72,7 +72,7 @@ extern intval_t ALU_any_int(void);
extern void ALU_defined_int(struct number *intresult);
// stores int value and flags, allowing for "paren" '(' too many (x-indirect addr).
extern void ALU_addrmode_int(struct expression *expression, int paren);
// stores value and flags (result may be either int or float)
// stores resulting object
extern void ALU_any_result(struct object *result);

View File

@ -20,10 +20,8 @@
// Constants
#define MACRONAME_DYNABUF_INITIALSIZE 128
#define ARG_SEPARATOR ' ' // separates macro title from arg types
#define ARGTYPE_NUM_VAL 'v'
#define ARGTYPE_NUM_REF 'V'
//#define ARGTYPE_STR_VAL 's'
//#define ARGTYPE_STR_REF 'S'
#define ARGTYPE_VALUE 'v'
#define ARGTYPE_REF 'r'
#define REFERENCE_CHAR '~' // prefix for call-by-reference
#define HALF_INITIAL_ARG_TABLE_SIZE 4
static const char exception_macro_twice[] = "Macro already defined.";
@ -185,9 +183,9 @@ void Macro_parse_definition(void) // Now GotByte = illegal char after "!macro"
do {
// handle call-by-reference character ('~')
if (GotByte != REFERENCE_CHAR) {
DynaBuf_append(internal_name, ARGTYPE_NUM_VAL);
DynaBuf_append(internal_name, ARGTYPE_VALUE);
} else {
DynaBuf_append(internal_name, ARGTYPE_NUM_REF);
DynaBuf_append(internal_name, ARGTYPE_REF);
DynaBuf_append(GlobalDynaBuf, REFERENCE_CHAR);
GetByte();
}
@ -253,8 +251,7 @@ void Macro_parse_call(void) // Now GotByte = dot or first char of macro name
// Accept n>=0 comma-separated arguments before CHAR_EOS.
// Valid argument formats are:
// EXPRESSION (everything that does NOT start with '~'
// ~.LOCAL_LABEL_BY_REFERENCE
// ~GLOBAL_LABEL_BY_REFERENCE
// ~SYMBOL
// now GotByte = non-space
if (GotByte != CHAR_EOS) { // any at all?
do {
@ -265,14 +262,14 @@ void Macro_parse_call(void) // Now GotByte = dot or first char of macro name
// In both cases, GlobalDynaBuf may be used.
if (GotByte == REFERENCE_CHAR) {
// read call-by-reference arg
DynaBuf_append(internal_name, ARGTYPE_NUM_REF);
DynaBuf_append(internal_name, ARGTYPE_REF);
GetByte(); // skip '~' character
Input_read_scope_and_keyword(&symbol_scope);
// GotByte = illegal char
arg_table[arg_count].symbol = symbol_find(symbol_scope, 0);
} else {
// read call-by-value arg
DynaBuf_append(internal_name, ARGTYPE_NUM_VAL);
DynaBuf_append(internal_name, ARGTYPE_VALUE);
ALU_any_result(&(arg_table[arg_count].result));
}
++arg_count;

View File

@ -9,7 +9,7 @@
#define RELEASE "0.96.5" // update before release FIXME
#define CODENAME "Fenchurch" // update before release
#define CHANGE_DATE "19 May" // update before release FIXME
#define CHANGE_DATE "20 May" // 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