def _(operand): offset, base = single(operand.items()) if not isinstance(offset, (Register, Integral)): raise TypeError("Expected integer offset. Got {}".format(offset)) if not isinstance(base, (Register, AutoIncrementedRegister)): raise TypeError("{} is not a base".format(base)) return Indexed(base=base, offset=offset)
def test_indexed_inequality(base_a, offset_a, base_b, offset_b): assume((base_a, offset_a) != (base_b, offset_b)) assert Indexed(base_a, offset_a) != Indexed(base_b, offset_b)
def test_indexed_hash_equality(base, offset): assert hash(Indexed(base, offset)) == hash(Indexed(base, offset))
def test_indexed_equality(base, offset): assert Indexed(base, offset) == Indexed(base, offset)
def test_indexed_inequality_different_types(base, offset): assert Indexed(base, offset) != object()
def test_indexed_repr(base, offset): r = repr(Indexed(base, offset)) assert r.startswith('Indexed') assert base.name in r assert check_balanced(r)
def test_indexed_autoincrement_with_out_of_range_offset_raises_value_error( index_register, offset): assume(offset != 0) with raises(ValueError): Indexed(index_register, offset)
def test_indexed_autoincrement_with_non_zero_offset_raises_value_error( index_register, delta, offset): assume(offset != 0) print(offset) with raises(ValueError): Indexed(AutoIncrementedRegister(index_register, delta), offset)
def test_indexed_values(base, offset): idx = Indexed(base, offset) assert idx.base == base assert idx.offset == offset
def test_indexed_zero_offset(): asm = AsmDsl() asm(ADDA, {0: X}) assert statements(asm) == (AddA(Indexed(X, 0)), )