]> git.sur5r.net Git - cc65/blobdiff - src/ca65/pseudo.c
Replaced builtin macro packages with .mac files that are included like ordinary ...
[cc65] / src / ca65 / pseudo.c
index 480fc61865d5cdb7d5d1ce89582ca5c1547a1ecf..3f67c2fe65b24750ff680032967cad11ec2993e1 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2011, Ullrich von Bassewitz                                      */
+/* (C) 1998-2012, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -38,8 +38,6 @@
 #include <string.h>
 #include <ctype.h>
 #include <errno.h>
-#include <sys/types.h>         /* EMX needs this */
-#include <sys/stat.h>
 
 /* common */
 #include "alignment.h"
@@ -47,6 +45,7 @@
 #include "bitops.h"
 #include "cddefs.h"
 #include "coll.h"
+#include "filestat.h"
 #include "gentype.h"
 #include "intstack.h"
 #include "scopedefs.h"
@@ -68,7 +67,6 @@
 #include "incpath.h"
 #include "instr.h"
 #include "listing.h"
-#include "macpack.h"
 #include "macro.h"
 #include "nexttok.h"
 #include "objcode.h"
@@ -370,12 +368,12 @@ static void DoAddr (void)
 
     /* Parse arguments */
     while (1) {
-       if (GetCPU() == CPU_65816) {
-                   EmitWord (GenWordExpr (Expression ()));
-       } else {
+        ExprNode* Expr = Expression ();
+       if (GetCPU () == CPU_65816 || ForceRange) {
            /* Do a range check */
-           EmitWord (Expression ());
-               }
+            Expr = GenWordExpr (Expr);
+       }
+        EmitWord (Expr);
        if (CurTok.Tok != TOK_COMMA) {
            break;
        } else {
@@ -586,7 +584,7 @@ static void DoByte (void)
            EmitStrBuf (&CurTok.SVal);
            NextTok ();
        } else {
-           EmitByte (Expression ());
+            EmitByte (BoundedExpr (Expression, 1));
        }
        if (CurTok.Tok != TOK_COMMA) {
            break;
@@ -595,7 +593,7 @@ static void DoByte (void)
            /* Do smart handling of dangling comma */
            if (CurTok.Tok == TOK_SEP) {
                Error ("Unexpected end of line");
-               break;
+               break;
            }
        }
     }
@@ -627,7 +625,7 @@ static void DoCharMap (void)
 
     /* Read the index as numerical value */
     Index = ConstExpression ();
-    if (Index < 0 || Index > 255) {
+    if (Index <= 0 || Index > 255) {
        /* Value out of range */
                ErrorSkip ("Range error");
        return;
@@ -791,7 +789,7 @@ static void DoDByt (void)
 
     /* Parse arguments */
     while (1) {
-       EmitWord (GenSwapExpr (Expression ()));
+       EmitWord (GenSwapExpr (BoundedExpr (Expression, 2)));
        if (CurTok.Tok != TOK_COMMA) {
            break;
        } else {
@@ -865,7 +863,7 @@ static void DoDWord (void)
 /* Define dwords */
 {
     while (1) {
-               EmitDWord (Expression ());
+               EmitDWord (BoundedExpr (Expression, 4));
        if (CurTok.Tok != TOK_COMMA) {
            break;
        } else {
@@ -965,7 +963,7 @@ static void DoFarAddr (void)
 
     /* Parse arguments */
     while (1) {
-               EmitFarAddr (Expression ());
+               EmitFarAddr (BoundedExpr (Expression, 3));
        if (CurTok.Tok != TOK_COMMA) {
            break;
        } else {
@@ -1264,7 +1262,7 @@ static void DoIncBin (void)
      * here.
      */
     SB_Terminate (&Name);
-    if (stat (SB_GetConstBuf (&Name), &StatBuf) != 0) {
+    if (FileStat (SB_GetConstBuf (&Name), &StatBuf) != 0) {
         Fatal ("Cannot stat input file `%m%p': %s", &Name, strerror (errno));
     }
 
@@ -1445,28 +1443,16 @@ static void DoLocalChar (void)
 static void DoMacPack (void)
 /* Insert a macro package */
 {
-    int Package;
-
     /* We expect an identifier */
     if (CurTok.Tok != TOK_IDENT) {
        ErrorSkip ("Identifier expected");
-       return;
-    }
-
-    /* Search for the macro package name */
-    LocaseSVal ();
-    Package = MacPackFind (&CurTok.SVal);
-    if (Package < 0) {
-       /* Not found */
-       ErrorSkip ("Invalid macro package");
-       return;
-    }
-
-    /* Insert the package. If this fails, skip the remainder of the line to
-     * avoid additional error messages.
-     */
-    if (MacPackInsert (Package) == 0) {
-        SkipUntilSep ();
+    } else {
+        SB_AppendStr (&CurTok.SVal, ".mac");
+        SB_Terminate (&CurTok.SVal);
+       if (NewInputFile (SB_GetConstBuf (&CurTok.SVal)) == 0) {
+            /* Error opening the file, skip remainder of line */
+            SkipUntilSep ();
+        }
     }
 }
 
@@ -1936,7 +1922,7 @@ static void DoWord (void)
 
     /* Parse arguments */
     while (1) {
-               EmitWord (Expression ());
+               EmitWord (BoundedExpr (Expression, 2));
        if (CurTok.Tok != TOK_COMMA) {
            break;
        } else {
@@ -1970,14 +1956,14 @@ static void DoZeropage (void)
 
 /* Control commands flags */
 enum {
-    ccNone     = 0x0000,               /* No special flags */
-    ccKeepToken        = 0x0001                /* Do not skip the current token */
+    ccNone     = 0x0000,               /* No special flags */
+    ccKeepToken        = 0x0001                /* Do not skip the current token */
 };
 
 /* Control command table */
 typedef struct CtrlDesc CtrlDesc;
 struct CtrlDesc {
-    unsigned           Flags;                  /* Flags for this directive */
+    unsigned           Flags;                  /* Flags for this directive */
     void               (*Handler) (void);      /* Command handler */
 };