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

Erik Huelsmann ehuelsmann at common-lisp.net
Thu Jan 15 23:19:36 UTC 2009


Author: ehuelsmann
Date: Thu Jan 15 23:19:35 2009
New Revision: 11557

Log:
Fix ticket #28: Expressly adjustable array not adjustable.

Renames adjustVector() to adjustArray() and implements adjustArray() on arrays.

Note: This is not the nicest solution; it removes 'private' modifiers, however,
  given the size of the commit, it seems like an issue to be resolved in a later
  cleanup of the Array vs Vector code.

Modified:
   trunk/abcl/src/org/armedbear/lisp/AbstractArray.java
   trunk/abcl/src/org/armedbear/lisp/AbstractVector.java
   trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte16.java
   trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte32.java
   trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte8.java
   trunk/abcl/src/org/armedbear/lisp/ComplexArray.java
   trunk/abcl/src/org/armedbear/lisp/ComplexArray_UnsignedByte32.java
   trunk/abcl/src/org/armedbear/lisp/ComplexArray_UnsignedByte8.java
   trunk/abcl/src/org/armedbear/lisp/ComplexBitVector.java
   trunk/abcl/src/org/armedbear/lisp/ComplexString.java
   trunk/abcl/src/org/armedbear/lisp/ComplexVector.java
   trunk/abcl/src/org/armedbear/lisp/ComplexVector_UnsignedByte32.java
   trunk/abcl/src/org/armedbear/lisp/ComplexVector_UnsignedByte8.java
   trunk/abcl/src/org/armedbear/lisp/NilVector.java
   trunk/abcl/src/org/armedbear/lisp/SimpleArray_T.java
   trunk/abcl/src/org/armedbear/lisp/SimpleArray_UnsignedByte32.java
   trunk/abcl/src/org/armedbear/lisp/SimpleArray_UnsignedByte8.java
   trunk/abcl/src/org/armedbear/lisp/SimpleBitVector.java
   trunk/abcl/src/org/armedbear/lisp/SimpleString.java
   trunk/abcl/src/org/armedbear/lisp/SimpleVector.java
   trunk/abcl/src/org/armedbear/lisp/ZeroRankArray.java
   trunk/abcl/src/org/armedbear/lisp/adjust_array.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 Jan 15 23:19:35 2009
@@ -86,6 +86,16 @@
         return -1; // Not reached.
     }
 
+    public void setFillPointer(LispObject fillPointer) throws ConditionThrowable
+    {
+        setFillPointer(fillPointer.intValue());
+    }
+
+    public void setFillPointer(int fillPointer) throws ConditionThrowable
+    {
+        noFillPointer();
+    }
+
     public boolean isAdjustable()
     {
         return true;
@@ -211,7 +221,7 @@
         sb.append('(');
         if (this instanceof SimpleArray_T)
             sb.append("SIMPLE-");
-        sb.append("ARRAY T (");
+        sb.append("ARRAY " + getElementType().writeToString() + " (");
         for (int i = 0; i < dimv.length; i++) {
             sb.append(dimv[i]);
             if (i < dimv.length - 1)
@@ -305,4 +315,14 @@
             return 0;
         }
     }
+
+  public abstract AbstractArray adjustArray(int[] dims,
+                                              LispObject initialElement,
+                                              LispObject initialContents)
+    throws ConditionThrowable;
+
+  public abstract AbstractArray adjustArray(int[] dims,
+                                              AbstractArray displacedTo,
+                                              int displacement)
+    throws ConditionThrowable;
 }

Modified: trunk/abcl/src/org/armedbear/lisp/AbstractVector.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/AbstractVector.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/AbstractVector.java	Thu Jan 15 23:19:35 2009
@@ -297,13 +297,27 @@
       }
   }
 
