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 ;;;; Programmers: Kevin M. Rosenberg and John DeSoi
8 ;;;; Date Started: Feb 2002
10 ;;;; $Id: primitives.cl,v 1.2 2002/04/06 19:11:15 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
15 ;;;; UFFI users are granted the rights to distribute and use this software
16 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
17 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
18 ;;;; *************************************************************************
20 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
24 (defmacro def-constant (name value &key (export nil))
25 "Macro to define a constant and to export it"
26 `(eval-when (:compile-toplevel :load-toplevel :execute)
27 (defconstant ,name ,value)
28 ,(if export (list 'export `(quote ,name)) (values))))
30 (defmacro def-type (name type)
31 "Generates a (deftype) statement for CL. Currently, only CMUCL
32 supports takes advantage of this optimization."
33 (declare (ignore type))
34 `(deftype ,name () t))
36 (defmacro null-char-p (val)
37 "Returns T if character is NULL"
40 (defmacro def-foreign-type (name type)
41 `(ccl::def-mactype ,name ,(ccl:find-mactype (convert-from-uffi-type type :type))))
43 (eval-when (:compile-toplevel :load-toplevel :execute)
44 (defvar +type-conversion-hash+ (make-hash-table :size 20)))
47 (defconstant +type-conversion-list+
48 '((* . :pointer) (:void . :void)
50 (:pointer-void . :pointer)
53 (:unsigned-char . :unsigned-byte)
55 (:int . :integer) (:unsigned-int . :unsigned-integer)
56 (:long . :long) (:unsigned-long . :unsigned-long)
57 (:float . :single-float) (:double . :double-float)
60 (dolist (type +type-conversion-list+)
61 (setf (gethash (car type) +type-conversion-hash+) (cdr type)))
64 (defmethod ph (&optional (os *standard-output*))
65 (maphash #'(lambda (k v) (format os "~&~S => ~S" k v)) +type-conversion-hash+))
67 (defun convert-from-uffi-type (type context)
68 "Converts from a uffi type to an implementation specific type"
72 ((and (eq type :void) (eq context :return)) nil)
74 (let ((found-type (gethash type +type-conversion-hash+)))
78 (cons (convert-from-uffi-type (first type) context)
79 (convert-from-uffi-type (rest type) context))))