Changeset 12592


Ignore:
Timestamp:
04/10/10 19:55:26 (11 years ago)
Author:
ehuelsmann
Message:

Consolidate the functionality of faslReadStructure and readStructure
and fix the fact that FaslReader? should have used faslReadStructure
all the time. It does now.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
3 edited

Legend:

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

    r12591 r12592  
    367367
    368368        {
    369             return stream.readStructure();
     369            return stream.readStructure(Stream.faslReadtable);
    370370        }
    371371    };
  • trunk/abcl/src/org/armedbear/lisp/LispReader.java

    r12431 r12592  
    398398
    399399        {
    400             return stream.readStructure();
     400            return stream.readStructure(Stream.currentReadtable);
    401401        }
    402402    };
  • trunk/abcl/src/org/armedbear/lisp/Stream.java

    r12559 r12592  
    390390    }
    391391
     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
    392428    public LispObject read(boolean eofError, LispObject eofValue,
    393429                           boolean recursive, LispThread thread)
     
    565601    }
    566602
    567     public LispObject readStructure() {
     603    public LispObject readStructure(ReadtableAccessor rta) {
    568604        final LispThread thread = LispThread.currentThread();
    569605        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);
    612606        if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
    613607            return NIL;
Note: See TracChangeset for help on using the changeset viewer.