1 ;;;; -*- Mode: ANSI-Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: UFFI -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: aggregates.cl
6 ;;;; Purpose: UFFI source to handle aggregate types
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
10 ;;;; $Id: aggregates.cl,v 1.1 2002/04/04 04:56:46 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)))
24 ;;; AGGREGATE SUPPORT IS NOT COMPLETE FOR MCL
27 ;! Need to finish enums, records and variants (unions)
29 (defmacro def-enum (enum-name args &key (separator-string "#"))
30 "Creates a constants for a C type enum list, symbols are created
31 in the created in the current package. The symbol is the concatenation
32 of the enum-name name, separator-string, and field-name"
36 (declare (fixnum counter))
38 (let ((name (if (listp arg) (car arg) arg))
39 (value (if (listp arg)
41 (setq counter (cadr arg))
46 (setq name (intern (concatenate 'string
47 (symbol-name enum-name)
50 (push `(uffi:def-constant ,name ,value) constants)))
51 (setf cmds (append '(progn)
52 #+allegro `((ff:def-foreign-type ,enum-name :int))
53 #+lispworks `((fli:define-c-typedef ,enum-name :int))
54 #+cmu `((alien:def-alien-type ,enum-name alien:signed))
55 (nreverse constants)))
60 (defmacro def-array-pointer (name-array type)
62 `(ff:def-foreign-type ,name-array
63 (:array ,(convert-from-uffi-type type :array)))
65 `(fli:define-c-typedef ,name-array
66 (:c-array ,(convert-from-uffi-type type :array)))
68 `(alien:def-alien-type ,name-array
69 (* ,(convert-from-uffi-type type :array)))
74 ; this is how rref expands array slot access (minus adding the struct offset)
75 (defmacro deref-array (obj type i)
76 "Returns a field from a row"
77 `(,(accessor-symbol type :get) ,obj (* (the fixnum ,i) ,(foreign-object-size type))))
79 (defmacro deref-array-set (obj type i value)
80 `(,(accessor-symbol type :set) ,obj ,value (* (the fixnum ,i) ,(foreign-object-size type))))
82 (defsetf deref-array deref-array-set)
86 (defun process-struct-fields (name fields)
88 (dolist (field fields)
89 (let ((field-name (car field))
91 (push (append (list field-name)
92 (if (eq type :pointer-self)
93 #+cmu `((* (alien:struct ,name)))
95 `(,(convert-from-uffi-type type :struct))))
97 (nreverse processed)))
100 (defmacro def-struct (name &rest fields)
101 `(ccl:defrecord ,name ,@(process-struct-fields name fields))
105 (defmacro def-union (name &rest fields)
106 `(ccl:defrecord ,name ,@(process-struct-fields name fields))
111 (defmacro get-slot-value (obj type slot)
112 (declare (ignore type))
114 `(ff:fslot-value-typed ,type :c ,obj ,slot)
116 `(fli:foreign-slot-value ,obj ,slot)
118 `(alien:slot ,obj ,slot)
121 (defmacro get-slot-pointer (obj type slot)
122 #+(or lispworks cmu) (declare (ignore type))
124 `(ff:fslot-value-typed ,type :c ,obj ,slot)
126 `(fli:foreign-slot-pointer ,obj ,slot)
128 `(alien:slot ,obj ,slot)