pulley_interpreter::decode

Trait BytecodeStream

Source
pub trait BytecodeStream: Copy {
    type Error;

    // Required methods
    fn unexpected_eof(&self) -> Self::Error;
    fn invalid_opcode(&self, code: u8) -> Self::Error;
    fn invalid_extended_opcode(&self, code: u16) -> Self::Error;
    fn invalid_reg(&self, reg: u8) -> Self::Error;
    fn read<const N: usize>(&mut self) -> Result<[u8; N], Self::Error>;
}
Available on crate feature decode only.
Expand description

An abstraction over any kind of bytecode stream.

There are two primary implementations:

  1. SafeBytecodeStream: A thin wrapper around an index into a &[u8]. This implementation is 100% safe code.

  2. UnsafeBytecodeStream: A thin wrapper over a raw pointer. This implementation is wildly unsafe and will result in memory unsafety and other terrors when given invalid bytecode, or even valid bytecode encoding a program that itself does not preserve memory safety.

Required Associated Types§

Source

type Error

The type of error that this bytecode stream produces on invalid operations.

Required Methods§

Source

fn unexpected_eof(&self) -> Self::Error

Create an “unexpected end-of-stream” error at the current position.

Source

fn invalid_opcode(&self, code: u8) -> Self::Error

Create an “invalid opcode” error at the current position.

Source

fn invalid_extended_opcode(&self, code: u16) -> Self::Error

Create an “invalid extended opcode” error at the current position.

Source

fn invalid_reg(&self, reg: u8) -> Self::Error

Create an “invalid register” error at the current position.

Source

fn read<const N: usize>(&mut self) -> Result<[u8; N], Self::Error>

Read N bytes from this bytecode stream, advancing the stream’s position at the same time.

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§