r3060: *** empty log message ***
[uffi.git] / src / primitives.lisp
index 6abd855bb5fe9b0cd704391c3a8aad64758e665a..dc91044d8cead83512ae03def4157a43fa98f23c 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; 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.5 2002/10/16 11:56:43 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)
-  #+cmu
+  #+(or lispworks allegro mcl cormanlisp)  (declare (ignore type))
+  #+(or lispworks allegro mcl cormanlisp) `(deftype ,name () t)
+  #+(or cmu scl)
   `(deftype ,name () '(alien:alien ,(convert-from-uffi-type type :declare)))
   #+sbcl
   `(deftype ,name () '(sb-alien:alien ,(convert-from-uffi-type type :declare)))
@@ -71,8 +69,9 @@ supports takes advantage of this optimization."
 (defmacro def-foreign-type (name type)
   #+lispworks `(fli:define-c-typedef ,name ,(convert-from-uffi-type type :type))
   #+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))
+  #+(or cmu scl) `(alien:def-alien-type ,name ,(convert-from-uffi-type type :type))
+  #+sbcl `(sb-alien:define-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))
@@ -85,11 +84,14 @@ supports takes advantage of this optimization."
 
 (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 scl) (defvar *cmu-def-type-hash* (make-hash-table :size 20))
   )
 
-#+cmu
-(defconstant +cmu-def-type-list+
+#+(or cmu sbcl scl)
+(defparameter *cmu-sbcl-def-type-list* nil)
+
+#+(or cmu scl)
+(defparameter *cmu-sbcl-def-type-list*
     '((:char . (alien:signed 8))
       (:unsigned-char . (alien:unsigned 8))
       (:byte . (alien:signed 8))
@@ -105,7 +107,7 @@ supports takes advantage of this optimization."
       )
   "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))
@@ -121,10 +123,10 @@ supports takes advantage of this optimization."
       )
   "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+
+#+(or cmu scl)
+(setq *type-conversion-list*
     '((* . *) (:void . c-call:void) 
       (:short . c-call:short)
       (:pointer-void . (* t))
@@ -141,24 +143,24 @@ supports takes advantage of this optimization."
       (: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))
@@ -173,7 +175,7 @@ supports takes advantage of this optimization."
       (:array . :array)))
 
 #+lispworks
-(setq +type-conversion-list+
+(setq *type-conversion-list*
     '((* . :pointer) (:void . :void) 
       (:short . :short)
       (:pointer-void . (:pointer :void))
@@ -190,7 +192,7 @@ supports takes advantage of this optimization."
       (: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)
@@ -204,7 +206,7 @@ supports takes advantage of this optimization."
        (:array . :array)))
 
 #+openmcl
-(setq +type-conversion-list+
+(setq *type-conversion-list*
      '((* . :address) (:void . :void)
        (:short . :short) (:unsigned-short . :unsigned-short)
        (:pointer-void . :address)
@@ -218,12 +220,12 @@ supports takes advantage of this optimization."
        (: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)))
+#+(or cmu sbcl scl)
+(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+)))
@@ -236,13 +238,13 @@ supports takes advantage of this optimization."
   "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)
+       #+(or cmu sbcl scl)
        ((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))))