repos
/
smoke
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
Fix overload resolution when a lisp smoke module is not loaded.
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
((smoke-name :initarg :smoke-name
21:04:08 '
65
:initform nil
'
66
:documentation "The name of the Smoke module"))
2009-04-05 tobias
67
(:report (lambda (condition stream)
2010-01-17 tobias
68
(format stream "No Smoke class named ~S in the Smoke module ~S."
21:04:08 '
69
(cell-error-name condition)
'
70
(slot-value condition 'smoke-name))))
2009-04-05 tobias
71
(:documentation "A undefined Smoke class"))
15:36:29 '
72
2010-01-10 tobias
73
(define-condition lisp-module-not-loaded (error)
17:31:42 '
74
((class-name :initarg :class-name))
'
75
(:report (lambda (condition stream)
'
76
(format stream "The Lisp smoke module of the class ~A is not loaded."
'
77
(slot-value condition 'class-name)))))
'
78
2010-01-17 tobias
79
(defun make-smoke-class (smoke name)
21:04:08 '
80
"Returns the class named NAME of the smoke module SMOKE.
2009-04-05 tobias
81
Signals an undefined-class condition when there is no class for NAME."
15:36:29 '
82
(with-foreign-object (c 'smoke-module-index)
'
83
(do () (nil)
2010-01-17 tobias
84
(smoke-find-class c (smoke-module-pointer smoke) name)
2009-04-05 tobias
85
(restart-case
15:36:29 '
86
(if (null-pointer-p (foreign-slot-value c 'smoke-module-index 'smoke))
2010-01-17 tobias
87
(error (make-condition 'undefined-class :name name :smoke-name (smoke-get-module-name (smoke-module-pointer smoke))))
2009-04-05 tobias
88
(return))
15:36:29 '
89
(supply (new-name)
'
90
:report "Supply a new class name"
'
91
:interactive read-new-value
'
92
(setf name new-name))))
2010-01-10 tobias
93
(let ((class (make-instance
17:31:42 '
94
'smoke-class
'
95
:id (foreign-slot-value c 'smoke-module-index 'index)
'
96
:smoke (gethash (pointer-address (foreign-slot-value
'
97
c 'smoke-module-index
'
98
'smoke))
'
99
*smoke-modules*))))
'
100
(unless (smoke class)
'
101
(error (make-condition 'lisp-module-not-loaded :class-name name)))
'
102
class)))
2009-04-05 tobias
103
15:36:29 '
104
(defun real-class (class)
'
105
"Returns the same class like CLASS, but such that EXTERNAL-P returns NIL."
'
106
(if (external-p class)
2010-01-17 tobias
107
(handler-case (make-smoke-class (smoke class) (name class))
2010-02-16 tobias
108
(undefined-class () class))
2009-04-05 tobias
109
class))
15:36:29 '
110
'
111
(defun class-id (module class)
'
112
"Returns the class id of CLASS for the Smoke module MODULE."
'
113
(if (eq (smoke class) module)
'
114
(id class)
'
115
(smoke-class-id module (name class))))
'
116
2010-02-16 tobias
117
;(defun smoke-subclassp (class base-class) TODO
2009-04-05 tobias
118
(defun derived-p (class base-class)
15:36:29 '
119
"Returns T when CLASS is derived from BASE-CLASS and NIL when not."
2010-02-16 tobias
120
(values
21:52:02 '
121
(derived-real-p (real-class class) (real-class base-class))
'
122
T))
2009-04-05 tobias
123
15:36:29 '
124
(defun derived-real-p (class base-class)
2009-08-02 tobias
125
(smoke-is-derived-from (smoke-module-pointer (smoke class))
10:12:41 '
126
(id class)
'
127
(smoke-module-pointer (smoke base-class))
'
128
(id base-class)))
2009-04-05 tobias
129
15:36:29 '
130
'
131
(defun smoke-class-direct-superclasses (class)
2009-05-26 tobias
132
(smoke-add-superclass class nil (class-slot-value class 'parents)))
2009-04-05 tobias
133
15:36:29 '
134
(defun smoke-add-superclass (class classes index)
2009-06-22 tobias
135
(let ((class-index (mem-aref (smoke-module-inheritance-list
12:18:08 '
136
(smoke class))
'
137
'smoke-index
'
138
index)))
2009-07-22 tobias
139
(assert (<= class-index (smoke-array-length
22:26:05 '
140
(smoke-module-classes (smoke class)))))
2009-04-05 tobias
141
(if (= 0 class-index)
15:36:29 '
142
classes
2009-07-22 tobias
143
(smoke-add-superclass
2009-08-02 tobias
144
class
10:12:41 '
145
(append classes
'
146
(list (make-smoke-class-from-id (smoke class) class-index)))
2009-07-22 tobias
147
(1+ index)))))