[pypy-dev] Poor performance with custom bytecode

Maciej Fijalkowski fijall at gmail.com
Fri Feb 17 16:25:18 CET 2012


On Fri, Feb 17, 2012 at 5:23 PM, Maciej Fijalkowski <fijall at gmail.com> wrote:
> On Fri, Feb 17, 2012 at 5:11 PM, Timothy Baldridge <tbaldridge at gmail.com> wrote:
>>> A more generally targeted question, besides the sample rpython tutorial for
>>> brainfuck, what are the recommended readings (parts of the pypy code,
>>> papers, etc), tools and/or magic for working at rpython on an interpreter?
>>
>>
>> Now, most of this code is more or less crap, but I do suggest taking a
>> look at my first stab at a RPython interpreter for Clojure
>>
>> https://github.com/halgari/clj-pypy
>>
>>
>> IIRC, the target complied okay, and you could run the code in scratchspace.clj.
>>
>> Basically I got to the point where I realized that if I had lisp
>> macros, I could write RPython code way faster. Half of the structures
>> in Clojure follow this pattern:
>>
>> class Foo(object):
>>    def __init__(self, foo bar, baz):
>>         self.foo = foo
>>         self.bar = bar
>>         self.baz = baz
>>    def addBarBaz(self):
>>         return bar + baz
>>
>> I could write that for that, or, in Clojure I could write myself a
>> macro and just do:
>>
>> (deftype Foo [foo bar baz]
>>      (addBarBaz[self] (+ bar baz)))
>>
>
> Just a sidenote - RPython allows you to do metaprogramming. It's not
> as easy and pleasant, but you can generate code. In fact we do it all
> over the place in pypy either using string and exec() or closures that
> return slightly different classes for each set of given parameters.

To go even further - you can do whatever you like that ends up with
living python objects. Then they can be compiled as RPython. If you
feel like bootstrapping by having pieces compiled to RPython then it's
all good.


More information about the pypy-dev mailing list