Beispiel #1
0
 def visitIfExp(self, n, needs_to_be_simple):
     (test, test_ss) = self.dispatch(n.test, True)
     (then, then_ss) = self.dispatch(n.then, True)
     (else_, else_ss) = self.dispatch(n.else_, True)        
     tmp = generate_name('tmp')
     return (Name(tmp), test_ss + [If([(test, Stmt(then_ss + [make_assign(tmp, then)]))],
                                      Stmt(else_ss + [make_assign(tmp, else_)]))])
Beispiel #2
0
 def visitSetSubscript(self, n, needs_to_be_simple):
     (c_result, c_ss) = self.dispatch(n.container, True)
     (k_result, k_ss) = self.dispatch(n.key, True)
     (v_result, v_ss) = self.dispatch(n.val, True)
     tmp = generate_name('tmp')
     rhs = SetSubscript(c_result, k_result, v_result)
     return (Name(tmp), c_ss + k_ss + v_ss + [make_assign(tmp, rhs)])
Beispiel #3
0
 def visitSubscript(self, n, needs_to_be_simple):
     (c_result, c_ss) = self.dispatch(n.expr, True)
     (k_result, k_ss) = self.dispatch(n.subs[0], True)
     rhs = Subscript(expr=c_result, flags=n.flags, subs=[k_result])
     if needs_to_be_simple:
         tmp = generate_name('tmp')
         return (Name(tmp), c_ss + k_ss + [make_assign(tmp, rhs)])
     else:
         return (rhs, c_ss + k_ss)            
Beispiel #4
0
 def visitCompare(self, n, needs_to_be_simple):
     (left,ss1) = self.dispatch(n.expr, True)
     op = n.ops[0][0]
     (right,ss2) = self.dispatch(n.ops[0][1], True)
     compare = Compare(expr=left, ops=[(op,right)])
     if needs_to_be_simple:
         tmp = generate_name('tmp')
         return (Name(tmp), ss1 + ss2 + [make_assign(tmp, compare)])
     else:
         return (compare, ss1 + ss2)            
Beispiel #5
0
    def visitIndirectCallFunc(self, n, needs_to_be_simple):
        (node, ss1) = self.dispatch(n.node, True)
        args_sss = [self.dispatch(arg, True) for arg in n.args]
        args = [arg for (arg,ss) in args_sss]
        ss2 = reduce(lambda a,b: a + b, [ss for (arg,ss) in args_sss], [])

        if needs_to_be_simple:
            tmp = generate_name('tmp')
            return (Name(tmp), ss1 + ss2 + [make_assign(tmp, IndirectCallFunc(node, args))])
        else:
            return (IndirectCallFunc(node, args), ss1 + ss2)
Beispiel #6
0
 def visitCallFunc(self, n, needs_to_be_simple):
     if isinstance(n.node, FunName):
         args_sss = [self.dispatch(arg, True) for arg in n.args]
         args = [arg for (arg,ss) in args_sss]
         ss = reduce(lambda a,b: a + b, [ss for (arg,ss) in args_sss], [])
         if needs_to_be_simple:
             tmp = generate_name('tmp')
             return (Name(tmp), ss + [make_assign(tmp, CallFunc(n.node, args))])
         else:
             return (CallFunc(n.node, args), ss)
     else:
         raise Exception('flatten3: only calls to named functions allowed, not %s' % repr(n.node))
Beispiel #7
0
 def visitLet(self, n, needs_to_be_simple):
     (rhs_result, rhs_ss) = self.dispatch(n.rhs, False)
     (body_result, body_ss) = self.dispatch(n.body, True)
     return (body_result, rhs_ss + [make_assign(n.var, rhs_result)] + body_ss)
Beispiel #8
0
 def visitProjectTo(self, n, needs_to_be_simple):
     (arg, ss) = self.dispatch(n.arg, True)
     tmp = generate_name('tmp')
     rhs = ProjectTo(n.typ, arg)
     return (Name(tmp), ss + [make_assign(tmp, rhs)])
Beispiel #9
0
 def visitGetTag(self, n, needs_to_be_simple):
     (e, ss) = self.dispatch(n.arg, True)
     tmp = generate_name('tmp')
     rhs = GetTag(e)
     return (Name(tmp), ss + [make_assign(tmp, rhs)])