3 ;; JSCL is free software: you can redistribute it and/or
4 ;; modify it under the terms of the GNU General Public License as
5 ;; published by the Free Software Foundation, either version 3 of the
6 ;; License, or (at your option) any later version.
8 ;; JSCL is distributed in the hope that it will be useful, but
9 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;; General Public License for more details.
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with JSCL. If not, see <http://www.gnu.org/licenses/>.
16 (/debug "loading array.lisp!")
18 (defun upgraded-array-element-type (typespec &optional environment)
19 (declare (ignore environment))
20 (if (eq typespec 'character)
24 (defun make-array (dimensions &key element-type initial-element adjustable fill-pointer)
25 (let* ((dimensions (ensure-list dimensions))
26 (size (!reduce #'* dimensions 1))
27 (array (make-storage-vector size)))
29 (if (eq element-type 'character)
31 (oset 1 array "stringp")
32 (setf element-type 'character
33 initial-element (or initial-element #\space)))
34 (setf element-type t))
37 (storage-vector-set array i initial-element))
38 ;; Record and return the object
39 (oset element-type array "type")
40 (oset dimensions array "dimensions")
47 (defun adjustable-array-p (array)
48 (unless (arrayp array)
49 (error "~S is not an array." array))
52 (defun array-element-type (array)
53 (unless (arrayp array)
54 (error "~S is not an array." array))
55 (if (eq (oget array "stringp") 1)
59 (defun array-dimensions (array)
60 (unless (arrayp array)
61 (error "~S is not an array." array))
62 (oget array "dimensions"))
64 ;; TODO: Error checking
65 (defun array-dimension (array axis)
66 (nth axis (array-dimensions array)))
68 (defun aref (array index)
69 (unless (arrayp array)
70 (error "~S is not an array." array))
71 (storage-vector-ref array index))
73 (defun aset (array index value)
74 (unless (arrayp array)
75 (error "~S is not an array." array))
76 (storage-vector-set array index value))
78 (define-setf-expander aref (array index)
79 (let ((g!array (gensym))
82 (values (list g!array g!index)
85 `(aset ,g!array ,g!index ,g!value)
86 `(aref ,g!array ,g!index))))
92 (and (arrayp x) (null (cdr (array-dimensions x)))))
94 (defun vector (&rest objects)
95 (list-to-vector objects))
97 ;;; FIXME: should take optional min-extension.
98 ;;; FIXME: should use fill-pointer instead of the absolute end of array
99 (defun vector-push-extend (new vector)
100 (unless (vectorp vector)
101 (error "~S is not a vector." vector))
102 (let ((size (storage-vector-size vector)))
103 (resize-storage-vector vector (1+ size))
104 (aset vector size new)