[armedbear-cvs] r12592 - trunk/abcl/src/org/armedbear/lisp
Erik Huelsmann
ehuelsmann at common-lisp.net
Sat Apr 10 19:55:27 UTC 2010
Author: ehuelsmann
Date: Sat Apr 10 15:55:26 2010
New Revision: 12592
Log:
Consolidate the functionality of faslReadStructure and readStructure
and fix the fact that FaslReader should have used faslReadStructure
all the time. It does now.
Modified:
trunk/abcl/src/org/armedbear/lisp/FaslReader.java
trunk/abcl/src/org/armedbear/lisp/LispReader.java
trunk/abcl/src/org/armedbear/lisp/Stream.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 15:55:26 2010
@@ -366,7 +366,7 @@
public LispObject execute(Stream stream, char c, int n)
{
- return stream.readStructure();
+ return stream.readStructure(Stream.faslReadtable);
}
};
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 15:55:26 2010
@@ -397,7 +397,7 @@
public LispObject execute(Stream stream, char c, int n)
{
- return stream.readStructure();
+ return stream.readStructure(Stream.currentReadtable);
}
};
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 15:55:26 2010
@@ -389,6 +389,42 @@
charPos = n;
}
+ /** Class to abstract readtable access
+ *
+ * Many of the functions below (used to) exist in 2 variants.
+ * One with hardcoded access to the FaslReadtable, the other
+ * with hardcoded access to the *readtable* variable.
+ *
+ * In order to prevent code duplication,
+ * this class abstracts access.
+ */
+ public static abstract class ReadtableAccessor {
+ /** Given the thread passed, return the applicable readtable. */
+ public abstract Readtable rt(LispThread thread);
+ }
+
+ /** pre-instantiated readtable accessor for the *readtable*. */
+ public static ReadtableAccessor currentReadtable
+ = new ReadtableAccessor()
+ {
+ public Readtable rt(LispThread thread)
+ {
+ return
+ (Readtable)Symbol.CURRENT_READTABLE.symbolValue(thread);
+ }
+ };
+
+ /** pre-instantiated readtable accessor for the fasl readtable. */
+ public static ReadtableAccessor faslReadtable
+ = new ReadtableAccessor()
+ {
+ public Readtable rt(LispThread thread)
+ {
+ return FaslReadtable.getInstance();
+ }
+ };
+
+
public LispObject read(boolean eofError, LispObject eofValue,
boolean recursive, LispThread thread)
@@ -564,7 +600,7 @@
return new Symbol(sb.toString());
}
- public LispObject readStructure() {
+ public LispObject readStructure(ReadtableAccessor rta) {
final LispThread thread = LispThread.currentThread();
LispObject obj = read(true, NIL, true, thread);
if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
@@ -606,48 +642,6 @@
this));
}
- public LispObject faslReadStructure() {
- final LispThread thread = LispThread.currentThread();
- LispObject obj = faslRead(true, NIL, true, thread);
- if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
- return NIL;
- if (obj.listp()) {
- Symbol structure = checkSymbol(obj.car());
- LispClass c = LispClass.findClass(structure);
- if (!(c instanceof StructureClass))
- return error(new ReaderError(structure.getName() +
- " is not a defined structure type.",
- this));
- LispObject args = obj.cdr();
- Symbol DEFSTRUCT_DEFAULT_CONSTRUCTOR =
- PACKAGE_SYS.intern("DEFSTRUCT-DEFAULT-CONSTRUCTOR");
- LispObject constructor =
- DEFSTRUCT_DEFAULT_CONSTRUCTOR.getSymbolFunctionOrDie().execute(structure);
- final int length = args.length();
- if ((length % 2) != 0)
- return error(new ReaderError("Odd number of keyword arguments following #S: " +
- obj.writeToString(),
- this));
- LispObject[] array = new LispObject[length];
- LispObject rest = args;
- for (int i = 0; i < length; i += 2) {
- LispObject key = rest.car();
- if (key instanceof Symbol && ((Symbol)key).getPackage() == PACKAGE_KEYWORD) {
- array[i] = key;
- } else {
- array[i] = PACKAGE_KEYWORD.intern(javaString(key));
- }
- array[i + 1] = rest.cadr();
- rest = rest.cddr();
- }
- return funcall(constructor.getSymbolFunctionOrDie(), array,
- thread);
- }
- return error(new ReaderError("Non-list following #S: " +
- obj.writeToString(),
- this));
- }
-
public LispObject readList(boolean requireProperList, boolean useFaslReadtable)
{
More information about the armedbear-cvs
mailing list