Esempio n. 1
0
  def visit_GeneratorExp(self, node):
    body = ast.Expr(value=ast.Yield(value=node.elt), loc=node.loc)
    for comp_node in reversed(node.generators):
      for if_node in reversed(comp_node.ifs):
        body = ast.If(test=if_node, body=[body], orelse=[], loc=node.loc)  # pylint: disable=redefined-variable-type
      body = ast.For(target=comp_node.target, iter=comp_node.iter,
                     body=[body], orelse=[], loc=node.loc)

    args = ast.arguments(args=[], vararg=None, kwarg=None, defaults=[])
    node = ast.FunctionDef(name='<generator>', args=args, body=[body])
    gen_func = self.visit_function_inline(node)
    result = self.block.alloc_temp()
    self.writer.write_checked_call2(
        result, '{}.Call(πF, nil, nil)', gen_func.expr)
    return result
Esempio n. 2
0
 def visit_Lambda(self, node):
   ret = ast.Return(value=node.body, loc=node.loc)
   func_node = ast.FunctionDef(
       name='<lambda>', args=node.args, body=[ret])
   return self.visit_function_inline(func_node)