18
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
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 |
"
|
|
12 |
|
|
13 |
Method subclass:#LazyMethod
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Kernel-Methods'
|
|
18 |
!
|
|
19 |
|
20
|
20 |
LazyMethod comment:'
|
|
21 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
27
|
23 |
|
|
24 |
$Header: /cvs/stx/stx/libcomp/LazyMethod.st,v 1.3 1994-08-11 21:41:15 claus Exp $
|
20
|
25 |
'!
|
|
26 |
|
|
27 |
!LazyMethod class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
27
|
45 |
$Header: /cvs/stx/stx/libcomp/LazyMethod.st,v 1.3 1994-08-11 21:41:15 claus Exp $
|
20
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
Instances of LazyMethod are created when doing a lazy autoload.
|
|
52 |
When executed, these will trigger an error in the VM (noByteCode),
|
|
53 |
which is cought here to create a real method from the receiver.
|
|
54 |
This allows faster loading of code, which will then be compiled
|
|
55 |
when first executed; for classes with a large number of methods, of
|
|
56 |
which only a small subset is actually used, this can also save
|
|
57 |
lots of memory.
|
|
58 |
"
|
|
59 |
! !
|
|
60 |
|
27
|
61 |
!LazyMethod methodsFor:'queries'!
|
|
62 |
|
|
63 |
isLazyMethod
|
|
64 |
^ true
|
|
65 |
! !
|
|
66 |
|
18
|
67 |
!LazyMethod methodsFor:'error handling'!
|
|
68 |
|
|
69 |
noByteCode
|
|
70 |
"this error is triggered by the interpreter when a lazy method
|
|
71 |
is about to be executed (by sending the bad method this message);
|
|
72 |
hard-compile the method now, install its bytecode in the receiver,
|
|
73 |
and call it now."
|
|
74 |
|
|
75 |
|code m lazy sender|
|
|
76 |
|
|
77 |
"compile the method"
|
|
78 |
|
|
79 |
lazy := Compiler compileLazy:false.
|
|
80 |
[
|
|
81 |
m := self asByteCodeMethod.
|
|
82 |
] valueNowOrOnUnwindDo:[
|
|
83 |
Compiler compileLazy:lazy.
|
|
84 |
].
|
|
85 |
|
|
86 |
m isNil ifTrue:[^ super invalidMethod].
|
|
87 |
byteCode := m byteCode.
|
|
88 |
sender := thisContext sender.
|
|
89 |
byteCode notNil ifTrue:[
|
|
90 |
literals := m literals.
|
|
91 |
flags := m flags.
|
|
92 |
"
|
|
93 |
thisContext sender is the original sends (the failed ones)
|
|
94 |
context ...
|
|
95 |
"
|
27
|
96 |
ObjectMemory flushCaches.
|
18
|
97 |
^ self valueWithReceiver:(sender receiver)
|
|
98 |
arguments:(sender args)
|
|
99 |
selector:(sender selector)
|
|
100 |
].
|
|
101 |
self error:'cannot compile method'
|
|
102 |
! !
|