def generate_program_item(self, context): g = cg.CG() g.append(cypy.join(cypy.cons(context.modifiers, (context.return_type.name,)), " ")) name = self._generate_name(context) g.append((" ", name, "(")) g.append(cypy.join(self._yield_arg_str(context), ", ")) g.append((") {\n", context.tab)) g.append((cypy.join(context.declarations, "\n"), "\n\n")) g.append(context.stmts) g.append((context.untab, "\n}\n")) return clq.ProgramItem(name, g.code)
def in_step_kernel(self, g): # TODO: Get rid of these once globals work constants = self.constants constants['get_global_id'] = clqcl.get_global_id constants['get_global_size'] = clqcl.get_global_size constants['min'] = clqcl.min constants['atom_add'] = clqcl.atom_add constants['atom_inc'] = clqcl.atom_inc constants['log'] = clqcl.log "def step_fn(" >> g py.join(py.cons(("timestep", "realization_start"), self.constants.iterkeys()), ",\n ") >> g ("):\n", g.tab) >> g self.trigger_staged_cg_hook("step_kernel_body", g)
def _builtin_fn_generate_Call(self, visitor, func, args): #@UnusedVariable builtin = self.builtin # extension inference requires_extensions = builtin.requires_extensions if requires_extensions is not None: resolve_type = visitor._resolve_type arg_types = (resolve_type(arg.unresolved_type) for arg in args) add_program_item = visitor._add_program_item for extension in requires_extensions(*arg_types): add_program_item(ExtensionItem(extension)) visit = visitor.visit all_args = cypy.join((visit(arg) for arg in args), ", ") return (builtin.name, "(", all_args, ")")
def _generic_generate_Call(context, node): arg_types = tuple(arg.unresolved_type.resolve(context) for arg in node.args) args = tuple(context.visit(arg) for i, arg in enumerate(node.args) if not isinstance(arg_types[i], VirtualType)) func = context.visit(node.func) code = (func.code, "(", cypy.join((arg.code for arg in args), ", "), ")") return astx.copy_node(node, args=args, func=func, code=code)
def _scalar_generate_BoolOp(self, visitor, op, values, position): #@UnusedVariable visit = visitor.visit return cypy.join((value for value in values), visit(op))
def _scalar_generate_Compare(self, visitor, left, ops, comparators, position): #@UnusedVariable visit = visitor.visit return ("(", cypy.join(_yield_Compare_terms(visit, left, comparators, ops), " && "), ")")
def _visit_body(self, body): docstring = self._docstring = self._determine_docstring(body) if docstring is not None: body = body[1:] return cypy.join((self.visit(stmt) for stmt in body), "\n")