예제 #1
0
    def __init__(self, env, func_def, closure_type, outer_py_func, **kwargs):
        super(ClosureNode, self).__init__(**kwargs)
        self.func_def = func_def
        self.type = closure_type
        self.outer_py_func = outer_py_func
        self.name = self.func_def.name

        func_env = env.translation.get_env(func_def)
        self.need_numba_func = not func_env or func_env.need_closure_wrapper
        self.lfunc = None
        self.wrapper_func = None
        self.wrapper_lfunc = None
        self.lfunc_pointer = None

        # FunctionEnvironment after type inference
        self.func_env = None
        # self.type_inferred_ast = None
        # self.symtab = None

        from numba import pipeline
        self.locals = pipeline.get_locals(func_def, None)

        # The Python extension type that must be instantiated to hold cellvars
        # self.scope_type = None
        self.ext_type = None
        self.need_closure_scope = False
예제 #2
0
    def __init__(self, env, func_def, closure_type, outer_py_func, **kwargs):
        super(ClosureNode, self).__init__(**kwargs)
        self.func_def = func_def
        self.type = closure_type
        self.outer_py_func = outer_py_func
        self.name = self.func_def.name

        func_env = env.translation.get_env(func_def)
        self.need_numba_func = not func_env or func_env.need_closure_wrapper
        self.lfunc = None
        self.wrapper_func = None
        self.wrapper_lfunc = None
        self.lfunc_pointer = None

        # FunctionEnvironment after type inference
        self.func_env = None
        # self.type_inferred_ast = None
        # self.symtab = None

        from numba import pipeline
        self.locals = pipeline.get_locals(func_def, None)

        # The Python extension type that must be instantiated to hold cellvars
        # self.scope_type = None
        self.ext_type = None
        self.need_closure_scope = False
예제 #3
0
    def __init__(self, func_def, closure_type, outer_py_func, **kwargs):
        super(ClosureNode, self).__init__(**kwargs)
        self.func_def = func_def
        self.type = closure_type
        self.outer_py_func = outer_py_func
        self.name = self.func_def.name

        self.need_numba_func = getattr(func_def, "need_closure_wrapper", True)
        self.lfunc = None
        self.wrapper_func = None
        self.wrapper_lfunc = None
        self.lfunc_pointer = None

        # ast and symtab after type inference
        self.type_inferred_ast = None
        self.symtab = None

        from numba import pipeline

        self.locals = pipeline.get_locals(func_def, None)

        # The Python extension type that must be instantiated to hold cellvars
        # self.scope_type = None
        self.ext_type = None
        self.need_closure_scope = False
예제 #4
0
파일: visitors.py 프로젝트: chiehwen/numba
def determine_variable_status(context, ast, locals_dict):
    """
    Determine what category referenced and assignment variables fall in:

        - local variables
        - free variables
        - cell variables
    """
    from numba import pipeline

    if hasattr(ast, 'variable_status_tuple'):
        return ast.variable_status_tuple

    v = VariableFindingVisitor()
    v.visit(ast)

    locals = set(v.assigned)
    locals.update(locals_dict)
    locals.update(arg.id for arg in ast.args.args)
    locals.update(func_def.name for func_def in v.func_defs)

    freevars = set(v.referenced) - locals
    cellvars = set()

    # Compute cell variables
    for func_def in v.func_defs:
        inner_locals_dict = pipeline.get_locals(func_def, None)

        inner_locals, inner_cellvars, inner_freevars = \
                            determine_variable_status(context, func_def,
                                                      inner_locals_dict)
        cellvars.update(locals.intersection(inner_freevars))

#    print ast.name, "locals", pformat(locals),      \
#                    "cellvars", pformat(cellvars),  \
#                    "freevars", pformat(freevars),  \
#                    "locals_dict", pformat(locals_dict)
#    print ast.name, "locals", pformat(locals)

    # Cache state
    ast.variable_status_tuple = locals, cellvars, freevars
    return locals, cellvars, freevars