Re: per-method jit compiler

2010-04-06 Thread Irmen de Jong

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':, 'c':, 'b':, 'd':
}
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


--
http://mail.python.org/mailman/listinfo/python-list


Re: per-method jit compiler

2010-04-06 Thread Florian Ludwig
On Mon, 2010-04-05 at 22:45 -0700, 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? 
I think its what done before by psyco:
http://psyco.sourceforge.net/

No need for a decorator though.

-- 
Florian Ludwig 

-- 
http://mail.python.org/mailman/listinfo/python-list


per-method jit compiler

2010-04-05 Thread Luis M . González
On 4 abr, 00:09, Steven D'Aprano  wrote:
> On Sat, 03 Apr 2010 22:58:43 +, kj wrote:
> > Suppose I have a function with the following signature:
> > def spam(x, y, z):
> > # etc.
> > Is there a way to refer, within the function, to all its arguments as a
> > single list?  (I.e. I'm looking for Python's equivalent of Perl's @_
> > variable.)
> Does this help?
> >>> def spam(a, b, c=3, d=4):
> ... 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.
> --
> Steven


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': , 'c': , 'b': , 'd':
}
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
-- 
http://mail.python.org/mailman/listinfo/python-list


per-method jit compiler

2010-04-05 Thread Luis M . González
On 4 abr, 00:09, Steven D'Aprano  wrote:
> On Sat, 03 Apr 2010 22:58:43 +, kj wrote:
> > Suppose I have a function with the following signature:
>
> > def spam(x, y, z):
> >     # etc.
>
> > Is there a way to refer, within the function, to all its arguments as a
> > single list?  (I.e. I'm looking for Python's equivalent of Perl's @_
> > variable.)
>
> Does this help?
>
> >>> def spam(a, b, c=3, d=4):
>
> ...     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.
>
> --
> Steven

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': , 'c': , 'b': , 'd': }

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
-- 
http://mail.python.org/mailman/listinfo/python-list