Esempio n. 1
0
def compileCodeObjects(filename, codeobjs):
    if len(codeobjs) == 0:
        stmts = []
    else:
        stmts = [ast.For(ast.AssName('[--codeobj--]', 'OP_ASSIGN'),
                         ast.Const(codeobjs),
                         ast.Stmt([ast.Exec(ast.Name('[--codeobj--]'),
                                            None, None)]),
                         None),
                 ast.AssName('[--codeobj--]', 'OP_DELETE')]

    module = ast.Module(None, ast.Stmt(stmts))
    compiler.misc.set_filename(filename, module)
    return pycodegen.ModuleCodeGenerator(module).getCode()
Esempio n. 2
0
    def _for(self, place, lst, body, **kw):
        assertResult(lst, "iterate over")

        # ensure topy in lexical order

        pl = compilePlace(place)
        l = topy(lst)
        bod = block(body, False)

        _else = kw.get('else')
        if _else:
            elseblock = block(_else, False)
        else:
            elseblock = None

        return ast.For(pl, l, bod, elseblock)
Esempio n. 3
0
 def p_for(self, p):
     """loop : FOR '(' assignment ';' expression ';' assignment ')' statement
             | FOR '(' assignment ';' expression ';' assignment ')' block"""
     p[0] = ast.For(p[3], p[5], p[7], p[9])
Esempio n. 4
0
 def _do_ForStatement(self, node):
     assign = self.transform_assign(node.Left)
     list = self.transform(node.List)
     body = self.transform_suite(node.Body)
     else_ = self.transform_suite(node.ElseStatement)
     return ast.For(assign, list, body, else_)
Esempio n. 5
0
def p_for_stmt(p):  # not very sure if 'test' is correct TODO
    """for_stmt :   FOR NAME IN test COLON suite
    """
    p[0] = ast.For(p[2], p[4], p[6], None)