PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Lib/allegrocl/allegrocl.swg

#
Unknown | 520 lines | 443 code | 77 blank | 0 comment | 0 complexity | 24fd8b4595a7d44ac0258a4e924217d4 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* Define a C preprocessor symbol that can be used in interface files
  2. to distinguish between the SWIG language modules. */
  3. #define SWIG_ALLEGRO_CL
  4. #define %ffargs(...) %feature("ffargs", "1", ##__VA_ARGS__)
  5. %ffargs(strings_convert="t");
  6. /* typemaps for argument and result type conversions. */
  7. %typemap(lin,numinputs=1) SWIGTYPE "(let (($out $in))\n $body)";
  8. %typemap(lout) bool, char, unsigned char, signed char,
  9. short, signed short, unsigned short,
  10. int, signed int, unsigned int,
  11. long, signed long, unsigned long,
  12. float, double, long double, char *, void *,
  13. enum SWIGTYPE "(setq ACL_ffresult $body)";
  14. %typemap(lout) void "$body";
  15. %typemap(lout) SWIGTYPE[ANY], SWIGTYPE *,
  16. SWIGTYPE & "(setq ACL_ffresult (make-instance '$lclass :foreign-address $body))";
  17. %typemap(lout) SWIGTYPE "(let* ((address $body)\n (new-inst (make-instance '$lclass :foreign-address address)))\n (unless (zerop address)\n (excl:schedule-finalization new-inst #'$ldestructor))\n (setq ACL_ffresult new-inst))";
  18. %typemap(lisptype) bool "boolean";
  19. %typemap(lisptype) char "character";
  20. %typemap(lisptype) unsigned char "integer";
  21. %typemap(lisptype) signed char "integer";
  22. %typemap(ffitype) bool ":int";
  23. %typemap(ffitype) char ":char";
  24. %typemap(ffitype) unsigned char ":unsigned-char";
  25. %typemap(ffitype) signed char ":char";
  26. %typemap(ffitype) short, signed short ":short";
  27. %typemap(ffitype) unsigned short ":unsigned-short";
  28. %typemap(ffitype) int, signed int ":int";
  29. %typemap(ffitype) unsigned int ":unsigned-int";
  30. %typemap(ffitype) long, signed long ":long";
  31. %typemap(ffitype) unsigned long ":unsigned-long";
  32. %typemap(ffitype) float ":float";
  33. %typemap(ffitype) double ":double";
  34. %typemap(ffitype) char * "(* :char)";
  35. %typemap(ffitype) void * "(* :void)";
  36. %typemap(ffitype) void ":void";
  37. %typemap(ffitype) enum SWIGTYPE ":int";
  38. %typemap(ffitype) SWIGTYPE & "(* :void)";
  39. %typemap(ctype) bool "int";
  40. %typemap(ctype) char, unsigned char, signed char,
  41. short, signed short, unsigned short,
  42. int, signed int, unsigned int,
  43. long, signed long, unsigned long,
  44. float, double, long double, char *, void *, void,
  45. enum SWIGTYPE, SWIGTYPE *,
  46. SWIGTYPE[ANY], SWIGTYPE & "$1_ltype";
  47. %typemap(ctype) SWIGTYPE "$&1_type";
  48. %typemap(in) bool "$1 = (bool)$input;";
  49. %typemap(in) char, unsigned char, signed char,
  50. short, signed short, unsigned short,
  51. int, signed int, unsigned int,
  52. long, signed long, unsigned long,
  53. float, double, long double, char *, void *, void,
  54. enum SWIGTYPE, SWIGTYPE *,
  55. SWIGTYPE[ANY], SWIGTYPE & "$1 = $input;";
  56. %typemap(in) SWIGTYPE "$1 = *$input;";
  57. /* We don't need to do any actual C-side typechecking, but need to
  58. use the precedence values to choose which overloaded function
  59. interfaces to generate when conflicts arise. */
  60. /* predefined precedence values
  61. Symbolic Name Precedence Value
  62. ------------------------------ ------------------
  63. SWIG_TYPECHECK_POINTER 0
  64. SWIG_TYPECHECK_VOIDPTR 10
  65. SWIG_TYPECHECK_BOOL 15
  66. SWIG_TYPECHECK_UINT8 20
  67. SWIG_TYPECHECK_INT8 25
  68. SWIG_TYPECHECK_UINT16 30
  69. SWIG_TYPECHECK_INT16 35
  70. SWIG_TYPECHECK_UINT32 40
  71. SWIG_TYPECHECK_INT32 45
  72. SWIG_TYPECHECK_UINT64 50
  73. SWIG_TYPECHECK_INT64 55
  74. SWIG_TYPECHECK_UINT128 60
  75. SWIG_TYPECHECK_INT128 65
  76. SWIG_TYPECHECK_INTEGER 70
  77. SWIG_TYPECHECK_FLOAT 80
  78. SWIG_TYPECHECK_DOUBLE 90
  79. SWIG_TYPECHECK_COMPLEX 100
  80. SWIG_TYPECHECK_UNICHAR 110
  81. SWIG_TYPECHECK_UNISTRING 120
  82. SWIG_TYPECHECK_CHAR 130
  83. SWIG_TYPECHECK_STRING 140
  84. SWIG_TYPECHECK_BOOL_ARRAY 1015
  85. SWIG_TYPECHECK_INT8_ARRAY 1025
  86. SWIG_TYPECHECK_INT16_ARRAY 1035
  87. SWIG_TYPECHECK_INT32_ARRAY 1045
  88. SWIG_TYPECHECK_INT64_ARRAY 1055
  89. SWIG_TYPECHECK_INT128_ARRAY 1065
  90. SWIG_TYPECHECK_FLOAT_ARRAY 1080
  91. SWIG_TYPECHECK_DOUBLE_ARRAY 1090
  92. SWIG_TYPECHECK_CHAR_ARRAY 1130
  93. SWIG_TYPECHECK_STRING_ARRAY 1140
  94. */
  95. %typecheck(SWIG_TYPECHECK_BOOL) bool { $1 = 1; };
  96. %typecheck(SWIG_TYPECHECK_CHAR) char { $1 = 1; };
  97. %typecheck(SWIG_TYPECHECK_FLOAT) float { $1 = 1; };
  98. %typecheck(SWIG_TYPECHECK_DOUBLE) double { $1 = 1; };
  99. %typecheck(SWIG_TYPECHECK_STRING) char * { $1 = 1; };
  100. %typecheck(SWIG_TYPECHECK_INTEGER)
  101. unsigned char, signed char,
  102. short, signed short, unsigned short,
  103. int, signed int, unsigned int,
  104. long, signed long, unsigned long,
  105. enum SWIGTYPE { $1 = 1; };
  106. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &,
  107. SWIGTYPE[ANY], SWIGTYPE { $1 = 1; };
  108. /* This maps C/C++ types to Lisp classes for overload dispatch */
  109. %typemap(lispclass) bool "t";
  110. %typemap(lispclass) char "character";
  111. %typemap(lispclass) unsigned char, signed char,
  112. short, signed short, unsigned short,
  113. int, signed int, unsigned int,
  114. long, signed long, unsigned long,
  115. enum SWIGTYPE "integer";
  116. %typemap(lispclass) float "single-float";
  117. %typemap(lispclass) double "double-float";
  118. %typemap(lispclass) char * "string";
  119. %typemap(out) bool "$result = (int)$1;";
  120. %typemap(out) char, unsigned char, signed char,
  121. short, signed short, unsigned short,
  122. int, signed int, unsigned int,
  123. long, signed long, unsigned long,
  124. float, double, long double, char *, void *, void,
  125. enum SWIGTYPE, SWIGTYPE *,
  126. SWIGTYPE[ANY], SWIGTYPE & "$result = $1;";
  127. #ifdef __cplusplus
  128. %typemap(out) SWIGTYPE "$result = new $1_type($1);";
  129. #else
  130. %typemap(out) SWIGTYPE {
  131. $result = ($&1_ltype) malloc(sizeof($1_type));
  132. memmove($result, &$1, sizeof($1_type));
  133. }
  134. #endif
  135. //////////////////////////////////////////////////////////////
  136. // UCS-2 string conversion
  137. // should this be SWIG_TYPECHECK_CHAR?
  138. %typecheck(SWIG_TYPECHECK_UNICHAR) wchar_t { $1 = 1; };
  139. %typemap(in) wchar_t "$1 = $input;";
  140. %typemap(lin,numinputs=1) wchar_t "(let (($out (char-code $in)))\n $body)";
  141. %typemap(lin,numinputs=1) wchar_t* "(excl:with-native-string ($out $in
  142. :external-format #+little-endian :fat-le #-little-endian :fat)\n
  143. $body)"
  144. %typemap(out) wchar_t "$result = $1;";
  145. %typemap(lout) wchar_t "(setq ACL_ffresult (code-char $body))";
  146. %typemap(lout) wchar_t* "(setq ACL_ffresult (excl:native-to-string $body
  147. :external-format #+little-endian :fat-le #-little-endian :fat))";
  148. %typemap(ffitype) wchar_t ":unsigned-short";
  149. %typemap(lisptype) wchar_t "";
  150. %typemap(ctype) wchar_t "wchar_t";
  151. %typemap(lispclass) wchar_t "character";
  152. %typemap(lispclass) wchar_t* "string";
  153. //////////////////////////////////////////////////////////////
  154. /* name conversion for overloaded operators. */
  155. #ifdef __cplusplus
  156. %rename(__add__) *::operator+;
  157. %rename(__pos__) *::operator+();
  158. %rename(__pos__) *::operator+() const;
  159. %rename(__sub__) *::operator-;
  160. %rename(__neg__) *::operator-() const;
  161. %rename(__neg__) *::operator-();
  162. %rename(__mul__) *::operator*;
  163. %rename(__deref__) *::operator*();
  164. %rename(__deref__) *::operator*() const;
  165. %rename(__div__) *::operator/;
  166. %rename(__mod__) *::operator%;
  167. %rename(__logxor__) *::operator^;
  168. %rename(__logand__) *::operator&;
  169. %rename(__logior__) *::operator|;
  170. %rename(__lognot__) *::operator~();
  171. %rename(__lognot__) *::operator~() const;
  172. %rename(__not__) *::operator!();
  173. %rename(__not__) *::operator!() const;
  174. %rename(__assign__) *::operator=;
  175. %rename(__add_assign__) *::operator+=;
  176. %rename(__sub_assign__) *::operator-=;
  177. %rename(__mul_assign__) *::operator*=;
  178. %rename(__div_assign__) *::operator/=;
  179. %rename(__mod_assign__) *::operator%=;
  180. %rename(__logxor_assign__) *::operator^=;
  181. %rename(__logand_assign__) *::operator&=;
  182. %rename(__logior_assign__) *::operator|=;
  183. %rename(__lshift__) *::operator<<;
  184. %rename(__lshift_assign__) *::operator<<=;
  185. %rename(__rshift__) *::operator>>;
  186. %rename(__rshift_assign__) *::operator>>=;
  187. %rename(__eq__) *::operator==;
  188. %rename(__ne__) *::operator!=;
  189. %rename(__lt__) *::operator<;
  190. %rename(__gt__) *::operator>;
  191. %rename(__lte__) *::operator<=;
  192. %rename(__gte__) *::operator>=;
  193. %rename(__and__) *::operator&&;
  194. %rename(__or__) *::operator||;
  195. %rename(__preincr__) *::operator++();
  196. %rename(__postincr__) *::operator++(int);
  197. %rename(__predecr__) *::operator--();
  198. %rename(__postdecr__) *::operator--(int);
  199. %rename(__comma__) *::operator,();
  200. %rename(__comma__) *::operator,() const;
  201. %rename(__member_ref__) *::operator->;
  202. %rename(__member_func_ref__) *::operator->*;
  203. %rename(__funcall__) *::operator();
  204. %rename(__aref__) *::operator[];
  205. #endif
  206. %insert("lisphead") %{
  207. ;; $Id: allegrocl.swg 9026 2006-03-21 07:15:38Z mutandiz $
  208. (eval-when (compile eval)
  209. ;;; You can define your own identifier converter if you want.
  210. ;;; Use the -identifier-converter command line argument to
  211. ;;; specify its name.
  212. (eval-when (:compile-toplevel :load-toplevel :execute)
  213. (defparameter *swig-export-list* nil))
  214. (defconstant *void* :..void..)
  215. ;; parsers to aid in finding SWIG definitions in files.
  216. (defun scm-p1 (form)
  217. (let* ((info (second form))
  218. (id (car info))
  219. (id-args (cddr info)))
  220. (apply swig:*swig-identifier-converter* id id-args)))
  221. (defmacro defswig1 (name (&rest args) &body body)
  222. `(progn (defmacro ,name ,args
  223. ,@body)
  224. (excl::define-simple-parser ,name scm-p1)) )
  225. (defmacro defswig2 (name (&rest args) &body body)
  226. `(progn (defmacro ,name ,args
  227. ,@body)
  228. (excl::define-simple-parser ,name second)))
  229. (defun read-symbol-from-string (string)
  230. (multiple-value-bind (result position)
  231. (read-from-string string nil "eof" :preserve-whitespace t)
  232. (if (and (symbolp result) (eql position (length string)))
  233. result
  234. (intern string))))
  235. (defun full-name (id type arity class)
  236. (case type
  237. (:getter (format nil "~@[~A_~]~A" class id))
  238. (:constructor (format nil "new_~A~@[~A~]" id arity))
  239. (:destructor (format nil "delete_~A" id))
  240. (:type (format nil "ff_~A" id))
  241. (:ff-operator (format nil "ffi_~A" id))
  242. (otherwise (format nil "~@[~A_~]~A~@[~A~]"
  243. class id arity))))
  244. (defun identifier-convert-null (id &key type class arity)
  245. (if (eq type :setter)
  246. `(setf ,(identifier-convert-null
  247. id :type :getter :class class :arity arity))
  248. (read-symbol-from-string (full-name id type arity class))))
  249. (defun identifier-convert-lispify (cname &key type class arity)
  250. (assert (stringp cname))
  251. (when (eq type :setter)
  252. (return-from identifier-convert-lispify
  253. `(setf ,(identifier-convert-lispify
  254. cname :type :getter :class class :arity arity))))
  255. (setq cname (full-name cname type arity class))
  256. (if (eq type :constant)
  257. (setf cname (format nil "*~A*" cname)))
  258. (setf cname (replace-regexp cname "_" "-"))
  259. (let ((lastcase :other)
  260. newcase char res)
  261. (dotimes (n (length cname))
  262. (setf char (schar cname n))
  263. (if* (alpha-char-p char)
  264. then
  265. (setf newcase (if (upper-case-p char) :upper :lower))
  266. (when (or (and (eq lastcase :upper) (eq newcase :lower))
  267. (and (eq lastcase :lower) (eq newcase :upper)))
  268. ;; case change... add a dash
  269. (push #\- res)
  270. (setf newcase :other))
  271. (push (char-downcase char) res)
  272. (setf lastcase newcase)
  273. else
  274. (push char res)
  275. (setf lastcase :other)))
  276. (read-symbol-from-string (coerce (nreverse res) 'string))))
  277. (defun id-convert-and-export (name &rest kwargs)
  278. (multiple-value-bind (symbol package)
  279. (apply *swig-identifier-converter* name kwargs)
  280. (let ((args (list (if (consp symbol) (cadr symbol) symbol)
  281. (or package *package*))))
  282. (apply #'export args)
  283. (pushnew args swig::*swig-export-list*))
  284. symbol))
  285. (defmacro swig-insert-id (name namespace &key (type :type) class)
  286. `(let ((*package* (find-package ,(package-name-for-namespace namespace))))
  287. (id-convert-and-export ,name :type ,type :class ,class)))
  288. (defswig2 swig-defconstant (string value)
  289. (let ((symbol (id-convert-and-export string :type :constant)))
  290. `(eval-when (compile load eval)
  291. (defconstant ,symbol ,value))))
  292. (defun maybe-reorder-args (funcname arglist)
  293. ;; in the foreign setter function the new value will be the last argument
  294. ;; in Lisp it needs to be the first
  295. (if (consp funcname)
  296. (append (last arglist) (butlast arglist))
  297. arglist))
  298. (defun maybe-return-value (funcname arglist)
  299. ;; setf functions should return the new value
  300. (when (consp funcname)
  301. `(,(if (consp (car arglist))
  302. (caar arglist)
  303. (car arglist)))))
  304. (defun swig-anyvarargs-p (arglist)
  305. (member :SWIG__varargs_ arglist))
  306. (defswig1 swig-defun ((name &optional (mangled-name name)
  307. &key (type :operator) class arity)
  308. arglist kwargs
  309. &body body)
  310. (let* ((symbol (id-convert-and-export name :type type
  311. :arity arity :class class))
  312. (mangle (if* (eq name mangled-name)
  313. then (id-convert-and-export
  314. (cond ((eq type :setter) (format nil "~A-set" name))
  315. ((eq type :getter) (format nil "~A-get" name))
  316. (t name))
  317. :type :ff-operator :arity arity :class class)
  318. else (intern mangled-name)))
  319. (defun-args (maybe-reorder-args
  320. symbol
  321. (mapcar #'car (and (not (equal arglist '(:void)))
  322. (loop as i in arglist
  323. when (eq (car i) :p+)
  324. collect (cdr i))))))
  325. (ffargs (if (equal arglist '(:void))
  326. arglist
  327. (mapcar #'cdr arglist)))
  328. )
  329. (when (swig-anyvarargs-p ffargs)
  330. (setq ffargs '()))
  331. `(eval-when (compile load eval)
  332. (excl::compiler-let ((*record-xref-info* nil))
  333. (ff:def-foreign-call (,mangle ,mangled-name) ,ffargs ,@kwargs))
  334. (macrolet ((swig-ff-call (&rest args)
  335. (cons ',mangle args)))
  336. (defun ,symbol ,defun-args
  337. ,@body
  338. ,@(maybe-return-value symbol defun-args))))))
  339. (defswig1 swig-defmethod ((name &optional (mangled-name name)
  340. &key (type :operator) class arity)
  341. ffargs kwargs
  342. &body body)
  343. (let* ((symbol (id-convert-and-export name :type type
  344. :arity arity :class class))
  345. (mangle (intern mangled-name))
  346. (defmethod-args (maybe-reorder-args
  347. symbol
  348. (unless (equal ffargs '(:void))
  349. (loop for (lisparg name dispatch) in ffargs
  350. when (eq lisparg :p+)
  351. collect `(,name ,dispatch)))))
  352. (ffargs (if (equal ffargs '(:void))
  353. ffargs
  354. (loop for (nil name nil . ffi) in ffargs
  355. collect `(,name ,@ffi)))))
  356. `(eval-when (compile load eval)
  357. (excl::compiler-let ((*record-xref-info* nil))
  358. (ff:def-foreign-call (,mangle ,mangled-name) ,ffargs ,@kwargs))
  359. (macrolet ((swig-ff-call (&rest args)
  360. (cons ',mangle args)))
  361. (defmethod ,symbol ,defmethod-args
  362. ,@body
  363. ,@(maybe-return-value symbol defmethod-args))))))
  364. (defswig1 swig-dispatcher ((name &key (type :operator) class arities))
  365. (let ((symbol (id-convert-and-export name
  366. :type type :class class)))
  367. `(eval-when (compile load eval)
  368. (defun ,symbol (&rest args)
  369. (case (length args)
  370. ,@(loop for arity in arities
  371. for symbol-n = (id-convert-and-export name
  372. :type type :class class :arity arity)
  373. collect `(,arity (apply #',symbol-n args)))
  374. (t (error "No applicable wrapper-methods for foreign call ~a with args ~a of classes ~a" ',symbol args (mapcar #'(lambda (x) (class-name (class-of x))) args)))
  375. )))))
  376. (defswig2 swig-def-foreign-stub (name)
  377. (let ((lsymbol (id-convert-and-export name :type :class))
  378. (symbol (id-convert-and-export name :type :type)))
  379. `(eval-when (compile load eval)
  380. (ff:def-foreign-type ,symbol (:class ))
  381. (defclass ,lsymbol (ff:foreign-pointer) ()))))
  382. (defswig2 swig-def-foreign-class (name supers &rest rest)
  383. (let ((lsymbol (id-convert-and-export name :type :class))
  384. (symbol (id-convert-and-export name :type :type)))
  385. `(eval-when (compile load eval)
  386. (ff:def-foreign-type ,symbol ,@rest)
  387. (defclass ,lsymbol ,supers
  388. ((foreign-type :initform ',symbol :initarg :foreign-type
  389. :accessor foreign-pointer-type))))))
  390. (defswig2 swig-def-foreign-type (name &rest rest)
  391. (let ((symbol (id-convert-and-export name :type :type)))
  392. `(eval-when (compile load eval)
  393. (ff:def-foreign-type ,symbol ,@rest))))
  394. (defswig2 swig-def-synonym-type (synonym of ff-synonym)
  395. `(eval-when (compile load eval)
  396. (setf (find-class ',synonym) (find-class ',of))
  397. (ff:def-foreign-type ,ff-synonym (:struct ))))
  398. (defun package-name-for-namespace (namespace)
  399. (list-to-delimited-string
  400. (cons *swig-module-name*
  401. (mapcar #'(lambda (name)
  402. (string
  403. (funcall *swig-identifier-converter*
  404. name
  405. :type :namespace)))
  406. namespace))
  407. "."))
  408. (defmacro swig-defpackage (namespace)
  409. (let* ((parent-namespaces (maplist #'reverse (cdr (reverse namespace))))
  410. (parent-strings (mapcar #'package-name-for-namespace
  411. parent-namespaces))
  412. (string (package-name-for-namespace namespace)))
  413. `(eval-when (compile load eval)
  414. (defpackage ,string
  415. (:use :common-lisp :ff :swig :excl
  416. ,@parent-strings ,*swig-module-name*)))))
  417. (defmacro swig-in-package (namespace)
  418. `(eval-when (compile load eval)
  419. (in-package ,(package-name-for-namespace namespace))))
  420. (defswig2 swig-defvar (name mangled-name &key type)
  421. (let ((symbol (id-convert-and-export name :type type)))
  422. `(eval-when (compile load eval)
  423. (ff:def-foreign-variable (,symbol ,mangled-name)))))
  424. ) ;; eval-when
  425. (eval-when (compile eval)
  426. (flet ((starts-with-p (str prefix)
  427. (and (>= (length str) (length prefix))
  428. (string= str prefix :end1 (length prefix)))))
  429. (export (loop for sym being each present-symbol of *package*
  430. when (or (starts-with-p (symbol-name sym) (symbol-name :swig-))
  431. (starts-with-p (symbol-name sym) (symbol-name :identifier-convert-)))
  432. collect sym))))
  433. %}
  434. %{
  435. #ifdef __cplusplus
  436. # define EXTERN extern "C"
  437. #else
  438. # define EXTERN extern
  439. #endif
  440. #define EXPORT EXTERN SWIGEXPORT
  441. #include <string.h>
  442. #include <stdlib.h>
  443. %}