per-method jit compiler

  • Thread starter Luis M. González
  • Start date
L

Luis M. González

On 4 abr, 00:09, Steven D'Aprano <st...@REMOVE-THIS-

- Ocultar texto de la cita -
cybersource.com.au said:
... pass
...>>> spam.__code__.co_varnames
('a', 'b', 'c', 'd')
The hardest part is having the function know its own name.
I see that you are already using the inspect module. That almost
certainly is the correct approach. I'd be surprised if inspect is too
heavyweight, but if it is, you can pull out the bits you need into your
own function.


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
{'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
 
I

Irmen de Jong

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
{'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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top