[Zope-dev] RFC : AnyScripts
Jerome Alet
alet@unice.fr
Fri, 8 Mar 2002 20:27:38 +0100
Hi,
I'm finally toying, after having stalled a too long time,
with the creation of ZShellScripts, which would be for ZShell
commands what PythonScripts are for Python...
The current, not yet available, incarnation is very highly
based on PythonScripts, however I wondered if something
better couldn't be done, because it seems to me to be an
unneeded repetition of most of the PythonScripts' code :
AnyScripts
AnyScripts would have a mandatory first line similar to the one
of any Unix shell script. By unix shell script I mean any script
which can be launched directly under Unix, not only bash or csh scripts,
but also perl, tcl, etc...
So an AnyScript would contain a first line like :
#! /scripts/interpreter
And the execution of this script in the context on which it
is applied would be delegated to another object present in
the path which was set on this very first line, i.e.
/scripts/interpreter
So you could put any interpreter object of your choice in
for example the /scripts folder (no path would mean
search the interpreter object within the acquisition path)
For example PythonScripts would contain something like :
#! /builtins/python
or something like that.
Out of my mind I can already think of a ZShell interpreter
object, but why not other types of interpreter objects :
perl
tcl
C (the language ! Why not after all)
etc...
Each interpreter object would have at least two methods :
compile() => returns a code object from source code, if meaningful
(otherwise returns the source unchanged), to be
stored in the AnyScript object which calls the
compile() method.
execute() => executes the above code object. This method of the
Interpreter object would be called by the AnyScript
object at run time, passing it the code object
obtained with compile()
Of course all of this come straight out of my mind, and there would
probably be some problems I'm not able to understand yet...
Bound variables would be like for PythonScripts, with the exception of their
content would be the best format for the Interpreter in question, so
each Interpreter object would probably also have a bind() method which
would bind vars in the preferred format for the AnyScript object which
calls this method, and would be accessible using the
preferred syntax of the langage in question, e.g. :
for PythonScripts, vars like context would be Zope Objects, like they
currently are.
for ZShell AnyScripts, vars like context, would be paths to Zope
Objects, and accessible with names like $context for example.
for C AnyScripts, vars would probably be something like PyObjects
pointers.
etc...
So AnyScripts objects would interact with their interpreter object of
choice to compile their source code, bind their vars, then finally
execute the code and get the result back.
What do you all think about this idea ?
Are any of you interested ?
I admit I don't know anything about the feasability of such a project
with other languages than ZShell, however if a single implementation
could be done, then anyone could add his own interpreter later...
PS : I'll do ZShellScripts anyway...
bye,
Jerome Alet