1/* Define a C preprocessor symbol that can be used in interface files
2   to distinguish between the SWIG language modules. */
3
4#define SWIG_UFFI
5
6/* Typespecs for basic types. */
7
8%typemap(ffitype) char ":char";
9%typemap(ffitype) unsigned char ":unsigned-char";
10%typemap(ffitype) signed char ":char";
11%typemap(ffitype) short ":short";
12%typemap(ffitype) signed short ":short";
13%typemap(ffitype) unsigned short ":unsigned-short";
14%typemap(ffitype) int ":int";
15%typemap(ffitype) signed int ":int";
16%typemap(ffitype) unsigned int ":unsigned-int";
17%typemap(ffitype) long ":long";
18%typemap(ffitype) signed long ":long";
19%typemap(ffitype) unsigned long ":unsigned-long";
20%typemap(ffitype) float ":float";
21%typemap(ffitype) double ":double";
22%typemap(ffitype) char * ":cstring";
23%typemap(ffitype) void * ":pointer-void";
24%typemap(ffitype) void ":void";
25
26// FIXME: This is guesswork
27typedef long size_t;
28
29%wrapper %{
30;; $Id: uffi.swg 7358 2005-08-09 15:09:15Z mkoeppe $
31
32(eval-when (compile eval)
33
34;;; You can define your own identifier converter if you want.
35;;; Use the -identifier-converter command line argument to
36;;; specify its name.
37
38(defun identifier-convert-null (id &key type)
39  (declare (ignore type))
40  (read-from-string id))
41
42(defun identifier-convert-lispify (cname &key type)
43  (assert (stringp cname))
44  (if (eq type :constant)
45      (setf cname (format nil "*~A*" cname)))
46  (setf cname (replace-regexp cname "_" "-"))
47  (let ((lastcase :other)
48        newcase char res)
49    (dotimes (n (length cname))
50      (setf char (schar cname n))
51      (if* (alpha-char-p char)
52         then
53              (setf newcase (if (upper-case-p char) :upper :lower))
54
55              (when (or (and (eq lastcase :upper) (eq newcase :lower))
56                        (and (eq lastcase :lower) (eq newcase :upper)))
57                ;; case change... add a dash
58                (push #\- res)
59                (setf newcase :other))
60
61              (push (char-downcase char) res)
62
63              (setf lastcase newcase)
64
65         else
66              (push char res)
67              (setf lastcase :other)))
68    (read-from-string (coerce (nreverse res) 'string))))
69
70(defun identifier-convert-low-level (cname &key type)
71  (assert (stringp cname))
72  (if (eq type :constant)
73    (setf cname (format nil "+~A+" cname)))
74  (setf cname (substitute #\- #\_ cname))
75  (if (eq type :operator)
76    (setf cname (format nil "%~A" cname)))
77  (if (eq type :constant-function)
78    nil)
79  (read-from-string cname))
80
81
82
83(defmacro swig-defconstant (string value &key (export T))
84  (let ((symbol (funcall *swig-identifier-converter* string :type :constant)))
85    `(eval-when (compile load eval)
86       (uffi:def-constant ,symbol ,value ,export))))
87
88(defmacro swig-defun (name &rest rest)
89  (let ((symbol (funcall *swig-identifier-converter* name :type :operator)))
90    `(eval-when (compile load eval)
91      (uffi:def-function (,name ,symbol) ,@rest)
92      (export (quote ,symbol)))))
93
94(defmacro swig-def-struct (name &rest fields)
95  "Declare a struct object"
96  (let ((symbol (funcall *swig-identifier-converter* name :type :type)))
97    `(eval-when (compile load eval)
98       (uffi:def-struct ,symbol ,@fields)
99       (export (quote ,symbol)))))
100
101
102) ;; eval-when
103%}
104