1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
154
|
3 |
All Rights Reserved
|
1
|
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 |
Object subclass:#Autoload
|
|
14 |
instanceVariableNames:''
|
216
|
15 |
classVariableNames:'LazyLoading AutoloadFailedSignal LoadedClasses'
|
1
|
16 |
poolDictionaries:''
|
|
17 |
category:'Kernel-Classes'
|
|
18 |
!
|
|
19 |
|
|
20 |
Autoload comment:'
|
5
|
21 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
154
|
22 |
All Rights Reserved
|
92
|
23 |
|
254
|
24 |
$Header: /cvs/stx/stx/libbasic/Autoload.st,v 1.17 1995-02-15 11:29:30 claus Exp $
|
1
|
25 |
'!
|
|
26 |
|
68
|
27 |
!Autoload class methodsFor:'documentation'!
|
|
28 |
|
88
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
154
|
32 |
All Rights Reserved
|
88
|
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 |
"
|
254
|
45 |
$Header: /cvs/stx/stx/libbasic/Autoload.st,v 1.17 1995-02-15 11:29:30 claus Exp $
|
88
|
46 |
"
|
|
47 |
!
|
|
48 |
|
68
|
49 |
documentation
|
|
50 |
"
|
|
51 |
In memory limited systems (as my 8Mb 386 is) all seldom-used classes are made
|
|
52 |
subclasses of this class. Autoload catches all messages and
|
|
53 |
files-In the corresponding code when first used. Then the cought message
|
|
54 |
is resent to the (now existing) class.
|
|
55 |
|
|
56 |
Late addition: above comment is no longer true - I have made now almost
|
|
57 |
all Demos & Goodies be autoloaded ... even for big systems.
|
|
58 |
|
|
59 |
class variables:
|
92
|
60 |
|
154
|
61 |
LazyLoading <Boolean> if true, the loaded classes
|
|
62 |
methods will NOT be compiled at
|
|
63 |
autoload time, but instead when
|
|
64 |
first called. This allows for a
|
|
65 |
faster load. However, expect short
|
|
66 |
pauses later when the methods are
|
|
67 |
first executed.
|
126
|
68 |
|
154
|
69 |
AutoloadFailedSignal <Signal> signal raised if an autoloaded
|
|
70 |
classes source is not available.
|
68
|
71 |
"
|
|
72 |
! !
|
|
73 |
|
126
|
74 |
!Autoload class methodsFor:'initialization'!
|
|
75 |
|
|
76 |
initialize
|
|
77 |
AutoloadFailedSignal isNil ifTrue:[
|
154
|
78 |
Object initialize.
|
|
79 |
|
|
80 |
AutoloadFailedSignal := Object errorSignal newSignalMayProceed:true.
|
|
81 |
AutoloadFailedSignal nameClass:self message:#autoloadFailedSignal.
|
|
82 |
AutoloadFailedSignal notifierString:'autoload failed '.
|
197
|
83 |
|
|
84 |
self setSuperclass:nil.
|
|
85 |
ObjectMemory flushCaches.
|
126
|
86 |
]
|
|
87 |
! !
|
|
88 |
|
|
89 |
!Autoload class methodsFor:'signal access'!
|
|
90 |
|
|
91 |
autoloadFailedSignal
|
|
92 |
"return the signal raised when an autoload fails"
|
|
93 |
|
|
94 |
^ AutoloadFailedSignal
|
|
95 |
! !
|
|
96 |
|
2
|
97 |
!Autoload class methodsFor:'queries'!
|
|
98 |
|
|
99 |
isLoaded
|
|
100 |
"return true, if the class has been loaded; redefined in Autoload;
|
|
101 |
see comment there. this allows testing for a class been already loaded."
|
|
102 |
|
164
|
103 |
^ (self == Autoload)
|
216
|
104 |
!
|
|
105 |
|
|
106 |
wasAutoloaded:aClass
|
|
107 |
^ LoadedClasses notNil and:[LoadedClasses includes:aClass]
|
2
|
108 |
! !
|
|
109 |
|
68
|
110 |
!Autoload class methodsFor:'lazy compilation'!
|
|
111 |
|
|
112 |
compileLazy:aBoolean
|
|
113 |
"turn on/off lazy loading - if on, fileIn is much faster,
|
|
114 |
but pauses are to be expected later.
|
|
115 |
If you like it, add a line to your startup file."
|
|
116 |
|
|
117 |
LazyLoading := aBoolean
|
|
118 |
! !
|
|
119 |
|
216
|
120 |
!Autoload class methodsFor:'adding autoloaded classes'!
|
|
121 |
|
|
122 |
addClass:aClassName
|
|
123 |
self addClass:aClassName inCategory:'autoloaded-Classes'
|
|
124 |
|
|
125 |
"
|
|
126 |
Autoload addClass:'Clock'
|
|
127 |
"
|
|
128 |
!
|
|
129 |
|
|
130 |
addClass:aClassName inCategory:aCategory
|
|
131 |
|nameSymbol|
|
|
132 |
|
|
133 |
nameSymbol := aClassName asSymbol.
|
|
134 |
(Smalltalk at:nameSymbol) isNil ifTrue:[
|
|
135 |
Autoload subclass:nameSymbol
|
|
136 |
instanceVariableNames:''
|
|
137 |
classVariableNames:''
|
|
138 |
poolDictionaries:''
|
|
139 |
category:aCategory.
|
|
140 |
]
|
|
141 |
"
|
|
142 |
Autoload addClass:'Clock' inCategory:'autoloaded-Demos'
|
|
143 |
"
|
|
144 |
! !
|
|
145 |
|
1
|
146 |
!Autoload class methodsFor:'loading'!
|
|
147 |
|
|
148 |
autoload
|
|
149 |
"use this to force loading
|
|
150 |
- it is defined a noop in all non-autoloading clases"
|
|
151 |
|
254
|
152 |
|mySelf myName newClass|
|
1
|
153 |
|
|
154 |
mySelf := self.
|
164
|
155 |
myName := self name asSymbol.
|
1
|
156 |
|
|
157 |
"remove myself - to avoid recompilation"
|
164
|
158 |
Smalltalk at:myName put:nil.
|
1
|
159 |
|
2
|
160 |
"load it"
|
68
|
161 |
Transcript showCr:('autoloading ', myName , ' ...'); endEntry.
|
1
|
162 |
|
216
|
163 |
Smalltalk fileInClass:myName initialize:false lazy:LazyLoading.
|
1
|
164 |
|
|
165 |
"did it work ?"
|
164
|
166 |
newClass := Smalltalk at:myName.
|
|
167 |
Smalltalk at:myName put:mySelf. "will be undone by become:"
|
1
|
168 |
|
138
|
169 |
"no - report the error"
|
1
|
170 |
newClass isNil ifTrue:[
|
138
|
171 |
"
|
|
172 |
this signal is raised, if an autoloaded class
|
|
173 |
cannot be loaded. Usually, this happends when
|
154
|
174 |
some sourcefile is missing, not readable or if
|
|
175 |
an entry is missing in the abbreviation file.
|
|
176 |
Check for a readable file named <myName>.st
|
|
177 |
in the 'source' directory and (if its a long fileName)
|
|
178 |
for a corresponding entry in the abbreviation file
|
|
179 |
'include/abbrev.stc'.
|
|
180 |
Finally, your searchpath could be set wrong -
|
|
181 |
both 'source' and 'include' directories must be found in
|
|
182 |
one of the directories named in systemPath.
|
|
183 |
|
|
184 |
In the debugger, press 'abort' to continue execution.
|
138
|
185 |
"
|
154
|
186 |
AutoloadFailedSignal
|
126
|
187 |
raiseRequestWith:self
|
154
|
188 |
errorString:('autoload of ' , myName , ' failed').
|
|
189 |
^ nil
|
1
|
190 |
].
|
|
191 |
|
216
|
192 |
LoadedClasses isNil ifTrue:[
|
|
193 |
LoadedClasses := IdentitySet new.
|
|
194 |
].
|
|
195 |
LoadedClasses add:self.
|
|
196 |
|
154
|
197 |
"wow - it worked. now the big trick ..."
|
1
|
198 |
|
|
199 |
self become:newClass.
|
216
|
200 |
LoadedClasses rehash.
|
|
201 |
self initialize. "/ thats the new class now
|
154
|
202 |
^ self "this is now the new class - see what doesNotUnderstand: does with it"
|
1
|
203 |
! !
|
|
204 |
|
|
205 |
!Autoload class methodsFor:'message catching'!
|
|
206 |
|
|
207 |
doesNotUnderstand:aMessage
|
|
208 |
"cought a message; load class and retry"
|
|
209 |
|
|
210 |
|newClass|
|
|
211 |
|
164
|
212 |
self ~~ Autoload ifTrue:[
|
|
213 |
newClass := self autoload.
|
|
214 |
newClass notNil ifTrue:[
|
|
215 |
^ newClass perform:(aMessage selector)
|
|
216 |
withArguments:(aMessage arguments)
|
|
217 |
]
|
1
|
218 |
].
|
|
219 |
super doesNotUnderstand:aMessage
|
|
220 |
!
|
|
221 |
|
|
222 |
new
|
|
223 |
"catch new"
|
|
224 |
|
|
225 |
^ self doesNotUnderstand:(Message selector:#new)
|
|
226 |
!
|
|
227 |
|
|
228 |
basicNew
|
|
229 |
"catch basicNew"
|
|
230 |
|
213
|
231 |
^ self doesNotUnderstand:(Message selector:#basicNew)
|
1
|
232 |
!
|
|
233 |
|
|
234 |
new:arg
|
|
235 |
"catch new:"
|
|
236 |
|
|
237 |
^ self doesNotUnderstand:(Message selector:#new: with:arg)
|
|
238 |
!
|
|
239 |
|
|
240 |
basicNew:arg
|
|
241 |
"catch basicNew:"
|
|
242 |
|
|
243 |
^ self doesNotUnderstand:(Message selector:#basicNew: with:arg)
|
|
244 |
!
|
|
245 |
|
|
246 |
subclass:a1 instanceVariableNames:a2 classVariableNames:a3 poolDictionaries:a4 category:a5
|
2
|
247 |
"catch subclass creation - this forces missing superclasses to be
|
|
248 |
loaded first"
|
|
249 |
|
68
|
250 |
|newClass sel args|
|
1
|
251 |
|
2
|
252 |
"take care: subclassing Autoload must still be possible"
|
1
|
253 |
(self == Autoload) ifTrue:[
|
154
|
254 |
^ super
|
|
255 |
subclass:a1
|
|
256 |
instanceVariableNames:a2
|
|
257 |
classVariableNames:a3
|
|
258 |
poolDictionaries:a4
|
|
259 |
category:a5
|
1
|
260 |
].
|
|
261 |
newClass := self autoload.
|
68
|
262 |
sel := thisContext selector.
|
|
263 |
args := thisContext args.
|
1
|
264 |
newClass notNil ifTrue:[
|
154
|
265 |
^ newClass perform:sel withArguments:args
|
1
|
266 |
].
|
|
267 |
^ nil
|
68
|
268 |
!
|
|
269 |
|
|
270 |
comment
|
164
|
271 |
(self == Autoload) ifTrue:[^ super comment].
|
68
|
272 |
^ 'not yet loaded'
|
1
|
273 |
! !
|
11
|
274 |
|
|
275 |
!Autoload class methodsFor:'fileout'!
|
|
276 |
|
|
277 |
fileOutDefinitionOn:aStream
|
92
|
278 |
"print an expression to define myself on aStream.
|
|
279 |
Since autoloaded classes dont know their real definition, simply
|
|
280 |
output some comment string making things clear."
|
11
|
281 |
|
164
|
282 |
(self == Autoload) ifTrue:[^ super fileOutDefinitionOn:aStream].
|
|
283 |
|
|
284 |
aStream nextPutAll:'''' , self name , ' is not yet loaded.'; cr.
|
|
285 |
aStream nextPutAll:' to load, execute: '.
|
|
286 |
aStream cr; cr; spaces:4; nextPutAll:self name , ' autoload'; cr.
|
|
287 |
aStream nextPutAll:''''.
|
11
|
288 |
! !
|