
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. 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? Thanks, 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)

2011/3/8 Timothy Baldridge <tbaldridge@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. -- Regards, Benjamin

On Tue, Mar 8, 2011 at 9:14 AM, Benjamin Peterson <benjamin@python.org> wrote:
2011/3/8 Timothy Baldridge <tbaldridge@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@codespeak.net http://codespeak.net/mailman/listinfo/pypy-dev
participants (3)
-
Benjamin Peterson
-
Maciej Fijalkowski
-
Timothy Baldridge