Closed cm68 closed 4 years ago
hi, I have a fix for this, extending your use of the stack, saving another byte for the unary stack when doing the parenthesis handing: (context diff)
@@ -156,7 +156,7 @@ static int ashr(int r, int n)
const char *expr(const char *p, int *v, int linepc, int allowfr,
enum expr_ecode *ecode, const char **ep)
{
- int si, usi;
+ int si, usi, usl;
const char *q;
char last;
int stack[ESTKSZ2];
@@ -172,6 +172,7 @@ const char *expr(const char *p, int *v, int linepc, int allowfr,
si = 0;
r = 0;
last = 'V'; /* first void */
+ usl = 0;
loop:
p = skipws(p);
if (*p == '(') {
@@ -184,6 +185,8 @@ loop:
}
stack[si++] = last;
stack[si++] = r;
+ stack[si++] = usl;
+ usl = usi;
p++;
r = 0;
last = 'v'; /* void */
@@ -197,6 +200,7 @@ loop:
} else {
p++;
n = r;
+ usl = stack[--si];
r = stack[--si];
last = (char) stack[--si];
goto oper;
@@ -396,7 +400,7 @@ uoper:
uopstk[usi++] = *p++;
goto loop;
oper:
- while (usi > 0) {
+ while (usi > usl) {
usi--;
switch (uopstk[usi]) {
case '~': n = ~n; break;
Thank you Curt. It seems to work perfectly. I will do some more tests and update uz80as soon with the fix. Thanks!
Ok! Version 1.11 is released with your fix. I have multiplied the stack size x 3 since we we now push 3 items or pop 3 items each time, to avoid overflow. I have added a new test for unary operators as well, just in case, to catch something like this in the future. And you are in the THANKS file. Thanks again!
your assembler is used in the RomWBW project as the linux TASM replacement. I wrote the makefiles and forked your assembler in the Tools/Unix subtree there. I'll try to track any of your new code there.
https://github.com/wwarthen/RomWBW/tree/master/Tools/unix/uz80as
you are credited here: https://github.com/wwarthen/RomWBW/blob/master/Readme.unix
uz80as was written by Jorge Giner Cordero, jorge.giner@hotmail.com,
and the original source can be found at https://github.com/jorgicor/uz80as
--curt
On Sun, Mar 29, 2020 at 3:26 AM Jorge Giner notifications@github.com wrote:
Ok! Version 1.11 is released with your fix. I have multiplied the stack size x 3 since we we now push 3 items or pop 3 items each time, to avoid overflow. I have added a new test for unary operators as well, just in case, to catch something like this in the future. And you are in the THANKS file. Thanks again!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jorgicor/uz80as/issues/1#issuecomment-605615069, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJJUTK3PKKD6JVO3G52XLXTRJ4O5VANCNFSM4K26NVOA .
-- I refine, they debug, he/she patches, they kludge.
my apologies for beating on the build process. I am allergic to automake. It's grossly overdesigned.
--curt
On Sun, Mar 29, 2020 at 3:26 AM Jorge Giner notifications@github.com wrote:
Ok! Version 1.11 is released with your fix. I have multiplied the stack size x 3 since we we now push 3 items or pop 3 items each time, to avoid overflow. I have added a new test for unary operators as well, just in case, to catch something like this in the future. And you are in the THANKS file. Thanks again!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jorgicor/uz80as/issues/1#issuecomment-605615069, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJJUTK3PKKD6JVO3G52XLXTRJ4O5VANCNFSM4K26NVOA .
-- I refine, they debug, he/she patches, they kludge.
Very nice work Curt! Of course feel free to do any changes that suit your needs. Anyway, I think you should include the file COPYING inside the folder where uz80as resides, since it contains the license for the code and copyright (I removed that from all source files). Thanks!
Will do. I'll put that in a pull request to wayne.
--curt
On Mon, Mar 30, 2020, 3:32 AM Jorge Giner notifications@github.com wrote:
Very nice work Curt! Of course feel free to do any changes that suit your needs. Anyway, I think you should include the file COPYING inside the folder where uz80as resides, since it contains the license for the code and copyright (I removed that from all source files). Thanks!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jorgicor/uz80as/issues/1#issuecomment-605919855, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJJUTKY4BBIAJDUQ5AS2OHTRKBYLJANCNFSM4K26NVOA .
the code assembled thusly:
0001 0000 FE .db ~(1|2) 0002 0001 .end
it should have emitted 0xFC
if you look at how the expression parser handles the parse, when it sees the leading ~, it pushes it on the unary operator stack. then, it processes the (. then it grabs the 1, then it applies the unary operators, generating $FE. this then persists.
it really needs to somehow mark the unary operator as deferred until the containing ) is processed. since I don't know the full logic, please have a look.