1
0
mirror of https://github.com/ksherlock/x65.git synced 2024-06-01 12:41:28 +00:00

Labels can begin with numbers

- It is a bad idea to define labels starting with numbers but apparently
Merlin allows it.
This commit is contained in:
Carl-Henrik Skårstedt 2016-03-01 18:34:20 -08:00
parent 462eaeccf6
commit 341cc8f2ad
3 changed files with 34 additions and 5 deletions

View File

@ -101,6 +101,7 @@ Primarily tested with personal archive of sources written for Kick assmebler, DA
* irp (indefinite repeat)
**FIXED**
* Labels can start with numbers and values will only be interpreted as decimal numbers if terminated by a character that is not an alphabetic character or underscore
* INCSYM failed with local labels, this is now properly handled. (fixed again..)
* INCBIN and IMPORT BINARY always failed (force 0 bytes length)
* Using more than 16 bytes of Pool labels was flawed as byte 15 and 16 would be the same address.

View File

@ -545,6 +545,9 @@ public:
// grab a block of text starting with (, [ or { and end with the corresponding number of ), ] or }
strref scoped_block_skip();
// check matching characters that are terminated by any character in term or ends
int match_chars_str(const strref match, const strref term = strref());
strref get_line() const; // return the current line even if empty,t don't change this line
strref get_line(strl_t line) const; // return line by index
strref next_line(); // return the current line even if empty and skip this to line after
@ -3115,6 +3118,7 @@ int strref::find_any_not_in_range(const strref range, strl_t pos) const {
return int_find_range(string+pos, length-pos, length, rng, !include);
}
// search of a character in a given range while also checking that
// skipped characters are in another given range.
int strref::find_range_char_within_range(const strref range_find, const strref range_within, strl_t pos) const {
@ -3157,6 +3161,30 @@ bool strref::char_matches_ranges(unsigned char c) const {
return (match && include) || (!match && !include);
}
// count number of characters matching the range match as long
// as it is terminated by a given character or empty
int strref::match_chars_str(const strref match, const strref term)
{
bool include_match, include_term;
strref rng = int_check_exclude(match, include_match);
strref trm = int_check_exclude(term, include_term);
int ret = 0;
const char *str = string;
int left = length;
while (left) {
char c = *str++;
if (include_match == int_char_match_range_case(c, rng.get(), rng.get_len())) {
ret++;
} else if (!term || include_term == int_char_match_range_case(c, trm.get(), trm.get_len())) {
return ret;
} else
return 0;
left--;
}
return ret;
}
// wildcard search
#define MAX_WILDCARD_SEGMENTS 64

10
x65.cpp
View File

@ -3180,7 +3180,7 @@ EvalOperator Asm::RPNToken_Merlin(strref &expression, const struct EvalContext &
else if (c == '!' && !(expression + 1).len_label()) {
if (etx.scope_pc < 0) return EVOP_NRY; // ! by itself is current scope, !+label char is a local label
++expression; value = etx.scope_pc; section = CurrSection().IsRelativeSection() ? SectionId() : -1; return EVOP_VAL;
} else if (strref::is_number(c)) {
} else if (expression.match_chars_str("0-9", "!a-zA-Z_")) {
if (prev_op == EVOP_VAL) return EVOP_STP; // value followed by value doesn't make sense, stop
value = expression.atoi_skip(); return EVOP_VAL;
} else if (c == '!' || c == ']' || c==':' || strref::is_valid_label(c)) {
@ -3245,8 +3245,8 @@ EvalOperator Asm::RPNToken(strref &exp, const struct EvalContext &etx, EvalOpera
if (c == '!' && !(exp + 1).len_label()) {
if (etx.scope_pc < 0) return EVOP_NRY;
++exp; value = etx.scope_pc; section = CurrSection().IsRelativeSection() ? SectionId() : -1; return EVOP_VAL;
} else if (strref::is_number(c)) {
if (prev_op == EVOP_VAL) return EVOP_STP; // value followed by value doesn't make sense, stop
} else if (exp.match_chars_str("0-9", "!a-zA-Z_")) {
if (prev_op == EVOP_VAL) return EVOP_STP; // value followed by value doesn't make sense, stop
value = exp.atoi_skip(); return EVOP_VAL;
} else if (c == '!' || c == ':' || c=='.' || c=='@' || strref::is_valid_label(c)) {
if (prev_op == EVOP_VAL) return EVOP_STP; // a value followed by a value does not make sense, probably start of a comment (ORCA/LISA?)
@ -5792,7 +5792,7 @@ StatusCode Asm::BuildLine(strref line)
line.clear();
} else if (syntax==SYNTAX_MERLIN && strref::is_ws(line_start[0])) {
error = ERROR_UNDEFINED_CODE;
} else if (label[0]=='$' || strref::is_number(label[0]))
} else if (label[0]=='$')
line.clear();
else {
if (label.get_last()==':')
@ -7170,7 +7170,7 @@ int main(int argc, char **argv)
}
}
// export vice label file
// export vice monitor commands
if (vs_file && !srcname.same_str(vs_file) && !assembler.map.empty()) {
if (FILE *f = fopen(vs_file, "w")) {
for (MapSymbolArray::iterator i = assembler.map.begin(); i!=assembler.map.end(); ++i) {