Smalltalk.st
branchjv
changeset 18389 387190d575f5
parent 18366 a6e62e167c32
parent 18385 2d0a9c256e0e
child 18561 73656aba2c89
--- a/Smalltalk.st	Thu May 21 06:57:28 2015 +0200
+++ b/Smalltalk.st	Sat May 23 06:49:51 2015 +0200
@@ -609,8 +609,10 @@
      Here, a few specific initializations are done, then the actual initialization is
      done inside an error handler in basicInitializeSystem.
      Notice:
-	this is NOT called when an image is restarted;
-	in this case the show starts in Smalltalk>>restart."
+        this is called by the VM's main entry. You will not find senders from Smalltalk.
+     Also Notice:
+        this is NOT called when an image is restarted;
+        in this case the show starts in Smalltalk>>restart."
 
     |idx|
 
@@ -620,79 +622,79 @@
     AbstractOperatingSystem initializeConcreteClass.
 
     CommandLineArguments isEmptyOrNil ifTrue:[
-	CommandLineArguments := #('stx') asOrderedCollection.
+        CommandLineArguments := #('stx') asOrderedCollection.
     ].
     CommandLine := CommandLineArguments copy.
     CommandLineArguments := CommandLineArguments asOrderedCollection.
     CommandName := CommandLineArguments removeFirst. "/ the command
 
     (idx := CommandLineArguments indexOf:'--silentStartup') ~~ 0 ifTrue:[
-	SilentLoading := true.
-	CommandLineArguments removeIndex:idx
+        SilentLoading := true.
+        CommandLineArguments removeIndex:idx
     ] ifFalse:[
-	SilentLoading := false.
+        SilentLoading := false.
     ].
     (idx := CommandLineArguments indexOf:'--verboseLoading') ~~ 0 ifTrue:[
-	VerboseLoading := true.
-	CommandLineArguments removeIndex:idx
+        VerboseLoading := true.
+        CommandLineArguments removeIndex:idx
     ] ifFalse:[
-	VerboseLoading := false.
+        VerboseLoading := false.
     ].
     (idx := CommandLineArguments indexOf:'--verboseStartup') ~~ 0 ifTrue:[
-	VerboseLoading := true.
-	VerboseStartup := true.
-	CommandLineArguments removeIndex:idx
+        VerboseLoading := true.
+        VerboseStartup := true.
+        CommandLineArguments removeIndex:idx
     ] ifFalse:[
-	VerboseStartup := false.
+        VerboseStartup := false.
     ].
     (idx := CommandLineArguments indexOf:'--verbose') ~~ 0 ifTrue:[
-	Verbose := true.
-	VerboseLoading := true.
-	VerboseStartup := true.
-	CommandLineArguments removeIndex:idx
+        Verbose := true.
+        VerboseLoading := true.
+        VerboseStartup := true.
+        CommandLineArguments removeIndex:idx
     ] ifFalse:[
-	Verbose := false.
+        Verbose := false.
     ].
 
     DebuggingStandAlone := false.
 
     StandAlone ifTrue:[
-	InfoPrinting := false.
-	ObjectMemory infoPrinting:false.
-	IgnoreAssertions := true.
-
-	idx := CommandLineArguments indexOf:'--debug'.
-	idx ~~ 0 ifTrue:[
-	    DebuggingStandAlone := true.
-	].
-	DebuggingStandAlone ifTrue:[
-	    Inspector := MiniInspector.
-	    Debugger := MiniDebugger.
-	    IgnoreAssertions := false.
-	].
+        InfoPrinting := false.
+        ObjectMemory infoPrinting:false.
+        IgnoreAssertions := true.
+
+        idx := CommandLineArguments indexOf:'--debug'.
+        idx ~~ 0 ifTrue:[
+            DebuggingStandAlone := true.
+        ].
+        DebuggingStandAlone ifTrue:[
+            Inspector := MiniInspector.
+            Debugger := MiniDebugger.
+            IgnoreAssertions := false.
+        ].
     ] ifFalse:[
-	"/
-	"/ define low-level debugging tools - graphical classes are not prepared yet
-	"/ to handle things.
-	"/ This will bring us into the MiniDebugger when an error occurs during startup.
-	"/
-	Inspector := MiniInspector.
-	Debugger := MiniDebugger.
-	IgnoreAssertions := false.
+        "/
+        "/ define low-level debugging tools - graphical classes are not prepared yet
+        "/ to handle things.
+        "/ This will bring us into the MiniDebugger when an error occurs during startup.
+        "/
+        Inspector := MiniInspector.
+        Debugger := MiniDebugger.
+        IgnoreAssertions := false.
     ].
 
     Error handle:[:ex |
-	StandAlone ifTrue:[
-	    DebuggingStandAlone ifFalse:[
-		'Startup Error - use "--debug" command line argument for more info' errorPrintCR.
-		Smalltalk exit:1.
-	    ].
-	    'Smalltalk [error]: Error during early initialization:' errorPrintCR.
-	    thisContext fullPrintAll.
-	].
-	ex reject.
+        StandAlone ifTrue:[
+            DebuggingStandAlone ifFalse:[
+                'Startup Error - use "--debug" command line argument for more info' errorPrintCR.
+                Smalltalk exit:1.
+            ].
+            'Smalltalk [error]: Error during early initialization:' errorPrintCR.
+            thisContext fullPrintAll.
+        ].
+        ex reject.
     ] do:[
-	self basicInitializeSystem
+        self basicInitializeSystem
     ].
 
     "Modified: / 12-10-2010 / 11:27:47 / cg"
