Changeset 12597


Ignore:
Timestamp:
04/10/10 21:00:21 (14 years ago)
Author:
ehuelsmann
Message:

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

Location:
trunk/abcl
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/FaslReader.java

    r12594 r12597  
    126126        {
    127127            return new Cons(Symbol.QUOTE,
    128                             new Cons(stream.faslRead(true, NIL, true,
    129                                                      LispThread.currentThread())));
     128                            new Cons(stream.read(true, NIL, true,
     129                                                 LispThread.currentThread(),
     130                                                 Stream.faslReadtable)));
    130131        }
    131132    };
     
    256257                                              stream));
    257258            else
    258                 return eval(stream.faslRead(true, NIL, true, thread),
     259                return eval(stream.read(true, NIL, true, thread,
     260                                        Stream.faslReadtable),
    259261                            new Environment(), thread);
    260262        }
     
    289291
    290292        {
    291             return stream.faslReadArray(n);
     293            return stream.readArray(n, Stream.faslReadtable);
    292294        }
    293295    };
     
    315317
    316318        {
    317             return stream.faslReadComplex();
     319            return stream.readComplex(Stream.faslReadtable);
    318320        }
    319321    };
     
    341343
    342344        {
    343             return stream.faslReadPathname();
     345            return stream.readPathname(Stream.faslReadtable);
    344346        }
    345347    };
     
    394396        {
    395397            return new Cons(Symbol.FUNCTION,
    396                             new Cons(stream.faslRead(true, NIL, true,
    397                                                      LispThread.currentThread())));
     398                            new Cons(stream.read(true, NIL, true,
     399                                                 LispThread.currentThread(),
     400                                                 Stream.faslReadtable)));
    398401        }
    399402    };
  • trunk/abcl/src/org/armedbear/lisp/Interpreter.java

    r12546 r12597  
    150150    {
    151151        return Lisp.eval(new StringInputStream(s).read(true, NIL, false,
    152                                                   LispThread.currentThread()));
     152                                                  LispThread.currentThread(),
     153                                                  Stream.currentReadtable));
    153154    }
    154155
     
    329330                    out._finishOutput();
    330331                    LispObject object =
    331                         getStandardInput().read(false, EOF, false, thread);
     332                        getStandardInput().read(false, EOF, false, thread,
     333                                                Stream.currentReadtable);
    332334                    if (object == EOF)
    333335                        break;
     
    500502    {
    501503        return new StringInputStream(s).read(true, NIL, false,
    502                                              LispThread.currentThread());
     504                                             LispThread.currentThread(),
     505                                             Stream.currentReadtable);
    503506    }
    504507
     
    517520        StringInputStream stream = new StringInputStream(s);
    518521        final LispThread thread = LispThread.currentThread();
    519         LispObject obj = stream.read(false, EOF, false, thread);
     522        LispObject obj = stream.read(false, EOF, false, thread,
     523                                     Stream.currentReadtable);
    520524        if (obj == EOF)
    521525            return error(new EndOfFile(stream));
  • trunk/abcl/src/org/armedbear/lisp/LispReader.java

    r12594 r12597  
    167167            return new Cons(Symbol.QUOTE,
    168168                            new Cons(stream.read(true, NIL, true,
    169                                                  LispThread.currentThread())));
     169                                                 LispThread.currentThread(),
     170                                                 Stream.currentReadtable)));
    170171        }
    171172    };
     
    293294                                              stream));
    294295            else
    295                 return eval(stream.read(true, NIL, true, thread),
     296                return eval(stream.read(true, NIL, true,
     297                                        thread, Stream.currentReadtable),
    296298                            new Environment(), thread);
    297299        }
     
    320322
    321323        {
    322             return stream.readArray(n);
     324            return stream.readArray(n, Stream.currentReadtable);
    323325        }
    324326    };
     
    346348
    347349        {
    348             return stream.readComplex();
     350            return stream.readComplex(Stream.currentReadtable);
    349351        }
    350352    };
     
    372374
    373375        {
    374             return stream.readPathname();
     376            return stream.readPathname(Stream.currentReadtable);
    375377        }
    376378    };
     
    426428            return new Cons(Symbol.FUNCTION,
    427429                            new Cons(stream.read(true, NIL, true,
    428                                                  LispThread.currentThread())));
     430                                                 LispThread.currentThread(),
     431                                                 Stream.currentReadtable)));
    429432        }
    430433    };
  • trunk/abcl/src/org/armedbear/lisp/Load.java

    r12550 r12597  
    547547            while (true) {
    548548                sourcePositionBinding.value = Fixnum.getInstance(in.getOffset());
    549                 LispObject obj = in.read(false, EOF, false, thread);
     549                LispObject obj = in.read(false, EOF, false,
     550                                         thread, Stream.currentReadtable);
    550551                if (obj == EOF)
    551552                    break;
     
    581582            in.setExternalFormat(_FASL_EXTERNAL_FORMAT_.symbolValue(thread));
    582583            while (true) {
    583                 LispObject obj = in.faslRead(false, EOF, true, thread);
     584                LispObject obj = in.read(false, EOF, true, thread, Stream.faslReadtable);
    584585                if (obj == EOF)
    585586                    break;
  • trunk/abcl/src/org/armedbear/lisp/Stream.java

    r12596 r12597  
    425425
    426426    public LispObject read(boolean eofError, LispObject eofValue,
    427                            boolean recursive, LispThread thread)
    428 
     427                           boolean recursive, LispThread thread,
     428                           ReadtableAccessor rta)
    429429    {
    430430        LispObject result = readPreservingWhitespace(eofError, eofValue,
    431                                                      recursive, thread,
    432                                                      currentReadtable);
     431                                                     recursive, thread, rta);
    433432        if (result != eofValue && !recursive) {
    434433            try {
     
    437436                    if (n >= 0) {
    438437                        char c = (char) n; // ### BUG: Codepoint conversion
    439                         Readtable rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
     438                        Readtable rt = rta.rt(thread);
    440439                        if (!rt.isWhitespace(c))
    441440                            _unreadChar(c);
     
    499498    }
    500499
    501     public LispObject faslRead(boolean eofError, LispObject eofValue,
    502                                boolean recursive, LispThread thread)
    503 
    504     {
    505         try {
    506             LispObject result =
    507                     readPreservingWhitespace(eofError, eofValue, recursive,
    508                                              thread, faslReadtable);
    509             if (result != eofValue && !recursive) {
    510                 if (_charReady()) {
    511                     int n = _readChar();
    512                     if (n >= 0) {
    513                         char c = (char) n; // ### BUG: Codepoint conversion
    514                         Readtable rt = FaslReadtable.getInstance();
    515                         if (!rt.isWhitespace(c))
    516                             _unreadChar(c);
    517                     }
    518                 }
    519             }
    520             if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
    521                 return NIL;
    522             else
    523                 return result;
    524         } catch (IOException e) {
    525             return error(new StreamError(this, e));
    526         }
    527     }
    528 
    529500    private final LispObject processChar(char c, Readtable rt)
    530501
     
    538509    }
    539510
    540     public LispObject readPathname() {
    541         LispObject obj = read(true, NIL, false, LispThread.currentThread());
    542         if (obj instanceof AbstractString)
    543             return Pathname.parseNamestring((AbstractString)obj);
    544         if (obj.listp())
    545             return Pathname.makePathname(obj);
    546         return error(new TypeError("#p requires a string or list argument."));
    547     }
    548 
    549     public LispObject faslReadPathname() {
    550         LispObject obj = faslRead(true, NIL, false, LispThread.currentThread());
     511    public LispObject readPathname(ReadtableAccessor rta) {
     512        LispObject obj = read(true, NIL, false,
     513                              LispThread.currentThread(), rta);
    551514        if (obj instanceof AbstractString)
    552515            return Pathname.parseNamestring((AbstractString)obj);
     
    572535    public LispObject readStructure(ReadtableAccessor rta) {
    573536        final LispThread thread = LispThread.currentThread();
    574         LispObject obj = read(true, NIL, true, thread);
     537        LispObject obj = read(true, NIL, true, thread, rta);
    575538        if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
    576539            return NIL;
     
    640603                        }
    641604                        _unreadChar(nextChar);
    642                         LispObject obj = read(true, NIL, true, thread);
     605                        LispObject obj = read(true, NIL, true, thread, rta);
    643606                        if (requireProperList) {
    644607                            if (!obj.listp())
     
    794757    }
    795758
    796     public LispObject readArray(int rank) {
     759    public LispObject readArray(int rank, ReadtableAccessor rta) {
    797760        final LispThread thread = LispThread.currentThread();
    798         LispObject obj = read(true, NIL, true, thread);
     761        LispObject obj = read(true, NIL, true, thread, rta);
    799762        if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
    800763            return NIL;
     
    815778    }
    816779
    817     public LispObject faslReadArray(int rank) {
     780    public LispObject readComplex(ReadtableAccessor rta) {
    818781        final LispThread thread = LispThread.currentThread();
    819         LispObject obj = faslRead(true, NIL, true, thread);
    820         if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
    821             return NIL;
    822         switch (rank) {
    823         case -1:
    824             return error(new ReaderError("No dimensions argument to #A.", this));
    825         case 0:
    826             return new ZeroRankArray(T, obj, false);
    827         case 1: {
    828             if (obj.listp() || obj instanceof AbstractVector)
    829                 return new SimpleVector(obj);
    830             return error(new ReaderError(obj.writeToString() + " is not a sequence.",
    831                                          this));
    832         }
    833         default:
    834             return new SimpleArray_T(rank, obj);
    835         }
    836     }
    837 
    838     public LispObject readComplex() {
    839         final LispThread thread = LispThread.currentThread();
    840         LispObject obj = read(true, NIL, true, thread);
    841         if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
    842             return NIL;
    843         if (obj instanceof Cons && obj.length() == 2)
    844             return Complex.getInstance(obj.car(), obj.cadr());
    845         // Error.
    846         StringBuilder sb = new StringBuilder("Invalid complex number format");
    847         if (this instanceof FileStream) {
    848             Pathname p = ((FileStream)this).getPathname();
    849             if (p != null) {
    850                 String namestring = p.getNamestring();
    851                 if (namestring != null) {
    852                     sb.append(" in #P\"");
    853                     sb.append(namestring);
    854                     sb.append('"');
    855                 }
    856             }
    857             sb.append(" at offset ");
    858             sb.append(_getFilePosition());
    859         }
    860         sb.append(": #C");
    861         sb.append(obj.writeToString());
    862         return error(new ReaderError(sb.toString(), this));
    863     }
    864 
    865     public LispObject faslReadComplex() {
    866         final LispThread thread = LispThread.currentThread();
    867         LispObject obj = faslRead(true, NIL, true, thread);
     782        LispObject obj = read(true, NIL, true, thread, rta);
    868783        if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
    869784            return NIL;
     
    22372152                                                     thread, currentReadtable);
    22382153            else
    2239                 result = in.read(eofError, third, false, thread);
     2154                result = in.read(eofError, third, false, thread, currentReadtable);
    22402155            return thread.setValues(result, Fixnum.getInstance(in.getOffset()));
    22412156        }
     
    22512166            final LispObject obj = Symbol.STANDARD_INPUT.symbolValue(thread);
    22522167            final Stream stream = checkStream(obj);
    2253             return stream.read(true, NIL, false, thread);
     2168            return stream.read(true, NIL, false, thread, currentReadtable);
    22542169        }
    22552170        @Override
     
    22612176                arg = Symbol.STANDARD_INPUT.symbolValue(thread);
    22622177            final Stream stream = checkStream(arg);
    2263             return stream.read(true, NIL, false, thread);
     2178            return stream.read(true, NIL, false, thread, currentReadtable);
    22642179        }
    22652180        @Override
     
    22732188                first = Symbol.STANDARD_INPUT.symbolValue(thread);
    22742189            final Stream stream = checkStream(first);
    2275             return stream.read(second != NIL, NIL, false, thread);
     2190            return stream.read(second != NIL, NIL, false, thread, currentReadtable);
    22762191        }
    22772192        @Override
     
    22862201                first = Symbol.STANDARD_INPUT.symbolValue(thread);
    22872202            final Stream stream = checkStream(first);
    2288             return stream.read(second != NIL, third, false, thread);
     2203            return stream.read(second != NIL, third, false, thread, currentReadtable);
    22892204        }
    22902205        @Override
     
    22992214                first = Symbol.STANDARD_INPUT.symbolValue(thread);
    23002215            final Stream stream = checkStream(first);
    2301             return stream.read(second != NIL, third, fourth != NIL, thread);
     2216            return stream.read(second != NIL, third, fourth != NIL,
     2217                               thread, currentReadtable);
    23022218        }
    23032219    };
  • trunk/abcl/test/src/org/armedbear/lisp/StreamTest.java

    r12424 r12597  
    2525    Pathname pathname = Pathname.makePathname(file);
    2626    Stream in = new Stream(Symbol.SYSTEM_STREAM, pathname.getInputStream(), Symbol.CHARACTER);
    27     LispObject o = in.read(false, Lisp.EOF, false, LispThread.currentThread());
     27    LispObject o = in.read(false, Lisp.EOF, false,
     28                           LispThread.currentThread(), Stream.currentReadtable);
    2829    assertFalse(o.equals(Lisp.NIL));
    2930    in._close();
Note: See TracChangeset for help on using the changeset viewer.