;;; Lisplab, level1-vector.lisp ;;; Vectors. These are 1D objects that form the bases for matrices. ;;; Copyright (C) 2009 Joern Inge Vestgaarden ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 2 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License along ;;; with this program; if not, write to the Free Software Foundation, Inc., ;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. (in-package :lisplab) (defclass vector-base () ((size :initarg :size :initform 0 :reader size :type type-blas-idx))) (defclass vector-any (vector-base element-base) ((store :initarg :store :initform nil :reader vector-store :type (simple-array t (*))))) ;;; TODO make similar macros for integer types, that would be more useful (defmacro ll-def-vector-class (class-name element-parent store-type) `(defclass ,class-name (vector-base ,element-parent) ((store :initarg :store :initform nil :reader vector-store :type ,store-type)))) (defmacro ll-def-vref (class-name store-type) (let ((v (gensym "vector")) (idx (gensym "idx"))) `(defmethod vref ((,v ,class-name) ,idx) (aref (the ,store-type (slot-value ,v 'store)) ,idx)))) (defmacro ll-def-setf-vref (class-name store-type element-type) (let ((v (gensym "vector")) (idx (gensym "idx")) (value (gensym "value"))) `(defmethod (setf vref) (,value (,v ,class-name) ,idx) (let ((,value (coerce ,value ',element-type))) (declare (type ,element-type ,value)) (setf (aref (the ,store-type (slot-value ,v 'store)) ,idx) ,value) ,value)))) (defmacro ll-def-vector1-class-and-vref (class-name element-parent store-type element-type) `(progn (ll-def-vector-class ,class-name ,element-parent ,store-type) (ll-def-vref ,class-name ,store-type) (ll-def-setf-vref ,class-name ,store-type ,element-type)))