-  public abstract AbstractVector adjustVector(int size,
+  public abstract AbstractArray adjustArray(int size,
                                               LispObject initialElement,
                                               LispObject initialContents)
     throws ConditionThrowable;
-
-  public abstract AbstractVector adjustVector(int size,
+  public abstract AbstractArray adjustArray(int size,
                                               AbstractArray displacedTo,
                                               int displacement)
     throws ConditionThrowable;
+
+
+  public AbstractArray adjustArray(int[] dims,
+                                              LispObject initialElement,
+                                              LispObject initialContents)
+    throws ConditionThrowable {
+      return adjustArray(dims[0], initialElement, initialContents);
+  }
+
+  public AbstractArray adjustArray(int[] dims,
+                                              AbstractArray displacedTo,
+                                              int displacement)
+    throws ConditionThrowable {
+      return adjustArray(dims[0], displacedTo, displacement);
+  }
 }

Modified: trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte16.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte16.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte16.java	Thu Jan 15 23:19:35 2009
@@ -258,7 +258,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        LispObject initialElement,
                                        LispObject initialContents)
         throws ConditionThrowable
@@ -291,7 +291,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        AbstractArray displacedTo,
                                        int displacement)
     {

Modified: trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte32.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte32.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte32.java	Thu Jan 15 23:19:35 2009
@@ -270,7 +270,7 @@
   }
 
   @Override
-  public AbstractVector adjustVector(int newCapacity,
+  public AbstractVector adjustArray(int newCapacity,
                                      LispObject initialElement,
                                      LispObject initialContents)
     throws ConditionThrowable
@@ -310,7 +310,7 @@
   }
 
   @Override
