Trait Bytecode

Source
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§

Source

fn op_range() -> RangeInclusive<u8>

Returns the range of instruction bytecodes covered by a set of operations.

Source

fn opcode_byte(&self) -> u8

Returns byte representing instruction code (without its arguments).

Source

fn code_byte_len(&self) -> u16

Returns the number of bytes used by the instruction and its arguments when serialized into the code segment.

Source

fn external_ref(&self) -> Option<Id>

If the instruction calls or references any external program, returns a reference to it.

Source

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.

Source

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§

Source

fn encode_instr<W>( &self, writer: &mut W, ) -> Result<(), <W as BytecodeWrite<Id>>::Error>
where W: BytecodeWrite<Id>,

Write an instruction as bytecode.

Source

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.

Implementors§

Source§

impl<Id> Bytecode<Id> for sonicapi::Instr<Id>
where Id: SiteId,

Source§

impl<Id> Bytecode<Id> for UsonicInstr
where Id: SiteId,

Source§

impl<Id> Bytecode<Id> for FieldInstr
where Id: SiteId,

Source§

impl<Id> Bytecode<Id> for sonicapi::aluvm::gfa::Instr<Id>
where Id: SiteId,

Source§

impl<Id> Bytecode<Id> for CtrlInstr<Id>
where Id: SiteId,

Source§

impl<Id> Bytecode<Id> for sonicapi::aluvm::alu::isa::Instr<Id>
where Id: SiteId,

Source§

impl<Id> Bytecode<Id> for ReservedInstr
where Id: SiteId,