Smalltalk.st
changeset 159 514c749165c3
parent 146 7c684e19ddc7
child 161 ed36169f354d
equal deleted inserted replaced
158:be947d4e7fb2 159:514c749165c3
     1 "
     1 "
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     3               All Rights Reserved
     3 	      All Rights Reserved
     4 
     4 
     5  This software is furnished under a license and may be used
     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
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
    11 "
    11 "
    12 
    12 
    13 Object subclass:#Smalltalk
    13 Object subclass:#Smalltalk
    14        instanceVariableNames:''
    14        instanceVariableNames:''
    15        classVariableNames:'ExitBlocks CachedClasses SystemPath 
    15        classVariableNames:'ExitBlocks CachedClasses SystemPath 
    16                            StartupClass StartupSelector StartupArguments
    16 			   StartupClass StartupSelector StartupArguments
    17                            CachedAbbreviations
    17 			   CachedAbbreviations
    18                            SilentLoading Initializing
    18 			   SilentLoading Initializing
    19                            StandAlone
    19 			   StandAlone
    20                            LogDoits'
    20 			   LogDoits'
    21        poolDictionaries:''
    21        poolDictionaries:''
    22        category:'System-Support'
    22        category:'System-Support'
    23 !
    23 !
    24 
    24 
    25 Smalltalk comment:'
    25 Smalltalk comment:'
    26 COPYRIGHT (c) 1988 by Claus Gittinger
    26 COPYRIGHT (c) 1988 by Claus Gittinger
    27              All Rights Reserved
    27 	     All Rights Reserved
    28 
    28 
    29 $Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.21 1994-08-23 23:11:28 claus Exp $
    29 $Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.22 1994-10-10 00:28:32 claus Exp $
    30 '!
    30 '!
    31 
    31 
    32 "
    32 "
    33  dont depend on these being global - they will become
    33  dont depend on these being global - they will become
    34  class variables of some class ...
    34  class variables of some class ...
    40 !Smalltalk class methodsFor:'documentation'!
    40 !Smalltalk class methodsFor:'documentation'!
    41 
    41 
    42 copyright
    42 copyright
    43 "
    43 "
    44  COPYRIGHT (c) 1988 by Claus Gittinger
    44  COPYRIGHT (c) 1988 by Claus Gittinger
    45               All Rights Reserved
    45 	      All Rights Reserved
    46 
    46 
    47  This software is furnished under a license and may be used
    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
    48  only in accordance with the terms of that license and with the
    49  inclusion of the above copyright notice.   This software may not
    49  inclusion of the above copyright notice.   This software may not
    50  be provided or otherwise made available to, or used by, any
    50  be provided or otherwise made available to, or used by, any
    53 "
    53 "
    54 !
    54 !
    55 
    55 
    56 version
    56 version
    57 "
    57 "
    58 $Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.21 1994-08-23 23:11:28 claus Exp $
    58 $Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.22 1994-10-10 00:28:32 claus Exp $
    59 "
    59 "
    60 !
    60 !
    61 
    61 
    62 documentation
    62 documentation
    63 "
    63 "
    70        (due to the need to be able to access globals from c-code as well).
    70        (due to the need to be able to access globals from c-code as well).
    71     However, it provides the known enumeration protocol.
    71     However, it provides the known enumeration protocol.
    72     It may change to become a subclass of collection at some time ...
    72     It may change to become a subclass of collection at some time ...
    73 
    73 
    74     Instance variables:
    74     Instance variables:
    75                                         none - all handling is done in the VM
    75 					none - all handling is done in the VM
    76 
    76 
    77     Class variables:
    77     Class variables:
    78         ExitBlocks      <Collection>    blocks to evaluate before system is
    78 	ExitBlocks      <Collection>    blocks to evaluate before system is
    79                                         left. Not currently used.
    79 					left. Not currently used.
    80 
    80 
    81         CachedClasses   <Collection>    known classes (cached for faster enumeration)
    81 	CachedClasses   <Collection>    known classes (cached for faster enumeration)
    82 
    82 
    83         SystemPath      <Collection>    path to search for system files (sources, bitmaps etc)
    83 	SystemPath      <Collection>    path to search for system files (sources, bitmaps etc)
    84 
    84 
    85         StartupClass    <Class>         class, which gets initial message 
    85 	StartupClass    <Class>         class, which gets initial message 
    86                                         (right after VM initialization)
    86 					(right after VM initialization)
    87         StartupSelector <Symbol>        message sent to StartupClass
    87 	StartupSelector <Symbol>        message sent to StartupClass
    88 
    88 
    89         CachedAbbreviations
    89 	CachedAbbreviations
    90                         <Dictionary>    className to filename mappings
    90 			<Dictionary>    className to filename mappings
    91 
    91 
    92         SilentLoading   <Boolean>       suppresses messages during fileIn and in compiler
    92 	SilentLoading   <Boolean>       suppresses messages during fileIn and in compiler
    93                                         (can be set to true from a customized main)
    93 					(can be set to true from a customized main)
    94 
    94 
    95         LogDoits        <Boolean>       if true, doits are also logged in the changes
    95 	LogDoits        <Boolean>       if true, doits are also logged in the changes
    96                                         file. Default is false, since the changes file
    96 					file. Default is false, since the changes file
    97                                         may become huge ...
    97 					may become huge ...
    98 "
    98 "
    99 ! !
    99 ! !
   100 
   100 
   101 !Smalltalk class methodsFor:'time-versions'!
   101 !Smalltalk class methodsFor:'time-versions'!
   102 
   102 
   149 
   149 
   150     "
   150     "
   151      Smalltalk versionString
   151      Smalltalk versionString
   152     "
   152     "
   153 "
   153 "
   154 $Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.21 1994-08-23 23:11:28 claus Exp $
   154 $Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.22 1994-10-10 00:28:32 claus Exp $
   155 "
   155 "
   156 !
   156 !
   157 
   157 
   158 versionDate
   158 versionDate
   159     "return the version date - thats the date when the smalltalk
   159     "return the version date - thats the date when the smalltalk
   162 %{
   162 %{
   163 #ifdef VERSIONDATE_STRING
   163 #ifdef VERSIONDATE_STRING
   164     RETURN ( _MKSTRING(VERSIONDATE_STRING COMMA_SND) );
   164     RETURN ( _MKSTRING(VERSIONDATE_STRING COMMA_SND) );
   165 #endif
   165 #endif
   166 %}.
   166 %}.
   167     ^ '3-aug-1994'
   167     ^ '23-aug-1994'
   168 
   168 
   169     "
   169     "
   170      Smalltalk versionDate
   170      Smalltalk versionDate
   171     "
   171     "
   172 !      
   172 !      
   203     "stupid: this should come from a resource file ...
   203     "stupid: this should come from a resource file ...
   204      but I dont use it here, to allow mini-systems without
   204      but I dont use it here, to allow mini-systems without
   205      Resource-stuff."
   205      Resource-stuff."
   206 
   206 
   207     (Language == #german) ifTrue:[
   207     (Language == #german) ifTrue:[
   208         ^ 'Willkommen bei SmallTalk/X version '
   208 	^ 'Willkommen bei SmallTalk/X version '
   209           , self versionString , ' vom ' , self versionDate
   209 	  , self versionString , ' vom ' , self versionDate
   210     ].
   210     ].
   211     (Language == #french) ifTrue:[
   211     (Language == #french) ifTrue:[
   212         ^ 'Bienvenue a SmallTalk/X version '
   212 	^ 'Bienvenue a SmallTalk/X version '
   213           , self versionString , ' de ' , self versionDate
   213 	  , self versionString , ' de ' , self versionDate
   214     ].
   214     ].
   215     ^ 'Hello World - here is SmallTalk/X version '
   215     ^ 'Hello World - here is SmallTalk/X version '
   216       , self versionString , ' of ' , self versionDate
   216       , self versionString , ' of ' , self versionDate
   217 
   217 
   218     "
   218     "
   253 
   253 
   254     "
   254     "
   255      must init display here - some classes (Color, Form) need it during initialize
   255      must init display here - some classes (Color, Form) need it during initialize
   256     "
   256     "
   257     Workstation notNil ifTrue:[
   257     Workstation notNil ifTrue:[
   258         Workstation initialize
   258 	Workstation initialize
   259     ].
   259     ].
   260 
   260 
   261     "
   261     "
   262      define low-level debugging tools - graphical classes are not prepared yet
   262      define low-level debugging tools - graphical classes are not prepared yet
   263      to handle things ... 
   263      to handle things ... 
   265     "
   265     "
   266     Inspector := MiniInspector.
   266     Inspector := MiniInspector.
   267     Debugger := MiniDebugger.
   267     Debugger := MiniDebugger.
   268     Compiler := ByteCodeCompiler.
   268     Compiler := ByteCodeCompiler.
   269     Compiler isNil ifTrue:[
   269     Compiler isNil ifTrue:[
   270         "
   270 	"
   271          ByteCodeCompiler is not in the system (i.e. has not been linked in)
   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
   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.
   273 	 NOTICE: a parser is always needed, otherwise we cannot read resource files etc.
   274         "
   274 	"
   275         Compiler := Parser
   275 	Compiler := Parser
   276     ].
   276     ].
   277 
   277 
   278     "
   278     "
   279      now finally initialize all classes
   279      now, finally, initialize all leftover classes
   280     "
   280     "
       
   281 "/    Object allSubclassesInOrderDo:[:aClass |
   281     self allBehaviorsDo:[:aClass |
   282     self allBehaviorsDo:[:aClass |
   282         "
   283 	"
   283          avoid never-ending story ...
   284 	 avoid never-ending story ...
   284         "
   285 	"
   285         (aClass ~~ Smalltalk) ifTrue:[
   286 	(aClass ~~ Smalltalk) ifTrue:[
   286             aClass initialize
   287 "/ 'init ' print. aClass name printNL.
   287         ]
   288 	    aClass initialize
   288     ].
   289 	]
       
   290     ].
       
   291 
   289     "
   292     "
   290      now we can enable the graphical debugger/inspector
   293      now we can enable the graphical debugger/inspector
   291     "
   294     "
   292     self initStandardTools.
   295     self initStandardTools.
   293     self initInterrupts.
   296     self initInterrupts.
   308 
   311 
   309     "
   312     "
   310      extract Language and LanguageTerritory from LANG variable.
   313      extract Language and LanguageTerritory from LANG variable.
   311      the language and territory must not be abbreviated,
   314      the language and territory must not be abbreviated,
   312      valid is for example: english_usa
   315      valid is for example: english_usa
   313                            english
   316 			   english
   314                            german
   317 			   german
   315                            german_austria
   318 			   german_austria
   316     "
   319     "
   317 
   320 
   318     envString := OperatingSystem getEnvironment:'LANG'.
   321     envString := OperatingSystem getEnvironment:'LANG'.
   319     envString notNil ifTrue:[
   322     envString notNil ifTrue:[
   320         i := envString indexOf:$_.
   323 	i := envString indexOf:$_.
   321         (i == 0) ifTrue:[
   324 	(i == 0) ifTrue:[
   322             langString := envString.
   325 	    langString := envString.
   323             terrString := envString
   326 	    terrString := envString
   324         ] ifFalse:[
   327 	] ifFalse:[
   325             langString := envString copyTo:(i - 1).
   328 	    langString := envString copyTo:(i - 1).
   326             terrString := envString copyFrom:(i + 1)
   329 	    terrString := envString copyFrom:(i + 1)
   327         ].
   330 	].
   328         Language := langString asSymbol.
   331 	Language := langString asSymbol.
   329         LanguageTerritory := terrString asSymbol
   332 	LanguageTerritory := terrString asSymbol
   330     ].
   333     ].
   331 
   334 
   332     "
   335     "
   333      this too is a leftover - once all refs to View3D
   336      this too is a leftover - once all refs to View3D
   334      are removed, this will vanish ...
   337      are removed, this will vanish ...
   335      (please use: View>>defaultStyle:)
   338      (please use: View>>defaultStyle:)
   336     "
   339     "
   337     envString := OperatingSystem getEnvironment:'VIEW3D'.
   340     envString := OperatingSystem getEnvironment:'VIEW3D'.
   338     envString notNil ifTrue:[
   341     envString notNil ifTrue:[
   339         firstChar := (envString at:1) asLowercase.
   342 	firstChar := (envString at:1) asLowercase.
   340         (firstChar == $t) ifTrue:[
   343 	(firstChar == $t) ifTrue:[
   341             Smalltalk at:#View3D put:true
   344 	    Smalltalk at:#View3D put:true
   342         ] ifFalse: [
   345 	] ifFalse: [
   343             Smalltalk at:#View3D put:false
   346 	    Smalltalk at:#View3D put:false
   344         ]
   347 	]
   345     ]
   348     ]
   346     "Smalltalk initGlobalsFromEnvironment"
   349     "Smalltalk initGlobalsFromEnvironment"
   347 !
   350 !
   348 
   351 
   349 initStandardTools
   352 initStandardTools
   352        they will redefine Inspector and Debugger for graphical interfaces"
   355        they will redefine Inspector and Debugger for graphical interfaces"
   353 
   356 
   354     "redefine debug-tools, if view-classes exist"
   357     "redefine debug-tools, if view-classes exist"
   355 
   358 
   356     Display notNil ifTrue:[
   359     Display notNil ifTrue:[
   357         InspectorView notNil ifTrue:[
   360 	InspectorView notNil ifTrue:[
   358             Inspector := InspectorView
   361 	    Inspector := InspectorView
   359         ].
   362 	].
   360         DebugView notNil ifTrue:[
   363 	DebugView notNil ifTrue:[
   361             Debugger := DebugView
   364 	    Debugger := DebugView
   362         ].
   365 	].
   363         Display initialize
   366 	Display initialize
   364     ]
   367     ]
   365     "Smalltalk initStandardTools"
   368     "Smalltalk initStandardTools"
   366 !
   369 !
   367 
   370 
   368 initStandardStreams
   371 initStandardStreams
   392 !
   395 !
   393 
   396 
   394 initSystemPath
   397 initSystemPath
   395     "setup path where system files are searched for.
   398     "setup path where system files are searched for.
   396      the default path is set to:
   399      the default path is set to:
   397             .
   400 	    .
   398             ..
   401 	    ..
   399             $HOME                    (if defined)
   402 	    $HOME                    (if defined)
   400             $HOME/.smalltalk         (if defined & existing)
   403 	    $HOME/.smalltalk         (if defined & existing)
   401             $SMALLTALK_LIBDIR        (if defined & existing)
   404 	    $SMALLTALK_LIBDIR        (if defined & existing)
   402             /usr/local/lib/smalltalk (if existing)
   405 	    /usr/local/lib/smalltalk (if existing)
   403             /usr/lib/smalltalk       (if existing)
   406 	    /usr/lib/smalltalk       (if existing)
   404 
   407 
   405      of course, it is possible to add entries from the 'smalltalk.rc'
   408      of course, it is possible to add entries from the 'smalltalk.rc'
   406      startup file; add expressions such as:
   409      startup file; add expressions such as:
   407             Smalltalk systemPath addFirst:'/foo/bar/baz'.
   410 	    Smalltalk systemPath addFirst:'/foo/bar/baz'.
   408         or: 
   411 	or: 
   409             Smalltalk systemPath addLast:'/fee/foe/foo'.
   412 	    Smalltalk systemPath addLast:'/fee/foe/foo'.
   410     "
   413     "
   411 
   414 
   412     |p homePath|
   415     |p homePath|
   413 
   416 
   414     homePath := OperatingSystem getHomeDirectory.
   417     homePath := OperatingSystem getHomeDirectory.
   420     SystemPath := OrderedCollection new.
   423     SystemPath := OrderedCollection new.
   421     SystemPath add:'.'.
   424     SystemPath add:'.'.
   422     SystemPath add:'..'.
   425     SystemPath add:'..'.
   423     SystemPath add:homePath.
   426     SystemPath add:homePath.
   424     (OperatingSystem isDirectory:(p := homePath , '/.smalltalk')) ifTrue:[
   427     (OperatingSystem isDirectory:(p := homePath , '/.smalltalk')) ifTrue:[
   425         SystemPath add:p
   428 	SystemPath add:p
   426     ].
   429     ].
   427     p := OperatingSystem getEnvironment:'SMALLTALK_LIBDIR'.
   430     p := OperatingSystem getEnvironment:'SMALLTALK_LIBDIR'.
   428     p notNil ifTrue:[
   431     p notNil ifTrue:[
   429         SystemPath add:p
   432 	SystemPath add:p
   430     ].
   433     ].
   431     (OperatingSystem isDirectory:'/usr/local/lib/smalltalk') ifTrue:[
   434     (OperatingSystem isDirectory:'/usr/local/lib/smalltalk') ifTrue:[
   432         SystemPath add:'/usr/local/lib/smalltalk'
   435 	SystemPath add:'/usr/local/lib/smalltalk'
   433     ].
   436     ].
   434     (OperatingSystem isDirectory:'/usr/lib/smalltalk') ifTrue:[
   437     (OperatingSystem isDirectory:'/usr/lib/smalltalk') ifTrue:[
   435         SystemPath add:'/usr/lib/smalltalk'
   438 	SystemPath add:'/usr/lib/smalltalk'
   436     ].
   439     ].
   437 
   440 
   438     "
   441     "
   439      Smalltalk initSystemPath
   442      Smalltalk initSystemPath
   440      Smalltalk systemPath
   443      Smalltalk systemPath
   446      and start dispatching; otherwise go into a read-eval-print loop"
   449      and start dispatching; otherwise go into a read-eval-print loop"
   447 
   450 
   448     |idx|
   451     |idx|
   449 
   452 
   450     Initializing := true.
   453     Initializing := true.
   451     Processor := ProcessorScheduler new.
   454 "/    Processor := ProcessorScheduler new.
   452 
   455 
   453     "
   456     "
   454      while reading patches- and rc-file, do not add things into change-file
   457      while reading patches- and rc-file, do not add things into change-file
   455     "
   458     "
   456     Class updateChanges:false.
   459     Class updateChanges:false.
   461      look for a '-e filename' argument - this will force evaluation of
   464      look for a '-e filename' argument - this will force evaluation of
   462      filename only, no standard startup
   465      filename only, no standard startup
   463     "
   466     "
   464     idx := Arguments indexOf:'-e'.
   467     idx := Arguments indexOf:'-e'.
   465     idx ~~ 0 ifTrue:[
   468     idx ~~ 0 ifTrue:[
   466         self fileIn:(Arguments at:idx + 1).
   469 	self fileIn:(Arguments at:idx + 1).
   467         self exit
   470 	self exit
   468     ].
   471     ].
   469 
   472 
   470     (self fileIn:((Arguments at:1) , '.rc')) ifFalse:[
   473     (self fileIn:((Arguments at:1) , '.rc')) ifFalse:[
   471         "no .rc file where executable is; try default smalltalk.rc"
   474 	"no .rc file where executable is; try default smalltalk.rc"
   472         self fileIn:'smalltalk.rc'
   475 	(self fileIn:'smalltalk.rc') ifFalse:[
       
   476 	    Transcript showCr:'no startup rc-file found'
       
   477 	]
   473     ].
   478     ].
   474 
   479 
   475     Class updateChanges:true.
   480     Class updateChanges:true.
   476 
   481 
   477     (SilentLoading == true) ifFalse:[   "i.e. undefined counts as false" 
   482     (SilentLoading == true) ifFalse:[   "i.e. undefined counts as false" 
   478         Transcript showCr:(self hello).
   483 	Transcript showCr:(self hello).
   479         Transcript showCr:(self copyrightString).
   484 	Transcript showCr:(self copyrightString).
   480         Transcript cr.
   485 	Transcript cr.
   481 
   486 
   482         DemoMode ifTrue:[
   487 	DemoMode ifTrue:[
   483             Transcript showCr:'*** Restricted use:                              ***'.
   488 	    Transcript showCr:'*** Restricted use:                              ***'.
   484             Transcript showCr:'*** This program may be used for education only. ***'.
   489 	    Transcript showCr:'*** This program may be used for education only. ***'.
   485             Transcript showCr:'*** Please read the files COPYRIGHT and LICENSE  ***'.
   490 	    Transcript showCr:'*** Please read the files COPYRIGHT and LICENSE  ***'.
   486             Transcript showCr:'*** for more details.                            ***'.
   491 	    Transcript showCr:'*** for more details.                            ***'.
   487             Transcript cr.
   492 	    Transcript cr.
   488         ].
   493 	].
   489     ].
   494     ].
   490 
   495 
   491     Initializing := false.
   496     Initializing := false.
   492 
   497 
   493     "
   498     "
   498 
   503 
   499     "
   504     "
   500      if there is a display, start its event dispatcher 
   505      if there is a display, start its event dispatcher 
   501     "
   506     "
   502     Display notNil ifTrue:[
   507     Display notNil ifTrue:[
   503         Display startDispatch.
   508 	Display startDispatch.
   504 
   509 
   505         "this is a leftover - will vanish"
   510 	"this is a leftover - will vanish"
   506 " "
   511 " "
   507         ModalDisplay notNil ifTrue:[
   512 	ModalDisplay notNil ifTrue:[
   508             ModalDisplay startDispatch
   513 	    ModalDisplay startDispatch
   509         ]
   514 	]
   510 " "
   515 " "
   511     ].
   516     ].
   512 
   517 
   513     (StartupClass notNil and:[StartupSelector notNil]) ifTrue:[
   518     (StartupClass notNil and:[StartupSelector notNil]) ifTrue:[
   514         StartupClass perform:StartupSelector withArguments:StartupArguments.
   519 	StartupClass perform:StartupSelector withArguments:StartupArguments.
   515     ].
   520     ].
   516 
   521 
   517     "
   522     "
   518      if view-classes exist, start dispatching;
   523      if view-classes exist, start dispatching;
   519      otherwise go into a read-eval-print loop
   524      otherwise go into a read-eval-print loop
   520     "
   525     "
   521     Display notNil ifTrue:[
   526     Display notNil ifTrue:[
   522         Processor dispatchLoop
   527 	Processor dispatchLoop
   523     ] ifFalse:[
   528     ] ifFalse:[
   524         self readEvalPrint
   529 	self readEvalPrint
   525     ].
   530     ].
   526 
   531 
   527     "done"
   532     "done"
   528 
   533 
   529     self exit
   534     self exit
   532 restart
   537 restart
   533     "startup after an image has been loaded;
   538     "startup after an image has been loaded;
   534      there are three change-notifications made to dependents of ObjectMemory,
   539      there are three change-notifications made to dependents of ObjectMemory,
   535      which allow a stepwise re-init: #earlyRestart, #restarted and #returnFromSnapshot.
   540      which allow a stepwise re-init: #earlyRestart, #restarted and #returnFromSnapshot.
   536      #earlyRestart is send first, nothing has been setup yet.
   541      #earlyRestart is send first, nothing has been setup yet.
   537                    (should be used to flush all device dependent entries)
   542 		   (should be used to flush all device dependent entries)
   538      #restarted is send right after.
   543      #restarted is send right after.
   539                    (should be used to recreate external resources (fds, bitmaps etc)
   544 		   (should be used to recreate external resources (fds, bitmaps etc)
   540      #returnFromSnapshot is sent last
   545      #returnFromSnapshot is sent last
   541                    (should be used to restart processes, reOpen Streams which cannot
   546 		   (should be used to restart processes, reOpen Streams which cannot
   542                     be automatically be reopened (i.e. Sockets, Pipes) and so on.
   547 		    be automatically be reopened (i.e. Sockets, Pipes) and so on.
   543      "
   548      "
   544 
   549 
   545     |deb insp imageName|
   550     |deb insp imageName|
   546 
   551 
   547     Initializing := true.
   552     Initializing := true.
   548     Processor reInitialize.
   553     Processor reinitialize.
   549 
   554 
   550     "temporary switch back to dumb interface - 
   555     "temporary switch back to dumb interface - 
   551      to handle errors while view-stuff is not yet reinitialized"
   556      to handle errors while view-stuff is not yet reinitialized"
   552 
   557 
   553     insp := Inspector.
   558     insp := Inspector.
   562      some must be reinitialized before ...
   567      some must be reinitialized before ...
   563      - sorry, but order is important
   568      - sorry, but order is important
   564     "
   569     "
   565 
   570 
   566     Workstation notNil ifTrue:[
   571     Workstation notNil ifTrue:[
   567         Workstation reinitialize.
   572 	Workstation reinitialize.
   568     ].
   573     ].
   569 
   574 
   570     ObjectMemory changed:#returnFromSnapshot.
   575     ObjectMemory changed:#returnFromSnapshot.
   571 
   576 
   572     OperatingSystem enableUserInterrupts.
   577     OperatingSystem enableUserInterrupts.
   580 
   585 
   581     "
   586     "
   582      if there is no Transcript, go to stderr
   587      if there is no Transcript, go to stderr
   583     "
   588     "
   584     Transcript isNil ifTrue:[
   589     Transcript isNil ifTrue:[
   585         self initStandardStreams.
   590 	self initStandardStreams.
   586         Transcript := Stderr
   591 	Transcript := Stderr
   587     ].
   592     ].
   588 
   593 
   589     (SilentLoading == true) ifFalse:[
   594     (SilentLoading == true) ifFalse:[
   590         Transcript cr.
   595 	Transcript cr.
   591         Transcript showCr:('Smalltalk restarted from:' , ObjectMemory imageName).
   596 	Transcript showCr:('Smalltalk restarted from:' , ObjectMemory imageName).
   592         Transcript cr.
   597 	Transcript cr.
   593 
   598 
   594         DemoMode ifTrue:[
   599 	DemoMode ifTrue:[
   595             Transcript showCr:'*** Restricted use:                              ***'.
   600 	    Transcript showCr:'*** Restricted use:                              ***'.
   596             Transcript showCr:'*** This program may be used for education only. ***'.
   601 	    Transcript showCr:'*** This program may be used for education only. ***'.
   597             Transcript showCr:'*** Please read the files COPYRIGHT and LICENSE  ***'.
   602 	    Transcript showCr:'*** Please read the files COPYRIGHT and LICENSE  ***'.
   598             Transcript showCr:'*** for more details.                            ***'.
   603 	    Transcript showCr:'*** for more details.                            ***'.
   599             Transcript cr.
   604 	    Transcript cr.
   600         ].
   605 	].
   601     ].
   606     ].
   602 
   607 
   603     "
   608     "
   604      give user a chance to re-customize things
   609      give user a chance to re-customize things
   605     "
   610     "
   606     (Arguments includes:'-faststart') ifFalse:[
   611     (Arguments includes:'-faststart') ifFalse:[
   607         Class updateChanges:false.
   612 	Class updateChanges:false.
   608         (self fileIn:((Arguments at:1) , '_r.rc')) ifFalse:[
   613 	(self fileIn:((Arguments at:1) , '_r.rc')) ifFalse:[
   609             "no _r.rc file where executable is; try default smalltalk_r.rc"
   614 	    "no _r.rc file where executable is; try default smalltalk_r.rc"
   610             self fileIn:'smalltalk_r.rc'
   615 	    self fileIn:'smalltalk_r.rc'
   611         ].
   616 	].
   612         Class updateChanges:true.
   617 	Class updateChanges:true.
   613     ].
   618     ].
   614 
   619 
   615     "
   620     "
   616      if there is a display, start its event dispatcher 
   621      if there is a display, start its event dispatcher 
   617     "
   622     "
   618     Display notNil ifTrue:[
   623     Display notNil ifTrue:[
   619         Display startDispatch.
   624 	Display startDispatch.
   620 " "
   625 " "
   621         ModalDisplay notNil ifTrue:[
   626 	ModalDisplay notNil ifTrue:[
   622             ModalDisplay startDispatch
   627 	    ModalDisplay startDispatch
   623         ]
   628 	]
   624 " "
   629 " "
   625     ].
   630     ].
   626 
   631 
   627     "
   632     "
   628      this allows firing an application by defining
   633      this allows firing an application by defining
   629      these two globals during snapshot ... or in main
   634      these two globals during snapshot ... or in main
   630     "
   635     "
   631     (StartupClass notNil and:[StartupSelector notNil]) ifTrue:[
   636     (StartupClass notNil and:[StartupSelector notNil]) ifTrue:[
   632         "allow customization by reading an image specific rc-file"
   637 	"allow customization by reading an image specific rc-file"
   633         imageName := ObjectMemory imageName.
   638 	imageName := ObjectMemory imageName.
   634         imageName notNil ifTrue:[
   639 	imageName notNil ifTrue:[
   635             (imageName endsWith:'.img') ifTrue:[
   640 	    (imageName endsWith:'.img') ifTrue:[
   636                 self fileIn:((imageName copyTo:(imageName size - 4)), '.rc')
   641 		self fileIn:((imageName copyTo:(imageName size - 4)), '.rc')
   637             ] ifFalse:[
   642 	    ] ifFalse:[
   638                 self fileIn:(imageName , '.rc')
   643 		self fileIn:(imageName , '.rc')
   639             ]
   644 	    ]
   640         ].
   645 	].
   641         StartupClass perform:StartupSelector withArguments:StartupArguments.
   646 	StartupClass perform:StartupSelector withArguments:StartupArguments.
   642     ].
   647     ].
   643 
   648 
   644     "
   649     "
   645      if view-classes exist, start dispatching;
   650      if view-classes exist, start dispatching;
   646      otherwise go into a read-eval-print loop
   651      otherwise go into a read-eval-print loop
   647     "
   652     "
   648     Display notNil ifTrue:[
   653     Display notNil ifTrue:[
   649         Processor dispatchLoop
   654 	Processor dispatchLoop
   650     ] ifFalse:[
   655     ] ifFalse:[
   651         self readEvalPrint
   656 	self readEvalPrint
   652     ].
   657     ].
   653 
   658 
   654     self exit
   659     self exit
   655 !
   660 !
   656 
   661 
   661 
   666 
   662     'ST- ' print.
   667     'ST- ' print.
   663     Stdin skipSeparators.
   668     Stdin skipSeparators.
   664     text := Stdin nextChunk.
   669     text := Stdin nextChunk.
   665     [text notNil] whileTrue:[
   670     [text notNil] whileTrue:[
   666         (Compiler evaluate:text) printNL.
   671 	(Compiler evaluate:text) printNL.
   667         'ST- ' print.
   672 	'ST- ' print.
   668         text := Stdin nextChunk
   673 	text := Stdin nextChunk
   669     ].
   674     ].
   670     '' printNL
   675     '' printNL
   671 ! !
   676 ! !
   672 
   677 
   673 !Smalltalk class methodsFor:'startup'!
   678 !Smalltalk class methodsFor:'startup'!
   719     "retrieve the value stored at aKey.
   724     "retrieve the value stored at aKey.
   720      If there is nothing stored under this key, return the value of
   725      If there is nothing stored under this key, return the value of
   721      the evaluation of aBlock."
   726      the evaluation of aBlock."
   722 
   727 
   723     (self includesKey:aKey) ifTrue:[
   728     (self includesKey:aKey) ifTrue:[
   724         ^ self at:aKey
   729 	^ self at:aKey
   725     ].
   730     ].
   726     ^ aBlock value
   731     ^ aBlock value
   727 
   732 
   728     "
   733     "
   729      Smalltalk at:#fooBar                      <- leads to an error
   734      Smalltalk at:#fooBar                      <- leads to an error
   766 
   771 
   767 keyAtValue:anObject
   772 keyAtValue:anObject
   768     "return the symbol under which anObject is stored - or nil"
   773     "return the symbol under which anObject is stored - or nil"
   769 
   774 
   770     self allKeysDo:[:aKey |
   775     self allKeysDo:[:aKey |
   771         (self at:aKey) == anObject ifTrue:[^ aKey]
   776 	(self at:aKey) == anObject ifTrue:[^ aKey]
   772     ]
   777     ]
   773 
   778 
   774     "Smalltalk keyAtValue:Object"
   779     "Smalltalk keyAtValue:Object"
   775 !
   780 !
   776 
   781 
   815 inspect
   820 inspect
   816     "redefined to launch a DictionaryInspector on the receiver
   821     "redefined to launch a DictionaryInspector on the receiver
   817      (instead of the default InspectorView)."
   822      (instead of the default InspectorView)."
   818 
   823 
   819     DictionaryInspectorView isNil ifTrue:[
   824     DictionaryInspectorView isNil ifTrue:[
   820         super inspect
   825 	super inspect
   821     ] ifFalse:[
   826     ] ifFalse:[
   822         DictionaryInspectorView openOn:self
   827 	DictionaryInspectorView openOn:self
   823     ]
   828     ]
   824 ! !
   829 ! !
   825 
   830 
   826 !Smalltalk class methodsFor:'misc stuff'!
   831 !Smalltalk class methodsFor:'misc stuff'!
   827 
   832 
   829     "add a block to be executed when Smalltalk finishes.
   834     "add a block to be executed when Smalltalk finishes.
   830      This feature is currently not used anywhere - but could be useful for
   835      This feature is currently not used anywhere - but could be useful for
   831      cleanup in stand alone applications."
   836      cleanup in stand alone applications."
   832 
   837 
   833     ExitBlocks isNil ifTrue:[
   838     ExitBlocks isNil ifTrue:[
   834         ExitBlocks := OrderedCollection with:aBlock
   839 	ExitBlocks := OrderedCollection with:aBlock
   835     ] ifFalse:[
   840     ] ifFalse:[
   836         ExitBlocks add:aBlock
   841 	ExitBlocks add:aBlock
   837     ]
   842     ]
   838 !
   843 !
   839 
   844 
   840 exit
   845 exit
   841     "finish Smalltalk system"
   846     "finish Smalltalk system"
   842 
   847 
   843     ExitBlocks notNil ifTrue:[
   848     ExitBlocks notNil ifTrue:[
   844         ExitBlocks do:[:aBlock |
   849 	ExitBlocks do:[:aBlock |
   845             aBlock value
   850 	    aBlock value
   846         ]
   851 	]
   847     ].
   852     ].
   848     OperatingSystem exit
   853     OperatingSystem exit
   849 
   854 
   850     "Smalltalk exit"
   855     "Smalltalk exit"
   851 !
   856 !
   891 !
   896 !
   892 
   897 
   893 printStackBacktrace
   898 printStackBacktrace
   894     "print a stack backtrace - then continue.
   899     "print a stack backtrace - then continue.
   895      WARNING: this method is for debugging only 
   900      WARNING: this method is for debugging only 
   896               it may be removed without notice"
   901 	      it may be removed without notice"
   897 
   902 
   898 %{
   903 %{
   899     printStack(__context);
   904     printStack(__context);
   900 %}
   905 %}
   901     "Smalltalk printStackBacktrace"
   906     "Smalltalk printStackBacktrace"
   906 
   911 
   907 %{
   912 %{
   908     char *msg;
   913     char *msg;
   909 
   914 
   910     if (__isString(aMessage))
   915     if (__isString(aMessage))
   911         msg = (char *) _stringVal(aMessage);
   916 	msg = (char *) _stringVal(aMessage);
   912     else
   917     else
   913         msg = "fatalAbort";
   918 	msg = "fatalAbort";
   914 
   919 
   915     fatal0(__context, msg);
   920     fatal0(__context, msg);
   916     /* NEVER RETURNS */
   921     /* NEVER RETURNS */
   917 %}
   922 %}
   918 !
   923 !
   935 !
   940 !
   936 
   941 
   937 statistic
   942 statistic
   938     "print some statistic data.
   943     "print some statistic data.
   939      WARNING: this method is for debugging only 
   944      WARNING: this method is for debugging only 
   940               it may be removed without notice"
   945 	      it may be removed without notice"
   941 
   946 
   942 %{  /* NOCONTEXT */
   947 %{  /* NOCONTEXT */
   943     statistic();
   948     __STATISTIC__();
   944 %}
   949 %}
   945 !
   950 !
   946 
   951 
   947 debugOn
   952 debugOn
   948     "turns some tracing on.
   953     "turns some tracing on.
   949      WARNING: this method is for debugging only 
   954      WARNING: this method is for debugging only 
   950               it may be removed without notice"
   955 	      it may be removed without notice"
   951 
   956 
   952     "LookupTrace := true.   "
   957     "LookupTrace := true.   "
   953     MessageTrace := true.
   958     MessageTrace := true.
   954     "AllocTrace := true.     "
   959     "AllocTrace := true.     "
   955     ObjectMemory flushInlineCaches
   960     ObjectMemory flushInlineCaches
   956 !
   961 !
   957 
   962 
   958 debugOff
   963 debugOff
   959     "turns tracing off.
   964     "turns tracing off.
   960      WARNING: this method is for debugging only 
   965      WARNING: this method is for debugging only 
   961               it may be removed without notice"
   966 	      it may be removed without notice"
   962 
   967 
   963     LookupTrace := nil.    
   968     LookupTrace := nil.    
   964     MessageTrace := nil
   969     MessageTrace := nil
   965     ". AllocTrace := nil     "
   970     ". AllocTrace := nil     "
   966 !
   971 !
   967 
   972 
   968 executionDebugOn
   973 executionDebugOn
   969     "turns tracing of interpreter on.
   974     "turns tracing of interpreter on.
   970      WARNING: this method is for debugging only 
   975      WARNING: this method is for debugging only 
   971               it may be removed without notice"
   976 	      it may be removed without notice"
   972 
   977 
   973     ExecutionTrace := true
   978     ExecutionTrace := true
   974 !
   979 !
   975 
   980 
   976 executionDebugOff
   981 executionDebugOff
   977     "turns tracing of interpreter off.
   982     "turns tracing of interpreter off.
   978      WARNING: this method is for debugging only 
   983      WARNING: this method is for debugging only 
   979               it may be removed without notice"
   984 	      it may be removed without notice"
   980 
   985 
   981     ExecutionTrace := nil
   986     ExecutionTrace := nil
   982 ! !
   987 ! !
   983 
   988 
   984 !Smalltalk class methodsFor:'enumeration'!
   989 !Smalltalk class methodsFor:'enumeration'!
  1000 associationsDo:aBlock
  1005 associationsDo:aBlock
  1001     "evaluate the argument, aBlock for all key/value pairs 
  1006     "evaluate the argument, aBlock for all key/value pairs 
  1002      in the Smalltalk dictionary"
  1007      in the Smalltalk dictionary"
  1003 
  1008 
  1004     self allKeysDo:[:aKey |
  1009     self allKeysDo:[:aKey |
  1005         aBlock value:(aKey -> (self at:aKey))
  1010 	aBlock value:(aKey -> (self at:aKey))
  1006     ]
  1011     ]
  1007 
  1012 
  1008     "Smalltalk associationsDo:[:assoc | assoc printNL]"
  1013     "Smalltalk associationsDo:[:assoc | assoc printNL]"
  1009 !
  1014 !
  1010 
  1015 
  1011 keysAndValuesDo:aBlock
  1016 keysAndValuesDo:aBlock
  1012     "evaluate the two-arg block, aBlock for all keys and values"
  1017     "evaluate the two-arg block, aBlock for all keys and values"
  1013 
  1018 
  1014     self allKeysDo:[:aKey |
  1019     self allKeysDo:[:aKey |
  1015         aBlock value:aKey value:(self at:aKey)
  1020 	aBlock value:aKey value:(self at:aKey)
  1016     ]
  1021     ]
  1017 !
  1022 !
  1018 
  1023 
  1019 allBehaviorsDo:aBlock
  1024 allBehaviorsDo:aBlock
  1020     "evaluate the argument, aBlock for all classes in the system"
  1025     "evaluate the argument, aBlock for all classes in the system"
  1057 references:anObject
  1062 references:anObject
  1058     "return true, if I refer to the argument, anObject
  1063     "return true, if I refer to the argument, anObject
  1059      must be reimplemented since Smalltalk is no real collection."
  1064      must be reimplemented since Smalltalk is no real collection."
  1060 
  1065 
  1061     self do:[:o |
  1066     self do:[:o |
  1062         (o == anObject) ifTrue:[^ true]
  1067 	(o == anObject) ifTrue:[^ true]
  1063     ].
  1068     ].
  1064     ^ false
  1069     ^ false
  1065 !
  1070 !
  1066 
  1071 
  1067 allClasses
  1072 allClasses
  1068     "return a collection of all classes in the system"
  1073     "return a collection of all classes in the system"
  1069 
  1074 
  1070     CachedClasses isNil ifTrue:[
  1075     CachedClasses isNil ifTrue:[
  1071         CachedClasses := IdentitySet new:500. 
  1076 	CachedClasses := IdentitySet new:800. 
  1072         self do:[:anObject |
  1077 	self do:[:anObject |
  1073             anObject notNil ifTrue:[
  1078 	    anObject notNil ifTrue:[
  1074                 anObject isBehavior ifTrue:[
  1079 		anObject isBehavior ifTrue:[
  1075                     CachedClasses add:anObject
  1080 		    CachedClasses add:anObject
  1076                 ]
  1081 		]
  1077             ]
  1082 	    ]
  1078         ]
  1083 	]
  1079     ].
  1084     ].
  1080     ^ CachedClasses
  1085     ^ CachedClasses
  1081 
  1086 
  1082     "Smalltalk allClasses"
  1087     "Smalltalk allClasses"
  1083 !
  1088 !
  1086     "return a collection of all classNames in the system"
  1091     "return a collection of all classNames in the system"
  1087 
  1092 
  1088     ^ self allClasses collect:[:aClass | aClass name]
  1093     ^ self allClasses collect:[:aClass | aClass name]
  1089 
  1094 
  1090     "Smalltalk classNames"
  1095     "Smalltalk classNames"
       
  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     "
  1091 ! !
  1115 ! !
  1092 
  1116 
  1093 !Smalltalk class methodsFor:'class management'!
  1117 !Smalltalk class methodsFor:'class management'!
  1094 
  1118 
  1095 renameClass:aClass to:newName
  1119 renameClass:aClass to:newName
  1119 
  1143 
  1120     "rename class variables"
  1144     "rename class variables"
  1121 
  1145 
  1122     names := aClass classVariableString asCollectionOfWords.
  1146     names := aClass classVariableString asCollectionOfWords.
  1123     names do:[:name |
  1147     names do:[:name |
  1124         cSym := (oldSym , ':' , name) asSymbol.
  1148 	cSym := (oldSym , ':' , name) asSymbol.
  1125         value := self at:cSym.
  1149 	value := self at:cSym.
  1126         self at:cSym put:nil.
  1150 	self at:cSym put:nil.
  1127         self removeKey:cSym.
  1151 	self removeKey:cSym.
  1128         cSym := (newSym , ':' , name) asSymbol.
  1152 	cSym := (newSym , ':' , name) asSymbol.
  1129         self at:cSym put:value.
  1153 	self at:cSym put:value.
  1130     ].
  1154     ].
  1131 
  1155 
  1132     aClass addChangeRecordForClassRename:oldName to:newName
  1156     aClass addChangeRecordForClassRename:oldName to:newName
  1133 !
  1157 !
  1134 
  1158 
  1139 
  1163 
  1140     |sym cSym names oldName|
  1164     |sym cSym names oldName|
  1141 
  1165 
  1142     oldName := aClass name.
  1166     oldName := aClass name.
  1143     sym := oldName asSymbol.
  1167     sym := oldName asSymbol.
  1144     ((self at:sym) == aClass) ifFalse:[ ^ self].
  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     ].
  1145 
  1180 
  1146     self at:sym put:nil. "nil it out for compiled accesses"
  1181     self at:sym put:nil. "nil it out for compiled accesses"
  1147     self removeKey:sym. 
  1182     self removeKey:sym. 
  1148 
  1183 
       
  1184     aClass category:#removed.
       
  1185 
  1149     "remove class variables"
  1186     "remove class variables"
  1150 
  1187 
  1151     names := aClass classVariableString asCollectionOfWords.
  1188     names := aClass classVariableString asCollectionOfWords.
  1152     names do:[:name |
  1189     names do:[:name |
  1153         cSym := (sym , ':' , name) asSymbol.
  1190 	cSym := (sym , ':' , name) asSymbol.
  1154         self at:cSym asSymbol put:nil.
  1191 	self at:cSym asSymbol put:nil.
  1155         self removeKey:cSym
  1192 	self removeKey:cSym
  1156     ].
  1193     ].
  1157 "
  1194 "
  1158     actually could get along with less flushing
  1195     actually could get along with less flushing
  1159     (entries for aClass and subclasses only)
  1196     (entries for aClass and subclasses only)
  1160 
  1197 
  1161     aClass allSubclassesDo:[:aSubclass |
  1198     aClass allSubclassesDo:[:aSubclass |
  1162         ObjectMemory flushInlineCachesForClass:aSubclass.
  1199 	ObjectMemory flushInlineCachesForClass:aSubclass.
  1163         ObjectMemory flushMethodCacheFor:aSubclass
  1200 	ObjectMemory flushMethodCacheFor:aSubclass
  1164     ].
  1201     ].
  1165     ObjectMemory flushInlineCachesForClass:aClass.
  1202     ObjectMemory flushInlineCachesForClass:aClass.
  1166     ObjectMemory flushMethodCacheFor:aClass
  1203     ObjectMemory flushMethodCacheFor:aClass
  1167 "
  1204 "
  1168     ObjectMemory flushInlineCaches.
  1205     ObjectMemory flushInlineCaches.
  1169     ObjectMemory flushMethodCache.
  1206     ObjectMemory flushMethodCache.
  1170 
  1207 
  1171     aClass addChangeRecordForClassRemove:oldName
  1208     aClass addChangeRecordForClassRemove:oldName.
  1172 ! !
  1209 ! !
  1173 
  1210 
  1174 !Smalltalk class methodsFor:'browsing'!
  1211 !Smalltalk class methodsFor:'browsing'!
  1175 
  1212 
  1176 browseChanges
  1213 browseChanges
  1177     "startup a changes browser"
  1214     "startup a changes browser"
  1178 
  1215 
  1179     ChangesBrowser notNil ifTrue:[
  1216     ChangesBrowser notNil ifTrue:[
  1180         ChangesBrowser open
  1217 	ChangesBrowser open
  1181     ] ifFalse:[
  1218     ] ifFalse:[
  1182         self warn:'no ChangesBrowser built in'
  1219 	self warn:'no ChangesBrowser built in'
  1183     ]
  1220     ]
  1184 
  1221 
  1185     "
  1222     "
  1186      Smalltalk browseChanges
  1223      Smalltalk browseChanges
  1187     "
  1224     "
  1263 
  1300 
  1264     ^ SystemPath
  1301     ^ SystemPath
  1265 
  1302 
  1266     "
  1303     "
  1267      Smalltalk systemPath
  1304      Smalltalk systemPath
       
  1305      Smalltalk systemPath addLast:'someOtherDirectoryPath'
  1268     "
  1306     "
  1269 !
  1307 !
  1270 
  1308 
  1271 getSystemFileName:aFileName
  1309 getSystemFileName:aFileName
  1272     "search aFileName in some standard places;
  1310     "search aFileName in some standard places;
  1276     "credits for this method go to Markus ...."
  1314     "credits for this method go to Markus ...."
  1277 
  1315 
  1278     |realName|
  1316     |realName|
  1279 
  1317 
  1280     (aFileName startsWith:'/') ifTrue:[
  1318     (aFileName startsWith:'/') ifTrue:[
  1281         "dont use path for absolute file names"
  1319 	"dont use path for absolute file names"
  1282 
  1320 
  1283         ^ aFileName
  1321 	^ aFileName
  1284     ].
  1322     ].
  1285 
  1323 
  1286     SystemPath do:[:dirName |
  1324     SystemPath do:[:dirName |
  1287         (OperatingSystem isReadable:
  1325 	(OperatingSystem isReadable:
  1288             (realName := dirName , '/' , aFileName)) 
  1326 	    (realName := dirName , '/' , aFileName)) 
  1289               ifTrue: [^ realName]].
  1327 	      ifTrue: [^ realName]].
  1290     ^ nil
  1328     ^ nil
  1291 !
  1329 !
  1292 
  1330 
  1293 systemFileStreamFor:aFileName
  1331 systemFileStreamFor:aFileName
  1294     "search aFileName in some standard places;
  1332     "search aFileName in some standard places;
  1297 
  1335 
  1298     |aString|
  1336     |aString|
  1299 
  1337 
  1300     aString := self getSystemFileName:aFileName.
  1338     aString := self getSystemFileName:aFileName.
  1301     aString notNil ifTrue:[
  1339     aString notNil ifTrue:[
  1302         ^ FileStream readonlyFileNamed:aString
  1340 	^ FileStream readonlyFileNamed:aString
  1303     ].
  1341     ].
  1304     ^ nil
  1342     ^ nil
  1305 !
  1343 !
  1306 
  1344 
  1307 readAbbreviations
  1345 readAbbreviations
  1311     |aStream line index thisName abbrev|
  1349     |aStream line index thisName abbrev|
  1312 
  1350 
  1313     CachedAbbreviations := Dictionary new.
  1351     CachedAbbreviations := Dictionary new.
  1314     aStream := self systemFileStreamFor:'abbrev.stc'.
  1352     aStream := self systemFileStreamFor:'abbrev.stc'.
  1315     aStream isNil ifTrue:[
  1353     aStream isNil ifTrue:[
  1316         aStream := self systemFileStreamFor:'include/abbrev.stc'.
  1354 	aStream := self systemFileStreamFor:'include/abbrev.stc'.
  1317     ].
  1355     ].
  1318     aStream notNil ifTrue:[
  1356     aStream notNil ifTrue:[
  1319         [aStream atEnd] whileFalse:[
  1357 	[aStream atEnd] whileFalse:[
  1320             line := aStream nextLine.
  1358 	    line := aStream nextLine.
  1321             line notNil ifTrue:[
  1359 	    line notNil ifTrue:[
  1322                 (line startsWith:'#') ifFalse:[
  1360 		(line startsWith:'#') ifFalse:[
  1323                     (line countWords == 2) ifTrue:[
  1361 		    (line countWords == 2) ifTrue:[
  1324                         index := line indexOfSeparatorStartingAt:1.
  1362 			index := line indexOfSeparatorStartingAt:1.
  1325                         (index ~~ 0) ifTrue:[
  1363 			(index ~~ 0) ifTrue:[
  1326                             thisName := line copyTo:(index - 1).
  1364 			    thisName := line copyTo:(index - 1).
  1327                             abbrev := (line copyFrom:index) withoutSeparators.
  1365 			    abbrev := (line copyFrom:index) withoutSeparators.
  1328                             CachedAbbreviations at:thisName put:abbrev.
  1366 			    CachedAbbreviations at:thisName put:abbrev.
  1329                         ]
  1367 			]
  1330                     ]
  1368 		    ]
  1331                 ]
  1369 		]
  1332             ]
  1370 	    ]
  1333         ].
  1371 	].
  1334         aStream close
  1372 	aStream close
  1335     ]
  1373     ]
  1336 !
  1374 !
  1337 
  1375 
  1338 abbreviations
  1376 abbreviations
  1339     "return a dictionary containing the classname-to-filename
  1377     "return a dictionary containing the classname-to-filename
  1340      mappings. (needed for sys5.3 users, where filenames are limited
  1378      mappings. (needed for sys5.3 users, where filenames are limited
  1341      to 14 chars)"
  1379      to 14 chars)"
  1342 
  1380 
  1343     CachedAbbreviations isNil ifTrue:[
  1381     CachedAbbreviations isNil ifTrue:[
  1344         self readAbbreviations
  1382 	self readAbbreviations
  1345     ].
  1383     ].
  1346     ^ CachedAbbreviations
  1384     ^ CachedAbbreviations
  1347 
  1385 
  1348     "flush with:
  1386     "flush with:
  1349 
  1387 
  1361 
  1399 
  1362     "first look, if the class exists and has a fileName"
  1400     "first look, if the class exists and has a fileName"
  1363 
  1401 
  1364 " later ... - compiler should put the source file name into the class
  1402 " later ... - compiler should put the source file name into the class
  1365     Symbol hasInterned:aClassName ifTrue:[:sym |
  1403     Symbol hasInterned:aClassName ifTrue:[:sym |
  1366         |class|
  1404 	|class|
  1367 
  1405 
  1368         (Smalltalk includesKey:sym) ifTrue:[
  1406 	(Smalltalk includesKey:sym) ifTrue:[
  1369             class := Smalltalk at:sym.
  1407 	    class := Smalltalk at:sym.
  1370             class isClass ifTrue:[
  1408 	    class isClass ifTrue:[
  1371                 abbrev := class classFileName.
  1409 		abbrev := class classFileName.
  1372             ]
  1410 	    ]
  1373         ]
  1411 	]
  1374     ].
  1412     ].
  1375 "
  1413 "
  1376 
  1414 
  1377     "look for abbreviation"
  1415     "look for abbreviation"
  1378 
  1416 
  1380     abbrev notNil ifTrue:[^ abbrev].
  1418     abbrev notNil ifTrue:[^ abbrev].
  1381 
  1419 
  1382     "no abbreviation found - if its a short name, take it"
  1420     "no abbreviation found - if its a short name, take it"
  1383 
  1421 
  1384     OperatingSystem maxFileNameLength < (fileName size + 3) ifTrue:[
  1422     OperatingSystem maxFileNameLength < (fileName size + 3) ifTrue:[
  1385         "this will only be triggered on sys5.3 type systems"
  1423 	"this will only be triggered on sys5.3 type systems"
  1386         self error:'cant find short for ' , fileName , ' in abbreviation file'
  1424 	self error:'cant find short for ' , fileName , ' in abbreviation file'
  1387     ].
  1425     ].
  1388     ^ fileName
  1426     ^ fileName
  1389 !
  1427 !
  1390 
  1428 
  1391 classNameForFile:aFileName
  1429 classNameForFile:aFileName
  1426      an object or shared object ?
  1464      an object or shared object ?
  1427     "
  1465     "
  1428     ((aFileName endsWith:'.o')
  1466     ((aFileName endsWith:'.o')
  1429     or:[(aFileName endsWith:'.obj')
  1467     or:[(aFileName endsWith:'.obj')
  1430     or:[aFileName endsWith:'.so']]) ifTrue:[
  1468     or:[aFileName endsWith:'.so']]) ifTrue:[
  1431         ObjectFileLoader isNil ifTrue:[^ false].
  1469 	ObjectFileLoader isNil ifTrue:[^ false].
  1432 	path := self getSystemFileName:aFileName.
  1470 	path := self getSystemFileName:aFileName.
  1433 	path isNil ifTrue:[^ false].
  1471 	path isNil ifTrue:[^ false].
  1434 	^ ObjectFileLoader loadObjectFile:aFileName
  1472 	^ ObjectFileLoader loadObjectFile:aFileName
  1435     ].
  1473     ].
  1436 
  1474 
  1447 
  1485 
  1448 fileInChanges
  1486 fileInChanges
  1449     "read in the last changes file - bringing the system to the state it
  1487     "read in the last changes file - bringing the system to the state it
  1450      had when left the last time.
  1488      had when left the last time.
  1451      WARNING: this method is rubbish: it should only read things after the
  1489      WARNING: this method is rubbish: it should only read things after the
  1452               last '**snapshot**' - entry."
  1490 	      last '**snapshot**' - entry."
  1453 
  1491 
  1454     |upd|
  1492     |upd|
  1455 
  1493 
  1456     "
  1494     "
  1457      tell Class to NOT update the changes file now ...
  1495      tell Class to NOT update the changes file now ...
  1458     "
  1496     "
  1459     upd := Class updateChanges:false.
  1497     upd := Class updateChanges:false.
  1460     [
  1498     [
  1461         self fileIn:'changes'
  1499 	self fileIn:'changes'
  1462     ] valueNowOrOnUnwindDo:[
  1500     ] valueNowOrOnUnwindDo:[
  1463         Class updateChanges:upd
  1501 	Class updateChanges:upd
  1464     ]
  1502     ]
  1465 
  1503 
  1466     "
  1504     "
  1467      Smalltalk fileInChanges 
  1505      Smalltalk fileInChanges 
  1468     "
  1506     "
  1476 
  1514 
  1477     |shortName newClass upd ok nm|
  1515     |shortName newClass upd ok nm|
  1478 
  1516 
  1479     upd := Class updateChanges:false.
  1517     upd := Class updateChanges:false.
  1480     [
  1518     [
  1481         "
  1519 	"
  1482          first, look for a loader-driver file (in fileIn/xxx.ld)
  1520 	 first, look for a loader-driver file (in fileIn/xxx.ld)
  1483         "
  1521 	"
  1484         (self fileIn:('fileIn/' , aClassName , '.ld'))
  1522 	(self fileIn:('fileIn/' , aClassName , '.ld'))
  1485         ifFalse:[
  1523 	ifFalse:[
  1486             shortName := self fileNameForClass:aClassName.
  1524 	    shortName := self fileNameForClass:aClassName.
  1487             "
  1525 	    "
  1488              try abbreviated driver-file (in fileIn/xxx.ld)
  1526 	     try abbreviated driver-file (in fileIn/xxx.ld)
  1489             "
  1527 	    "
  1490             (self fileIn:('fileIn/' , shortName , '.ld'))
  1528 	    (self fileIn:('fileIn/' , shortName , '.ld'))
  1491             ifFalse:[
  1529 	    ifFalse:[
  1492                 "
  1530 		"
  1493                  then, if dynamic linking is available, look for a shared binary in binary/xxx.o
  1531 		 then, if dynamic linking is available, look for a shared binary in binary/xxx.o
  1494                 "
  1532 		"
  1495                 ObjectFileLoader notNil ifTrue:[
  1533 		ObjectFileLoader notNil ifTrue:[
  1496                     nm := 'binary/' , aClassName.
  1534 		    nm := 'binary/' , aClassName.
  1497                     (self fileInClassObject:aClassName from:(nm , '.so'))
  1535 		    (self fileInClassObject:aClassName from:(nm , '.so'))
  1498                     ifFalse:[
  1536 		    ifFalse:[
  1499                         (self fileInClassObject:aClassName from:(nm , '.o'))
  1537 			(self fileInClassObject:aClassName from:(nm , '.o'))
  1500                         ifFalse:[
  1538 			ifFalse:[
  1501                             nm := 'binary/' , shortName.
  1539 			    nm := 'binary/' , shortName.
  1502                             (self fileInClassObject:aClassName from:(nm , '.so'))
  1540 			    (self fileInClassObject:aClassName from:(nm , '.so'))
  1503                             ifFalse:[
  1541 			    ifFalse:[
  1504                                 ok := self fileInClassObject:aClassName from:(nm , '.o')
  1542 				ok := self fileInClassObject:aClassName from:(nm , '.o')
  1505                             ].
  1543 			    ].
  1506                         ].
  1544 			].
  1507                     ].
  1545 		    ].
  1508                 ].
  1546 		].
  1509 
  1547 
  1510                 "
  1548 		"
  1511                  if that did not work, look for an st-source file ...
  1549 		 if that did not work, look for an st-source file ...
  1512                 "
  1550 		"
  1513                 ok ifFalse:[
  1551 		ok ifFalse:[
  1514                     (self fileIn:(aClassName , '.st'))
  1552 		    (self fileIn:(aClassName , '.st'))
  1515                     ifFalse:[
  1553 		    ifFalse:[
  1516                         (self fileIn:(shortName , '.st')) 
  1554 			(self fileIn:(shortName , '.st')) 
  1517                         ifFalse:[
  1555 			ifFalse:[
  1518                             "
  1556 			    "
  1519                              ... and in the standard source-directory
  1557 			     ... and in the standard source-directory
  1520                             "
  1558 			    "
  1521                             (self fileIn:('source/' , aClassName , '.st'))
  1559 			    (self fileIn:('source/' , aClassName , '.st'))
  1522                             ifFalse:[
  1560 			    ifFalse:[
  1523                                 ok := self fileIn:('source/' , shortName , '.st')
  1561 				ok := self fileIn:('source/' , shortName , '.st')
  1524                             ]
  1562 			    ]
  1525                         ]
  1563 			]
  1526                     ]
  1564 		    ]
  1527                 ]
  1565 		]
  1528             ].
  1566 	    ].
  1529         ]
  1567 	]
  1530     ] valueNowOrOnUnwindDo:[Class updateChanges:upd].
  1568     ] valueNowOrOnUnwindDo:[Class updateChanges:upd].
  1531     newClass := self at:(aClassName asSymbol).
  1569     newClass := self at:(aClassName asSymbol).
  1532     newClass notNil ifTrue:[newClass initialize]
  1570     newClass notNil ifTrue:[newClass initialize]
       
  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     ]
  1533 ! !
  1585 ! !
  1534 
  1586 
  1535 !Smalltalk class methodsFor: 'binary storage'!
  1587 !Smalltalk class methodsFor: 'binary storage'!
  1536 
  1588 
  1537 addGlobalsTo: globalDictionary manager: manager
  1589 addGlobalsTo: globalDictionary manager: manager
  1538     |pools|
  1590     |pools|
  1539 
  1591 
  1540     pools := Set new.
  1592     pools := Set new.
  1541     self associationsDo:[:assoc |
  1593     self associationsDo:[:assoc |
  1542         assoc value == self ifFalse:[
  1594 	assoc value == self ifFalse:[
  1543             assoc value isClass ifTrue:[
  1595 	    assoc value isClass ifTrue:[
  1544                 assoc value addGlobalsTo:globalDictionary manager:manager.
  1596 		assoc value addGlobalsTo:globalDictionary manager:manager.
  1545                 pools addAll:assoc value sharedPools
  1597 		pools addAll:assoc value sharedPools
  1546             ] ifFalse:[
  1598 	    ] ifFalse:[
  1547                 globalDictionary at:assoc put:self
  1599 		globalDictionary at:assoc put:self
  1548             ].
  1600 	    ].
  1549             assoc value isNil ifFalse:[
  1601 	    assoc value isNil ifFalse:[
  1550                 globalDictionary at:assoc value put:self
  1602 		globalDictionary at:assoc value put:self
  1551             ]
  1603 	    ]
  1552         ]
  1604 	]
  1553     ].
  1605     ].
  1554 
  1606 
  1555     pools do:[:poolDictionary|
  1607     pools do:[:poolDictionary|
  1556         poolDictionary addGlobalsTo:globalDictionary manager:manager
  1608 	poolDictionary addGlobalsTo:globalDictionary manager:manager
  1557     ]
  1609     ]
  1558 !
  1610 !
  1559 
  1611 
  1560 storeBinaryDefinitionOf: anObject on: stream manager: manager
  1612 storeBinaryDefinitionOf: anObject on: stream manager: manager
  1561     |string|
  1613     |string|
  1562 
  1614 
  1563     anObject class == Association ifTrue:[
  1615     anObject class == Association ifTrue:[
  1564         string := 'Smalltalk associationAt: ', anObject key storeString
  1616 	string := 'Smalltalk associationAt: ', anObject key storeString
  1565     ] ifFalse: [
  1617     ] ifFalse: [
  1566         string := 'Smalltalk at: ', (self keyAtValue: anObject) storeString
  1618 	string := 'Smalltalk at: ', (self keyAtValue: anObject) storeString
  1567     ].
  1619     ].
  1568     stream nextNumber:2 put:string size.
  1620     stream nextNumber:2 put:string size.
  1569     string do:[:char | stream nextPut:char asciiValue]
  1621     string do:[:char | stream nextPut:char asciiValue]
  1570 ! !
  1622 ! !