1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
159
|
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:#Smalltalk
|
|
14 |
instanceVariableNames:''
|
7
|
15 |
classVariableNames:'ExitBlocks CachedClasses SystemPath
|
159
|
16 |
StartupClass StartupSelector StartupArguments
|
|
17 |
CachedAbbreviations
|
|
18 |
SilentLoading Initializing
|
|
19 |
StandAlone
|
|
20 |
LogDoits'
|
1
|
21 |
poolDictionaries:''
|
|
22 |
category:'System-Support'
|
|
23 |
!
|
|
24 |
|
|
25 |
Smalltalk comment:'
|
5
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
159
|
27 |
All Rights Reserved
|
95
|
28 |
|
161
|
29 |
$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.23 1994-10-10 03:51:02 claus Exp $
|
1
|
30 |
'!
|
|
31 |
|
70
|
32 |
"
|
|
33 |
dont depend on these being global - they will become
|
|
34 |
class variables of some class ...
|
|
35 |
Being global is a historical leftover ...
|
|
36 |
"
|
1
|
37 |
Smalltalk at:#Language put:#english!
|
|
38 |
Smalltalk at:#LanguageTerritory put:#usa!
|
70
|
39 |
|
|
40 |
!Smalltalk class methodsFor:'documentation'!
|
|
41 |
|
95
|
42 |
copyright
|
|
43 |
"
|
|
44 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
159
|
45 |
All Rights Reserved
|
95
|
46 |
|
|
47 |
This software is furnished under a license and may be used
|
|
48 |
only in accordance with the terms of that license and with the
|
|
49 |
inclusion of the above copyright notice. This software may not
|
|
50 |
be provided or otherwise made available to, or used by, any
|
|
51 |
other person. No title to or ownership of the software is
|
|
52 |
hereby transferred.
|
|
53 |
"
|
|
54 |
!
|
|
55 |
|
|
56 |
version
|
|
57 |
"
|
161
|
58 |
$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.23 1994-10-10 03:51:02 claus Exp $
|
95
|
59 |
"
|
|
60 |
!
|
|
61 |
|
70
|
62 |
documentation
|
|
63 |
"
|
|
64 |
This is one of the central classes in the system;
|
|
65 |
it provides all system-startup, shutdown and maintenance support.
|
|
66 |
Also global variables are kept here.
|
|
67 |
|
|
68 |
As you will notice, this is NOT a Dictionary
|
|
69 |
- my implementation of globals is totally different
|
|
70 |
(due to the need to be able to access globals from c-code as well).
|
|
71 |
However, it provides the known enumeration protocol.
|
|
72 |
It may change to become a subclass of collection at some time ...
|
|
73 |
|
|
74 |
Instance variables:
|
159
|
75 |
none - all handling is done in the VM
|
70
|
76 |
|
|
77 |
Class variables:
|
159
|
78 |
ExitBlocks <Collection> blocks to evaluate before system is
|
|
79 |
left. Not currently used.
|
70
|
80 |
|
159
|
81 |
CachedClasses <Collection> known classes (cached for faster enumeration)
|
70
|
82 |
|
159
|
83 |
SystemPath <Collection> path to search for system files (sources, bitmaps etc)
|
70
|
84 |
|
159
|
85 |
StartupClass <Class> class, which gets initial message
|
|
86 |
(right after VM initialization)
|
|
87 |
StartupSelector <Symbol> message sent to StartupClass
|
70
|
88 |
|
159
|
89 |
CachedAbbreviations
|
|
90 |
<Dictionary> className to filename mappings
|
70
|
91 |
|
159
|
92 |
SilentLoading <Boolean> suppresses messages during fileIn and in compiler
|
|
93 |
(can be set to true from a customized main)
|
122
|
94 |
|
159
|
95 |
LogDoits <Boolean> if true, doits are also logged in the changes
|
|
96 |
file. Default is false, since the changes file
|
|
97 |
may become huge ...
|
70
|
98 |
"
|
|
99 |
! !
|
1
|
100 |
|
|
101 |
!Smalltalk class methodsFor:'time-versions'!
|
|
102 |
|
|
103 |
majorVersion
|
85
|
104 |
"return the major version number.
|
|
105 |
This is only incremented for very fundamental changes,
|
|
106 |
which make old object files totally incompatible
|
|
107 |
(for example, if the layout/representation of fundamental
|
|
108 |
classes changes)."
|
1
|
109 |
|
|
110 |
^ 2
|
|
111 |
|
85
|
112 |
"
|
|
113 |
Smalltalk majorVersion
|
|
114 |
"
|
1
|
115 |
!
|
|
116 |
|
|
117 |
minorVersion
|
85
|
118 |
"return the minor version number.
|
|
119 |
This is incremented for changes which make some old object
|
|
120 |
files incompatible, or the protocol changes such that some
|
|
121 |
classes need rework."
|
1
|
122 |
|
70
|
123 |
^ 10
|
1
|
124 |
|
85
|
125 |
"
|
|
126 |
Smalltalk minorVersion
|
|
127 |
"
|
1
|
128 |
!
|
|
129 |
|
|
130 |
revision
|
85
|
131 |
"return the revision number.
|
|
132 |
Incremented for releases which fix bugs/add features."
|
1
|
133 |
|
95
|
134 |
^ 3
|
1
|
135 |
|
85
|
136 |
"
|
|
137 |
Smalltalk revision
|
|
138 |
"
|
1
|
139 |
!
|
|
140 |
|
95
|
141 |
versionString
|
1
|
142 |
"return the version string"
|
|
143 |
|
|
144 |
^ (self majorVersion printString ,
|
|
145 |
'.',
|
|
146 |
self minorVersion printString ,
|
|
147 |
'.',
|
|
148 |
self revision printString)
|
|
149 |
|
85
|
150 |
"
|
95
|
151 |
Smalltalk versionString
|
85
|
152 |
"
|
88
|
153 |
"
|
161
|
154 |
$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.23 1994-10-10 03:51:02 claus Exp $
|
88
|
155 |
"
|
1
|
156 |
!
|
|
157 |
|
|
158 |
versionDate
|
95
|
159 |
"return the version date - thats the date when the smalltalk
|
|
160 |
executable was linked."
|
85
|
161 |
|
|
162 |
%{
|
|
163 |
#ifdef VERSIONDATE_STRING
|
|
164 |
RETURN ( _MKSTRING(VERSIONDATE_STRING COMMA_SND) );
|
|
165 |
#endif
|
|
166 |
%}.
|
161
|
167 |
^ '10-oct-1994'
|
85
|
168 |
|
|
169 |
"
|
|
170 |
Smalltalk versionDate
|
|
171 |
"
|
|
172 |
!
|
1
|
173 |
|
85
|
174 |
configuration
|
|
175 |
"for developers only: return the configuration, with which
|
95
|
176 |
this smalltalk was compiled."
|
1
|
177 |
|
85
|
178 |
%{
|
|
179 |
#ifdef CONFIGURATION_STRING
|
|
180 |
RETURN ( _MKSTRING(CONFIGURATION_STRING COMMA_SND) );
|
|
181 |
#endif
|
|
182 |
%}.
|
|
183 |
^ 'unknown'
|
|
184 |
|
|
185 |
"
|
|
186 |
Smalltalk configuration
|
|
187 |
"
|
|
188 |
!
|
1
|
189 |
|
95
|
190 |
copyrightString
|
1
|
191 |
"return a copyright string"
|
|
192 |
|
50
|
193 |
^ 'Copyright (c) 1988-94 by Claus Gittinger'
|
1
|
194 |
|
85
|
195 |
"
|
95
|
196 |
Smalltalk copyrightString
|
85
|
197 |
"
|
1
|
198 |
!
|
|
199 |
|
|
200 |
hello
|
|
201 |
"return a greeting string"
|
|
202 |
|
85
|
203 |
"stupid: this should come from a resource file ...
|
|
204 |
but I dont use it here, to allow mini-systems without
|
|
205 |
Resource-stuff."
|
70
|
206 |
|
1
|
207 |
(Language == #german) ifTrue:[
|
159
|
208 |
^ 'Willkommen bei SmallTalk/X version '
|
|
209 |
, self versionString , ' vom ' , self versionDate
|
1
|
210 |
].
|
2
|
211 |
(Language == #french) ifTrue:[
|
159
|
212 |
^ 'Bienvenue a SmallTalk/X version '
|
|
213 |
, self versionString , ' de ' , self versionDate
|
2
|
214 |
].
|
27
|
215 |
^ 'Hello World - here is SmallTalk/X version '
|
95
|
216 |
, self versionString , ' of ' , self versionDate
|
1
|
217 |
|
85
|
218 |
"
|
|
219 |
Smalltalk hello
|
|
220 |
"
|
1
|
221 |
!
|
|
222 |
|
|
223 |
timeStamp
|
|
224 |
"return a string useful for timestamping a file"
|
|
225 |
|
95
|
226 |
^ '''From Smalltalk/X, Version:' , (Smalltalk versionString) , ' on '
|
1
|
227 |
, Date today printString , ' at ' , Time now printString
|
|
228 |
, ''''
|
|
229 |
! !
|
|
230 |
|
|
231 |
!Smalltalk class methodsFor:'initialization'!
|
|
232 |
|
|
233 |
initialize
|
24
|
234 |
"initialize all other classes; setup dispatcher processes etc.
|
|
235 |
- this one is the first entry into the smalltalk world right after startup,
|
|
236 |
ususally followed by Smalltalk>>start"
|
1
|
237 |
|
|
238 |
self initGlobalsFromEnvironment.
|
|
239 |
|
70
|
240 |
"
|
|
241 |
sorry - there are some, which MUST be initialized before ..
|
|
242 |
reason: if any error happens during init, we need Signals, Stdout etc. to be there
|
|
243 |
"
|
1
|
244 |
Object initialize.
|
|
245 |
ExternalStream initialize.
|
|
246 |
self initStandardStreams.
|
|
247 |
|
70
|
248 |
"
|
|
249 |
sorry, path must be set before ...
|
|
250 |
reason: some classes need it during initialize (they might need resources, bitmaps etc)
|
|
251 |
"
|
1
|
252 |
self initSystemPath.
|
|
253 |
|
70
|
254 |
"
|
|
255 |
must init display here - some classes (Color, Form) need it during initialize
|
|
256 |
"
|
1
|
257 |
Workstation notNil ifTrue:[
|
159
|
258 |
Workstation initialize
|
1
|
259 |
].
|
|
260 |
|
70
|
261 |
"
|
|
262 |
define low-level debugging tools - graphical classes are not prepared yet
|
|
263 |
to handle things ...
|
|
264 |
- this will bring us into the MiniDebugger when an error occurs
|
|
265 |
"
|
1
|
266 |
Inspector := MiniInspector.
|
|
267 |
Debugger := MiniDebugger.
|
|
268 |
Compiler := ByteCodeCompiler.
|
|
269 |
Compiler isNil ifTrue:[
|
159
|
270 |
"
|
|
271 |
ByteCodeCompiler is not in the system (i.e. has not been linked in)
|
|
272 |
this allows at least immediate evaluations for runtime systems without compiler
|
|
273 |
NOTICE: a parser is always needed, otherwise we cannot read resource files etc.
|
|
274 |
"
|
|
275 |
Compiler := Parser
|
1
|
276 |
].
|
|
277 |
|
70
|
278 |
"
|
159
|
279 |
now, finally, initialize all leftover classes
|
70
|
280 |
"
|
159
|
281 |
"/ Object allSubclassesInOrderDo:[:aClass |
|
2
|
282 |
self allBehaviorsDo:[:aClass |
|
159
|
283 |
"
|
|
284 |
avoid never-ending story ...
|
|
285 |
"
|
|
286 |
(aClass ~~ Smalltalk) ifTrue:[
|
|
287 |
"/ 'init ' print. aClass name printNL.
|
|
288 |
aClass initialize
|
|
289 |
]
|
1
|
290 |
].
|
159
|
291 |
|
85
|
292 |
"
|
|
293 |
now we can enable the graphical debugger/inspector
|
|
294 |
"
|
1
|
295 |
self initStandardTools.
|
70
|
296 |
self initInterrupts.
|
1
|
297 |
|
|
298 |
"Smalltalk initialize"
|
|
299 |
!
|
|
300 |
|
122
|
301 |
initUserPreferences
|
|
302 |
"setup other stuff"
|
|
303 |
|
|
304 |
LogDoits := false
|
|
305 |
!
|
|
306 |
|
1
|
307 |
initGlobalsFromEnvironment
|
|
308 |
"setup globals from the shell-environment"
|
|
309 |
|
|
310 |
|envString firstChar i langString terrString|
|
|
311 |
|
70
|
312 |
"
|
|
313 |
extract Language and LanguageTerritory from LANG variable.
|
1
|
314 |
the language and territory must not be abbreviated,
|
|
315 |
valid is for example: english_usa
|
159
|
316 |
english
|
|
317 |
german
|
|
318 |
german_austria
|
70
|
319 |
"
|
1
|
320 |
|
|
321 |
envString := OperatingSystem getEnvironment:'LANG'.
|
|
322 |
envString notNil ifTrue:[
|
159
|
323 |
i := envString indexOf:$_.
|
|
324 |
(i == 0) ifTrue:[
|
|
325 |
langString := envString.
|
|
326 |
terrString := envString
|
|
327 |
] ifFalse:[
|
|
328 |
langString := envString copyTo:(i - 1).
|
|
329 |
terrString := envString copyFrom:(i + 1)
|
|
330 |
].
|
|
331 |
Language := langString asSymbol.
|
|
332 |
LanguageTerritory := terrString asSymbol
|
1
|
333 |
].
|
|
334 |
|
70
|
335 |
"
|
|
336 |
this too is a leftover - once all refs to View3D
|
|
337 |
are removed, this will vanish ...
|
|
338 |
(please use: View>>defaultStyle:)
|
|
339 |
"
|
1
|
340 |
envString := OperatingSystem getEnvironment:'VIEW3D'.
|
|
341 |
envString notNil ifTrue:[
|
159
|
342 |
firstChar := (envString at:1) asLowercase.
|
|
343 |
(firstChar == $t) ifTrue:[
|
|
344 |
Smalltalk at:#View3D put:true
|
|
345 |
] ifFalse: [
|
|
346 |
Smalltalk at:#View3D put:false
|
|
347 |
]
|
1
|
348 |
]
|
|
349 |
"Smalltalk initGlobalsFromEnvironment"
|
|
350 |
!
|
|
351 |
|
|
352 |
initStandardTools
|
95
|
353 |
"predefine some tools which we will need later
|
1
|
354 |
- if the view-classes exist,
|
|
355 |
they will redefine Inspector and Debugger for graphical interfaces"
|
|
356 |
|
|
357 |
"redefine debug-tools, if view-classes exist"
|
|
358 |
|
95
|
359 |
Display notNil ifTrue:[
|
159
|
360 |
InspectorView notNil ifTrue:[
|
|
361 |
Inspector := InspectorView
|
|
362 |
].
|
|
363 |
DebugView notNil ifTrue:[
|
|
364 |
Debugger := DebugView
|
|
365 |
].
|
|
366 |
Display initialize
|
1
|
367 |
]
|
|
368 |
"Smalltalk initStandardTools"
|
|
369 |
!
|
|
370 |
|
|
371 |
initStandardStreams
|
|
372 |
"initialize some well-known streams"
|
|
373 |
|
|
374 |
Stdout := NonPositionableExternalStream forStdout.
|
|
375 |
Stderr := NonPositionableExternalStream forStderr.
|
|
376 |
Stdin := NonPositionableExternalStream forStdin.
|
|
377 |
Printer := PrinterStream.
|
|
378 |
Transcript := Stderr
|
|
379 |
|
|
380 |
"Smalltalk initStandardStreams"
|
|
381 |
!
|
|
382 |
|
|
383 |
initInterrupts
|
|
384 |
"initialize interrupts"
|
|
385 |
|
|
386 |
OperatingSystem enableUserInterrupts.
|
77
|
387 |
OperatingSystem enableHardSignalInterrupts.
|
2
|
388 |
OperatingSystem enableFpExceptionInterrupts.
|
|
389 |
|
|
390 |
ObjectMemory userInterruptHandler:self.
|
13
|
391 |
ObjectMemory signalInterruptHandler:self.
|
|
392 |
ObjectMemory recursionInterruptHandler:self.
|
1
|
393 |
|
|
394 |
"Smalltalk initInterrupts"
|
|
395 |
!
|
|
396 |
|
|
397 |
initSystemPath
|
70
|
398 |
"setup path where system files are searched for.
|
7
|
399 |
the default path is set to:
|
159
|
400 |
.
|
|
401 |
..
|
|
402 |
$HOME (if defined)
|
|
403 |
$HOME/.smalltalk (if defined & existing)
|
|
404 |
$SMALLTALK_LIBDIR (if defined & existing)
|
|
405 |
/usr/local/lib/smalltalk (if existing)
|
|
406 |
/usr/lib/smalltalk (if existing)
|
70
|
407 |
|
|
408 |
of course, it is possible to add entries from the 'smalltalk.rc'
|
|
409 |
startup file; add expressions such as:
|
159
|
410 |
Smalltalk systemPath addFirst:'/foo/bar/baz'.
|
|
411 |
or:
|
|
412 |
Smalltalk systemPath addLast:'/fee/foe/foo'.
|
7
|
413 |
"
|
1
|
414 |
|
70
|
415 |
|p homePath|
|
|
416 |
|
|
417 |
homePath := OperatingSystem getHomeDirectory.
|
1
|
418 |
|
70
|
419 |
"
|
|
420 |
the path is set to search files first locally
|
|
421 |
- this allows private stuff to override global stuff
|
|
422 |
"
|
1
|
423 |
SystemPath := OrderedCollection new.
|
|
424 |
SystemPath add:'.'.
|
|
425 |
SystemPath add:'..'.
|
70
|
426 |
SystemPath add:homePath.
|
|
427 |
(OperatingSystem isDirectory:(p := homePath , '/.smalltalk')) ifTrue:[
|
159
|
428 |
SystemPath add:p
|
1
|
429 |
].
|
|
430 |
p := OperatingSystem getEnvironment:'SMALLTALK_LIBDIR'.
|
|
431 |
p notNil ifTrue:[
|
159
|
432 |
SystemPath add:p
|
1
|
433 |
].
|
|
434 |
(OperatingSystem isDirectory:'/usr/local/lib/smalltalk') ifTrue:[
|
159
|
435 |
SystemPath add:'/usr/local/lib/smalltalk'
|
1
|
436 |
].
|
|
437 |
(OperatingSystem isDirectory:'/usr/lib/smalltalk') ifTrue:[
|
159
|
438 |
SystemPath add:'/usr/lib/smalltalk'
|
1
|
439 |
].
|
|
440 |
|
95
|
441 |
"
|
|
442 |
Smalltalk initSystemPath
|
|
443 |
Smalltalk systemPath
|
|
444 |
"
|
161
|
445 |
! !
|
|
446 |
|
|
447 |
!Smalltalk class methodsFor:'startup'!
|
1
|
448 |
|
|
449 |
start
|
|
450 |
"main startup, if there is a Display, initialize it
|
|
451 |
and start dispatching; otherwise go into a read-eval-print loop"
|
|
452 |
|
7
|
453 |
|idx|
|
|
454 |
|
1
|
455 |
Initializing := true.
|
159
|
456 |
"/ Processor := ProcessorScheduler new.
|
1
|
457 |
|
70
|
458 |
"
|
|
459 |
while reading patches- and rc-file, do not add things into change-file
|
|
460 |
"
|
1
|
461 |
Class updateChanges:false.
|
7
|
462 |
|
|
463 |
self fileIn:'patches'.
|
|
464 |
|
70
|
465 |
"
|
|
466 |
look for a '-e filename' argument - this will force evaluation of
|
|
467 |
filename only, no standard startup
|
|
468 |
"
|
7
|
469 |
idx := Arguments indexOf:'-e'.
|
|
470 |
idx ~~ 0 ifTrue:[
|
159
|
471 |
self fileIn:(Arguments at:idx + 1).
|
|
472 |
self exit
|
7
|
473 |
].
|
|
474 |
|
|
475 |
(self fileIn:((Arguments at:1) , '.rc')) ifFalse:[
|
159
|
476 |
"no .rc file where executable is; try default smalltalk.rc"
|
|
477 |
(self fileIn:'smalltalk.rc') ifFalse:[
|
|
478 |
Transcript showCr:'no startup rc-file found'
|
|
479 |
]
|
7
|
480 |
].
|
|
481 |
|
|
482 |
Class updateChanges:true.
|
1
|
483 |
|
70
|
484 |
(SilentLoading == true) ifFalse:[ "i.e. undefined counts as false"
|
159
|
485 |
Transcript showCr:(self hello).
|
|
486 |
Transcript showCr:(self copyrightString).
|
|
487 |
Transcript cr.
|
70
|
488 |
|
159
|
489 |
DemoMode ifTrue:[
|
|
490 |
Transcript showCr:'*** Restricted use: ***'.
|
|
491 |
Transcript showCr:'*** This program may be used for education only. ***'.
|
|
492 |
Transcript showCr:'*** Please read the files COPYRIGHT and LICENSE ***'.
|
|
493 |
Transcript showCr:'*** for more details. ***'.
|
|
494 |
Transcript cr.
|
|
495 |
].
|
1
|
496 |
].
|
|
497 |
|
|
498 |
Initializing := false.
|
50
|
499 |
|
85
|
500 |
"
|
|
501 |
reenable the graphical debugger/inspector (they could have been
|
|
502 |
defined as autoloaded in the patches file)
|
|
503 |
"
|
|
504 |
self initStandardTools.
|
|
505 |
|
|
506 |
"
|
95
|
507 |
if there is a display, start its event dispatcher
|
85
|
508 |
"
|
8
|
509 |
Display notNil ifTrue:[
|
159
|
510 |
Display startDispatch.
|
10
|
511 |
|
159
|
512 |
"this is a leftover - will vanish"
|
95
|
513 |
" "
|
159
|
514 |
ModalDisplay notNil ifTrue:[
|
|
515 |
ModalDisplay startDispatch
|
|
516 |
]
|
95
|
517 |
" "
|
8
|
518 |
].
|
24
|
519 |
|
|
520 |
(StartupClass notNil and:[StartupSelector notNil]) ifTrue:[
|
159
|
521 |
StartupClass perform:StartupSelector withArguments:StartupArguments.
|
24
|
522 |
].
|
|
523 |
|
95
|
524 |
"
|
|
525 |
if view-classes exist, start dispatching;
|
|
526 |
otherwise go into a read-eval-print loop
|
|
527 |
"
|
|
528 |
Display notNil ifTrue:[
|
159
|
529 |
Processor dispatchLoop
|
95
|
530 |
] ifFalse:[
|
159
|
531 |
self readEvalPrint
|
95
|
532 |
].
|
1
|
533 |
|
|
534 |
"done"
|
|
535 |
|
|
536 |
self exit
|
|
537 |
!
|
|
538 |
|
|
539 |
restart
|
24
|
540 |
"startup after an image has been loaded;
|
10
|
541 |
there are three change-notifications made to dependents of ObjectMemory,
|
|
542 |
which allow a stepwise re-init: #earlyRestart, #restarted and #returnFromSnapshot.
|
|
543 |
#earlyRestart is send first, nothing has been setup yet.
|
159
|
544 |
(should be used to flush all device dependent entries)
|
10
|
545 |
#restarted is send right after.
|
159
|
546 |
(should be used to recreate external resources (fds, bitmaps etc)
|
10
|
547 |
#returnFromSnapshot is sent last
|
159
|
548 |
(should be used to restart processes, reOpen Streams which cannot
|
|
549 |
be automatically be reopened (i.e. Sockets, Pipes) and so on.
|
1
|
550 |
"
|
10
|
551 |
|
77
|
552 |
|deb insp imageName|
|
1
|
553 |
|
|
554 |
Initializing := true.
|
159
|
555 |
Processor reinitialize.
|
1
|
556 |
|
95
|
557 |
"temporary switch back to dumb interface -
|
|
558 |
to handle errors while view-stuff is not yet reinitialized"
|
1
|
559 |
|
|
560 |
insp := Inspector.
|
|
561 |
deb := Debugger.
|
|
562 |
Inspector := MiniInspector.
|
|
563 |
Debugger := MiniDebugger.
|
|
564 |
|
7
|
565 |
ObjectMemory changed:#earlyRestart.
|
1
|
566 |
ObjectMemory changed:#restarted.
|
|
567 |
|
|
568 |
"
|
|
569 |
some must be reinitialized before ...
|
|
570 |
- sorry, but order is important
|
|
571 |
"
|
|
572 |
|
62
|
573 |
Workstation notNil ifTrue:[
|
159
|
574 |
Workstation reinitialize.
|
62
|
575 |
].
|
1
|
576 |
|
|
577 |
ObjectMemory changed:#returnFromSnapshot.
|
|
578 |
|
|
579 |
OperatingSystem enableUserInterrupts.
|
77
|
580 |
OperatingSystem enableHardSignalInterrupts.
|
1
|
581 |
|
10
|
582 |
"and back to real interface"
|
1
|
583 |
Inspector := insp.
|
|
584 |
Debugger := deb.
|
|
585 |
|
|
586 |
Initializing := false.
|
|
587 |
|
|
588 |
"
|
|
589 |
if there is no Transcript, go to stderr
|
|
590 |
"
|
|
591 |
Transcript isNil ifTrue:[
|
159
|
592 |
self initStandardStreams.
|
|
593 |
Transcript := Stderr
|
1
|
594 |
].
|
|
595 |
|
70
|
596 |
(SilentLoading == true) ifFalse:[
|
159
|
597 |
Transcript cr.
|
|
598 |
Transcript showCr:('Smalltalk restarted from:' , ObjectMemory imageName).
|
|
599 |
Transcript cr.
|
70
|
600 |
|
159
|
601 |
DemoMode ifTrue:[
|
|
602 |
Transcript showCr:'*** Restricted use: ***'.
|
|
603 |
Transcript showCr:'*** This program may be used for education only. ***'.
|
|
604 |
Transcript showCr:'*** Please read the files COPYRIGHT and LICENSE ***'.
|
|
605 |
Transcript showCr:'*** for more details. ***'.
|
|
606 |
Transcript cr.
|
|
607 |
].
|
1
|
608 |
].
|
|
609 |
|
7
|
610 |
"
|
|
611 |
give user a chance to re-customize things
|
|
612 |
"
|
95
|
613 |
(Arguments includes:'-faststart') ifFalse:[
|
159
|
614 |
Class updateChanges:false.
|
|
615 |
(self fileIn:((Arguments at:1) , '_r.rc')) ifFalse:[
|
|
616 |
"no _r.rc file where executable is; try default smalltalk_r.rc"
|
|
617 |
self fileIn:'smalltalk_r.rc'
|
|
618 |
].
|
|
619 |
Class updateChanges:true.
|
7
|
620 |
].
|
|
621 |
|
95
|
622 |
"
|
|
623 |
if there is a display, start its event dispatcher
|
|
624 |
"
|
10
|
625 |
Display notNil ifTrue:[
|
159
|
626 |
Display startDispatch.
|
95
|
627 |
" "
|
159
|
628 |
ModalDisplay notNil ifTrue:[
|
|
629 |
ModalDisplay startDispatch
|
|
630 |
]
|
95
|
631 |
" "
|
10
|
632 |
].
|
|
633 |
|
95
|
634 |
"
|
|
635 |
this allows firing an application by defining
|
|
636 |
these two globals during snapshot ... or in main
|
|
637 |
"
|
7
|
638 |
(StartupClass notNil and:[StartupSelector notNil]) ifTrue:[
|
159
|
639 |
"allow customization by reading an image specific rc-file"
|
|
640 |
imageName := ObjectMemory imageName.
|
|
641 |
imageName notNil ifTrue:[
|
|
642 |
(imageName endsWith:'.img') ifTrue:[
|
|
643 |
self fileIn:((imageName copyTo:(imageName size - 4)), '.rc')
|
|
644 |
] ifFalse:[
|
|
645 |
self fileIn:(imageName , '.rc')
|
|
646 |
]
|
|
647 |
].
|
|
648 |
StartupClass perform:StartupSelector withArguments:StartupArguments.
|
1
|
649 |
].
|
|
650 |
|
95
|
651 |
"
|
|
652 |
if view-classes exist, start dispatching;
|
|
653 |
otherwise go into a read-eval-print loop
|
|
654 |
"
|
1
|
655 |
Display notNil ifTrue:[
|
159
|
656 |
Processor dispatchLoop
|
1
|
657 |
] ifFalse:[
|
159
|
658 |
self readEvalPrint
|
1
|
659 |
].
|
95
|
660 |
|
|
661 |
self exit
|
1
|
662 |
!
|
|
663 |
|
|
664 |
readEvalPrint
|
24
|
665 |
"simple read-eval-print loop for non-graphical Minitalk"
|
1
|
666 |
|
|
667 |
|text|
|
|
668 |
|
|
669 |
'ST- ' print.
|
|
670 |
Stdin skipSeparators.
|
|
671 |
text := Stdin nextChunk.
|
|
672 |
[text notNil] whileTrue:[
|
159
|
673 |
(Compiler evaluate:text) printNL.
|
|
674 |
'ST- ' print.
|
|
675 |
text := Stdin nextChunk
|
1
|
676 |
].
|
95
|
677 |
'' printNL
|
161
|
678 |
!
|
70
|
679 |
|
|
680 |
startupClass:aClass selector:aSymbol arguments:anArrayOrNil
|
|
681 |
"set the class, selector and arguments to be performed when smalltalk
|
|
682 |
starts. Setting those before saving a snapshot, will make the saved
|
|
683 |
image come up executing your application (instead of the normal mainloop)"
|
|
684 |
|
|
685 |
StartupClass := aClass.
|
|
686 |
StartupSelector := aSymbol.
|
|
687 |
StartupArguments := anArrayOrNil
|
|
688 |
!
|
|
689 |
|
|
690 |
startupClass
|
|
691 |
"return the class, that will get the start message when smalltalk
|
|
692 |
starts and its non-nil. Usually this is nil, but saving an image
|
|
693 |
with a non-nil StartupClass allows stand-alone applications"
|
|
694 |
|
|
695 |
^ StartupClass
|
|
696 |
!
|
|
697 |
|
|
698 |
startupSelector
|
|
699 |
"return the selector, that will be sent to StartupClass"
|
|
700 |
|
|
701 |
^ StartupSelector
|
|
702 |
!
|
|
703 |
|
|
704 |
startupArguments
|
|
705 |
"return the arguments passed to StartupClass"
|
|
706 |
|
|
707 |
^ StartupArguments
|
|
708 |
! !
|
|
709 |
|
1
|
710 |
!Smalltalk class methodsFor:'accessing'!
|
|
711 |
|
|
712 |
at:aKey
|
70
|
713 |
"retrieve the value stored under aKey, a symbol
|
|
714 |
- return nil if not present"
|
1
|
715 |
|
|
716 |
%{ /* NOCONTEXT */
|
77
|
717 |
extern OBJ _GLOBAL_GET();
|
1
|
718 |
|
77
|
719 |
RETURN ( _GLOBAL_GET(aKey) );
|
1
|
720 |
%}
|
|
721 |
!
|
|
722 |
|
|
723 |
at:aKey ifAbsent:aBlock
|
95
|
724 |
"retrieve the value stored at aKey.
|
|
725 |
If there is nothing stored under this key, return the value of
|
|
726 |
the evaluation of aBlock."
|
1
|
727 |
|
|
728 |
(self includesKey:aKey) ifTrue:[
|
159
|
729 |
^ self at:aKey
|
1
|
730 |
].
|
|
731 |
^ aBlock value
|
95
|
732 |
|
|
733 |
"
|
|
734 |
Smalltalk at:#fooBar <- leads to an error
|
|
735 |
Smalltalk at:#fooBar ifAbsent:['sorry'] <- no error
|
|
736 |
"
|
1
|
737 |
!
|
|
738 |
|
|
739 |
at:aKey put:aValue
|
|
740 |
"store the argument aValue under aKey, a symbol"
|
|
741 |
|
|
742 |
CachedClasses := nil.
|
|
743 |
|
|
744 |
%{ /* NOCONTEXT */
|
77
|
745 |
_GLOBAL_SET(aKey, aValue, (OBJ *)0);
|
|
746 |
%}.
|
|
747 |
^ aValue
|
1
|
748 |
!
|
|
749 |
|
|
750 |
removeKey:aKey
|
|
751 |
"remove the argument from the globals dictionary"
|
|
752 |
|
|
753 |
CachedClasses := nil.
|
|
754 |
|
|
755 |
%{ /* NOCONTEXT */
|
77
|
756 |
extern OBJ _GLOBAL_REMOVE();
|
1
|
757 |
|
77
|
758 |
RETURN ( _GLOBAL_REMOVE(aKey) );
|
1
|
759 |
%}
|
|
760 |
!
|
|
761 |
|
|
762 |
includesKey:aKey
|
|
763 |
"return true, if the key is known"
|
|
764 |
|
|
765 |
%{ /* NOCONTEXT */
|
77
|
766 |
extern OBJ _GLOBAL_KEYKNOWN();
|
1
|
767 |
|
77
|
768 |
RETURN ( _GLOBAL_KEYKNOWN(aKey) );
|
1
|
769 |
%}
|
|
770 |
!
|
|
771 |
|
|
772 |
keyAtValue:anObject
|
|
773 |
"return the symbol under which anObject is stored - or nil"
|
|
774 |
|
|
775 |
self allKeysDo:[:aKey |
|
159
|
776 |
(self at:aKey) == anObject ifTrue:[^ aKey]
|
1
|
777 |
]
|
|
778 |
|
|
779 |
"Smalltalk keyAtValue:Object"
|
|
780 |
!
|
|
781 |
|
|
782 |
keys
|
|
783 |
"return a collection with all keys in the Smalltalk dictionary"
|
|
784 |
|
|
785 |
|keys|
|
|
786 |
|
77
|
787 |
keys := IdentitySet new.
|
1
|
788 |
self allKeysDo:[:k | keys add:k].
|
|
789 |
^ keys
|
|
790 |
! !
|
|
791 |
|
|
792 |
!Smalltalk class methodsFor:'copying'!
|
|
793 |
|
|
794 |
shallowCopy
|
|
795 |
"redefine copy - there is only one Smalltalk dictionary"
|
|
796 |
|
|
797 |
^ self
|
|
798 |
!
|
|
799 |
|
13
|
800 |
simpleDeepCopy
|
|
801 |
"redefine copy - there is only one Smalltalk dictionary"
|
|
802 |
|
|
803 |
^ self
|
|
804 |
!
|
|
805 |
|
|
806 |
deepCopyUsing:aDictionary
|
|
807 |
"redefine copy - there is only one Smalltalk dictionary"
|
|
808 |
|
|
809 |
^ self
|
|
810 |
!
|
|
811 |
|
1
|
812 |
deepCopy
|
|
813 |
"redefine copy - there is only one Smalltalk dictionary"
|
|
814 |
|
|
815 |
^ self
|
|
816 |
! !
|
|
817 |
|
|
818 |
!Smalltalk class methodsFor:'inspecting'!
|
|
819 |
|
|
820 |
inspect
|
|
821 |
"redefined to launch a DictionaryInspector on the receiver
|
|
822 |
(instead of the default InspectorView)."
|
|
823 |
|
|
824 |
DictionaryInspectorView isNil ifTrue:[
|
159
|
825 |
super inspect
|
1
|
826 |
] ifFalse:[
|
159
|
827 |
DictionaryInspectorView openOn:self
|
1
|
828 |
]
|
|
829 |
! !
|
|
830 |
|
|
831 |
!Smalltalk class methodsFor:'misc stuff'!
|
|
832 |
|
|
833 |
addExitBlock:aBlock
|
24
|
834 |
"add a block to be executed when Smalltalk finishes.
|
|
835 |
This feature is currently not used anywhere - but could be useful for
|
|
836 |
cleanup in stand alone applications."
|
1
|
837 |
|
7
|
838 |
ExitBlocks isNil ifTrue:[
|
159
|
839 |
ExitBlocks := OrderedCollection with:aBlock
|
1
|
840 |
] ifFalse:[
|
159
|
841 |
ExitBlocks add:aBlock
|
1
|
842 |
]
|
|
843 |
!
|
|
844 |
|
|
845 |
exit
|
|
846 |
"finish Smalltalk system"
|
|
847 |
|
7
|
848 |
ExitBlocks notNil ifTrue:[
|
159
|
849 |
ExitBlocks do:[:aBlock |
|
|
850 |
aBlock value
|
|
851 |
]
|
1
|
852 |
].
|
|
853 |
OperatingSystem exit
|
|
854 |
|
|
855 |
"Smalltalk exit"
|
|
856 |
!
|
|
857 |
|
|
858 |
sleep:aDelay
|
70
|
859 |
"wait for aDelay seconds.
|
|
860 |
WARNING: this is historical leftover and will be removed"
|
1
|
861 |
|
|
862 |
OperatingSystem sleep:aDelay
|
|
863 |
! !
|
|
864 |
|
70
|
865 |
!Smalltalk class methodsFor:'message control'!
|
|
866 |
|
|
867 |
silentLoading:aBoolean
|
|
868 |
"allows access to the Silentloading class variable, which controls
|
|
869 |
messages from all kinds of system onto the transcript.
|
|
870 |
You can save a snapshot with this flag set to true, which makes
|
|
871 |
the image come up silent. Can also be set, to read in files unlogged."
|
|
872 |
|
|
873 |
|prev|
|
|
874 |
|
|
875 |
prev := SilentLoading.
|
|
876 |
SilentLoading := aBoolean.
|
|
877 |
^ prev
|
|
878 |
!
|
|
879 |
|
|
880 |
silentLoading
|
|
881 |
"returns the Silentloading class variable."
|
|
882 |
|
|
883 |
^ SilentLoading
|
|
884 |
! !
|
|
885 |
|
1
|
886 |
!Smalltalk class methodsFor:'debugging'!
|
|
887 |
|
70
|
888 |
debugBreakPoint
|
|
889 |
"call the dummy debug function, on which a breakpoint
|
|
890 |
can be put in adb, sdb, dbx or gdb.
|
|
891 |
This method will not be present in the future."
|
|
892 |
%{
|
|
893 |
_PATCHUPCONTEXTS(__context);
|
|
894 |
debugBreakPoint();
|
|
895 |
%}
|
|
896 |
!
|
|
897 |
|
1
|
898 |
printStackBacktrace
|
70
|
899 |
"print a stack backtrace - then continue.
|
|
900 |
WARNING: this method is for debugging only
|
159
|
901 |
it may be removed without notice"
|
1
|
902 |
|
|
903 |
%{
|
|
904 |
printStack(__context);
|
|
905 |
%}
|
70
|
906 |
"Smalltalk printStackBacktrace"
|
|
907 |
!
|
|
908 |
|
|
909 |
fatalAbort:aMessage
|
|
910 |
"report a fatal-error; print a stack backtrace and exit with core dump"
|
|
911 |
|
|
912 |
%{
|
|
913 |
char *msg;
|
|
914 |
|
|
915 |
if (__isString(aMessage))
|
159
|
916 |
msg = (char *) _stringVal(aMessage);
|
70
|
917 |
else
|
159
|
918 |
msg = "fatalAbort";
|
70
|
919 |
|
|
920 |
fatal0(__context, msg);
|
|
921 |
/* NEVER RETURNS */
|
|
922 |
%}
|
1
|
923 |
!
|
|
924 |
|
|
925 |
fatalAbort
|
70
|
926 |
"report a fatal-error, print a stack backtrace and exit with core dump"
|
1
|
927 |
%{
|
70
|
928 |
fatal0(__context, "fatalAbort");
|
|
929 |
/* NEVER RETURNS */
|
|
930 |
%}
|
|
931 |
!
|
|
932 |
|
|
933 |
exitWithCoreDump
|
|
934 |
"abort program and dump core"
|
|
935 |
|
|
936 |
%{ /* NOCONTEXT */
|
|
937 |
abort();
|
|
938 |
/* NEVER RETURNS */
|
1
|
939 |
%}
|
|
940 |
!
|
|
941 |
|
|
942 |
statistic
|
70
|
943 |
"print some statistic data.
|
|
944 |
WARNING: this method is for debugging only
|
159
|
945 |
it may be removed without notice"
|
70
|
946 |
|
|
947 |
%{ /* NOCONTEXT */
|
159
|
948 |
__STATISTIC__();
|
1
|
949 |
%}
|
|
950 |
!
|
|
951 |
|
|
952 |
debugOn
|
70
|
953 |
"turns some tracing on.
|
|
954 |
WARNING: this method is for debugging only
|
159
|
955 |
it may be removed without notice"
|
1
|
956 |
|
|
957 |
"LookupTrace := true. "
|
|
958 |
MessageTrace := true.
|
|
959 |
"AllocTrace := true. "
|
|
960 |
ObjectMemory flushInlineCaches
|
|
961 |
!
|
|
962 |
|
|
963 |
debugOff
|
70
|
964 |
"turns tracing off.
|
|
965 |
WARNING: this method is for debugging only
|
159
|
966 |
it may be removed without notice"
|
1
|
967 |
|
|
968 |
LookupTrace := nil.
|
|
969 |
MessageTrace := nil
|
|
970 |
". AllocTrace := nil "
|
|
971 |
!
|
|
972 |
|
|
973 |
executionDebugOn
|
70
|
974 |
"turns tracing of interpreter on.
|
|
975 |
WARNING: this method is for debugging only
|
159
|
976 |
it may be removed without notice"
|
1
|
977 |
|
|
978 |
ExecutionTrace := true
|
|
979 |
!
|
|
980 |
|
|
981 |
executionDebugOff
|
70
|
982 |
"turns tracing of interpreter off.
|
|
983 |
WARNING: this method is for debugging only
|
159
|
984 |
it may be removed without notice"
|
1
|
985 |
|
|
986 |
ExecutionTrace := nil
|
|
987 |
! !
|
|
988 |
|
70
|
989 |
!Smalltalk class methodsFor:'enumeration'!
|
1
|
990 |
|
|
991 |
do:aBlock
|
|
992 |
"evaluate the argument, aBlock for all values in the Smalltalk dictionary"
|
|
993 |
%{
|
77
|
994 |
_GLOBALS_DO(&aBlock COMMA_CON);
|
1
|
995 |
%}
|
|
996 |
!
|
|
997 |
|
|
998 |
allKeysDo:aBlock
|
|
999 |
"evaluate the argument, aBlock for all keys in the Smalltalk dictionary"
|
|
1000 |
%{
|
77
|
1001 |
_GLOBALKEYS_DO(&aBlock COMMA_CON);
|
1
|
1002 |
%}
|
|
1003 |
!
|
|
1004 |
|
|
1005 |
associationsDo:aBlock
|
|
1006 |
"evaluate the argument, aBlock for all key/value pairs
|
|
1007 |
in the Smalltalk dictionary"
|
|
1008 |
|
|
1009 |
self allKeysDo:[:aKey |
|
159
|
1010 |
aBlock value:(aKey -> (self at:aKey))
|
1
|
1011 |
]
|
|
1012 |
|
95
|
1013 |
"Smalltalk associationsDo:[:assoc | assoc printNL]"
|
24
|
1014 |
!
|
|
1015 |
|
|
1016 |
keysAndValuesDo:aBlock
|
|
1017 |
"evaluate the two-arg block, aBlock for all keys and values"
|
|
1018 |
|
|
1019 |
self allKeysDo:[:aKey |
|
159
|
1020 |
aBlock value:aKey value:(self at:aKey)
|
24
|
1021 |
]
|
70
|
1022 |
!
|
|
1023 |
|
|
1024 |
allBehaviorsDo:aBlock
|
|
1025 |
"evaluate the argument, aBlock for all classes in the system"
|
|
1026 |
|
|
1027 |
self allClasses do:aBlock
|
|
1028 |
!
|
|
1029 |
|
|
1030 |
allClassesDo:aBlock
|
|
1031 |
"evaluate the argument, aBlock for all classes in the system.
|
|
1032 |
Backward compatibility - use allBehaviorsDo: for ST-80 compatibility."
|
|
1033 |
|
|
1034 |
^ self allBehaviorsDo:aBlock
|
1
|
1035 |
! !
|
|
1036 |
|
|
1037 |
!Smalltalk class methodsFor:'queries'!
|
|
1038 |
|
|
1039 |
numberOfGlobals
|
|
1040 |
"return the number of global variables in the system"
|
|
1041 |
|
70
|
1042 |
|tally "{ Class: SmallInteger }" |
|
1
|
1043 |
|
|
1044 |
tally := 0.
|
|
1045 |
self do:[:obj | tally := tally + 1].
|
|
1046 |
^ tally
|
|
1047 |
|
|
1048 |
"Smalltalk numberOfGlobals"
|
|
1049 |
!
|
|
1050 |
|
|
1051 |
cellAt:aName
|
|
1052 |
"return the address of a global cell
|
|
1053 |
- used internally for compiler only"
|
|
1054 |
|
|
1055 |
%{ /* NOCONTEXT */
|
77
|
1056 |
extern OBJ _GLOBAL_GETCELL();
|
1
|
1057 |
|
77
|
1058 |
RETURN ( _GLOBAL_GETCELL(aName) );
|
1
|
1059 |
%}
|
|
1060 |
!
|
|
1061 |
|
|
1062 |
references:anObject
|
|
1063 |
"return true, if I refer to the argument, anObject
|
70
|
1064 |
must be reimplemented since Smalltalk is no real collection."
|
1
|
1065 |
|
|
1066 |
self do:[:o |
|
159
|
1067 |
(o == anObject) ifTrue:[^ true]
|
1
|
1068 |
].
|
|
1069 |
^ false
|
|
1070 |
!
|
|
1071 |
|
|
1072 |
allClasses
|
|
1073 |
"return a collection of all classes in the system"
|
|
1074 |
|
|
1075 |
CachedClasses isNil ifTrue:[
|
159
|
1076 |
CachedClasses := IdentitySet new:800.
|
|
1077 |
self do:[:anObject |
|
|
1078 |
anObject notNil ifTrue:[
|
|
1079 |
anObject isBehavior ifTrue:[
|
|
1080 |
CachedClasses add:anObject
|
|
1081 |
]
|
|
1082 |
]
|
|
1083 |
]
|
1
|
1084 |
].
|
|
1085 |
^ CachedClasses
|
|
1086 |
|
|
1087 |
"Smalltalk allClasses"
|
|
1088 |
!
|
|
1089 |
|
|
1090 |
classNames
|
|
1091 |
"return a collection of all classNames in the system"
|
|
1092 |
|
|
1093 |
^ self allClasses collect:[:aClass | aClass name]
|
7
|
1094 |
|
70
|
1095 |
"Smalltalk classNames"
|
159
|
1096 |
!
|
|
1097 |
|
|
1098 |
classNamed:aString
|
|
1099 |
"return the class with name aString, or nil if absent"
|
|
1100 |
|
|
1101 |
|cls|
|
|
1102 |
|
|
1103 |
"be careful, to not invent new symbols ..."
|
|
1104 |
aString knownAsSymbol ifTrue:[
|
|
1105 |
cls := self at:(aString asSymbol) ifAbsent:[^ nil].
|
|
1106 |
cls isBehavior ifTrue:[^ cls]
|
|
1107 |
].
|
|
1108 |
^ nil
|
|
1109 |
|
|
1110 |
"
|
|
1111 |
Smalltalk classNamed:'Object'
|
|
1112 |
Smalltalk classNamed:'fooBar'
|
|
1113 |
Smalltalk classNamed:'true'
|
|
1114 |
"
|
1
|
1115 |
! !
|
|
1116 |
|
70
|
1117 |
!Smalltalk class methodsFor:'class management'!
|
1
|
1118 |
|
8
|
1119 |
renameClass:aClass to:newName
|
|
1120 |
"rename aClass to newName"
|
|
1121 |
|
|
1122 |
|oldName oldSym newSym names cSym value|
|
|
1123 |
|
|
1124 |
oldName := aClass name.
|
|
1125 |
oldSym := oldName asSymbol.
|
|
1126 |
|
|
1127 |
((self at:oldSym) == aClass) ifFalse:[^ self].
|
|
1128 |
|
|
1129 |
"rename the class"
|
|
1130 |
|
|
1131 |
aClass setName:newName.
|
|
1132 |
|
|
1133 |
"and its meta"
|
|
1134 |
|
|
1135 |
aClass class setName:(newName , 'class').
|
|
1136 |
|
|
1137 |
"store it in Smalltalk"
|
|
1138 |
|
|
1139 |
newSym := newName asSymbol.
|
|
1140 |
self at:oldSym put:nil.
|
|
1141 |
self removeKey:oldSym.
|
|
1142 |
self at:newSym put:aClass.
|
|
1143 |
|
|
1144 |
"rename class variables"
|
|
1145 |
|
|
1146 |
names := aClass classVariableString asCollectionOfWords.
|
|
1147 |
names do:[:name |
|
159
|
1148 |
cSym := (oldSym , ':' , name) asSymbol.
|
|
1149 |
value := self at:cSym.
|
|
1150 |
self at:cSym put:nil.
|
|
1151 |
self removeKey:cSym.
|
|
1152 |
cSym := (newSym , ':' , name) asSymbol.
|
|
1153 |
self at:cSym put:value.
|
8
|
1154 |
].
|
|
1155 |
|
|
1156 |
aClass addChangeRecordForClassRename:oldName to:newName
|
|
1157 |
!
|
|
1158 |
|
1
|
1159 |
removeClass:aClass
|
|
1160 |
"remove the argument, aClass from the smalltalk dictionary;
|
2
|
1161 |
we have to flush the caches since these methods are now void.
|
|
1162 |
Also, class variables of aClass are removed."
|
1
|
1163 |
|
8
|
1164 |
|sym cSym names oldName|
|
1
|
1165 |
|
8
|
1166 |
oldName := aClass name.
|
|
1167 |
sym := oldName asSymbol.
|
159
|
1168 |
((self at:sym) == aClass) ifFalse:[
|
|
1169 |
"check other name ..."
|
|
1170 |
(self includes:aClass) ifFalse:[
|
|
1171 |
'no such class' errorPrintNL.
|
|
1172 |
^ self
|
|
1173 |
].
|
|
1174 |
"the class has changed its name - without telling me ...
|
|
1175 |
what should be done in this case ?"
|
|
1176 |
'class ' errorPrint. oldName errorPrint.
|
|
1177 |
' has changed its name' errorPrintNL.
|
|
1178 |
^ self
|
|
1179 |
].
|
2
|
1180 |
|
8
|
1181 |
self at:sym put:nil. "nil it out for compiled accesses"
|
|
1182 |
self removeKey:sym.
|
|
1183 |
|
159
|
1184 |
aClass category:#removed.
|
|
1185 |
|
8
|
1186 |
"remove class variables"
|
2
|
1187 |
|
8
|
1188 |
names := aClass classVariableString asCollectionOfWords.
|
|
1189 |
names do:[:name |
|
159
|
1190 |
cSym := (sym , ':' , name) asSymbol.
|
|
1191 |
self at:cSym asSymbol put:nil.
|
|
1192 |
self removeKey:cSym
|
8
|
1193 |
].
|
1
|
1194 |
"
|
8
|
1195 |
actually could get along with less flushing
|
|
1196 |
(entries for aClass and subclasses only)
|
1
|
1197 |
|
24
|
1198 |
aClass allSubclassesDo:[:aSubclass |
|
159
|
1199 |
ObjectMemory flushInlineCachesForClass:aSubclass.
|
|
1200 |
ObjectMemory flushMethodCacheFor:aSubclass
|
24
|
1201 |
].
|
8
|
1202 |
ObjectMemory flushInlineCachesForClass:aClass.
|
|
1203 |
ObjectMemory flushMethodCacheFor:aClass
|
1
|
1204 |
"
|
8
|
1205 |
ObjectMemory flushInlineCaches.
|
|
1206 |
ObjectMemory flushMethodCache.
|
|
1207 |
|
159
|
1208 |
aClass addChangeRecordForClassRemove:oldName.
|
70
|
1209 |
! !
|
|
1210 |
|
|
1211 |
!Smalltalk class methodsFor:'browsing'!
|
1
|
1212 |
|
|
1213 |
browseChanges
|
|
1214 |
"startup a changes browser"
|
|
1215 |
|
70
|
1216 |
ChangesBrowser notNil ifTrue:[
|
159
|
1217 |
ChangesBrowser open
|
1
|
1218 |
] ifFalse:[
|
159
|
1219 |
self warn:'no ChangesBrowser built in'
|
1
|
1220 |
]
|
|
1221 |
|
77
|
1222 |
"
|
|
1223 |
Smalltalk browseChanges
|
|
1224 |
"
|
1
|
1225 |
!
|
|
1226 |
|
|
1227 |
browseAllSelect:aBlock
|
|
1228 |
"startup a browser for all methods for which aBlock returns true"
|
|
1229 |
|
|
1230 |
SystemBrowser browseAllSelect:aBlock
|
|
1231 |
|
77
|
1232 |
"
|
|
1233 |
Smalltalk browseAllSelect:[:m | m literals isNil]
|
|
1234 |
"
|
1
|
1235 |
!
|
|
1236 |
|
|
1237 |
browseImplementorsOf:aSelectorSymbol
|
|
1238 |
"startup a browser for all methods implementing a particular message"
|
|
1239 |
|
|
1240 |
SystemBrowser browseImplementorsOf:aSelectorSymbol
|
|
1241 |
|
77
|
1242 |
"
|
|
1243 |
Smalltalk browseImplementorsOf:#at:put:
|
|
1244 |
"
|
1
|
1245 |
!
|
|
1246 |
|
|
1247 |
browseAllCallsOn:aSelectorSymbol
|
|
1248 |
"startup a browser for all methods sending a particular message"
|
|
1249 |
|
|
1250 |
SystemBrowser browseAllCallsOn:aSelectorSymbol
|
|
1251 |
|
77
|
1252 |
"
|
|
1253 |
Smalltalk browseAllCallsOn:#at:put:
|
|
1254 |
"
|
70
|
1255 |
! !
|
|
1256 |
|
|
1257 |
!Smalltalk class methodsFor:'system management'!
|
|
1258 |
|
88
|
1259 |
language
|
|
1260 |
"return the language setting"
|
|
1261 |
|
|
1262 |
^ Language
|
|
1263 |
!
|
|
1264 |
|
|
1265 |
languageTerritory
|
|
1266 |
"return the language territory setting"
|
|
1267 |
|
|
1268 |
^ LanguageTerritory
|
|
1269 |
!
|
|
1270 |
|
122
|
1271 |
logDoits
|
|
1272 |
"return true if doits should go into the changes file
|
|
1273 |
as well as changes - by default, this is off, since
|
|
1274 |
it can blow up the changes file enormously ...
|
|
1275 |
"
|
|
1276 |
|
|
1277 |
^ LogDoits
|
|
1278 |
|
|
1279 |
"
|
|
1280 |
LogDoits := false
|
|
1281 |
LogDoits := true
|
|
1282 |
"
|
|
1283 |
!
|
|
1284 |
|
|
1285 |
logDoits:aBoolean
|
|
1286 |
"turn on/off logging of doits in the changes file.
|
|
1287 |
By default, this is off, since it can blow up the
|
|
1288 |
changes file enormously ...
|
|
1289 |
"
|
|
1290 |
|
|
1291 |
LogDoits := aBoolean
|
|
1292 |
|
|
1293 |
!
|
|
1294 |
|
70
|
1295 |
systemPath
|
|
1296 |
"return a collection of directorynames, where smalltalk
|
|
1297 |
looks for system files
|
|
1298 |
(usually in subdirs such as resources, bitmaps, source etc.)
|
|
1299 |
see comment in Smalltalk>>initSystemPath."
|
|
1300 |
|
|
1301 |
^ SystemPath
|
77
|
1302 |
|
|
1303 |
"
|
|
1304 |
Smalltalk systemPath
|
159
|
1305 |
Smalltalk systemPath addLast:'someOtherDirectoryPath'
|
77
|
1306 |
"
|
70
|
1307 |
!
|
|
1308 |
|
|
1309 |
getSystemFileName:aFileName
|
|
1310 |
"search aFileName in some standard places;
|
|
1311 |
return the absolute filename or nil if none is found.
|
|
1312 |
see comment in Smalltalk>>initSystemPath."
|
|
1313 |
|
|
1314 |
"credits for this method go to Markus ...."
|
|
1315 |
|
|
1316 |
|realName|
|
|
1317 |
|
|
1318 |
(aFileName startsWith:'/') ifTrue:[
|
159
|
1319 |
"dont use path for absolute file names"
|
70
|
1320 |
|
159
|
1321 |
^ aFileName
|
70
|
1322 |
].
|
|
1323 |
|
|
1324 |
SystemPath do:[:dirName |
|
159
|
1325 |
(OperatingSystem isReadable:
|
|
1326 |
(realName := dirName , '/' , aFileName))
|
|
1327 |
ifTrue: [^ realName]].
|
70
|
1328 |
^ nil
|
|
1329 |
!
|
|
1330 |
|
|
1331 |
systemFileStreamFor:aFileName
|
|
1332 |
"search aFileName in some standard places;
|
|
1333 |
return a readonly fileStream or nil if not found.
|
|
1334 |
see comment in Smalltalk>>initSystemPath"
|
|
1335 |
|
|
1336 |
|aString|
|
|
1337 |
|
|
1338 |
aString := self getSystemFileName:aFileName.
|
|
1339 |
aString notNil ifTrue:[
|
159
|
1340 |
^ FileStream readonlyFileNamed:aString
|
70
|
1341 |
].
|
|
1342 |
^ nil
|
1
|
1343 |
!
|
|
1344 |
|
10
|
1345 |
readAbbreviations
|
|
1346 |
"read classname to filename mappings from abbrev.stc.
|
|
1347 |
sigh - all for those poor sys5.3 people ..."
|
|
1348 |
|
|
1349 |
|aStream line index thisName abbrev|
|
|
1350 |
|
|
1351 |
CachedAbbreviations := Dictionary new.
|
|
1352 |
aStream := self systemFileStreamFor:'abbrev.stc'.
|
146
|
1353 |
aStream isNil ifTrue:[
|
159
|
1354 |
aStream := self systemFileStreamFor:'include/abbrev.stc'.
|
146
|
1355 |
].
|
10
|
1356 |
aStream notNil ifTrue:[
|
159
|
1357 |
[aStream atEnd] whileFalse:[
|
|
1358 |
line := aStream nextLine.
|
|
1359 |
line notNil ifTrue:[
|
|
1360 |
(line startsWith:'#') ifFalse:[
|
|
1361 |
(line countWords == 2) ifTrue:[
|
|
1362 |
index := line indexOfSeparatorStartingAt:1.
|
|
1363 |
(index ~~ 0) ifTrue:[
|
|
1364 |
thisName := line copyTo:(index - 1).
|
|
1365 |
abbrev := (line copyFrom:index) withoutSeparators.
|
|
1366 |
CachedAbbreviations at:thisName put:abbrev.
|
|
1367 |
]
|
|
1368 |
]
|
|
1369 |
]
|
|
1370 |
]
|
|
1371 |
].
|
|
1372 |
aStream close
|
10
|
1373 |
]
|
|
1374 |
!
|
|
1375 |
|
70
|
1376 |
abbreviations
|
|
1377 |
"return a dictionary containing the classname-to-filename
|
|
1378 |
mappings. (needed for sys5.3 users, where filenames are limited
|
|
1379 |
to 14 chars)"
|
7
|
1380 |
|
70
|
1381 |
CachedAbbreviations isNil ifTrue:[
|
159
|
1382 |
self readAbbreviations
|
7
|
1383 |
].
|
70
|
1384 |
^ CachedAbbreviations
|
77
|
1385 |
|
122
|
1386 |
"flush with:
|
|
1387 |
|
77
|
1388 |
CachedAbbreviations := nil
|
|
1389 |
"
|
1
|
1390 |
!
|
|
1391 |
|
|
1392 |
fileNameForClass:aClassName
|
|
1393 |
"return a good filename for aClassName -
|
|
1394 |
using abbreviation file if there is one"
|
|
1395 |
|
10
|
1396 |
|fileName abbrev|
|
1
|
1397 |
|
|
1398 |
fileName := aClassName.
|
|
1399 |
|
10
|
1400 |
"first look, if the class exists and has a fileName"
|
|
1401 |
|
24
|
1402 |
" later ... - compiler should put the source file name into the class
|
10
|
1403 |
Symbol hasInterned:aClassName ifTrue:[:sym |
|
159
|
1404 |
|class|
|
10
|
1405 |
|
159
|
1406 |
(Smalltalk includesKey:sym) ifTrue:[
|
|
1407 |
class := Smalltalk at:sym.
|
|
1408 |
class isClass ifTrue:[
|
|
1409 |
abbrev := class classFileName.
|
|
1410 |
]
|
|
1411 |
]
|
10
|
1412 |
].
|
|
1413 |
"
|
|
1414 |
|
7
|
1415 |
"look for abbreviation"
|
1
|
1416 |
|
70
|
1417 |
abbrev := self abbreviations at:fileName ifAbsent:[nil].
|
10
|
1418 |
abbrev notNil ifTrue:[^ abbrev].
|
7
|
1419 |
|
10
|
1420 |
"no abbreviation found - if its a short name, take it"
|
|
1421 |
|
|
1422 |
OperatingSystem maxFileNameLength < (fileName size + 3) ifTrue:[
|
159
|
1423 |
"this will only be triggered on sys5.3 type systems"
|
|
1424 |
self error:'cant find short for ' , fileName , ' in abbreviation file'
|
1
|
1425 |
].
|
|
1426 |
^ fileName
|
|
1427 |
!
|
|
1428 |
|
2
|
1429 |
classNameForFile:aFileName
|
10
|
1430 |
"return the className which corresponds to an abbreviated fileName,
|
|
1431 |
or nil if no special translation applies. The given filename arg should
|
|
1432 |
NOT include any suffix such as '.st'."
|
2
|
1433 |
|
70
|
1434 |
^ self abbreviations keyAtValue:aFileName ifAbsent:[aFileName].
|
2
|
1435 |
|
|
1436 |
"Smalltalk classNameForFile:'DrawObj'"
|
|
1437 |
!
|
|
1438 |
|
1
|
1439 |
fileInClassObject:aClassName from:aFileName
|
70
|
1440 |
"read in the named object file and dynamic-link it into the system
|
|
1441 |
- look for it in some standard places;
|
|
1442 |
return true if ok, false if failed."
|
1
|
1443 |
|
70
|
1444 |
"
|
|
1445 |
check if the dynamic loader class is in
|
|
1446 |
"
|
42
|
1447 |
ObjectFileLoader isNil ifTrue:[^ false].
|
1
|
1448 |
|
70
|
1449 |
(self getSystemFileName:aFileName) isNil ifTrue:[^ false].
|
10
|
1450 |
^ (ObjectFileLoader loadClass:aClassName fromObjectFile:aFileName) notNil
|
1
|
1451 |
|
70
|
1452 |
"
|
|
1453 |
Smalltalk fileInClassObject:'AbstractPath' from:'../goodies/Paths/AbstrPath.o'
|
|
1454 |
"
|
1
|
1455 |
!
|
|
1456 |
|
|
1457 |
fileIn:aFileName
|
|
1458 |
"read in the named file - look for it in some standard places;
|
|
1459 |
return true if ok, false if failed"
|
|
1460 |
|
122
|
1461 |
|aStream path|
|
|
1462 |
|
|
1463 |
"
|
|
1464 |
an object or shared object ?
|
|
1465 |
"
|
|
1466 |
((aFileName endsWith:'.o')
|
|
1467 |
or:[(aFileName endsWith:'.obj')
|
|
1468 |
or:[aFileName endsWith:'.so']]) ifTrue:[
|
159
|
1469 |
ObjectFileLoader isNil ifTrue:[^ false].
|
122
|
1470 |
path := self getSystemFileName:aFileName.
|
|
1471 |
path isNil ifTrue:[^ false].
|
|
1472 |
^ ObjectFileLoader loadObjectFile:aFileName
|
|
1473 |
].
|
1
|
1474 |
|
|
1475 |
aStream := self systemFileStreamFor:aFileName.
|
|
1476 |
aStream isNil ifTrue:[^ false].
|
|
1477 |
|
|
1478 |
[aStream fileIn] valueNowOrOnUnwindDo:[aStream close].
|
|
1479 |
^ true
|
|
1480 |
|
77
|
1481 |
"
|
|
1482 |
Smalltalk fileIn:'games/TicTacToe.st'
|
|
1483 |
"
|
1
|
1484 |
!
|
|
1485 |
|
|
1486 |
fileInChanges
|
|
1487 |
"read in the last changes file - bringing the system to the state it
|
70
|
1488 |
had when left the last time.
|
|
1489 |
WARNING: this method is rubbish: it should only read things after the
|
159
|
1490 |
last '**snapshot**' - entry."
|
1
|
1491 |
|
|
1492 |
|upd|
|
|
1493 |
|
70
|
1494 |
"
|
|
1495 |
tell Class to NOT update the changes file now ...
|
|
1496 |
"
|
1
|
1497 |
upd := Class updateChanges:false.
|
95
|
1498 |
[
|
159
|
1499 |
self fileIn:'changes'
|
95
|
1500 |
] valueNowOrOnUnwindDo:[
|
159
|
1501 |
Class updateChanges:upd
|
95
|
1502 |
]
|
1
|
1503 |
|
77
|
1504 |
"
|
|
1505 |
Smalltalk fileInChanges
|
|
1506 |
"
|
1
|
1507 |
!
|
|
1508 |
|
|
1509 |
fileInClass:aClassName
|
10
|
1510 |
"find a source/object file for aClassName and -if found - load it.
|
95
|
1511 |
search is in some standard places trying driver-file (.ld), object-file (.o) and
|
|
1512 |
finally source file (.st) in that order.
|
70
|
1513 |
The file is first searched for using the class name, then the abbreviated name."
|
1
|
1514 |
|
95
|
1515 |
|shortName newClass upd ok nm|
|
1
|
1516 |
|
7
|
1517 |
upd := Class updateChanges:false.
|
|
1518 |
[
|
159
|
1519 |
"
|
|
1520 |
first, look for a loader-driver file (in fileIn/xxx.ld)
|
|
1521 |
"
|
|
1522 |
(self fileIn:('fileIn/' , aClassName , '.ld'))
|
|
1523 |
ifFalse:[
|
|
1524 |
shortName := self fileNameForClass:aClassName.
|
|
1525 |
"
|
|
1526 |
try abbreviated driver-file (in fileIn/xxx.ld)
|
|
1527 |
"
|
|
1528 |
(self fileIn:('fileIn/' , shortName , '.ld'))
|
|
1529 |
ifFalse:[
|
|
1530 |
"
|
|
1531 |
then, if dynamic linking is available, look for a shared binary in binary/xxx.o
|
|
1532 |
"
|
|
1533 |
ObjectFileLoader notNil ifTrue:[
|
|
1534 |
nm := 'binary/' , aClassName.
|
|
1535 |
(self fileInClassObject:aClassName from:(nm , '.so'))
|
|
1536 |
ifFalse:[
|
|
1537 |
(self fileInClassObject:aClassName from:(nm , '.o'))
|
|
1538 |
ifFalse:[
|
|
1539 |
nm := 'binary/' , shortName.
|
|
1540 |
(self fileInClassObject:aClassName from:(nm , '.so'))
|
|
1541 |
ifFalse:[
|
|
1542 |
ok := self fileInClassObject:aClassName from:(nm , '.o')
|
|
1543 |
].
|
|
1544 |
].
|
|
1545 |
].
|
|
1546 |
].
|
77
|
1547 |
|
159
|
1548 |
"
|
|
1549 |
if that did not work, look for an st-source file ...
|
|
1550 |
"
|
|
1551 |
ok ifFalse:[
|
|
1552 |
(self fileIn:(aClassName , '.st'))
|
|
1553 |
ifFalse:[
|
|
1554 |
(self fileIn:(shortName , '.st'))
|
|
1555 |
ifFalse:[
|
|
1556 |
"
|
|
1557 |
... and in the standard source-directory
|
|
1558 |
"
|
|
1559 |
(self fileIn:('source/' , aClassName , '.st'))
|
|
1560 |
ifFalse:[
|
|
1561 |
ok := self fileIn:('source/' , shortName , '.st')
|
|
1562 |
]
|
|
1563 |
]
|
|
1564 |
]
|
|
1565 |
]
|
|
1566 |
].
|
|
1567 |
]
|
7
|
1568 |
] valueNowOrOnUnwindDo:[Class updateChanges:upd].
|
|
1569 |
newClass := self at:(aClassName asSymbol).
|
70
|
1570 |
newClass notNil ifTrue:[newClass initialize]
|
159
|
1571 |
!
|
|
1572 |
|
|
1573 |
silentFileIn:aFilename
|
|
1574 |
"same as fileIn:, but do not output 'compiled...'-messages on Transcript.
|
|
1575 |
Main use is during startup."
|
|
1576 |
|
|
1577 |
|wasSilent|
|
|
1578 |
|
|
1579 |
wasSilent := self silentLoading:true.
|
|
1580 |
[
|
|
1581 |
self fileIn:aFilename
|
|
1582 |
] valueNowOrOnUnwindDo:[
|
|
1583 |
self silentLoading:wasSilent
|
|
1584 |
]
|
1
|
1585 |
! !
|
2
|
1586 |
|
|
1587 |
!Smalltalk class methodsFor: 'binary storage'!
|
|
1588 |
|
|
1589 |
addGlobalsTo: globalDictionary manager: manager
|
70
|
1590 |
|pools|
|
|
1591 |
|
|
1592 |
pools := Set new.
|
|
1593 |
self associationsDo:[:assoc |
|
159
|
1594 |
assoc value == self ifFalse:[
|
|
1595 |
assoc value isClass ifTrue:[
|
|
1596 |
assoc value addGlobalsTo:globalDictionary manager:manager.
|
|
1597 |
pools addAll:assoc value sharedPools
|
|
1598 |
] ifFalse:[
|
|
1599 |
globalDictionary at:assoc put:self
|
|
1600 |
].
|
|
1601 |
assoc value isNil ifFalse:[
|
|
1602 |
globalDictionary at:assoc value put:self
|
|
1603 |
]
|
|
1604 |
]
|
2
|
1605 |
].
|
|
1606 |
|
70
|
1607 |
pools do:[:poolDictionary|
|
159
|
1608 |
poolDictionary addGlobalsTo:globalDictionary manager:manager
|
2
|
1609 |
]
|
|
1610 |
!
|
|
1611 |
|
|
1612 |
storeBinaryDefinitionOf: anObject on: stream manager: manager
|
70
|
1613 |
|string|
|
2
|
1614 |
|
70
|
1615 |
anObject class == Association ifTrue:[
|
159
|
1616 |
string := 'Smalltalk associationAt: ', anObject key storeString
|
2
|
1617 |
] ifFalse: [
|
159
|
1618 |
string := 'Smalltalk at: ', (self keyAtValue: anObject) storeString
|
2
|
1619 |
].
|
70
|
1620 |
stream nextNumber:2 put:string size.
|
|
1621 |
string do:[:char | stream nextPut:char asciiValue]
|
2
|
1622 |
! !
|