[squeak-dev] The Inbox: System-dtl.1164.mcz
David T. Lewis
lewis at mail.msen.com
Fri Jun 12 21:04:20 UTC 2020
It works pretty well actually:
$ time run squeak -- -evaluate "(3 + 4 + Float pi cubed) asScaledDecimal: 20"
38.00627668029981975905s20
real 0m0.134s
user 0m0.054s
sys 0m0.088s
On Fri, Jun 12, 2020 at 03:41:34PM -0400, David T. Lewis wrote:
> Hi Tim,
>
> On Tue, Jun 09, 2020 at 12:06:00PM -0700, tim Rowledge wrote:
> >
> >
> > > On 2020-06-09, at 11:52 AM, David T. Lewis <lewis at mail.msen.com> wrote:
> > >
> > > Funny you should mention it, that's how I went down this rabbit hole
> > > in the first place. I was thinking that it would be an obviously good
> > > thing to do if we could evaluate a doIt or named script file immediately
> > > on image startup, as opposed to waiting until all of the Etoys script
> > > processing comes to life somewhere later in the startUp process.
> >
> > Exactly. Note that VW has several commandline switches we might want to learn from
> >
> > -filein {some file names}
> > -doit {some strings}
> > -evaluate {a single string & write result to stdout & quit
> > -cli {start a commandline loop}
> >
>
> Attached is a quick and dirty implementation than handles -filein, -doit, and -evaluate.
>
> Dave
>
> 'From Squeak6.0alpha of 8 June 2020 [latest update: #19714] on 12 June 2020 at 3:38:05 pm'!
"Change Set: DoItFirst-dtl
Date: 12 June 2020
Author: David T Lewis
Be the first thing in the system startup list, and do things that should be done prior to any additional image initialization. If the first image argument is a recognized option, evalutate it. Image arguments are typically preceeded by a '--' token on the command line.
Possible command options:
-filein {some file names}
-doit {some strings}
-evaluate {a single string & write result to stdout & quit"!
!DoItFirst commentStamp: 'dtl 6/12/2020 15:34' prior: 0!
Be the first thing in the system startup list, and do things that should be done prior to any additional image initialization. If the first image argument is a recognized option, evalutate it. Image arguments are typically preceeded by a '--' token on the command line.
Possible command options:
-filein {some file names}
-doit {some strings}
-evaluate {a single string & write result to stdout & quit
!
!DoItFirst class methodsFor: 'class initialization' stamp: 'dtl 6/11/2020 18:42'!
initialize
"DoItFirst initialize"
Smalltalk addToStartUpList: self before: SmallInteger.! !
!DoItFirst class methodsFor: 'actions' stamp: 'dtl 6/12/2020 14:41'!
doIt: arguments
"Evaluate arguments and print the result on stdout, or error message on stderr.
Exit the image after any error."
FileStream startUp: true.
arguments do: [ :arg |
[FileStream stdout nextPutAll: (Compiler evaluate: arg) asString; lf; flush]
on: Error
do: [ :ex | FileStream stderr nextPutAll: ex asString; lf; flush.
Smalltalk quitPrimitive ]]! !
!DoItFirst class methodsFor: 'actions' stamp: 'dtl 6/12/2020 14:35'!
evaluate: arg
"Evaluate arg and print the result on stdout, or error message on stderr.
Exit immediately without saving the image."
FileStream startUp: true.
[FileStream stdout nextPutAll: (Compiler evaluate: arg) asString; lf; flush]
on: Error
do: [ :ex | FileStream stderr nextPutAll: ex asString; lf; flush ].
Smalltalk quitPrimitive! !
!DoItFirst class methodsFor: 'actions' stamp: 'dtl 6/12/2020 15:28'!
fileIn: fileNames
"File in each named file. On error, print a message to stderr and exit the image."
FileStream startUp: true.
fileNames do: [ :arg |
[ | fs |
fs := FileStream oldFileNamed: arg.
FileStream stdout nextPutAll: 'fiie in ', fs asString; lf; flush.
fs fileIn ]
on: Error
do: [ :ex | FileStream stderr nextPutAll: ex asString; lf; flush.
Smalltalk quitPrimitive ]]! !
!DoItFirst class methodsFor: 'system startup' stamp: 'dtl 6/12/2020 14:47'!
startUp: resuming
resuming ifTrue: [ | args |
args := Smalltalk arguments.
args size > 1
ifTrue: [ args first
caseOf: {
[ '-doit' ] -> [ self doIt: args allButFirst ] .
[ '--doit' ] -> [ self doIt: args allButFirst ] .
[ '-evaluate' ] -> [ self evaluate: args second ] .
[ '--evaluate' ] -> [ self evaluate: args second ] .
[ '-filein' ] -> [ self fileIn: args allButFirst ] .
[ '--filein' ] -> [ self fileIn: args allButFirst ]
}
otherwise: []]]
! !
DoItFirst initialize!
>
More information about the Squeak-dev
mailing list
|