mirror of
https://github.com/uffejakobsen/acme.git
synced 2025-08-15 18:27:32 +00:00
internal cleanup: moved "indirect" flag from result to expression struct
git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@125 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
30
src/alu.c
30
src/alu.c
@@ -158,9 +158,6 @@ static int operator_sp; // operator stack pointer
|
|||||||
static struct result *operand_stack = NULL; // flags and value
|
static struct result *operand_stack = NULL; // flags and value
|
||||||
static int operand_stk_size = HALF_INITIAL_STACK_SIZE;
|
static int operand_stk_size = HALF_INITIAL_STACK_SIZE;
|
||||||
static int operand_sp; // value stack pointer
|
static int operand_sp; // value stack pointer
|
||||||
static int indirect_flag; // Flag for indirect addressing TODO - get rid of extra var
|
|
||||||
// (indicated by useless parentheses)
|
|
||||||
// Contains either 0 or MVALUE_INDIRECT
|
|
||||||
enum alu_state {
|
enum alu_state {
|
||||||
STATE_EXPECT_OPERAND_OR_MONADIC_OPERATOR,
|
STATE_EXPECT_OPERAND_OR_MONADIC_OPERATOR,
|
||||||
STATE_EXPECT_DYADIC_OPERATOR,
|
STATE_EXPECT_DYADIC_OPERATOR,
|
||||||
@@ -1029,7 +1026,7 @@ static void ensure_int_from_fp(void)
|
|||||||
|
|
||||||
// Try to reduce stacks by performing high-priority operations
|
// Try to reduce stacks by performing high-priority operations
|
||||||
// (if the previous operator has a higher priority than the current one, do it)
|
// (if the previous operator has a higher priority than the current one, do it)
|
||||||
static void try_to_reduce_stacks(int *open_parentheses)
|
static void try_to_reduce_stacks(struct expression *expression)
|
||||||
{
|
{
|
||||||
if (operator_sp < 2) {
|
if (operator_sp < 2) {
|
||||||
alu_state = STATE_EXPECT_OPERAND_OR_MONADIC_OPERATOR;
|
alu_state = STATE_EXPECT_OPERAND_OR_MONADIC_OPERATOR;
|
||||||
@@ -1056,29 +1053,29 @@ static void try_to_reduce_stacks(int *open_parentheses)
|
|||||||
// the only operator with a lower priority than this
|
// the only operator with a lower priority than this
|
||||||
// "start-of-expression" operator is "end-of-expression",
|
// "start-of-expression" operator is "end-of-expression",
|
||||||
// therefore we know we are done.
|
// therefore we know we are done.
|
||||||
// don't touch indirect_flag; needed for INDIRECT flag
|
// don't touch "is_parenthesized", because start/end are obviously not "real" operators
|
||||||
--operator_sp; // decrement operator stack pointer
|
--operator_sp; // decrement operator stack pointer
|
||||||
alu_state = STATE_END;
|
alu_state = STATE_END;
|
||||||
break;
|
break; // FIXME - why not return?
|
||||||
case OPHANDLE_OPENING:
|
case OPHANDLE_OPENING:
|
||||||
indirect_flag = MVALUE_INDIRECT; // parentheses found
|
expression->is_parenthesized = TRUE; // found parentheses. if this is not the outermost level, the outermost level will fix this.
|
||||||
switch (operator_stack[operator_sp - 1]->handle) {
|
switch (operator_stack[operator_sp - 1]->handle) {
|
||||||
case OPHANDLE_CLOSING: // matching parentheses
|
case OPHANDLE_CLOSING: // matching parentheses
|
||||||
operator_sp -= 2; // remove both of them
|
operator_sp -= 2; // remove both of them
|
||||||
alu_state = STATE_EXPECT_DYADIC_OPERATOR;
|
alu_state = STATE_EXPECT_DYADIC_OPERATOR;
|
||||||
break;
|
break;
|
||||||
case OPHANDLE_EXPREND: // unmatched parenthesis
|
case OPHANDLE_EXPREND: // unmatched parenthesis
|
||||||
++(*open_parentheses); // count
|
++(expression->open_parentheses); // count
|
||||||
goto RNTLObutDontTouchIndirectFlag;
|
goto RNTLObutDontTouchIndirectFlag;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Bug_found("StrangeParenthesis", operator_stack[operator_sp - 1]->handle);
|
Bug_found("StrangeParenthesis", operator_stack[operator_sp - 1]->handle);
|
||||||
}
|
}
|
||||||
break;
|
break; // FIXME - why not return?
|
||||||
case OPHANDLE_CLOSING:
|
case OPHANDLE_CLOSING:
|
||||||
Throw_error("Too many ')'.");
|
Throw_error("Too many ')'.");
|
||||||
alu_state = STATE_ERROR;
|
alu_state = STATE_ERROR;
|
||||||
return;
|
return; // FIXME - why not break?
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
case OPHANDLE_ADDR:
|
case OPHANDLE_ADDR:
|
||||||
@@ -1413,9 +1410,9 @@ handle_flags_and_dec_stacks:
|
|||||||
--operand_sp;
|
--operand_sp;
|
||||||
// entry point for monadic operators
|
// entry point for monadic operators
|
||||||
remove_next_to_last_operator:
|
remove_next_to_last_operator:
|
||||||
// toplevel operation was something other than parentheses
|
// operation was something other than parentheses
|
||||||
indirect_flag = 0;
|
expression->is_parenthesized = FALSE;
|
||||||
// entry point for '(' operator (has set indirect_flag, so don't clear now)
|
// entry point for when '(' operator meets "end of expression": keep is_parenthesized set!
|
||||||
RNTLObutDontTouchIndirectFlag:
|
RNTLObutDontTouchIndirectFlag:
|
||||||
// Remove operator and shift down next one
|
// Remove operator and shift down next one
|
||||||
operator_stack[operator_sp - 2] = operator_stack[operator_sp - 1];
|
operator_stack[operator_sp - 2] = operator_stack[operator_sp - 1];
|
||||||
@@ -1429,13 +1426,15 @@ static void parse_expression(struct expression *expression)
|
|||||||
{
|
{
|
||||||
struct result *result = &expression->number;
|
struct result *result = &expression->number;
|
||||||
|
|
||||||
|
// init
|
||||||
expression->open_parentheses = 0;
|
expression->open_parentheses = 0;
|
||||||
|
expression->is_parenthesized = FALSE; // toplevel operator will set this: '(' to TRUE, all others to FALSE
|
||||||
|
//expression->number will be overwritten later, so no need to init
|
||||||
|
|
||||||
operator_sp = 0; // operator stack pointer
|
operator_sp = 0; // operator stack pointer
|
||||||
operand_sp = 0; // value stack pointer
|
operand_sp = 0; // value stack pointer
|
||||||
// begin by reading value (or monadic operator)
|
// begin by reading value (or monadic operator)
|
||||||
alu_state = STATE_EXPECT_OPERAND_OR_MONADIC_OPERATOR;
|
alu_state = STATE_EXPECT_OPERAND_OR_MONADIC_OPERATOR;
|
||||||
indirect_flag = 0; // Contains either 0 or MVALUE_INDIRECT // FIXME
|
|
||||||
PUSH_OPERATOR(&ops_exprstart);
|
PUSH_OPERATOR(&ops_exprstart);
|
||||||
do {
|
do {
|
||||||
// check stack sizes. enlarge if needed
|
// check stack sizes. enlarge if needed
|
||||||
@@ -1452,7 +1451,7 @@ static void parse_expression(struct expression *expression)
|
|||||||
break; // no fallthrough; state might
|
break; // no fallthrough; state might
|
||||||
// have been changed to END or ERROR
|
// have been changed to END or ERROR
|
||||||
case STATE_TRY_TO_REDUCE_STACKS:
|
case STATE_TRY_TO_REDUCE_STACKS:
|
||||||
try_to_reduce_stacks(&expression->open_parentheses);
|
try_to_reduce_stacks(expression);
|
||||||
break;
|
break;
|
||||||
case STATE_MAX_GO_ON: // suppress
|
case STATE_MAX_GO_ON: // suppress
|
||||||
case STATE_ERROR: // compiler
|
case STATE_ERROR: // compiler
|
||||||
@@ -1469,7 +1468,6 @@ static void parse_expression(struct expression *expression)
|
|||||||
Bug_found("OperatorStackNotEmpty", operator_sp);
|
Bug_found("OperatorStackNotEmpty", operator_sp);
|
||||||
// copy result
|
// copy result
|
||||||
*result = operand_stack[0];
|
*result = operand_stack[0];
|
||||||
expression->number.flags |= indirect_flag; // OR indirect flag FIXME - get rid of "indirect"
|
|
||||||
// only allow *one* force bit
|
// only allow *one* force bit
|
||||||
if (result->flags & MVALUE_FORCE24)
|
if (result->flags & MVALUE_FORCE24)
|
||||||
result->flags &= ~(MVALUE_FORCE16 | MVALUE_FORCE08);
|
result->flags &= ~(MVALUE_FORCE16 | MVALUE_FORCE08);
|
||||||
|
@@ -25,6 +25,7 @@ struct expression {
|
|||||||
struct result number;
|
struct result number;
|
||||||
//int flags; // TODO: move EXISTS and INDIRECT here
|
//int flags; // TODO: move EXISTS and INDIRECT here
|
||||||
int open_parentheses; // number of parentheses still open
|
int open_parentheses; // number of parentheses still open
|
||||||
|
int is_parenthesized; // actually bool: whole expression was in parentheses (indicating indirect addressing)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ struct expression {
|
|||||||
|
|
||||||
// TODO - move EXISTS and INDIRECT to a new "expression flags" struct! 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_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:
|
// meaning of bits in "flags" of struct result:
|
||||||
#define MVALUE_IS_FP (1u << 6) // floating point value
|
#define MVALUE_IS_FP (1u << 6) // floating point value
|
||||||
#define MVALUE_UNSURE (1u << 5) // value once was related to undefined
|
#define MVALUE_UNSURE (1u << 5) // value once was related to undefined
|
||||||
|
@@ -552,7 +552,7 @@ static int get_argument(struct result *result)
|
|||||||
*result = expression.number;
|
*result = expression.number;
|
||||||
typesystem_want_addr(result);
|
typesystem_want_addr(result);
|
||||||
// check for indirect addressing
|
// check for indirect addressing
|
||||||
if (expression.number.flags & MVALUE_INDIRECT)
|
if (expression.is_parenthesized)
|
||||||
address_mode_bits |= AMB_INDIRECT;
|
address_mode_bits |= AMB_INDIRECT;
|
||||||
// check for internal index (before closing parenthesis)
|
// check for internal index (before closing parenthesis)
|
||||||
if (expression.open_parentheses) {
|
if (expression.open_parentheses) {
|
||||||
|
Reference in New Issue
Block a user