Struct ketos::bytecode::CodeBlock
[−]
[src]
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]
fn new() -> CodeBlock
Creates an empty CodeBlock
with a small reserved buffer.
fn empty() -> CodeBlock
Creates an empty CodeBlock
without reserving data.
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.
fn len(&self) -> usize
Returns the size of all encoded instructions.
fn is_empty(&self) -> bool
Returns whether any intruction was encoded.
fn bytes(&self) -> &[u8]
Returns encoded bytecode data.
flush
should be called first to ensure all instructions are encoded.
fn is_mostly_empty(&self) -> bool
Returns whether the code block is mostly empty, permitting the compiler to prune it in some cases.
fn set_next(&mut self, block: u32)
Sets the block which will immediately follow this block.
May only be called once.
fn jump_to(&mut self, instr: JumpInstruction, block: u32)
Sets the jump instruction at the end of the block.
May only be called once.
fn write_jump(&mut self, label: u32, short: bool) -> Result<(), CompileError>
Write stored jump instruction to buffer, if present.
fn flush(&mut self) -> Result<(), CompileError>
Forcibly encodes a pending instruction. Does not encode a jump instruction.
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.