mirror of
https://github.com/uffejakobsen/acme.git
synced 2024-12-01 16:50:46 +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 RELEASE "0.95.4" // update before release (FIXME)
|
||||||
#define CODENAME "Fenchurch" // update before release
|
#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 CHANGE_YEAR "2014" // update before release
|
||||||
//#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" // FIXME
|
//#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" // FIXME
|
||||||
#define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // 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_undefined_count = 0; // no "NeedValue" errors yet
|
||||||
pass_real_errors = 0; // no real errors yet
|
pass_real_errors = 0; // no real errors yet
|
||||||
// Process toplevel files
|
// 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))) {
|
if ((fd = fopen(toplevel_sources[ii], FILE_READBINARY))) {
|
||||||
Parse_and_close_file(fd, toplevel_sources[ii]);
|
Parse_and_close_file(fd, toplevel_sources[ii]);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error: Cannot open toplevel file \"%s\".\n", toplevel_sources[ii]);
|
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!
|
// FIXME - if "filename" starts with "-", tell user to give options FIRST, files SECOND!
|
||||||
pass_real_errors++;
|
++pass_real_errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pass_real_errors)
|
if (pass_real_errors)
|
||||||
@ -375,13 +375,13 @@ static signed long string_to_number(const char *string)
|
|||||||
|
|
||||||
if (*string == '%') {
|
if (*string == '%') {
|
||||||
base = 2;
|
base = 2;
|
||||||
string++;
|
++string;
|
||||||
} else if (*string == '&') {
|
} else if (*string == '&') {
|
||||||
base = 8;
|
base = 8;
|
||||||
string++;
|
++string;
|
||||||
} else if (*string == '$') {
|
} else if (*string == '$') {
|
||||||
base = 16;
|
base = 16;
|
||||||
string++;
|
++string;
|
||||||
} else if ((*string == '0') && ((string[1] == 'x') || (string[1] == 'X'))) {
|
} else if ((*string == '0') && ((string[1] == 'x') || (string[1] == 'X'))) {
|
||||||
base = 16;
|
base = 16;
|
||||||
string += 2;
|
string += 2;
|
||||||
@ -498,7 +498,7 @@ static char short_option(const char *argument)
|
|||||||
report_filename = cliargs_safe_get_next(arg_reportfile);
|
report_filename = cliargs_safe_get_next(arg_reportfile);
|
||||||
break;
|
break;
|
||||||
case 'v': // "-v" changes verbosity
|
case 'v': // "-v" changes verbosity
|
||||||
Process_verbosity++;
|
++Process_verbosity;
|
||||||
if ((argument[1] >= '0') && (argument[1] <= '9'))
|
if ((argument[1] >= '0') && (argument[1] <= '9'))
|
||||||
Process_verbosity = *(++argument) - '0';
|
Process_verbosity = *(++argument) - '0';
|
||||||
break;
|
break;
|
||||||
@ -525,7 +525,7 @@ static char short_option(const char *argument)
|
|||||||
default: // unknown ones: program termination
|
default: // unknown ones: program termination
|
||||||
return *argument;
|
return *argument;
|
||||||
}
|
}
|
||||||
argument++;
|
++argument;
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
return '\0';
|
return '\0';
|
||||||
|
18
src/alu.c
18
src/alu.c
@ -220,7 +220,7 @@ do { \
|
|||||||
// the user.
|
// the user.
|
||||||
static void just_count(void)
|
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.
|
// further passes. This function counts these errors and shows them to the user.
|
||||||
static void count_and_throw(void)
|
static void count_and_throw(void)
|
||||||
{
|
{
|
||||||
pass_undefined_count++;
|
++pass_undefined_count;
|
||||||
Throw_error(exception_undefined);
|
Throw_error(exception_undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +376,7 @@ static void parse_binary_value(void) // Now GotByte = "%" or "b"
|
|||||||
digits = -1; // digit counter
|
digits = -1; // digit counter
|
||||||
|
|
||||||
do {
|
do {
|
||||||
digits++;
|
++digits;
|
||||||
switch (GetByte()) {
|
switch (GetByte()) {
|
||||||
case '0':
|
case '0':
|
||||||
case '.':
|
case '.':
|
||||||
@ -418,7 +418,7 @@ static void parse_hexadecimal_value(void) // Now GotByte = "$" or "x"
|
|||||||
intval_t value = 0;
|
intval_t value = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
digits++;
|
++digits;
|
||||||
go_on = 0;
|
go_on = 0;
|
||||||
byte = GetByte();
|
byte = GetByte();
|
||||||
// first, convert "A-F" to "a-f"
|
// first, convert "A-F" to "a-f"
|
||||||
@ -521,7 +521,7 @@ static void parse_octal_value(void) // Now GotByte = "&"
|
|||||||
GetByte();
|
GetByte();
|
||||||
while ((GotByte >= '0') && (GotByte <= '7')) {
|
while ((GotByte >= '0') && (GotByte <= '7')) {
|
||||||
value = (value << 3) + (GotByte & 7); // this works. it's ASCII.
|
value = (value << 3) + (GotByte & 7); // this works. it's ASCII.
|
||||||
digits++;
|
++digits;
|
||||||
GetByte();
|
GetByte();
|
||||||
}
|
}
|
||||||
// set force bits
|
// set force bits
|
||||||
@ -979,7 +979,7 @@ static void try_to_reduce_stacks(int *open_parentheses)
|
|||||||
// special (pseudo) operators
|
// special (pseudo) operators
|
||||||
case OPHANDLE_RETURN:
|
case OPHANDLE_RETURN:
|
||||||
// don't touch indirect_flag; needed for INDIRECT flag
|
// 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;
|
alu_state = STATE_END;
|
||||||
break;
|
break;
|
||||||
case OPHANDLE_OPENING:
|
case OPHANDLE_OPENING:
|
||||||
@ -990,7 +990,7 @@ static void try_to_reduce_stacks(int *open_parentheses)
|
|||||||
alu_state = STATE_EXPECT_DYADIC_OPERATOR;
|
alu_state = STATE_EXPECT_DYADIC_OPERATOR;
|
||||||
break;
|
break;
|
||||||
case OPHANDLE_END: // unmatched parenthesis
|
case OPHANDLE_END: // unmatched parenthesis
|
||||||
(*open_parentheses)++; // count
|
++(*open_parentheses); // count
|
||||||
goto RNTLObutDontTouchIndirectFlag;
|
goto RNTLObutDontTouchIndirectFlag;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1332,7 +1332,7 @@ handle_flags_and_dec_stacks:
|
|||||||
// "AND" DEFINED flag
|
// "AND" DEFINED flag
|
||||||
LEFT_FLAGS &= (RIGHT_FLAGS | ~MVALUE_DEFINED);
|
LEFT_FLAGS &= (RIGHT_FLAGS | ~MVALUE_DEFINED);
|
||||||
LEFT_FLAGS &= ~MVALUE_ISBYTE; // clear ISBYTE flag
|
LEFT_FLAGS &= ~MVALUE_ISBYTE; // clear ISBYTE flag
|
||||||
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
|
// toplevel operation was something other than parentheses
|
||||||
@ -1341,7 +1341,7 @@ remove_next_to_last_operator:
|
|||||||
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];
|
||||||
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)
|
if (byte == EOF)
|
||||||
break;
|
break;
|
||||||
Output_byte(byte);
|
Output_byte(byte);
|
||||||
size--;
|
--size;
|
||||||
}
|
}
|
||||||
// if more should have been read, warn and add padding
|
// if more should have been read, warn and add padding
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
@ -24,7 +24,7 @@ const char *cliargs_get_next(void)
|
|||||||
if (arguments_left == 0)
|
if (arguments_left == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
arguments_left--;
|
--arguments_left;
|
||||||
return *next_argument++;
|
return *next_argument++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,7 +435,7 @@ static enum eos PO_source(void) // Now GotByte = illegal char
|
|||||||
Throw_error(exception_cannot_open_input_file);
|
Throw_error(exception_cannot_open_input_file);
|
||||||
}
|
}
|
||||||
// Leave nesting level
|
// Leave nesting level
|
||||||
source_recursions_left++;
|
++source_recursions_left;
|
||||||
return ENSURE_EOS;
|
return ENSURE_EOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,7 +374,7 @@ void Throw_error(const char *message)
|
|||||||
{
|
{
|
||||||
PLATFORM_ERROR(message);
|
PLATFORM_ERROR(message);
|
||||||
throw_message(message, "Error");
|
throw_message(message, "Error");
|
||||||
pass_real_errors++;
|
++pass_real_errors;
|
||||||
if (pass_real_errors >= max_errors)
|
if (pass_real_errors >= max_errors)
|
||||||
exit(ACME_finalize(EXIT_FAILURE));
|
exit(ACME_finalize(EXIT_FAILURE));
|
||||||
}
|
}
|
||||||
|
@ -376,10 +376,10 @@ char *Input_skip_or_store_block(int store)
|
|||||||
} while ((GotByte != CHAR_EOS) && (GotByte != byte));
|
} while ((GotByte != CHAR_EOS) && (GotByte != byte));
|
||||||
break;
|
break;
|
||||||
case CHAR_SOB:
|
case CHAR_SOB:
|
||||||
depth++;
|
++depth;
|
||||||
break;
|
break;
|
||||||
case CHAR_EOB:
|
case CHAR_EOB:
|
||||||
depth--;
|
--depth;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (depth);
|
} while (depth);
|
||||||
@ -431,7 +431,7 @@ int Input_append_keyword_to_global_dynabuf(void)
|
|||||||
// add characters to buffer until an illegal one comes along
|
// add characters to buffer until an illegal one comes along
|
||||||
while (BYTEFLAGS(GotByte) & CONTS_KEYWORD) {
|
while (BYTEFLAGS(GotByte) & CONTS_KEYWORD) {
|
||||||
DYNABUF_APPEND(GlobalDynaBuf, GotByte);
|
DYNABUF_APPEND(GlobalDynaBuf, GotByte);
|
||||||
length++;
|
++length;
|
||||||
GetByte();
|
GetByte();
|
||||||
}
|
}
|
||||||
if (length == 0)
|
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);
|
DynaBuf_append(internal_name, ARGTYPE_NUM_VAL);
|
||||||
ALU_any_result(&(arg_table[arg_count].result));
|
ALU_any_result(&(arg_table[arg_count].result));
|
||||||
}
|
}
|
||||||
arg_count++;
|
++arg_count;
|
||||||
} while (Input_accept_comma());
|
} while (Input_accept_comma());
|
||||||
}
|
}
|
||||||
// now arg_table contains the arguments
|
// 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.").
|
// as above ("Macro parameter twice.").
|
||||||
symbol->result = arg_table[arg_count].result;
|
symbol->result = arg_table[arg_count].result;
|
||||||
}
|
}
|
||||||
arg_count++;
|
++arg_count;
|
||||||
} while (Input_accept_comma());
|
} while (Input_accept_comma());
|
||||||
}
|
}
|
||||||
// and now, finally, parse the actual macro body
|
// 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
|
GotByte = local_gotbyte; // CAUTION - ugly kluge
|
||||||
Input_ensure_EOS();
|
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 {
|
struct {
|
||||||
intval_t start; // start of current segment (or NO_SEGMENT_START)
|
intval_t start; // start of current segment (or NO_SEGMENT_START)
|
||||||
intval_t max; // highest address segment may use
|
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
|
struct segment list_head; // head element of doubly-linked ring list
|
||||||
} segment;
|
} 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
|
// variables
|
||||||
static struct output default_output;
|
static struct output default_output;
|
||||||
@ -78,18 +82,6 @@ static struct ronode file_formats[] = {
|
|||||||
static enum output_format output_format = OUTPUT_FORMAT_UNSPECIFIED;
|
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
|
// report binary output
|
||||||
static void report_binary(char value)
|
static void report_binary(char value)
|
||||||
{
|
{
|
||||||
@ -152,7 +144,7 @@ static void real_output(intval_t byte)
|
|||||||
if (report->fd)
|
if (report->fd)
|
||||||
report_binary(byte & 0xff); // file for reporting, taking also CPU_2add
|
report_binary(byte & 0xff); // file for reporting, taking also CPU_2add
|
||||||
out->buffer[out->write_idx++] = byte & 0xff;
|
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
|
// check whether ptr undefined
|
||||||
if (Output_byte == no_output) {
|
if (Output_byte == no_output) {
|
||||||
Output_byte(0); // trigger error with a dummy byte
|
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?
|
// did we reach segment limit?
|
||||||
if (out->write_idx + size - 1 > out->segment.max)
|
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)
|
// init output buffer (fill memory with initial value)
|
||||||
fill_completely(fill_value & 0xff);
|
fill_completely(fill_value & 0xff);
|
||||||
Tree_add_table(&pseudo_opcode_tree, pseudo_opcodes);
|
Tree_add_table(&pseudo_opcode_tree, pseudo_opcodes);
|
||||||
Tree_add_table(&segment_modifier_tree, segment_modifiers);
|
|
||||||
// init ring list of segments
|
// init ring list of segments
|
||||||
out->segment.list_head.next = &out->segment.list_head;
|
out->segment.list_head.next = &out->segment.list_head;
|
||||||
out->segment.list_head.prev = &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)
|
// 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!)
|
// 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.
|
// 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
|
// FIXME - move to basics.c
|
||||||
void PO_setpc(void)
|
void PO_setpc(void)
|
||||||
{
|
{
|
||||||
void *node_body;
|
|
||||||
int segment_flags = 0;
|
int segment_flags = 0;
|
||||||
intval_t new_addr = ALU_defined_int();
|
intval_t new_addr = ALU_defined_int();
|
||||||
|
|
||||||
@ -622,12 +613,14 @@ void PO_setpc(void)
|
|||||||
if (Input_read_and_lower_keyword() == 0)
|
if (Input_read_and_lower_keyword() == 0)
|
||||||
return;
|
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.");
|
Throw_error("Unknown \"* =\" segment modifier.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
segment_flags |= (int) node_body;
|
|
||||||
}
|
}
|
||||||
vcpu_set_pc(new_addr, segment_flags);
|
vcpu_set_pc(new_addr, segment_flags);
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ void symbols_clear_init(void)
|
|||||||
|
|
||||||
// cut down all the trees (clear pointer table)
|
// cut down all the trees (clear pointer table)
|
||||||
ptr = symbols_forest;
|
ptr = symbols_forest;
|
||||||
for (ii = 255; ii >= 0; ii--)
|
for (ii = 255; ii >= 0; --ii)
|
||||||
*ptr++ = NULL;
|
*ptr++ = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,9 +194,9 @@ void Tree_dump_forest(struct rwnode **forest, int id_number, void (*fn)(struct r
|
|||||||
{
|
{
|
||||||
int ii;
|
int ii;
|
||||||
|
|
||||||
for (ii = 255; ii >= 0; ii--) {
|
for (ii = 255; ii >= 0; --ii) {
|
||||||
if (*forest)
|
if (*forest)
|
||||||
dump_tree(*forest, id_number, fn, env);
|
dump_tree(*forest, id_number, fn, env);
|
||||||
forest++;
|
++forest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user