Beispiel #1
0
 def test_floats(self):
     inp = '''
     [f0]
     f1 = float_add(3.5, f0)
     '''
     loop, oloop = self.reparse(inp)
     equaloplists(loop.operations, oloop.operations)
Beispiel #2
0
 def test_floats(self):
     inp = '''
     [f0]
     f1 = float_add(3.5, f0)
     '''
     loop, oloop = self.reparse(inp)
     equaloplists(loop.operations, oloop.operations)
Beispiel #3
0
def test_remove_consts_and_duplicates():
    class FakeStaticData:
        cpu = None
    def is_another_box_like(box, referencebox):
        assert box is not referencebox
        assert isinstance(box, referencebox.clonebox().__class__)
        assert box.value == referencebox.value
        return True
    metainterp = pyjitpl.MetaInterp(FakeStaticData())
    metainterp.history = History()
    b1 = BoxInt(1)
    b2 = BoxInt(2)
    c3 = ConstInt(3)
    boxes = [b1, b2, b1, c3]
    dup = {}
    metainterp.remove_consts_and_duplicates(boxes, 0, 4, dup)
    assert boxes[0] is b1
    assert boxes[1] is b2
    assert is_another_box_like(boxes[2], b1)
    assert is_another_box_like(boxes[3], c3)
    assert equaloplists(metainterp.history.operations, [
        ResOperation(rop.SAME_AS, [b1], boxes[2]),
        ResOperation(rop.SAME_AS, [c3], boxes[3]),
        ])
    assert dup == {b1: None, b2: None}
    #
    del metainterp.history.operations[:]
    b4 = BoxInt(4)
    boxes = ["something random", b2, b4, "something else"]
    metainterp.remove_consts_and_duplicates(boxes, 1, 3, dup)
    assert is_another_box_like(boxes[1], b2)
    assert boxes[2] is b4
    assert equaloplists(metainterp.history.operations, [
        ResOperation(rop.SAME_AS, [b2], boxes[1]),
        ])
Beispiel #4
0
 def reparse(self, inp, namespace=None, check_equal=True):
     """ parse loop once, then log it and parse again.
     Checks that we get the same thing.
     """
     if namespace is None:
         namespace = {}
     loop = pure_parse(inp, namespace=namespace)
     logger = Logger(self.make_metainterp_sd())
     output = logger.log_loop(loop, namespace)
     oloop = pure_parse(output, namespace=namespace)
     if check_equal:
         equaloplists(loop.operations, oloop.operations)
         assert oloop.inputargs == loop.inputargs
     return loop, oloop
Beispiel #5
0
 def reparse(self, inp, namespace=None, check_equal=True):
     """ parse loop once, then log it and parse again.
     Checks that we get the same thing.
     """
     if namespace is None:
         namespace = {}
     loop = pure_parse(inp, namespace=namespace)
     logger = Logger(self.ts)
     output = logger.log_loop(loop, namespace)
     oloop = pure_parse(output, namespace=namespace)
     if check_equal:
         equaloplists(loop.operations, oloop.operations)
         assert oloop.inputargs == loop.inputargs
     return loop, oloop