Use strcmp, fix constructor & destrucor calling for classes witn namespace (phonon::MediaPlayer) and add :arg0 to :arg2 initargs
Annotate for file src/smoke.lisp
2010-01-10 tobias 1 ;;; Copyright (C) 2009 Tobias Rautenkranz <tobias@rautenkranz.ch>
2009-04-14 tobias 2 ;;;
14:23:24 ' 3 ;;; This program is free software: you can redistribute it and/or modify
' 4 ;;; it under the terms of the GNU General Public License as published by
' 5 ;;; the Free Software Foundation, either version 3 of the License, or
' 6 ;;; (at your option) any later version.
' 7 ;;;
' 8 ;;; This program is distributed in the hope that it will be useful,
' 9 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
' 10 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' 11 ;;; GNU General Public License for more details.
' 12 ;;;
' 13 ;;; You should have received a copy of the GNU General Public License
' 14 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
' 15 ;;;
' 16 ;;; As a special exception, the copyright holders of this library give you
' 17 ;;; permission to link this library with independent modules to produce an
' 18 ;;; executable, regardless of the license terms of these independent
' 19 ;;; modules, and to copy and distribute the resulting executable under
' 20 ;;; terms of your choice, provided that you also meet, for each linked
' 21 ;;; independent module, the terms and conditions of the license of that
' 22 ;;; module. An independent module is a module which is not derived from or
' 23 ;;; based on this library. If you modify this library, you may extend this
' 24 ;;; exception to your version of the library, but you are not obligated to
' 25 ;;; do so. If you do not wish to do so, delete this exception statement
' 26 ;;; from your version.
2009-04-05 tobias 27
2009-04-14 tobias 28 (in-package #:smoke)
2009-04-05 tobias 29
2009-06-30 tobias 30 (declaim (inline call-s-method))
2009-06-22 tobias 31 (defun call-s-method (method object-pointer stack-pointer)
12:18:08 ' 32 (foreign-funcall-pointer
2009-07-08 tobias 33 (foreign-slot-value (smoke-class-pointer (get-class method))
2009-08-02 tobias 34 'smoke-class
10:12:41 ' 35 'class-function)
2009-06-22 tobias 36 ()
12:18:08 ' 37 smoke-index (foreign-slot-value (smoke-method-pointer method)
2009-08-02 tobias 38 'smoke-method
10:12:41 ' 39 'method)
2009-06-22 tobias 40 :pointer object-pointer
12:18:08 ' 41 smoke-stack stack-pointer
' 42 :void))
' 43
' 44 (defun s-call (method object-pointer &optional (args nil))
2009-04-05 tobias 45 (with-stack (stack args (arguments method) )
2009-07-08 tobias 46 (call-s-method method object-pointer (call-stack-pointer stack))
20:41:19 ' 47 (type-to-lisp (call-stack-pointer stack) (return-type method))))
2009-04-05 tobias 48
2009-06-22 tobias 49 (defun pointer-call (method object-pointer &optional (args nil))
2009-04-05 tobias 50 (with-stack (stack args (arguments method) )
2009-07-08 tobias 51 (call-s-method method object-pointer (call-stack-pointer stack))
20:41:19 ' 52 (foreign-slot-value (call-stack-pointer stack) 'smoke-stack-item 'class)))
2009-04-05 tobias 53
2009-08-02 tobias 54
2009-04-05 tobias 55 (defun smoke-call (class pointer method-name &optional (args nil))
2009-08-02 tobias 56 (s-call
10:12:41 ' 57 (make-smoke-method-from-name class method-name)
' 58 pointer args))
2009-04-05 tobias 59
2010-01-17 tobias 60 (defun static-call (smoke class-name method-name &rest args)
2009-08-02 tobias 61 (s-call
10:12:41 ' 62 (make-smoke-method-from-name (make-smoke-class smoke class-name)
' 63 method-name)
' 64 (null-pointer) args))
2010-01-17 tobias 65
2009-04-05 tobias 66 (defun enum-call (method)
15:36:29 ' 67 "Return the enum value for METHOD."
' 68 ;; FIXME:
' 69 ;; we could use static call, but QGraphicsEllipseItem::Type has
' 70 ;; wrongly QGraphicsGridLayout as return type. Smoke ignores case
2009-08-02 tobias 71 ;; and confuses it with the member function type() ??
10:12:41 ' 72 ;; (27.2.09)
2009-04-05 tobias 73 ;;
15:36:29 ' 74 (assert (enum-p method))
' 75 (with-stack (stack nil nil)
2009-07-08 tobias 76 (call-s-method method (null-pointer) (call-stack-pointer stack))
20:41:19 ' 77 (foreign-slot-value (call-stack-pointer stack) 'smoke-stack-item 'long)))
2009-04-05 tobias 78
15:36:29 ' 79 (defun delete-pointer (pointer class)
' 80 "Destructs the object at POINTER of type CLASS.
2009-07-01 tobias 81 Calls the destructor and frees the memory."
2009-06-30 tobias 82 (declare (optimize (speed 3)))
2009-07-22 tobias 83 (let ((method-name (concatenate 'string "~" (constructor-name class))))
2009-08-02 tobias 84 (s-call
10:12:41 ' 85 (make-smoke-method-from-name class method-name)
2009-07-22 tobias 86 pointer)))
2009-04-05 tobias 87
15:36:29 ' 88 (defun delete-object (object)
2010-02-19 tobias 89 (let ((method-name (concatenate 'string "~" (name (class-of object)))))
21:22:50 ' 90 (s-call
2009-08-02 tobias 91 (make-smoke-method-from-name (class-of object) method-name)
10:12:41 ' 92 (pointer object)))
2009-04-05 tobias 93 (setf (slot-value object 'pointer) (null-pointer)))
15:36:29 ' 94
2009-06-22 tobias 95 (defun set-binding (object)
12:18:08 ' 96 "Sets the Smoke binding for OBJECT, that receives its callbacks."
' 97 (declare (optimize (speed 3)))
2010-02-18 tobias 98 (with-foreign-object (stack 'smoke-stack-item 2)
2009-08-02 tobias 99 (setf (foreign-slot-value (mem-aref stack
10:12:41 ' 100 'smoke-stack-item
' 101 1)
' 102 'smoke-stack-item
' 103 'voidp)
2010-02-18 tobias 104 (smoke-module-binding (smoke (class-of object))))
19:57:00 ' 105 (foreign-funcall-pointer
' 106 (foreign-slot-value (smoke-class-pointer (class-of object))
2009-08-02 tobias 107 'smoke-class
10:12:41 ' 108 'class-function)
2010-02-18 tobias 109 ()
19:57:00 ' 110 smoke-index 0 ;; set binding method index
2009-08-02 tobias 111 :pointer (pointer object) smoke-stack stack
2010-02-18 tobias 112 :void)))
2009-04-05 tobias 113
2009-06-22 tobias 114 (defun init (smoke module)
2009-04-05 tobias 115 "Returns the a new Smoke binding for the Smoke module SMOKE."
2010-01-10 tobias 116 (use-foreign-library libsmoke-c)
2009-08-02 tobias 117 (let* ((binding (smoke-init smoke
10:12:41 ' 118 (callback destructed)
2010-02-18 tobias 119 (callback dispatch-method))))
2010-01-10 tobias 120 (setf (binding smoke) binding
08:49:36 ' 121 (smoke-module-pointer module) smoke
2010-02-19 tobias 122 (smoke-module-binding module) binding)
21:10:24 ' 123 (init-smoke-module module)
' 124 (setf (gethash (pointer-address smoke) *smoke-modules*) module)
' 125 module))
2009-04-05 tobias 126
2009-05-12 tobias 127 (let ((pointer-symbol-map (make-hash-table)))
13:54:46 ' 128 (defun register-smoke-module-var (symbol)
' 129 "Registers SYMBOL of a variable containing a pointer to a Smoke module."
2009-08-02 tobias 130 (setf (gethash (pointer-address (smoke-module-pointer (eval symbol))) pointer-symbol-map)
2009-05-12 tobias 131 symbol))
13:54:46 ' 132 (defun get-smoke-variable-for-pointer (pointer)
' 133 "Returns the SYMBOL of the variable whose value is POINTER."
' 134 (gethash (pointer-address pointer) pointer-symbol-map)))
' 135
2009-04-05 tobias 136 (defun call (object method-name &rest args)
2009-08-02 tobias 137 (smoke-call (class-of object)
10:12:41 ' 138 (pointer object)
' 139 method-name
' 140 args))
2009-04-05 tobias 141
2009-04-12 tobias 142 (defmethod documentation ((class smoke-standard-class) (doc-type (eql 't)))
20:25:47 ' 143 (declare (optimize (speed 3)))
2009-04-05 tobias 144 (format nil "~@[~A~%~]C++ name: ~A" (call-next-method) (name class)))
15:36:29 ' 145
2009-07-22 tobias 146 (defmethod documentation ((gf smoke-gf) (doc-type (eql 't)))
2009-04-12 tobias 147 (declare (optimize (speed 3)))
2009-04-05 tobias 148 (let ((methods (all-methods (name gf))))
15:36:29 ' 149 (format nil "~@[~A~%~]~{~T~A~%~}"
' 150 (call-next-method)
' 151 (sort (mapcar #'method-declaration methods) #'string<=))))
' 152
2009-07-22 tobias 153
22:26:05 ' 154 (declaim (inline cstring=))
' 155 (defun cstring= (string1 string2)
' 156 "Returns T when the C strings STRING1 and STRING2 are equal
' 157 and NIL otherwise."
' 158 (zerop (strcmp string1 string2)))
' 159
2009-04-05 tobias 160 (defun all-methods (name)
15:36:29 ' 161 "Returns a list of all methods named NAME."
2010-01-10 tobias 162 ;;FIXME speed this up, needed by (mb:document :smoke).
2009-07-22 tobias 163 (declare (optimize (speed 3)))
22:26:05 ' 164 (with-foreign-string (name name)
2009-04-05 tobias 165 (let ((methods))
2009-06-22 tobias 166 (maphash
2009-07-22 tobias 167 #'(lambda (address module)
22:26:05 ' 168 (declare (ignore address))
' 169 (map-methods #'(lambda (method)
' 170 (when (and (cstring= name (smoke-method-name method))
' 171 (not (enum-p method)))
' 172 (push (make-smoke-method
' 173 :id (smoke-method-id method)
' 174 :smoke (smoke-method-smoke method))
' 175 methods)))
' 176 module))
' 177 *smoke-modules*)
' 178 methods)))
2009-04-05 tobias 179
15:36:29 ' 180 (defun fgrep-methods (smoke str)
' 181 (map-methods #'(lambda (method)
2009-06-22 tobias 182 (when (search str (name method))
12:18:08 ' 183 (princ (method-declaration method))
' 184 (terpri)))
2009-04-05 tobias 185 smoke))
15:36:29 ' 186
2009-06-11 tobias 187 (defmacro define-smoke-module (package library
14:35:40 ' 188 (variable variable-name)
2009-05-14 tobias 189 (init-function function-name))
12:07:00 ' 190 "Define a Smoke module."
2009-06-22 tobias 191 (let ((smoke-module (intern "*SMOKE-MODULE*")))
12:18:08 ' 192 `(progn
2009-07-22 tobias 193 (eval-when (:compile-toplevel :load-toplevel :execute)
22:26:05 ' 194 (define-foreign-library ,library
' 195 (:unix ,(format nil "~(~A~).so.2" library))
' 196 (t (:default ,(format nil "~(~A~)" library)))))
2009-07-02 tobias 197 (eval-startup (:compile-toplevel :execute)
2009-07-22 tobias 198 (load-foreign-library ',library))
2009-07-02 tobias 199 (eval-startup (:compile-toplevel :execute)
2009-08-02 tobias 200 (defcvar (,variable ,variable-name
10:12:41 ' 201 :read-only t
' 202 :library ,library) :pointer)
2009-12-13 tobias 203 (defcfun (,init-function ,(format nil "_Z~A~Av"
10:17:08 ' 204 (length function-name)
' 205 function-name)
' 206 :library ,library)
2009-06-30 tobias 207 :void))
2009-06-12 tobias 208 (eval-when (:compile-toplevel :load-toplevel :execute)
2009-06-22 tobias 209 (defparameter ,smoke-module (make-smoke-module)))
12:18:08 ' 210 (eval-startup (:compile-toplevel :execute)
2009-06-30 tobias 211 (,init-function)
22:47:39 ' 212 (init ,variable ,smoke-module)
' 213 (register-smoke-module-var ',smoke-module))
2009-06-22 tobias 214 (define-classes-and-gfs ,package ,smoke-module))))
2009-05-14 tobias 215
2009-08-02 tobias 216
2009-04-05 tobias 217 (defun fgrep-classes (smoke str)
15:36:29 ' 218 (map-classes #'(lambda (class)
' 219 (when (search str (name class))
' 220 (format t "~A~%" (name class))))
' 221 smoke))
2009-05-28 tobias 222 (defmacro define-takes-ownership (method lambda-list object)
2009-06-08 tobias 223 "Declares METHOD transfers the ownership of OBJECT to the
09:20:54 ' 224 first argument of LAMBDA-LIST."
2009-05-31 tobias 225 `(defmethod ,method :before ,lambda-list
2009-06-30 tobias 226 (declare (ignorable ,@(loop for arg in (rest lambda-list) collect
22:47:39 ' 227 (if (consp arg)
' 228 (first arg)
' 229 arg))))
2009-06-08 tobias 230 (transfer-ownership-to ,object ,(if (consp (first lambda-list))
09:20:54 ' 231 (first (first lambda-list))
' 232 (first lambda-list)))))
2009-05-28 tobias 233