-  public AbstractVector adjustVector(int newCapacity,
+  public AbstractVector adjustArray(int newCapacity,
                                      AbstractArray displacedTo,
                                      int displacement)
   {

Modified: trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte8.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte8.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/BasicVector_UnsignedByte8.java	Thu Jan 15 23:19:35 2009
@@ -268,7 +268,7 @@
   }
 
   @Override
-  public AbstractVector adjustVector(int newCapacity,
+  public AbstractVector adjustArray(int newCapacity,
                                      LispObject initialElement,
                                      LispObject initialContents)
     throws ConditionThrowable
@@ -308,7 +308,7 @@
   }
 
   @Override
-  public AbstractVector adjustVector(int newCapacity,
+  public AbstractVector adjustArray(int newCapacity,
                                      AbstractArray displacedTo,
                                      int displacement)
   {

Modified: trunk/abcl/src/org/armedbear/lisp/ComplexArray.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ComplexArray.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ComplexArray.java	Thu Jan 15 23:19:35 2009
@@ -37,7 +37,7 @@
 {
     private final int[] dimv;
     private final LispObject elementType;
-    private final int totalSize;
+    private int totalSize;
 
     // For non-displaced arrays.
     private LispObject[] data;
@@ -235,4 +235,57 @@
     {
         return writeToString(dimv);
     }
+
+    @Override
+    public AbstractArray adjustArray(int[] dims,
+                                              LispObject initialElement,
+                                              LispObject initialContents)
+            throws ConditionThrowable {
+        if (isAdjustable()) {
+            if (initialContents != NIL)
+                setInitialContents(0, dims, initialContents, 0);
+            else {
+                //### FIXME Take the easy way out: we don't want to reorganize
+                // all of the array code yet
+                SimpleArray_T tempArray = new SimpleArray_T(dims, elementType);
+                tempArray.fill(initialElement);
+                SimpleArray_T.copyArray(this, tempArray);
+                this.data = tempArray.data;
+
+                for (int i = 0; i < dims.length; i++)
+                    dimv[i] = dims[i];
+            }
+            return this;
+        } else {
+            if (initialContents != NIL)
+                return new ComplexArray(dims, elementType, initialContents);
+            else {
+                ComplexArray newArray = new ComplexArray(dims, elementType);
+                newArray.fill(initialElement);
+                return newArray;
+            }
+        }
+    }
+
+    @Override
+    public AbstractArray adjustArray(int[] dims,
+                                              AbstractArray displacedTo,
+                                              int displacement)
+            throws ConditionThrowable {
+        if (isAdjustable()) {
+            for (int i = 0; i < dims.length; i++)
+                dimv[i] = dims[i];
+
+            this.data = null;
+            this.array = displacedTo;
+            this.displacement = displacement;
+            this.totalSize = computeTotalSize(dims);
+
+            return this;
+        } else {
+            ComplexArray a = new ComplexArray(dims, displacedTo, displacement);
+            
+            return a;
+        }
+    }
 }

Modified: trunk/abcl/src/org/armedbear/lisp/ComplexArray_UnsignedByte32.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ComplexArray_UnsignedByte32.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ComplexArray_UnsignedByte32.java	Thu Jan 15 23:19:35 2009
@@ -36,7 +36,7 @@
 public final class ComplexArray_UnsignedByte32 extends AbstractArray
 {
     private final int[] dimv;
-    private final int totalSize;
+    private int totalSize;
 
     // For non-displaced arrays.
     // FIXME We should really use an array of unboxed values!
@@ -231,4 +231,58 @@
     {
         return writeToString(dimv);
     }
+
+
+    @Override
+    public AbstractArray adjustArray(int[] dims,
+                                              LispObject initialElement,
+                                              LispObject initialContents)
+            throws ConditionThrowable {
+        if (isAdjustable()) {
+            if (initialContents != NIL)
+                setInitialContents(0, dims, initialContents, 0);
+            else {
+                //### FIXME Take the easy way out: we don't want to reorganize
+                // all of the array code yet
+                SimpleArray_UnsignedByte32 tempArray = new SimpleArray_UnsignedByte32(dims, getElementType());
+                tempArray.fill(initialElement);
+                SimpleArray_UnsignedByte32.copyArray(this, tempArray);
+                this.data = tempArray.data;
+
+                for (int i = 0; i < dims.length; i++)
+                    dimv[i] = dims[i];
+            }
+            return this;
+        } else {
+            if (initialContents != NIL)
+                return new ComplexArray_UnsignedByte32(dims, initialContents);
+            else {
+                ComplexArray_UnsignedByte32 newArray = new ComplexArray_UnsignedByte32(dims);
+                newArray.fill(initialElement);
+                return newArray;
+            }
+        }
+    }
+
+    @Override
+    public AbstractArray adjustArray(int[] dims,
+                                              AbstractArray displacedTo,
+                                              int displacement)
+            throws ConditionThrowable {
+        if (isAdjustable()) {
+            for (int i = 0; i < dims.length; i++)
+                dimv[i] = dims[i];
+
+            this.data = null;
+            this.array = displacedTo;
+            this.displacement = displacement;
+            this.totalSize = computeTotalSize(dims);
+
+            return this;
+        } else {
+            ComplexArray_UnsignedByte32 a = new ComplexArray_UnsignedByte32(dims, displacedTo, displacement);
+
+            return a;
+        }
+    }
 }

Modified: trunk/abcl/src/org/armedbear/lisp/ComplexArray_UnsignedByte8.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ComplexArray_UnsignedByte8.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ComplexArray_UnsignedByte8.java	Thu Jan 15 23:19:35 2009
@@ -36,7 +36,7 @@
 public final class ComplexArray_UnsignedByte8 extends AbstractArray
 {
     private final int[] dimv;
-    private final int totalSize;
+    private int totalSize;
 
     // For non-displaced arrays.
     private byte[] data;
@@ -233,4 +233,58 @@
         }
         return writeToString(dimv);
     }
+
+
+    @Override
+    public AbstractArray adjustArray(int[] dims,
+                                              LispObject initialElement,
+                                              LispObject initialContents)
+            throws ConditionThrowable {
+        if (isAdjustable()) {
+            if (initialContents != NIL)
+                setInitialContents(0, dims, initialContents, 0);
+            else {
+                //### FIXME Take the easy way out: we don't want to reorganize
+                // all of the array code yet
+                SimpleArray_UnsignedByte8 tempArray = new SimpleArray_UnsignedByte8(dims, getElementType());
+                tempArray.fill(initialElement);
+                SimpleArray_UnsignedByte8.copyArray(this, tempArray);
+                this.data = tempArray.data;
+
+                for (int i = 0; i < dims.length; i++)
+                    dimv[i] = dims[i];
+            }
+            return this;
+        } else {
+            if (initialContents != NIL)
+                return new ComplexArray_UnsignedByte8(dims, initialContents);
+            else {
+                ComplexArray_UnsignedByte8 newArray = new ComplexArray_UnsignedByte8(dims);
+                newArray.fill(initialElement);
+                return newArray;
+            }
+        }
+    }
+
+    @Override
+    public AbstractArray adjustArray(int[] dims,
+                                              AbstractArray displacedTo,
+                                              int displacement)
+            throws ConditionThrowable {
+        if (isAdjustable()) {
+            for (int i = 0; i < dims.length; i++)
+                dimv[i] = dims[i];
+
+            this.data = null;
+            this.array = displacedTo;
+            this.displacement = displacement;
+            this.totalSize = computeTotalSize(dims);
+
+            return this;
+        } else {
+            ComplexArray_UnsignedByte8 a = new ComplexArray_UnsignedByte8(dims, displacedTo, displacement);
+
+            return a;
+        }
+    }
 }

Modified: trunk/abcl/src/org/armedbear/lisp/ComplexBitVector.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ComplexBitVector.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ComplexBitVector.java	Thu Jan 15 23:19:35 2009
@@ -319,7 +319,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        LispObject initialElement,
                                        LispObject initialContents)
         throws ConditionThrowable
