[ANN] DoItFirst command line goodie on SqueakSource

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
27 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
A few cups of coffee this morning led to some enhancements to my DoItFirst
utility, so I decided to put in on SqueakSource.

   http://www.squeaksource.com/DoItFirst

It works more or less like this:

$ squeak squeak.image -- -help
DoItFirst image arguments:
        -doit argumentlist "evaluate each argument as a doIt expression"
        -evaluate arg "evaluate arg, print result then exit"
        -filein filelist "file in each file named in fileList"
        -cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
        -help "print this message"


Dave


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

marcel.taeumel
Hi Dave.

Thank you! Looks good.

Here are some thoughts:

- The small footprint of this is awesome!
- Since you assume that "FileDirectory startUp" can work in the case of emergency, we should move it further up in the StartUpList.
- You are likely to need full support of SmallInteger, Delay, Time, and DateAndTime -- so I suggest moving it after those classes in the StartUpList. I am writing this without looking at the current implementation of their #startUp: methods because it should not matter ... conceptionally.
- So, what about putting this into Trunk and having the following elements first in the startup list:

1. SmallInteger
2. Delay
3. Time
4. DateAndTime
5. FileDirectory
6. DoItFirst
...

Best,
Marcel

Am 14.06.2020 19:15:28 schrieb David T. Lewis <[hidden email]>:

A few cups of coffee this morning led to some enhancements to my DoItFirst
utility, so I decided to put in on SqueakSource.

http://www.squeaksource.com/DoItFirst

It works more or less like this:

$ squeak squeak.image -- -help
DoItFirst image arguments:
-doit argumentlist "evaluate each argument as a doIt expression"
-evaluate arg "evaluate arg, print result then exit"
-filein filelist "file in each file named in fileList"
-cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
-help "print this message"


Dave




Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
Hi Marcel,

I added you and Tim and Eliot as developers in the SS repository, and anyone
else is welcome too, though I did not want to make it global writable since
this class is dangerous if you make an error in the wrong place ... ask me how
I know ;-)

The class is lightweight, but I think we should play with it for a while
before considering it for trunk. For now, it's easy enough to load it from
SqueakSource. Here's the shortcut:

   Installer ss
      project: 'DoItFirst';
      install: 'DoItFirst-System-Support'.

It seems quite possible that a more general argument processing approach
may be needed. For example, if I am trying to rescue a broken image, then
I want to be able to process a -doit at the earliest possible opportunity,
preferably before anything else happens in the startUp list. On the other
hand, if I am handling the -filein option, then I might want this to be done
much later in the startUp processing.

So let's just play around with this for a while and see what works :-)

Dave

On Sun, Jun 14, 2020 at 07:30:05PM +0200, Marcel Taeumel wrote:

> Hi Dave.
>
> Thank you! Looks good.
>
> Here are some thoughts:
>
> - The small footprint of this is awesome!
> - Since you assume that "FileDirectory startUp" can work in the case of emergency, we should move it further up in the StartUpList.
> - You are likely to need full support of SmallInteger, Delay, Time, and DateAndTime -- so I suggest moving it after those classes in the StartUpList. I am writing this without looking at the current implementation of their #startUp: methods because it should not matter ... conceptionally.
> - So, what about putting this into Trunk and having the following elements first in the startup list:
>
> 1. SmallInteger
> 2. Delay
> 3. Time
> 4. DateAndTime
> 5. FileDirectory
> 6. DoItFirst
> ...
>
> Best,
> Marcel
> Am 14.06.2020 19:15:28 schrieb David T. Lewis <[hidden email]>:
> A few cups of coffee this morning led to some enhancements to my DoItFirst
> utility, so I decided to put in on SqueakSource.
>
> http://www.squeaksource.com/DoItFirst
>
> It works more or less like this:
>
> $ squeak squeak.image -- -help
> DoItFirst image arguments:
> -doit argumentlist "evaluate each argument as a doIt expression"
> -evaluate arg "evaluate arg, print result then exit"
> -filein filelist "file in each file named in fileList"
> -cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
> -help "print this message"
>
>
> Dave
>
>

>

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

marcel.taeumel
preferably before anything else happens in the startUp list.

Well, you may have to set up some state in the VM (or the OS) first, which might have to be communicated from within the image. Like the display depth. Since we cannot know in general, we have to rely on the modules we have in Squeak, which are classes in the start up list. "as early as possible" should therefore translate to "are early as meaningful" :-) We can surely not recover from *all* kinds of errors with a DoItFirst mechanism. But maybe from quite a lot.

Best,
Marcel

Am 14.06.2020 23:19:57 schrieb David T. Lewis <[hidden email]>:

Hi Marcel,

