Ejemplo n.º 1
0
    def test_refine_body_break(self):
        # def f(lst, x):
        #     for x in lst:
        #         if True:
        #            break
        #     return x
            
        with graph_factory():
            g = G(
              C(START_TICK, "lst", 1, "iterable"),
              T(1, tasks.IterTask()),
              C(1, "value", 2, "$iterator"),
              C(START_TICK, "x", 2, "x"),
              T(2, tasks.ForTask(False, False, G("body",
                  T(1, tasks.ConstTask(True)),
                  C(1, "value", 2, "$breaked"),
                  C(START_TICK, "$target",2 , "x"),
                  C(START_TICK, "$iterator", 2, "$iterator"),
                  T(2, tasks.ForTask(True, True, G("body"), G("else"))),
                  C(2, "x", FINAL_TICK, "x")
              ), G("else"))),
              C(2, "x", FINAL_TICK, "retval")
            )

            
        target = g.get_task(START_TICK + 2)
        target.refine(g, START_TICK + 2, {"$iterator":iter([1,2,3])})
        
        with graph_factory():
            expected = G(
              C(START_TICK, "lst", 1, "iterable"),
              T(1, tasks.IterTask()),
              C(1, "value", (2,1,2,2), "$iterator"),
              T((2,1,1), tasks.ConstTask(1)),
              T((2,1,2,1), tasks.ConstTask(True)),
              C((2,1,1), "value", (2,1,2,2), "x"),
              C((2,1,2,1), "value", (2,1,2,2), "$breaked"),
              T((2,1,2,2), tasks.ForTask(True, True, G("body",
                  T(1, tasks.ConstTask(True)),
                  C(1, "value", 2, "$breaked"),
                  C(START_TICK, "$target",2 , "x"),
                  C(START_TICK, "$iterator", 2, "$iterator"),
                  T(2, tasks.ForTask(True, True, G("body"), G("else"))),
                  C(2, "x", FINAL_TICK, "x")
              ), G("else"))),
              C((2,1,2,2), "x", FINAL_TICK, "retval")
            )
            
        utils.assert_graph_equal(expected, g)
Ejemplo n.º 2
0
 def test_refine_body_twice(self):
     # def f(lst, x):
     #     for x in lst:
     #         pass
     #     return x
         
     with graph_factory():
         g = G(
           C(START_TICK, "lst", 1, "iterable"),
           T(1, tasks.IterTask()),
           C(1, "value", 2, "$iterator"),
           C(START_TICK, "x", 2, "x"),
           T(2, tasks.ForTask(False, False, G("body",
               C(START_TICK, "$target",1 , "x"),
               C(START_TICK, "$iterator", 1, "$iterator"),
               T(1, tasks.ForTask(True, False, G("body"), G("else"))),
               C(1, "x", FINAL_TICK, "x")
           ), G("else"))),
           C(2, "x", FINAL_TICK, "retval")
         )
         
     it = iter([1,2,3])
     
     target_tick = START_TICK + 2
     target = g.get_task(target_tick)
     target.refine(g, target_tick, {"$iterator":it})
     
     target_tick = Tick.parse_tick((2,1,2,1))
     target = g.get_task(target_tick)
     target.refine(g, target_tick, {"$iterator":it})                
     
     with graph_factory():
         expected = G(
           C(START_TICK, "lst", 1, "iterable"),
           T(1, tasks.IterTask()),
           T((2,1,1), tasks.ConstTask(1)),
           T((2,2,1), tasks.ConstTask(2)),
           C(1, "value", (2,2,2,1), "$iterator"),
           C((2,2,1), "value", (2,2,2,1), "x"),
           T((2,2,2,1), tasks.ForTask(True, False, G("body",
               C(START_TICK, "$target",1 , "x"),
               C(START_TICK, "$iterator", 1, "$iterator"),
               T(1, tasks.ForTask(True, False, G("body"), G("else"))),
               C(1, "x", FINAL_TICK, "x")
           ), G("else"))),
           C((2,2,2,1), "x", FINAL_TICK, "retval")
         )
         
     utils.assert_graph_equal(expected, g)
