[armedbear-cvs] r12597 - in trunk/abcl: src/org/armedbear/lisp test/src/org/armedbear/lisp

Erik Huelsmann ehuelsmann at common-lisp.net
Sat Apr 10 21:00:22 UTC 2010


Author: ehuelsmann
Date: Sat Apr 10 17:00:21 2010
New Revision: 12597

Log:
Consolidate faslRead, faslReadArray, faslReadComplex and faslReadPathname
with their non-'fasl' versions.

Modified:
   trunk/abcl/src/org/armedbear/lisp/FaslReader.java
   trunk/abcl/src/org/armedbear/lisp/Interpreter.java
   trunk/abcl/src/org/armedbear/lisp/LispReader.java
   trunk/abcl/src/org/armedbear/lisp/Load.java
   trunk/abcl/src/org/armedbear/lisp/Stream.java
   trunk/abcl/test/src/org/armedbear/lisp/StreamTest.java

Modified: trunk/abcl/src/org/armedbear/lisp/FaslReader.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/FaslReader.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/FaslReader.java	Sat Apr 10 17:00:21 2010
@@ -125,8 +125,9 @@
 
         {
             return new Cons(Symbol.QUOTE,
-                            new Cons(stream.faslRead(true, NIL, true,
-                                                     LispThread.currentThread())));
+                            new Cons(stream.read(true, NIL, true,
+                                                 LispThread.currentThread(),
+                                                 Stream.faslReadtable)));
         }
     };
 
@@ -255,7 +256,8 @@
                 return error(new ReaderError("Can't read #. when *READ-EVAL* is NIL.",
                                               stream));
             else
-                return eval(stream.faslRead(true, NIL, true, thread),
+                return eval(stream.read(true, NIL, true, thread,
+                                        Stream.faslReadtable),
                             new Environment(), thread);
         }
     };
@@ -288,7 +290,7 @@
         public LispObject execute(Stream stream, char c, int n)
 
         {
-            return stream.faslReadArray(n);
+            return stream.readArray(n, Stream.faslReadtable);
         }
     };
 
@@ -314,7 +316,7 @@
         public LispObject execute(Stream stream, char c, int n)
 
         {
-            return stream.faslReadComplex();
+            return stream.readComplex(Stream.faslReadtable);
         }
     };
 
@@ -340,7 +342,7 @@
         public LispObject execute(Stream stream, char c, int n)
 
         {
-            return stream.faslReadPathname();
+            return stream.readPathname(Stream.faslReadtable);
         }
     };
 
@@ -393,8 +395,9 @@
 
         {
             return new Cons(Symbol.FUNCTION,
-                            new Cons(stream.faslRead(true, NIL, true,
-                                                     LispThread.currentThread())));
+                            new Cons(stream.read(true, NIL, true,
+                                                 LispThread.currentThread(),
+                                                 Stream.faslReadtable)));
         }
     };
 

Modified: trunk/abcl/src/org/armedbear/lisp/Interpreter.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Interpreter.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Interpreter.java	Sat Apr 10 17:00:21 2010
@@ -149,7 +149,8 @@
     public LispObject eval(String s)
     {
         return Lisp.eval(new StringInputStream(s).read(true, NIL, false,
-                                                  LispThread.currentThread()));
+                                                  LispThread.currentThread(),
+                                                  Stream.currentReadtable));
     }
 
     public static synchronized void initializeLisp()
@@ -328,7 +329,8 @@
                     out._writeString("* ");
                     out._finishOutput();
                     LispObject object =
-                        getStandardInput().read(false, EOF, false, thread);
+                        getStandardInput().read(false, EOF, false, thread,
+                                                Stream.currentReadtable);
                     if (object == EOF)
                         break;
                     out.setCharPos(0);
@@ -499,7 +501,8 @@
     public static final LispObject readFromString(String s)
     {
         return new StringInputStream(s).read(true, NIL, false,
-                                             LispThread.currentThread());
+                                             LispThread.currentThread(),
+                                             Stream.currentReadtable);
     }
 
     // For j.
