def lazy_function(f): return thunk.fromvalue( FunctionType( LazyTransformer().visit(f.__code__), f.__globals__, f.__name__, tuple(map(thunk.fromvalue, f.__defaults__ or ())), f.__closure__, ), )
def __call__(self, f): return thunk.fromvalue( FunctionType( self.transform(Code.from_pycode(f.__code__)).to_pycode(), f.__globals__, f.__name__, tuple(map(thunk.fromvalue, f.__defaults__ or ())), f.__closure__, ), )
def __call__(self, f): return thunk.fromvalue( FunctionType( self.visit(f.__code__), f.__globals__, f.__name__, tuple(map(thunk.fromvalue, f.__defaults__ or ())), f.__closure__, ), )
def _build_set(self, instr): # TOS v_0 # ... # TOSn v_n yield instructions.BUILD_TUPLE(instr.arg).steal(instr) # TOS (v_0, ..., v_n) yield instructions.LOAD_CONST(thunk.fromvalue(set)) # TOS thunk.fromvalue(set) # TOS1 (v_0, ..., v_n) yield instructions.ROT_TWO() # TOS (v_0, ..., v_n) # TOS1 thunk.fromvalue(set) yield instructions.CALL_FUNCTION(1)
def visit_const(self, const): const = super().visit_const(const) if not isinstance(const, CodeType): const = thunk.fromvalue(const) return const
def transform_consts(self, consts): return tuple( const if isinstance(const, CodeType) else thunk.fromvalue(const) for const in super().transform_consts(consts) )
def visit_consts(self, consts): return tuple( const if isinstance(const, CodeType) else thunk.fromvalue(const) for const in super().visit_consts(consts) )