uffi.swg 3.1 KB

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