From bff56ae8031bf72aa31a98901a901ad9f5dacdcd Mon Sep 17 00:00:00 2001 From: marcobaye Date: Sun, 30 Nov 2014 17:00:13 +0000 Subject: [PATCH] Removed another silly two-entry keyword tree. Minor refactoring. No change in functionality. git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@46 4df02467-bbd4-4a76-a152-e7ce94205b78 --- src/acme.c | 16 ++++++++-------- src/alu.c | 18 +++++++++--------- src/basics.c | 2 +- src/cliargs.c | 2 +- src/flow.c | 2 +- src/global.c | 2 +- src/input.c | 6 +++--- src/macro.c | 6 +++--- src/output.c | 33 +++++++++++++-------------------- src/symbol.c | 2 +- src/tree.c | 4 ++-- 11 files changed, 43 insertions(+), 50 deletions(-) diff --git a/src/acme.c b/src/acme.c index bfc4d73..fe5e972 100644 --- a/src/acme.c +++ b/src/acme.c @@ -17,7 +17,7 @@ #define RELEASE "0.95.4" // update before release (FIXME) #define CODENAME "Fenchurch" // update before release -#define CHANGE_DATE "26 Nov" // update before release +#define CHANGE_DATE "30 Nov" // update before release #define CHANGE_YEAR "2014" // update before release //#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" // FIXME #define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME @@ -252,13 +252,13 @@ static int perform_pass(void) pass_undefined_count = 0; // no "NeedValue" errors yet pass_real_errors = 0; // no real errors yet // Process toplevel files - for (ii = 0; ii < toplevel_src_count; ii++) { + for (ii = 0; ii < toplevel_src_count; ++ii) { if ((fd = fopen(toplevel_sources[ii], FILE_READBINARY))) { Parse_and_close_file(fd, toplevel_sources[ii]); } else { fprintf(stderr, "Error: Cannot open toplevel file \"%s\".\n", toplevel_sources[ii]); // FIXME - if "filename" starts with "-", tell user to give options FIRST, files SECOND! - pass_real_errors++; + ++pass_real_errors; } } if (pass_real_errors) @@ -375,13 +375,13 @@ static signed long string_to_number(const char *string) if (*string == '%') { base = 2; - string++; + ++string; } else if (*string == '&') { base = 8; - string++; + ++string; } else if (*string == '$') { base = 16; - string++; + ++string; } else if ((*string == '0') && ((string[1] == 'x') || (string[1] == 'X'))) { base = 16; string += 2; @@ -498,7 +498,7 @@ static char short_option(const char *argument) report_filename = cliargs_safe_get_next(arg_reportfile); break; case 'v': // "-v" changes verbosity - Process_verbosity++; + ++Process_verbosity; if ((argument[1] >= '0') && (argument[1] <= '9')) Process_verbosity = *(++argument) - '0'; break; @@ -525,7 +525,7 @@ static char short_option(const char *argument) default: // unknown ones: program termination return *argument; } - argument++; + ++argument; } done: return '\0'; diff --git a/src/alu.c b/src/alu.c index c96aa09..7ebf1d3 100644 --- a/src/alu.c +++ b/src/alu.c @@ -220,7 +220,7 @@ do { \ // the user. static void just_count(void) { - pass_undefined_count++; + ++pass_undefined_count; } @@ -228,7 +228,7 @@ static void just_count(void) // further passes. This function counts these errors and shows them to the user. static void count_and_throw(void) { - pass_undefined_count++; + ++pass_undefined_count; Throw_error(exception_undefined); } @@ -376,7 +376,7 @@ static void parse_binary_value(void) // Now GotByte = "%" or "b" digits = -1; // digit counter do { - digits++; + ++digits; switch (GetByte()) { case '0': case '.': @@ -418,7 +418,7 @@ static void parse_hexadecimal_value(void) // Now GotByte = "$" or "x" intval_t value = 0; do { - digits++; + ++digits; go_on = 0; byte = GetByte(); // first, convert "A-F" to "a-f" @@ -521,7 +521,7 @@ static void parse_octal_value(void) // Now GotByte = "&" GetByte(); while ((GotByte >= '0') && (GotByte <= '7')) { value = (value << 3) + (GotByte & 7); // this works. it's ASCII. - digits++; + ++digits; GetByte(); } // set force bits @@ -979,7 +979,7 @@ static void try_to_reduce_stacks(int *open_parentheses) // special (pseudo) operators case OPHANDLE_RETURN: // don't touch indirect_flag; needed for INDIRECT flag - operator_sp--; // decrement operator stack pointer + --operator_sp; // decrement operator stack pointer alu_state = STATE_END; break; case OPHANDLE_OPENING: @@ -990,7 +990,7 @@ static void try_to_reduce_stacks(int *open_parentheses) alu_state = STATE_EXPECT_DYADIC_OPERATOR; break; case OPHANDLE_END: // unmatched parenthesis - (*open_parentheses)++; // count + ++(*open_parentheses); // count goto RNTLObutDontTouchIndirectFlag; default: @@ -1332,7 +1332,7 @@ handle_flags_and_dec_stacks: // "AND" DEFINED flag LEFT_FLAGS &= (RIGHT_FLAGS | ~MVALUE_DEFINED); LEFT_FLAGS &= ~MVALUE_ISBYTE; // clear ISBYTE flag - operand_sp--; + --operand_sp; // entry point for monadic operators remove_next_to_last_operator: // toplevel operation was something other than parentheses @@ -1341,7 +1341,7 @@ remove_next_to_last_operator: RNTLObutDontTouchIndirectFlag: // Remove operator and shift down next one operator_stack[operator_sp-2] = operator_stack[operator_sp-1]; - operator_sp--; // decrement operator stack pointer + --operator_sp; // decrement operator stack pointer } diff --git a/src/basics.c b/src/basics.c index 8955f5d..2b9f69f 100644 --- a/src/basics.c +++ b/src/basics.c @@ -104,7 +104,7 @@ static enum eos PO_binary(void) if (byte == EOF) break; Output_byte(byte); - size--; + --size; } // if more should have been read, warn and add padding if (size > 0) { diff --git a/src/cliargs.c b/src/cliargs.c index c311d3a..3757ef8 100644 --- a/src/cliargs.c +++ b/src/cliargs.c @@ -24,7 +24,7 @@ const char *cliargs_get_next(void) if (arguments_left == 0) return NULL; - arguments_left--; + --arguments_left; return *next_argument++; } diff --git a/src/flow.c b/src/flow.c index 0f6698d..ffc4071 100644 --- a/src/flow.c +++ b/src/flow.c @@ -435,7 +435,7 @@ static enum eos PO_source(void) // Now GotByte = illegal char Throw_error(exception_cannot_open_input_file); } // Leave nesting level - source_recursions_left++; + ++source_recursions_left; return ENSURE_EOS; } diff --git a/src/global.c b/src/global.c index 5de69ad..65ff293 100644 --- a/src/global.c +++ b/src/global.c @@ -374,7 +374,7 @@ void Throw_error(const char *message) { PLATFORM_ERROR(message); throw_message(message, "Error"); - pass_real_errors++; + ++pass_real_errors; if (pass_real_errors >= max_errors) exit(ACME_finalize(EXIT_FAILURE)); } diff --git a/src/input.c b/src/input.c index 3e7ee81..c4562c8 100644 --- a/src/input.c +++ b/src/input.c @@ -376,10 +376,10 @@ char *Input_skip_or_store_block(int store) } while ((GotByte != CHAR_EOS) && (GotByte != byte)); break; case CHAR_SOB: - depth++; + ++depth; break; case CHAR_EOB: - depth--; + --depth; break; } } while (depth); @@ -431,7 +431,7 @@ int Input_append_keyword_to_global_dynabuf(void) // add characters to buffer until an illegal one comes along while (BYTEFLAGS(GotByte) & CONTS_KEYWORD) { DYNABUF_APPEND(GlobalDynaBuf, GotByte); - length++; + ++length; GetByte(); } if (length == 0) diff --git a/src/macro.c b/src/macro.c index 8637b3c..b5530a1 100644 --- a/src/macro.c +++ b/src/macro.c @@ -269,7 +269,7 @@ void Macro_parse_call(void) // Now GotByte = dot or first char of macro name DynaBuf_append(internal_name, ARGTYPE_NUM_VAL); ALU_any_result(&(arg_table[arg_count].result)); } - arg_count++; + ++arg_count; } while (Input_accept_comma()); } // now arg_table contains the arguments @@ -324,7 +324,7 @@ void Macro_parse_call(void) // Now GotByte = dot or first char of macro name // as above ("Macro parameter twice."). symbol->result = arg_table[arg_count].result; } - arg_count++; + ++arg_count; } while (Input_accept_comma()); } // and now, finally, parse the actual macro body @@ -344,5 +344,5 @@ void Macro_parse_call(void) // Now GotByte = dot or first char of macro name GotByte = local_gotbyte; // CAUTION - ugly kluge Input_ensure_EOS(); } - macro_recursions_left++; // leave this nesting level + ++macro_recursions_left; // leave this nesting level } diff --git a/src/output.c b/src/output.c index a78da44..d808c4a 100644 --- a/src/output.c +++ b/src/output.c @@ -46,10 +46,14 @@ struct output { struct { intval_t start; // start of current segment (or NO_SEGMENT_START) intval_t max; // highest address segment may use - int flags; // "overlay" and "invisible" flags + int flags; // segment flags ("overlay" and "invisible", see below) struct segment list_head; // head element of doubly-linked ring list } segment; }; +// segment flags (FIXME - move to header file when setpc() is moved to pseudo_opcodes.c): +#define SEGMENT_FLAG_OVERLAY (1u << 0) // do not warn about this segment overwriting another one +#define SEGMENT_FLAG_INVISIBLE (1u << 1) // do not warn about other segments overwriting this one + // variables static struct output default_output; @@ -78,18 +82,6 @@ static struct ronode file_formats[] = { static enum output_format output_format = OUTPUT_FORMAT_UNSPECIFIED; -// predefined stuff -static struct ronode *segment_modifier_tree = NULL; // tree to hold segment modifiers -// segment modifiers -#define SEGMENT_FLAG_OVERLAY (1u << 0) -#define SEGMENT_FLAG_INVISIBLE (1u << 1) -static struct ronode segment_modifiers[] = { - PREDEFNODE("overlay", SEGMENT_FLAG_OVERLAY), - PREDEFLAST("invisible", SEGMENT_FLAG_INVISIBLE), - // ^^^^ this marks the last element -}; - - // report binary output static void report_binary(char value) { @@ -152,7 +144,7 @@ static void real_output(intval_t byte) if (report->fd) report_binary(byte & 0xff); // file for reporting, taking also CPU_2add out->buffer[out->write_idx++] = byte & 0xff; - CPU_state.add_to_pc++; + ++CPU_state.add_to_pc; } @@ -177,7 +169,7 @@ void Output_fake(int size) // check whether ptr undefined if (Output_byte == no_output) { Output_byte(0); // trigger error with a dummy byte - size--; // fix amount to cater for dummy byte + --size; // fix amount to cater for dummy byte } // did we reach segment limit? if (out->write_idx + size - 1 > out->segment.max) @@ -378,7 +370,6 @@ void Output_init(signed long fill_value) // init output buffer (fill memory with initial value) fill_completely(fill_value & 0xff); Tree_add_table(&pseudo_opcode_tree, pseudo_opcodes); - Tree_add_table(&segment_modifier_tree, segment_modifiers); // init ring list of segments out->segment.list_head.next = &out->segment.list_head; out->segment.list_head.prev = &out->segment.list_head; @@ -561,6 +552,7 @@ void Output_start_segment(intval_t address_change, int segment_flags) // TODO - add "!skip AMOUNT" pseudo opcode as alternative to "* = * + AMOUNT" (needed for assemble-to-end-address) +// the new pseudo opcode would skip the given amount of bytes without starting a new segment // set program counter to defined value (FIXME - allow for undefined!) // if start address was given on command line, main loop will call this before each pass. @@ -611,7 +603,6 @@ Maybe like this: // FIXME - move to basics.c void PO_setpc(void) { - void *node_body; int segment_flags = 0; intval_t new_addr = ALU_defined_int(); @@ -622,12 +613,14 @@ void PO_setpc(void) if (Input_read_and_lower_keyword() == 0) return; - if (!Tree_easy_scan(segment_modifier_tree, &node_body, GlobalDynaBuf)) { + if (strcmp(GlobalDynaBuf->buffer, "overlay") == 0) { + segment_flags |= SEGMENT_FLAG_OVERLAY; + } else if (strcmp(GlobalDynaBuf->buffer, "invisible") == 0) { + segment_flags |= SEGMENT_FLAG_INVISIBLE; + } else { Throw_error("Unknown \"* =\" segment modifier."); return; } - - segment_flags |= (int) node_body; } vcpu_set_pc(new_addr, segment_flags); } diff --git a/src/symbol.c b/src/symbol.c index 80869b7..44fbc86 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -330,7 +330,7 @@ void symbols_clear_init(void) // cut down all the trees (clear pointer table) ptr = symbols_forest; - for (ii = 255; ii >= 0; ii--) + for (ii = 255; ii >= 0; --ii) *ptr++ = NULL; } diff --git a/src/tree.c b/src/tree.c index 58437cc..c95676b 100644 --- a/src/tree.c +++ b/src/tree.c @@ -194,9 +194,9 @@ void Tree_dump_forest(struct rwnode **forest, int id_number, void (*fn)(struct r { int ii; - for (ii = 255; ii >= 0; ii--) { + for (ii = 255; ii >= 0; --ii) { if (*forest) dump_tree(*forest, id_number, fn, env); - forest++; + ++forest; } }