pub trait Bytecode<Id>where
Id: SiteId,{
// Required methods
fn op_range() -> RangeInclusive<u8>;
fn opcode_byte(&self) -> u8;
fn code_byte_len(&self) -> u16;
fn external_ref(&self) -> Option<Id>;
fn encode_operands<W>(
&self,
writer: &mut W,
) -> Result<(), <W as BytecodeWrite<Id>>::Error>
where W: BytecodeWrite<Id>;
fn decode_operands<R>(
reader: &mut R,
opcode: u8,
) -> Result<Self, CodeEofError>
where Self: Sized,
R: BytecodeRead<Id>;
// Provided methods
fn encode_instr<W>(
&self,
writer: &mut W,
) -> Result<(), <W as BytecodeWrite<Id>>::Error>
where W: BytecodeWrite<Id> { ... }
fn decode_instr<R>(reader: &mut R) -> Result<Self, CodeEofError>
where Self: Sized,
R: BytecodeRead<Id> { ... }
}
Expand description
Non-failing byte encoding for the instruction set.
We can’t use io
since (1) we are no_std, (2) it operates data with unlimited length (while we
are bound by u16), (3) it provides too many fails in situations when we can’t fail because of
u16
-bounding and exclusive in-memory encoding handling.
Required Methods§
Sourcefn op_range() -> RangeInclusive<u8>
fn op_range() -> RangeInclusive<u8>
Returns the range of instruction bytecodes covered by a set of operations.
Sourcefn opcode_byte(&self) -> u8
fn opcode_byte(&self) -> u8
Returns byte representing instruction code (without its arguments).
Sourcefn code_byte_len(&self) -> u16
fn code_byte_len(&self) -> u16
Returns the number of bytes used by the instruction and its arguments when serialized into the code segment.
Sourcefn external_ref(&self) -> Option<Id>
fn external_ref(&self) -> Option<Id>
If the instruction calls or references any external program, returns a reference to it.
Sourcefn encode_operands<W>(
&self,
writer: &mut W,
) -> Result<(), <W as BytecodeWrite<Id>>::Error>where
W: BytecodeWrite<Id>,
fn encode_operands<W>(
&self,
writer: &mut W,
) -> Result<(), <W as BytecodeWrite<Id>>::Error>where
W: BytecodeWrite<Id>,
Writes an instruction operands as bytecode, omitting opcode byte.
Sourcefn decode_operands<R>(reader: &mut R, opcode: u8) -> Result<Self, CodeEofError>where
Self: Sized,
R: BytecodeRead<Id>,
fn decode_operands<R>(reader: &mut R, opcode: u8) -> Result<Self, CodeEofError>where
Self: Sized,
R: BytecodeRead<Id>,
Reads an instruction operands from bytecode, provided the opcode byte.
Provided Methods§
Sourcefn encode_instr<W>(
&self,
writer: &mut W,
) -> Result<(), <W as BytecodeWrite<Id>>::Error>where
W: BytecodeWrite<Id>,
fn encode_instr<W>(
&self,
writer: &mut W,
) -> Result<(), <W as BytecodeWrite<Id>>::Error>where
W: BytecodeWrite<Id>,
Write an instruction as bytecode.
Sourcefn decode_instr<R>(reader: &mut R) -> Result<Self, CodeEofError>where
Self: Sized,
R: BytecodeRead<Id>,
fn decode_instr<R>(reader: &mut R) -> Result<Self, CodeEofError>where
Self: Sized,
R: BytecodeRead<Id>,
Reads an instruction from bytecode.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.