[][src]Struct ketos::bytecode::CodeBlock

pub struct CodeBlock {
    pub jump: Option<(JumpInstruction, u32)>,
    pub next: Option<u32>,
    // some fields omitted
}

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

Methods

impl CodeBlock[src]

pub fn new() -> CodeBlock[src]

Creates an empty CodeBlock with a small reserved buffer.

pub fn empty() -> CodeBlock[src]

Creates an empty CodeBlock without reserving data.

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

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.

pub fn len(&self) -> usize[src]

Returns the size of all encoded instructions.

pub fn is_empty(&self) -> bool[src]

Returns whether any intruction was encoded.

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

Returns encoded bytecode data.

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

pub fn is_mostly_empty(&self) -> bool[src]

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

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

Sets the block which will immediately follow this block.

May only be called once.

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

Sets the jump instruction at the end of the block.

May only be called once.

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

Write stored jump instruction to buffer, if present.

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

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

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

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

Trait Implementations

impl Debug for CodeBlock[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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