Exemple #1
0
        def r_compile():
            jit_func = Aware.f(self, id(start_func))
            bc = Bytecode()

            bc.append(PyInstr(InstrNames.LOAD_CONST, jit_func))
            bc.extend([load_arg(each, cellvars, lineno) for each in argnames])
            bc.extend([
                PyInstr(InstrNames.CALL_FUNCTION, len(argnames)),
                PyInstr(InstrNames.RETURN_VALUE)
            ])
            bc._copy_attr_from(code)
            start_func.__code__ = bc.to_code()
            start_func.__jit__ = jit_func
            return jit_func
Exemple #2
0
    def func_info(cls, func: types.FunctionType) -> types.FunctionType:
        names = func.__code__.co_names
        code = Bytecode.from_code(func.__code__)
        codeinfo = cls.code_info(code)

        def r_compile():
            jit_func = Aware.f(self)
            print("jit_func", type(jit_func))
            bc = Bytecode()

            bc.append(PyInstr(InstrNames.LOAD_CONST, jit_func))
            bc.extend([load_arg(each, cellvars, lineno) for each in argnames])
            bc.extend([
                PyInstr(InstrNames.CALL_FUNCTION, len(argnames)),
                PyInstr(InstrNames.RETURN_VALUE)
            ])
            bc._copy_attr_from(code)
            start_func.__code__ = bc.to_code()
            start_func.__jit__ = jit_func
            return jit_func

        start_func = copy_func(func)
        start_func_code = Bytecode()
        lineno = code.first_lineno
        argnames = code.argnames
        start_func_code.argnames = argnames
        cellvars = code.cellvars
        start_func_code.extend([
            PyInstr(InstrNames.LOAD_CONST, r_compile, lineno=lineno),
            PyInstr(InstrNames.CALL_FUNCTION, 0, lineno=lineno),
            *(load_arg(each, cellvars, lineno) for each in argnames),
            PyInstr(InstrNames.CALL_FUNCTION, len(argnames), lineno=lineno),
            PyInstr(InstrNames.RETURN_VALUE, lineno=lineno)
        ])
        start_func_code._copy_attr_from(code)
        self = PyFuncInfo(func.__name__, func.__module__, func.__defaults__,
                          func.__kwdefaults__, func.__closure__,
                          func.__globals__, codeinfo, func, {}, names)
        start_func.__code__ = start_func_code.to_code()
        start_func.__func_info__ = self
        start_func.__compile__ = r_compile
        start_func.__jit__ = None
        return start_func
Exemple #3
0
def load_arg(x, cellvars, lineno):
    if x in cellvars:
        return PyInstr(InstrNames.LOAD_DEREF, CellVar(x), lineno=lineno)

    return PyInstr(InstrNames.LOAD_FAST, x, lineno=lineno)