@@ -516,7 +519,8 @@
             initializeJLisp();
         StringInputStream stream = new StringInputStream(s);
         final LispThread thread = LispThread.currentThread();
-        LispObject obj = stream.read(false, EOF, false, thread);
+        LispObject obj = stream.read(false, EOF, false, thread,
+                                     Stream.currentReadtable);
         if (obj == EOF)
             return error(new EndOfFile(stream));
         final SpecialBindingsMark mark = thread.markSpecialBindings();

Modified: trunk/abcl/src/org/armedbear/lisp/LispReader.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/LispReader.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/LispReader.java	Sat Apr 10 17:00:21 2010
@@ -166,7 +166,8 @@
         {
             return new Cons(Symbol.QUOTE,
                             new Cons(stream.read(true, NIL, true,
-                                                 LispThread.currentThread())));
+                                                 LispThread.currentThread(),
+                                                 Stream.currentReadtable)));
         }
     };
 
@@ -292,7 +293,8 @@
                 return error(new ReaderError("Can't read #. when *READ-EVAL* is NIL.",
                                               stream));
             else
-                return eval(stream.read(true, NIL, true, thread),
+                return eval(stream.read(true, NIL, true,
+                                        thread, Stream.currentReadtable),
                             new Environment(), thread);
         }
     };
@@ -319,7 +321,7 @@
         public LispObject execute(Stream stream, char c, int n)
 
         {
-            return stream.readArray(n);
+            return stream.readArray(n, Stream.currentReadtable);
         }
     };
 
@@ -345,7 +347,7 @@
         public LispObject execute(Stream stream, char c, int n)
 
         {
-            return stream.readComplex();
+            return stream.readComplex(Stream.currentReadtable);
         }
     };
 
@@ -371,7 +373,7 @@
         public LispObject execute(Stream stream, char c, int n)
 
         {
-            return stream.readPathname();
+            return stream.readPathname(Stream.currentReadtable);
         }
     };
 
@@ -425,7 +427,8 @@
         {
             return new Cons(Symbol.FUNCTION,
                             new Cons(stream.read(true, NIL, true,
-                                                 LispThread.currentThread())));
+                                                 LispThread.currentThread(),
+                                                 Stream.currentReadtable)));
         }
     };
 

