예제 #1
0
def test_indirect_sometimes_residual_pure_but_fixed_red_call():
    def h1(x):
        return x-2
    def h2(x):
        return x*4
    l = [h1, h2]
    def f(n, x):
        frozenl = hint(l, deepfreeze=True)
        h = frozenl[n&1]
        z = h(x)
        hint(z, concrete=True)
        return z

    P = StopAtXPolicy(h1)
    P.oopspec = True
    P.entrypoint_returns_red = False
    hs, hannotator = hannotate(f, [int, int], policy=P, annotator=True)
    assert hs.is_green()

    #tsgraph = graphof(hannotator.translator, h2)
    #hs = hannotator.binding(tsgraph.getargs()[0])
    #assert hs.is_green()

    tsgraph = graphof(hannotator.translator, f)
    hs = hannotator.binding(tsgraph.getargs()[0])
    assert hs.is_green()
    hs = hannotator.binding(tsgraph.getargs()[1])
    assert hs.is_green()
예제 #2
0
    def test_indirect_sometimes_residual_pure_but_fixed_red_call(self, setup=setup_for_indirect_call):
        def h1(x):
            return x-2
        def h2(x):
            return x*4
        call, lst = setup(h1, h2)
        def f(n, x):
            frozenl = hint(lst, deepfreeze=True)
            h = frozenl[n&1]
            z = call(h, x)
            hint(z, concrete=True)
            return z

        P = StopAtXPolicy(h1)
        P.oopspec = True
        P.entrypoint_returns_red = False
        hs, hannotator = self.hannotate(f, [int, int], policy=P, annotator=True)
        assert hs.is_green()

        #tsgraph = graphof(hannotator.translator, h2)
        #hs = hannotator.binding(tsgraph.getargs()[0])
        #assert hs.is_green()

        tsgraph = graphof(hannotator.translator, f)
        hs = hannotator.binding(tsgraph.getargs()[0])
        assert hs.is_green()
        hs = hannotator.binding(tsgraph.getargs()[1])
        assert hs.is_green()
예제 #3
0
def test_indirect_sometimes_residual_pure_red_call():
    def h1(x):
        return x-2
    def h2(x):
        return x*4
    l = [h1, h2]
    def f(n, x):
        frozenl = hint(l, deepfreeze=True)
        h = frozenl[n&1]
        return h(x)

    P = StopAtXPolicy(h1)
    P.oopspec = True
    P.entrypoint_returns_red = False
    hs, hannotator = hannotate(f, [int, int], policy=P, annotator=True)
    assert not hs.is_green()
    assert isinstance(hs, SomeLLAbstractConstant)

    tsgraph = graphof(hannotator.translator, h2)
    hs = hannotator.binding(tsgraph.getargs()[0])
    assert not hs.is_green()
예제 #4
0
    def test_indirect_sometimes_residual_pure_red_call(self, setup=setup_for_indirect_call):
        def h1(x):
            return x-2
        def h2(x):
            return x*4
        call, lst = setup(h1, h2)
        def f(n, x):
            frozenl = hint(lst, deepfreeze=True)
            h = frozenl[n&1]
            return call(h, x)

        P = StopAtXPolicy(h1)
        P.oopspec = True
        P.entrypoint_returns_red = False
        hs, hannotator = self.hannotate(f, [int, int], policy=P, annotator=True)
        assert not hs.is_green()
        assert isinstance(hs, SomeLLAbstractConstant)

        tsgraph = graphof(hannotator.translator, h2)
        hs = hannotator.binding(tsgraph.getargs()[0])
        assert not hs.is_green()
예제 #5
0
def test_manual_marking_of_pure_functions():
    d = {}
    def h1(s):
        try:
            return d[s]
        except KeyError:
            d[s] = r = hash(s)
            return r
    h1._pure_function_ = True
    def f(n):
        hint(n, concrete=True)
        if n == 0:
            s = "abc"
        else:
            s = "123"
        a = h1(s)
        return a

    P = StopAtXPolicy(h1)
    P.oopspec = True
    P.entrypoint_returns_red = False
    hs = hannotate(f, [int], policy=P)
    assert hs.is_green()
예제 #6
0
    def test_manual_marking_of_pure_functions(self):
        d = {}
        def h1(s):
            try:
                return d[s]
            except KeyError:
                d[s] = r = hash(s)
                return r
        h1._pure_function_ = True
        def f(n):
            hint(n, concrete=True)
            if n == 0:
                s = "abc"
            else:
                s = "123"
            a = h1(s)
            return a

        P = StopAtXPolicy(h1)
        P.oopspec = True
        P.entrypoint_returns_red = False
        hs = self.hannotate(f, [int], policy=P)
        assert hs.is_green()
예제 #7
0
def test_indirect_sometimes_residual_red_call():
    class Stuff:
        pass
    stuff = Stuff()
    def h1(x):
        stuff.hello = 123
        return x-2
    def h2(x):
        return x*4
    l = [h1, h2]
    def f(n, x):
        frozenl = hint(l, deepfreeze=True)
        h = frozenl[n&1]
        return h(x)

    P = StopAtXPolicy(h1)
    P.oopspec = True
    P.entrypoint_returns_red = False
    hs, hannotator = hannotate(f, [int, int], policy=P, annotator=True)
    assert not hs.is_green()

    tsgraph = graphof(hannotator.translator, h2)
    hs = hannotator.binding(tsgraph.getargs()[0])
    assert not hs.is_green()