repos
/
smoke
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
Fix class-map image loading and use the new static smoke methods.
Annotate for file src/objects/class.lisp
2009-04-05 tobias
1
(in-package #:smoke)
15:36:29 '
2
2009-06-22 tobias
3
(defclass smoke-class ()
2009-08-02 tobias
4
((id :initform 0 :type smoke-index
10:12:41 '
5
:reader id :initarg :id)
'
6
(smoke :type smoke-module
'
7
:reader smoke :initarg :smoke)))
2009-04-05 tobias
8
2009-06-22 tobias
9
(defun make-smoke-class-from-id (smoke id)
2009-07-08 tobias
10
(make-instance 'smoke-class :id id :smoke smoke))
2009-04-05 tobias
11
2009-07-08 tobias
12
(declaim (inline smoke-class-pointer))
20:41:19 '
13
(defun smoke-class-pointer (class)
2009-08-02 tobias
14
(mem-aref (the foreign-pointer
10:12:41 '
15
(smoke-array-pointer (smoke-module-classes (smoke class))))
2009-07-08 tobias
16
'smoke-class
20:41:19 '
17
(the smoke-index (id class))))
2009-04-05 tobias
18
2009-05-26 tobias
19
(declaim (inline class-slot-value))
09:54:47 '
20
(defun class-slot-value (class slot-name)
2009-07-08 tobias
21
(foreign-slot-value (smoke-class-pointer class)
2009-04-05 tobias
22
'smoke-class slot-name))
15:36:29 '
23
2009-06-22 tobias
24
(define-compiler-macro class-slot-value (&whole form class slot-name)
12:18:08 '
25
(if (constantp slot-name)
2009-07-08 tobias
26
`(foreign-slot-value (smoke-class-pointer ,class)
2009-06-22 tobias
27
'smoke-class ,slot-name)
12:18:08 '
28
form))
'
29
2009-04-05 tobias
30
(defmethod name ((class smoke-class))
2009-05-26 tobias
31
(class-slot-value class 'name))
2009-04-05 tobias
32
15:36:29 '
33
(defun map-classes (function smoke)
2009-07-01 tobias
34
"Applies FUNCTION to the classes of SMOKE."
2009-05-14 tobias
35
(declare (function function)
12:07:00 '
36
(optimize (speed 3)))
2009-04-05 tobias
37
(let ((class (make-instance 'smoke-class
2009-05-14 tobias
38
:smoke smoke)))
2009-06-22 tobias
39
(loop for id from 1 to (smoke-array-length (smoke-module-classes smoke)) do
2009-07-08 tobias
40
(setf (slot-value class 'id)
20:41:19 '
41
id)
2009-04-05 tobias
42
(funcall function class))))
15:36:29 '
43
'
44
(defun external-p (class)
'
45
"Returns T when CLASS is external in its module; NIL otherwise."
2009-08-02 tobias
46
(declare (type smoke-class class)
10:12:41 '
47
(optimize (speed 3)))
2009-05-26 tobias
48
(class-slot-value class 'external))
2009-04-05 tobias
49
2009-06-22 tobias
50
(defun get-class-flag (class flag)
12:18:08 '
51
(declare (optimize (speed 3)))
'
52
(logand (class-slot-value class 'flags)
'
53
(the fixnum (foreign-enum-value 'smoke-class-flags flag))))
2009-04-05 tobias
54
15:36:29 '
55
(defmethod constructor-p ((class smoke-class))
'
56
"Returns T when CLASS has a constructor; NIL otherwise."
2009-06-22 tobias
57
(/= 0 (get-class-flag class :constructor)))
2009-04-05 tobias
58
2009-05-24 tobias
59
(defun virtual-destructor-p (class)
11:30:05 '
60
"Returns T when CLASS has a virtual destructor and NIL otherwise."
2009-06-22 tobias
61
(/= 0 (get-class-flag class :virtual-destructor)))
2009-05-24 tobias
62
2009-04-05 tobias
63
(define-condition undefined-class (cell-error)
2010-01-17 tobias
64
()
2009-04-05 tobias
65
(:report (lambda (condition stream)
2010-01-17 tobias
66
(format stream "No Smoke class named ~S."
21:04:08 '
67
(cell-error-name condition))))
2009-04-05 tobias
68
(:documentation "A undefined Smoke class"))
15:36:29 '
69
2010-01-10 tobias
70
(define-condition lisp-module-not-loaded (error)
17:31:42 '
71
((class-name :initarg :class-name))
'
72
(:report (lambda (condition stream)
'
73
(format stream "The Lisp smoke module of the class ~A is not loaded."
'
74
(slot-value condition 'class-name)))))
'
75
2010-01-17 tobias
76
(defun make-smoke-class (name)
21:04:08 '
77
"Returns the class named NAME.
2009-04-05 tobias
78
Signals an undefined-class condition when there is no class for NAME."
15:36:29 '
79
(with-foreign-object (c 'smoke-module-index)
'
80
(do () (nil)
2010-01-17 tobias
81
(smoke-find-class c name)
2009-04-05 tobias
82
(restart-case
15:36:29 '
83
(if (null-pointer-p (foreign-slot-value c 'smoke-module-index 'smoke))
2010-01-17 tobias
84
(error (make-condition 'undefined-class :name name))
2009-04-05 tobias
85
(return))
15:36:29 '
86
(supply (new-name)
'
87
:report "Supply a new class name"
'
88
:interactive read-new-value
'
89
(setf name new-name))))
2010-01-10 tobias
90
(let ((class (make-instance
17:31:42 '
91
'smoke-class
'
92
:id (foreign-slot-value c 'smoke-module-index 'index)
'
93
:smoke (gethash (pointer-address (foreign-slot-value
'
94
c 'smoke-module-index
'
95
'smoke))
'
96
*smoke-modules*))))
'
97
(unless (smoke class)
'
98
(error (make-condition 'lisp-module-not-loaded :class-name name)))
'
99
class)))
2009-04-05 tobias
100
15:36:29 '
101
(defun real-class (class)
'
102
"Returns the same class like CLASS, but such that EXTERNAL-P returns NIL."
'
103
(if (external-p class)
2010-01-17 tobias
104
(handler-case (make-smoke-class (name class))
2010-02-16 tobias
105
(undefined-class () class))
2009-04-05 tobias
106
class))
15:36:29 '
107
'
108
(defun class-id (module class)
'
109
"Returns the class id of CLASS for the Smoke module MODULE."
'
110
(if (eq (smoke class) module)
'
111
(id class)
'
112
(smoke-class-id module (name class))))
'
113
2010-02-16 tobias
114
;(defun smoke-subclassp (class base-class) TODO
2009-04-05 tobias
115
(defun derived-p (class base-class)
15:36:29 '
116
"Returns T when CLASS is derived from BASE-CLASS and NIL when not."
2010-02-16 tobias
117
(values
21:52:02 '
118
(derived-real-p (real-class class) (real-class base-class))
'
119
T))
2009-04-05 tobias
120
15:36:29 '
121
(defun derived-real-p (class base-class)
2009-08-02 tobias
122
(smoke-is-derived-from (smoke-module-pointer (smoke class))
10:12:41 '
123
(id class)
'
124
(smoke-module-pointer (smoke base-class))
'
125
(id base-class)))
2009-04-05 tobias
126
15:36:29 '
127
'
128
(defun smoke-class-direct-superclasses (class)
2009-05-26 tobias
129
(smoke-add-superclass class nil (class-slot-value class 'parents)))
2009-04-05 tobias
130
15:36:29 '
131
(defun smoke-add-superclass (class classes index)
2009-06-22 tobias
132
(let ((class-index (mem-aref (smoke-module-inheritance-list
12:18:08 '
133
(smoke class))
'
134
'smoke-index
'
135
index)))
2009-07-22 tobias
136
(assert (<= class-index (smoke-array-length
22:26:05 '
137
(smoke-module-classes (smoke class)))))
2009-04-05 tobias
138
(if (= 0 class-index)
15:36:29 '
139
classes
2009-07-22 tobias
140
(smoke-add-superclass
2009-08-02 tobias
141
class
10:12:41 '
142
(append classes
'
143
(list (make-smoke-class-from-id (smoke class) class-index)))
2009-07-22 tobias
144
(1+ index)))))