X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=expr.c;h=07391acfe6f8fceb5dfaabcdaea036f1acf9b117;hp=5c7fc8760437375850a2b60ee4496ab8cee60def;hb=c74d8ef6f193cb2be876c920c5cb7f599dd5418a;hpb=090bda1c00a18b3f616e734090ba456a461879a1 diff --git a/expr.c b/expr.c index 5c7fc87..07391ac 100644 --- a/expr.c +++ b/expr.c @@ -3,7 +3,7 @@ // EXPR.C - Expression Analyzer // Copyright (C) 199x Landon Dyer, 2011 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 -// Source Utilised with the Kind Permission of Landon Dyer +// Source utilised with the kind permission of Landon Dyer // #include "expr.h" @@ -278,7 +278,8 @@ int expr2(void) // pcloc == location at start of line *evalTokenBuffer++ = (orgactive ? orgaddr : pcloc); - *evalTokenBuffer++ = ABS | DEFINED; // Store attribs + // '*' takes attributes of current section, not ABS! + *evalTokenBuffer++ = cursect | DEFINED; break; default: return error("bad expression"); @@ -347,7 +348,8 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) else *evalTokenBuffer++ = *a_value = pcloc; - *a_attr = ABS | DEFINED; + // '*' takes attributes of current section, not ABS! + *a_attr = cursect | DEFINED; if (a_esym != NULL) *a_esym = NULL; @@ -360,7 +362,7 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) j = (*p == '.' ? curenv : 0); symbol = lookup(p, LABEL, j); #if 0 -printf("eval: Looking up symbol [=%08X]\n", symbol); +printf("eval: Looking up symbol (%s) [=%08X]\n", p, symbol); if (symbol) printf(" attr=%04X, attre=%08X, val=%i, name=%s\n", symbol->sattr, symbol->sattre, symbol->svalue, symbol->sname); #endif @@ -419,7 +421,8 @@ thrown away right here. What the hell is it for? *a_attr = (WORD)(symbol->sattr & ~GLOBAL); - if ((symbol->sattr & (GLOBAL | DEFINED)) == GLOBAL && a_esym != NULL) + if ((symbol->sattr & (GLOBAL | DEFINED)) == GLOBAL + && a_esym != NULL) *a_esym = symbol; tok += 2; @@ -500,7 +503,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) } *++sattr = (WORD)(sy->sattr & ~GLOBAL); // Push attribs - sym_seg = (WORD)(sy->sattr & (TEXT | DATA | BSS)); + sym_seg = (WORD)(sy->sattr & TDB); break; case CONST: //printf("evexpr(): CONST = %i\n", *tk); @@ -528,11 +531,13 @@ 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 & (TEXT | DATA | BSS))) + if (!(*sattr & TDB)) *sattr = sattr[1]; - else if (sattr[1] & (TEXT | DATA | BSS)) + else if (sattr[1] & TDB) return error(seg_error); break; @@ -540,25 +545,26 @@ 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 & (TEXT | DATA | BSS)); - + attr = (WORD)(*sattr & TDB); +#if 0 +printf("EVEXPR (-): sym1 = %X, sym2 = %X\n", attr, sattr[1]); +#endif + // If symbol1 is ABS, take attributes from symbol2 if (!attr) *sattr = sattr[1]; - else if (sattr[1] & (TEXT | DATA | BSS)) - { - if (!(attr & sattr[1])) - return error(seg_error); - else - *sattr &= ~(TEXT | DATA | BSS); - } + // Otherwise, they're both TDB and so attributes cancel out + else if (sattr[1] & TDB) + *sattr &= ~TDB; break; // Unary operators only work on ABS items case UNMINUS: //printf("evexpr(): UNMINUS\n"); - if (*sattr & (TEXT | DATA | BSS)) + if (*sattr & TDB) error(seg_error); *sval = -(int)*sval; @@ -566,7 +572,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) break; case '!': //printf("evexpr(): !\n"); - if (*sattr & (TEXT | DATA | BSS)) + if (*sattr & TDB) error(seg_error); *sval = !*sval; @@ -574,7 +580,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) break; case '~': //printf("evexpr(): ~\n"); - if (*sattr & (TEXT | DATA | BSS)) + if (*sattr & TDB) error(seg_error); *sval = ~*sval; @@ -662,7 +668,9 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) case '*': --sval; --sattr; // Pop attrib +//printf("--> NxN: %i x %i = ", *sval, sval[1]); *sval *= sval[1]; +//printf("%i\n", *sval); break; case '/': --sval; @@ -671,7 +679,13 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) 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;