[armedbear-cvs] r13706 - trunk/abcl/src/org/armedbear/lisp

ehuelsmann at common-lisp.net ehuelsmann at common-lisp.net
Tue Dec 20 21:52:14 UTC 2011


Author: ehuelsmann
Date: Tue Dec 20 13:52:14 2011
New Revision: 13706

Log:
Refactor Stream.readToken() to fix an issue reported by Blake McBride
where ABCL treats the symbol and package specifier as one - which is incorrect.

Also improve symbol lookup in case of internal and external symbols by
not creating SimpleStrings for the symbol name before looking up.

Modified:
   trunk/abcl/src/org/armedbear/lisp/Stream.java

Modified: trunk/abcl/src/org/armedbear/lisp/Stream.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Stream.java	Tue Dec 20 13:48:22 2011	(r13705)
+++ trunk/abcl/src/org/armedbear/lisp/Stream.java	Tue Dec 20 13:52:14 2011	(r13706)
@@ -1030,11 +1030,8 @@
         if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
             return NIL;
         final LispObject readtableCase = rt.getReadtableCase();
-        final String token;
-        if (readtableCase == Keyword.INVERT)
-            token = invert(sb.toString(), flags);
-        else
-            token = sb.toString();
+        final String token =  sb.toString();
+        final boolean invert = readtableCase == Keyword.INVERT;
         final int length = token.length();
         if (length > 0) {
             final char firstChar = token.charAt(0);
@@ -1073,33 +1070,62 @@
                         return number;
                 }
             }
-            if (firstChar == ':')
-                if (flags == null || !flags.get(0))
-                    return PACKAGE_KEYWORD.intern(token.substring(1));
-            int index = findUnescapedDoubleColon(token, flags);
-            if (index > 0) {
-                String packageName = token.substring(0, index);
-                String symbolName = token.substring(index + 2);
-                Package pkg = Packages.findPackage(packageName);
-                if (pkg == null)
-                    return error(new LispError("Package \"" + packageName +
-                                               "\" not found."));
-                return pkg.intern(symbolName);
+            
+            String symbolName;
+            String packageName = null;
+            BitSet symbolFlags;
+            BitSet packageFlags = null;
+            Package pkg = null;
+            boolean internSymbol = true;
+            if (firstChar == ':' && (flags == null || !flags.get(0))) {
+                    symbolName = token.substring(1);
+                    pkg = PACKAGE_KEYWORD;
+                    if (flags != null)
+                        symbolFlags = flags.get(1, flags.size());
+                    else
+                        symbolFlags = null;
+            } else {
+                int index = findUnescapedDoubleColon(token, flags);
+                if (index > 0) {
+                    packageName = token.substring(0, index);
+                    packageFlags = (flags != null) ? flags.get(0, index) :  null;
+                    symbolName = token.substring(index + 2);
+                    symbolFlags = (flags != null) ? flags.get(index+2, flags.size()) : null;
+                } else {
+                    index = findUnescapedSingleColon(token, flags);
+                    if (index > 0) {
+                        packageName = token.substring(0, index);
+                        packageFlags = (flags != null) ? flags.get(0, index) : null;
+                        symbolName = token.substring(index + 1);
+                        symbolFlags = (flags != null) ? flags.get(index+2, flags.size()) : null;
+                        internSymbol = false;
+                    } else {
+                        pkg = (Package)Symbol._PACKAGE_.symbolValue(thread);
+                        symbolName = token;
+                        symbolFlags = flags;
+                    }
+                }
             }
-            index = findUnescapedSingleColon(token, flags);
-            if (index > 0) {
-                final String packageName = token.substring(0, index);
-                Package pkg = Packages.findPackage(packageName);
+            if (pkg == null) {
+                if (invert)
+                    packageName = invert(packageName, packageFlags);
+
+                pkg = Packages.findPackage(packageName);
                 if (pkg == null)
-                    return error(new PackageError("Package \"" + packageName +
-                                                  "\" not found."));
-                final String symbolName = token.substring(index + 1);
-                final SimpleString s = new SimpleString(symbolName);
-                Symbol symbol = pkg.findExternalSymbol(s);
+                    return error(new ReaderError("The package \"" + packageName + "\" can't be found.", this));
+            }
+            if (invert)
+                symbolName = invert(symbolName, symbolFlags);
+            
+            if (internSymbol) {
+                return pkg.intern(symbolName);
+            } else {
+                Symbol symbol = pkg.findExternalSymbol(symbolName);
                 if (symbol != null)
                     return symbol;
+
                 // Error!
-                if (pkg.findInternalSymbol(s) != null)
+                if (pkg.findInternalSymbol(symbolName) != null)
                     return error(new ReaderError("The symbol \"" + symbolName +
                                                  "\" is not external in package " +
                                                  packageName + '.',
@@ -1111,8 +1137,7 @@
                                                  this));
             }
         }
-        // Intern token in current package.
-        return ((Package)Symbol._PACKAGE_.symbolValue(thread)).intern(new SimpleString(token));
+        return error(new ReaderError("Can't intern zero-length symbol.", this));
     }
 
     private final BitSet _readToken(StringBuilder sb, Readtable rt)




More information about the armedbear-cvs mailing list