1 ;;;; -*- Mode: ANSI-Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: UFFI -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: primitives.cl
6 ;;;; Purpose: UFFI source to handle immediate types
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
10 ;;;; $Id: primitives.cl,v 1.1 2002/04/04 05:03:14 desoi Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
23 (defmacro def-constant (name value &key (export nil))
24 "Macro to define a constant and to export it"
25 `(eval-when (:compile-toplevel :load-toplevel :execute)
26 (defconstant ,name ,value)
27 ,(if export (list 'export `(quote ,name)) (values))))
29 (defmacro def-type (name type)
30 "Generates a (deftype) statement for CL. Currently, only CMUCL
31 supports takes advantage of this optimization."
32 (declare (ignore type))
33 `(deftype ,name () t))
35 (defmacro null-char-p (val)
36 "Returns T if character is NULL"
39 (defmacro def-foreign-type (name type)
40 `(ccl::def-mactype ,name ,(ccl:find-mactype (convert-from-uffi-type type :type))))
42 (eval-when (:compile-toplevel :load-toplevel :execute)
43 (defvar +type-conversion-hash+ (make-hash-table :size 20)))
46 (defconstant +type-conversion-list+
47 '((* . :pointer) (:void . :void)
49 (:pointer-void . :pointer)
52 (:unsigned-char . :unsigned-byte)
54 (:int . :integer) (:unsigned-int . :unsigned-integer)
55 (:long . :long) (:unsigned-long . :unsigned-long)
56 (:float . :single-float) (:double . :double-float)
59 (dolist (type +type-conversion-list+)
60 (setf (gethash (car type) +type-conversion-hash+) (cdr type)))
63 (defmethod ph (&optional (os *standard-output*))
64 (maphash #'(lambda (k v) (format os "~&~S => ~S" k v)) +type-conversion-hash+))
66 (defun convert-from-uffi-type (type context)
67 "Converts from a uffi type to an implementation specific type"
71 ((and (eq type :void) (eq context :return)) nil)
73 (let ((found-type (gethash type +type-conversion-hash+)))
77 (cons (convert-from-uffi-type (first type) context)
78 (convert-from-uffi-type (rest type) context))))