Skip to content

Commit c987a5c

Browse files
committed
Bugfix for AgonPlatform#60, additional tests
1 parent c56cabb commit c987a5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+145
-419
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ bin/
5555
src/.vs/
5656
*.vsidx
5757
*Browse.VC.db
58-
*.suo
58+
*.suo
59+
60+
# Test output
61+
test.output
62+
tests/*.bin

src/assemble.c

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,31 @@ uint8_t getAsciiValue(char *string) {
7777
// labelb-1
7878
// labela+labelb+offset1-1
7979
// The string should not contain any spaces, needs to be a single token
80-
int24_t getValue(char *string, bool req_firstpass) {
81-
uint8_t length,substlength;
82-
int24_t total, tmp;
83-
char operator, *ptr, unary_operator;
84-
label_t *lbl;
80+
int24_t getValue(char *str, bool req_firstpass) {
8581
streamtoken_t token;
86-
87-
ptr = string;
88-
total = 0;
89-
unary_operator = 0;
82+
label_t *lbl;
83+
uint24_t total, tmp;
84+
uint8_t length, substlength;
85+
char prev_op = '+', unary = 0;
86+
bool expect = true;
9087

9188
if((pass == 1) && !req_firstpass) return 0;
9289

93-
operator = '+'; // previous operand in case of single value/label
94-
while(ptr) {
95-
tmp = 0;
96-
length = getOperatorToken(&token, ptr);
97-
if(length) {
98-
if(currentExpandedMacro) {
99-
substlength = macroExpandArg(_macro_VAL_buffer, token.start, currentExpandedMacro);
100-
if(substlength) {
101-
token.start = _macro_VAL_buffer;
102-
length = substlength;
103-
}
90+
total = 0;
91+
while(str) {
92+
length = getOperatorToken(&token, str);
93+
if(currentExpandedMacro) {
94+
substlength = macroExpandArg(_macro_VAL_buffer, token.start, currentExpandedMacro);
95+
if(substlength) {
96+
token.start = _macro_VAL_buffer;
97+
length = substlength;
10498
}
105-
99+
}
100+
if(length == 0) { // at begin, or middle, OK. Expect catch at end
101+
expect = true;
102+
unary = token.terminator;
103+
}
104+
else { // normal processing
106105
lbl = findLabel(token.start);
107106
if(lbl) {
108107
tmp = lbl->address;
@@ -116,19 +115,19 @@ int24_t getValue(char *string, bool req_firstpass) {
116115
}
117116
}
118117
}
119-
}
120-
121-
if(unary_operator) {
122-
switch(unary_operator) {
123-
case '-': tmp = -tmp; break;
124-
case '~': tmp = ~tmp; break;
125-
case '+': break;
126-
default: break;
118+
if(unary) {
119+
switch(unary) {
120+
case '-': tmp = -tmp; break;
121+
case '~': tmp = ~tmp; break;
122+
case '+': break;
123+
default:
124+
error(message[ERROR_UNARYOPERATOR]);
125+
return 0;
126+
}
127+
unary = 0; // reset
128+
expect = false;
127129
}
128-
}
129-
130-
if(length) { // when an actual value is present between operators
131-
switch(operator) {
130+
switch(prev_op) {
132131
case '+': total += tmp; break;
133132
case '-': total -= tmp; break;
134133
case '*': total *= tmp; break;
@@ -144,17 +143,14 @@ int24_t getValue(char *string, bool req_firstpass) {
144143
error(message[ERROR_OPERATOR]);
145144
return total;
146145
}
146+
prev_op = token.terminator;
147+
expect = false;
147148
}
148-
149-
if(token.terminator && (length == 0)) {
150-
unary_operator = token.terminator;
151-
}
152-
else {
153-
unary_operator = 0;
154-
operator = token.terminator;
155-
}
156-
if(operator) ptr = token.next;
157-
else ptr = NULL;
149+
str = token.next;
150+
}
151+
if(expect) {
152+
error(message[ERROR_MISSINGOPERAND]);
153+
return 0;
158154
}
159155
return total;
160156
}

src/globals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ char *message[] = {
6767
"Invalid literal format",
6868
"Parse error",
6969
"Invalid operator",
70+
"Illegal unary opeator",
7071
"Argument is not a power of 2",
7172
"Maximum nested level of include files reached",
7273
"Maximum number of macros reached",

src/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ enum {
9090
ERROR_ASCIIFORMAT,
9191
ERROR_PARSE,
9292
ERROR_OPERATOR,
93+
ERROR_UNARYOPERATOR,
9394
ERROR_POWER2,
9495
ERROR_MAXINCLUDEFILES,
9596
ERROR_MAXMACROS,

src/utils.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ uint8_t getOperatorToken(streamtoken_t *token, char *src) {
311311
if(*src) token->next = shift?src+2:src+1;
312312
else token->next = NULL;
313313

314-
*src-- = 0; // terminate early and revert one character
315-
while(isspace(*src)) { // remove trailing space(s)
316-
*src-- = 0; // terminate on trailing spaces
317-
if(length-- == 0) break;
314+
if(length) {
315+
*src-- = 0; // terminate early and revert one character
316+
while(isspace(*src)) { // remove trailing space(s)
317+
*src-- = 0; // terminate on trailing spaces
318+
if(length-- == 0) break;
319+
}
318320
}
319321
return length;
320322
}

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export ASMBIN=../../bin/ez80asm
33
NOCOLOR='\033[0m'
44
RED='\033[0;31m'
55
GREEN='\033[0;32m'
6-
FORMAT='%-20.20s'
6+
FORMAT='%-25.25s'
77

88
testresult=2
99
failed=0

tests/Conditional_asm/test.output

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/Errors_labels/test.output

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/Errors_literals/test.output

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/Errors_macros/test.output

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)