author | Claus Gittinger <cg@exept.de> |
Wed, 24 Apr 1996 19:55:17 +0200 | |
changeset 1278 | 7ef5a312d87e |
parent 1277 | 7acd342fb251 |
child 1292 | 89497fff7f87 |
permissions | -rw-r--r-- |
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 |
||
620 | 13 |
nil subclass:#Autoload |
938
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
14 |
instanceVariableNames:'' |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
15 |
classVariableNames:'LazyLoading AutoloadFailedSignal LoadedClasses' |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
16 |
poolDictionaries:'' |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
17 |
category:'Kernel-Classes' |
1 | 18 |
! |
19 |
||
68 | 20 |
!Autoload class methodsFor:'documentation'! |
21 |
||
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
154 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
68 | 36 |
documentation |
37 |
" |
|
38 |
In memory limited systems (as my 8Mb 386 is) all seldom-used classes are made |
|
39 |
subclasses of this class. Autoload catches all messages and |
|
40 |
files-In the corresponding code when first used. Then the cought message |
|
41 |
is resent to the (now existing) class. |
|
42 |
||
43 |
Late addition: above comment is no longer true - I have made now almost |
|
44 |
all Demos & Goodies be autoloaded ... even for big systems. |
|
45 |
||
1278 | 46 |
[class variables:] |
92 | 47 |
|
1278 | 48 |
LazyLoading <Boolean> if true, the loaded classes |
49 |
methods will NOT be compiled at |
|
50 |
autoload time, but instead when |
|
51 |
first called. This allows for a |
|
52 |
faster load. However, expect short |
|
53 |
pauses later when the methods are |
|
54 |
first executed. |
|
126 | 55 |
|
1278 | 56 |
AutoloadFailedSignal <Signal> signal raised if an autoloaded |
57 |
classes source is not available. |
|
922 | 58 |
|
1278 | 59 |
LoadedClasses <Collection> set of classes that heve been |
60 |
autoloaded (for later unload) |
|
68 | 61 |
" |
62 |
! ! |
|
63 |
||
126 | 64 |
!Autoload class methodsFor:'initialization'! |
65 |
||
66 |
initialize |
|
67 |
AutoloadFailedSignal isNil ifTrue:[ |
|
624
f09ad5cf21d4
cannot access Objects classVars directly in nil-subclass
Claus Gittinger <cg@exept.de>
parents:
620
diff
changeset
|
68 |
AutoloadFailedSignal := Object errorSignal newSignalMayProceed:true. |
154 | 69 |
AutoloadFailedSignal nameClass:self message:#autoloadFailedSignal. |
70 |
AutoloadFailedSignal notifierString:'autoload failed '. |
|
197 | 71 |
|
72 |
self setSuperclass:nil. |
|
73 |
ObjectMemory flushCaches. |
|
126 | 74 |
] |
75 |
! ! |
|
76 |
||
345 | 77 |
!Autoload class methodsFor:'Signal constants'! |
126 | 78 |
|
79 |
autoloadFailedSignal |
|
80 |
"return the signal raised when an autoload fails" |
|
81 |
||
82 |
^ AutoloadFailedSignal |
|
83 |
! ! |
|
84 |
||
359 | 85 |
!Autoload class methodsFor:'adding/removing autoloaded classes'! |
86 |
||
216 | 87 |
addClass:aClassName |
1277 | 88 |
"given a name, install a corresponding autoload class stub for it" |
89 |
||
216 | 90 |
self addClass:aClassName inCategory:'autoloaded-Classes' |
91 |
||
92 |
" |
|
93 |
Autoload addClass:'Clock' |
|
94 |
" |
|
1277 | 95 |
|
96 |
"Modified: 24.4.1996 / 19:54:16 / cg" |
|
216 | 97 |
! |
98 |
||
99 |
addClass:aClassName inCategory:aCategory |
|
1277 | 100 |
"given a name, install a corresponding autoload class stub for it" |
101 |
||
216 | 102 |
|nameSymbol| |
103 |
||
104 |
nameSymbol := aClassName asSymbol. |
|
105 |
(Smalltalk at:nameSymbol) isNil ifTrue:[ |
|
1277 | 106 |
Autoload subclass:nameSymbol |
107 |
instanceVariableNames:'' |
|
108 |
classVariableNames:'' |
|
109 |
poolDictionaries:'' |
|
110 |
category:aCategory. |
|
216 | 111 |
] |
112 |
" |
|
113 |
Autoload addClass:'Clock' inCategory:'autoloaded-Demos' |
|
114 |
" |
|
1277 | 115 |
|
116 |
"Modified: 24.4.1996 / 19:54:20 / cg" |
|
620 | 117 |
! |
118 |
||
119 |
removeClass:aClass |
|
1277 | 120 |
"remove a class from the list of loaded classes" |
121 |
||
620 | 122 |
LoadedClasses remove:aClass ifAbsent:[] |
1277 | 123 |
|
124 |
"Modified: 24.4.1996 / 19:54:35 / cg" |
|
620 | 125 |
! ! |
126 |
||
127 |
!Autoload class methodsFor:'fileout'! |
|
128 |
||
129 |
fileOutDefinitionOn:aStream |
|
130 |
"print an expression to define myself on aStream. |
|
131 |
Since autoloaded classes dont know their real definition, simply |
|
132 |
output some comment string making things clear in the browser." |
|
133 |
||
709
c31cbd5e5323
more info for autoloaded classes (for browsers definition text)
Claus Gittinger <cg@exept.de>
parents:
661
diff
changeset
|
134 |
|myName fileName nm mgr classFileName packageDir| |
620 | 135 |
|
136 |
(self == Autoload) ifTrue:[^ super fileOutDefinitionOn:aStream]. |
|
137 |
||
138 |
myName := self name. |
|
139 |
aStream nextPutAll:'"' ; nextPutAll:'Notice from Autoload:'; cr; cr; |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
140 |
spaces:4; nextPutAll:myName , ' is not yet loaded.'; cr; cr. |
620 | 141 |
aStream nextPutAll:'to load, execute: '. |
142 |
aStream cr; cr; spaces:4; nextPutAll:myName , ' autoload'; cr. |
|
143 |
||
144 |
" |
|
145 |
the following is simply informative ... |
|
146 |
actually, its a hack & kludge - there ought to be a method for this |
|
147 |
in Smalltalk |
|
148 |
(knowing the details of loading here is no good coding style) |
|
149 |
" |
|
150 |
fileName := Smalltalk fileNameForClass:myName. |
|
151 |
(ObjectFileLoader notNil and:[Smalltalk loadBinaries]) ifTrue:[ |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
152 |
(nm := Smalltalk libraryFileNameOfClass:myName) notNil ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
153 |
nm := nm , ' (a classLibrary, possibly including more classes)' |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
154 |
] ifFalse:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
155 |
nm := Smalltalk getBinaryFileName:(fileName , '.so'). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
156 |
nm isNil ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
157 |
nm := Smalltalk getBinaryFileName:(fileName , '.o') |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
158 |
]. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
159 |
nm notNil ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
160 |
nm := nm , ' (a classBinary)' |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
161 |
] |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
162 |
]. |
620 | 163 |
]. |
164 |
nm isNil ifTrue:[ |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
165 |
nm := Smalltalk getFileInFileName:(fileName , '.st'). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
166 |
nm isNil ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
167 |
nm := Smalltalk getSourceFileName:(fileName , '.st'). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
168 |
]. |
620 | 169 |
]. |
170 |
nm notNil ifTrue:[ |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
171 |
aStream cr; nextPutAll:'When accessed, ' , myName , ' will automatically be loaded'; cr. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
172 |
aStream nextPutAll:'from: '; cr; spaces:4; nextPutAll:nm. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
173 |
nm asFilename isSymbolicLink ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
174 |
aStream cr; cr. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
175 |
aStream nextPutAll:'which is a link to: '; cr; spaces:4; |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
176 |
nextPutAll:(nm asFilename linkInfo at:#path). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
177 |
] |
620 | 178 |
] ifFalse:[ |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
179 |
aStream cr; nextPutAll:'There is currently no file to load ' , myName , ' from.'; cr; cr. |
709
c31cbd5e5323
more info for autoloaded classes (for browsers definition text)
Claus Gittinger <cg@exept.de>
parents:
661
diff
changeset
|
180 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
181 |
(mgr := Smalltalk at:#SourceCodeManager) notNil ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
182 |
classFileName := Smalltalk fileNameForClass:myName. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
183 |
packageDir := Smalltalk sourceDirectoryNameOfClass:myName. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
184 |
]. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
185 |
(classFileName notNil and:[packageDir notNil]) ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
186 |
aStream nextPutAll:'When accessed, I''ll ask the sourceCodeManager to load the code |
709
c31cbd5e5323
more info for autoloaded classes (for browsers definition text)
Claus Gittinger <cg@exept.de>
parents:
661
diff
changeset
|
187 |
from "' , classFileName , '.st" in the "' , packageDir , '" package.'. |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
188 |
] ifFalse:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
189 |
aStream nextPutAll:'When accessed, an error will be reported.'. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
729
diff
changeset
|
190 |
] |
620 | 191 |
]. |
192 |
aStream cr; nextPutAll:'"'. |
|
709
c31cbd5e5323
more info for autoloaded classes (for browsers definition text)
Claus Gittinger <cg@exept.de>
parents:
661
diff
changeset
|
193 |
|
c31cbd5e5323
more info for autoloaded classes (for browsers definition text)
Claus Gittinger <cg@exept.de>
parents:
661
diff
changeset
|
194 |
"Created: 8.12.1995 / 00:31:53 / cg" |
727
475d224376d3
careful with empty source info in descriptive message
Claus Gittinger <cg@exept.de>
parents:
709
diff
changeset
|
195 |
"Modified: 9.12.1995 / 22:31:02 / cg" |
620 | 196 |
! ! |
197 |
||
198 |
!Autoload class methodsFor:'lazy compilation'! |
|
199 |
||
200 |
compileLazy |
|
201 |
"return the lazy loading flag - if on, fileIn is much faster, |
|
202 |
but pauses are to be expected later, since methods are compiled |
|
203 |
when first executed." |
|
204 |
||
205 |
^ LazyLoading |
|
206 |
! |
|
207 |
||
208 |
compileLazy:aBoolean |
|
209 |
"turn on/off lazy loading - if on, fileIn is much faster, |
|
210 |
but pauses are to be expected later, since methods are compiled |
|
211 |
when first executed. |
|
212 |
If you like it, add a line to your startup file." |
|
213 |
||
214 |
LazyLoading := aBoolean |
|
216 | 215 |
! ! |
216 |
||
1 | 217 |
!Autoload class methodsFor:'loading'! |
218 |
||
219 |
autoload |
|
220 |
"use this to force loading |
|
221 |
- it is defined a noop in all non-autoloading clases" |
|
222 |
||
938
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
223 |
|mySelf myName newClass oldMeta project| |
1 | 224 |
|
225 |
mySelf := self. |
|
164 | 226 |
myName := self name asSymbol. |
1 | 227 |
|
228 |
"remove myself - to avoid recompilation" |
|
164 | 229 |
Smalltalk at:myName put:nil. |
1 | 230 |
|
2 | 231 |
"load it" |
68 | 232 |
Transcript showCr:('autoloading ', myName , ' ...'); endEntry. |
1 | 233 |
|
860
b3ffea40999a
use new becomeSameAs: to migrate to new class.
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
234 |
[ |
938
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
235 |
"/ |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
236 |
"/ in order to not get a package of private (or whatever), |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
237 |
"/ temporarily set the currentProject to nil. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
238 |
"/ we will later set the classes package to something useful |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
239 |
"/ |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
240 |
Project notNil ifTrue:[ |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
241 |
project := Project current. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
242 |
Project setProject:nil. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
243 |
]. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
244 |
Smalltalk fileInClass:myName initialize:false lazy:LazyLoading. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
245 |
project notNil ifTrue:[ |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
246 |
Project setProject:project. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
247 |
]. |
860
b3ffea40999a
use new becomeSameAs: to migrate to new class.
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
248 |
] valueOnUnwindDo:[ |
938
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
249 |
project notNil ifTrue:[ |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
250 |
Project setProject:project. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
251 |
]. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
252 |
Smalltalk at:myName put:mySelf. |
860
b3ffea40999a
use new becomeSameAs: to migrate to new class.
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
253 |
]. |
1 | 254 |
|
255 |
"did it work ?" |
|
164 | 256 |
newClass := Smalltalk at:myName. |
257 |
Smalltalk at:myName put:mySelf. "will be undone by become:" |
|
1 | 258 |
|
138 | 259 |
"no - report the error" |
1 | 260 |
newClass isNil ifTrue:[ |
938
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
261 |
" |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
262 |
this signal is raised, if an autoloaded class |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
263 |
cannot be loaded. Usually, this happends when |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
264 |
some sourcefile is missing, not readable or if |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
265 |
an entry is missing in the abbreviation file. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
266 |
Check for a readable file named <myName>.st |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
267 |
in the 'source' directory and (if its a long fileName) |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
268 |
for a corresponding entry in the abbreviation file |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
269 |
'include/abbrev.stc'. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
270 |
Finally, your searchpath could be set wrong - |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
271 |
both 'source' and 'include' directories must be found in |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
272 |
one of the directories named in systemPath. |
154 | 273 |
|
938
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
274 |
In the debugger, press 'abort' to continue execution. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
275 |
" |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
276 |
AutoloadFailedSignal |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
277 |
raiseRequestWith:self |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
278 |
errorString:('autoload of ' , myName , ' failed'). |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
279 |
^ nil |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
280 |
]. |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
281 |
|
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
282 |
"/ |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
283 |
"/ autoloaded classes get their package from the revision (if present) |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
284 |
"/ this only happens with autoloaded sourceFiles which have no package |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
285 |
"/ info encoded. (binary classes have it) |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
286 |
"/ |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
287 |
newClass package isNil ifTrue:[ |
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
288 |
newClass setPackageFromRevision. |
1 | 289 |
]. |
290 |
||
216 | 291 |
LoadedClasses isNil ifTrue:[ |
938
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
292 |
LoadedClasses := IdentitySet new. |
216 | 293 |
]. |
921
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
294 |
LoadedClasses add:newClass. |
216 | 295 |
|
154 | 296 |
"wow - it worked. now the big trick ..." |
1 | 297 |
|
921
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
298 |
"/ newClass class setSoleInstance:self. "/ will be undone by become ... |
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
299 |
oldMeta := self class. |
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
300 |
|
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
301 |
self setName:(self name , ' (auto)'). |
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
302 |
self class setName:(self class name , ' (auto)'). |
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
303 |
|
860
b3ffea40999a
use new becomeSameAs: to migrate to new class.
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
304 |
self becomeSameAs:newClass. |
921
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
305 |
oldMeta becomeSameAs:newClass class. |
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
306 |
|
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
307 |
ObjectMemory flushCaches. |
216 | 308 |
LoadedClasses rehash. |
921
4db7603f9506
rename myself (just in case) & flush caches after loading
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
309 |
|
1148 | 310 |
(newClass class implements:#initialize) ifTrue:[ |
311 |
newClass initialize. |
|
312 |
]. |
|
886 | 313 |
newClass postAutoload. |
314 |
^ newClass |
|
938
a23bc7f62ed1
set package info when autoloading
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
315 |
|
1148 | 316 |
"Modified: 10.4.1996 / 08:52:47 / cg" |
1 | 317 |
! ! |
318 |
||
319 |
!Autoload class methodsFor:'message catching'! |
|
320 |
||
620 | 321 |
basicNew |
1277 | 322 |
"catch basicNew - load the class and send it to the real one" |
620 | 323 |
|
324 |
^ self doesNotUnderstand:(Message selector:#basicNew) |
|
1277 | 325 |
|
326 |
"Modified: 24.4.1996 / 19:53:10 / cg" |
|
620 | 327 |
! |
328 |
||
329 |
basicNew:arg |
|
1277 | 330 |
"catch basicNew: - load the class and send it to the real one" |
620 | 331 |
|
332 |
^ self doesNotUnderstand:(Message selector:#basicNew: with:arg) |
|
1277 | 333 |
|
334 |
"Modified: 24.4.1996 / 19:53:16 / cg" |
|
620 | 335 |
! |
336 |
||
337 |
comment |
|
338 |
"return the classes comment. |
|
339 |
Autoloaded classes have no comment; but I myself have one" |
|
340 |
||
341 |
(self == Autoload) ifTrue:[^ super comment]. |
|
342 |
^ 'not yet loaded' |
|
343 |
! |
|
344 |
||
1 | 345 |
doesNotUnderstand:aMessage |
1277 | 346 |
"cought a message; load the class and retry the message" |
1 | 347 |
|
348 |
|newClass| |
|
349 |
||
164 | 350 |
self ~~ Autoload ifTrue:[ |
1277 | 351 |
newClass := self autoload. |
352 |
newClass notNil ifTrue:[ |
|
353 |
^ newClass perform:(aMessage selector) |
|
354 |
withArguments:(aMessage arguments) |
|
355 |
] |
|
1 | 356 |
]. |
789
155eca125ef0
return value from doesNotUnderstand (so handler can return a value)
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
357 |
^ super doesNotUnderstand:aMessage |
1277 | 358 |
|
359 |
"Modified: 24.4.1996 / 19:53:27 / cg" |
|
1 | 360 |
! |
361 |
||
362 |
new |
|
1277 | 363 |
"catch new - load the class and send it to the real one" |
1 | 364 |
|
365 |
^ self doesNotUnderstand:(Message selector:#new) |
|
1277 | 366 |
|
367 |
"Modified: 24.4.1996 / 19:53:30 / cg" |
|
1 | 368 |
! |
369 |
||
370 |
new:arg |
|
1277 | 371 |
"catch new: - load the class and send it to the real one" |
1 | 372 |
|
373 |
^ self doesNotUnderstand:(Message selector:#new: with:arg) |
|
1277 | 374 |
|
375 |
"Modified: 24.4.1996 / 19:53:32 / cg" |
|
1 | 376 |
! |
377 |
||
378 |
subclass:a1 instanceVariableNames:a2 classVariableNames:a3 poolDictionaries:a4 category:a5 |
|
2 | 379 |
"catch subclass creation - this forces missing superclasses to be |
380 |
loaded first" |
|
381 |
||
68 | 382 |
|newClass sel args| |
1 | 383 |
|
2 | 384 |
"take care: subclassing Autoload must still be possible" |
1 | 385 |
(self == Autoload) ifTrue:[ |
154 | 386 |
^ super |
387 |
subclass:a1 |
|
388 |
instanceVariableNames:a2 |
|
389 |
classVariableNames:a3 |
|
390 |
poolDictionaries:a4 |
|
391 |
category:a5 |
|
1 | 392 |
]. |
393 |
newClass := self autoload. |
|
68 | 394 |
sel := thisContext selector. |
395 |
args := thisContext args. |
|
1 | 396 |
newClass notNil ifTrue:[ |
154 | 397 |
^ newClass perform:sel withArguments:args |
1 | 398 |
]. |
399 |
^ nil |
|
400 |
! ! |
|
11 | 401 |
|
620 | 402 |
!Autoload class methodsFor:'queries'! |
356 | 403 |
|
620 | 404 |
isBehavior |
405 |
"return true if the recevier is some kind of class. |
|
406 |
Autoloaded classes are definitely; therefore return true." |
|
164 | 407 |
|
620 | 408 |
^ true |
409 |
! |
|
356 | 410 |
|
729 | 411 |
isBuiltInClass |
1266 | 412 |
"return true if this class is known by the run-time-system. |
413 |
Returns false here." |
|
414 |
||
729 | 415 |
^ false |
416 |
||
417 |
"Created: 10.12.1995 / 00:28:22 / cg" |
|
1266 | 418 |
"Modified: 23.4.1996 / 15:55:36 / cg" |
729 | 419 |
! |
420 |
||
620 | 421 |
isLoaded |
422 |
"return true, if the class has been loaded; redefined in Autoload; |
|
423 |
see comment there. this allows testing for a class been already loaded." |
|
424 |
||
425 |
^ (self == Autoload) |
|
426 |
! |
|
427 |
||
922 | 428 |
loadedClasses |
429 |
"return the set of classes that were autoloaded" |
|
430 |
||
431 |
^ LoadedClasses |
|
432 |
! |
|
433 |
||
620 | 434 |
wasAutoloaded:aClass |
922 | 435 |
"return true, if aClass was autoloaded" |
436 |
||
620 | 437 |
^ LoadedClasses notNil and:[LoadedClasses includes:aClass] |
11 | 438 |
! ! |
620 | 439 |
|
661 | 440 |
!Autoload class methodsFor:'documentation'! |
441 |
||
442 |
version |
|
1278 | 443 |
^ '$Header: /cvs/stx/stx/libbasic/Autoload.st,v 1.46 1996-04-24 17:55:17 cg Exp $' |
661 | 444 |
! ! |
620 | 445 |
Autoload initialize! |