Modified: trunk/abcl/src/org/armedbear/lisp/Load.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Load.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Load.java	Sat Apr 10 17:00:21 2010
@@ -546,7 +546,8 @@
             LispObject result = NIL;
             while (true) {
                 sourcePositionBinding.value = Fixnum.getInstance(in.getOffset());
-                LispObject obj = in.read(false, EOF, false, thread);
+                LispObject obj = in.read(false, EOF, false,
+                                         thread, Stream.currentReadtable);
                 if (obj == EOF)
                     break;
                 result = eval(obj, env, thread);
@@ -580,7 +581,7 @@
                                AutoloadedFunctionProxy.makePreloadingContext());
             in.setExternalFormat(_FASL_EXTERNAL_FORMAT_.symbolValue(thread));
             while (true) {
-                LispObject obj = in.faslRead(false, EOF, true, thread);
+                LispObject obj = in.read(false, EOF, true, thread, Stream.faslReadtable);
                 if (obj == EOF)
                     break;
                 result = eval(obj, env, thread);

Modified: trunk/abcl/src/org/armedbear/lisp/Stream.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Stream.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Stream.java	Sat Apr 10 17:00:21 2010
@@ -424,19 +424,18 @@
 
 
     public LispObject read(boolean eofError, LispObject eofValue,
-                           boolean recursive, LispThread thread)
-
+                           boolean recursive, LispThread thread,
+                           ReadtableAccessor rta)
     {
         LispObject result = readPreservingWhitespace(eofError, eofValue,
-                                                     recursive, thread,
-                                                     currentReadtable);
+                                                     recursive, thread, rta);
         if (result != eofValue && !recursive) {
             try {
                 if (_charReady()) {
                     int n = _readChar();
                     if (n >= 0) {
                         char c = (char) n; // ### BUG: Codepoint conversion
-                        Readtable rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
+                        Readtable rt = rta.rt(thread);
                         if (!rt.isWhitespace(c))
                             _unreadChar(c);
                     }
@@ -498,34 +497,6 @@
         }
     }
 
-    public LispObject faslRead(boolean eofError, LispObject eofValue,
-                               boolean recursive, LispThread thread)
-
-    {
-        try {
-            LispObject result =
-                    readPreservingWhitespace(eofError, eofValue, recursive,
-                                             thread, faslReadtable);
-            if (result != eofValue && !recursive) {
-                if (_charReady()) {
-                    int n = _readChar();
-                    if (n >= 0) {
-                        char c = (char) n; // ### BUG: Codepoint conversion
-                        Readtable rt = FaslReadtable.getInstance();
-                        if (!rt.isWhitespace(c))
-                            _unreadChar(c);
-                    }
-                }
-            }
-            if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
-                return NIL;
-            else
-                return result;
-        } catch (IOException e) {
-            return error(new StreamError(this, e));
-        }
-    }
-
     private final LispObject processChar(char c, Readtable rt)
 
     {
@@ -537,17 +508,9 @@
         return readToken(c, rt);
     }
 
-    public LispObject readPathname() {
-        LispObject obj = read(true, NIL, false, LispThread.currentThread());
-        if (obj instanceof AbstractString)
-            return Pathname.parseNamestring((AbstractString)obj);
-        if (obj.listp())
-            return Pathname.makePathname(obj);
-        return error(new TypeError("#p requires a string or list argument."));
-    }
-
-    public LispObject faslReadPathname() {
-        LispObject obj = faslRead(true, NIL, false, LispThread.currentThread());
+    public LispObject readPathname(ReadtableAccessor rta) {
+        LispObject obj = read(true, NIL, false,
+                              LispThread.currentThread(), rta);
         if (obj instanceof AbstractString)
             return Pathname.parseNamestring((AbstractString)obj);
         if (obj.listp())
@@ -571,7 +534,7 @@
 
     public LispObject readStructure(ReadtableAccessor rta) {
         final LispThread thread = LispThread.currentThread();
-        LispObject obj = read(true, NIL, true, thread);
+        LispObject obj = read(true, NIL, true, thread, rta);
         if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
             return NIL;
         if (obj.listp()) {
@@ -639,7 +602,7 @@
                                                              this));
                         }
                         _unreadChar(nextChar);
-                        LispObject obj = read(true, NIL, true, thread);
+                        LispObject obj = read(true, NIL, true, thread, rta);
                         if (requireProperList) {
                             if (!obj.listp())
                                 error(new ReaderError("The value " +
@@ -793,9 +756,9 @@
         }
     }
 
-    public LispObject readArray(int rank) {
+    public LispObject readArray(int rank, ReadtableAccessor rta) {
         final LispThread thread = LispThread.currentThread();
-        LispObject obj = read(true, NIL, true, thread);
+        LispObject obj = read(true, NIL, true, thread, rta);
         if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
             return NIL;
         switch (rank) {
@@ -814,57 +777,9 @@
         }
     }
 
-    public LispObject faslReadArray(int rank) {
-        final LispThread thread = LispThread.currentThread();
-        LispObject obj = faslRead(true, NIL, true, thread);
-        if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
-            return NIL;
-        switch (rank) {
-        case -1:
-            return error(new ReaderError("No dimensions argument to #A.", this));
-        case 0:
-            return new ZeroRankArray(T, obj, false);
-        case 1: {
-            if (obj.listp() || obj instanceof AbstractVector)
-                return new SimpleVector(obj);
-            return error(new ReaderError(obj.writeToString() + " is not a sequence.",
-                                         this));
-        }
-        default:
-            return new SimpleArray_T(rank, obj);
-        }
-    }
-
-    public LispObject readComplex() {
-        final LispThread thread = LispThread.currentThread();
-        LispObject obj = read(true, NIL, true, thread);
-        if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
-            return NIL;
-        if (obj instanceof Cons && obj.length() == 2)
-            return Complex.getInstance(obj.car(), obj.cadr());
-        // Error.
-        StringBuilder sb = new StringBuilder("Invalid complex number format");
-        if (this instanceof FileStream) {
-            Pathname p = ((FileStream)this).getPathname();
-            if (p != null) {
-                String namestring = p.getNamestring();
-                if (namestring != null) {
-                    sb.append(" in #P\"");
-                    sb.append(namestring);
-                    sb.append('"');
-                }
-            }
-            sb.append(" at offset ");
-            sb.append(_getFilePosition());
-        }
-        sb.append(": #C");
-        sb.append(obj.writeToString());
-        return error(new ReaderError(sb.toString(), this));
-    }
-
-    public LispObject faslReadComplex() {
+    public LispObject readComplex(ReadtableAccessor rta) {
         final LispThread thread = LispThread.currentThread();
-        LispObject obj = faslRead(true, NIL, true, thread);
+        LispObject obj = read(true, NIL, true, thread, rta);
         if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
             return NIL;
         if (obj instanceof Cons && obj.length() == 2)
@@ -2236,7 +2151,7 @@
                 result = in.readPreservingWhitespace(eofError, third, false,
                                                      thread, currentReadtable);
             else
-                result = in.read(eofError, third, false, thread);
+                result = in.read(eofError, third, false, thread, currentReadtable);
             return thread.setValues(result, Fixnum.getInstance(in.getOffset()));
         }
     };
@@ -2250,7 +2165,7 @@
             final LispThread thread = LispThread.currentThread();
             final LispObject obj = Symbol.STANDARD_INPUT.symbolValue(thread);
             final Stream stream = checkStream(obj);
-            return stream.read(true, NIL, false, thread);
+            return stream.read(true, NIL, false, thread, currentReadtable);
         }
         @Override
         public LispObject execute(LispObject arg) {
@@ -2260,7 +2175,7 @@
             else if (arg == NIL)
                 arg = Symbol.STANDARD_INPUT.symbolValue(thread);
             final Stream stream = checkStream(arg);
-            return stream.read(true, NIL, false, thread);
+            return stream.read(true, NIL, false, thread, currentReadtable);
         }
         @Override
         public LispObject execute(LispObject first, LispObject second)
@@ -2272,7 +2187,7 @@
             else if (first == NIL)
                 first = Symbol.STANDARD_INPUT.symbolValue(thread);
             final Stream stream = checkStream(first);
-            return stream.read(second != NIL, NIL, false, thread);
+            return stream.read(second != NIL, NIL, false, thread, currentReadtable);
         }
         @Override
         public LispObject execute(LispObject first, LispObject second,
@@ -2285,7 +2200,7 @@
             else if (first == NIL)
                 first = Symbol.STANDARD_INPUT.symbolValue(thread);
             final Stream stream = checkStream(first);
-            return stream.read(second != NIL, third, false, thread);
+            return stream.read(second != NIL, third, false, thread, currentReadtable);
         }
         @Override
         public LispObject execute(LispObject first, LispObject second,
@@ -2298,7 +2213,8 @@
             else if (first == NIL)
                 first = Symbol.STANDARD_INPUT.symbolValue(thread);
             final Stream stream = checkStream(first);
-            return stream.read(second != NIL, third, fourth != NIL, thread);
+            return stream.read(second != NIL, third, fourth != NIL,
+                               thread, currentReadtable);
         }
     };
 

Modified: trunk/abcl/test/src/org/armedbear/lisp/StreamTest.java
==============================================================================
--- trunk/abcl/test/src/org/armedbear/lisp/StreamTest.java	(original)
+++ trunk/abcl/test/src/org/armedbear/lisp/StreamTest.java	Sat Apr 10 17:00:21 2010
@@ -24,7 +24,8 @@
     }
     Pathname pathname = Pathname.makePathname(file);
     Stream in = new Stream(Symbol.SYSTEM_STREAM, pathname.getInputStream(), Symbol.CHARACTER);
-    LispObject o = in.read(false, Lisp.EOF, false, LispThread.currentThread());
+    LispObject o = in.read(false, Lisp.EOF, false,
+                           LispThread.currentThread(), Stream.currentReadtable);
     assertFalse(o.equals(Lisp.NIL));
     in._close();
     file.delete();




More information about the armedbear-cvs mailing list