From 73292e1b4fdc4353003f3d0c70e34484058c8ac5 Mon Sep 17 00:00:00 2001 From: marcobaye Date: Mon, 29 Jul 2024 20:08:01 +0000 Subject: [PATCH] more refactoring of input git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@380 4df02467-bbd4-4a76-a152-e7ce94205b78 --- src/global.c | 1 + src/input.c | 22 +++++++++++++++++++++- src/input.h | 7 ++++--- src/macro.c | 30 ++++++++++-------------------- src/version.h | 2 +- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/global.c b/src/global.c index eb7be59..11cbbd5 100644 --- a/src/global.c +++ b/src/global.c @@ -423,6 +423,7 @@ int parse_optional_block(void) SKIPSPACE(); if (GotByte != CHAR_SOB) return FALSE; + parse_until_eob_or_eof(); if (GotByte != CHAR_EOB) Throw_serious_error(exception_no_right_brace); diff --git a/src/input.c b/src/input.c index 8fe5ba6..03a4da7 100644 --- a/src/input.c +++ b/src/input.c @@ -42,6 +42,7 @@ static struct input outermost = { // variables struct input *input_now = &outermost; // current input structure char GotByte; // last byte read (processed) +// TODO: move GotByte into input struct! // functions @@ -857,7 +858,26 @@ void inputchange_new_file(struct inputchange_buf *icb, FILE *fd, const char *ete icb->gb = GotByte; 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) +{ + 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; + // remember where outer input struct is + icb->outer_input = input_now; + // activate new input + icb->gb = GotByte; + input_now = &icb->new_input; +} +// 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; +} // restore input struct from buffer void inputchange_back(struct inputchange_buf *icb) { diff --git a/src/input.h b/src/input.h index 96a5367..b971089 100644 --- a/src/input.h +++ b/src/input.h @@ -64,7 +64,6 @@ extern const char FILE_READBINARY[]; // Variables extern struct input *input_now; // current input structure -// TODO - put in input struct? extern char GotByte; // last byte read (processed) @@ -168,10 +167,12 @@ struct inputchange_buf { *outer_input; char gb; // buffer for GotByte }; - // 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); +// switch from macro parameters to macro body +extern void inputchange_macro2_body(char *macro_body); // restore input struct from buffer extern void inputchange_back(struct inputchange_buf *icb); diff --git a/src/macro.c b/src/macro.c index 516e575..73cd259 100644 --- a/src/macro.c +++ b/src/macro.c @@ -175,14 +175,13 @@ void macro_parse_definition(void) // Now GotByte = illegal char after "!macro" } // Parse macro call ("+MACROTITLE"). Has to be re-entrant. +// TODO: split this into smaller functions, some of the inner blocks are much too long void macro_parse_call(void) // Now GotByte = first char of macro name { - char local_gotbyte; struct symbol *symbol; struct section new_section, *outer_section; - struct input new_input, - *outer_input; + struct inputchange_buf icb; struct macro *actual_macro; struct rwnode *macro_node, *symbol_node; @@ -240,18 +239,9 @@ void macro_parse_call(void) // Now GotByte = first char of macro name } else { // make macro_node point to the macro struct actual_macro = macro_node->body; - local_gotbyte = GotByte; // CAUTION - ugly kluge // set up new input - new_input = *input_now; // copy current input structure into new - new_input.location = actual_macro->definition; - new_input.source = INPUTSRC_RAM; - new_input.state = INPUTSTATE_NORMAL; // FIXME - fix others! - new_input.src.ram_ptr = actual_macro->parameter_list; - // remember old input - outer_input = input_now; - // activate new input - input_now = &new_input; + inputchange_macro1_params(&icb, &actual_macro->definition, actual_macro->parameter_list); outer_msg_sum = pass.warning_count + pass.error_count; // remember for call stack decision @@ -261,8 +251,9 @@ void macro_parse_call(void) // Now GotByte = first char of macro name // FALSE = title mustn't be freed section_new(&new_section, "Macro", actual_macro->original_name, FALSE); section_new_cheap_scope(&new_section); - GetByte(); // fetch first byte of parameter list + // assign arguments + GetByte(); // fetch first byte of parameter list if (GotByte != CHAR_EOS) { // any at all? arg_count = 0; do { @@ -292,10 +283,10 @@ void macro_parse_call(void) // Now GotByte = first char of macro name ++arg_count; } while (input_accept_comma()); } + // and now, finally, parse the actual macro body - input_now->state = INPUTSTATE_NORMAL; // FIXME - fix others! // maybe call parse_ram_block(actual_macro->definition.line_number, actual_macro->body) - input_now->src.ram_ptr = actual_macro->body; + inputchange_macro2_body(actual_macro->body); parse_until_eob_or_eof(); if (GotByte != CHAR_EOB) BUG("IllegalBlockTerminator", GotByte); @@ -303,10 +294,9 @@ void macro_parse_call(void) // Now GotByte = first char of macro name section_finalize(&new_section); // restore previous section section_now = outer_section; - // restore previous input: - input_now = outer_input; - // restore old Gotbyte context - GotByte = local_gotbyte; // CAUTION - ugly kluge + + // restore previous input + inputchange_back(&icb); // if needed, dump call stack if (outer_msg_sum != pass.warning_count + pass.error_count) diff --git a/src/version.h b/src/version.h index f5b6ac9..c2035a4 100644 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ #define RELEASE "0.97" // update before release FIXME #define CODENAME "Zem" // update before release -#define CHANGE_DATE "17 Jul" // update before release FIXME +#define CHANGE_DATE "18 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