Changeset 12592
- Timestamp:
- 04/10/10 19:55:26 (13 years ago)
- Location:
- trunk/abcl/src/org/armedbear/lisp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/FaslReader.java
r12591 r12592 367 367 368 368 { 369 return stream.readStructure( );369 return stream.readStructure(Stream.faslReadtable); 370 370 } 371 371 }; -
trunk/abcl/src/org/armedbear/lisp/LispReader.java
r12431 r12592 398 398 399 399 { 400 return stream.readStructure( );400 return stream.readStructure(Stream.currentReadtable); 401 401 } 402 402 }; -
trunk/abcl/src/org/armedbear/lisp/Stream.java
r12559 r12592 390 390 } 391 391 392 /** Class to abstract readtable access 393 * 394 * Many of the functions below (used to) exist in 2 variants. 395 * One with hardcoded access to the FaslReadtable, the other 396 * with hardcoded access to the *readtable* variable. 397 * 398 * In order to prevent code duplication, 399 * this class abstracts access. 400 */ 401 public static abstract class ReadtableAccessor { 402 /** Given the thread passed, return the applicable readtable. */ 403 public abstract Readtable rt(LispThread thread); 404 } 405 406 /** pre-instantiated readtable accessor for the *readtable*. */ 407 public static ReadtableAccessor currentReadtable 408 = new ReadtableAccessor() 409 { 410 public Readtable rt(LispThread thread) 411 { 412 return 413 (Readtable)Symbol.CURRENT_READTABLE.symbolValue(thread); 414 } 415 }; 416 417 /** pre-instantiated readtable accessor for the fasl readtable. */ 418 public static ReadtableAccessor faslReadtable 419 = new ReadtableAccessor() 420 { 421 public Readtable rt(LispThread thread) 422 { 423 return FaslReadtable.getInstance(); 424 } 425 }; 426 427 392 428 public LispObject read(boolean eofError, LispObject eofValue, 393 429 boolean recursive, LispThread thread) … … 565 601 } 566 602 567 public LispObject readStructure( ) {603 public LispObject readStructure(ReadtableAccessor rta) { 568 604 final LispThread thread = LispThread.currentThread(); 569 605 LispObject obj = read(true, NIL, true, thread); 570 if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)571 return NIL;572 if (obj.listp()) {573 Symbol structure = checkSymbol(obj.car());574 LispClass c = LispClass.findClass(structure);575 if (!(c instanceof StructureClass))576 return error(new ReaderError(structure.getName() +577 " is not a defined structure type.",578 this));579 LispObject args = obj.cdr();580 Symbol DEFSTRUCT_DEFAULT_CONSTRUCTOR =581 PACKAGE_SYS.intern("DEFSTRUCT-DEFAULT-CONSTRUCTOR");582 LispObject constructor =583 DEFSTRUCT_DEFAULT_CONSTRUCTOR.getSymbolFunctionOrDie().execute(structure);584 final int length = args.length();585 if ((length % 2) != 0)586 return error(new ReaderError("Odd number of keyword arguments following #S: " +587 obj.writeToString(),588 this));589 LispObject[] array = new LispObject[length];590 LispObject rest = args;591 for (int i = 0; i < length; i += 2) {592 LispObject key = rest.car();593 if (key instanceof Symbol && ((Symbol)key).getPackage() == PACKAGE_KEYWORD) {594 array[i] = key;595 } else {596 array[i] = PACKAGE_KEYWORD.intern(javaString(key));597 }598 array[i + 1] = rest.cadr();599 rest = rest.cddr();600 }601 return funcall(constructor.getSymbolFunctionOrDie(), array,602 thread);603 }604 return error(new ReaderError("Non-list following #S: " +605 obj.writeToString(),606 this));607 }608 609 public LispObject faslReadStructure() {610 final LispThread thread = LispThread.currentThread();611 LispObject obj = faslRead(true, NIL, true, thread);612 606 if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL) 613 607 return NIL;
Note: See TracChangeset
for help on using the changeset viewer.