1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
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:#Smalltalk
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:'exitBlocks CachedClasses'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
Smalltalk comment:'
|
|
21 |
|
5
|
22 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
This is one of the central classes in the system;
|
|
26 |
it provides all system-startup, shutdown and maintenance support.
|
|
27 |
Also global variables are kept here.
|
|
28 |
|
|
29 |
As you will notice, this is NOT a Dictionary
|
|
30 |
- my implementation of globals is totally different
|
|
31 |
(due to the need to be able to access globals from c-code as well).
|
|
32 |
|
5
|
33 |
$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.4 1993-10-13 02:13:47 claus Exp $
|
1
|
34 |
'!
|
|
35 |
|
|
36 |
Smalltalk at:#ErrorNumber put:nil!
|
|
37 |
Smalltalk at:#ErrorString put:nil!
|
|
38 |
Smalltalk at:#Language put:#english!
|
|
39 |
Smalltalk at:#LanguageTerritory put:#usa!
|
|
40 |
Smalltalk at:#Initializing put:false!
|
|
41 |
Smalltalk at:#SilentLoading put:false!
|
|
42 |
Smalltalk at:#RecursionLimit put:nil!
|
|
43 |
Smalltalk at:#MemoryLimit put:nil!
|
|
44 |
Smalltalk at:#SystemPath put:nil!
|
|
45 |
Smalltalk at:#StartupClass put:nil!
|
|
46 |
Smalltalk at:#StartupSelector put:nil!
|
2
|
47 |
Smalltalk at:#StartupArguments put:nil!
|
1
|
48 |
Smalltalk at:#SignalCatchBlock put:nil!
|
|
49 |
|
|
50 |
!Smalltalk class methodsFor:'time-versions'!
|
|
51 |
|
|
52 |
majorVersion
|
|
53 |
"return the major version number"
|
|
54 |
|
|
55 |
^ 2
|
|
56 |
|
|
57 |
"Smalltalk majorVersion"
|
|
58 |
!
|
|
59 |
|
|
60 |
minorVersion
|
|
61 |
"return the minor version number"
|
|
62 |
|
|
63 |
^ 7
|
|
64 |
|
|
65 |
"Smalltalk minorVersion"
|
|
66 |
!
|
|
67 |
|
|
68 |
revision
|
|
69 |
"return the revision number"
|
|
70 |
|
2
|
71 |
^ 2
|
1
|
72 |
|
|
73 |
"Smalltalk revision"
|
|
74 |
!
|
|
75 |
|
|
76 |
version
|
|
77 |
"return the version string"
|
|
78 |
|
|
79 |
^ (self majorVersion printString ,
|
|
80 |
'.',
|
|
81 |
self minorVersion printString ,
|
|
82 |
'.',
|
|
83 |
self revision printString)
|
|
84 |
|
|
85 |
"Smalltalk version"
|
|
86 |
!
|
|
87 |
|
|
88 |
versionDate
|
|
89 |
"return the version date"
|
|
90 |
|
2
|
91 |
^ '9-Sep-1993'
|
1
|
92 |
|
|
93 |
"Smalltalk versionDate"
|
|
94 |
!
|
|
95 |
|
|
96 |
copyright
|
|
97 |
"return a copyright string"
|
|
98 |
|
|
99 |
^ 'Copyright (c) 1988-93 by Claus Gittinger'
|
|
100 |
|
|
101 |
"Smalltalk copyright"
|
|
102 |
!
|
|
103 |
|
|
104 |
hello
|
|
105 |
"return a greeting string"
|
|
106 |
|
|
107 |
(Language == #german) ifTrue:[
|
|
108 |
^ 'Willkommen bei Smalltalk/X version '
|
|
109 |
, self version , ' vom ' , self versionDate
|
|
110 |
].
|
2
|
111 |
(Language == #french) ifTrue:[
|
|
112 |
^ 'Bienvenue a Smalltalk/X version '
|
|
113 |
, self version , ' de ' , self versionDate
|
|
114 |
].
|
1
|
115 |
^ 'Hello World - here is Smalltalk/X version '
|
|
116 |
, self version , ' of ' , self versionDate
|
|
117 |
|
|
118 |
"Smalltalk hello"
|
|
119 |
!
|
|
120 |
|
|
121 |
timeStamp
|
|
122 |
"return a string useful for timestamping a file"
|
|
123 |
|
|
124 |
^ '''From Smalltalk/X, Version:' , (Smalltalk version) , ' on '
|
|
125 |
, Date today printString , ' at ' , Time now printString
|
|
126 |
, ''''
|
|
127 |
! !
|
|
128 |
|
|
129 |
!Smalltalk class methodsFor:'initialization'!
|
|
130 |
|
|
131 |
initialize
|
|
132 |
"this one is called from init - initialize all other classes"
|
|
133 |
|
|
134 |
self initGlobalsFromEnvironment.
|
|
135 |
|
|
136 |
"sorry - there are some, which MUST be initialized before ..
|
|
137 |
reason: if any error happens during init, we need Stdout to be there"
|
|
138 |
|
|
139 |
Object initialize.
|
|
140 |
|
|
141 |
ExternalStream initialize.
|
|
142 |
self initStandardStreams.
|
|
143 |
|
|
144 |
"sorry, path must be set before ...
|
|
145 |
reason: some classes need it during initialize"
|
|
146 |
|
|
147 |
self initSystemPath.
|
|
148 |
|
|
149 |
"must init display here - some classes (Color) need it during
|
|
150 |
initialize"
|
|
151 |
|
|
152 |
Workstation notNil ifTrue:[
|
|
153 |
Workstation initialize
|
|
154 |
].
|
|
155 |
|
|
156 |
Inspector := MiniInspector.
|
|
157 |
Debugger := MiniDebugger.
|
|
158 |
Compiler := ByteCodeCompiler.
|
|
159 |
Compiler isNil ifTrue:[
|
|
160 |
"this allows at least immediate evaluations"
|
|
161 |
Compiler := Parser
|
|
162 |
].
|
|
163 |
|
2
|
164 |
self allBehaviorsDo:[:aClass |
|
1
|
165 |
"aviod never-ending story ..."
|
|
166 |
(aClass ~~ Smalltalk) ifTrue:[
|
|
167 |
aClass initialize
|
|
168 |
]
|
|
169 |
].
|
|
170 |
self initStandardTools.
|
|
171 |
self initInterrupts
|
|
172 |
|
|
173 |
"Smalltalk initialize"
|
|
174 |
!
|
|
175 |
|
|
176 |
initGlobalsFromEnvironment
|
|
177 |
"setup globals from the shell-environment"
|
|
178 |
|
|
179 |
|envString firstChar i langString terrString|
|
|
180 |
|
|
181 |
"extract Language and LanguageTerritory from LANG variable.
|
|
182 |
the language and territory must not be abbreviated,
|
|
183 |
valid is for example: english_usa
|
|
184 |
english
|
|
185 |
german
|
|
186 |
german_austria"
|
|
187 |
|
|
188 |
envString := OperatingSystem getEnvironment:'LANG'.
|
|
189 |
envString notNil ifTrue:[
|
|
190 |
i := envString indexOf:$_.
|
|
191 |
(i == 0) ifTrue:[
|
|
192 |
langString := envString.
|
|
193 |
terrString := envString
|
|
194 |
] ifFalse:[
|
|
195 |
langString := envString copyFrom:1 to:(i - 1).
|
|
196 |
terrString := envString copyFrom:(i + 1)
|
|
197 |
].
|
|
198 |
Language := langString asSymbol.
|
|
199 |
LanguageTerritory := terrString asSymbol
|
|
200 |
].
|
|
201 |
|
|
202 |
envString := OperatingSystem getEnvironment:'VIEW3D'.
|
|
203 |
envString notNil ifTrue:[
|
|
204 |
firstChar := (envString at:1) asLowercase.
|
|
205 |
(firstChar == $t) ifTrue:[
|
|
206 |
Smalltalk at:#View3D put:true
|
|
207 |
] ifFalse: [
|
|
208 |
Smalltalk at:#View3D put:false
|
|
209 |
]
|
|
210 |
]
|
|
211 |
"Smalltalk initGlobalsFromEnvironment"
|
|
212 |
!
|
|
213 |
|
|
214 |
initStandardTools
|
|
215 |
"predefine some tools we will need later
|
|
216 |
- if the view-classes exist,
|
|
217 |
they will redefine Inspector and Debugger for graphical interfaces"
|
|
218 |
|
|
219 |
"redefine debug-tools, if view-classes exist"
|
|
220 |
|
|
221 |
(Smalltalk at:#Display) notNil ifTrue:[
|
|
222 |
(Smalltalk at:#InspectorView) notNil ifTrue:[
|
|
223 |
Inspector := Smalltalk at:#InspectorView
|
|
224 |
].
|
|
225 |
(Smalltalk at:#DebugView) notNil ifTrue:[
|
|
226 |
Debugger := Smalltalk at:#DebugView
|
|
227 |
].
|
|
228 |
Display initialize
|
|
229 |
]
|
|
230 |
"Smalltalk initStandardTools"
|
|
231 |
!
|
|
232 |
|
|
233 |
initStandardStreams
|
|
234 |
"initialize some well-known streams"
|
|
235 |
|
|
236 |
Stdout := NonPositionableExternalStream forStdout.
|
|
237 |
Stderr := NonPositionableExternalStream forStderr.
|
|
238 |
Stdin := NonPositionableExternalStream forStdin.
|
|
239 |
Printer := PrinterStream.
|
|
240 |
Transcript := Stderr
|
|
241 |
|
|
242 |
"Smalltalk initStandardStreams"
|
|
243 |
!
|
|
244 |
|
|
245 |
initInterrupts
|
|
246 |
"initialize interrupts"
|
|
247 |
|
|
248 |
OperatingSystem enableUserInterrupts.
|
|
249 |
OperatingSystem enableSignalInterrupts.
|
2
|
250 |
OperatingSystem enableFpExceptionInterrupts.
|
|
251 |
|
|
252 |
ObjectMemory userInterruptHandler:self.
|
1
|
253 |
|
|
254 |
"Smalltalk initInterrupts"
|
|
255 |
!
|
|
256 |
|
|
257 |
initSystemPath
|
|
258 |
"setup path to search for system files"
|
|
259 |
|
|
260 |
|p|
|
|
261 |
|
|
262 |
"the path is set to search files first locally
|
|
263 |
- this allows private stuff to override global stuff"
|
|
264 |
|
|
265 |
SystemPath := OrderedCollection new.
|
|
266 |
SystemPath add:'.'.
|
|
267 |
SystemPath add:'..'.
|
|
268 |
SystemPath add:(OperatingSystem getHomeDirectory).
|
|
269 |
(OperatingSystem isDirectory:(OperatingSystem getHomeDirectory , '/.smalltalk')) ifTrue:[
|
|
270 |
SystemPath add:(OperatingSystem getHomeDirectory , '/.smalltalk')
|
|
271 |
].
|
|
272 |
p := OperatingSystem getEnvironment:'SMALLTALK_LIBDIR'.
|
|
273 |
p notNil ifTrue:[
|
|
274 |
SystemPath add:p
|
|
275 |
].
|
|
276 |
(OperatingSystem isDirectory:'/usr/local/lib/smalltalk') ifTrue:[
|
|
277 |
SystemPath add:'/usr/local/lib/smalltalk'
|
|
278 |
].
|
|
279 |
(OperatingSystem isDirectory:'/usr/lib/smalltalk') ifTrue:[
|
|
280 |
SystemPath add:'/usr/lib/smalltalk'
|
|
281 |
].
|
|
282 |
|
|
283 |
"Smalltalk initSystemPath"
|
|
284 |
"SystemPath"
|
|
285 |
!
|
|
286 |
|
|
287 |
start
|
|
288 |
"main startup, if there is a Display, initialize it
|
|
289 |
and start dispatching; otherwise go into a read-eval-print loop"
|
|
290 |
|
|
291 |
Initializing := true.
|
|
292 |
|
|
293 |
"read patches- and rc-file, do not add things into change-file"
|
|
294 |
|
|
295 |
Class updateChanges:false.
|
|
296 |
[
|
|
297 |
self fileIn:'patches'.
|
|
298 |
|
|
299 |
(self fileIn:((Arguments at:1) , '.rc')) ifFalse:[
|
|
300 |
"no .rc file where executable is; try default smalltalk.rc"
|
|
301 |
self fileIn:'smalltalk.rc'
|
|
302 |
]
|
|
303 |
] valueNowOrOnUnwindDo:[Class updateChanges:true].
|
|
304 |
|
|
305 |
SilentLoading ifFalse:[
|
|
306 |
Transcript showCr:(self hello).
|
|
307 |
Transcript showCr:(self copyright).
|
|
308 |
Transcript cr
|
|
309 |
].
|
|
310 |
|
|
311 |
Initializing := false.
|
|
312 |
DemoMode ifTrue:[
|
|
313 |
Transcript showCr:'Unlicensed demo mode with limitations.'
|
|
314 |
].
|
|
315 |
|
|
316 |
[self saveMainLoop] whileTrue:[ ].
|
|
317 |
|
|
318 |
"done"
|
|
319 |
|
|
320 |
self exit
|
|
321 |
!
|
|
322 |
|
|
323 |
restart
|
|
324 |
"startup after an image has been loaded
|
|
325 |
"
|
|
326 |
|deb insp|
|
|
327 |
|
|
328 |
Initializing := true.
|
|
329 |
|
|
330 |
"temporary switch back to dumb interface"
|
|
331 |
|
|
332 |
insp := Inspector.
|
|
333 |
deb := Debugger.
|
|
334 |
Inspector := MiniInspector.
|
|
335 |
Debugger := MiniDebugger.
|
|
336 |
|
|
337 |
ObjectMemory changed:#restarted.
|
|
338 |
|
|
339 |
"
|
|
340 |
some must be reinitialized before ...
|
|
341 |
- sorry, but order is important
|
|
342 |
"
|
|
343 |
|
|
344 |
Workstation reinitialize.
|
|
345 |
View reinitialize.
|
|
346 |
|
|
347 |
ObjectMemory changed:#returnFromSnapshot.
|
|
348 |
|
|
349 |
OperatingSystem enableUserInterrupts.
|
|
350 |
OperatingSystem enableSignalInterrupts.
|
|
351 |
|
|
352 |
Inspector := insp.
|
|
353 |
Debugger := deb.
|
|
354 |
|
|
355 |
Initializing := false.
|
|
356 |
|
|
357 |
|
|
358 |
"
|
|
359 |
if there is no Transcript, go to stderr
|
|
360 |
"
|
|
361 |
Transcript isNil ifTrue:[
|
|
362 |
self initStandardStreams.
|
|
363 |
Transcript := Stderr
|
|
364 |
].
|
|
365 |
|
|
366 |
Transcript cr.
|
|
367 |
Transcript showCr:('Smalltalk restarted from:' , ImageName).
|
|
368 |
DemoMode ifTrue:[
|
|
369 |
Transcript showCr:'Unlicensed demo mode with limitations.'
|
|
370 |
].
|
|
371 |
|
|
372 |
"this allows firing an application by defining
|
|
373 |
these two globals during snapshot ..."
|
|
374 |
|
|
375 |
StartupClass notNil ifTrue:[
|
|
376 |
StartupSelector notNil ifTrue:[
|
|
377 |
|
|
378 |
"allow customization by reading an image specific rc-file"
|
|
379 |
ImageName notNil ifTrue:[
|
|
380 |
(ImageName endsWith:'.img') ifTrue:[
|
|
381 |
self fileIn:((ImageName copyFrom:1 to:(ImageName size - 4)), '.rc')
|
|
382 |
] ifFalse:[
|
|
383 |
self fileIn:(ImageName , '.rc')
|
|
384 |
]
|
|
385 |
].
|
2
|
386 |
StartupClass perform:StartupSelector withArguments:StartupArguments
|
1
|
387 |
]
|
|
388 |
].
|
|
389 |
|
|
390 |
Display notNil ifTrue:[
|
|
391 |
Display dispatch
|
|
392 |
] ifFalse:[
|
|
393 |
self readEvalPrint
|
|
394 |
].
|
|
395 |
|
|
396 |
self exit
|
|
397 |
!
|
|
398 |
|
|
399 |
saveMainLoop
|
|
400 |
"main dispatching loop - exits with true for a bad exit (to restart),
|
|
401 |
false for real exit"
|
|
402 |
|
|
403 |
Smalltalk at:#SignalCatchBlock put:[^ true].
|
|
404 |
|
|
405 |
"if view-classes exist, start dispatching;
|
|
406 |
otherwise go into a read-eval-print loop"
|
|
407 |
|
|
408 |
Display notNil ifTrue:[
|
|
409 |
Display dispatch
|
|
410 |
] ifFalse:[
|
|
411 |
self readEvalPrint
|
|
412 |
].
|
|
413 |
^ false
|
|
414 |
!
|
|
415 |
|
|
416 |
readEvalPrint
|
|
417 |
"simple read-eval-print loop for non-graphical Tinytalk"
|
|
418 |
|
|
419 |
|text|
|
|
420 |
|
|
421 |
'ST- ' print.
|
|
422 |
Stdin skipSeparators.
|
|
423 |
text := Stdin nextChunk.
|
|
424 |
[text notNil] whileTrue:[
|
|
425 |
(Compiler evaluate:text) printNewline.
|
|
426 |
'ST- ' print.
|
|
427 |
text := Stdin nextChunk
|
|
428 |
].
|
|
429 |
'' printNewline
|
|
430 |
! !
|
|
431 |
|
|
432 |
!Smalltalk class methodsFor:'accessing'!
|
|
433 |
|
|
434 |
at:aKey
|
|
435 |
"retrieve the value stored under aKey, a symbol"
|
|
436 |
|
|
437 |
%{ /* NOCONTEXT */
|
|
438 |
extern OBJ _GETGLOBAL();
|
|
439 |
|
|
440 |
RETURN ( _GETGLOBAL(aKey) );
|
|
441 |
%}
|
|
442 |
!
|
|
443 |
|
|
444 |
at:aKey ifAbsent:aBlock
|
|
445 |
"retrieve the value stored under aKey.
|
|
446 |
If there is none stored this key, return the value of
|
|
447 |
the evaluation of aBlock"
|
|
448 |
|
|
449 |
(self includesKey:aKey) ifTrue:[
|
|
450 |
^ self at:aKey
|
|
451 |
].
|
|
452 |
^ aBlock value
|
|
453 |
!
|
|
454 |
|
|
455 |
at:aKey put:aValue
|
|
456 |
"store the argument aValue under aKey, a symbol"
|
|
457 |
|
|
458 |
CachedClasses := nil.
|
|
459 |
|
|
460 |
%{ /* NOCONTEXT */
|
|
461 |
extern OBJ _SETGLOBAL();
|
|
462 |
|
|
463 |
RETURN ( _SETGLOBAL(aKey, aValue, (OBJ *)0) );
|
|
464 |
%}
|
|
465 |
!
|
|
466 |
|
|
467 |
removeKey:aKey
|
|
468 |
"remove the argument from the globals dictionary"
|
|
469 |
|
|
470 |
CachedClasses := nil.
|
|
471 |
|
|
472 |
%{ /* NOCONTEXT */
|
|
473 |
extern OBJ _REMOVEGLOBAL();
|
|
474 |
|
|
475 |
RETURN ( _REMOVEGLOBAL(aKey) );
|
|
476 |
%}
|
|
477 |
!
|
|
478 |
|
|
479 |
includesKey:aKey
|
|
480 |
"return true, if the key is known"
|
|
481 |
|
|
482 |
%{ /* NOCONTEXT */
|
|
483 |
extern OBJ _KEYKNOWN();
|
|
484 |
|
|
485 |
RETURN ( _KEYKNOWN(aKey) );
|
|
486 |
%}
|
|
487 |
!
|
|
488 |
|
|
489 |
keyAtValue:anObject
|
|
490 |
"return the symbol under which anObject is stored - or nil"
|
|
491 |
|
|
492 |
self allKeysDo:[:aKey |
|
|
493 |
(self at:aKey) == anObject ifTrue:[^ aKey]
|
|
494 |
]
|
|
495 |
|
|
496 |
"Smalltalk keyAtValue:Object"
|
|
497 |
!
|
|
498 |
|
|
499 |
keys
|
|
500 |
"return a collection with all keys in the Smalltalk dictionary"
|
|
501 |
|
|
502 |
|keys|
|
|
503 |
|
|
504 |
keys := OrderedCollection new.
|
|
505 |
self allKeysDo:[:k | keys add:k].
|
|
506 |
^ keys
|
|
507 |
! !
|
|
508 |
|
|
509 |
!Smalltalk class methodsFor:'copying'!
|
|
510 |
|
|
511 |
shallowCopy
|
|
512 |
"redefine copy - there is only one Smalltalk dictionary"
|
|
513 |
|
|
514 |
^ self
|
|
515 |
!
|
|
516 |
|
|
517 |
deepCopy
|
|
518 |
"redefine copy - there is only one Smalltalk dictionary"
|
|
519 |
|
|
520 |
^ self
|
|
521 |
! !
|
|
522 |
|
|
523 |
!Smalltalk class methodsFor:'inspecting'!
|
|
524 |
|
|
525 |
inspect
|
|
526 |
"redefined to launch a DictionaryInspector on the receiver
|
|
527 |
(instead of the default InspectorView)."
|
|
528 |
|
|
529 |
DictionaryInspectorView isNil ifTrue:[
|
|
530 |
super inspect
|
|
531 |
] ifFalse:[
|
|
532 |
DictionaryInspectorView openOn:self
|
|
533 |
]
|
|
534 |
! !
|
|
535 |
|
|
536 |
!Smalltalk class methodsFor:'misc stuff'!
|
|
537 |
|
|
538 |
addExitBlock:aBlock
|
|
539 |
"add a block to be executed when Smalltalk finishes"
|
|
540 |
|
|
541 |
exitBlocks isNil ifTrue:[
|
|
542 |
exitBlocks := Array with:aBlock
|
|
543 |
] ifFalse:[
|
|
544 |
exitBlocks add:aBlock
|
|
545 |
]
|
|
546 |
!
|
|
547 |
|
|
548 |
exit
|
|
549 |
"finish Smalltalk system"
|
|
550 |
|
|
551 |
exitBlocks notNil ifTrue:[
|
|
552 |
exitBlocks do:[:aBlock |
|
|
553 |
aBlock value
|
|
554 |
]
|
|
555 |
].
|
|
556 |
%{
|
|
557 |
mainExit(0);
|
|
558 |
%}
|
|
559 |
.
|
|
560 |
OperatingSystem exit
|
|
561 |
|
|
562 |
"Smalltalk exit"
|
|
563 |
!
|
|
564 |
|
|
565 |
sleep:aDelay
|
|
566 |
"wait for aDelay seconds"
|
|
567 |
|
|
568 |
OperatingSystem sleep:aDelay
|
|
569 |
! !
|
|
570 |
|
|
571 |
!Smalltalk class methodsFor:'debugging'!
|
|
572 |
|
|
573 |
printStackBacktrace
|
|
574 |
"print a stack backtrace"
|
|
575 |
|
|
576 |
%{
|
|
577 |
printStack(__context);
|
|
578 |
%}
|
|
579 |
!
|
|
580 |
|
|
581 |
fatalAbort
|
|
582 |
"abort program and dump core"
|
|
583 |
%{
|
|
584 |
fatal0(__context, "abort");
|
|
585 |
%}
|
|
586 |
!
|
|
587 |
|
|
588 |
statistic
|
|
589 |
"print some statistic data"
|
|
590 |
%{
|
|
591 |
statistic();
|
|
592 |
%}
|
|
593 |
!
|
|
594 |
|
|
595 |
debugOn
|
|
596 |
"temporary"
|
|
597 |
|
|
598 |
"LookupTrace := true. "
|
|
599 |
MessageTrace := true.
|
|
600 |
"AllocTrace := true. "
|
|
601 |
ObjectMemory flushInlineCaches
|
|
602 |
!
|
|
603 |
|
|
604 |
debugOff
|
|
605 |
"temporary"
|
|
606 |
|
|
607 |
LookupTrace := nil.
|
|
608 |
MessageTrace := nil
|
|
609 |
". AllocTrace := nil "
|
|
610 |
!
|
|
611 |
|
|
612 |
allocDebugOn
|
|
613 |
"temporary"
|
|
614 |
|
|
615 |
AllocTrace := true
|
|
616 |
!
|
|
617 |
|
|
618 |
allocDebugOff
|
|
619 |
"temporary"
|
|
620 |
|
|
621 |
AllocTrace := nil
|
|
622 |
!
|
|
623 |
|
|
624 |
executionDebugOn
|
|
625 |
"temporary"
|
|
626 |
|
|
627 |
ExecutionTrace := true
|
|
628 |
!
|
|
629 |
|
|
630 |
executionDebugOff
|
|
631 |
"temporary"
|
|
632 |
|
|
633 |
ExecutionTrace := nil
|
|
634 |
! !
|
|
635 |
|
|
636 |
!Smalltalk class methodsFor:'looping'!
|
|
637 |
|
|
638 |
do:aBlock
|
|
639 |
"evaluate the argument, aBlock for all values in the Smalltalk dictionary"
|
|
640 |
%{
|
|
641 |
__allGlobalsDo(&aBlock COMMA_CON);
|
|
642 |
%}
|
|
643 |
!
|
|
644 |
|
|
645 |
allKeysDo:aBlock
|
|
646 |
"evaluate the argument, aBlock for all keys in the Smalltalk dictionary"
|
|
647 |
%{
|
|
648 |
__allKeysDo(&aBlock COMMA_CON);
|
|
649 |
%}
|
|
650 |
!
|
|
651 |
|
2
|
652 |
allBehaviorsDo:aBlock
|
1
|
653 |
"evaluate the argument, aBlock for all classes in the system"
|
|
654 |
|
|
655 |
self allClasses do:aBlock
|
|
656 |
!
|
|
657 |
|
2
|
658 |
allClassesDo:aBlock
|
|
659 |
"evaluate the argument, aBlock for all classes in the system.
|
|
660 |
Backward compatibility - use allBehaviorsDo: for ST-80 compatibility."
|
|
661 |
|
|
662 |
^ self allBehaviorsDo:aBlock
|
|
663 |
!
|
|
664 |
|
1
|
665 |
associationsDo:aBlock
|
|
666 |
"evaluate the argument, aBlock for all key/value pairs
|
|
667 |
in the Smalltalk dictionary"
|
|
668 |
|
|
669 |
self allKeysDo:[:aKey |
|
|
670 |
aBlock value:(aKey -> (self at:aKey))
|
|
671 |
]
|
|
672 |
|
|
673 |
"Smalltalk associationsDo:[:assoc | assoc printNewline]"
|
|
674 |
! !
|
|
675 |
|
|
676 |
!Smalltalk class methodsFor:'queries'!
|
|
677 |
|
|
678 |
numberOfGlobals
|
|
679 |
"return the number of global variables in the system"
|
|
680 |
|
|
681 |
|tally|
|
|
682 |
|
|
683 |
tally := 0.
|
|
684 |
self do:[:obj | tally := tally + 1].
|
|
685 |
^ tally
|
|
686 |
|
|
687 |
"Smalltalk numberOfGlobals"
|
|
688 |
!
|
|
689 |
|
|
690 |
cellAt:aName
|
|
691 |
"return the address of a global cell
|
|
692 |
- used internally for compiler only"
|
|
693 |
|
|
694 |
%{ /* NOCONTEXT */
|
|
695 |
extern OBJ _GETGLOBALCELL();
|
|
696 |
|
|
697 |
RETURN ( _GETGLOBALCELL(aName) );
|
|
698 |
%}
|
|
699 |
!
|
|
700 |
|
|
701 |
references:anObject
|
|
702 |
"return true, if I refer to the argument, anObject
|
|
703 |
must be reimplemented since Smalltalk is no real collection"
|
|
704 |
|
|
705 |
self do:[:o |
|
|
706 |
(o == anObject) ifTrue:[^ true]
|
|
707 |
].
|
|
708 |
^ false
|
|
709 |
!
|
|
710 |
|
|
711 |
allClasses
|
|
712 |
"return a collection of all classes in the system"
|
|
713 |
|
|
714 |
CachedClasses isNil ifTrue:[
|
|
715 |
CachedClasses := IdentitySet new:400.
|
|
716 |
self do:[:anObject |
|
|
717 |
anObject notNil ifTrue:[
|
|
718 |
(anObject isBehavior) ifTrue:[
|
|
719 |
CachedClasses add:anObject
|
|
720 |
]
|
|
721 |
]
|
|
722 |
]
|
|
723 |
].
|
|
724 |
^ CachedClasses
|
|
725 |
|
|
726 |
"Smalltalk allClasses"
|
|
727 |
!
|
|
728 |
|
|
729 |
classNames
|
|
730 |
"return a collection of all classNames in the system"
|
|
731 |
|
|
732 |
|
|
733 |
^ self allClasses collect:[:aClass | aClass name]
|
|
734 |
! !
|
|
735 |
|
|
736 |
!Smalltalk class methodsFor:'system management'!
|
|
737 |
|
|
738 |
removeClass:aClass
|
|
739 |
"remove the argument, aClass from the smalltalk dictionary;
|
2
|
740 |
we have to flush the caches since these methods are now void.
|
|
741 |
Also, class variables of aClass are removed."
|
1
|
742 |
|
2
|
743 |
|sym cSym names|
|
1
|
744 |
|
|
745 |
sym := aClass name asSymbol.
|
|
746 |
((self at:sym) == aClass) ifTrue:[
|
|
747 |
self at:sym put:nil. "nil it out for compiled accesses"
|
2
|
748 |
self removeKey:sym.
|
|
749 |
|
|
750 |
"remove class variables"
|
|
751 |
|
|
752 |
names := aClass classVariableString asCollectionOfWords.
|
|
753 |
names do:[:name |
|
|
754 |
cSym := (sym , ':' , name) asSymbol.
|
|
755 |
self at:cSym asSymbol put:nil.
|
|
756 |
self removeKey:cSym
|
|
757 |
].
|
1
|
758 |
"
|
|
759 |
actually could get along with less flushing
|
|
760 |
(entries for aClass and subclasses only)
|
|
761 |
|
|
762 |
ObjectMemory flushInlineCachesForClass:aClass.
|
|
763 |
ObjectMemory flushMethodCacheFor:aClass
|
|
764 |
"
|
|
765 |
ObjectMemory flushInlineCaches.
|
|
766 |
ObjectMemory flushMethodCache
|
|
767 |
]
|
|
768 |
!
|
|
769 |
|
|
770 |
browseChanges
|
|
771 |
"startup a changes browser"
|
|
772 |
|
|
773 |
(self at:#ChangesBrowser) notNil ifTrue:[
|
|
774 |
ChangesBrowser start
|
|
775 |
] ifFalse:[
|
|
776 |
self error:'no ChangesBrowser'
|
|
777 |
]
|
|
778 |
|
|
779 |
"Smalltalk browseChanges "
|
|
780 |
!
|
|
781 |
|
|
782 |
browseAllSelect:aBlock
|
|
783 |
"startup a browser for all methods for which aBlock returns true"
|
|
784 |
|
|
785 |
SystemBrowser browseAllSelect:aBlock
|
|
786 |
|
|
787 |
" Smalltalk browseAllSelect:[:m | m literals isNil] "
|
|
788 |
!
|
|
789 |
|
|
790 |
browseImplementorsOf:aSelectorSymbol
|
|
791 |
"startup a browser for all methods implementing a particular message"
|
|
792 |
|
|
793 |
SystemBrowser browseImplementorsOf:aSelectorSymbol
|
|
794 |
|
|
795 |
" Smalltalk browseImplementorsOf:#at:put: "
|
|
796 |
!
|
|
797 |
|
|
798 |
browseAllCallsOn:aSelectorSymbol
|
|
799 |
"startup a browser for all methods sending a particular message"
|
|
800 |
|
|
801 |
SystemBrowser browseAllCallsOn:aSelectorSymbol
|
|
802 |
|
|
803 |
" Smalltalk browseAllCallsOn:#at:put: "
|
|
804 |
!
|
|
805 |
|
|
806 |
systemFileStreamFor:aFileName
|
|
807 |
"search aFileName in some standard places;
|
|
808 |
return a fileStream or nil if not found"
|
|
809 |
|
|
810 |
|aStream|
|
|
811 |
|
|
812 |
SystemPath do:[:dirName |
|
|
813 |
aStream := FileStream readonlyFileNamed:(dirName , '/' , aFileName).
|
|
814 |
aStream notNil ifTrue:[^ aStream]
|
|
815 |
].
|
|
816 |
^ nil
|
|
817 |
!
|
|
818 |
|
|
819 |
fileNameForClass:aClassName
|
|
820 |
"return a good filename for aClassName -
|
|
821 |
using abbreviation file if there is one"
|
|
822 |
|
|
823 |
|fileName aStream abbrev line thisName index|
|
|
824 |
|
|
825 |
fileName := aClassName.
|
|
826 |
|
|
827 |
fileName size < 10 ifTrue:[^ fileName].
|
|
828 |
|
|
829 |
"too bad - look for abbreviation"
|
|
830 |
|
|
831 |
aStream := self systemFileStreamFor:'abbrev.stc'.
|
|
832 |
aStream notNil ifTrue:[
|
|
833 |
[aStream atEnd] whileFalse:[
|
|
834 |
line := aStream nextLine.
|
|
835 |
line notNil ifTrue:[
|
|
836 |
(line countWords == 2) ifTrue:[
|
|
837 |
index := line indexOfSeparatorStartingAt:1.
|
|
838 |
(index ~~ 0) ifTrue:[
|
|
839 |
thisName := line copyFrom:1 to:(index - 1).
|
|
840 |
(thisName = fileName) ifTrue:[
|
|
841 |
abbrev := (line copyFrom:index) withoutSeparators.
|
|
842 |
aStream close.
|
|
843 |
^ abbrev
|
|
844 |
]
|
|
845 |
]
|
|
846 |
]
|
|
847 |
]
|
|
848 |
].
|
|
849 |
aStream close
|
|
850 |
].
|
|
851 |
|
|
852 |
"no file found"
|
|
853 |
OperatingSystem maxFileNameLength >= (fileName size + 3) ifTrue:[
|
|
854 |
" self warn:'filename ' , fileName , ' will not work on sys5 machines' "
|
|
855 |
] ifFalse:[
|
|
856 |
self error:'cant find short for ' , fileName , ' in abbreviation file'
|
|
857 |
].
|
|
858 |
^ fileName
|
|
859 |
!
|
|
860 |
|
2
|
861 |
classNameForFile:aFileName
|
|
862 |
"return the className which corresponds to an
|
|
863 |
abbreviated fileName"
|
|
864 |
|
|
865 |
|fileName aStream abbrev line thisName index|
|
|
866 |
|
|
867 |
"too bad - look for abbreviation"
|
|
868 |
|
|
869 |
aStream := self systemFileStreamFor:'abbrev.stc'.
|
|
870 |
aStream notNil ifTrue:[
|
|
871 |
[aStream atEnd] whileFalse:[
|
|
872 |
line := aStream nextLine.
|
|
873 |
line notNil ifTrue:[
|
|
874 |
(line countWords == 2) ifTrue:[
|
|
875 |
index := line indexOfSeparatorStartingAt:1.
|
|
876 |
(index ~~ 0) ifTrue:[
|
|
877 |
thisName := line copyFrom:1 to:(index - 1).
|
|
878 |
abbrev := (line copyFrom:index) withoutSeparators.
|
|
879 |
(abbrev = aFileName) ifTrue:[
|
|
880 |
aStream close.
|
|
881 |
^ thisName
|
|
882 |
]
|
|
883 |
]
|
|
884 |
]
|
|
885 |
]
|
|
886 |
].
|
|
887 |
aStream close
|
|
888 |
].
|
|
889 |
|
|
890 |
^ thisName
|
|
891 |
|
|
892 |
"Smalltalk classNameForFile:'DrawObj'"
|
|
893 |
!
|
|
894 |
|
1
|
895 |
fileInClassObject:aClassName from:aFileName
|
|
896 |
"read in the named object file - look for it in some standard places;
|
|
897 |
return true if ok, false if failed"
|
|
898 |
|
|
899 |
|aStream|
|
|
900 |
|
|
901 |
aStream := self systemFileStreamFor:aFileName.
|
|
902 |
aStream isNil ifTrue:[^ false].
|
|
903 |
aStream close.
|
|
904 |
|
|
905 |
(ObjectFileLoader loadClass:aClassName fromObjectFile:aFileName) isNil ifTrue:[^ false].
|
|
906 |
^ true
|
|
907 |
|
|
908 |
" Smalltalk fileInClassObject:'AbstractPath' from:'../goodies/Paths/AbstrPath.o' "
|
|
909 |
!
|
|
910 |
|
|
911 |
fileIn:aFileName
|
|
912 |
"read in the named file - look for it in some standard places;
|
|
913 |
return true if ok, false if failed"
|
|
914 |
|
|
915 |
|aStream|
|
|
916 |
|
|
917 |
aStream := self systemFileStreamFor:aFileName.
|
|
918 |
aStream isNil ifTrue:[^ false].
|
|
919 |
|
|
920 |
[aStream fileIn] valueNowOrOnUnwindDo:[aStream close].
|
|
921 |
^ true
|
|
922 |
|
|
923 |
" Smalltalk fileIn:'games/TicTacToe.st' "
|
|
924 |
!
|
|
925 |
|
|
926 |
fileInChanges
|
|
927 |
"read in the last changes file - bringing the system to the state it
|
|
928 |
had when left the last time"
|
|
929 |
|
|
930 |
|upd|
|
|
931 |
|
|
932 |
"tell Class to NOT update the changes file now ..."
|
|
933 |
upd := Class updateChanges:false.
|
|
934 |
[self fileIn:'changes'] valueNowOrOnUnwindDo:[Class updateChanges:upd]
|
|
935 |
|
|
936 |
"Smalltalk fileInChanges "
|
|
937 |
!
|
|
938 |
|
|
939 |
fileInClass:aClassName
|
|
940 |
"find a source/object file for aClassName and -if found - load it"
|
|
941 |
|
|
942 |
|fName newClass upd|
|
|
943 |
|
|
944 |
fName := self fileNameForClass:aClassName.
|
|
945 |
fName notNil ifTrue:[
|
|
946 |
upd := Class updateChanges:false.
|
|
947 |
[
|
|
948 |
(self fileIn:('fileIn/' , fName , '.ld')) ifFalse:[
|
|
949 |
(self fileInClassObject:aClassName from:('binary/' , fName, '.so')) ifFalse:[
|
|
950 |
(self fileInClassObject:aClassName from:('binary/' , fName, '.o')) ifFalse:[
|
2
|
951 |
(self fileIn:(fName , '.st')) ifFalse:[
|
|
952 |
self fileIn:('source/' , fName , '.st')
|
|
953 |
]
|
1
|
954 |
]
|
|
955 |
]
|
|
956 |
]
|
|
957 |
] valueNowOrOnUnwindDo:[Class updateChanges:upd].
|
|
958 |
newClass := self at:(aClassName asSymbol).
|
|
959 |
(newClass notNil
|
|
960 |
and:[newClass implements:#initialize]) ifTrue:[newClass initialize]
|
|
961 |
]
|
|
962 |
! !
|
2
|
963 |
|
|
964 |
!Smalltalk class methodsFor: 'binary storage'!
|
|
965 |
|
|
966 |
addGlobalsTo: globalDictionary manager: manager
|
|
967 |
| pools |
|
|
968 |
pools _ Set new.
|
|
969 |
self associationsDo: [:assoc|
|
|
970 |
assoc value == self ifFalse:[
|
|
971 |
assoc value isClass ifTrue: [
|
|
972 |
assoc value addGlobalsTo: globalDictionary manager: manager.
|
|
973 |
"pools addAll: assoc value sharedPools"
|
|
974 |
] ifFalse: [
|
|
975 |
globalDictionary at: assoc put: self
|
|
976 |
].
|
|
977 |
assoc value isNil ifFalse:[
|
|
978 |
globalDictionary at: assoc value put: self
|
|
979 |
]
|
|
980 |
]
|
|
981 |
].
|
|
982 |
|
|
983 |
pools do: [:poolDictionary|
|
|
984 |
poolDictionary addGlobalsTo: globalDictionary manager: manager
|
|
985 |
]
|
|
986 |
!
|
|
987 |
|
|
988 |
storeBinaryDefinitionOf: anObject on: stream manager: manager
|
|
989 |
| string |
|
|
990 |
|
|
991 |
anObject class == Association ifTrue: [
|
|
992 |
string := 'Smalltalk associationAt: ', anObject key storeString
|
|
993 |
] ifFalse: [
|
|
994 |
string := 'Smalltalk at: ', (self keyAtValue: anObject) storeString
|
|
995 |
].
|
|
996 |
stream nextNumber: 2 put: string size.
|
|
997 |
string do: [:char| stream nextPut: char asciiValue]
|
|
998 |
! !
|