Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
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, ")")
Exemple #4
0
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, ")")
Exemple #5
0
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) 
Exemple #6
0
def _scalar_generate_BoolOp(self, visitor, op, values, position): #@UnusedVariable
    visit = visitor.visit
    return cypy.join((value for value in values), visit(op))
Exemple #7
0
def _scalar_generate_Compare(self, visitor, left, ops, comparators, position): #@UnusedVariable
    visit = visitor.visit
    return ("(", 
            cypy.join(_yield_Compare_terms(visit, left, comparators, ops), 
                     " && "), 
           ")")
Exemple #8
0
 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")
Exemple #9
0
def _scalar_generate_BoolOp(self, visitor, op, values,
                            position):  #@UnusedVariable
    visit = visitor.visit
    return cypy.join((value for value in values), visit(op))
Exemple #10
0
def _scalar_generate_Compare(self, visitor, left, ops, comparators,
                             position):  #@UnusedVariable
    visit = visitor.visit
    return ("(",
            cypy.join(_yield_Compare_terms(visit, left, comparators, ops),
                      " && "), ")")
Exemple #11
0
 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")