示例#1
0
    def for_stmt(self, index, sequence, body, else_body=None):
        counter = self.frame.gettemp('int')
        item = self.factory.makePyObject(self.frame.gettemp("PyObject"))
        seq = self.frame.gettemp("PyObject")

        init = []
        init.append(jast.Set(counter, jast.IntegerConstant(0)))
        init.append(jast.Set(seq, self.visit(sequence).asAny()))

        counter_inc = jast.PostOperation(counter, '++')

        test = jast.Set(item.asAny(),
                        jast.Invoke(seq, "__finditem__", [counter_inc]))
        test = jast.Operation('!=', test, jast.Identifier('null'))

        suite = []
        suite.append(self.set(index, item))
        suite.append(self.visit(body))
        suite = jast.Block(suite)

        if else_body is not None:
            else_body = jast.Block(self.visit(else_body))
            wtmp = self.frame.gettemp('boolean')
            ret = [init, jast.WhileElse(test, suite, else_body, wtmp)]
            self.frame.freetemp(wtmp)
            return ret
        else:
            return [init, jast.While(test, suite)]
示例#2
0
 def visitWhile(self, node):
     stest = self.visit(node.test).nonzero()
     sbody = jast.Block(self.suite(node.body))
     if node.orelse is not None:
         orelse = jast.Block(self.suite(node.orelse))
         wtmp = self.frame.gettemp('boolean')
         ret = jast.WhileElse(stest, sbody, orelse, wtmp)
         self.frame.freetemp(wtmp)
         return ret
     else:
         return jast.While(stest, sbody)
示例#3
0
 def while_stmt(self, test, body, else_body=None):
     stest = self.visit(test).nonzero()
     sbody = jast.Block(self.visit(body))
     if else_body is not None:
         else_body = jast.Block(self.visit(else_body))
         wtmp = self.frame.gettemp('boolean')
         ret = jast.WhileElse(stest, sbody, else_body, wtmp)
         self.frame.freetemp(wtmp)
         return ret
     else:
         return jast.While(stest, sbody)
示例#4
0
    def visitFor(self, node):
        iter = self.frame.gettemp('PyObject')
        item = self.factory.makePyObject(self.frame.gettemp("PyObject"))
        seq = self.visit(node.iter).asAny() 

        init = []
        init.append(jast.Set(iter, jast.Invoke(seq, "__iter__", [])))

        test = jast.Set(item.asAny(), jast.Invoke(iter, "__iternext__", []))
        test = jast.Operation('!=', test, jast.Identifier('null'))

        suite = []
        suite.append(self.set(node.target, item))
        suite.append(self.suite(node.body))
        suite = jast.Block(suite)

        if node.orelse is not None:
            orelse = jast.Block(self.suite(node.orelse))
            wtmp = self.frame.gettemp('boolean')
            ret = [init, jast.WhileElse(test, suite, orelse, wtmp)]
            self.frame.freetemp(wtmp)
            return ret
        else:
            return [init, jast.While(test, suite)]