Gerd Moellmann <[EMAIL PROTECTED]> writes:

> "Pierre R. Mai" <[EMAIL PROTECTED]> writes:
>
>> somehow (coerce x 'simple-array) fails.
>
> Isn't this implementation-dependent behavior?

Yes and no, though not in the way you seem to think:

>   * (typep (make-array 1 :fill-pointer 0) 'simple-array)
>   nil
>   * (typep (make-array 1) 'simple-array)
>   t
>
> CLHS, SIMPLE-ARRAY:
>
>   It is implementation-dependent whether displaced arrays, vectors with fill
>   pointers, or arrays that are actually adjustable are simple arrays.

This isn't really pertinent, since the call to coerce is supposed to
turn a known non-simple-array vector[1] into a simple-array vector.
However you are only guaranteed by CLHS that coerce will work for
recognizable subtypes of vector, which simple-array clearly isn't (it
isn't even a subtype, since it also encompasses multi-dimensional
arrays).

CMUCL previously allowed the use of (coerce x 'simple-array) for
turning non-simple-array vectors into simple-array vectors, but that
has been fixed in recent times.  Hence we need to adjust the code in
dump-vector in compiler/dump.lisp to use

(coerce x `(simple-array ,(array-element-type x) (*)))

instead (this fix has been suggested by Christophe Rhodes).

The fix has already been committed to the CVS repository.

People that want to try it out can compile and load the following
file:

(in-package :C)

(defun dump-vector (x file)
  (let ((simple-version (if (array-header-p x)
                            (coerce x
                                    `(simple-array ,(array-element-type x) (*)))
                            x)))
    (typecase simple-version
      (simple-base-string
       (if *coalesce-constants*
           (unless (equal-check-table x file)
             (dump-simple-string simple-version file)
             (equal-save-object x file))
           (dump-simple-string simple-version file)))
      (simple-vector
       (dump-simple-vector simple-version file)
       (eq-save-object x file))
      ((simple-array single-float (*))
       (dump-single-float-vector simple-version file)
       (eq-save-object x file))
      ((simple-array double-float (*))
       (dump-double-float-vector simple-version file)
       (eq-save-object x file))
      #+long-float
      ((simple-array long-float (*))
       (dump-long-float-vector simple-version file)
       (eq-save-object x file))
      ((simple-array (complex single-float) (*))
       (dump-complex-single-float-vector simple-version file)
       (eq-save-object x file))
      ((simple-array (complex double-float) (*))
       (dump-complex-double-float-vector simple-version file)
       (eq-save-object x file))
      #+long-float
      ((simple-array (complex long-float) (*))
       (dump-complex-long-float-vector simple-version file)
       (eq-save-object x file))
      (t
       (dump-i-vector simple-version file)
       (eq-save-object x file)))))

Regs, Pierre.

Footnotes: 
[1]  This word usage is intended to prevent confusion with
simple-vectors:  All simple vectors are simple-arrays, but there are
simple-arrays that are also vectors, but aren't simple-vectors,
e.g. (make-array 50 :element-type '(unsigned-byte 8)).  Hence
"simple-array vector" is meant to be the same as what the type
(simple-array <whatever> (*)) for all whatevers encompasses.

-- 
Pierre R. Mai <[EMAIL PROTECTED]>                    http://www.pmsf.de/pmai/
 The most likely way for the world to be destroyed, most experts agree,
 is by accident. That's where we come in; we're computer professionals.
 We cause accidents.                           -- Nathaniel Borenstein


Reply via email to