Skip to main content

BytecodeBuilder

Struct BytecodeBuilder 

Source
pub struct BytecodeBuilder { /* private fields */ }
Expand description

Builder for constructing bytecode chunks

Implementations§

Source§

impl BytecodeBuilder

Source

pub fn new() -> Self

Create a new bytecode builder

Source

pub fn for_function(info: FunctionInfo) -> Self

Create a builder for a function

Source

pub fn set_source_file(&mut self, path: String)

Set the source file path for stack traces

Source

pub fn source_file(&self) -> Option<&String>

Get the current source file path

Source

pub fn registers(&mut self) -> &mut RegisterAllocator

Get access to the register allocator

Source

pub fn set_span(&mut self, span: Span)

Set the current source span for source map

Source

pub fn clear_span(&mut self)

Clear the current source span

Source

pub fn emit(&mut self, op: Op) -> usize

Emit an instruction and return its index

Source

pub fn emit_jump(&mut self) -> JumpPlaceholder

Emit a jump instruction with a placeholder target

Source

pub fn emit_jump_if_true(&mut self, cond: Register) -> JumpPlaceholder

Emit a conditional jump (if true) with a placeholder target

Source

pub fn emit_jump_if_false(&mut self, cond: Register) -> JumpPlaceholder

Emit a conditional jump (if false) with a placeholder target

Source

pub fn emit_jump_if_nullish(&mut self, cond: Register) -> JumpPlaceholder

Emit a conditional jump (if nullish) with a placeholder target

Source

pub fn emit_jump_if_not_nullish(&mut self, cond: Register) -> JumpPlaceholder

Emit a conditional jump (if NOT nullish) with a placeholder target

Source

pub fn emit_jump_to(&mut self, target: usize)

Emit a jump to a known target

Source

pub fn patch_jump(&mut self, placeholder: JumpPlaceholder)

Patch a jump placeholder to jump to the current position

Source

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.

Source

pub fn patch_try_targets( &mut self, idx: usize, catch_target: JumpTarget, finally_target: JumpTarget, )

Patch PushTry instruction with catch and finally targets

Source

pub fn patch_iter_try_target(&mut self, idx: usize, target: JumpTarget)

Patch PushIterTry instruction with catch target

Source

pub fn current_offset(&self) -> usize

Get the current instruction offset (for jump targets)

Source

pub fn add_string(&mut self, s: JsString) -> Result<u16, JsError>

Add a string constant to the pool (with deduplication)

Source

pub fn add_number(&mut self, n: f64) -> Result<u16, JsError>

Add a number constant to the pool (with deduplication)

Source

pub fn add_constant(&mut self, constant: Constant) -> Result<u16, JsError>

Add a constant to the pool

Source

pub fn add_chunk(&mut self, chunk: BytecodeChunk) -> Result<u16, JsError>

Add a nested bytecode chunk (for functions)

Source

pub fn add_excluded_keys(&mut self, keys: Vec<JsString>) -> Result<u16, JsError>

Add excluded keys for object rest destructuring

Source

pub fn emit_load_string( &mut self, dst: Register, s: JsString, ) -> Result<(), JsError>

Emit LoadConst for a string

Source

pub fn emit_load_number(&mut self, dst: Register, n: f64) -> Result<(), JsError>

Emit LoadConst for a number

Source

pub fn emit_halt(&mut self)

Emit Halt instruction

Source

pub fn finish(self) -> BytecodeChunk

Finish building and return the bytecode chunk

Source

pub fn alloc_register(&mut self) -> Result<Register, JsError>

Allocate a register

Source

pub fn free_register(&mut self, r: Register)

Free a register

Source

pub fn reserve_registers(&mut self, count: u8) -> Result<Register, JsError>

Reserve a range of consecutive registers

Source

pub fn free_registers(&mut self, start: Register, count: u8)

Free a range of consecutive registers (frees from end to start for optimal reuse)

Trait Implementations§

Source§

impl Default for BytecodeBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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.