[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Jul 7 23:37:56 2003 
Subject:Re: Poplog for scripting? 
From:Aaron Sloman 
Volume-ID:1030707.01 


hebisch@math.uni.wroc.pl (Waldek Hebisch) writes:

[Maybe you should join the poplog-dev email list?
I can add you if you wish. It's for discussion of poplog
developments that may be of limited interest to general
users.]

> Date: 7 Jul 2003 21:35:39 GMT
> Organization: Politechnika Wroclawska
>
> I was considering using Poplog for (Linux) scripting. I immediatly
> meet few obstacles:

Various people have raised similar questions in the past. I think
the person who has done most work on this is Steve Leach.

> 1) Script interpreter must be a binary. As distributed Poplog
>    depends on shell scripts to set up environment variables

Unless you have already set them up as some of us do in our login
files. But I appreciate that that would not be appropriate for
system startup scripts.

On linux and solaris you can run the basepop11 executable without
any of the environment variables set. Some things probably will
not work, but I don't know which. The obvious thing is autoloading,
if the various library directories are not defined, but you probably
would not want that in scripts.

Several environment variables are needed to run basepop11 +startup

> 2) Command-line handling: script should be able to take
>    arguments on command line without risk of Poplog treating
>    them in some magic way (deadly for suid scripts).

It should be possible to recompile a version of poplog with
different behaviour for arguments.

Already the rsvpop11 image will not run at all unless given
a saved image. (It used to be used for delivery of products
it is not now provided by default. See HELP newpop abd below [*].

All the current magic ways are documented in REF system

    basepop11 +filename
        = run saved image


(pop11 = basepop11 +startup)

    basepop11 %flag
    basepop11 +filename %flag

Use special flags to control e.g. whether init.p and vedinit.p files
are read, whether startup banner is printed, etc.


    basepop11 ....  file.p

Start up and compile the file then exit. The file could call the
compiler to compile from the terminal or could perform some task
and finish.

Input and output can be redirected as usual in unix.

However, if the argument is one of ved, help, teach, ref or doc
it is interpreted as an instruction to start pop11 (or prolog, etc.)
then run the corresponding command. E.g.

    pop11 ved foo.p

If argument starts with ":" treat it as pop11 command to be obeyed,
e.g.

    basepop11 ":99*9=>"
    ** 891

If you run a saved image it can take over the processing of some
of the command line options.


[*] If you go into an empty directory and type

    pglink -rsv

It will create (among other things) an executable newpop11
and an executable rsvpop11. If you run the latter it will
immediately exit. If you use the newpop11 executable to
compile some code and produce a saved image foo.psv

then
    rsvpop11 +foo

will run the saved image.

> 3) Ignoring the first line (#!...) used to invoke Poplog

If you use a saved image that reads the script you can make it
do this.

Craig Brozefsky tried something like this a few years ago.
I have saved his package here:

    http://www.cs.bham.ac.uk/research/poplog/popsh-0.1.tar.gz
        9512 bytes

browsable here
    http://www.cs.bham.ac.uk/research/poplog/popsh/

Original version here:
    http://www.red-bean.com/~craig/popsh

I gather you have already found it on www.poplog.org

> 4) Startup time: tiny scripts are expected to execute quickly
>    but on 650 MHz Duron Popog take 100ms to start

How did you test it?

Here is poplog on a 400 mhz celeron on dell laptop running redhat 9
using tcsh as shell:

   % time basepop11 ":sysexit();"
   0.010u 0.010s 0:00.00 0.0%      0+0k 0+0io 457pf+0w

   % time basepop11 ":99*9=>;sysexit();"
   ** 891
   0.010u 0.010s 0:00.00 0.0%      0+0k 0+0io 467pf+0w

I.e. the whole thing, including running and finishing, takes 10 ms ?

(Using bash, the time command gives longer times, about 20 ms.)

> 5) Regexp support.

There is a regular expression described in REF regexp.

It uses @ instead of \ as 'escape' character, and has some other
facilities for use in Ved., e.g. allowing @a and @z to refer to
beginning and end of lines.

The source files could be changed for scripts using standard unix
syntax. They are here:

    $popsrc/*regexp*

> I see to packages in GOSPL going in this direction, namely `popsh'
> and `usr-bin-poplog'. However `popsh' only solves problem 3 above.
> `usr-bin-poplog' solves problem 1 at the cost of adding wrapper
> binary which would increase startup time and help nothing to
> problem 2.

I have not looked at this. Should do.

> It seems that Poplog captures enviroment variables quite early
> during its startup. So it should be easy to have default values
> of enviroment variables in the Poplog binary. For runtime
> customisation getting data from a pop11 init file seems more
> natural then going trough shell script -- I wonder why the original
> design used so much indirection.

There's a long history, including use of poplog to build itself
and also making it easy for users to tailor it via environment
variables, plus invoking saved images via a name of executable
linked to basepop11.

E.g. if foo is a link to basepop11, then running foo is equivalent
to running
    basepop11 $pop_foo

Hence $pop_pop11 has to be defined as something like:

    +$popsavelib/startup.psv

(or in Birmingham as +$poplocalbin/startup.psv )

Likewise pop_clisp, pop_pml, pop_plog
See
    $popcom/poplog (.sh)
    $popcom/popenv (.sh)


I now think something like a default startup script like init.p
in the installation directory, which user's ~/.popinit.p (or
something like that) could override would have been better.

It should be possible to change the poplog startup mechanisms
in $popsrc/poplog_main.p

(E.g. there is code in there for password checking that is now
not needed. I don't know how much of it runs before it
returns.)

> To solve problem with possibly mangled command line I would like
> a special option that would stop further interpretation of
> command line arguments by Poplog -- how hard would that be?

Starting up a saved image would do that. Otherwise I suppose
the startup flags need to be extended.

> I have tried to run directly Poplog binary.

Do you mean basepop11?

> When I enabled `mmap'

How do you do that?

> support startup time went down to 8 ms even with saved image
> containing pop11+clisp+prolog+pml (and the process size is much
> smaller then in distributed version). Why is `mmap' not enabled
> by default on Linux?

Is this a missing linker flag in $popsys/poplink_cmnd ?

> Concering regular expressions: included regexp package seem to
> implement very limited subset of regular expressions. Are there
> more powerful regular expressions available?

I wonder which package in poplog you looked at. The pop11
list matcher (HELP matches) is different from the regexp
matcher on strings.

> (I know that Prolog
> DCG-s are more powerful, but they clumsier to use).
>
> By the way, experimentig with Poplog I few times got non-working
> installation and I had to restore it from tarball. Now, I know how
> to link Poplog in an alternate directory. However it would be
> better to be able to compile in non-system directory and currently
> I got problems with include files. Even better would be to put
> object files in different directory then sources, but that makes
> problem with includes even worse. How `popc' searches for
> inclede files?

There is a global variable

    popincludelist

which holds a list of directory names. It is used by the 'include'
macro. Its default value is set in
    $popautolib/popincludelist.p

so that it can be autoloaded.

Often packages will extend it, as they extend popuseslist, popautolist,
vedteachlist, vedhelplist, etc.

I hope that helps.

Aaron
====
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk   (ReadATas@please !)
PAPERS: http://www.cs.bham.ac.uk/research/cogaff/ (And free book on Philosophy of AI)
FREE TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html