def create_numba_function(self, node, translator): closure_scope = self.ast.cur_scope if closure_scope is None: closure_scope = nodes.NULL scope_type = void.pointer() else: assert node.func_def.args.args[0].variable.type scope_type = closure_scope.type node.wrapper_func, node.wrapper_lfunc, methoddef = ( translator.build_wrapper_function(get_lfunc=True)) # Keep methoddef alive # assert methoddef in node.py_func.live_objects modname = self.module_name self.keep_alive(modname) # Create function signature with closure scope at runtime create_numbafunc_signature = node.type( void.pointer(), # PyMethodDef *ml object_, # PyObject *module void.pointer(), # PyObject *code scope_type, # PyObject *closure void.pointer(), # void *native_func object_, # PyObject *native_signature object_, # PyObject *keep_alive ) # Create function with closure scope at runtime create_numbafunc = nodes.ptrfromint( extension_types.NumbaFunction_NewEx_pointer, create_numbafunc_signature.pointer()) methoddef_p = ctypes.cast(ctypes.byref(methoddef), ctypes.c_void_p).value args = [ nodes.const(methoddef_p, void.pointer()), nodes.const(modname, object_), nodes.NULL, closure_scope, nodes.const(node.lfunc_pointer, void.pointer()), nodes.const(node.type.signature, object_), nodes.NULL, # nodes.const(node.py_func, object_), ] func_call = nodes.NativeFunctionCallNode( signature=create_numbafunc_signature, function_node=create_numbafunc, args=args) result = func_call #stats = [nodes.inject_print(nodes.const("calling...", c_string_type)), # result] #result = ast.Suite(body=stats) result = self.visit(result) return result
def visit_ConstNode(self, node): constant = node.pyval if node.type.is_complex: real = nodes.ConstNode(constant.real, node.type.base_type) imag = nodes.ConstNode(constant.imag, node.type.base_type) node = nodes.ComplexNode(real, imag) elif node.type.is_pointer: addr_int = constnodes.get_pointer_address(constant, node.type) node = nodes.ptrfromint(addr_int, node.type) elif node.type.is_object and not nodes.is_null_constant(constant): node = nodes.ObjectInjectNode(constant, node.type) return node
def create_numba_function(self, node, p): closure_scope = self.ast.cur_scope if closure_scope is None: closure_scope = nodes.NULL scope_type = void.pointer() else: assert node.func_def.args.args[0].variable.type scope_type = closure_scope.type node.wrapper_func, node.wrapper_lfunc, methoddef = ( p.translator.build_wrapper_function(get_lfunc=True)) # Keep methoddef alive assert methoddef in node.py_func.live_objects modname = self.func.__module__ node.py_func.live_objects.append(modname) # Create function with closure scope at runtime create_numbafunc_signature = node.type( void.pointer(), # PyMethodDef *ml object_, # PyObject *module void.pointer(), # PyObject *code scope_type, # PyObject *closure void.pointer(), # void *native_func object_, # PyObject *native_signature object_, # PyObject *keep_alive ) create_numbafunc = nodes.ptrfromint( extension_types.NumbaFunction_NewEx_pointer, create_numbafunc_signature.pointer()) methoddef_p = ctypes.cast(ctypes.byref(methoddef), ctypes.c_void_p).value args = [ nodes.const(methoddef_p, void.pointer()), nodes.const(modname, object_), nodes.NULL, closure_scope, nodes.const(node.lfunc_pointer, void.pointer()), nodes.const(node.type.signature, object_), nodes.const(node.py_func, object_), ] func_call = nodes.NativeFunctionCallNode( signature=create_numbafunc_signature, function_node=create_numbafunc, args=args) # Assign closure to its name func_name = node.func_def.name dst = self._load_name(func_name, self.symtab[func_name].is_cellvar) dst.ctx = ast.Store() result = ast.Assign(targets=[dst], value=func_call) #stats = [nodes.inject_print(nodes.const("calling...", c_string_type)), # result] #result = ast.Suite(body=stats) result = self.visit(result) return result
def create_numba_function(self, node, func_env): from numba.codegen import llvmwrapper closure_scope = self.ast.cur_scope if closure_scope is None: closure_scope = nodes.NULL scope_type = void.pointer() else: assert node.func_def.args.args[0].variable.type scope_type = closure_scope.type self.env.translation.push_env(func_env) try: node.wrapper_func, node.wrapper_lfunc, methoddef = ( llvmwrapper.build_wrapper_function(self.env)) finally: self.env.translation.pop() # Keep methoddef alive # assert methoddef in node.py_func.live_objects modname = self.module_name self.keep_alive(modname) # Create function signature with closure scope at runtime create_numbafunc_signature = node.type( void.pointer(), # PyMethodDef *ml object_, # PyObject *module void.pointer(), # PyObject *code scope_type, # PyObject *closure void.pointer(), # void *native_func object_, # PyObject *native_signature object_, # PyObject *keep_alive ) # Create function with closure scope at runtime create_numbafunc = nodes.ptrfromint( numbawrapper.NumbaFunction_NewEx_pointer, create_numbafunc_signature.pointer()) methoddef_p = ctypes.cast(ctypes.byref(methoddef), ctypes.c_void_p).value args = [ nodes.const(methoddef_p, void.pointer()), nodes.const(modname, object_), nodes.NULL, closure_scope, nodes.const(node.lfunc_pointer, void.pointer()), nodes.const(node.type.signature, object_), nodes.NULL, # nodes.const(node.py_func, object_), ] func_call = nodes.NativeFunctionCallNode( signature=create_numbafunc_signature, function_node=create_numbafunc, args=args) result = func_call #stats = [nodes.inject_print(nodes.const("calling...", c_string_type)), # result] #result = ast.Suite(body=stats) result = self.visit(result) return result