[pypy-dev] Non standard ASTs

Maciej Fijalkowski fijall at gmail.com
Tue Dec 13 16:03:00 CET 2011


On Tue, Dec 13, 2011 at 4:41 PM, Timothy Baldridge <tbaldridge at gmail.com> wrote:
> For some time now, I've been working on my Clojure/pypy
> implementation. However, I'm starting to wish I had a few Clojure
> facilities while writing my rpython clojure interpreter. Basically I
> would love to have macros, protocols, symbol resolution, and a ton of
> other little features for helping with run-time code generation and
> the like.
> So this is when I started thinking about generating python code from
> Clojure source. That is, in Python we have a AST, and in Clojure we
> can parse LISP lists and convert them to AST constructs. This is when
> I started to realize where Python falls short of the flexability of
> Clojure in a few key areas:
> 1) multiline closures (lambdas with more than one statement)2) IfExpr
> with multiline bodies.
> I tried working with the ast module in Python 2.7...and it's horribly
> restricted. I found a old lib from PEAK that does what I want
> (BytecodeAssembler) but it's fairly old, and no longer supported. So
> this is when I thought of the ast in /pypy/interpreter/astcompiler/
> Does the pypy interpreter support non-standard constructs like IfExpr
> with a multiline body? And if not, could it be adapted to support
> this?
> I'd rather not drop all the way to emitting Python bytecode...but I
> may have to. My end goal is to have my target load some rClojure (as I
> call it) code. And then have pypy translate this rClojure code to a
> native interpreter. Yes, we're talking about adding a new front-end to
> pypy.
> Timothy
> --
> “One of the main causes of the fall of the Roman Empire was
> that–lacking zero–they had no way to indicate successful termination
> of their C programs.”
> (Robert Firth)
> _______________________________________________
> pypy-dev mailing list
> pypy-dev at python.org
> http://mail.python.org/mailman/listinfo/pypy-dev

RPython works based on the python bytecode, so you're free to emit
python bytecode from whatever suits you. However, you're very much on
your own, since this is never going to be incorporated in PyPy. I
would strongly discourage you from dealing with AST - but that might
be just a personal dislike of AST manipulation as a mean of mapping
concepts from different languages.

Cheers,
fijal


More information about the pypy-dev mailing list