[Types-sig] Viper module compiler begun

skaller skaller@maxtal.com.au
Sun, 26 Dec 1999 08:33:41 +1100


I have started work on a function which takes an already
imported module, and generates CPython 1.5.2 CAPI
compatible C code. [i.e. the idea is that you can compile
it as a replacement for the source python script]

This function does not as yet use the type information
which the function argument type declarations provide
[recall I have implemented 'def f(x!typeexpr)']

However, it _does_ use the type information available
from the module level objects (obviously, this is necessary
to distinguish functions from other kinds of object :-)

Note also, the model under investigation does not
'compile' from script source, instead, the script
is executed by the interpreter first, to build the module
dictionary, and then code is generate to make each of the
objects found in the module dictionary.

Because of this approach, a lot of the 'dynamism'
involved in constructing a module is bypassed -- it is 
handled in the usual way by the interpreter.

Clearly, this approach is limited. One of the problems
is that any objects 'imported' from elsewhere will
get duplicated in each such module (rather than being shared).

I'd call this a 'leaf compiler' for this reason: it works
best with modules that can be regarded as leaves (not
needing to import from other modules). I'm investigating
how to get around this (look at the source, to see what is
imported, and actually import it, rather than building
copies of the objects).

I'll report back later on further progress. I note that while
my code is written in ML, if the tool proves useful, in that
it can compile code for some modules, and that code runs
significantly faster than script, then a translation
into Python should be possible.

In particular, such a translator could be compiled with itself .. :-)

-- 
John Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850