def _(operand): item = single(operand) if isinstance(item, Label): return ExtendedDirect(item) elif isinstance(item, Integral): if item < 0: raise ValueError("Direct address {} is negative.".format(operand)) if item <= 0xFF: return PageDirect(item) if item <= 0xFFFF: return ExtendedDirect(item) raise ValueError( "Direct address 0x{:X} out of range 0x0000-0xFFFF".format(item)) else: raise TypeError( "Expected integer address or label. Got {}".format(item))
def _(item): if item < 0: raise ValueError("Direct address {} is negative.".format(item)) if item <= 0xFF: return PageDirect(item) if item <= 0xFFFF: return ExtendedDirect(item) raise ValueError( "Direct address 0x{:X} out of range 0x0000-0xFFFF".format(item))
def _(item): return ExtendedDirect(item.value)
def test_extended_direct_equal_hash(address): assert hash(ExtendedDirect(address)) == hash(ExtendedDirect(address))
def test_extended_direct_inequality_different_types(address): assert ExtendedDirect(address) != object()
def test_extended_direct_inequality(a, b): assume(a != b) assert ExtendedDirect(a) != ExtendedDirect(b)
def test_extended_direct_repr(address): r = repr(ExtendedDirect(address)) assert r.startswith('ExtendedDirect') assert hex(address)[2:].upper() in r assert check_balanced(r)
def test_extended_direct_three_byte_address_raises_value_error(address): address = 0x010000 with raises(ValueError): ExtendedDirect(address)
def test_negative_extended_direct_address_raises_value_error(address): with raises(ValueError): ExtendedDirect(address)
def test_extended_direct_address_must_be_two_byte(address): r = ExtendedDirect(address) assert r.address == address
def test_extended_direct_incorrect_type_raises_type_error(): with raises(TypeError): ExtendedDirect(object())
def test_extended_direct_address_assembly(): asm = AsmDsl() asm(ADDB, {0x1C48}) assert statements(asm) == (AddB(ExtendedDirect(0x1C48)), )