@@ -3900,21 +3902,23 @@
 
 restart
     "startup after an image has been loaded;
+     This is called by the VM's main entry - you should not find senders from Smalltalk.
+
      there are three change-notifications made to dependents of ObjectMemory,
      which allow a stepwise re-init: #earlyRestart, #restarted and #returnFromSnapshot.
 
      #earlySystemInstallation is sent for ST80 compatibility
 
      #earlyRestart is send first, nothing has been setup yet.
-		   (should be used to flush all device dependent entries)
+                   (should be used to flush all device dependent entries)
 
      #restarted is send right after.
-		   (should be used to recreate external resources (fds, bitmaps etc)
+                   (should be used to recreate external resources (fds, bitmaps etc)
 
      #returnFromSnapshot is sent last
-		   (should be used to restart processes, reOpen Streams which cannot
-		    be automatically be reopened (i.e. Sockets, Pipes) and so on.
-		   (Notice that positionable fileStreams are already reopened and repositioned)
+                   (should be used to restart processes, reOpen Streams which cannot
+                    be automatically be reopened (i.e. Sockets, Pipes) and so on.
+                   (Notice that positionable fileStreams are already reopened and repositioned)
      "
 
     |deb insp transcript idx|
@@ -3938,12 +3942,12 @@
 
     idx := CommandLineArguments indexOf:'-q'.
     idx == 0 ifTrue:[
-	idx := CommandLineArguments indexOf:'--silent'.
+        idx := CommandLineArguments indexOf:'--silent'.
     ].
     idx ~~ 0 ifTrue:[
-	Object infoPrinting:false.
-	ObjectMemory infoPrinting:false.
-	CommandLineArguments removeAtIndex:idx.
+        Object infoPrinting:false.
+        ObjectMemory infoPrinting:false.
+        CommandLineArguments removeAtIndex:idx.
     ].
 
     "/ start catching SIGSEGV and SIGBUS
@@ -3969,7 +3973,7 @@
     insp := Inspector.
     deb := Debugger.
     deb notNil ifTrue:[
-	deb reinitialize
+        deb reinitialize
     ].
     Inspector := MiniInspector.
     Debugger := MiniDebugger.
@@ -3982,16 +3986,16 @@
     "/ ObjectFileLoader; therefore, must reload before doing any notifications.
 
     ObjectFileLoader notNil ifTrue:[
-	ObjectFileLoader reloadAllRememberedObjectFiles.
+        ObjectFileLoader reloadAllRememberedObjectFiles.
     ].
 
     "/ invalidate all display connections.
     "/ This is required to avoid trouble if someone accesses
     "/ a display during early startup.
     Screen notNil ifTrue:[
-	Screen allScreens do:[:eachDisplay |
-	    eachDisplay invalidateConnection.
-	].
+        Screen allScreens do:[:eachDisplay |
+            eachDisplay invalidateConnection.
+        ].
     ].
 
     ObjectMemory changed:#earlySystemInstallation.
@@ -4003,7 +4007,7 @@
     "/ flush device handles & recreate OS resources (if possible)
     "/ (mostly view/GC/color & font stuff)
     ObjectMemory
-	changed:#earlyRestart; changed:#restarted.
+        changed:#earlyRestart; changed:#restarted.
 
     "/ start catching SIGINT and SIGQUIT
     OperatingSystem enableUserInterrupts.
@@ -4014,78 +4018,78 @@
     "/ reading if smalltalk_r.rc may be suppressed by the --faststart argument.
     idx := CommandLineArguments indexOf:'--faststart'.
     idx == 0 ifTrue:[
-	idx := CommandLineArguments indexOf:'--fastStart'.
+        idx := CommandLineArguments indexOf:'--fastStart'.
     ].
     idx ~~ 0 ifTrue:[
-	CommandLineArguments removeAtIndex:idx.
+        CommandLineArguments removeAtIndex:idx.
     ] ifFalse:[
-	CallbackSignal := QuerySignal new.
-	[
-	    Class withoutUpdatingChangesDo:[
-		(self fileIn:(self commandName , '_r.rc')) ifFalse:[
-		    "no _r.rc file where executable is; try default smalltalk_r.rc"
-		    self fileIn:'smalltalk_r.rc'
-		].
-	    ]
-	] on:CallbackSignal do:[:ex|
-	    "/ now, display and view-stuff works;
-	    "/ back to the previous debugging interface
-	    Inspector := insp.
-	    Debugger := deb.
-
-	    "/ reinstall Transcript, if not changed during restart.
-	    "/ if there was no Transcript, go to stderr
-	    (transcript notNil and:[Transcript == Stderr]) ifTrue:[
-		Transcript := transcript.
-	    ].
-	    Initializing := false.
-	    ex proceed.
-	].
-	CallbackSignal := nil.
+        CallbackSignal := QuerySignal new.
+        [
+            Class withoutUpdatingChangesDo:[
+                (self fileIn:(self commandName , '_r.rc')) ifFalse:[
+                    "no _r.rc file where executable is; try default smalltalk_r.rc"
+                    self fileIn:'smalltalk_r.rc'
+                ].
+            ]
+        ] on:CallbackSignal do:[:ex|
+            "/ now, display and view-stuff works;
+            "/ back to the previous debugging interface
+            Inspector := insp.
+            Debugger := deb.
+
+            "/ reinstall Transcript, if not changed during restart.
+            "/ if there was no Transcript, go to stderr
+            (transcript notNil and:[Transcript == Stderr]) ifTrue:[
+                Transcript := transcript.
+            ].
+            Initializing := false.
+            ex proceed.
+        ].
+        CallbackSignal := nil.
     ].
 
     "/ reinitialization (restart) of Display is normally performed
     "/ in the restart script. If this has not been run for some reason,
     "/ do in now.
     Initializing ifTrue:[
-	Display notNil ifTrue:[
-	    [
-		Display reinitializeFor:Screen defaultDisplayName.
-	    ] on:Screen deviceOpenErrorSignal do:[
-		'Smalltalk [error]: Cannot restart connection to: ' errorPrint.
-		Screen defaultDisplayName errorPrintCR.
-		OperatingSystem exit:1.
-	    ].
-	].
-	"/ now, display and view-stuff works;
-	"/ back to the previous debugging interface
-
-	Inspector := insp.
-	Debugger := deb.
-
-	"/ reinstall Transcript, if not changed during restart.
-	"/ if there was no Transcript, go to stderr
-
-	(transcript notNil and:[Transcript == Stderr]) ifTrue:[
-	    Transcript := transcript.
-	].
-	Initializing := false.
+        Display notNil ifTrue:[
+            [
+                Display reinitializeFor:Screen defaultDisplayName.
+            ] on:Screen deviceOpenErrorSignal do:[
+                'Smalltalk [error]: Cannot restart connection to: ' errorPrint.
+                Screen defaultDisplayName errorPrintCR.
+                OperatingSystem exit:1.
+            ].
+        ].
+        "/ now, display and view-stuff works;
+        "/ back to the previous debugging interface
+
+        Inspector := insp.
+        Debugger := deb.
+
+        "/ reinstall Transcript, if not changed during restart.
+        "/ if there was no Transcript, go to stderr
+
+        (transcript notNil and:[Transcript == Stderr]) ifTrue:[
+            Transcript := transcript.
+        ].
+        Initializing := false.
     ].
     Screen notNil ifTrue:[
-	"clean up leftover screens (and views) that haven't been reopened.
-	 Operate on a copy, since brokenConnection removes us from AllScreens"
-	Screen allScreens copy do:[:eachDisplay |
-	    eachDisplay isOpen ifFalse:[
-		'Smalltalk [info]: cannot reopen secondary display: ' errorPrint.
-		eachDisplay errorPrintCR.
-		eachDisplay cleanupAfterDispatch; brokenConnection.
-	    ]
-	].
+        "clean up leftover screens (and views) that haven't been reopened.
+         Operate on a copy, since brokenConnection removes us from AllScreens"
+        Screen allScreens copy do:[:eachDisplay |
+            eachDisplay isOpen ifFalse:[
+                'Smalltalk [info]: cannot reopen secondary display: ' errorPrint.
+                eachDisplay errorPrintCR.
+                eachDisplay cleanupAfterDispatch; brokenConnection.
+            ]
+        ].
     ].
 
     deb := insp := transcript := nil.   "avoid dangling refs"
     (StartupClass perform:#keepSplashWindowOpen ifNotUnderstood:[false]) ifFalse:[
-	self hideSplashWindow.   "/ if there is one, it's now time to hide it
+        self hideSplashWindow.   "/ if there is one, it's now time to hide it
     ].
     self mainStartup:true
 
@@ -4149,243 +4153,243 @@
      while reading patches- and rc-file, do not add things into change-file
     "
     Class withoutUpdatingChangesDo:[
-	|commandFile defaultRC prevCatchSetting
-	 isEval isPrint isFilter isRepl idxFileArg process|
-
-	isEval := isPrint := isFilter := isRepl := false.
-	didReadRCFile := false.
-
-	StandAlone ifFalse:[
-	    "/
-	    "/ look for any '-q', '-e', '-l' or '-f' command line arguments
-	    "/ and handle them;
-	    "/ read startup and patches file
-	    "/
-	    idx := CommandLineArguments indexOfAny:#('-R' '--repl').
-	    isRepl := (idx ~~ 0).
-
-	    idx := CommandLineArguments indexOfAny:#('-q' '--silent').
-	    idx ~~ 0 ifTrue:[
-		Object infoPrinting:false.
-		ObjectMemory infoPrinting:false.
-		CommandLineArguments removeAtIndex:idx.
-		SilentLoading := true.
-	    ].
-
-	    [
-		idx := CommandLineArguments indexOfAny:#('-pp' '--packagePath').
-		idx ~~ 0
-	    ] whileTrue:[
-		arg := CommandLineArguments at:idx + 1.
-		CommandLineArguments removeAtIndex:idx+1; removeAtIndex:idx.
-		self packagePath addLast:arg.
-		VerboseStartup == true ifTrue:[
-		    ('Smalltalk [info]: add to packagePath: "', arg, '".') infoPrintCR.
-		].
-	    ].
-
-	    [
-		idx := CommandLineArguments indexOfAny:#('-l' '--load').
-		idx ~~ 0
-	    ] whileTrue:[
-		arg := CommandLineArguments at:idx + 1.
-		CommandLineArguments removeAtIndex:idx+1; removeAtIndex:idx.
-		arg asFilename exists ifTrue:[
-		    Smalltalk fileIn:arg
-		] ifFalse:[
-		    Smalltalk loadPackage:arg
-		].
-	    ].
-
-	    "/ look for a '-e filename' or '--execute filename' argument
-	    "/ this will force fileIn of filename only, no standard startup.
-
-	    idx := CommandLineArguments indexOfAny:#('-e' '--execute' '--script').
-	    idx ~~ 0 ifTrue:[
-		SilentLoading := true.
-		CommandName := arg := CommandLineArguments at:idx + 1.
-
-		CommandLineArguments
-		    removeAtIndex:idx+1; removeAtIndex:idx.
-
-		self startSchedulerAndBackgroundCollector.
-		keepSplashWindow ifFalse:[ self hideSplashWindow ].
-		Initializing := false.
-
-		process := [
-		    VerboseStartup == true ifTrue:[
-			('Smalltalk [info]: reading script from: "', arg, '".') infoPrintCR.
-		    ].
-		    UserInterrupt handle:[:ex |
-			self exit:128+(OperatingSystem sigINT).
-		    ] do:[
-			arg = '-' ifTrue:[
-			    self fileInStream:Stdin
-				   lazy:nil
-				   silent:nil
-				   logged:false
-				   addPath:nil
-			] ifFalse:[
-			    IsSTScript := true.
-			    self fileIn:arg.
-			].
-		    ].
-		    "/ after the script, if Screen has been opened and there are any open windows,
-		    "/ then do not exit
-		    Display notNil ifTrue:[
-			Display exitOnLastClose:true.
-			Display checkForEndOfDispatch.
-			Processor exitWhenNoMoreUserProcesses:true.
-		    ] ifFalse:[
-			self exit.
-		    ].
-		] newProcess.
-		process priority:(Processor userSchedulingPriority).
-		process name:'main'.
-		process beGroupLeader.
-		process resume.
-
-		Processor dispatchLoop.
-		self exit
-	    ].
-
-	    "look for a '-f filename' or '--file filename' argument
-	     if scripting, thisis loaded before -P, -E or-R action.
-	     if not scripting, this will force evaluation of filename instead of smalltalk.rc"
-	    idxFileArg := CommandLineArguments indexOfAny:#('-f' '--file').
-	    (idxFileArg ~~ 0) ifTrue:[
-		commandFile := CommandLineArguments at:idxFileArg+1.
-		CommandLineArguments removeAtIndex:idxFileArg+1; removeAtIndex:idxFileArg.
-	    ].
-
-	    "/ look for a '-E expr' or '--eval expr' argument (-P or --print to print the result of evaluation)
-	    "/ or -F/--filter or a '--repl' argument
-	    "/ E, P and F this will force evaluation of expr only, no standard startup
-	    "/ repl go into an interactive loop.
-	    idx := CommandLineArguments indexOfAny:#('-E' '--eval').
-	    (isEval := (idx ~~ 0)) ifFalse:[
-		idx := CommandLineArguments indexOfAny:#('-P' '--print').
-		(isPrint := (idx ~~ 0)) ifFalse:[
-		    idx := CommandLineArguments indexOfAny:#('-F' '--filter').
-		    (isFilter := (idx ~~ 0)) ifFalse:[
-			idx := CommandLineArguments indexOfAny:#('-R' '--repl').
-			isRepl := (idx ~~ 0)
-		    ].
-		].
-	    ].
-
-	    (isEval | isPrint | isFilter | isRepl) ifTrue:[
-		isRepl ifFalse:[
-		    CommandLineArguments size <= idx ifTrue:[
-			'stx: missing argument after -E/-P/-F' errorPrintCR.
-			self exit:1.
-		    ].
-		    arg := CommandLineArguments at:idx + 1.
-		    CommandLineArguments removeAtIndex:idx+1.
-		].
-		CommandLineArguments removeAtIndex:idx.
-
-		self startSchedulerAndBackgroundCollector.
-		keepSplashWindow ifFalse:[ self hideSplashWindow ].
-		Initializing := false.
-
-		"/ enable this, so we can provide $1..$n in the script
-		ParserFlags allowDollarInIdentifier:true.
-		ParserFlags warnDollarInIdentifier:false.
-
-		"/ add bindings for arguments
-		CommandLineArguments doWithIndex:[:arg :i |
-		    Workspace workspaceVariableAt:('_$',i printString) put:arg.
-		].
-
-		"/ all of the above allow for a -f file to be loaded before any other action
-		(commandFile notNil) ifTrue:[
-		    VerboseStartup == true ifTrue:[
-			('Smalltalk [info]: reading command file from: "', commandFile, '".') infoPrintCR.
-		    ].
-		    (self secureFileIn:commandFile) ifFalse:[
-			('Smalltalk [error]: "', commandFile, '" not found.') errorPrintCR.
-			OperatingSystem exit:1.
-		    ]
-		].
-
-		isRepl ifTrue:[
-		    self readEvalPrint.
-		    self exit.
-		].
-		process := [
-		    VerboseStartup == true ifTrue:[
-			('Smalltalk [info]: executing expression: "', arg, '".') infoPrintCR.
-		    ].
-		    UserInterrupt handle:[:ex |
-			self exit:128+(OperatingSystem sigINT).
-		    ] do:[
-			isFilter ifTrue:[
-			    "/ --filter - apply code to each input line.
-			    "/ compile code only once
-			    Compiler
-				compile:'doIt ',arg
-				forClass:String
-				notifying:(EvalScriptingErrorHandler new source:arg).
-
-			    [Stdin atEnd] whileFalse:[
-				|line|
-
-				line := Stdin nextLine.
-				line doIt.
-			    ].
-			] ifFalse:[
-			    "/ --print or --eval
-			    |rslt|
-
-			    rslt := Parser new
-					evaluate:arg
-					notifying:(EvalScriptingErrorHandler new source:arg)
-					compile:true.
-			    isPrint ifTrue:[
-				rslt printCR.
-			    ].
-			].
-		    ].
-
-		    "/ after the script, if Screen has been opened and there are any open windows,
-		    "/ then do not exit
-		    Display notNil ifTrue:[
-			Display exitOnLastClose:true.
-			Display checkForEndOfDispatch.
-			Processor exitWhenNoMoreUserProcesses:true.
-			VerboseStartup == true ifTrue:[
-			    ('Smalltalk [info]: display opened.') infoPrintCR.
-			].
-		    ] ifFalse:[
-			VerboseStartup == true ifTrue:[
-			    ('Smalltalk [info]: no display - exit after script.') infoPrintCR.
-			].
-			self exit.
-		    ].
-		] newProcess.
-		process priority:(Processor userSchedulingPriority).
-		process name:'main'.
-		process beGroupLeader.
-		process resume.
-
-		Processor dispatchLoop.
-		VerboseStartup == true ifTrue:[
-		    ('Smalltalk [info]: exit normally.') infoPrintCR.
-		].
-		self exit
-	    ].
-	].
-
-	commandFile notNil ifTrue:[
-	    SilentLoading := true.  "/ suppress the hello & copyright messages
-	    self addStartBlock:
-		[
-		    (self secureFileIn:commandFile) ifFalse:[
-			('Smalltalk [error]: startup file "', commandFile, '" not found.') errorPrintCR.
-			OperatingSystem exit:1.
-		    ].
-		].
+        |commandFile defaultRC prevCatchSetting
+         isEval isPrint isFilter isRepl idxFileArg process|
+
+        isEval := isPrint := isFilter := isRepl := false.
+        didReadRCFile := false.
+
+        StandAlone ifFalse:[
+            "/
+            "/ look for any '-q', '-e', '-l' or '-f' command line arguments
+            "/ and handle them;
+            "/ read startup and patches file
+            "/
+            idx := CommandLineArguments indexOfAny:#('-R' '--repl').
+            isRepl := (idx ~~ 0).
+
+            idx := CommandLineArguments indexOfAny:#('-q' '--silent').
+            idx ~~ 0 ifTrue:[
+                Object infoPrinting:false.
+                ObjectMemory infoPrinting:false.
+                CommandLineArguments removeAtIndex:idx.
+                SilentLoading := true.
+            ].
+
+            [
+                idx := CommandLineArguments indexOfAny:#('-pp' '--packagePath').
+                idx ~~ 0
+            ] whileTrue:[
+                arg := CommandLineArguments at:idx + 1.
+                CommandLineArguments removeAtIndex:idx+1; removeAtIndex:idx.
+                self packagePath addLast:arg.
+                VerboseStartup == true ifTrue:[
+                    ('Smalltalk [info]: add to packagePath: "', arg, '".') infoPrintCR.
+                ].
+            ].
+
+            [
+                idx := CommandLineArguments indexOfAny:#('-l' '--load').
+                idx ~~ 0
+            ] whileTrue:[
+                arg := CommandLineArguments at:idx + 1.
+                CommandLineArguments removeAtIndex:idx+1; removeAtIndex:idx.
+                arg asFilename exists ifTrue:[
+                    Smalltalk fileIn:arg
+                ] ifFalse:[
+                    Smalltalk loadPackage:arg
+                ].
+            ].
+
+            "/ look for a '-e filename' or '--execute filename' argument
+            "/ this will force fileIn of filename only, no standard startup.
+
+            idx := CommandLineArguments indexOfAny:#('-e' '--execute' '--script').
+            idx ~~ 0 ifTrue:[
+                SilentLoading := true.
+                CommandName := arg := CommandLineArguments at:idx + 1.
+
+                CommandLineArguments
+                    removeAtIndex:idx+1; removeAtIndex:idx.
+
+                self startSchedulerAndBackgroundCollector.
+                keepSplashWindow ifFalse:[ self hideSplashWindow ].
+                Initializing := false.
+
+                process := [
+                    VerboseStartup == true ifTrue:[
+                        ('Smalltalk [info]: reading script from: "', arg, '".') infoPrintCR.
+                    ].
+                    UserInterrupt handle:[:ex |
+                        self exit:128+(OperatingSystem sigINT).
+                    ] do:[
+                        arg = '-' ifTrue:[
+                            self fileInStream:Stdin
+                                   lazy:nil
+                                   silent:nil
+                                   logged:false
+                                   addPath:nil
+                        ] ifFalse:[
+                            IsSTScript := true.
+                            self fileIn:arg.
+                        ].
+                    ].
+                    "/ after the script, if Screen has been opened and there are any open windows,
+                    "/ then do not exit
+                    Display notNil ifTrue:[
+                        Display exitOnLastClose:true.
+                        Display checkForEndOfDispatch.
+                        Processor exitWhenNoMoreUserProcesses:true.
+                    ] ifFalse:[
+                        self exit.
+                    ].
+                ] newProcess.
+                process priority:(Processor userSchedulingPriority).
+                process name:'main'.
+                process beGroupLeader.
+                process resume.
+
+                Processor dispatchLoop.
+                self exit
+            ].
+
+            "look for a '-f filename' or '--file filename' argument
+             if scripting, thisis loaded before -P, -E or-R action.
+             if not scripting, this will force evaluation of filename instead of smalltalk.rc"
+            idxFileArg := CommandLineArguments indexOfAny:#('-f' '--file').
+            (idxFileArg ~~ 0) ifTrue:[
+                commandFile := CommandLineArguments at:idxFileArg+1.
+                CommandLineArguments removeAtIndex:idxFileArg+1; removeAtIndex:idxFileArg.
+            ].
+
+            "/ look for a '-E expr' or '--eval expr' argument (-P or --print to print the result of evaluation)
+            "/ or -F/--filter or a '--repl' argument
+            "/ E, P and F this will force evaluation of expr only, no standard startup
+            "/ repl go into an interactive loop.
+            idx := CommandLineArguments indexOfAny:#('-E' '--eval').
+            (isEval := (idx ~~ 0)) ifFalse:[
+                idx := CommandLineArguments indexOfAny:#('-P' '--print').
+                (isPrint := (idx ~~ 0)) ifFalse:[
+                    idx := CommandLineArguments indexOfAny:#('-F' '--filter').
+                    (isFilter := (idx ~~ 0)) ifFalse:[
+                        idx := CommandLineArguments indexOfAny:#('-R' '--repl').
+                        isRepl := (idx ~~ 0)
+                    ].
+                ].
+            ].
+
+            (isEval | isPrint | isFilter | isRepl) ifTrue:[
+                isRepl ifFalse:[
+                    CommandLineArguments size <= idx ifTrue:[
+                        'stx: missing argument after -E/-P/-F' errorPrintCR.
+                        self exit:1.
+                    ].
+                    arg := CommandLineArguments at:idx + 1.
+                    CommandLineArguments removeAtIndex:idx+1.
+                ].
+                CommandLineArguments removeAtIndex:idx.
+
+                self startSchedulerAndBackgroundCollector.
+                keepSplashWindow ifFalse:[ self hideSplashWindow ].
+                Initializing := false.
+
+                "/ enable this, so we can provide $1..$n in the script
+                ParserFlags allowDollarInIdentifier:true.
+                ParserFlags warnDollarInIdentifier:false.
+
+                "/ add bindings for arguments
+                CommandLineArguments doWithIndex:[:arg :i |
+                    Workspace workspaceVariableAt:('_$',i printString) put:arg.
+                ].
+
+                "/ all of the above allow for a -f file to be loaded before any other action
+                (commandFile notNil) ifTrue:[
+                    VerboseStartup == true ifTrue:[
+                        ('Smalltalk [info]: reading command file from: "', commandFile, '".') infoPrintCR.
+                    ].
+                    (self secureFileIn:commandFile) ifFalse:[
+                        ('Smalltalk [error]: "', commandFile, '" not found.') errorPrintCR.
+                        OperatingSystem exit:1.
+                    ]
+                ].
+
+                isRepl ifTrue:[
+                    self readEvalPrint.
+                    self exit.
+                ].
+                process := [
+                    VerboseStartup == true ifTrue:[
+                        ('Smalltalk [info]: executing expression: "', arg, '".') infoPrintCR.
+                    ].
+                    UserInterrupt handle:[:ex |
+                        self exit:128+(OperatingSystem sigINT).
+                    ] do:[
+                        isFilter ifTrue:[
+                            "/ --filter - apply code to each input line.
+                            "/ compile code only once
+                            Compiler
+                                compile:'doIt:line ',arg
+                                forClass:String
+                                notifying:(EvalScriptingErrorHandler new source:arg).
+
+                            [Stdin atEnd] whileFalse:[
+                                |line|
+
+                                line := Stdin nextLine.
+                                line doIt:line.
+                            ].
+                        ] ifFalse:[
+                            "/ --print or --eval
+                            |rslt|
+
+                            rslt := Parser new
+                                        evaluate:arg
+                                        notifying:(EvalScriptingErrorHandler new source:arg)
+                                        compile:true.
+                            isPrint ifTrue:[
+                                rslt printCR.
+                            ].
+                        ].
+                    ].
+
+                    "/ after the script, if Screen has been opened and there are any open windows,
+                    "/ then do not exit
+                    Display notNil ifTrue:[
+                        Display exitOnLastClose:true.
+                        Display checkForEndOfDispatch.
+                        Processor exitWhenNoMoreUserProcesses:true.
+                        VerboseStartup == true ifTrue:[
+                            ('Smalltalk [info]: display opened.') infoPrintCR.
+                        ].
+                    ] ifFalse:[
+                        VerboseStartup == true ifTrue:[
+                            ('Smalltalk [info]: no display - exit after script.') infoPrintCR.
+                        ].
+                        self exit.
+                    ].
+                ] newProcess.
+                process priority:(Processor userSchedulingPriority).
+                process name:'main'.
+                process beGroupLeader.
+                process resume.
+
+                Processor dispatchLoop.
+                VerboseStartup == true ifTrue:[
+                    ('Smalltalk [info]: exit normally.') infoPrintCR.
+                ].
+                self exit
+            ].
+        ].
+
+        commandFile notNil ifTrue:[
+            SilentLoading := true.  "/ suppress the hello & copyright messages
+            self addStartBlock:
+                [
+                    (self secureFileIn:commandFile) ifFalse:[
+                        ('Smalltalk [error]: startup file "', commandFile, '" not found.') errorPrintCR.
+                        OperatingSystem exit:1.
+                    ].
+                ].
 
 "/            self startSchedulerAndBackgroundCollector.
 "/            keepSplashWindow ifFalse:[ self hideSplashWindow ].
@@ -4395,67 +4399,67 @@
 "/                ('Smalltalk [error]: startup file "', commandFile, '" not found.') errorPrintCR.
 "/                OperatingSystem exit:1.
 "/            ].
-	] ifFalse:[
-	    "/ look for <command>.rc
-	    "/ if not found, read smalltalk.rc (or stxapp.rc for standAlone operation)
-
-	    commandFile := self commandName asFilename withSuffix:'rc'.
-	    (didReadRCFile := commandFile exists and:[self secureFileIn:commandFile]) ifFalse:[
-		StandAlone ifFalse:[
-		    defaultRC := 'smalltalk.rc' "/asFilename
-		] ifTrue:[
-		    defaultRC := 'stxapp.rc' "/asFilename
-		].
-		"JV@2011-11-01: DO NOT check defaultRC exist - this prevents smalltalk to
-		    to be started with different working directory than stx/projects/smalltalk !!!!!!"
-
-		"/didReadRCFile := defaultRC exists and:[self secureFileIn:defaultRC].
-		didReadRCFile := (self getSystemFileName:defaultRC) notNil
-				 and:[self secureFileIn:defaultRC].
-		didReadRCFile ifFalse:[
-		    StandAlone ifFalse:[
-			'Smalltalk [warning]: no startup rc-file found. Going into line-by-line interpreter.' infoPrintCR.
-			graphicalMode := false.
-		    ]
-		]
-	    ].
-
-	    "/ ('StandAlone is %1' bindWith:StandAlone) printCR.
-	    "/ ('Headless is %1' bindWith:HeadlessOperation) printCR.
-	    "/ ('Display is %1' bindWith:Display) printCR.
-	    "/ ('Screen is %1' bindWith:Screen) printCR.
-
-	    keepSplashWindow ifFalse:[ self hideSplashWindow ].
-	    didReadRCFile ifFalse:[
-		'private.rc' asFilename exists ifTrue:[ self secureFileIn:'private.rc' ].
-
-		"/
-		"/ No RC file found;
-		"/ Setup more default stuff
-		"/
-		StandAlone ifFalse:[
-		    "/ its a smalltalk - proceed in interpreter.
-		    'Smalltalk [warning]: no startup rc-file found. Going into line-by-line interpreter.' infoPrintCR.
-		    graphicalMode := false.
-		].
-
-		"/ setup more defaults...
+        ] ifFalse:[
+            "/ look for <command>.rc
+            "/ if not found, read smalltalk.rc (or stxapp.rc for standAlone operation)
+
+            commandFile := self commandName asFilename withSuffix:'rc'.
+            (didReadRCFile := commandFile exists and:[self secureFileIn:commandFile]) ifFalse:[
+                StandAlone ifFalse:[
+                    defaultRC := 'smalltalk.rc' "/asFilename
+                ] ifTrue:[
+                    defaultRC := 'stxapp.rc' "/asFilename
+                ].
+                "JV@2011-11-01: DO NOT check defaultRC exist - this prevents smalltalk to
+                    to be started with different working directory than stx/projects/smalltalk !!!!!!"
+
+                "/didReadRCFile := defaultRC exists and:[self secureFileIn:defaultRC].
+                didReadRCFile := (self getSystemFileName:defaultRC) notNil
+                                 and:[self secureFileIn:defaultRC].
+                didReadRCFile ifFalse:[
+                    StandAlone ifFalse:[
+                        'Smalltalk [warning]: no startup rc-file found. Going into line-by-line interpreter.' infoPrintCR.
+                        graphicalMode := false.
+                    ]
+                ]
+            ].
+
+            "/ ('StandAlone is %1' bindWith:StandAlone) printCR.
+            "/ ('Headless is %1' bindWith:HeadlessOperation) printCR.
+            "/ ('Display is %1' bindWith:Display) printCR.
+            "/ ('Screen is %1' bindWith:Screen) printCR.
+
+            keepSplashWindow ifFalse:[ self hideSplashWindow ].
+            didReadRCFile ifFalse:[
+                'private.rc' asFilename exists ifTrue:[ self secureFileIn:'private.rc' ].
+
+                "/
+                "/ No RC file found;
+                "/ Setup more default stuff
+                "/
+                StandAlone ifFalse:[
+                    "/ its a smalltalk - proceed in interpreter.
+                    'Smalltalk [warning]: no startup rc-file found. Going into line-by-line interpreter.' infoPrintCR.
+                    graphicalMode := false.
+                ].
+
+                "/ setup more defaults...
 "/                ObjectMemory startBackgroundCollectorAt:5.
 "/                ObjectMemory startBackgroundFinalizationAt:5.
-		self addStartBlock:[
-		    self startSchedulerAndBackgroundCollector
-		].
-	    ].
-	].
-	(CommandLineArguments includes:'--scripting') ifTrue:[
-	    self addStartBlock:[
-		StandaloneStartup handleScriptingOptionsFromArguments:CommandLineArguments.
-	    ].
-	].
+                self addStartBlock:[
+                    self startSchedulerAndBackgroundCollector
+                ].
+            ].
+        ].
+        (CommandLineArguments includes:'--scripting') ifTrue:[
+            self addStartBlock:[
+                StandaloneStartup handleScriptingOptionsFromArguments:CommandLineArguments.
+            ].
+        ].
     ].
 
     HeadlessOperation ifTrue:[
-	graphicalMode := false.
+        graphicalMode := false.
     ].
 
     keepSplashWindow ifFalse:[ self hideSplashWindow ].
@@ -8284,11 +8288,11 @@
 !Smalltalk class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.1131 2015-05-18 00:07:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.1133 2015-05-22 18:41:08 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.1131 2015-05-18 00:07:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.1133 2015-05-22 18:41:08 cg Exp $'
 !
 
 version_HG