X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=expr.c;h=d1b9ac2e08e50114af26a0272cc93f5e0123348b;hp=8e2c33aa11f93e37538e13a75a91daa293d5832f;hb=a47cfb0704fdda11fe194a2eab611f3f82e95a03;hpb=d0c28c349ddfb8393568037f68bddbe8979ce0df diff --git a/expr.c b/expr.c index 8e2c33a..d1b9ac2 100644 --- a/expr.c +++ b/expr.c @@ -194,7 +194,7 @@ getsym: if (*tok != SYMBOL && *tok != STRING) return error(str_error); - p = string[tok[1]]; + p2 = string[tok[1]]; tok += 2; w = (WORD)(!strcmp(p, p2)); @@ -311,8 +311,9 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) // followed by the value 101, it will trigger a bad evaluation here. // This is probably a really bad assumption to be making here...! // (assuming tok[1] == EOL is a single token that is) + // Seems that even other tokens (SUNARY type) can fuck this up too. // if ((tok[1] == EOL) - if ((tok[1] == EOL && tok[0] != CONST) + if ((tok[1] == EOL && (tok[0] != CONST && tokenClass[tok[0]] != SUNARY)) || (((*tok == CONST || *tok == SYMBOL) || (*tok >= KW_R0 && *tok <= KW_R31)) && (tokenClass[tok[2]] < UNARY))) { @@ -531,7 +532,9 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) //printf("evexpr(): +\n"); --sval; // Pop value --sattr; // Pop attrib +//printf("--> N+N: %i + %i = ", *sval, sval[1]); *sval += sval[1]; // Compute value +//printf("%i\n", *sval); if (!(*sattr & TDB)) *sattr = sattr[1]; @@ -543,7 +546,9 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) //printf("evexpr(): -\n"); --sval; // Pop value --sattr; // Pop attrib +//printf("--> N-N: %i - %i = ", *sval, sval[1]); *sval -= sval[1]; // Compute value +//printf("%i\n", *sval); attr = (WORD)(*sattr & TDB); #if 0 @@ -664,7 +669,9 @@ printf("EVEXPR (-): sym1 = %X, sym2 = %X\n", attr, sattr[1]); case '*': --sval; --sattr; // Pop attrib +//printf("--> NxN: %i x %i = ", *sval, sval[1]); *sval *= sval[1]; +//printf("%i\n", *sval); break; case '/': --sval; @@ -673,7 +680,13 @@ printf("EVEXPR (-): sym1 = %X, sym2 = %X\n", attr, sattr[1]); if (sval[1] == 0) return error("divide by zero"); - *sval /= sval[1]; +//printf("--> N/N: %i / %i = ", sval[0], sval[1]); + // Compiler is picky here: Without casting these, it discards + // the sign if dividing a negative # by a positive one, + // creating a bad result. :-/ + // Probably a side effect of using VALUE intead of ints. + *sval = (int)sval[0] / (int)sval[1]; +//printf("%i\n", *sval); break; case '%': --sval;