[pypy-dev] Basic math ops

Maciej Fijalkowski fijall at gmail.com
Wed Mar 9 13:36:26 CET 2011

On Tue, Mar 8, 2011 at 9:14 AM, Benjamin Peterson <benjamin at python.org> wrote:
> 2011/3/8 Timothy Baldridge <tbaldridge at gmail.com>:
>> In my interpreter, I have several primitive wrapper objects:
>> IntObject, FloatObject, etc.
>> Currently I'm planning to create functions for every combination:
>> def add_int_float(i, f):
>>     return FloatObject(i.int_value() + f.float_value())
>> then I'd need some sort of dispatch code that would say
>> if isinstance(arg1, IntObject) and isinstance(arg2, FloatObject):
>>    return add_int_float(arg1, arg2)
>> It seems like pypy should have something to do this already. I saw
>> some information on this but that seemed specific to the Python
>> interpreter.
> You could use multimethods. Look at the stuff in pypy/objspace/std/
> for examples. (It's a bit messy.)
>> What's the recommended procedure on this? Is there a way to tell pypy
>> "this object wraps a single value, so keep it unwrapped if you can",
>> or does pypy figure that out automagically?
> The JIT will unwrap things automatically.

For JIT to be happier you can however say:

class A(object):
  _immutable_fields_ = ['value']

so it'll know that fields don't change once the object is constructed

> --
> Regards,
> Benjamin
> _______________________________________________
> pypy-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/pypy-dev

More information about the Pypy-dev mailing list