@@ -380,7 +380,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int size, AbstractArray displacedTo,
+    public AbstractVector adjustArray(int size, AbstractArray displacedTo,
                                        int displacement)
         throws ConditionThrowable
     {

Modified: trunk/abcl/src/org/armedbear/lisp/ComplexString.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ComplexString.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ComplexString.java	Thu Jan 15 23:19:35 2009
@@ -597,7 +597,7 @@
   }
 
   @Override
-  public AbstractVector adjustVector(int newCapacity,
+  public AbstractVector adjustArray(int newCapacity,
                                      LispObject initialElement,
                                      LispObject initialContents)
     throws ConditionThrowable
@@ -674,7 +674,7 @@
   }
 
   @Override
-  public AbstractVector adjustVector(int newCapacity,
+  public AbstractVector adjustArray(int newCapacity,
                                      AbstractArray displacedTo,
                                      int displacement)
     throws ConditionThrowable

Modified: trunk/abcl/src/org/armedbear/lisp/ComplexVector.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ComplexVector.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ComplexVector.java	Thu Jan 15 23:19:35 2009
@@ -365,7 +365,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        LispObject initialElement,
                                        LispObject initialContents)
         throws ConditionThrowable
@@ -412,7 +412,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        AbstractArray displacedTo,
                                        int displacement)
         throws ConditionThrowable

Modified: trunk/abcl/src/org/armedbear/lisp/ComplexVector_UnsignedByte32.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ComplexVector_UnsignedByte32.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ComplexVector_UnsignedByte32.java	Thu Jan 15 23:19:35 2009
@@ -367,7 +367,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        LispObject initialElement,
                                        LispObject initialContents)
         throws ConditionThrowable
@@ -416,7 +416,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        AbstractArray displacedTo,
                                        int displacement)
         throws ConditionThrowable

Modified: trunk/abcl/src/org/armedbear/lisp/ComplexVector_UnsignedByte8.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ComplexVector_UnsignedByte8.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ComplexVector_UnsignedByte8.java	Thu Jan 15 23:19:35 2009
@@ -379,7 +379,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        LispObject initialElement,
                                        LispObject initialContents)
         throws ConditionThrowable
@@ -429,7 +429,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        AbstractArray displacedTo,
                                        int displacement)
         throws ConditionThrowable

Modified: trunk/abcl/src/org/armedbear/lisp/NilVector.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/NilVector.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/NilVector.java	Thu Jan 15 23:19:35 2009
@@ -247,7 +247,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        LispObject initialElement,
                                        LispObject initialContents)
         throws ConditionThrowable
@@ -258,7 +258,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int size, AbstractArray displacedTo,
+    public AbstractVector adjustArray(int size, AbstractArray displacedTo,
                                        int displacement)
         throws ConditionThrowable
     {

Modified: trunk/abcl/src/org/armedbear/lisp/SimpleArray_T.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/SimpleArray_T.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/SimpleArray_T.java	Thu Jan 15 23:19:35 2009
@@ -38,7 +38,7 @@
   private final int[] dimv;
   private final LispObject elementType;
   private final int totalSize;
-  private final LispObject[] data;
+  final LispObject[] data;
 
   public SimpleArray_T(int[] dimv, LispObject elementType)
   {
@@ -89,6 +89,14 @@
     setInitialContents(0, dimv, initialContents, 0);
   }
 
+  public SimpleArray_T(final int[] dimv, final LispObject[] initialData,
+          final LispObject elementType) {
+      this.dimv = dimv;
+      this.elementType = elementType;
+      this.data = initialData;
+      this.totalSize = computeTotalSize(dimv);
+  }
+
   private int setInitialContents(int axis, int[] dims, LispObject contents,
                                  int index)
     throws ConditionThrowable
@@ -314,6 +322,7 @@
     return writeToString(dimv);
   }
 
