Exemplo n.º 1
0
    def test_simple_merge_generalize(self):
        S = self.STRUCT
        constbox20 = makebox(20)
        oldbox = vmalloc(S, constbox20)
        frozenbox = oldbox.freeze(rvalue.freeze_memo())
        # check that frozenbox matches oldbox exactly
        assert self.match(frozenbox, oldbox, [])      # there is no FrozenVar

        constbox23 = makebox(23)
        newbox = vmalloc(S, constbox23)
        # non-exact match: a different constant box in the virtual struct field
        assert not self.match(frozenbox, newbox, [constbox23])
        #  constbox23 is what should be generalized with forcevar()
        #  in order to get something that is at least as general as
        #  both oldbox and newbox

        jitstate = FakeJITState()
        replace_memo = rvalue.copy_memo()
        forcedbox = constbox23.forcevar(jitstate, replace_memo, False)
        assert not forcedbox.is_constant()
        assert jitstate.curbuilder.ops == [
            ('same_as', (signed_kind, constbox23.genvar), forcedbox.genvar)]
        assert replace_memo.boxes == {constbox23: forcedbox}

        # change constbox to forcedbox inside newbox
        newbox.replace(replace_memo)
        assert (newbox.content.op_getfield(jitstate, self.fielddesc) is
                forcedbox)

        # check that now newbox really generalizes oldbox
        newfrozenbox = newbox.freeze(rvalue.freeze_memo())
        assert self.match(newfrozenbox, oldbox, [constbox20])
Exemplo n.º 2
0
    def test_simple_merge_generalize(self):
        S = self.STRUCT
        constbox20 = makebox(20)
        oldbox = vmalloc(S, constbox20)
        frozenbox = oldbox.freeze(rvalue.freeze_memo())
        # check that frozenbox matches oldbox exactly
        assert self.match(frozenbox, oldbox, [])  # there is no FrozenVar

        constbox23 = makebox(23)
        newbox = vmalloc(S, constbox23)
        # non-exact match: a different constant box in the virtual struct field
        assert not self.match(frozenbox, newbox, [constbox23])
        #  constbox23 is what should be generalized with forcevar()
        #  in order to get something that is at least as general as
        #  both oldbox and newbox

        jitstate = FakeJITState()
        replace_memo = rvalue.copy_memo()
        forcedbox = constbox23.forcevar(jitstate, replace_memo, False)
        assert not forcedbox.is_constant()
        assert jitstate.curbuilder.ops == [
            ('same_as', (signed_kind, constbox23.genvar), forcedbox.genvar)
        ]
        assert replace_memo.boxes == {constbox23: forcedbox}

        # change constbox to forcedbox inside newbox
        newbox.replace(replace_memo)
        assert (newbox.content.op_getfield(jitstate, self.fielddesc) is
                forcedbox)

        # check that now newbox really generalizes oldbox
        newfrozenbox = newbox.freeze(rvalue.freeze_memo())
        assert self.match(newfrozenbox, oldbox, [constbox20])
Exemplo n.º 3
0
    def test_nested_structure_no_vars(self):
        NESTED = self.NESTEDSTRUCT
        constbox30 = makebox(30)
        constbox20 = makebox(20)
        oldbox = vmalloc(NESTED, constbox20, vmalloc(NESTED, constbox30))

        jitstate = FakeJITState()
        frozenbox = oldbox.freeze(rvalue.freeze_memo())
        # check that frozenbox matches oldbox exactly
        assert self.match(frozenbox, oldbox, [])  # there is no FrozenVar
Exemplo n.º 4
0
    def test_nested_structure_no_vars(self):
        NESTED = self.NESTEDSTRUCT
        constbox30 = makebox(30)
        constbox20 = makebox(20)
        oldbox = vmalloc(NESTED, constbox20, vmalloc(NESTED, constbox30))

        jitstate = FakeJITState()
        frozenbox = oldbox.freeze(rvalue.freeze_memo())
        # check that frozenbox matches oldbox exactly
        assert self.match(frozenbox, oldbox, [])     # there is no FrozenVar
Exemplo n.º 5
0
    def test_simple_merge(self):
        V42 = FakeGenVar(42)
        oldbox = vmalloc(self.STRUCT, makebox(V42))
        frozenbox = oldbox.freeze(rvalue.freeze_memo())
        # check that frozenbox matches oldbox exactly
        jitstate = FakeJITState()
        fieldbox = oldbox.content.op_getfield(jitstate, self.fielddesc)
        assert self.match(frozenbox, oldbox, [fieldbox])

        constbox23 = makebox(23)
        newbox = vmalloc(self.STRUCT, constbox23)
        # check that frozenbox also matches newbox exactly
        assert self.match(frozenbox, newbox, [constbox23])
Exemplo n.º 6
0
    def test_simple_merge(self):
        V42 = FakeGenVar(42)
        oldbox = vmalloc(self.STRUCT, makebox(V42))
        frozenbox = oldbox.freeze(rvalue.freeze_memo())
        # check that frozenbox matches oldbox exactly
        jitstate = FakeJITState()
        fieldbox = oldbox.content.op_getfield(jitstate, self.fielddesc)
        assert self.match(frozenbox, oldbox, [fieldbox])

        constbox23 = makebox(23)
        newbox = vmalloc(self.STRUCT, constbox23)
        # check that frozenbox also matches newbox exactly
        assert self.match(frozenbox, newbox, [constbox23])
Exemplo n.º 7
0
    def test_nested_structures_variables(self):
        NESTED = self.NESTEDSTRUCT
        varbox42 = makebox(FakeGenVar(42))
        constbox20 = makebox(20)
        oldbox = vmalloc(NESTED, constbox20, vmalloc(NESTED, varbox42))
        jitstate = FakeJITState()
        frozenbox = oldbox.freeze(rvalue.freeze_memo())
        # check that frozenbox matches oldbox exactly
        assert self.match(frozenbox, oldbox, [varbox42])

        constbox30 = makebox(30)
        newbox = vmalloc(NESTED, constbox20, vmalloc(NESTED, constbox30))
        # check that frozenbox also matches newbox exactly
        assert self.match(frozenbox, newbox, [constbox30])
Exemplo n.º 8
0
    def test_nested_structures_variables(self):
        NESTED = self.NESTEDSTRUCT
        varbox42 = makebox(FakeGenVar(42))
        constbox20 = makebox(20)
        oldbox = vmalloc(NESTED, constbox20, vmalloc(NESTED, varbox42))
        jitstate = FakeJITState()
        frozenbox = oldbox.freeze(rvalue.freeze_memo())
        # check that frozenbox matches oldbox exactly
        assert self.match(frozenbox, oldbox, [varbox42])

        constbox30 = makebox(30)
        newbox = vmalloc(NESTED, constbox20, vmalloc(NESTED, constbox30))
        # check that frozenbox also matches newbox exactly
        assert self.match(frozenbox, newbox, [constbox30])