def visit_FunctionDef(self, node): # can't nest functions if self._in_function: raise InvalidOperationError( "Nested function definitions are not supported.", node) self._in_function = True # do all the work self.return_type = None args = self.visit(node.args) body = [ self.visit(stmt) for stmt in node.body ] if self.return_type is None: self.return_type = VoidURT(node) # return a copy of the root node with all the information as # attributes return astx.copy_node(node, name=node.name, args=args, body=body, decorator_list=[], return_type=self.return_type, all_variables=cypy.frozendict(self.all_variables), arguments=cypy.frozendict(self.arguments), local_variables=cypy.frozendict(self.local_variables), free_variables=cypy.frozendict(self.free_variables) )
def _all_constants(self): # All constants (provided constants + free variable constants). constants = self.constants globals = self.globals return cypy.frozendict(cypy.cons( constants.iteritems(), ((name, globals[name]) for name in self.free_variables if name not in constants) ))
def _all_constants(self): # All constants (provided constants + free variable constants). constants = self.constants globals = self.globals return cypy.frozendict( cypy.cons( constants.iteritems(), ((name, globals[name]) for name in self.free_variables if name not in constants)))
def visit_FunctionDef(self, n): if self.in_function: raise NotImplementedError( "Inner concrete_fn definitions are not supported.") self.in_function = True args = self.visit(n.args) body = [self.visit(stmt) for stmt in n.body] return_type = self.return_type if return_type is None: return_type = cl.cl_void return astx.copy_node( n, name=n.name, args=args, body=body, return_type=return_type, all_variables=cypy.frozendict(self.all_variables), argument_variables=cypy.frozendict(self.argument_variables), local_variables=cypy.frozendict(self.local_variables), free_variables=cypy.frozendict(self.free_variables))
def visit_FunctionDef(self, n): if self.in_function: raise NotImplementedError( "Inner concrete_fn definitions are not supported.") self.in_function = True args = self.visit(n.args) body = [ self.visit(stmt) for stmt in n.body ] return_type = self.return_type if return_type is None: return_type = cl.cl_void return astx.copy_node(n, name=n.name, args=args, body=body, return_type=return_type, all_variables=cypy.frozendict(self.all_variables), argument_variables=cypy.frozendict(self.argument_variables), local_variables=cypy.frozendict(self.local_variables), free_variables=cypy.frozendict(self.free_variables) )
def __init__(self, generic_fn, explicit_arg_names, explicit_arg_types, constants): self.generic_fn = generic_fn self.explicit_arg_names = explicit_arg_names self.explicit_arg_types = explicit_arg_types self.explicit_arg_map = cypy.frozendict(zip(explicit_arg_names, explicit_arg_types)) self.constants = constants self.local_variables = dict(generic_fn.annotated_ast.local_variables) self.all_variables = generic_fn.all_variables self.implicit_args = [ ] self.implicit_args_map = { } self._resolving_name = None # a list of program items needed by this concrete function self.program_items = [ ]
def __init__(self, generic_fn, explicit_arg_names, explicit_arg_types, constants): self.generic_fn = generic_fn self.explicit_arg_names = explicit_arg_names self.explicit_arg_types = explicit_arg_types self.explicit_arg_map = cypy.frozendict( zip(explicit_arg_names, explicit_arg_types)) self.constants = constants self.local_variables = dict(generic_fn.annotated_ast.local_variables) self.all_variables = generic_fn.all_variables self.implicit_args = [] self.implicit_args_map = {} self._resolving_name = None # a list of program items needed by this concrete function self.program_items = []
def constants(self, constants): #@DuplicatedSignature if hasattr(constants, "__setitem__"): constants = cypy.frozendict(constants) self._constants = constants
def __init__(self, generic_fn, arg_types, backend): self.generic_fn = generic_fn self.arg_types = arg_types self.backend = backend self.arg_map = cypy.frozendict(zip(generic_fn.arg_names, arg_types))