-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Implement __bool__ and __len__ via unary_op virtual method for all types. #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…pes. __bool__() and __len__() are just the same as __neg__() or __invert__(), and require efficient dispatching implementation (not requiring search/lookup). type->unary_op() is just the right choice for this short of adding standalone virtual method(s) to already big mp_obj_type_t structure.
And as a note, with this changes, uPy self-hosts unix versions of mandel.py and conwaylife.py (which was the motivation for starting to look into these changes). |
It is neat. Still need to implement Don't know what you mean by self hosts... mandel.py and conwaylife.py always worked with unix/micropython. |
Implement __bool__ and __len__ via unary_op virtual method for all types.
Yes, as bunch of other methods -
Not for me. It didn't work when I submitted patch for them (and lot of list stuff was missing then), and this time it failed on some ops for long ints, in particular, in true check (I was a bit surprised that rnd() implementation pushes numbers into long int, but that's it). |
Probably need Examples all work for me on my 32 bit machine, and 64 bits. Do they work for you now? |
Yes, both mandel and conwaylife work for me. I tried to time conwaylife with uPy and CPy3.3, and uPy with just by a slightest edge. But that's not informative, because most time is spent in screen output. We'll need to think about better benchmark.
FFI module shows that already need ;-).
What about calling it at sweep stage? (Yes, sure, that makes GC all suddenly much slow, so as an option; also, intuitively, one could try to "optimize" GC implementation by splitting 2-bit flags into two 1-bit vectors (or interleaving words); unclear how much that will actually improve). |
I just found that -O3 was not being applied to vm.c or gc.c. It now is, and uPy should be 20% faster than it has been for the last week.
Don't think that's possible. The GC heap can contain non-uPy objects and you can't tell what's an object and what's not... Would need to split it into 2 heaps to support sweep calling del. |
Ah right...
Or force type header on all allocations to make it precise, or have impl without conservative guarantees, which may segfault once in a while ;-). |
Actually, a type header, 1 bit, would be a nice addition. 2 types: either data, or a uPy object with a |
Per #229
bool() and len() are just the same as neg() or invert(),
and require efficient dispatching implementation (not requiring search/lookup).
type->unary_op() is just the right choice for this short of adding
standalone virtual method(s) to already big mp_obj_type_t structure.