+  @Override
   public AbstractArray adjustArray(int[] dimv, LispObject initialElement,
                                    LispObject initialContents)
     throws ConditionThrowable
@@ -330,12 +339,13 @@
             return newArray;
           }
       }
-    // New dimensions are identical to old dimensions.
-    return this;
+    // New dimensions are identical to old dimensions, yet
+    // we're not mutable, so, we need to return a new array
+    return new SimpleArray_T(dimv, data.clone(), elementType);
   }
 
   // Copy a1 to a2 for index tuples that are valid for both arrays.
-  private static void copyArray(AbstractArray a1, AbstractArray a2)
+  static void copyArray(AbstractArray a1, AbstractArray a2)
     throws ConditionThrowable
   {
     Debug.assertTrue(a1.getRank() == a2.getRank());
@@ -366,6 +376,7 @@
       }
   }
 
+  @Override
   public AbstractArray adjustArray(int[] dimv, AbstractArray displacedTo,
                                    int displacement)
   {

Modified: trunk/abcl/src/org/armedbear/lisp/SimpleArray_UnsignedByte32.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/SimpleArray_UnsignedByte32.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/SimpleArray_UnsignedByte32.java	Thu Jan 15 23:19:35 2009
@@ -39,7 +39,7 @@
     private final int totalSize;
 
     // FIXME We should really use an array of unboxed values!
-    private final LispObject[] data;
+    final LispObject[] data;
 
     public SimpleArray_UnsignedByte32(int[] dimv)
     {
@@ -309,7 +309,7 @@
     }
 
     // Copy a1 to a2 for index tuples that are valid for both arrays.
-    private static void copyArray(AbstractArray a1, AbstractArray a2)
+    static void copyArray(AbstractArray a1, AbstractArray a2)
         throws ConditionThrowable
     {
         Debug.assertTrue(a1.getRank() == a2.getRank());

Modified: trunk/abcl/src/org/armedbear/lisp/SimpleArray_UnsignedByte8.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/SimpleArray_UnsignedByte8.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/SimpleArray_UnsignedByte8.java	Thu Jan 15 23:19:35 2009
@@ -37,7 +37,7 @@
 {
     private final int[] dimv;
     private final int totalSize;
-    private final byte[] data;
+    final byte[] data;
 
     public SimpleArray_UnsignedByte8(int[] dimv)
     {
@@ -306,7 +306,7 @@
     }
 
     // Copy a1 to a2 for index tuples that are valid for both arrays.
-    private static void copyArray(AbstractArray a1, AbstractArray a2)
+    static void copyArray(AbstractArray a1, AbstractArray a2)
         throws ConditionThrowable
     {
         Debug.assertTrue(a1.getRank() == a2.getRank());

Modified: trunk/abcl/src/org/armedbear/lisp/SimpleBitVector.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/SimpleBitVector.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/SimpleBitVector.java	Thu Jan 15 23:19:35 2009
@@ -194,7 +194,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        LispObject initialElement,
                                        LispObject initialContents)
         throws ConditionThrowable
@@ -239,7 +239,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        AbstractArray displacedTo,
                                        int displacement)
         throws ConditionThrowable

Modified: trunk/abcl/src/org/armedbear/lisp/SimpleString.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/SimpleString.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/SimpleString.java	Thu Jan 15 23:19:35 2009
@@ -460,7 +460,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        LispObject initialElement,
                                        LispObject initialContents)
         throws ConditionThrowable
@@ -495,7 +495,7 @@
     }
 
     @Override
-    public AbstractVector adjustVector(int newCapacity,
+    public AbstractVector adjustArray(int newCapacity,
                                        AbstractArray displacedTo,
                                        int displacement)
         throws ConditionThrowable

Modified: trunk/abcl/src/org/armedbear/lisp/SimpleVector.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/SimpleVector.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/SimpleVector.java	Thu Jan 15 23:19:35 2009
@@ -331,7 +331,7 @@
   }
 
   @Override
