[armedbear-cvs] r12713 - trunk/abcl/src/org/armedbear/lisp

Alessio Stalla astalla at common-lisp.net
Thu May 20 17:58:14 UTC 2010


Author: astalla
Date: Thu May 20 13:58:13 2010
New Revision: 12713

Log:
Serialization support for some Lisp types.
For symbols and packages, only the "identity" is serialized, i.e. package name + symbol name.
For packages, it is expected that a package of the same name exists "at the other side".
For symbols, the deserialized symbol is interned in its home package.


Modified:
   trunk/abcl/src/org/armedbear/lisp/AbstractArray.java
   trunk/abcl/src/org/armedbear/lisp/Cons.java
   trunk/abcl/src/org/armedbear/lisp/LispInteger.java
   trunk/abcl/src/org/armedbear/lisp/Nil.java
   trunk/abcl/src/org/armedbear/lisp/Package.java
   trunk/abcl/src/org/armedbear/lisp/Symbol.java

Modified: trunk/abcl/src/org/armedbear/lisp/AbstractArray.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/AbstractArray.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/AbstractArray.java	Thu May 20 13:58:13 2010
@@ -35,7 +35,7 @@
 
 import static org.armedbear.lisp.Lisp.*;
 
-public abstract class AbstractArray extends LispObject
+public abstract class AbstractArray extends LispObject implements java.io.Serializable
 {
     @Override
     public LispObject typep(LispObject type)

Modified: trunk/abcl/src/org/armedbear/lisp/Cons.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Cons.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Cons.java	Thu May 20 13:58:13 2010
@@ -35,7 +35,7 @@
 
 import static org.armedbear.lisp.Lisp.*;
 
-public final class Cons extends LispObject
+public final class Cons extends LispObject implements java.io.Serializable
 {
   public LispObject car;
   public LispObject cdr;

Modified: trunk/abcl/src/org/armedbear/lisp/LispInteger.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/LispInteger.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/LispInteger.java	Thu May 20 13:58:13 2010
@@ -36,7 +36,7 @@
 /** This class merely serves as the super class for
  * Fixnum and Bignum
  */
-public class LispInteger extends LispObject
+public class LispInteger extends LispObject implements java.io.Serializable
 {
 
   public static LispInteger getInstance(long l) {

Modified: trunk/abcl/src/org/armedbear/lisp/Nil.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Nil.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Nil.java	Thu May 20 13:58:13 2010
@@ -164,4 +164,9 @@
             return "|COMMON-LISP|::|NIL|";
         return "NIL";
     }
+
+    public Object readResolve() throws java.io.ObjectStreamException {
+       return NIL;
+    }
+
 }

Modified: trunk/abcl/src/org/armedbear/lisp/Package.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Package.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Package.java	Thu May 20 13:58:13 2010
@@ -40,20 +40,20 @@
 import java.util.Iterator;
 import java.util.List;
 
-public final class Package extends LispObject
+public final class Package extends LispObject implements java.io.Serializable
 {
     private String name;
-    private SimpleString lispName;
+    private transient SimpleString lispName;
 
-    private LispObject propertyList;
+    private transient LispObject propertyList;
 
-    private final SymbolHashTable internalSymbols = new SymbolHashTable(16);
-    private final SymbolHashTable externalSymbols = new SymbolHashTable(16);
+    private transient final SymbolHashTable internalSymbols = new SymbolHashTable(16);
+    private transient final SymbolHashTable externalSymbols = new SymbolHashTable(16);
 
-    private HashMap<String,Symbol> shadowingSymbols;
-    private ArrayList<String> nicknames;
-    private LispObject useList = null;
-    private ArrayList<Package> usedByList = null;
+    private transient HashMap<String,Symbol> shadowingSymbols;
+    private transient ArrayList<String> nicknames;
+    private transient LispObject useList = null;
+    private transient ArrayList<Package> usedByList = null;
 
     // Anonymous package.
     public Package()
@@ -848,4 +848,13 @@
         } else
             return unreadableString("PACKAGE");
     }
+
+    public Object readResolve() throws java.io.ObjectStreamException {
+	Package pkg = Packages.findPackage(name);
+	if(pkg != null) {
+	    return pkg;
+	} else {
+	    return error(new PackageError(name + " is not the name of a package."));
+	}
+    }
 }

Modified: trunk/abcl/src/org/armedbear/lisp/Symbol.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Symbol.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Symbol.java	Thu May 20 13:58:13 2010
@@ -35,7 +35,7 @@
 
 import static org.armedbear.lisp.Lisp.*;
 
-public class Symbol extends LispObject
+public class Symbol extends LispObject implements java.io.Serializable
 {
   // Bit flags.
   private static final int FLAG_SPECIAL           = 0x0001;
@@ -55,11 +55,11 @@
   /** To be accessed by LispThread only:
    * used to find the index in the LispThread.specials array
    */
-  int specialIndex = LispThread.UNASSIGNED_SPECIAL_INDEX;
+  transient int specialIndex = LispThread.UNASSIGNED_SPECIAL_INDEX;
   private LispObject pkg; // Either a package object or NIL.
-  private LispObject value;
-  private LispObject function;
-  private LispObject propertyList;
+  private transient LispObject value;
+  private transient LispObject function;
+  private transient LispObject propertyList;
   private int flags;
 
   // Construct an uninterned symbol.
@@ -908,6 +908,15 @@
       function.incrementHotCount();
   }
 
+    public Object readResolve() throws java.io.ObjectStreamException {
+	if(pkg instanceof Package) {
+	    Symbol s = ((Package) pkg).intern(name.getStringValue());
+	    return s;
+	} else {
+	    return this;
+	}
+    }
+
 
   // External symbols in CL package.
   public static final Symbol AND_ALLOW_OTHER_KEYS =




More information about the armedbear-cvs mailing list