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 (defun upgraded-array-element-type (typespec &optional environment)
17 (declare (ignore environment))
18 (if (eq typespec 'character)
22 (defun make-array (dimensions &key element-type initial-element adjustable fill-pointer)
23 (let* ((dimensions (ensure-list dimensions))
24 (size (!reduce #'* dimensions 1))
25 (array (make-storage-vector size)))
27 (if (eq element-type 'character)
28 (setf element-type 'character
29 initial-element (or initial-element #\space))
30 (setf element-type t))
33 (storage-vector-set array i initial-element))
34 ;; Record and return the object
35 (oset array "type" element-type)
36 (oset array "dimensions" dimensions)
43 (defun adjustable-array-p (array)
44 (unless (arrayp array)
45 (error "~S is not an array." array))
48 (defun array-element-type (array)
49 (unless (arrayp array)
50 (error "~S is not an array." array))
53 (defun array-dimensions (array)
54 (unless (arrayp array)
55 (error "~S is not an array." array))
56 (oget array "dimensions"))
58 ;; TODO: Error checking
59 (defun array-dimension (array axis)
60 (nth axis (array-dimensions array)))
62 (defun aref (array index)
63 (unless (arrayp array)
64 (error "~S is not an array." array))
65 (storage-vector-ref array index))
67 (defun aset (array index value)
68 (unless (arrayp array)
69 (error "~S is not an array." array))
70 (storage-vector-set array index value))
76 (and (arrayp x) (null (cdr (array-dimensions x)))))
78 ;;; FIXME: should take optional min-extension.
79 ;;; FIXME: should use fill-pointer instead of the absolute end of array
80 (defun vector-push-extend (new vector)
81 (let ((size (storage-vector-size vector)))
82 (resize-storage-vector vector (1+ size))
83 (aset vector size new)