| | 73 | ;;;;**************************************************************************** |
| | 74 | ;;;; Types |
| | 75 | ;;;;**************************************************************************** |
| | 76 | |
| | 77 | ;;; CL type definitions: |
| | 78 | (deftype unsigned-byte8 () '(unsigned-byte 8)) |
| | 79 | (deftype unsigned-byte16 () '(unsigned-byte 16)) |
| | 80 | (deftype unsigned-byte32 () '(unsigned-byte 32)) |
| | 81 | (deftype unsigned-byte64 () '(unsigned-byte 64)) |
| | 82 | |
| | 83 | ;;; C type definitions from cffi-net/unixint.cffi.lisp: |
| | 84 | (cffi:defctype uint8 :unsigned-char) |
| | 85 | (cffi:defctype uint16 :unsigned-short) |
| | 86 | (cffi:defctype uint32 :unsigned-int) |
| | 87 | (cffi:defctype uint64 :unsigned-long) |
| | 88 | (cffi:defctype int8 :char) |
| | 89 | (cffi:defctype int16 :short) |
| | 90 | (cffi:defctype int32 :int) |
| | 91 | (cffi:defctype int64 :long) |
| | 92 | |
| | 93 | #-cffi-features:no-long-long |
| | 94 | (cffi:defctype size uint64) |
| | 95 | |
| | 96 | #+cffi-features:no-long-long |
| | 97 | (progn (cerror "Use :uint32 instead." "This platform does not support long long types.") |
| | 98 | (cffi:defctype size uint32)) |
| | 99 | |
| | 100 | ;;;(deftype unsigned-fixnum () `(integer 0 ,most-positive-fixnum)) |
| | 101 | |
| | 102 | (defparameter *type-names* |
| | 103 | '( |
| | 104 | (fixnum :int "_int") |
| | 105 | (unsigned-fixnum :unsigned-int "_uint") |
| | 106 | (single-float :float "_float") |
| | 107 | (double-float :double "") |
| | 108 | ;;(long-double :long "_long_double") |
| | 109 | (complex gsl-complex "_complex") |
| | 110 | (t nil "")) |
| | 111 | "A list of type name mappings, each being a list |
| | 112 | Lisp type, C type as CFFI understands it, and GSL |
| | 113 | splice string.") |
| | 114 | |
| | 115 | (defun lookup-splice-name (cl-type) |
| | 116 | (third (find cl-type *type-names* :key #'first))) |
| | 117 | |
| | 118 | (defun lookup-C-type (cl-type) |
| | 119 | (second (find cl-type *type-names* :key #'first))) |
| | 120 | |
| | 121 | (defun splice-name (base-name keyword symbol) |
| | 122 | "Make a new C name for a data function from a base name." |
| | 123 | (let* ((insert (+ (search keyword base-name) (length keyword)))) |
| | 124 | (concatenate 'string |
| | 125 | (subseq base-name 0 insert) |
| | 126 | (lookup-splice-name symbol) |
| | 127 | (subseq base-name insert)))) |