|
1 " |
|
2 COPYRIGHT (c) 1991-93 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 Object subclass:#Autoload |
|
14 instanceVariableNames:'' |
|
15 classVariableNames:'' |
|
16 poolDictionaries:'' |
|
17 category:'Kernel-Classes' |
|
18 ! |
|
19 |
|
20 Autoload comment:' |
|
21 |
|
22 COPYRIGHT (c) 1991-93 by Claus Gittinger |
|
23 All Rights Reserved |
|
24 |
|
25 In memory limited systems (as my 8Mb 386 is) all seldom-used classes are made |
|
26 subclasses of this class. Autoload catches all messages and |
|
27 files-In the corresponding code when first used. Then the cought message |
|
28 is resent to the (now existing) class. |
|
29 |
|
30 %W% %E% |
|
31 written fall 91 by claus |
|
32 '! |
|
33 |
|
34 !Autoload class methodsFor:'loading'! |
|
35 |
|
36 autoload |
|
37 "use this to force loading |
|
38 - it is defined a noop in all non-autoloading clases" |
|
39 |
|
40 |mySelf myName mySym newClass| |
|
41 |
|
42 mySelf := self. |
|
43 myName := self name. |
|
44 mySym := myName asSymbol. |
|
45 |
|
46 "remove myself - to avoid recompilation" |
|
47 Smalltalk at:mySym put:nil. |
|
48 |
|
49 "load" |
|
50 Transcript showCr:('autoloading ', myName , ' ...'). |
|
51 |
|
52 Smalltalk fileInClass:myName. |
|
53 |
|
54 "did it work ?" |
|
55 newClass := Smalltalk at:mySym. |
|
56 Smalltalk at:mySym put:mySelf. "will be undone by become:" |
|
57 |
|
58 newClass isNil ifTrue:[ |
|
59 "no - reinstall myself" |
|
60 self warn:('autoload of ' , myName , ' failed'). |
|
61 ^ nil |
|
62 ]. |
|
63 |
|
64 "wow - it did" |
|
65 |
|
66 self become:newClass. |
|
67 ^ self |
|
68 ! ! |
|
69 |
|
70 !Autoload class methodsFor:'message catching'! |
|
71 |
|
72 doesNotUnderstand:aMessage |
|
73 "cought a message; load class and retry" |
|
74 |
|
75 |newClass| |
|
76 |
|
77 newClass := self autoload. |
|
78 newClass notNil ifTrue:[ |
|
79 ^ newClass perform:(aMessage selector) |
|
80 withArguments:(aMessage arguments) |
|
81 ]. |
|
82 super doesNotUnderstand:aMessage |
|
83 ! |
|
84 |
|
85 new |
|
86 "catch new" |
|
87 |
|
88 ^ self doesNotUnderstand:(Message selector:#new) |
|
89 ! |
|
90 |
|
91 basicNew |
|
92 "catch basicNew" |
|
93 |
|
94 ^ self doesNotUnderstand:(Message selector:#basicew) |
|
95 ! |
|
96 |
|
97 new:arg |
|
98 "catch new:" |
|
99 |
|
100 ^ self doesNotUnderstand:(Message selector:#new: with:arg) |
|
101 ! |
|
102 |
|
103 basicNew:arg |
|
104 "catch basicNew:" |
|
105 |
|
106 ^ self doesNotUnderstand:(Message selector:#basicNew: with:arg) |
|
107 ! |
|
108 |
|
109 subclass:a1 instanceVariableNames:a2 classVariableNames:a3 poolDictionaries:a4 category:a5 |
|
110 |newClass| |
|
111 |
|
112 (self == Autoload) ifTrue:[ |
|
113 ^ super subclass:a1 instanceVariableNames:a2 classVariableNames:a3 poolDictionaries:a4 category:a5 |
|
114 ]. |
|
115 newClass := self autoload. |
|
116 newClass notNil ifTrue:[ |
|
117 ^ newClass perform:(thisContext selector) |
|
118 withArguments:(thisContext args) |
|
119 ]. |
|
120 ^ nil |
|
121 ! ! |