-  public AbstractVector adjustVector(int newCapacity,
+  public AbstractVector adjustArray(int newCapacity,
                                      LispObject initialElement,
                                      LispObject initialContents)
     throws ConditionThrowable
@@ -371,7 +371,7 @@
   }
 
   @Override
-  public AbstractVector adjustVector(int newCapacity,
+  public AbstractVector adjustArray(int newCapacity,
                                      AbstractArray displacedTo,
                                      int displacement)
   {

Modified: trunk/abcl/src/org/armedbear/lisp/ZeroRankArray.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ZeroRankArray.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ZeroRankArray.java	Thu Jan 15 23:19:35 2009
@@ -162,4 +162,31 @@
         sb.append(" NIL");
         return unreadableString(sb.toString());
     }
+
+  @Override
+  public AbstractArray adjustArray(int[] dims,
+                                              LispObject initialElement,
+                                              LispObject initialContents)
+    throws ConditionThrowable {
+      if (isAdjustable()) {
+          if (initialContents != NIL)
+              data = initialContents;
+          else
+              data = initialElement;
+          return this;
+      } else {
+          return new ZeroRankArray(elementType,
+                  initialContents != NIL ? initialContents : initialElement,
+                  false);
+      }
+  }
+
+  @Override
+  public AbstractArray adjustArray(int[] dims,
+                                              AbstractArray displacedTo,
+                                              int displacement)
+    throws ConditionThrowable {
+      error(new TypeError("Displacement not supported for array of rank 0."));
+      return null;
+  }
 }

Modified: trunk/abcl/src/org/armedbear/lisp/adjust_array.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/adjust_array.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/adjust_array.java	Thu Jan 15 23:19:35 2009
@@ -67,9 +67,8 @@
             return error(new LispError("ADJUST-ARRAY: incompatible element type."));
         }
         if (array.getRank() == 0) {
-            if (initialContentsProvided != NIL)
-                array.aset(0, initialContents);
-            return array;
+            return array.adjustArray(new int[0], NIL,
+                    (initialContentsProvided != NIL) ? initialContents : initialElement);
         }
         if (initialElementProvided == NIL && array.getElementType() == T)
             initialElement = Fixnum.ZERO;
@@ -81,18 +80,18 @@
                 newSize = Fixnum.getValue(dimensions);
             if (array instanceof AbstractVector) {
                 AbstractVector v = (AbstractVector) array;
-                AbstractVector v2;
+                AbstractArray v2;
                 if (displacedTo != NIL) {
                     final int displacement;
                     if (displacedIndexOffset == NIL)
                         displacement = 0;
                     else
                         displacement = Fixnum.getValue(displacedIndexOffset);
-                    v2 = v.adjustVector(newSize,
+                    v2 = v.adjustArray(newSize,
                                         checkArray(displacedTo),
                                         displacement);
                 } else {
-                    v2 = v.adjustVector(newSize,
+                    v2 = v.adjustArray(newSize,
                                         initialElement,
                                         initialContents);
                 }
@@ -112,24 +111,21 @@
             }
         } else
             dimv[0] = Fixnum.getValue(dimensions);
-        if (array instanceof SimpleArray_T) {
-            SimpleArray_T a = (SimpleArray_T) array;
-            if (displacedTo != NIL) {
-                final int displacement;
-                if (displacedIndexOffset == NIL)
-                    displacement = 0;
-                else
-                    displacement = Fixnum.getValue(displacedIndexOffset);
-                return a.adjustArray(dimv,
+
+        if (displacedTo != NIL) {
+            final int displacement;
+            if (displacedIndexOffset == NIL)
+                displacement = 0;
+            else
+                displacement = Fixnum.getValue(displacedIndexOffset);
+            return array.adjustArray(dimv,
                                      checkArray(displacedTo),
                                      displacement);
-            } else {
-                return a.adjustArray(dimv,
+        } else {
+            return array.adjustArray(dimv,
                                      initialElement,
                                      initialContents);
-            }
         }
-        return error(new LispError("ADJUST-ARRAY: unsupported case."));
     }
 
     private static final Primitive _ADJUST_ARRAY = new adjust_array();




More information about the armedbear-cvs mailing list