Ejemplo n.º 3
0
    def test_while_break(self):
        def f(x):
            while x:
                if True:
                    break
            return x

        with graph_factory():
            expected = G(
                C(START_TICK, "x", 1, "$test"), C(START_TICK, "x", 1, "x"),
                T(
                    1,
                    tasks.WhileTask(
                        False, False,
                        G(
                            "body",
                            C(START_TICK, "x", 2, "$test"),
                            C(START_TICK, "x", 2, "x"),
                            T(1, tasks.ConstTask(True), {'quick': True}),
                            C(1, "value", 2, "$breaked"),
                            T(
                                2,
                                tasks.WhileTask(True, True, G("body"),
                                                G("else"))),
                        ), G("else"))), C(START_TICK, "x", FINAL_TICK,
                                          "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 4
0
    def test_while(self):
        def f(x):
            while x:
                pass
            return x

        with graph_factory():
            expected = G(
                C(START_TICK, "x", 1, "$test"), C(START_TICK, "x", 1, "x"),
                T(
                    1,
                    tasks.WhileTask(
                        False, False,
                        G(
                            "body",
                            C(START_TICK, "x", 1, "$test"),
                            C(START_TICK, "x", 1, "x"),
                            T(
                                1,
                                tasks.WhileTask(True, False, G("body"),
                                                G("else"))),
                        ), G("else"))), C(START_TICK, "x", FINAL_TICK,
                                          "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 5
0
    def test_for_break(self):
        def f(lst, x):
            for x in lst:
                if True:
                    break
            return x

        with graph_factory():
            expected = G(
                C(START_TICK, "lst", 1, "iterable"),
                T(1, tasks.IterTask(), {'quick': True}),
                C(1, "value", 2, "$iterator"), C(START_TICK, "x", 2, "x"),
                T(
                    2,
                    tasks.ForTask(
                        False, False,
                        G(
                            "body", T(1, tasks.ConstTask(True),
                                      {'quick': True}),
                            C(1, "value", 2, "$breaked"),
                            C(START_TICK, "$target", 2, "x"),
                            C(START_TICK, "$iterator", 2, "$iterator"),
                            T(2, tasks.ForTask(True, True, G("body"),
                                               G("else"))),
                            C(2, "x", FINAL_TICK, "x")), G("else"))),
                C(2, "x", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 6
0
    def test_for_break(self):
        
        def f(lst, x):
            for x in lst:
                if True:
                    break
            return x
            
        with graph_factory():
            expected = G(
              C(START_TICK, "lst", 1, "iterable"),
              T(1, tasks.IterTask(), {'quick':True}),
              C(1, "value", 2, "$iterator"),
              C(START_TICK, "x", 2, "x"),
              T(2, tasks.ForTask(False, False, G("body",
                  T(1, tasks.ConstTask(True), {'quick':True}),
                  C(1, "value", 2, "$breaked"),
                  C(START_TICK, "$target",2 , "x"),
                  C(START_TICK, "$iterator", 2, "$iterator"),
                  T(2, tasks.ForTask(True, True, G("body"), G("else"))),
                  C(2, "x", FINAL_TICK, "x")
              ), G("else"))),
              C(2, "x", FINAL_TICK, "retval")
            )

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 7
0
 def test_refine_body_twice(self):
     # def f(x):
     #     while x:
     #         pass
     #     return x
         
     with graph_factory():
         g = G(
           C(START_TICK, "x", 1, "$test"),
           C(START_TICK, "x", 1, "x"),
           T(1, tasks.WhileTask(False, False, G("body",
               C(START_TICK, "x", 1 , "$test"),
               C(START_TICK, "x", 1 , "x"),
               T(1, tasks.WhileTask(True, False, G("body"), G("else"))),
           ), G("else"))),
           C(START_TICK, "x", FINAL_TICK, "retval")
         )
         
         
     target = g.get_task(START_TICK + 1)
     target.refine(g, START_TICK + 1, {"$test":True})
     
     target = g.get_task(Tick.parse_tick((1,1,1)))
     target.refine(g, Tick.parse_tick((1,1,1)), {"$test":True})
     
     with graph_factory():
         expected = G(
           C(START_TICK, "x", (1,2,1), "$test"),
           C(START_TICK, "x", (1,2,1), "x"),
           T((1,2,1), tasks.WhileTask(True, False, G("body",
               C(START_TICK, "x", 1 , "$test"),
               C(START_TICK, "x", 1 , "x"),
               T(1, tasks.WhileTask(True, False, G("body"), G("else"))),
           ), G("else"))),
           C(START_TICK, "x", FINAL_TICK, "retval")
         )
         
         
     utils.assert_graph_equal(expected, g)
Ejemplo n.º 8
0
    def test_while(self):
        
        def f(x):
            while x:
                pass
            return x
            
        with graph_factory():
            expected = G(
              C(START_TICK, "x", 1, "$test"),
              C(START_TICK, "x", 1, "x"),
              T(1, tasks.WhileTask(False, False, G("body",
                  C(START_TICK, "x", 1 , "$test"),
                  C(START_TICK, "x", 1 , "x"),
                  T(1, tasks.WhileTask(True, False, G("body"), G("else"))),
              ), G("else"))),
              C(START_TICK, "x", FINAL_TICK, "retval")
            )

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 9
0
    def test_while_break(self):
        
        def f(x):
            while x:
                if True:
                    break
            return x
            
        with graph_factory():
            expected = G(
              C(START_TICK, "x", 1, "$test"),
              C(START_TICK, "x", 1, "x"),
              T(1, tasks.WhileTask(False, False, G("body",
                  C(START_TICK, "x", 2 , "$test"),
                  C(START_TICK, "x", 2 , "x"),
                  T(1, tasks.ConstTask(True), {'quick':True}),
                  C(1, "value", 2, "$breaked"),
                  T(2, tasks.WhileTask(True, True, G("body"), G("else"))),
              ), G("else"))),
              C(START_TICK, "x", FINAL_TICK, "retval")
            )

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)