Struct CodeBlock

Source
pub struct CodeBlock {
    pub jump: Option<(JumpInstruction, u32)>,
    pub next: Option<u32>,
    /* private fields */
}
Expand description

Contains a series of bytecode instructions

Fields§

§jump: Option<(JumpInstruction, u32)>

Jump instruction added to the end of the block

§next: Option<u32>

Refers to the block that immediately follows this block

Implementations§

Source§

impl CodeBlock

Source

pub fn new() -> CodeBlock

Creates an empty CodeBlock with a small reserved buffer.

Source

pub fn empty() -> CodeBlock

Creates an empty CodeBlock without reserving data.

Source

pub fn calculate_size(&self, short: bool) -> usize

Returns the final size of the block, including all encoded instructions and final jump instruction. short indicates whether jump instruction offsets are encoded in short format.

If there is an unencoded instruction, its size is estimated.

Source

pub fn len(&self) -> usize

Returns the size of all encoded instructions.

Source

pub fn is_empty(&self) -> bool

Returns whether any intruction was encoded.

Source

pub fn bytes(&self) -> &[u8]

Returns encoded bytecode data.

flush should be called first to ensure all instructions are encoded.

Source

pub fn is_mostly_empty(&self) -> bool

Returns whether the code block is mostly empty, permitting the compiler to prune it in some cases.

Source

pub fn set_next(&mut self, block: u32)

Sets the block which will immediately follow this block.

May only be called once.

Source

pub fn jump_to(&mut self, instr: JumpInstruction, block: u32)

Sets the jump instruction at the end of the block.

May only be called once.

Source

pub fn write_jump( &mut self, label: u32, short: bool, ) -> Result<(), CompileError>

Write stored jump instruction to buffer, if present.

Source

pub fn flush(&mut self) -> Result<(), CompileError>

Forcibly encodes a pending instruction. Does not encode a jump instruction.

Source

pub fn push_instruction( &mut self, instr: Instruction, ) -> Result<(), CompileError>

Adds an instruction the block. The instruction may be stored until later to be merged into a combination instruction.

Trait Implementations§

Source§

impl Debug for CodeBlock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V