repos
/
smoke
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
Update to the new Smoke ABI (v.3)
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 'class-function)
2009-06-22 tobias
35
()
12:18:08 '
36
smoke-index (foreign-slot-value (smoke-method-pointer method)
2009-08-02 tobias
37
'smoke-method 'method)
2009-06-22 tobias
38
:pointer object-pointer
12:18:08 '
39
smoke-stack stack-pointer
'
40
:void))
'
41
'
42
(defun s-call (method object-pointer &optional (args nil))
2009-04-05 tobias
43
(with-stack (stack args (arguments method) )
2009-07-08 tobias
44
(call-s-method method object-pointer (call-stack-pointer stack))
20:41:19 '
45
(type-to-lisp (call-stack-pointer stack) (return-type method))))
2009-04-05 tobias
46
2009-06-22 tobias
47
(defun pointer-call (method object-pointer &optional (args nil))
2009-04-05 tobias
48
(with-stack (stack args (arguments method) )
2009-07-08 tobias
49
(call-s-method method object-pointer (call-stack-pointer stack))
20:41:19 '
50
(foreign-slot-value (call-stack-pointer stack) 'smoke-stack-item 'class)))
2009-04-05 tobias
51
15:36:29 '
52
(defun smoke-call (class pointer method-name &optional (args nil))
2009-08-02 tobias
53
(s-call (make-smoke-method-from-name class method-name) pointer args))
2009-04-05 tobias
54
2010-01-17 tobias
55
(defun static-call (smoke class-name method-name &rest args)
21:04:08 '
56
(s-call (make-smoke-method-from-name (make-smoke-class smoke class-name)
'
57
method-name)
'
58
(null-pointer) args))
'
59
2009-04-05 tobias
60
(defun enum-call (method)
15:36:29 '
61
"Return the enum value for METHOD."
'
62
;; FIXME:
2009-08-02 tobias
63
;;
2009-04-05 tobias
64
;; we could use static call, but QGraphicsEllipseItem::Type has
15:36:29 '
65
;; wrongly QGraphicsGridLayout as return type. Smoke ignores case
2009-08-02 tobias
66
;; and confuses it with the member function type() ?? (27.2.09)
2009-04-05 tobias
67
;;
15:36:29 '
68
(assert (enum-p method))
'
69
(with-stack (stack nil nil)
2009-07-08 tobias
70
(call-s-method method (null-pointer) (call-stack-pointer stack))
20:41:19 '
71
(foreign-slot-value (call-stack-pointer stack) 'smoke-stack-item 'long)))
2009-04-05 tobias
72
15:36:29 '
73
(defun delete-pointer (pointer class)
'
74
"Destructs the object at POINTER of type CLASS.
2009-07-01 tobias
75
Calls the destructor and frees the memory."
2009-06-30 tobias
76
(declare (optimize (speed 3)))
2009-07-22 tobias
77
(let ((method-name (concatenate 'string "~" (constructor-name class))))
2009-08-02 tobias
78
(s-call (make-smoke-method-from-name class method-name) pointer)))
2009-04-05 tobias
79
15:36:29 '
80
(defun delete-object (object)
2010-02-19 tobias
81
(let ((method-name (concatenate 'string "~" (name (class-of object)))))
21:22:50 '
82
(s-call
'
83
(make-smoke-method-from-name (class-of object) method-name)
'
84
(pointer object)))
2009-04-05 tobias
85
(setf (slot-value object 'pointer) (null-pointer)))
15:36:29 '
86
2009-06-22 tobias
87
(defun set-binding (object)
12:18:08 '
88
"Sets the Smoke binding for OBJECT, that receives its callbacks."
'
89
(declare (optimize (speed 3)))
2010-02-18 tobias
90
(with-foreign-object (stack 'smoke-stack-item 2)
19:57:00 '
91
(setf (foreign-slot-value (mem-aref stack 'smoke-stack-item 1)
'
92
'smoke-stack-item 'voidp)
'
93
(smoke-module-binding (smoke (class-of object))))
'
94
(foreign-funcall-pointer
'
95
(foreign-slot-value (smoke-class-pointer (class-of object))
'
96
'smoke-class 'class-function)
'
97
()
'
98
smoke-index 0 ;; set binding method index
'
99
:pointer (pointer object)
'
100
smoke-stack stack
'
101
:void)))
2009-04-05 tobias
102
2009-06-22 tobias
103
(defun init (smoke module)
2009-04-05 tobias
104
"Returns the a new Smoke binding for the Smoke module SMOKE."
2010-01-10 tobias
105
(use-foreign-library libsmoke-c)
2010-02-18 tobias
106
(let* ((binding (smoke-init smoke (callback destructed)
19:57:00 '
107
(callback dispatch-method))))
2010-01-10 tobias
108
(setf (binding smoke) binding
08:49:36 '
109
(smoke-module-pointer module) smoke
2010-02-19 tobias
110
(smoke-module-binding module) binding)
21:10:24 '
111
(init-smoke-module module)
'
112
(setf (gethash (pointer-address smoke) *smoke-modules*) module)
'
113
module))
2009-04-05 tobias
114
2009-05-12 tobias
115
(let ((pointer-symbol-map (make-hash-table)))
13:54:46 '
116
(defun register-smoke-module-var (symbol)
'
117
"Registers SYMBOL of a variable containing a pointer to a Smoke module."
2009-08-02 tobias
118
(setf (gethash (pointer-address (smoke-module-pointer (eval symbol)))
10:12:41 '
119
pointer-symbol-map)
2009-05-12 tobias
120
symbol))
13:54:46 '
121
(defun get-smoke-variable-for-pointer (pointer)
'
122
"Returns the SYMBOL of the variable whose value is POINTER."
'
123
(gethash (pointer-address pointer) pointer-symbol-map)))
'
124
2009-04-05 tobias
125
(defun call (object method-name &rest args)
2009-08-02 tobias
126
(smoke-call (class-of object) (pointer object)
10:12:41 '
127
method-name args))
2009-04-05 tobias
128
2009-04-12 tobias
129
(defmethod documentation ((class smoke-standard-class) (doc-type (eql 't)))
20:25:47 '
130
(declare (optimize (speed 3)))
2009-04-05 tobias
131
(format nil "~@[~A~%~]C++ name: ~A" (call-next-method) (name class)))
15:36:29 '
132
2009-07-22 tobias
133
(defmethod documentation ((gf smoke-gf) (doc-type (eql 't)))
2009-04-12 tobias
134
(declare (optimize (speed 3)))
2009-04-05 tobias
135
(let ((methods (all-methods (name gf))))
15:36:29 '
136
(format nil "~@[~A~%~]~{~T~A~%~}"
'
137
(call-next-method)
'
138
(sort (mapcar #'method-declaration methods) #'string<=))))
'
139
2009-07-22 tobias
140
(declaim (inline cstring=))
22:26:05 '
141
(defun cstring= (string1 string2)
'
142
"Returns T when the C strings STRING1 and STRING2 are equal
'
143
and NIL otherwise."
'
144
(zerop (strcmp string1 string2)))
'
145
2009-04-05 tobias
146
(defun all-methods (name)
15:36:29 '
147
"Returns a list of all methods named NAME."
2010-01-10 tobias
148
;;FIXME speed this up, needed by (mb:document :smoke).
2009-07-22 tobias
149
(declare (optimize (speed 3)))
22:26:05 '
150
(with-foreign-string (name name)
2009-04-05 tobias
151
(let ((methods))
2009-06-22 tobias
152
(maphash
2009-07-22 tobias
153
#'(lambda (address module)
22:26:05 '
154
(declare (ignore address))
'
155
(map-methods #'(lambda (method)
'
156
(when (and (cstring= name (smoke-method-name method))
'
157
(not (enum-p method)))
'
158
(push (make-smoke-method
'
159
:id (smoke-method-id method)
'
160
:smoke (smoke-method-smoke method))
'
161
methods)))
'
162
module))
'
163
*smoke-modules*)
'
164
methods)))
2009-04-05 tobias
165
15:36:29 '
166
(defun fgrep-methods (smoke str)
'
167
(map-methods #'(lambda (method)
2009-06-22 tobias
168
(when (search str (name method))
12:18:08 '
169
(princ (method-declaration method))
'
170
(terpri)))
2009-04-05 tobias
171
smoke))
15:36:29 '
172
2009-06-11 tobias
173
(defmacro define-smoke-module (package library
14:35:40 '
174
(variable variable-name)
2009-05-14 tobias
175
(init-function function-name))
12:07:00 '
176
"Define a Smoke module."
2009-06-22 tobias
177
(let ((smoke-module (intern "*SMOKE-MODULE*")))
12:18:08 '
178
`(progn
2009-07-22 tobias
179
(eval-when (:compile-toplevel :load-toplevel :execute)
22:26:05 '
180
(define-foreign-library ,library
2009-12-13 tobias
181
(:unix ,(format nil "~(~A~).so.3" library))
2009-07-22 tobias
182
(t (:default ,(format nil "~(~A~)" library)))))
2009-07-02 tobias
183
(eval-startup (:compile-toplevel :execute)
2009-07-22 tobias
184
(load-foreign-library ',library))
2009-08-02 tobias
185
2009-07-02 tobias
186
(eval-startup (:compile-toplevel :execute)
2009-08-02 tobias
187
(defcvar (,variable ,variable-name :read-only t :library ,library)
10:12:41 '
188
:pointer)
2009-12-13 tobias
189
(defcfun (,init-function ,function-name :library ,library)
2009-06-30 tobias
190
:void))
2009-06-12 tobias
191
(eval-when (:compile-toplevel :load-toplevel :execute)
2009-06-22 tobias
192
(defparameter ,smoke-module (make-smoke-module)))
12:18:08 '
193
(eval-startup (:compile-toplevel :execute)
2009-06-30 tobias
194
(,init-function)
22:47:39 '
195
(init ,variable ,smoke-module)
'
196
(register-smoke-module-var ',smoke-module))
2009-06-22 tobias
197
(define-classes-and-gfs ,package ,smoke-module))))
2009-05-14 tobias
198
2009-04-05 tobias
199
(defun fgrep-classes (smoke str)
15:36:29 '
200
(map-classes #'(lambda (class)
'
201
(when (search str (name class))
'
202
(format t "~A~%" (name class))))
'
203
smoke))
2009-05-28 tobias
204
(defmacro define-takes-ownership (method lambda-list object)
2009-06-08 tobias
205
"Declares METHOD transfers the ownership of OBJECT to the
09:20:54 '
206
first argument of LAMBDA-LIST."
2009-05-31 tobias
207
`(defmethod ,method :before ,lambda-list
2009-06-30 tobias
208
(declare (ignorable ,@(loop for arg in (rest lambda-list) collect
22:47:39 '
209
(if (consp arg)
'
210
(first arg)
'
211
arg))))
2009-06-08 tobias
212
(transfer-ownership-to ,object ,(if (consp (first lambda-list))
09:20:54 '
213
(first (first lambda-list))
'
214
(first lambda-list)))))
2009-05-28 tobias
215