per-method jit compiler
Irmen de Jong
irmen-NOSPAM- at xs4all.nl
Tue Apr 6 15:56:11 EDT 2010
On 6-4-2010 8:22, Luis M. González wrote:
> The above post gave me an idea (very naive, of couse).
> What if I write a simple decorator to figure out the types of every
> function, and then we use it as a base for a simple method-jit
> compiler for python?
> example:
> def typer(f):
> def wrap(*args):
> a = f.func_code.co_varnames
> b = [type(i) for i in args]
> return dict(zip(a,b))
> return wrap
> @typer
> def spam(a, b, c=3, d=4):
> pass
>>>> spam(8,'hello',9.9, 10)
>
> {'a':<type 'int'>, 'c':<type 'float'>, 'b':<type 'str'>, 'd':
> <type
> 'int'>}
> So by using this information, we record all the argument types used
> the first time each function/method is executed, and then we generate
> optimized code for them.
> From this point on, a guard should check if all arguments remain the
> same and, if so, the optimized code is run.
> Otherwise, just fall back to the interpreter.
> He! I have no idea how to implement it...
> Any guru out there?
> Luis
Isn't this what Psyco (http://psyco.sourceforge.net/) does?
-irmen
More information about the Python-list
mailing list