I added you and Tim and Eliot as developers in the SS repository, and anyone
else is welcome too, though I did not want to make it global writable since
this class is dangerous if you make an error in the wrong place ... ask me how
I know ;-)

The class is lightweight, but I think we should play with it for a while
before considering it for trunk. For now, it's easy enough to load it from
SqueakSource. Here's the shortcut:

Installer ss
project: 'DoItFirst';
install: 'DoItFirst-System-Support'.

It seems quite possible that a more general argument processing approach
may be needed. For example, if I am trying to rescue a broken image, then
I want to be able to process a -doit at the earliest possible opportunity,
preferably before anything else happens in the startUp list. On the other
hand, if I am handling the -filein option, then I might want this to be done
much later in the startUp processing.

So let's just play around with this for a while and see what works :-)

Dave

On Sun, Jun 14, 2020 at 07:30:05PM +0200, Marcel Taeumel wrote:
> Hi Dave.
>
> Thank you! Looks good.
>
> Here are some thoughts:
>
> - The small footprint of this is awesome!
> - Since you assume that "FileDirectory startUp" can work in the case of emergency, we should move it further up in the StartUpList.
> - You are likely to need full support of SmallInteger, Delay, Time, and DateAndTime -- so I suggest moving it after those classes in the StartUpList. I am writing this without looking at the current implementation of their #startUp: methods because it should not matter ... conceptionally.
> - So, what about putting this into Trunk and having the following elements first in the startup list:
>
> 1. SmallInteger
> 2. Delay
> 3. Time
> 4. DateAndTime
> 5. FileDirectory
> 6. DoItFirst
> ...
>
> Best,
> Marcel
> Am 14.06.2020 19:15:28 schrieb David T. Lewis :
> A few cups of coffee this morning led to some enhancements to my DoItFirst
> utility, so I decided to put in on SqueakSource.
>
> http://www.squeaksource.com/DoItFirst
>
> It works more or less like this:
>
> $ squeak squeak.image -- -help
> DoItFirst image arguments:
> -doit argumentlist "evaluate each argument as a doIt expression"
> -evaluate arg "evaluate arg, print result then exit"
> -filein filelist "file in each file named in fileList"
> -cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
> -help "print this message"
>
>
> Dave
>
>

>



Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
In reply to this post by David T. Lewis
On Sun, Jun 14, 2020 at 01:15:01PM -0400, David T. Lewis wrote:
> A few cups of coffee this morning led to some enhancements to my DoItFirst
> utility, so I decided to put in on SqueakSource.
>
>    http://www.squeaksource.com/DoItFirst
>

I have been updating this since the original post, and I think it is
in pretty good shape at this point. Latest version on SqueakSource is
DoItFirst-System-Support-dtl.14.mcz.

In order to make this work properly I also add a couple of references
to DoItFirst from other class startUp methods. That is messy to add to
a MCZ, so I'm attaching a change set containing the latest package plus
the two additional startUp calls.

I think this is clean enough to consider adding to trunk now, so if
folks think it is a good idea, let me know and I'll add it.

To summarize (from the -help command line option):

DoItFirst image arguments:
        -doit argumentlist "evaluate each argument as a doIt expression"
        -evaluate arg "evaluate arg, print result then exit"
        -filein filelist "file in each file named in fileList"
        -cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
        -debug "enter a debugger as soon as possible in the startUp processing"
        -help "print this message"

Dave
 



