]> git.sur5r.net Git - cc65/blobdiff - src/ca65/scanner.c
Added builtin .min() and .max() pseudo functions to the assembler.
[cc65] / src / ca65 / scanner.c
index 51cc998bc32d362598ee7c66befdc3d2871b073b..7edee8dfbc8979cc245dd1f6b9380e3e8d22a9c3 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2008 Ullrich von Bassewitz                                       */
-/*               Roemerstrasse 52                                            */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1998-2010, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -146,6 +146,7 @@ struct DotKeyword {
     { ".ASSERT",        TOK_ASSERT      },
     { ".AUTOIMPORT",   TOK_AUTOIMPORT  },
     { ".BANKBYTE",      TOK_BANKBYTE    },
+    { ".BANKBYTES",     TOK_BANKBYTES   },
     { ".BITAND",       TOK_AND         },
     { ".BITNOT",       TOK_NOT         },
     { ".BITOR",                TOK_OR          },
@@ -199,6 +200,7 @@ struct DotKeyword {
     { ".GLOBAL",       TOK_GLOBAL      },
     { ".GLOBALZP",     TOK_GLOBALZP    },
     { ".HIBYTE",        TOK_HIBYTE      },
+    { ".HIBYTES",       TOK_HIBYTES     },
     { ".HIWORD",        TOK_HIWORD      },
     { ".I16",          TOK_I16         },
     { ".I8",           TOK_I8          },
@@ -226,6 +228,7 @@ struct DotKeyword {
     { ".LIST",         TOK_LIST        },
     { ".LISTBYTES",    TOK_LISTBYTES   },
     { ".LOBYTE",        TOK_LOBYTE      },
+    { ".LOBYTES",       TOK_LOBYTES     },
     { ".LOCAL",                TOK_LOCAL       },
     { ".LOCALCHAR",    TOK_LOCALCHAR   },
     { ".LOWORD",        TOK_LOWORD      },
@@ -233,7 +236,9 @@ struct DotKeyword {
     { ".MACPACK",      TOK_MACPACK     },
     { ".MACRO",                TOK_MACRO       },
     { ".MATCH",                TOK_MATCH       },
+    { ".MAX",           TOK_MAX         },
     { ".MID",          TOK_MID         },
+    { ".MIN",           TOK_MIN         },
     { ".MOD",          TOK_MOD         },
     { ".NOT",          TOK_BOOLNOT     },
     { ".NULL",         TOK_NULL        },
@@ -429,9 +434,12 @@ static const CharSourceFunctions IFFunc = {
 
 
 
-void NewInputFile (const char* Name)
-/* Open a new input file */
+int NewInputFile (const char* Name)
+/* Open a new input file. Returns true if the file could be successfully opened
+ * and false otherwise.
+ */
 {
+    int RetCode = 0;            /* Return code. Assume an error. */
     char* PathName = 0;
 
     /* First try to open the file */
@@ -446,10 +454,11 @@ void NewInputFile (const char* Name)
                /* We are on include level. Search for the file in the include
         * directories.
         */
-       PathName = FindInclude (Name);
+       PathName = FindInclude (Name, INC_STD);
                if (PathName == 0 || (F = fopen (PathName, "r")) == 0) {
            /* Not found or cannot open, print an error and bail out */
            Error ("Cannot open include file `%s': %s", Name, strerror (errno));
+            goto ExitPoint;
        }
 
                /* Use the path name from now on */
@@ -495,8 +504,15 @@ void NewInputFile (const char* Name)
         UseCharSource (S);
     }
 
+    /* File successfully opened */
+    RetCode = 1;
+
+ExitPoint:
     /* Free an allocated name buffer */
     xfree (PathName);
+
+    /* Return the success code */
+    return RetCode;
 }
 
 
@@ -1002,8 +1018,11 @@ Again:
                    break;
 
                case 'S':
-                   Tok = TOK_S;
-                   return;
+                    if (CPU == CPU_65816) {
+                        Tok = TOK_S;
+                        return;
+                    }
+                    break;
 
                case 'X':
                    Tok = TOK_X;
@@ -1063,7 +1082,7 @@ CharAgain:
            NextChar ();
             if (C != '*') {
                 Tok = TOK_DIV;
-            } else {
+            } else if (CComments) {
                 /* Remember the position, then skip the '*' */
                 FilePos Pos = CurPos;
                 NextChar ();
@@ -1071,14 +1090,14 @@ CharAgain:
                     while (C !=  '*') {
                         if (C == EOF) {
                             PError (&Pos, "Unterminated comment");
-                            goto Again;
+                            goto CharAgain;
                         }
                         NextChar ();
                     }
                     NextChar ();
                 } while (C != '/');
                 NextChar ();
-                goto Again;  
+                goto Again;
             }
            return;
 
@@ -1356,12 +1375,7 @@ unsigned char ParseAddrSize (void)
  * error message and return ADDR_SIZE_DEFAULT.
  */
 {
-    static const char* Keys[] = {
-        "DIRECT", "ZEROPAGE", "ZP",
-        "ABSOLUTE", "ABS", "NEAR",
-        "FAR",
-        "LONG", "DWORD",
-    };
+    unsigned char AddrSize;
 
     /* Check for an identifier */
     if (Tok != TOK_IDENT) {
@@ -1369,21 +1383,15 @@ unsigned char ParseAddrSize (void)
         return ADDR_SIZE_DEFAULT;
     }
 
-    /* Search for the attribute */
-    switch (GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]))) {
-        case 0:
-        case 1:
-        case 2: return ADDR_SIZE_ZP;
-        case 3:
-        case 4:
-        case 5: return ADDR_SIZE_ABS;
-        case 6: return ADDR_SIZE_FAR;
-        case 7:
-        case 8: return ADDR_SIZE_LONG;
-        default:
-            Error ("Address size specifier expected");
-            return ADDR_SIZE_DEFAULT;
+    /* Convert the attribute */
+    AddrSize = AddrSizeFromStr (SB_GetConstBuf (&SVal));
+    if (AddrSize == ADDR_SIZE_INVALID) {
+        Error ("Address size specifier expected");
+        AddrSize = ADDR_SIZE_DEFAULT;
     }
+
+    /* Done */
+    return AddrSize;
 }