From: espen Date: Fri, 11 Apr 2008 18:51:57 +0000 (+0000) Subject: Added support for OR as return type X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/clg/commitdiff_plain/557e2be6def0331e042ddd1880bf85c4af0f5fe7 Added support for OR as return type --- diff --git a/gffi/basic-types.lisp b/gffi/basic-types.lisp index bbc1657..5231aaf 100644 --- a/gffi/basic-types.lisp +++ b/gffi/basic-types.lisp @@ -20,7 +20,7 @@ ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -;; $Id: basic-types.lisp,v 1.11 2008-03-25 02:00:58 espen Exp $ +;; $Id: basic-types.lisp,v 1.12 2008-04-11 18:51:57 espen Exp $ (in-package "GFFI") @@ -93,6 +93,8 @@ (define-type-generic to-alien-function (type &optional copy-p) "Returns a function of one argument which will translate objects of the given type to alien repesentation. An optional function, taking the origional object and the alien representation as arguments, to clean up after the alien value is not needed any more may be returned as a second argument.") (define-type-generic from-alien-function (type &key ref) "Returns a function of one argument which will translate alien objects of the given type to lisp representation. REF should be :FREE, :COPY, :STATIC or :TEMP") +(define-type-generic alien-typep-form (type alien) + "Returns a form evaluating to T if ALIEN is an alien representation of TYPE.") (define-type-generic callback-wrapper (type var arg form) "Creates a wrapper around FORM which binds the lisp translation of ARG to VAR during a C callback.") @@ -959,6 +961,20 @@ (define-type-method to-alien-form ((type or) form &optional copy-p) `(,type ,(to-alien-form type 'value copy-p))) (rest (type-expand-to 'or type)))))) +(define-type-method from-alien-form ((type or) form &key ref) + (declare (ignore ref)) + `(let ((alien ,form)) + (cond + ,@(loop + for (type . rest) on (rest (type-expand-to 'or type)) + collect + `(,(if (endp rest) + t + (alien-typep-form type 'alien)) + ,(from-alien-form type 'alien)))))) + + + (define-type-method to-alien-function ((type or) &optional copy-p) (let* ((expanded-type (type-expand-to 'or type)) (functions (loop @@ -1019,6 +1035,9 @@ (define-type-method reader-function ((type pointer) &key ref (inlined t)) #'ref-pointer) + +;;; Null Pointer + (define-type-method alien-type ((type null)) (declare (ignore type)) (alien-type 'pointer)) @@ -1027,6 +1046,14 @@ (define-type-method size-of ((type null) &key (inlined t)) (assert-inlined type inlined) (size-of 'pointer)) +(define-type-method alien-typep-form ((type null) null) + (declare (ignore type)) + `(null-pointer-p ,null)) + +(define-type-method from-alien-form ((type null) null &key ref) + (declare (ignore type null ref)) + nil) + (define-type-method to-alien-form ((type null) null &optional copy-p) (declare (ignore type copy-p)) `(progn ,null (make-pointer 0)))