Closed thautwarm closed 3 years ago
WIP:
import jit
@jit.parametric_struct
class JitClosure:
free : object
fptr : object
def __init__(self, free, fptr):
self.free = free
self.fptr = fptr
def __call__(self, *args):
return self.fptr(*self.free, *args)
# don't write
def f(x):
return lambda : x
# instead, use
def f(x):
JitClosure((1, ), lambda c: c)
# don't write
def f(x, y):
return lambda x, y, z: x + y + z
# instead, use
def f(x):
return JitClosure((1, 2), lambda x, y, z: x + y + z)
simple escape analysis can be done, say, if a variable is initialized in only one source code point.
closed for the favour of #8
so far it's hard to make closures efficient, because each free variable has to have top type. in lack of escape analysis to give better assumptions for the type of a free variable. this is not the core of dynjit though it contributes a lot to performance when the programs use high order functions.