internal cleanup, no change in functionality

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@127 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-04-28 11:18:22 +00:00
parent c4a88fa738
commit 0a4c13bb2e
8 changed files with 39 additions and 43 deletions

View File

@ -398,25 +398,23 @@ static void parse_quoted_character(char closing_quote)
static void parse_binary_value(void) // Now GotByte = "%" or "b" static void parse_binary_value(void) // Now GotByte = "%" or "b"
{ {
intval_t value = 0; intval_t value = 0;
int go_on = TRUE, // continue loop flag int flags = MVALUE_DEFINED,
flags = MVALUE_DEFINED,
digits = -1; // digit counter digits = -1; // digit counter
do { for (;;) {
++digits; ++digits;
switch (GetByte()) { switch (GetByte()) {
case '0': case '0':
case '.': case '.':
value <<= 1; value <<= 1;
break; continue;
case '1': case '1':
case '#': case '#':
value = (value << 1) | 1; value = (value << 1) | 1;
break; continue;
default:
go_on = 0;
} }
} while (go_on); break; // found illegal character
}
// set force bits // set force bits
if (config.honor_leading_zeroes) { if (config.honor_leading_zeroes) {
if (digits > 8) { if (digits > 8) {
@ -435,34 +433,33 @@ static void parse_binary_value(void) // Now GotByte = "%" or "b"
// Parse hexadecimal value. It accepts "0" to "9", "a" to "f" and "A" to "F". // Parse hexadecimal value. It accepts "0" to "9", "a" to "f" and "A" to "F".
// Capital letters will be converted to lowercase letters using the flagtable.
// The current value is stored as soon as a character is read that is none of // The current value is stored as soon as a character is read that is none of
// those given above. // those given above.
static void parse_hexadecimal_value(void) // Now GotByte = "$" or "x" static void parse_hexadecimal_value(void) // Now GotByte = "$" or "x"
{ {
char byte; char byte;
int go_on, // continue loop flag int digits = -1, // digit counter
digits = -1, // digit counter
flags = MVALUE_DEFINED; flags = MVALUE_DEFINED;
intval_t value = 0; intval_t value = 0;
do { for (;;) {
++digits; ++digits;
go_on = 0;
byte = GetByte(); byte = GetByte();
// first, convert "A-F" to "a-f" // if digit or legal character, add value
byte |= (BYTEFLAGS(byte) & BYTEIS_UPCASE);
// if digit, add digit value
if ((byte >= '0') && (byte <= '9')) { if ((byte >= '0') && (byte <= '9')) {
value = (value << 4) + (byte - '0'); value = (value << 4) + (byte - '0');
go_on = 1; // keep going continue;
} }
// if legal ("a-f") character, add character value
if ((byte >= 'a') && (byte <= 'f')) { if ((byte >= 'a') && (byte <= 'f')) {
value = (value << 4) + (byte - 'a') + 10; value = (value << 4) + (byte - 'a') + 10;
go_on = 1; // keep going continue;
} }
} while (go_on); if ((byte >= 'A') && (byte <= 'F')) {
value = (value << 4) + (byte - 'A') + 10;
continue;
}
break; // found illegal character
}
// set force bits // set force bits
if (config.honor_leading_zeroes) { if (config.honor_leading_zeroes) {
if (digits > 2) { if (digits > 2) {
@ -636,7 +633,7 @@ static int expect_operand_or_monadic_operator(void)
perform_negation = !perform_negation; perform_negation = !perform_negation;
} while (GetByte() == '-'); } while (GetByte() == '-');
SKIPSPACE(); SKIPSPACE();
if (BYTEFLAGS(GotByte) & FOLLOWS_ANON) { if (BYTE_FOLLOWS_ANON(GotByte)) {
DynaBuf_append(GlobalDynaBuf, '\0'); DynaBuf_append(GlobalDynaBuf, '\0');
get_symbol_value(section_now->local_scope, 0, GlobalDynaBuf->size - 1); // -1 to not count terminator get_symbol_value(section_now->local_scope, 0, GlobalDynaBuf->size - 1); // -1 to not count terminator
goto now_expect_dyadic; goto now_expect_dyadic;
@ -738,7 +735,7 @@ static int expect_operand_or_monadic_operator(void)
goto now_expect_dyadic; goto now_expect_dyadic;
} }
if (BYTEFLAGS(GotByte) & STARTS_KEYWORD) { if (BYTE_STARTS_KEYWORD(GotByte)) {
register int length; register int length;
// Read global label (or "NOT") // Read global label (or "NOT")
@ -917,7 +914,7 @@ static void expect_dyadic_operator(void)
// end of expression or text version of dyadic operator // end of expression or text version of dyadic operator
default: default:
// check string versions of operators // check string versions of operators
if (BYTEFLAGS(GotByte) & STARTS_KEYWORD) { if (BYTE_STARTS_KEYWORD(GotByte)) {
Input_read_and_lower_keyword(); Input_read_and_lower_keyword();
// Now GotByte = illegal char // Now GotByte = illegal char
// search for tree item // search for tree item

View File

@ -1,5 +1,5 @@
// ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
// Copyright (C) 1998-2016 Marco Baye // Copyright (C) 1998-2020 Marco Baye
// Have a look at "acme.c" for further info // Have a look at "acme.c" for further info
// //
// Dynamic buffer stuff // Dynamic buffer stuff
@ -123,6 +123,7 @@ void DynaBuf_to_lower(struct dynabuf *target, struct dynabuf *source)
// But actually it doesn't matter, because only pre-defined // But actually it doesn't matter, because only pre-defined
// keywords are converted, and all of those are plain // keywords are converted, and all of those are plain
// old-fashioned 7-bit ASCII anyway. So I guess it'll do. // old-fashioned 7-bit ASCII anyway. So I guess it'll do.
// FIXME - use BYTE_ macro from global.h
*write = '\0'; // terminate *write = '\0'; // terminate
} }

View File

@ -72,7 +72,7 @@ const char exception_syntax[] = "Syntax error.";
// ....3... preceding sequence of '-' characters is anonymous backward // ....3... preceding sequence of '-' characters is anonymous backward
// label. Currently only set for ')', ',' and CHAR_EOS. // label. Currently only set for ')', ',' and CHAR_EOS.
// .....210 currently unused // .....210 currently unused
const char Byte_flags[256] = { const char global_byte_flags[256] = {
/*$00*/ 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// control characters /*$00*/ 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// control characters
0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -281,7 +281,7 @@ void Parse_until_eob_or_eof(void)
case '+': case '+':
GetByte(); GetByte();
if ((GotByte == LOCAL_PREFIX) // TODO - allow "cheap macros"?! if ((GotByte == LOCAL_PREFIX) // TODO - allow "cheap macros"?!
|| (BYTEFLAGS(GotByte) & CONTS_KEYWORD)) || (BYTE_CONTINUES_KEYWORD(GotByte)))
Macro_parse_call(); Macro_parse_call();
else else
parse_forward_anon_def(&statement_flags); parse_forward_anon_def(&statement_flags);
@ -296,7 +296,7 @@ void Parse_until_eob_or_eof(void)
parse_local_symbol_def(&statement_flags, section_now->cheap_scope); parse_local_symbol_def(&statement_flags, section_now->cheap_scope);
break; break;
default: default:
if (BYTEFLAGS(GotByte) & STARTS_KEYWORD) { if (BYTE_STARTS_KEYWORD(GotByte)) {
parse_mnemo_or_global_symbol_def(&statement_flags); parse_mnemo_or_global_symbol_def(&statement_flags);
} else { } else {
Throw_error(exception_syntax); Throw_error(exception_syntax);

View File

@ -50,14 +50,12 @@ extern const char exception_number_out_of_range[];
extern const char exception_pc_undefined[]; extern const char exception_pc_undefined[];
extern const char exception_syntax[]; extern const char exception_syntax[];
// byte flags table // byte flags table
extern const char Byte_flags[]; extern const char global_byte_flags[];
#define BYTEFLAGS(c) (Byte_flags[(unsigned char) c]) #define BYTE_STARTS_KEYWORD(b) (global_byte_flags[(unsigned char) b] & (1u << 7)) // byte is allowed at start of keyword (a-z, A-Z, _, everything>127)
#define STARTS_KEYWORD (1u << 7) // Byte is allowed to start a keyword #define BYTE_CONTINUES_KEYWORD(b) (global_byte_flags[(unsigned char) b] & (1u << 6)) // byte is allowed in a keyword (as above, plus digits)
#define CONTS_KEYWORD (1u << 6) // Byte is allowed in a keyword //#define BYTE_TO_LOWER_CASE(b) bit 5 means: "byte is upper case, and can be converted to lower case by ORing this bit" - but this is not used at the moment!
#define BYTEIS_UPCASE (1u << 5) // Byte is upper case and can be #define BYTE_IS_SYNTAX_CHAR(b) (global_byte_flags[(unsigned char) b] & (1u << 4)) // special character for input syntax
// converted to lower case by OR-ing this bit(!) #define BYTE_FOLLOWS_ANON(b) (global_byte_flags[(unsigned char) b] & (1u << 3)) // preceding '-' are backward label
#define BYTEIS_SYNTAX (1u << 4) // special character for input syntax
#define FOLLOWS_ANON (1u << 3) // preceding '-' are backward label
// bits 2, 1 and 0 are currently unused // bits 2, 1 and 0 are currently unused
// TODO - put in runtime struct: // TODO - put in runtime struct:

View File

@ -1,5 +1,5 @@
// ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
// Copyright (C) 1998-2017 Marco Baye // Copyright (C) 1998-2020 Marco Baye
// Have a look at "acme.c" for further info // Have a look at "acme.c" for further info
// //
// Input stuff // Input stuff
@ -135,7 +135,7 @@ static char get_processed_from_file(void)
// defined "from_file", trouble may arise... // defined "from_file", trouble may arise...
Input_now->state = INPUTSTATE_NORMAL; Input_now->state = INPUTSTATE_NORMAL;
// EOF must be checked first because it cannot be used // EOF must be checked first because it cannot be used
// as an index into Byte_flags[] // as an index into global_byte_flags[]
if (from_file == EOF) { if (from_file == EOF) {
// remember to send an end-of-file // remember to send an end-of-file
Input_now->state = INPUTSTATE_EOF; Input_now->state = INPUTSTATE_EOF;
@ -144,7 +144,7 @@ static char get_processed_from_file(void)
// check whether character is special one // check whether character is special one
// if not, everything's cool and froody, so return it // if not, everything's cool and froody, so return it
if ((BYTEFLAGS(from_file) & BYTEIS_SYNTAX) == 0) if (BYTE_IS_SYNTAX_CHAR(from_file) == 0)
return (char) from_file; return (char) from_file;
// check special characters ("0x00 TAB LF CR SPC / : ; }") // check special characters ("0x00 TAB LF CR SPC / : ; }")
@ -423,7 +423,7 @@ int Input_append_keyword_to_global_dynabuf(void)
int length = 0; int length = 0;
// 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 (BYTE_CONTINUES_KEYWORD(GotByte)) {
DYNABUF_APPEND(GlobalDynaBuf, GotByte); DYNABUF_APPEND(GlobalDynaBuf, GotByte);
++length; ++length;
GetByte(); GetByte();

View File

@ -1,5 +1,5 @@
// ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code. // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
// Copyright (C) 1998-2017 Marco Baye // Copyright (C) 1998-2020 Marco Baye
// Have a look at "acme.c" for further info // Have a look at "acme.c" for further info
// //
// Input stuff // Input stuff
@ -46,7 +46,7 @@ extern const char FILE_READBINARY[];
#define CHAR_EOB '}' // end of block #define CHAR_EOB '}' // end of block
#define CHAR_SOL (10) // start of line (in high-level format) #define CHAR_SOL (10) // start of line (in high-level format)
#define CHAR_EOF (13) // end of file (in high-level format) #define CHAR_EOF (13) // end of file (in high-level format)
// If the characters above are changed, don't forget to adjust Byte_flags[]! // if the characters above are changed, don't forget to adjust global_byte_flags[]!
// Variables // Variables

View File

@ -737,7 +737,7 @@ static enum eos po_zone(void)
allocated = FALSE; allocated = FALSE;
// Check whether a zone title is given. If yes and it can be read, // Check whether a zone title is given. If yes and it can be read,
// get copy, remember pointer and remember to free it later on. // get copy, remember pointer and remember to free it later on.
if (BYTEFLAGS(GotByte) & CONTS_KEYWORD) { if (BYTE_CONTINUES_KEYWORD(GotByte)) {
// Because we know of one character for sure, // Because we know of one character for sure,
// there's no need to check the return value. // there's no need to check the return value.
Input_read_keyword(); Input_read_keyword();

View File

@ -9,7 +9,7 @@
#define RELEASE "0.96.5" // update before release FIXME #define RELEASE "0.96.5" // update before release FIXME
#define CODENAME "Fenchurch" // update before release #define CODENAME "Fenchurch" // update before release
#define CHANGE_DATE "27 Apr" // update before release FIXME #define CHANGE_DATE "28 Apr" // update before release FIXME
#define CHANGE_YEAR "2020" // update before release #define CHANGE_YEAR "2020" // update before release
//#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" //#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/"
#define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME #define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME