def _(operand): """Parse an immediate operand. Immediate operands are simple values such as 0, 0x10, or 0b10101010, or an expression evaluating to such a value, such as ord("A"). """ return Immediate(operand)
def _(operand): try: byte = single(operand) except ValueError as ve: raise ValueError( "Immediate8 string operand must contain an single ASCII character. Got {} in {!r}" .format(len(operand), operand)) from ve return Immediate(byte)
def test_immediate_hash(a): assert hash(Immediate(a)) == hash(Immediate(a))
def test_immediate_inequality_different_types(a): assert Immediate(a) != object()
def test_immediate_inequality(a, b): assume(a != b) assert Immediate(a) != Immediate(b)
def test_immediate_equality(a): assert Immediate(a) == Immediate(a)
def test_bytes_operand_gives_immediate_value(b): assert parse_operand(b) == Immediate(b[0], 1)
def _(operand): unsigned = operand.value.to_bytes(2, byteorder="big", signed=True) return Immediate(int.from_bytes(unsigned, byteorder="big", signed=False), 2)
def _(operand): return Immediate(operand)
def test_i16_operand(): assert parse_operand(I16(-4567)) == Immediate(60969, 2)
def test_i32_operand(): assert parse_operand(I32(0x45671234)) == Immediate(0x45671234, 4)
def test_i8_operand(): assert parse_operand(I8(-42)) == Immediate(214, 1)
def test_u16_operand(): assert parse_operand(U16(0x4567)) == Immediate(0x4567, 2)
def test_u8_operand(): assert parse_operand(U8(42)) == Immediate(42, 1)
def _(operand): return Immediate(int.from_bytes(operand, byteorder="big", signed=False), len(operand))
def test_immediate_value(a): assert Immediate(a).value == a
def _(operand): return Immediate(operand.value, 4)
def test_immediate_repr(a): r = repr(Immediate(a)) assert r.startswith('Immediate') assert str(a) in r assert check_balanced(r)
def _(operand): return Immediate( int.from_bytes(operand.value.to_bytes(4, byteorder="big", signed=True), byteorder="big", signed=False), 4)
def test_immediate_address_assembly(): asm = AsmDsl() asm(LDA, 0x30) assert statements(asm) == (LdA(Immediate(0x30)), )