X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=expr.c;h=8d18a67ec5ef9b4fddde0d28e9dd8f268d712abe;hp=debcd8884d06915ad75b007ccc72866265407081;hb=cfd001aea60f54e49d9beae0f941c513f45c202b;hpb=ff2052bcaa1428a33a202822a81a6f9b8e567ef4 diff --git a/expr.c b/expr.c index debcd88..8d18a67 100644 --- a/expr.c +++ b/expr.c @@ -1,7 +1,7 @@ // -// RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System +// RMAC - Reboot's Macro Assembler for all Atari computers // EXPR.C - Expression Analyzer -// Copyright (C) 199x Landon Dyer, 2017 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // @@ -23,7 +23,7 @@ // N.B.: The size of tokenClass should be identical to the largest value of // a token; we're assuming 256 but not 100% sure! static char tokenClass[256]; // Generated table of token classes -static VALUE evstk[EVSTACKSIZE]; // Evaluator value stack +static uint32_t evstk[EVSTACKSIZE]; // Evaluator value stack static WORD evattr[EVSTACKSIZE]; // Evaluator attribute stack // Token-class initialization list @@ -61,9 +61,9 @@ static int symbolNum; // Pointer to the entry in symbolPtr[] // // Obtain a string value // -static VALUE str_value(char * p) +static uint32_t str_value(char * p) { - VALUE v; + uint32_t v; for(v=0; *p; p++) v = (v << 8) | (*p & 0xFF); @@ -244,10 +244,10 @@ int expr2(void) if (sy->sattre & EQUATEDREG) { if ((regbank == BANK_0) && (sy->sattre & BANK_1) && !altbankok) - warns("equated symbol \'%s\' cannot be used in register bank 0", sy->sname); + warn("equated symbol \'%s\' cannot be used in register bank 0", sy->sname); if ((regbank == BANK_1) && (sy->sattre & BANK_0) && !altbankok) - warns("equated symbol \'%s\' cannot be used in register bank 1", sy->sname); + warn("equated symbol \'%s\' cannot be used in register bank 1", sy->sname); } *evalTokenBuffer++ = SYMBOL; @@ -264,7 +264,7 @@ int expr2(void) return ERROR; if (*tok++ != ')') - return error("missing close parenthesis ')'"); + return error("missing closing parenthesis ')'"); break; case '[': @@ -272,7 +272,7 @@ int expr2(void) return ERROR; if (*tok++ != ']') - return error("missing close parenthesis ']'"); + return error("missing closing bracket ']'"); break; case '$': @@ -287,6 +287,20 @@ int expr2(void) *evalTokenBuffer++ = (orgactive ? orgaddr : pcloc); // '*' takes attributes of current section, not ABS! *evalTokenBuffer++ = cursect | DEFINED; + break; + case '{': + if (expr0() != OK) // Eat up first parameter (register or immediate) + return ERROR; + + if (*tok++ != ':') // Demand a ':' there + return error("missing colon ':'"); + + if (expr0() != OK) // Eat up second parameter (register or immediate) + return ERROR; + + if (*tok++ != '}') + return error("missing closing brace '}'"); + break; default: return error("bad expression"); @@ -299,7 +313,7 @@ int expr2(void) // // Recursive-descent expression analyzer (with some simple speed hacks) // -int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) +int expr(TOKEN * otk, uint32_t * a_value, WORD * a_attr, SYM ** a_esym) { // Passed in values (once derefenced, that is) can all be zero. They are // there so that the expression analyzer can fill them in as needed. The @@ -386,7 +400,7 @@ if (symbol) // means it will be fixed up later, and thus, not an error. if ((symbol->sattre & UNDEF_EQUR) && !riscImmTokenSeen) { - errors("undefined register equate '%s'", symbol->sname); + error("undefined register equate '%s'", symbol->sname); //if we return right away, it returns some spurious errors... // return ERROR; } @@ -395,10 +409,10 @@ if (symbol) if (symbol->sattre & EQUATEDREG) { if ((regbank == BANK_0) && (symbol->sattre & BANK_1) && !altbankok) - warns("equated symbol '%s' cannot be used in register bank 0", symbol->sname); + warn("equated symbol '%s' cannot be used in register bank 0", symbol->sname); if ((regbank == BANK_1) && (symbol->sattre & BANK_0) && !altbankok) - warns("equated symbol '%s' cannot be used in register bank 1", symbol->sname); + warn("equated symbol '%s' cannot be used in register bank 1", symbol->sname); } *evalTokenBuffer++ = SYMBOL; @@ -462,19 +476,14 @@ thrown away right here. What the hell is it for? // UNDEFINED, but it's value includes everything but the symbol value, and // `a_esym' is set to the external symbol. // -int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) +int evexpr(TOKEN * tk, uint32_t * a_value, WORD * a_attr, SYM ** a_esym) { - WORD * sattr; - VALUE * sval; WORD attr; SYM * sy; - SYM * esym; - WORD sym_seg; - - sval = evstk; // (Empty) initial stack - sattr = evattr; - esym = NULL; // No external symbol involved - sym_seg = 0; + uint32_t * sval = evstk; // (Empty) initial stack + WORD * sattr = evattr; + SYM * esym = NULL; // No external symbol involved + WORD sym_seg = 0; while (*tk != ENDEXPR) { @@ -685,14 +694,14 @@ printf("EVEXPR (-): sym1 = %X, sym2 = %X\n", attr, sattr[1]); sattr--; // Pop attrib if (sval[1] == 0) - return error("divide by zero"); + return error("division by zero"); //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]; + // Definitely a side effect of using uint32_ts intead of ints. + *sval = (int32_t)sval[0] / (int32_t)sval[1]; //printf("%i\n", *sval); break; case '%': @@ -744,7 +753,7 @@ printf("EVEXPR (-): sym1 = %X, sym2 = %X\n", attr, sattr[1]); // sym_seg added in 1.0.16 to solve a problem with forward symbols in // expressions where absolute values also existed. The absolutes were // overiding the symbol segments and not being included :( - //*a_attr = *sattr | sym_seg; // Copy value + attrib + //*a_attr = *sattr | sym_seg; // Copy value + attrib *a_attr = *sattr; // Copy value + attrib *a_value = *sval;