[pypy-dev] setting attribute of JitHookInterface instance

Maciej Fijalkowski fijall at gmail.com
Wed Mar 16 07:59:52 EDT 2016


It's general. You can do whatever you like before runtime (during
import time for example) as long as the presented world to rpython is
static enough - in other words Python is a meta-programming language
for RPython

On Wed, Mar 16, 2016 at 1:34 PM, Magnus Morton <m at magnusmorton.com> wrote:
> Hi Armin,
>
> Thanks for looking into this. Is this pre-translation code a general thing possible with any RPython based compiler, or is it very PyPy specific?
>
> Cheers,
> Magnus
>
>> On 16 Mar 2016, at 08:45, Armin Rigo <arigo at tunes.org> wrote:
>>
>> Hi Magnus,
>>
>> On 16 March 2016 at 01:37, Magnus Morton <m at magnusmorton.com> wrote:
>>> You can recreate it in PyPy by putting the following two lines pretty much anywhere in interpreter level code other than the setup_after_space_initialization methods
>>>
>>> from pypy.module.pypyjit.hooks import pypy_hooks
>>> pypy_hooks.foo = “foo”
>>>
>>> What I can’t understand is what is special about the setup_after_space_initialization methods that makes it work there.
>>
>> Reproduced and figured it out.  Added some docs in eda9fd6a0601:
>>
>> +    # WARNING: You should make a single prebuilt instance of a subclass
>> +    # of this class.  You can, before translation, initialize some
>> +    # attributes on this instance, and then read or change these
>> +    # attributes inside the methods of the subclass.  But this prebuilt
>> +    # instance *must not* be seen during the normal annotation/rtyping
>> +    # of the program!  A line like ``pypy_hooks.foo = ...`` must not
>> +    # appear inside your interpreter's RPython code.
>>
>> In PyPy, setup_after_space_initialization() is not RPython (which means
>> it is executed before translation).
>>
>>
>> A bientôt,
>>
>> Armin.
>
> _______________________________________________
> pypy-dev mailing list
> pypy-dev at python.org
> https://mail.python.org/mailman/listinfo/pypy-dev


More information about the pypy-dev mailing list