author | Claus Gittinger <cg@exept.de> |
Fri, 09 Aug 2019 12:02:21 +0200 | |
changeset 4467 | 4698a67f4800 |
parent 4403 | 4649f9dd9614 |
child 4587 | 07094cd02017 |
permissions | -rw-r--r-- |
18 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 3 |
All Rights Reserved |
18 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1053
ecffa1f6ce6e
slightly faster #resources access if there are no resources
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
12 |
"{ Package: 'stx:libcomp' }" |
ecffa1f6ce6e
slightly faster #resources access if there are no resources
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
13 |
|
4208 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
799 | 16 |
Method variableSubclass:#LazyMethod |
249
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
17 |
instanceVariableNames:'' |
853
9914057fa471
moved recompilation semaphore from LazyMethod to Method
Claus Gittinger <cg@exept.de>
parents:
852
diff
changeset
|
18 |
classVariableNames:'CompilationFailedSignal' |
249
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
19 |
poolDictionaries:'' |
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
20 |
category:'Kernel-Methods' |
18 | 21 |
! |
22 |
||
799 | 23 |
!LazyMethod class methodsFor:'documentation'! |
20 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
45 | 28 |
All Rights Reserved |
20 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
Instances of LazyMethod are created when doing a lazy autoload. |
|
45 | 42 |
They do not contain any code (neither byte- nor machinecode), but |
43 |
keep their sourcecode only. |
|
44 |
||
20 | 45 |
When executed, these will trigger an error in the VM (noByteCode), |
533 | 46 |
which is caught here to create a real method from the receiver, |
45 | 47 |
amd re-execute the method. |
48 |
||
49 |
This allows faster loading of code, which will be later compiled |
|
20 | 50 |
when first executed; for classes with a large number of methods, of |
51 |
which only a small subset is actually used, this can also save |
|
45 | 52 |
lots of memory (beside making autoloading faster). |
262 | 53 |
|
54 |
[author:] |
|
55 |
Claus Gittinger |
|
56 |
||
57 |
[see also:] |
|
58 |
Autoload |
|
20 | 59 |
" |
60 |
! ! |
|
61 |
||
799 | 62 |
!LazyMethod class methodsFor:'initialization'! |
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
63 |
|
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
64 |
initialize |
45 | 65 |
CompilationFailedSignal isNil ifTrue:[ |
1452
957cd8579489
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
1450
diff
changeset
|
66 |
CompilationFailedSignal := InvalidCodeError newSignalMayProceed:true. |
852
ec002c00033a
moved recompilation semaphore from LazyMethod to Method
Claus Gittinger <cg@exept.de>
parents:
799
diff
changeset
|
67 |
CompilationFailedSignal nameClass:self message:#compilationFailedSignal. |
ec002c00033a
moved recompilation semaphore from LazyMethod to Method
Claus Gittinger <cg@exept.de>
parents:
799
diff
changeset
|
68 |
CompilationFailedSignal notifierString:'compilation of lazy method failed'. |
45 | 69 |
] |
70 |
! ! |
|
71 |
||
799 | 72 |
!LazyMethod class methodsFor:'Signal constants'! |
45 | 73 |
|
74 |
compilationFailedSignal |
|
75 |
^ CompilationFailedSignal |
|
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
76 |
! ! |
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
77 |
|
54 | 78 |
!LazyMethod methodsFor:'compiling'! |
18 | 79 |
|
54 | 80 |
makeRealMethod |
81 |
"make the receiver a real method; i.e. compile the sourcecode and |
|
82 |
fill in the bytecode. This must be done in order to execute the receiver." |
|
18 | 83 |
|
54 | 84 |
|m| |
18 | 85 |
|
86 |
"compile the method" |
|
87 |
||
88 |
[ |
|
852
ec002c00033a
moved recompilation semaphore from LazyMethod to Method
Claus Gittinger <cg@exept.de>
parents:
799
diff
changeset
|
89 |
m := self asExecutableMethod. |
45 | 90 |
] valueUninterruptably. |
91 |
||
799 | 92 |
(m isNil |
93 |
or:[(byteCode := m byteCode) isNil |
|
94 |
and:[m hasCode not]]) ifTrue:[ |
|
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
95 |
" |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
96 |
compilation failed |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
97 |
" |
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
98 |
^ nil |
54 | 99 |
]. |
292
163651658aee
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
262
diff
changeset
|
100 |
self literals:m literals. |
54 | 101 |
flags := m flags. |
126 | 102 |
self code:(m code). |
54 | 103 |
self changeClassToThatOf:m. |
104 |
^ self |
|
126 | 105 |
|
799 | 106 |
"Created: / 24.10.1995 / 14:02:50 / cg" |
107 |
"Modified: / 24.6.1996 / 17:23:57 / stefan" |
|
108 |
"Modified: / 13.11.1998 / 23:20:41 / cg" |
|
54 | 109 |
! ! |
110 |
||
111 |
!LazyMethod methodsFor:'error handling'! |
|
112 |
||
113 |
noByteCode |
|
114 |
"this is triggered by the interpreter when a lazy method is about to |
|
115 |
be executed (by sending the to-be executed method this message). |
|
116 |
Hard-compile the method, install its bytecode in the receiver, |
|
117 |
and recall it." |
|
118 |
||
119 |
|sender spec class selector| |
|
120 |
||
4403 | 121 |
sender := thisContext sender. |
122 |
selector := sender selector. |
|
123 |
||
54 | 124 |
"compile the method" |
125 |
||
126 |
self makeRealMethod isNil ifTrue:[ |
|
4403 | 127 |
"/ compilation failed |
986
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
128 |
class := self containingClass. |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
129 |
class notNil ifTrue:[ |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
130 |
spec := class name , '>>' , selector |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
131 |
] ifFalse:[ |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
132 |
spec := 'unknown>>' , selector |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
133 |
]. |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
134 |
" |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
135 |
this error is triggered, if the compilation of a lazy method |
4208 | 136 |
failed - this happens for example, if a lazy method's code has been |
986
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
137 |
changed in a fileBrowser without checking the code for syntactical |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
138 |
correctnes, or if the instvars of an autoloaded classes superclass |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
139 |
have been changed without changing the subclasses code ... |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
140 |
You should enter the SystemBrowser on this method, and try accepting |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
141 |
to see what the problem is. |
4208 | 142 |
The method's class is found in the local 'class', |
986
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
143 |
the selector is found in the local 'selector'. |
45 | 144 |
|
986
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
145 |
As a general rule: never edit autoloaded classes from anything |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
146 |
except the browser - to check that they work and are compilable. |
0398d8de8242
when resending a method after it has been compiled
Claus Gittinger <cg@exept.de>
parents:
892
diff
changeset
|
147 |
" |
4403 | 148 |
^ CompilationFailedSignal |
149 |
raiseRequestWith:self |
|
150 |
errorString:('compilation of lazy method ' , spec , ' failed') |
|
40
45ecd4441edb
compilation is donw in critical region - it was not reentrant
claus
parents:
27
diff
changeset
|
151 |
]. |
45 | 152 |
|
153 |
" |
|
154 |
Now, the receiver method has mutated into a real (non-lazy) one. |
|
155 |
Get the original message receiver and args, and execute the method. |
|
156 |
||
157 |
ThisContext sender is the context of the original send (the failed one) |
|
158 |
" |
|
159 |
ObjectMemory flushCaches. |
|
160 |
||
4403 | 161 |
^ self |
162 |
valueWithReceiver:(sender receiver) |
|
163 |
arguments:(sender args) |
|
164 |
selector:selector |
|
165 |
search:(sender searchClass) |
|
166 |
sender:nil |
|
4208 | 167 |
|
168 |
"Modified (comment): / 21-11-2017 / 13:02:50 / cg" |
|
4403 | 169 |
"Modified (format): / 03-04-2019 / 22:39:44 / Claus Gittinger" |
18 | 170 |
! ! |
142 | 171 |
|
172 |
!LazyMethod methodsFor:'queries'! |
|
173 |
||
174 |
isLazyMethod |
|
175 |
^ true |
|
891 | 176 |
! |
177 |
||
1072
99bd12c0fe76
always return an array from #literals
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
178 |
literals |
99bd12c0fe76
always return an array from #literals
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
179 |
"cannot ask a lazyMethod for literals ..." |
99bd12c0fe76
always return an array from #literals
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
180 |
|
99bd12c0fe76
always return an array from #literals
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
181 |
|m| |
99bd12c0fe76
always return an array from #literals
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
182 |
|
99bd12c0fe76
always return an array from #literals
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
183 |
(m := self asExecutableMethod) notNil ifTrue:[^ m literals]. |
99bd12c0fe76
always return an array from #literals
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
184 |
^ #() |
99bd12c0fe76
always return an array from #literals
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
185 |
! |
99bd12c0fe76
always return an array from #literals
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
186 |
|
2275
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
187 |
literalsDetect:aBlock ifNone:exceptionalValue |
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
188 |
"cannot ask a lazyMethod for literals ..." |
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
189 |
|
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
190 |
|m| |
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
191 |
|
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
192 |
(m := self asExecutableMethod) notNil ifTrue:[^ m literalsDetect:aBlock ifNone:exceptionalValue]. |
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
193 |
^ exceptionalValue value |
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
194 |
! |
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
195 |
|
1083
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
196 |
messagesSent |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
197 |
"cannot ask a lazyMethod for messagesSent ..." |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
198 |
|
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
199 |
|m| |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
200 |
|
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
201 |
(m := self asExecutableMethod) notNil ifTrue:[^ m messagesSent]. |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
202 |
^ #() |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
203 |
! |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
204 |
|
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
205 |
messagesSentToSelf |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
206 |
"cannot ask a lazyMethod for messagesSentToSelf ..." |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
207 |
|
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
208 |
|m| |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
209 |
|
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
210 |
(m := self asExecutableMethod) notNil ifTrue:[^ m messagesSentToSelf]. |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
211 |
^ #() |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
212 |
! |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
213 |
|
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
214 |
messagesSentToSuper |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
215 |
"cannot ask a lazyMethod for messagesSentToSuper ..." |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
216 |
|
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
217 |
|m| |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
218 |
|
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
219 |
(m := self asExecutableMethod) notNil ifTrue:[^ m messagesSentToSuper]. |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
220 |
^ #() |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
221 |
! |
c66b7d5dcc92
added #messagesSentToSelf, toSuper and sent
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
222 |
|
891 | 223 |
resources |
224 |
"cannot ask a lazyMethod for resources ..." |
|
225 |
||
892 | 226 |
|m| |
227 |
||
1115
ca9303f55111
better resource parsing (without compiling)
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
228 |
^ self parseResources. |
ca9303f55111
better resource parsing (without compiling)
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
229 |
"/ (self source includesString:'resource') ifFalse:[^ nil]. |
ca9303f55111
better resource parsing (without compiling)
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
230 |
"/ |
ca9303f55111
better resource parsing (without compiling)
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
231 |
"/ (m := self asExecutableMethod) notNil ifTrue:[^ m resources]. |
ca9303f55111
better resource parsing (without compiling)
Claus Gittinger <cg@exept.de>
parents:
1083
diff
changeset
|
232 |
"/ ^ nil |
142 | 233 |
! ! |
234 |
||
799 | 235 |
!LazyMethod class methodsFor:'documentation'! |
249
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
236 |
|
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
237 |
version |
4208 | 238 |
^ '$Header$' |
2275
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
239 |
! |
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
240 |
|
726c29682fd8
added: #literalsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
241 |
version_CVS |
4208 | 242 |
^ '$Header$' |
249
fb82fccfb779
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
190
diff
changeset
|
243 |
! ! |
1450 | 244 |
|
4208 | 245 |
|
142 | 246 |
LazyMethod initialize! |