1 | ;;; arrays.lisp |
---|
2 | ;;; |
---|
3 | ;;; Copyright (C) 2003 Peter Graves |
---|
4 | ;;; $Id: arrays.lisp,v 1.12 2003-06-23 19:41:56 piso Exp $ |
---|
5 | ;;; |
---|
6 | ;;; This program is free software; you can redistribute it and/or |
---|
7 | ;;; modify it under the terms of the GNU General Public License |
---|
8 | ;;; as published by the Free Software Foundation; either version 2 |
---|
9 | ;;; of the License, or (at your option) any later version. |
---|
10 | ;;; |
---|
11 | ;;; This program is distributed in the hope that it will be useful, |
---|
12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | ;;; GNU General Public License for more details. |
---|
15 | ;;; |
---|
16 | ;;; You should have received a copy of the GNU General Public License |
---|
17 | ;;; along with this program; if not, write to the Free Software |
---|
18 | ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | |
---|
20 | (in-package "COMMON-LISP") |
---|
21 | |
---|
22 | (defconstant array-total-size-limit #x1000000) |
---|
23 | (defconstant array-rank-limit 8) |
---|
24 | |
---|
25 | (defun make-array (dimensions &key |
---|
26 | (element-type t) |
---|
27 | (initial-element nil initial-element-p) |
---|
28 | initial-contents adjustable fill-pointer |
---|
29 | displaced-to displaced-index-offset) |
---|
30 | (%make-array dimensions element-type initial-element initial-element-p |
---|
31 | initial-contents adjustable fill-pointer displaced-to |
---|
32 | displaced-index-offset)) |
---|
33 | |
---|
34 | (defun array-row-major-index (array &rest subscripts) |
---|
35 | (%array-row-major-index array subscripts)) |
---|
36 | |
---|
37 | (defun %aset (array &rest stuff) |
---|
38 | (if (= (length stuff) 2) |
---|
39 | (%set-row-major-aref array (car stuff) (cadr stuff)) |
---|
40 | (let ((subscripts (butlast stuff)) |
---|
41 | (new-value (car (last stuff)))) |
---|
42 | (%set-row-major-aref array (%array-row-major-index array subscripts) |
---|
43 | new-value)))) |
---|
44 | |
---|
45 | (defsetf aref %aset) |
---|
46 | (defsetf row-major-aref %set-row-major-aref) |
---|
47 | |
---|
48 | (defun bit (bit-array &rest subscripts) |
---|
49 | (row-major-aref bit-array (%array-row-major-index bit-array subscripts))) |
---|
50 | |
---|
51 | (defun sbit (simple-bit-array &rest subscripts) |
---|
52 | (row-major-aref simple-bit-array |
---|
53 | (%array-row-major-index simple-bit-array subscripts))) |
---|
54 | |
---|
55 | (defsetf bit %aset) |
---|
56 | (defsetf sbit %aset) |
---|