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(eval-when (compile eval)
31
32;;; You can define your own identifier converter if you want.
33;;; Use the -identifier-converter command line argument to
34;;; specify its name.
35
36(defun identifier-convert-null (id &key type)
37  (declare (ignore type))
38  (read-from-string id))
39
40(defun identifier-convert-lispify (cname &key type)
41  (assert (stringp cname))
42  (if (eq type :constant)
43      (setf cname (format nil "*~A*" cname)))
44  (setf cname (replace-regexp cname "_" "-"))
45  (let ((lastcase :other)
46        newcase char res)
47    (dotimes (n (length cname))
48      (setf char (schar cname n))
49      (if* (alpha-char-p char)
50         then
51              (setf newcase (if (upper-case-p char) :upper :lower))
52
53              (when (or (and (eq lastcase :upper) (eq newcase :lower))
54                        (and (eq lastcase :lower) (eq newcase :upper)))
55                ;; case change... add a dash
56                (push #\- res)
57                (setf newcase :other))
58
59              (push (char-downcase char) res)
60
61              (setf lastcase newcase)
62
63         else
64              (push char res)
65              (setf lastcase :other)))
66    (read-from-string (coerce (nreverse res) 'string))))
67
68(defun identifier-convert-low-level (cname &key type)
69  (assert (stringp cname))
70  (if (eq type :constant)
71    (setf cname (format nil "+~A+" cname)))
72  (setf cname (substitute #\- #\_ cname))
73  (if (eq type :operator)
74    (setf cname (format nil "%~A" cname)))
75  (if (eq type :constant-function)
76    nil)
77  (read-from-string cname))
78
79
80
81(defmacro swig-defconstant (string value &key (export T))
82  (let ((symbol (funcall *swig-identifier-converter* string :type :constant)))
83    `(eval-when (compile load eval)
84       (uffi:def-constant ,symbol ,value ,export))))
85
86(defmacro swig-defun (name &rest rest)
87  (let ((symbol (funcall *swig-identifier-converter* name :type :operator)))
88    `(eval-when (compile load eval)
89      (uffi:def-function (,name ,symbol) ,@rest)
90      (export (quote ,symbol)))))
91
92(defmacro swig-def-struct (name &rest fields)
93  "Declare a struct object"
94  (let ((symbol (funcall *swig-identifier-converter* name :type :type)))
95    `(eval-when (compile load eval)
96       (uffi:def-struct ,symbol ,@fields)
97       (export (quote ,symbol)))))
98
99
100) ;; eval-when
101%}
102