]> Shamusworld >> Repos - rmac/blobdiff - expr.c
Version bump for last patch; now at v1.13.4.
[rmac] / expr.c
diff --git a/expr.c b/expr.c
index b86111bd579769168ecad264fb1d087f57b02ba8..74b68c9c3ffe0bb9bfc7368bb48ef0ecd3a8fc25 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -1,7 +1,7 @@
-
+//
 // RMAC - Reboot's Macro Assembler for all Atari computers
 // EXPR.C - Expression Analyzer
-// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011-2018 Reboot and Friends
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
 // Source utilised with the kind permission of Landon Dyer
 //
@@ -900,11 +900,10 @@ printf("EVEXPR (-): sym1 = %X, sym2 = %X\n", attr, sattr[1]);
 
                // All other binary operators must have two ABS items to work with.
                // They all produce an ABS value.
+               // Shamus: Is this true? There's at least one counterexample of legit
+               //         code where this assumption fails to produce correct code.
                default:
 //printf("evexpr(): default\n");
-                       // GH - Removed for v1.0.15 as part of the fix for indexed loads.
-                       //if ((*sattr & (TEXT|DATA|BSS)) || (*--sattr & (TEXT|DATA|BSS)))
-                       //error(seg_error);
 
                        switch ((int)tk.u32[-1])
                        {
@@ -936,7 +935,7 @@ An open question here is do we promote ints to floats as signed or unsigned? It
                                }
 //printf("%i\n", *sval);
 
-                               *sattr = ABS | DEFINED | attr;          // Expr becomes absolute
+//no                           *sattr = ABS | DEFINED | attr;          // Expr becomes absolute
                                break;
 
                        case '/':
@@ -974,7 +973,7 @@ An open question here is do we promote ints to floats as signed or unsigned? It
                                }
 //printf("%i\n", *sval);
 
-                               *sattr = ABS | DEFINED | attr;          // Expr becomes absolute
+//no                           *sattr = ABS | DEFINED | attr;          // Expr becomes absolute
                                break;
 
                        case '%':
@@ -988,7 +987,7 @@ An open question here is do we promote ints to floats as signed or unsigned? It
                                        return error("mod (%) by zero");
 
                                *sval %= sval[1];
-                               *sattr = ABS | DEFINED;                 // Expr becomes absolute
+//no                           *sattr = ABS | DEFINED;                 // Expr becomes absolute
                                break;
 
                        case SHL:
@@ -999,7 +998,7 @@ An open question here is do we promote ints to floats as signed or unsigned? It
                                        return error("floating point numbers not allowed with operator '<<'.");
 
                                *sval <<= sval[1];
-                               *sattr = ABS | DEFINED;                 // Expr becomes absolute
+//no                           *sattr = ABS | DEFINED;                 // Expr becomes absolute
                                break;
 
                        case SHR:
@@ -1010,7 +1009,7 @@ An open question here is do we promote ints to floats as signed or unsigned? It
                                        return error("floating point numbers not allowed with operator '>>'.");
 
                                *sval >>= sval[1];
-                               *sattr = ABS | DEFINED;                 // Expr becomes absolute
+//no                           *sattr = ABS | DEFINED;                 // Expr becomes absolute
                                break;
 
                        case '&':
@@ -1021,7 +1020,7 @@ An open question here is do we promote ints to floats as signed or unsigned? It
                                        return error("floating point numbers not allowed with operator '&'.");
 
                                *sval &= sval[1];
-                               *sattr = ABS | DEFINED;                 // Expr becomes absolute
+//no                           *sattr = ABS | DEFINED;                 // Expr becomes absolute
                                break;
 
                        case '^':
@@ -1032,7 +1031,7 @@ An open question here is do we promote ints to floats as signed or unsigned? It
                                        return error("floating point numbers not allowed with operator '^'.");
 
                                *sval ^= sval[1];
-                               *sattr = ABS | DEFINED;                 // Expr becomes absolute
+//no                           *sattr = ABS | DEFINED;                 // Expr becomes absolute
                                break;
 
                        case '|':
@@ -1043,7 +1042,7 @@ An open question here is do we promote ints to floats as signed or unsigned? It
                                        return error("floating point numbers not allowed with operator '|'.");
 
                                *sval |= sval[1];
-                               *sattr = ABS | DEFINED;                 // Expr becomes absolute
+//no                           *sattr = ABS | DEFINED;                 // Expr becomes absolute
                                break;
 
                        default:
@@ -1066,3 +1065,27 @@ An open question here is do we promote ints to floats as signed or unsigned? It
        return OK;
 }
 
+
+//
+// Count the # of tokens in the passed in expression
+// N.B.: 64-bit constants count as two tokens each
+//
+uint16_t ExpressionLength(TOKEN * tk)
+{
+       uint16_t length;
+
+       for(length=0; tk[length]!=ENDEXPR; length++)
+       {
+               // Add one to length for 2X tokens, two for 3X tokens
+               if (tk[length] == SYMBOL)
+                       length++;
+               else if ((tk[length] == CONST) || (tk[length] == FCONST))
+                       length += 2;
+       }
+
+       // Add 1 for ENDEXPR
+       length++;
+
+       return length;
+}
+