Over the last few days I've been experimenting with a simple
Python->Parrot compiler. This morning I finally implemented binding
variables to a register, so it now can actually compute something.
See http://www.mems-exchange.org/software/files/parrot-gen.py for
the code.
Limitations:
* Currently this only understands a *really* limited subset of Python.
* The only allowable type is integer; strings, floats, long ints, &c.,
aren't supported at all.
* It will die with an assertion if you feed it a language construct it
doesn't handle (def, class, most operators).
* Code structure is suboptimal; this is just a quick-and-dirty hack.
Example usage:
ute parrot>cat euclid.py
# Python implementation of Euclid's algorithm
m = 96
n = 64
print m,n
r = m % n
while r != 0:
m = n
n = r
r = m % n
print n
ute parrot>python euclid.py
96 64
32
ute parrot>python parrot-gen.py -r euclid.py
96 64
32
ute parrot>cat euclid.pasm
main:
set I3, 96
set I10, 64
set I9, 0
add I0, I3, I9
...