diff --git a/init/funcallable.lisp b/init/funcallable.lisp index ed96f6ce552ea899766776d6a496f18c6673478f..bdb0aca4e4fce22ae09580570c8dc80eaf7ee25d 100644 --- a/init/funcallable.lisp +++ b/init/funcallable.lisp @@ -1,6 +1,6 @@ ;; Generate a lambda that calls the user function; will be called by callback. ;; Liam Healy -;; Time-stamp: <2010-06-30 19:57:28EDT funcallable.lisp> +;; Time-stamp: <2010-07-10 22:18:51EDT funcallable.lisp> ;; ;; Copyright 2009 Liam M. Healy ;; Distributed under the terms of the GNU General Public License @@ -65,21 +65,35 @@ ;;;; Reference foreign elements and make multiple-value-bind form ;;;;**************************************************************************** +(defun gref-mpointer-form + (mpointer index &optional (category 'vector) (element-type 'double-float)) + "Create the call that will return an element from a GSL array mpointer." + (ffexpand + nil + (actual-gsl-function-name + '("gsl_" :category :type "_get") category element-type) + `(:pointer ,mpointer sizet ,index ,element-type))) + (defun reference-foreign-element (foreign-variable-name linear-index argspec dimension-values) "Form to reference, for getting or setting, the element of a foreign array, or a scalar." (if (parse-callback-argspec argspec 'dimensions) (if (eql (parse-callback-argspec argspec 'array-type) :foreign-array) - `(grid:gref - ,foreign-variable-name - ,@(let ((dims (value-from-dimensions argspec dimension-values))) - (if (= (length dims) 2) ; matrix - (multiple-value-list - (floor linear-index - (first dims))) - (list linear-index nil))) - ',(grid:cffi-cl (parse-callback-argspec argspec 'element-type))) + (if (= (length (value-from-dimensions argspec dimension-values)) 2) ; matrix + (error "Not ready for matrices yet!") + #+(or) + (gref-mpointer-form + foreign-variable-name + (multiple-value-list + (floor linear-index + (first dims))) + 'matrix + (parse-callback-argspec argspec 'element-type)) + ;; A vector + (gref-mpointer-form + foreign-variable-name linear-index 'vector + (parse-callback-argspec argspec 'element-type))) `(cffi:mem-aref ,foreign-variable-name ',(parse-callback-argspec argspec 'element-type)