Changeset 12597
- Timestamp:
- 04/10/10 21:00:21 (14 years ago)
- Location:
- trunk/abcl
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/FaslReader.java
r12594 r12597 126 126 { 127 127 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))); 130 131 } 131 132 }; … … 256 257 stream)); 257 258 else 258 return eval(stream.faslRead(true, NIL, true, thread), 259 return eval(stream.read(true, NIL, true, thread, 260 Stream.faslReadtable), 259 261 new Environment(), thread); 260 262 } … … 289 291 290 292 { 291 return stream. faslReadArray(n);293 return stream.readArray(n, Stream.faslReadtable); 292 294 } 293 295 }; … … 315 317 316 318 { 317 return stream. faslReadComplex();319 return stream.readComplex(Stream.faslReadtable); 318 320 } 319 321 }; … … 341 343 342 344 { 343 return stream. faslReadPathname();345 return stream.readPathname(Stream.faslReadtable); 344 346 } 345 347 }; … … 394 396 { 395 397 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))); 398 401 } 399 402 }; -
trunk/abcl/src/org/armedbear/lisp/Interpreter.java
r12546 r12597 150 150 { 151 151 return Lisp.eval(new StringInputStream(s).read(true, NIL, false, 152 LispThread.currentThread())); 152 LispThread.currentThread(), 153 Stream.currentReadtable)); 153 154 } 154 155 … … 329 330 out._finishOutput(); 330 331 LispObject object = 331 getStandardInput().read(false, EOF, false, thread); 332 getStandardInput().read(false, EOF, false, thread, 333 Stream.currentReadtable); 332 334 if (object == EOF) 333 335 break; … … 500 502 { 501 503 return new StringInputStream(s).read(true, NIL, false, 502 LispThread.currentThread()); 504 LispThread.currentThread(), 505 Stream.currentReadtable); 503 506 } 504 507 … … 517 520 StringInputStream stream = new StringInputStream(s); 518 521 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); 520 524 if (obj == EOF) 521 525 return error(new EndOfFile(stream)); -
trunk/abcl/src/org/armedbear/lisp/LispReader.java
r12594 r12597 167 167 return new Cons(Symbol.QUOTE, 168 168 new Cons(stream.read(true, NIL, true, 169 LispThread.currentThread()))); 169 LispThread.currentThread(), 170 Stream.currentReadtable))); 170 171 } 171 172 }; … … 293 294 stream)); 294 295 else 295 return eval(stream.read(true, NIL, true, thread), 296 return eval(stream.read(true, NIL, true, 297 thread, Stream.currentReadtable), 296 298 new Environment(), thread); 297 299 } … … 320 322 321 323 { 322 return stream.readArray(n );324 return stream.readArray(n, Stream.currentReadtable); 323 325 } 324 326 }; … … 346 348 347 349 { 348 return stream.readComplex( );350 return stream.readComplex(Stream.currentReadtable); 349 351 } 350 352 }; … … 372 374 373 375 { 374 return stream.readPathname( );376 return stream.readPathname(Stream.currentReadtable); 375 377 } 376 378 }; … … 426 428 return new Cons(Symbol.FUNCTION, 427 429 new Cons(stream.read(true, NIL, true, 428 LispThread.currentThread()))); 430 LispThread.currentThread(), 431 Stream.currentReadtable))); 429 432 } 430 433 }; -
trunk/abcl/src/org/armedbear/lisp/Load.java
r12550 r12597 547 547 while (true) { 548 548 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); 550 551 if (obj == EOF) 551 552 break; … … 581 582 in.setExternalFormat(_FASL_EXTERNAL_FORMAT_.symbolValue(thread)); 582 583 while (true) { 583 LispObject obj = in. faslRead(false, EOF, true, thread);584 LispObject obj = in.read(false, EOF, true, thread, Stream.faslReadtable); 584 585 if (obj == EOF) 585 586 break; -
trunk/abcl/src/org/armedbear/lisp/Stream.java
r12596 r12597 425 425 426 426 public LispObject read(boolean eofError, LispObject eofValue, 427 boolean recursive, LispThread thread )428 427 boolean recursive, LispThread thread, 428 ReadtableAccessor rta) 429 429 { 430 430 LispObject result = readPreservingWhitespace(eofError, eofValue, 431 recursive, thread, 432 currentReadtable); 431 recursive, thread, rta); 433 432 if (result != eofValue && !recursive) { 434 433 try { … … 437 436 if (n >= 0) { 438 437 char c = (char) n; // ### BUG: Codepoint conversion 439 Readtable rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);438 Readtable rt = rta.rt(thread); 440 439 if (!rt.isWhitespace(c)) 441 440 _unreadChar(c); … … 499 498 } 500 499 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 conversion514 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 else523 return result;524 } catch (IOException e) {525 return error(new StreamError(this, e));526 }527 }528 529 500 private final LispObject processChar(char c, Readtable rt) 530 501 … … 538 509 } 539 510 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); 551 514 if (obj instanceof AbstractString) 552 515 return Pathname.parseNamestring((AbstractString)obj); … … 572 535 public LispObject readStructure(ReadtableAccessor rta) { 573 536 final LispThread thread = LispThread.currentThread(); 574 LispObject obj = read(true, NIL, true, thread );537 LispObject obj = read(true, NIL, true, thread, rta); 575 538 if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL) 576 539 return NIL; … … 640 603 } 641 604 _unreadChar(nextChar); 642 LispObject obj = read(true, NIL, true, thread );605 LispObject obj = read(true, NIL, true, thread, rta); 643 606 if (requireProperList) { 644 607 if (!obj.listp()) … … 794 757 } 795 758 796 public LispObject readArray(int rank ) {759 public LispObject readArray(int rank, ReadtableAccessor rta) { 797 760 final LispThread thread = LispThread.currentThread(); 798 LispObject obj = read(true, NIL, true, thread );761 LispObject obj = read(true, NIL, true, thread, rta); 799 762 if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL) 800 763 return NIL; … … 815 778 } 816 779 817 public LispObject faslReadArray(int rank) {780 public LispObject readComplex(ReadtableAccessor rta) { 818 781 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); 868 783 if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL) 869 784 return NIL; … … 2237 2152 thread, currentReadtable); 2238 2153 else 2239 result = in.read(eofError, third, false, thread );2154 result = in.read(eofError, third, false, thread, currentReadtable); 2240 2155 return thread.setValues(result, Fixnum.getInstance(in.getOffset())); 2241 2156 } … … 2251 2166 final LispObject obj = Symbol.STANDARD_INPUT.symbolValue(thread); 2252 2167 final Stream stream = checkStream(obj); 2253 return stream.read(true, NIL, false, thread );2168 return stream.read(true, NIL, false, thread, currentReadtable); 2254 2169 } 2255 2170 @Override … … 2261 2176 arg = Symbol.STANDARD_INPUT.symbolValue(thread); 2262 2177 final Stream stream = checkStream(arg); 2263 return stream.read(true, NIL, false, thread );2178 return stream.read(true, NIL, false, thread, currentReadtable); 2264 2179 } 2265 2180 @Override … … 2273 2188 first = Symbol.STANDARD_INPUT.symbolValue(thread); 2274 2189 final Stream stream = checkStream(first); 2275 return stream.read(second != NIL, NIL, false, thread );2190 return stream.read(second != NIL, NIL, false, thread, currentReadtable); 2276 2191 } 2277 2192 @Override … … 2286 2201 first = Symbol.STANDARD_INPUT.symbolValue(thread); 2287 2202 final Stream stream = checkStream(first); 2288 return stream.read(second != NIL, third, false, thread );2203 return stream.read(second != NIL, third, false, thread, currentReadtable); 2289 2204 } 2290 2205 @Override … … 2299 2214 first = Symbol.STANDARD_INPUT.symbolValue(thread); 2300 2215 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); 2302 2218 } 2303 2219 }; -
trunk/abcl/test/src/org/armedbear/lisp/StreamTest.java
r12424 r12597 25 25 Pathname pathname = Pathname.makePathname(file); 26 26 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); 28 29 assertFalse(o.equals(Lisp.NIL)); 29 30 in._close();
Note: See TracChangeset
for help on using the changeset viewer.