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 ... <rest deleted; you get the idea> ... Currently the Parrot interpreter only supports integer, floating point, and string registers. There's no way to store the contents of a register in memory as far as I can tell, and PMCs -- the polymorphic objects that would correspond to PyObjects -- aren't implemented either. This means it's not possible to handle general variables, and therefore we'll have to wait for PMCs before general Python programs can be handled. --amk
Wow. Cool! You should cc the language-dev list. I got some complaints from the Perlers there that the Python community seems uninterested in Parrot -- this is proof we *are* interested! --Guido van Rossum (home page: http://www.python.org/~guido/)
On Wed, Sep 26, 2001 at 10:25:35AM -0400, Guido van Rossum wrote:
Wow. Cool! You should cc the language-dev list. I got some complaints from the Perlers there that the Python community seems uninterested in Parrot -- this is proof we *are* interested!
I've seen. I'm convinced. Uhm. Wow, cool. Andrew, are you planning to do any more on this? If so, let me know if we can do anything that will make it easier for you - more information, more things implemented, or whatever. You know, it would be quite an embarrassment to me if there was a Python->Parrot compiler before a Perl->Parrot one. Not that I'm offering a challenge, or anything. ;) -- UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. -- Doug Gwyn
[Simon Cozens]
You know, it would be quite an embarrassment to me if there was a Python->Parrot compiler before a Perl->Parrot one. Not that I'm offering a challenge, or anything. ;) Don't worry, spitting out bytecodes is the easy part ... anyway ;) When there is PMCs support in place and someone begins to reimplement Python runtime and submitting a lot of patches to adjust things ... then you should worry ;)
regards.
On Wed, Sep 26, 2001 at 03:24:19PM +0100, Simon Cozens wrote:
Andrew, are you planning to do any more on this? If so, let me know if we can do anything that will make it easier for you - more information, more things implemented, or whatever.
It's been entertaining so far, and I'll probably keep playing with it, but I have no intention of becoming the person responsible for Parrot/Python interfacing long-term. The only helpful thing that needs to be implemented would be PMCs, and that's scheduled for Parrot 0.0.3. Without PMCs, there seems little else productive that can be done. (Oh, I did send a trivial patch to Gregor to make assemble.pl return a non-zero status when there's an assembly error; otherwise parrot-gen.py has no way to detect a problem in its output.) Question for Guido and Simon: Should I check this into sandbox/ in the Python CVS tree, or do you want to pull it into the Parrot CVS? I'd like to have it in a public CVS tree someplace, preferably one where I have checkin privileges. sandbox/ is fine with me. --amk
Question for Guido and Simon: Should I check this into sandbox/ in the Python CVS tree, or do you want to pull it into the Parrot CVS? I'd like to have it in a public CVS tree someplace, preferably one where I have checkin privileges. sandbox/ is fine with me.
If Simon can give you write access in a corner of the Parrot tree, that might be the best solution; if not, sandbox is fine with me too. --Guido van Rossum (home page: http://www.python.org/~guido/)
Andrew, which version of the compiler package do you use? When I try to use the version that Jeremy just checked into the standard library, I get a traceback: $ ~/python/src/linux/python parrot-gen.py -S euclid.py Traceback (most recent call last): File "parrot-gen.py", line 405, in ? main() File "parrot-gen.py", line 395, in main generate_assembly(filename, asm_filename) File "parrot-gen.py", line 355, in generate_assembly lnf = walk(ast, LocalNameFinder(), 0) File "/home/guido/python/src/Lib/compiler/visitor.py", line 114, in walk walker.preorder(tree, visitor) AttributeError: 'int' object has no attribute 'preorder' $ --Guido van Rossum (home page: http://www.python.org/~guido/)
On Wed, 26 Sep 2001, Guido van Rossum wrote:
Question for Guido and Simon: Should I check this into sandbox/ in the Python CVS tree, or do you want to pull it into the Parrot CVS? I'd like to have it in a public CVS tree someplace, preferably one where I have checkin privileges. sandbox/ is fine with me.
If Simon can give you write access in a corner of the Parrot tree, that might be the best solution; if not, sandbox is fine with me too.
I didn't see Simon follow up on this. I would think that we can get Andrew an account. Andrew, sign up for an account at http://dev.perl.org/auth/account, then if Simon will just say the word I can flip the bits to give you commit access to parrot/languages/python/ or something like that. :-) - ask -- ask bjoern hansen, http://ask.netcetera.dk/ !try; do(); more than a billion impressions per week, http://valueclick.com
On Fri, Oct 05, 2001 at 01:40:28AM -0700, Ask Bjoern Hansen wrote:
I didn't see Simon follow up on this. I would think that we can get Andrew an account.
I think we decided off-list that Guido would be OK with it going in Python CVS for now. Also, www.parrotcode.org -- "He was a modest, good-humored boy. It was Oxford that made him insufferable."
participants (5)
-
Andrew Kuchling
-
Ask Bjoern Hansen
-
Guido van Rossum
-
Samuele Pedroni
-
Simon Cozens