Exemplo n.º 1
0
def test_genbooleq():
    gv1 = GenVar()
    gv2 = GenVar()
    gf = rgenop.genconst(False)
    gt = rgenop.genconst(True)

    for b1 in [False, True]:
        for b2 in [False, True]:
            for rev in [False, True]:
                jitstate = DummyJITState()
                box = desc.genbooleq(jitstate,
                                     rgenop.genconst(b1),
                                     rgenop.genconst(b2),
                                     rev)
                assert box.genvar.revealconst(lltype.Bool) == (b1 == b2) ^ rev
                assert not jitstate.curbuilder.operations

    for b2 in [False, True]:
        for rev in [False, True]:
            for flip in [False, True]:
                jitstate = DummyJITState()
                args = [gv1, rgenop.genconst(b2), rev]
                if flip:
                    args[0], args[1] = args[1], args[0]
                box = desc.genbooleq(jitstate, *args)

                should_neg = (b2 == rev)
                if should_neg:
                    assert jitstate.curbuilder.operations == [
                        ("bool_not", gv1, box.genvar),
                        ]
                else:
                    assert box.genvar == gv1
                    assert not jitstate.curbuilder.operations

    for rev in [False, True]:
        jitstate = DummyJITState()
        box = desc.genbooleq(jitstate, gv1, gv2, rev)
        ops = jitstate.curbuilder.operations
        _, _, gvi1 = ops[0]
        _, _, gvi2 = ops[1]
        assert ops == [
            ("cast_bool_to_int", gv1, gvi1),
            ("cast_bool_to_int", gv2, gvi2),
            (["int_eq", "int_ne"][rev], gvi1, gvi2, box.genvar),
            ]
Exemplo n.º 2
0
def test_genbooleq():
    gv1 = GenVar()
    gv2 = GenVar()
    gf = rgenop.genconst(False)
    gt = rgenop.genconst(True)

    for b1 in [False, True]:
        for b2 in [False, True]:
            for rev in [False, True]:
                jitstate = DummyJITState()
                box = desc.genbooleq(jitstate,
                                     rgenop.genconst(b1),
                                     rgenop.genconst(b2),
                                     rev)
                assert box.genvar.revealconst(lltype.Bool) == (b1 == b2) ^ rev
                assert not jitstate.curbuilder.operations

    for b2 in [False, True]:
        for rev in [False, True]:
            for flip in [False, True]:
                jitstate = DummyJITState()
                args = [gv1, rgenop.genconst(b2), rev]
                if flip:
                    args[0], args[1] = args[1], args[0]
                box = desc.genbooleq(jitstate, *args)

                should_neg = (b2 == rev)
                if should_neg:
                    assert jitstate.curbuilder.operations == [
                        ("bool_not", gv1, box.genvar),
                        ]
                else:
                    assert box.genvar == gv1
                    assert not jitstate.curbuilder.operations

    for rev in [False, True]:
        jitstate = DummyJITState()
        box = desc.genbooleq(jitstate, gv1, gv2, rev)
        ops = jitstate.curbuilder.operations
        _, _, gvi1 = ops[0]
        _, _, gvi2 = ops[1]
        assert ops == [
            ("cast_bool_to_int", gv1, gvi1),
            ("cast_bool_to_int", gv2, gvi2),
            (["int_eq", "int_ne"][rev], gvi1, gvi2, box.genvar),
            ]
Exemplo n.º 3
0
def test_getboolbox():
    for b1 in [False, True]:
        for b2 in [False, True]:
            jitstate = DummyJITState()
            box = desc.getboolbox(jitstate, rgenop.genconst(b1), b2)
            assert box.genvar.revealconst(lltype.Bool) == b1 ^ b2
            assert not jitstate.curbuilder.operations

    gv1 = GenVar()
    jitstate = DummyJITState()
    box = desc.getboolbox(jitstate, gv1, False)
    assert box.genvar == gv1
    assert not jitstate.curbuilder.operations

    jitstate = DummyJITState()
    box = desc.getboolbox(jitstate, gv1, True)
    assert jitstate.curbuilder.operations == [
        ("bool_not", gv1, box.genvar),
    ]
Exemplo n.º 4
0
def test_getboolbox():
    for b1 in [False, True]:
        for b2 in [False, True]:
            jitstate = DummyJITState()
            box = desc.getboolbox(jitstate, rgenop.genconst(b1), b2)
            assert box.genvar.revealconst(lltype.Bool) == b1 ^ b2
            assert not jitstate.curbuilder.operations

    gv1 = GenVar()
    jitstate = DummyJITState()
    box = desc.getboolbox(jitstate, gv1, False)
    assert box.genvar == gv1
    assert not jitstate.curbuilder.operations

    jitstate = DummyJITState()
    box = desc.getboolbox(jitstate, gv1, True)
    assert jitstate.curbuilder.operations == [
        ("bool_not", gv1, box.genvar),
        ]