The Topy project

François Pinard pinard at iro.umontreal.ca
Fri Apr 5 17:45:53 EST 2002


[Chris Liechti]

> I think the ideal solution would be to translate the source language to
> a meta language that describes the algorithm and its properties.

This is already what Topy does, yet the meta-language is produced and left
in tree form.  There was no need to make a surface representation for it.
Well, I did make a bastardised representation, but for debugging only!

> [...] then this cookbook could be used to generate code in any other
> language - however I don't think that such an approach is really possible
> with today's technologies...

I would agree, if you speak of "any" language.  Python has great lengths of
expressive power, it beats to this many other languages I learned before.
We may inject many small languages into Python, and still have plenty of
unused room on the Python side.  A few things appear to be missing (like
`goto's!), but we prefer to live without such things anyway, don't we?

The current meta-representation is surprisingly simple, at least so far.
It seems sufficient to convey most of Scheme (I have nothing to represent
lazy evaluation, nor continuations).  Some reasonable trickery is needed to
represent nested scopes and `let' loops: I found nothing intractable yet,
and no real problem will pop up.  Plans are still opened about `letrec';
hopefully, I'll find something not too ugly. :-)

It is notable to me that the meta-representation is much more simpler than
what would be needed to represent Python itself.  It prosaically means,
in particular, that it would not be thinkable to use Topy for translating
Python to something else, because that middle representation is just
unable to convey generic Python code.  This limitation is very expectable;
we cannot succeed into making Python compilers because it is difficult
to automatically guess the intent of a random source fragment, it looks
equally difficult to translate Python legibly to most other languages.
Or else, we would need a target language _significantly_ more expressive
than Python itself; and waiting for this, we should not hold our breath...

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list