;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
-;;;; $Id: primitives.lisp,v 1.1 2002/09/30 10:02:36 kevin Exp $
+;;;; $Id: primitives.lisp,v 1.3 2002/10/14 01:51:15 kevin Exp $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
(defmacro def-type (name type)
"Generates a (deftype) statement for CL. Currently, only CMUCL
supports takes advantage of this optimization."
- #+(or lispworks allegro mcl)
- (declare (ignore type))
- #+(or lispworks allegro mcl)
- `(deftype ,name () t)
+ #+(or lispworks allegro mcl cormanlisp) (declare (ignore type))
+ #+(or lispworks allegro mcl cormanlisp) `(deftype ,name () t)
#+cmu
`(deftype ,name () '(alien:alien ,(convert-from-uffi-type type :declare)))
#+sbcl
#+allegro `(ff:def-foreign-type ,name ,(convert-from-uffi-type type :type))
#+cmu `(alien:def-alien-type ,name ,(convert-from-uffi-type type :type))
#+sbcl `(sb-alien:def-alien-type ,name ,(convert-from-uffi-type type :type))
+ #+cormanlisp `(ct:defctype ,name ,(convert-from-uffi-type type :type))
#+mcl
(let ((mcl-type (convert-from-uffi-type type :type)))
(unless (or (keywordp mcl-type) (consp mcl-type))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar +type-conversion-hash+ (make-hash-table :size 20))
- #+(or cmu sbcl) (defvar +cmu-def-type-hash+ (make-hash-table :size 20))
+ #+(or cmu sbcl) (defvar *cmu-def-type-hash* (make-hash-table :size 20))
)
+#+(or cmu sbcl)
+(defparameter *cmu-sbcl-def-type-list* nil)
+
#+cmu
-(defconstant +cmu-def-type-list+
+(defparameter *cmu-sbcl-def-type-list*
'((:char . (alien:signed 8))
(:unsigned-char . (alien:unsigned 8))
(:byte . (alien:signed 8))
)
"Conversions in CMUCL for def-foreign-type are different than in def-function")
#+sbcl
-(defconstant +cmu-def-type-list+
+(defparameter *cmu-sbcl-def-type-list*
'((:char . (sb-alien:signed 8))
(:unsigned-char . (sb-alien:unsigned 8))
(:byte . (sb-alien:signed 8))
)
"Conversions in SBCL for def-foreign-type are different than in def-function")
-(defparameter +type-conversion-list+ nil)
+(defparameter *type-conversion-list* nil)
#+cmu
-(setq +type-conversion-list+
+(setq *type-conversion-list*
'((* . *) (:void . c-call:void)
(:short . c-call:short)
(:pointer-void . (* t))
(:array . alien:array)))
#+sbcl
-(setq +type-conversion-list+
- '((* . *) (:void . void)
- (:short . short)
+(setq *type-conversion-list*
+ '((* . *) (:void . sb-alien:void)
+ (:short . sb-alien:short)
(:pointer-void . (* t))
- (:cstring . c-string)
- (:char . char)
+ (:cstring . sb-alien:c-string)
+ (:char . sb-alien:char)
(:unsigned-char . (sb-alien:unsigned 8))
(:byte . (sb-alien:signed 8))
(:unsigned-byte . (sb-alien:unsigned 8))
- (:short . unsigned-short)
- (:unsigned-short . unsigned-short)
- (:int . integer) (:unsigned-int . unsigned-int)
- (:long . long) (:unsigned-long . unsigned-long)
- (:float . float) (:double . double)
- (:array . array)))
+ (:short . sb-alien:unsigned-short)
+ (:unsigned-short . sb-alien:unsigned-short)
+ (:int . sb-alien:integer) (:unsigned-int . sb-alien:unsigned-int)
+ (:long . sb-alien:long) (:unsigned-long . sb-alien:unsigned-long)
+ (:float . sb-alien:float) (:double . sb-alien:double)
+ (:array . sb-alien:array)))
-#+allegro
-(setq +type-conversion-list+
+#+(or allegro cormanlisp)
+(setq *type-conversion-list*
'((* . *) (:void . :void)
(:short . :short)
(:pointer-void . (* :void))
(:array . :array)))
#+lispworks
-(setq +type-conversion-list+
+(setq *type-conversion-list*
'((* . :pointer) (:void . :void)
(:short . :short)
(:pointer-void . (:pointer :void))
(:array . :c-array)))
#+(and mcl (not openmcl))
-(setq +type-conversion-list+
+(setq *type-conversion-list*
'((* . :pointer) (:void . :void)
(:short . :short) (:unsigned-short . :unsigned-short)
(:pointer-void . :pointer)
(:array . :array)))
#+openmcl
-(setq +type-conversion-list+
+(setq *type-conversion-list*
'((* . :address) (:void . :void)
(:short . :short) (:unsigned-short . :unsigned-short)
(:pointer-void . :address)
(:float . :single-float) (:double . :double-float)
(:array . :array)))
-(dolist (type +type-conversion-list+)
+(dolist (type *type-conversion-list*)
(setf (gethash (car type) +type-conversion-hash+) (cdr type)))
#+(or cmu sbcl)
-(dolist (type +cmu-def-type-list+)
- (setf (gethash (car type) +cmu-def-type-hash+) (cdr type)))
+(dolist (type *cmu-sbcl-def-type-list*)
+ (setf (gethash (car type) *cmu-def-type-hash*) (cdr type)))
(defun basic-convert-from-uffi-type (type)
(let ((found-type (gethash type +type-conversion-hash+)))
"Converts from a uffi type to an implementation specific type"
(if (atom type)
(cond
- #+allegro
+ #+(or allegro cormanlisp)
((and (or (eq context :routine) (eq context :return))
(eq type :cstring))
(setq type '((* :char) integer)))
#+(or cmu sbcl)
((eq context :type)
- (let ((cmu-type (gethash type +cmu-def-type-hash+)))
+ (let ((cmu-type (gethash type *cmu-def-type-hash*)))
(if cmu-type
cmu-type
(basic-convert-from-uffi-type type))))