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
impl CodeBlock
Sourcepub fn calculate_size(&self, short: bool) -> usize
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.
Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
Returns encoded bytecode data.
flush
should be called first to ensure all instructions are encoded.
Sourcepub fn is_mostly_empty(&self) -> bool
pub fn is_mostly_empty(&self) -> bool
Returns whether the code block is mostly empty, permitting the compiler to prune it in some cases.
Sourcepub fn set_next(&mut self, block: u32)
pub fn set_next(&mut self, block: u32)
Sets the block which will immediately follow this block.
May only be called once.
Sourcepub fn jump_to(&mut self, instr: JumpInstruction, block: u32)
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.
Sourcepub fn write_jump(
&mut self,
label: u32,
short: bool,
) -> Result<(), CompileError>
pub fn write_jump( &mut self, label: u32, short: bool, ) -> Result<(), CompileError>
Write stored jump instruction to buffer, if present.
Sourcepub fn flush(&mut self) -> Result<(), CompileError>
pub fn flush(&mut self) -> Result<(), CompileError>
Forcibly encodes a pending instruction. Does not encode a jump instruction.
Sourcepub fn push_instruction(
&mut self,
instr: Instruction,
) -> Result<(), CompileError>
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.