On Wed, Apr 22, 2009 at 3:00 PM, Antonio Cuni <[email protected]> wrote: > Luke Kenneth Casson Leighton wrote: > >> advanced features like metaclass support would be hard - this was >> proven to be incorrect, by writing an implementation of "type()" for >> pyjamas in under 24 hours and about 100 lines of javascript. > > [cut] > > in PyPy, typeobject.py and typetype.py contain roughly 1000 lines of RPython > code (to which we must add the related logic which is somewhere else). > In CPython, typeobject.c contains about 6000 lines of C. > > Honestly, I doubt a that 100 lines of javascript code can make a python > compliant type().
http://pyjamas.svn.sourceforge.net/viewvc/pyjamas/trunk/library/_pyjs.js?view=markup see pyjs_type(). it's 58 lines. 89 if you include pyjs_extend() as well. the regression tests are passed, successfully, and the regression tests are also run by the standard python interpreter as well. all i did was copy the lines of code that are auto-generated by pyjs.py (resulting in hard-coded javascript) and put them into that function (pyjs_type) as a "generic" function. it's close enough so that the "hard-coded class generation" could now actually be replaced by a call to pyjs_type() - it's just that pyjs.py is a bit messy so i'm reluctant to do it right now. it may well be the case that there is a lot of functionality of this implementation of type() that i'm missing, that i don't know about, and would welcome comments about it, letting me know what i've missed. for example, i always used to use "if type(clsinstance) == SomeClass" until i was slapped on the wrist and told to use isinstance, but the code i have there in pyjs_type i _know_ won't support that. l. _______________________________________________ [email protected] http://codespeak.net/mailman/listinfo/pypy-dev
