mirror of
https://github.com/uffejakobsen/acme.git
synced 2024-11-22 18:32:09 +00:00
more refactoring of input
git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@386 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
parent
b11bdcded0
commit
a53aa01a1e
51
src/flow.c
51
src/flow.c
@ -53,8 +53,9 @@ boolean check_ifdef_condition(void)
|
||||
// parse a loop body (TODO - also use for macro body?)
|
||||
static void parse_ram_block(struct block *block)
|
||||
{
|
||||
input_now->location.line_number = block->start; // set line number to loop start
|
||||
input_now->src.ram_ptr = block->body; // set RAM read pointer to loop
|
||||
// set line number to loop start
|
||||
// set RAM read pointer to loop
|
||||
inputchange_set_ram(block->start, block->body);
|
||||
// parse block
|
||||
parse_until_eob_or_eof();
|
||||
if (GotByte != CHAR_EOB)
|
||||
@ -118,20 +119,13 @@ static void iterating_for(struct for_loop *loop)
|
||||
// back end function for "!for" pseudo opcode
|
||||
void flow_forloop(struct for_loop *loop)
|
||||
{
|
||||
struct input loop_input,
|
||||
*outer_input;
|
||||
struct inputchange_buf icb;
|
||||
|
||||
// switching input makes us lose GotByte. But we know it's '}' anyway!
|
||||
// set up new input
|
||||
loop_input = *input_now; // copy current input structure into new
|
||||
loop_input.source = INPUTSRC_RAM; // set new byte source
|
||||
// remember old input
|
||||
outer_input = input_now;
|
||||
// activate new input
|
||||
// (not yet useable; pointer and line number are still missing)
|
||||
input_now = &loop_input;
|
||||
// remember input and set up new one:
|
||||
inputchange_new_ram(&icb);
|
||||
// fix line number (not for block, but in case symbol handling throws errors)
|
||||
input_now->location.line_number = loop->block.start;
|
||||
inputchange_set_ram(loop->block.start, NULL);
|
||||
|
||||
switch (loop->algorithm) {
|
||||
case FORALGO_OLDCOUNT:
|
||||
case FORALGO_NEWCOUNT:
|
||||
@ -143,8 +137,9 @@ void flow_forloop(struct for_loop *loop)
|
||||
default:
|
||||
BUG("IllegalLoopAlgo", loop->algorithm);
|
||||
}
|
||||
// restore previous input:
|
||||
input_now = outer_input;
|
||||
|
||||
// restore outer input
|
||||
inputchange_back(&icb);
|
||||
}
|
||||
|
||||
|
||||
@ -223,8 +218,8 @@ static boolean check_condition(struct condition *condition)
|
||||
return TRUE; // non-existing conditions are always true
|
||||
|
||||
// set up input for expression evaluation
|
||||
input_now->location.line_number = condition->line;
|
||||
input_now->src.ram_ptr = condition->body;
|
||||
inputchange_set_ram(condition->line, condition->body);
|
||||
|
||||
GetByte(); // proceed with next char
|
||||
ALU_defined_int(&intresult);
|
||||
if (GotByte)
|
||||
@ -236,17 +231,11 @@ static boolean check_condition(struct condition *condition)
|
||||
// back end function for "!do" and "!while" pseudo opcodes
|
||||
void flow_do_while(struct do_while *loop)
|
||||
{
|
||||
struct input loop_input;
|
||||
struct input *outer_input;
|
||||
struct inputchange_buf icb;
|
||||
|
||||
// remember input and prepare new one:
|
||||
inputchange_new_ram(&icb);
|
||||
|
||||
// set up new input
|
||||
loop_input = *input_now; // copy current input structure into new
|
||||
loop_input.source = INPUTSRC_RAM; // set new byte source
|
||||
// remember old input
|
||||
outer_input = input_now;
|
||||
// activate new input (not useable yet, as pointer and
|
||||
// line number are not yet set up)
|
||||
input_now = &loop_input;
|
||||
for (;;) {
|
||||
// check head condition
|
||||
if (!check_condition(&loop->head_cond))
|
||||
@ -256,8 +245,10 @@ void flow_do_while(struct do_while *loop)
|
||||
if (!check_condition(&loop->tail_cond))
|
||||
break;
|
||||
}
|
||||
// restore previous input:
|
||||
input_now = outer_input;
|
||||
// restore outer input
|
||||
inputchange_back(&icb);
|
||||
// FIXME - the line above also restores GotByte, so this is no longer necessary,
|
||||
// but check before removing:
|
||||
GotByte = CHAR_EOS; // CAUTION! Very ugly kluge.
|
||||
// But by switching input, we lost the outer input's GotByte. We know
|
||||
// it was CHAR_EOS. We could just call GetByte() to get real input, but
|
||||
|
30
src/input.c
30
src/input.c
@ -854,29 +854,41 @@ void inputchange_new_file(struct inputchange_buf *icb, FILE *fd, const char *ete
|
||||
icb->new_input.src.fd = fd;
|
||||
// remember where outer input struct is
|
||||
icb->outer_input = input_now;
|
||||
// activate new input
|
||||
icb->gb = GotByte;
|
||||
// activate new input
|
||||
input_now = &icb->new_input;
|
||||
}
|
||||
// save current input struct in buffer, then switch input to macro parameters
|
||||
void inputchange_macro1_params(struct inputchange_buf *icb, struct location *def, char *params)
|
||||
// save current input struct in buffer, then switch to RAM
|
||||
void inputchange_new_ram(struct inputchange_buf *icb)
|
||||
{
|
||||
icb->new_input = *input_now; // copy current input structure into new
|
||||
icb->new_input.location = *def;
|
||||
icb->new_input.source = INPUTSRC_RAM;
|
||||
icb->new_input.state = INPUTSTATE_NORMAL; // FIXME - fix others!
|
||||
icb->new_input.src.ram_ptr = params;
|
||||
icb->new_input.source = INPUTSRC_RAM; // set new byte source
|
||||
icb->new_input.src.ram_ptr = NULL; // force crash if used before setup is finished
|
||||
// remember where outer input struct is
|
||||
icb->outer_input = input_now;
|
||||
// activate new input
|
||||
icb->gb = GotByte;
|
||||
// activate new input (not useable yet, as pointer and line number are not yet set up)
|
||||
input_now = &icb->new_input;
|
||||
}
|
||||
// FIXME - merge these three functions into a single one (by always using a "location"):
|
||||
// setup for reading from RAM (for parsing loop conditions etc.)
|
||||
void inputchange_set_ram(int line_num, char *body)
|
||||
{
|
||||
input_now->location.line_number = line_num;
|
||||
input_now->src.ram_ptr = body;
|
||||
}
|
||||
// switch input to macro parameters
|
||||
void inputchange_macro1_params(struct location *def, char *params)
|
||||
{
|
||||
input_now->location = *def;
|
||||
input_now->src.ram_ptr = params;
|
||||
input_now->state = INPUTSTATE_NORMAL; // FIXME - fix others!
|
||||
}
|
||||
// switch from macro parameters to macro body
|
||||
void inputchange_macro2_body(char *macro_body)
|
||||
{
|
||||
input_now->state = INPUTSTATE_NORMAL; // FIXME - fix others!
|
||||
input_now->src.ram_ptr = macro_body;
|
||||
input_now->state = INPUTSTATE_NORMAL; // FIXME - fix others!
|
||||
}
|
||||
// restore input struct from buffer
|
||||
void inputchange_back(const struct inputchange_buf *icb)
|
||||
|
@ -156,8 +156,12 @@ struct inputchange_buf {
|
||||
};
|
||||
// save current input struct in buffer, then switch input to new source code file
|
||||
extern void inputchange_new_file(struct inputchange_buf *icb, FILE *fd, const char *eternal_plat_filename);
|
||||
// save current input struct in buffer, then switch input to macro parameters
|
||||
extern void inputchange_macro1_params(struct inputchange_buf *icb, struct location *def, char *params);
|
||||
// save current input struct in buffer, then switch to RAM
|
||||
extern void inputchange_new_ram(struct inputchange_buf *icb);
|
||||
// setup for reading from RAM (for parsing loop conditions etc.)
|
||||
extern void inputchange_set_ram(int line_num, char *body);
|
||||
// switch input to macro parameters
|
||||
extern void inputchange_macro1_params(struct location *def, char *params);
|
||||
// switch from macro parameters to macro body
|
||||
extern void inputchange_macro2_body(char *macro_body);
|
||||
// restore input struct from buffer
|
||||
|
@ -240,8 +240,9 @@ void macro_parse_call(void) // Now GotByte = first char of macro name
|
||||
// make macro_node point to the macro struct
|
||||
actual_macro = macro_node->body;
|
||||
|
||||
// set up new input
|
||||
inputchange_macro1_params(&icb, &actual_macro->definition, actual_macro->parameter_list);
|
||||
// remember input and set up new one:
|
||||
inputchange_new_ram(&icb);
|
||||
inputchange_macro1_params(&actual_macro->definition, actual_macro->parameter_list);
|
||||
|
||||
outer_msg_sum = pass.warning_count + pass.error_count; // remember for call stack decision
|
||||
|
||||
@ -295,7 +296,7 @@ void macro_parse_call(void) // Now GotByte = first char of macro name
|
||||
// restore previous section
|
||||
section_now = outer_section;
|
||||
|
||||
// restore previous input
|
||||
// restore outer input
|
||||
inputchange_back(&icb);
|
||||
|
||||
// if needed, dump call stack
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#define RELEASE "0.97" // update before release FIXME
|
||||
#define CODENAME "Zem" // update before release
|
||||
#define CHANGE_DATE "22 Jul" // update before release FIXME
|
||||
#define CHANGE_DATE "23 Jul" // 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
|
||||
|
Loading…
Reference in New Issue
Block a user