pub struct BytecodeBuilder { /* private fields */ }Expand description
Builder for constructing bytecode chunks
Implementations§
Source§impl BytecodeBuilder
impl BytecodeBuilder
Sourcepub fn for_function(info: FunctionInfo) -> Self
pub fn for_function(info: FunctionInfo) -> Self
Create a builder for a function
Sourcepub fn set_source_file(&mut self, path: String)
pub fn set_source_file(&mut self, path: String)
Set the source file path for stack traces
Sourcepub fn source_file(&self) -> Option<&String>
pub fn source_file(&self) -> Option<&String>
Get the current source file path
Sourcepub fn clear_span(&mut self)
pub fn clear_span(&mut self)
Clear the current source span
Sourcepub fn emit_jump(&mut self) -> JumpPlaceholder
pub fn emit_jump(&mut self) -> JumpPlaceholder
Emit a jump instruction with a placeholder target
Sourcepub fn emit_jump_if_true(&mut self, cond: Register) -> JumpPlaceholder
pub fn emit_jump_if_true(&mut self, cond: Register) -> JumpPlaceholder
Emit a conditional jump (if true) with a placeholder target
Sourcepub fn emit_jump_if_false(&mut self, cond: Register) -> JumpPlaceholder
pub fn emit_jump_if_false(&mut self, cond: Register) -> JumpPlaceholder
Emit a conditional jump (if false) with a placeholder target
Sourcepub fn emit_jump_if_nullish(&mut self, cond: Register) -> JumpPlaceholder
pub fn emit_jump_if_nullish(&mut self, cond: Register) -> JumpPlaceholder
Emit a conditional jump (if nullish) with a placeholder target
Sourcepub fn emit_jump_if_not_nullish(&mut self, cond: Register) -> JumpPlaceholder
pub fn emit_jump_if_not_nullish(&mut self, cond: Register) -> JumpPlaceholder
Emit a conditional jump (if NOT nullish) with a placeholder target
Sourcepub fn emit_jump_to(&mut self, target: usize)
pub fn emit_jump_to(&mut self, target: usize)
Emit a jump to a known target
Sourcepub fn patch_jump(&mut self, placeholder: JumpPlaceholder)
pub fn patch_jump(&mut self, placeholder: JumpPlaceholder)
Patch a jump placeholder to jump to the current position
Sourcepub fn patch_jump_to(
&mut self,
placeholder: JumpPlaceholder,
target: JumpTarget,
)
pub fn patch_jump_to( &mut self, placeholder: JumpPlaceholder, target: JumpTarget, )
Patch a jump placeholder to jump to a specific target
NOTE: All Op variants with a JumpTarget field must be listed here. We explicitly list non-jump variants to get compile errors when new jump ops are added.
Sourcepub fn patch_try_targets(
&mut self,
idx: usize,
catch_target: JumpTarget,
finally_target: JumpTarget,
)
pub fn patch_try_targets( &mut self, idx: usize, catch_target: JumpTarget, finally_target: JumpTarget, )
Patch PushTry instruction with catch and finally targets
Sourcepub fn patch_iter_try_target(&mut self, idx: usize, target: JumpTarget)
pub fn patch_iter_try_target(&mut self, idx: usize, target: JumpTarget)
Patch PushIterTry instruction with catch target
Sourcepub fn current_offset(&self) -> usize
pub fn current_offset(&self) -> usize
Get the current instruction offset (for jump targets)
Sourcepub fn add_string(&mut self, s: JsString) -> Result<u16, JsError>
pub fn add_string(&mut self, s: JsString) -> Result<u16, JsError>
Add a string constant to the pool (with deduplication)
Sourcepub fn add_number(&mut self, n: f64) -> Result<u16, JsError>
pub fn add_number(&mut self, n: f64) -> Result<u16, JsError>
Add a number constant to the pool (with deduplication)
Sourcepub fn add_constant(&mut self, constant: Constant) -> Result<u16, JsError>
pub fn add_constant(&mut self, constant: Constant) -> Result<u16, JsError>
Add a constant to the pool
Sourcepub fn add_chunk(&mut self, chunk: BytecodeChunk) -> Result<u16, JsError>
pub fn add_chunk(&mut self, chunk: BytecodeChunk) -> Result<u16, JsError>
Add a nested bytecode chunk (for functions)
Sourcepub fn add_excluded_keys(&mut self, keys: Vec<JsString>) -> Result<u16, JsError>
pub fn add_excluded_keys(&mut self, keys: Vec<JsString>) -> Result<u16, JsError>
Add excluded keys for object rest destructuring
Sourcepub fn emit_load_string(
&mut self,
dst: Register,
s: JsString,
) -> Result<(), JsError>
pub fn emit_load_string( &mut self, dst: Register, s: JsString, ) -> Result<(), JsError>
Emit LoadConst for a string
Sourcepub fn emit_load_number(&mut self, dst: Register, n: f64) -> Result<(), JsError>
pub fn emit_load_number(&mut self, dst: Register, n: f64) -> Result<(), JsError>
Emit LoadConst for a number
Sourcepub fn finish(self) -> BytecodeChunk
pub fn finish(self) -> BytecodeChunk
Finish building and return the bytecode chunk
Sourcepub fn alloc_register(&mut self) -> Result<Register, JsError>
pub fn alloc_register(&mut self) -> Result<Register, JsError>
Allocate a register
Sourcepub fn free_register(&mut self, r: Register)
pub fn free_register(&mut self, r: Register)
Free a register
Sourcepub fn reserve_registers(&mut self, count: u8) -> Result<Register, JsError>
pub fn reserve_registers(&mut self, count: u8) -> Result<Register, JsError>
Reserve a range of consecutive registers
Sourcepub fn free_registers(&mut self, start: Register, count: u8)
pub fn free_registers(&mut self, start: Register, count: u8)
Free a range of consecutive registers (frees from end to start for optimal reuse)