On Tue, Mar 8, 2011 at 9:14 AM, Benjamin Peterson <[email protected]> wrote: > 2011/3/8 Timothy Baldridge <[email protected]>: >> 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 > _______________________________________________ > [email protected] > http://codespeak.net/mailman/listinfo/pypy-dev _______________________________________________ [email protected] http://codespeak.net/mailman/listinfo/pypy-dev
