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