mirror of
https://github.com/uffejakobsen/acme.git
synced 2024-11-29 04:49:20 +00:00
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
This commit is contained in:
parent
8495ba9ddf
commit
bff56ae803
16
src/acme.c
16
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';
|
||||
|
18
src/alu.c
18
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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -24,7 +24,7 @@ const char *cliargs_get_next(void)
|
||||
if (arguments_left == 0)
|
||||
return NULL;
|
||||
|
||||
arguments_left--;
|
||||
--arguments_left;
|
||||
return *next_argument++;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
33
src/output.c
33
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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user