DoItFirst-dtl.1.cs (11K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

stes
In reply to this post by David T. Lewis
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


Nice utility.  It provides a workaround or solution to Transcript
redirectToStdOut not working (or not working robustly).

$ cat headless-hello.sq

TranscriptStream redirectToStdOut.
Transcript show:'hello world'.
Smalltalk quitPrimitive

$ squeak -headless squeak.image headless-hello.sq

For some reason the above prints no output in squeak-4.

I believe that I tested it on older Squeak versions (version 3?) and there,
redirectToStdout worked.  Or perhaps in some versions I notice that it
sometimes seems to print on stdout and sometimes not.

But anyway the DoItFirst package and its -evaluate on the other hand,
uses "Filestream stdout" and seems to work better; it depends on the asString
message (it sends asString to the argument that is being evaluated).

$ squeak -headless squeak.image -- -evaluate "#'hello world'"
hello world

$ squeak -headless squeak.image -- -evaluate "Smalltalk imageFormatVersion"
6504

In any case this provides a mechanism for batch oriented processing.

Thanks,
David Stes

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJfw8EKAAoJEAwpOKXMq1MaPPMH/Av2+4xVDKutBXZBlfvUbx1c
o6Z9OuVhvtnMdIPU19fIy0o4347V0AqKNrxFJz1MQaF05ZBu7a9hXf3+qsF6pkTY
xfNRRd8sIYajGrad9bjPjPotMFJKn+pYFdg7Tp/IKc4yXv9x+kzPJRCRqtlM94qH
m91zcW1vK6yqNWxeS0FBvpSXpNgxTP0aOw4myzb0VzXB/Tge9BS2QOfQi4NIx/0O
p8Nqumvo0YJA30Fvvrz163Dng8LeH97yfeh1q1DXp987Ys5Sa5pfboy2CWjiWqsS
T9thHiZa0wt2KZoB8m2WUdT2wXKv+uYRmYvx6Wh4d5vfST1Ql774pE+0uRGXBdE=
=quQK
-----END PGP SIGNATURE-----

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

stes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


I've a request for enhancement.

I like the DoItFirst package, but I think there should be -f option,
like in AWK to read from a source file.

For example:

bash-4.4$ squeak squeak.image  -- -help          
DoItFirst image arguments:
        -doit argumentlist "evaluate each argument as a doIt expression"
        -evaluate arg "evaluate arg, print result then exit"
        -filein filelist "file in each file named in fileList"
        -cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
        -debug "enter a debugger as soon as possible in the startUp processing"
        -help "print this message"

bash-4.4$ cat loop.st
|cltn index|
cltn _ OrderedCollection new.
index _ 1.
[index <= 10] whileTrue: [cltn add: index. index _ index + 1].
cltn

bash-4.4$ squeak squeak.image  -- -evaluate "`cat loop.st`"
an OrderedCollection(1 2 3 4 5 6 7 8 9 10)

What I'd propose is to add a -f which is like -evaluate and the 'cat'.

bash-4.4$ squeak squeak.image  -- -f loop.st
an OrderedCollection(1 2 3 4 5 6 7 8 9 10)

As far as I can see the DoItFirst package does not have this, because -filein
is not quite the same.

When I try
bash-4.4$ squeak squeak.image  -- -filein loop.st          

that doesn't work.  So a -f option would be nice,
or is there a solution that I don't see ?

Also a short name like -c or -e as a shortcut for -evaluate would be nice.

In any case, I've tried DoItFirst both with the squeak-4 from subversion,
and the squeak-5 from OpenSmalltalk (Cog VM and Stack VM release 5.0 with
Squeak6.0alpha images) and the DoItFirst package seems to work fine.

Regards,
David Stes


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJfxz3AAAoJEAwpOKXMq1MaqY4IAI2Rdesu6SKMpXlMdbPrAHSB
YxSkjICNFRY+0TF8irelEU4UhLOn8Rap7xKjD7ZmbvD4Q0TKxys0fMAYw2F9jjvD
gNIvx7I4GcfGdH14QEmyNAUdEt0Rv88uReeZcoJxY54ycQuoEveeAGeMID5e38kw
UDZ25WIX0l4/dKmblkAHrgwVfoKUr2ukOdSr2VsusE8Gc34+mvsNx93U1VNpBrgi
EOWRq6r2FsqHmCfdvoW3H9FgnUYL80c0nRftLdU7EKZXdZTTWL1dclyckmVLTHqd
pPO3UxXrluvAk+VqtvxsMLqFoiJdYhp9080FGAMJZh2LnLfhZy7aXbSaRF02KV4=
=5Mia
-----END PGP SIGNATURE-----

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

fniephaus
In reply to this post by David T. Lewis
This is great! +1 for adding this to trunk, leaving the when to Dave.

Two thoughts:

- Since you've started to "mess" with some #startUp: methods, why not mess with the startUp routine as well? Let's say, you add a flag that lists all items in the startUpList and quits the image. You can then add another flag that lets you choose the position of the DoItFirst class within the list, and insert the class right before processing it (e.g. #processStartUpList:). And by default, the position could be set to some reasonable value (right after SmallInteger, FileStream, et al.). If I don't care about the position, I can just use the default. If I want a special position, I can print the current list and then rerun with an index.

- I don't know how yet, but it'd be cool to be able to cut off the rest of the startUp list with this utility, or exclude certain classes from the startUp list. In TruffleSqueak, for example, we jump through some hoops to set up an image for headless execution [1] and it'd be nice if we could simplify that with your utility.

Cheers,
Fabio


On Thu, Nov 26, 2020 at 9:01 PM David T. Lewis <[hidden email]> wrote:
On Sun, Jun 14, 2020 at 01:15:01PM -0400, David T. Lewis wrote:
> A few cups of coffee this morning led to some enhancements to my DoItFirst
> utility, so I decided to put in on SqueakSource.
>
>    http://www.squeaksource.com/DoItFirst
>

I have been updating this since the original post, and I think it is
in pretty good shape at this point. Latest version on SqueakSource is
DoItFirst-System-Support-dtl.14.mcz.

In order to make this work properly I also add a couple of references
to DoItFirst from other class startUp methods. That is messy to add to
a MCZ, so I'm attaching a change set containing the latest package plus
the two additional startUp calls.

I think this is clean enough to consider adding to trunk now, so if
folks think it is a good idea, let me know and I'll add it.

To summarize (from the -help command line option):

DoItFirst image arguments:
        -doit argumentlist "evaluate each argument as a doIt expression"
        -evaluate arg "evaluate arg, print result then exit"
        -filein filelist "file in each file named in fileList"
        -cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
        -debug "enter a debugger as soon as possible in the startUp processing"
        -help "print this message"

Dave




Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
In reply to this post by stes
Hi David,

These are very good suggestions, sorry I did not reply earlier.

It sounds like a good Sunday Squeaker project for tomorrow after
I get a good pot of coffee going :-)

Thanks,
Dave

On Wed, Dec 02, 2020 at 08:12:05AM +0100, [hidden email] wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
>
> I've a request for enhancement.
>
> I like the DoItFirst package, but I think there should be -f option,
> like in AWK to read from a source file.
>
> For example:
>
> bash-4.4$ squeak squeak.image  -- -help          
> DoItFirst image arguments:
> -doit argumentlist "evaluate each argument as a doIt expression"
> -evaluate arg "evaluate arg, print result then exit"
> -filein filelist "file in each file named in fileList"
> -cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
> -debug "enter a debugger as soon as possible in the startUp processing"
> -help "print this message"
>
> bash-4.4$ cat loop.st
> |cltn index|
> cltn _ OrderedCollection new.
> index _ 1.
> [index <= 10] whileTrue: [cltn add: index. index _ index + 1].
> cltn
>
> bash-4.4$ squeak squeak.image  -- -evaluate "`cat loop.st`"
> an OrderedCollection(1 2 3 4 5 6 7 8 9 10)
>
> What I'd propose is to add a -f which is like -evaluate and the 'cat'.
>
> bash-4.4$ squeak squeak.image  -- -f loop.st
> an OrderedCollection(1 2 3 4 5 6 7 8 9 10)
>
> As far as I can see the DoItFirst package does not have this, because -filein
> is not quite the same.
>
> When I try
> bash-4.4$ squeak squeak.image  -- -filein loop.st          
>
> that doesn't work.  So a -f option would be nice,
> or is there a solution that I don't see ?
>
> Also a short name like -c or -e as a shortcut for -evaluate would be nice.
>
> In any case, I've tried DoItFirst both with the squeak-4 from subversion,
> and the squeak-5 from OpenSmalltalk (Cog VM and Stack VM release 5.0 with
> Squeak6.0alpha images) and the DoItFirst package seems to work fine.
>
> Regards,
> David Stes
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2
>
> iQEcBAEBCAAGBQJfxz3AAAoJEAwpOKXMq1MaqY4IAI2Rdesu6SKMpXlMdbPrAHSB
> YxSkjICNFRY+0TF8irelEU4UhLOn8Rap7xKjD7ZmbvD4Q0TKxys0fMAYw2F9jjvD
> gNIvx7I4GcfGdH14QEmyNAUdEt0Rv88uReeZcoJxY54ycQuoEveeAGeMID5e38kw
> UDZ25WIX0l4/dKmblkAHrgwVfoKUr2ukOdSr2VsusE8Gc34+mvsNx93U1VNpBrgi
> EOWRq6r2FsqHmCfdvoW3H9FgnUYL80c0nRftLdU7EKZXdZTTWL1dclyckmVLTHqd
> pPO3UxXrluvAk+VqtvxsMLqFoiJdYhp9080FGAMJZh2LnLfhZy7aXbSaRF02KV4=
> =5Mia
> -----END PGP SIGNATURE-----
>

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

timrowledge
That reminds me I promised you a copy of the fibonacci script. For some reason it simply won't work properly in a plain 5.3 release image (the stdout is in a bad state) but is ok if you use an image that has been saved from that.




tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
"Bo***x" said Pooh when Piglet kneed him in the groin.





FibonacciTestScript.st (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

stes
In reply to this post by stes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


Thanks for posting this interesting FibonacciTestScript.st.

First of all the script also uses FileStream stdout, and shows how
to use nextPutAll to write to stdout.  Also it shows how to time a block.

For me on Squeak VM 4.19.2 I get an error however from the first line:

bash-4.4$ head -1 FibonacciTestScript.st
#!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image

I think the error 'Invalid Character' in Squeak 4.6 is from the  #! line.

I ran the script as follows:

bash-4.4$ squeak -nodisplay squeak.image -- -evaluate 'Smalltalk version'
Squeak4.6

However I think I don't need the "DoItFirst" package, just to run the FibonacciTestScript, which is using FileStream stdout by itself :

bash-4.4$ squeak -nodisplay squeak.image FibonacciTestScript.st          

Anyway thanks for posting the script.

David Stes

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJfzO5kAAoJEAwpOKXMq1MaQNoIAL+iI6yVH3MtvG9zykLL4fOo
BOVG9wwNQYSSXUZisjtn01Z0OmF/heplEsf4PWzyJGxhMYalXRs/v6/P0LxN/iR8
Rbm2rBTaF1ItXWaUjBbicnoNSVKciOPUhHt3CwqUXyuKV3co8pMRkoHefL+6jej3
MB7a25XBTW6rHzJR+FqETBPgsi8qcCyz/XTOMFHxUg00LnU1m0+MLmw8IuvtJ42y
ENtiDK24kXRSFpFctFrSK0Isq6jUGHlIdiy1L9+S3u9v3V8R8Jhvne/x8a5JLMDZ
i7zrM6K4SFY5PLDAY5JqemabYuT3GO3C8s60iEoptptTUNeTf6q9RkJlJj1RCHU=
=nw27
-----END PGP SIGNATURE-----

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
In reply to this post by David T. Lewis
David,

I added your enhancements in DoItFirst-System-Support-dtl.15 on SqueakSource:

  DoItFirst image arguments:
      --doit argumentlist "evaluate each argument as a doIt expression"
      --evaluate arg "evaluate arg, print result then exit"
      --file filename "evaluate contents of filename, print result then exit"
      --filein filelist "file in each file named in fileList"
      --cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
      --debug "enter a debugger as soon as possible in the startUp processing"
      --help "print this message"
  some arguments have single character synonyms, -f is a synonym for --file, -d for --doit
  single '-' may be used instead of '--', -help is interpreted as --help


Dave

On Sat, Dec 05, 2020 at 03:56:41PM -0500, David T. Lewis wrote:

> Hi David,
>
> These are very good suggestions, sorry I did not reply earlier.
>
> It sounds like a good Sunday Squeaker project for tomorrow after
> I get a good pot of coffee going :-)
>
> Thanks,
> Dave
>
> On Wed, Dec 02, 2020 at 08:12:05AM +0100, [hidden email] wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA256
> >
> >
> > I've a request for enhancement.
> >
> > I like the DoItFirst package, but I think there should be -f option,
> > like in AWK to read from a source file.
> >
> > For example:
> >
> > bash-4.4$ squeak squeak.image  -- -help          
> > DoItFirst image arguments:
> > -doit argumentlist "evaluate each argument as a doIt expression"
> > -evaluate arg "evaluate arg, print result then exit"
> > -filein filelist "file in each file named in fileList"
> > -cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
> > -debug "enter a debugger as soon as possible in the startUp processing"
> > -help "print this message"
> >
> > bash-4.4$ cat loop.st
> > |cltn index|
> > cltn _ OrderedCollection new.
> > index _ 1.
> > [index <= 10] whileTrue: [cltn add: index. index _ index + 1].
> > cltn
> >
> > bash-4.4$ squeak squeak.image  -- -evaluate "`cat loop.st`"
> > an OrderedCollection(1 2 3 4 5 6 7 8 9 10)
> >
> > What I'd propose is to add a -f which is like -evaluate and the 'cat'.
> >
> > bash-4.4$ squeak squeak.image  -- -f loop.st
> > an OrderedCollection(1 2 3 4 5 6 7 8 9 10)
> >
> > As far as I can see the DoItFirst package does not have this, because -filein
> > is not quite the same.
> >
> > When I try
> > bash-4.4$ squeak squeak.image  -- -filein loop.st          
> >
> > that doesn't work.  So a -f option would be nice,
> > or is there a solution that I don't see ?
> >
> > Also a short name like -c or -e as a shortcut for -evaluate would be nice.
> >
> > In any case, I've tried DoItFirst both with the squeak-4 from subversion,
> > and the squeak-5 from OpenSmalltalk (Cog VM and Stack VM release 5.0 with
> > Squeak6.0alpha images) and the DoItFirst package seems to work fine.
> >
> > Regards,
> > David Stes
> >
> >
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v2
> >
> > iQEcBAEBCAAGBQJfxz3AAAoJEAwpOKXMq1MaqY4IAI2Rdesu6SKMpXlMdbPrAHSB
> > YxSkjICNFRY+0TF8irelEU4UhLOn8Rap7xKjD7ZmbvD4Q0TKxys0fMAYw2F9jjvD
> > gNIvx7I4GcfGdH14QEmyNAUdEt0Rv88uReeZcoJxY54ycQuoEveeAGeMID5e38kw
> > UDZ25WIX0l4/dKmblkAHrgwVfoKUr2ukOdSr2VsusE8Gc34+mvsNx93U1VNpBrgi
> > EOWRq6r2FsqHmCfdvoW3H9FgnUYL80c0nRftLdU7EKZXdZTTWL1dclyckmVLTHqd
> > pPO3UxXrluvAk+VqtvxsMLqFoiJdYhp9080FGAMJZh2LnLfhZy7aXbSaRF02KV4=
> > =5Mia
> > -----END PGP SIGNATURE-----
> >
>

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
On Sun, Dec 06, 2020 at 10:03:25AM -0500, David T. Lewis wrote:

> David,
>
> I added your enhancements in DoItFirst-System-Support-dtl.15 on SqueakSource:
>
>   DoItFirst image arguments:
>       --doit argumentlist "evaluate each argument as a doIt expression"
>       --evaluate arg "evaluate arg, print result then exit"
>       --file filename "evaluate contents of filename, print result then exit"
>       --filein filelist "file in each file named in fileList"
>       --cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
>       --debug "enter a debugger as soon as possible in the startUp processing"
>       --help "print this message"
>   some arguments have single character synonyms, -f is a synonym for --file, -d for --doit
>   single '-' may be used instead of '--', -help is interpreted as --help
>

Please use DoItFirst-System-Support-dtl.16 which fixes a couple of slips
in the DoItFirst-System-Support-dtl.15 commit. Not enough coffee this
morning I guess, sorry about that.

Dave


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
In reply to this post by fniephaus
On Sat, Dec 05, 2020 at 09:33:26AM +0100, Fabio Niephaus wrote:

> This is great! +1 for adding this to trunk, leaving the when to Dave.
>
> Two thoughts:
>
> - Since you've started to "mess" with some #startUp: methods, why not mess
> with the startUp routine as well? Let's say, you add a flag that lists all
> items in the startUpList and quits the image. You can then add another flag
> that lets you choose the position of the DoItFirst class within the
> list, and insert the class right before processing it (e.g.
> #processStartUpList:). And by default, the position could be set to some
> reasonable value (right after SmallInteger, FileStream, et al.). If I don't
> care about the position, I can just use the default. If I want a special
> position, I can print the current list and then rerun with an index.
>

The way I handled this is by making DoItFirst be the first entry in the
startup list, and having it invoke the startUp in other classes if and only
if needed to process the command line options. The rationale for this
is that the --debug option will enter a debugger at the earliest possible
time before encountering any errors that might occur later in the
startUp processing. This is a feature that you don't need very often,
but when you need it, you really need it.

> - I don't know how yet, but it'd be cool to be able to cut off the rest of
> the startUp list with this utility, or exclude certain classes from the
> startUp list. In TruffleSqueak, for example, we jump through some hoops to
> set up an image for headless execution [1] and it'd be nice if we could
> simplify that with your utility.
>

That might be a tricky problem, but I'm sure it can be done. In principle
we could manipulate the startup from one of the existing argument hooks,
but at that point we are already iterating over the startup list so
it is presumably not good to manipulate the list at that time. One
possible solution that comes to mind is to move DoItFirst out of the
startup list, and just explictly call it right before processing the
list.

I note also that we do not have accessors for the StartUpList and ShutDownList,
so we would probably want to add these too.

Dave


> Cheers,
> Fabio
>
> [1]
> https://github.com/hpi-swa/trufflesqueak/blob/4aa371a608bd73e9be1a6c65e727eb45370d23e8/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageContext.java#L191-L207
>
> On Thu, Nov 26, 2020 at 9:01 PM David T. Lewis <[hidden email]> wrote:
>
> > On Sun, Jun 14, 2020 at 01:15:01PM -0400, David T. Lewis wrote:
> > > A few cups of coffee this morning led to some enhancements to my
> > DoItFirst
> > > utility, so I decided to put in on SqueakSource.
> > >
> > >    http://www.squeaksource.com/DoItFirst
> > >
> >
> > I have been updating this since the original post, and I think it is
> > in pretty good shape at this point. Latest version on SqueakSource is
> > DoItFirst-System-Support-dtl.14.mcz.
> >
> > In order to make this work properly I also add a couple of references
> > to DoItFirst from other class startUp methods. That is messy to add to
> > a MCZ, so I'm attaching a change set containing the latest package plus
> > the two additional startUp calls.
> >
> > I think this is clean enough to consider adding to trunk now, so if
> > folks think it is a good idea, let me know and I'll add it.
> >
> > To summarize (from the -help command line option):
> >
> > DoItFirst image arguments:
> >         -doit argumentlist "evaluate each argument as a doIt expression"
> >         -evaluate arg "evaluate arg, print result then exit"
> >         -filein filelist "file in each file named in fileList"
> >         -cwd path "set FileDirectory defaultDirectory to path prior to
> > evaluating other options"
> >         -debug "enter a debugger as soon as possible in the startUp
> > processing"
> >         -help "print this message"
> >
> > Dave
> >
> >
> >

>


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
On Sun, Dec 06, 2020 at 12:52:39PM -0500, David T. Lewis wrote:

> On Sat, Dec 05, 2020 at 09:33:26AM +0100, Fabio Niephaus wrote:
>
> > - I don't know how yet, but it'd be cool to be able to cut off the rest of
> > the startUp list with this utility, or exclude certain classes from the
> > startUp list. In TruffleSqueak, for example, we jump through some hoops to
> > set up an image for headless execution [1] and it'd be nice if we could
> > simplify that with your utility.
> >
>
> That might be a tricky problem, but I'm sure it can be done. In principle
> we could manipulate the startup from one of the existing argument hooks,
> but at that point we are already iterating over the startup list so
> it is presumably not good to manipulate the list at that time. One
> possible solution that comes to mind is to move DoItFirst out of the
> startup list, and just explictly call it right before processing the
> list.
>

Actually I may have spoken too soon, because the existing --doit option
seems to be able to manipulate the startup list directly with no
problem at all. For example, I ran this command line:

$ run squeak.image -- --doit 'Smalltalk removeFromStartUpList: PowerManagement' 'Smalltalk removeFromStartUpList: ExtendedClipboardInterface' &

This removed PowerManagement and ExtendedClipboardInterface from the
startup list, and the remaining elements of the list were processed
without problems.

So as far as I can tell, you will be able to customize the startup
list in any way necessary just by adding some --doit snippets on
the command line.

Dave


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

timrowledge
In reply to this post by stes


> On 2020-12-06, at 6:46 AM, [hidden email] <[hidden email]> wrote:
>
> First of all the script also uses FileStream stdout, and shows how
> to use nextPutAll to write to stdout.  Also it shows how to time a block.

I hope those are all useful things to learn; the stdout thing may be an issue, at least for the 5.3 release image.

>
> For me on Squeak VM 4.19.2 I get an error however from the first line:
>
> bash-4.4$ head -1 FibonacciTestScript.st
> #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image

Ah, right, now I remember. We had some fascinating discussions about this area  and that line was added because it means you can set the file permissions to executable and simply run the fibonacci file as a unix script; the #!/usr/bin/squeak will actually run the vm, pass it the following words and thus run the system with this script. Neat, eh? Dig into the list archives for May 2019 (which was about 300 years ago IIRC) and subject 'Faster fibonacci' and related stuff. Subbu suggested some extra-neat ways of making Squeak do scripty-things using the unix script-handler.


>
> I think the error 'Invalid Character' in Squeak 4.6 is from the  #! line.

Yes, sometihng got added for 5.3 to make it able to skip that. I'm not sure what; digging into those emails should reveal it.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
"Bother" said Pooh, as the IRS kicked his door in.



Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
On Sun, Dec 06, 2020 at 10:50:13AM -0800, tim Rowledge wrote:

>
>
> > On 2020-12-06, at 6:46 AM, [hidden email] <[hidden email]> wrote:
> >
> > First of all the script also uses FileStream stdout, and shows how
> > to use nextPutAll to write to stdout.  Also it shows how to time a block.
>
> I hope those are all useful things to learn; the stdout thing may be an issue, at least for the 5.3 release image.
>
> >
> > For me on Squeak VM 4.19.2 I get an error however from the first line:
> >
> > bash-4.4$ head -1 FibonacciTestScript.st
> > #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image
>
> Ah, right, now I remember. We had some fascinating discussions about this area  and that line was added because it means you can set the file permissions to executable and simply run the fibonacci file as a unix script; the #!/usr/bin/squeak will actually run the vm, pass it the following words and thus run the system with this script. Neat, eh? Dig into the list archives for May 2019 (which was about 300 years ago IIRC) and subject 'Faster fibonacci' and related stuff. Subbu suggested some extra-neat ways of making Squeak do scripty-things using the unix script-handler.
>


There is a preference for "Read document at startup" that needs to be enabled
in order for this to work.

In addition, you will need to set the script file to be executable:

$ chmod +x FibonacciTestScript.st

Then edit the first line of the file to match your own local system.
Tim's script starts with:

#!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image

On my computer, the executable script for running Squeak VMs is
called /usr/local/bin/run rather than /usr/bin/squeak, and the
particular image that I am running at the moment is called squeak.12.image,
so I edited the line in my script file to look like this:

#!/usr/local/bin/spur64 squeak.12.image

So now the FibonacciTestScript.st file is a Unix executable shell
script, and I can run it like this:

$ ./FibonacciTestScript.st

You can google "unix shebang" to find explanations of how this works.
The basic idea is that the script file runs some program specified
in the comment (starts with #) on the first line of the script, then
it passes itself as an additional parameter to whatever program it ran.
So Unix thinks it's a shell script, and Squeak thinks it's a Smalltalk
start document. The shell script starts Squeak, and then feeds itself
back into Squeak as the start documemt.

According to Wikipedia:

  "The shebang was introduced by Dennis Ritchie between Edition 7 and 8 at Bell Laboratories"

Not bad for a 35-plus year old shell hack, eh?

Dave


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

K K Subbu
On 07/12/20 1:40 am, David T. Lewis wrote:

> Tim's script starts with:
>
> #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image
>
> On my computer, the executable script for running Squeak VMs is
> called /usr/local/bin/run rather than /usr/bin/squeak, and the
> particular image that I am running at the moment is called squeak.12.image,
> so I edited the line in my script file to look like this:
>
> #!/usr/local/bin/spur64 squeak.12.image
>
> So now the FibonacciTestScript.st file is a Unix executable shell
> script, and I can run it like this:
>
> $ ./FibonacciTestScript.st

On Linux, one can use the binfmt_misc (see update-binfmts(8)) to shorten
launch times for interpreters like squeak. This kernel module can match
command files with their interpreter based on extension or embedded code
patterns. Python and Java already use this feature. update-binfmts can
install, display, find, disable, enable or remove interpreters and their
scripts/images based on file extensions or embedded magic codes.

Executing .st scripts will require two registrations. One to match .st
to its image and a second one to match the image to its vm.

1. To match .st to image, register a magic pattern with the binfmt_misc
feature along with the specific image to be launched:

$ sudo update-binfmts --install squeak5-64
/var/squeak/squeak5-3-64bit.image --magic '"#spur64"' --offset 0

This will execute all .st files beginning with "spur64" with the given
image.
$ chmod +x ./foo-bar.st /var/squeak/squeak5.3-64bit.image
$ head -1 ./foo-bar.st
"#spur64"

Now the command
$ ./foo-bar.st arg1 arg2
will be equivalent to:
$ /var/squeak/squeak5.3-64bit.image ./foo-bar.st arg1 arg2

2. Register another pattern to match .image to spur64 interpreter. Then
the line is equivalent to:

$ /usr/local/bin/spur64 /var/squeak/squeak5.3-64bit.image ./foo-bar.st
arg1 arg2

Registration is a one-time effort. Because the matching and loading is
done in a kernel module, the startup time is reduced. This trick can be
useful on platforms like RPi.

HTH .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

stes
In reply to this post by stes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


First of all, thanks for updating the DoItFirst package.
I think that DoItFirst is a really nice package.

I'm having some additional questions which I'll move to the "beginners"
emailing list !

So I'll post some question on the beginners emailing list about DoItFirst.

David Stes

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJfzgX5AAoJEAwpOKXMq1MatA8IAJPzrcnoUmwfBCUAkWL5XcqD
LqxnHFMone8xwgQvabW3Ten+Q4flebCAffhQ9g5bL6mcojajW3CKkvX9pGZehmjE
knxp3adeAKq4fXL2lhHPNX155int70iWGvjtE8uXuw37mWwz/70U59XzKHTiaKzN
yeaQmT5dghCf8zjhEoJs/TZUxbgFiF+lZU82ewwos2lynlYCBE1vs2C3R41PhQvw
AQ5uYQYTFHAhLkYBOHc0mhZWoZqMB83IHncSWfol4fLFMnt6m2OamLVTqd2bZsIR
oJmW98p6+EG5HRQqqM8gOdINvEqsScl0K615tlw1NGAzF6vdzTfiZmh5hlsHChQ=
=1zs8
-----END PGP SIGNATURE-----

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis
In reply to this post by fniephaus
On Sat, Dec 05, 2020 at 09:33:26AM +0100, Fabio Niephaus wrote:
> This is great! +1 for adding this to trunk, leaving the when to Dave.
>

Done.

To see available command line options on a unix-like system:

   $ squeak squeak.image -- -h
   DoItFirst image arguments:
       --doit argumentlist "evaluate each argument as a doIt expression"
       --evaluate arg "evaluate arg, print result then exit"
       --file filename "evaluate contents of filename, print result then exit"
       --filein filelist "file in each file named in fileList"
       --cwd path "set FileDirectory defaultDirectory to path prior to evaluating other options"
       --debug "enter a debugger as soon as possible in the startUp processing"
       --help "print this message"
   some arguments have single character synonyms, -f is a synonym for --file, -d for --doit
   single '-' may be used instead of '--', -help is interpreted as --help

Dave

12