pub struct Emitter { /* private fields */ }Expand description
Builder for constructing bytecode chunks.
Implementations§
Source§impl Emitter
impl Emitter
pub fn new() -> Self
pub fn emit_op(&mut self, op: Op)
pub fn emit_u16(&mut self, val: u16)
pub fn emit_u32(&mut self, val: u32)
pub fn emit_i32(&mut self, val: i32)
Sourcepub fn add_const(&mut self, val: Value) -> u16
pub fn add_const(&mut self, val: Value) -> u16
Add a constant to the pool, deduplicating by value equality. Returns the u16 index into the constant pool.
Sourcepub fn emit_const(&mut self, val: Value)
pub fn emit_const(&mut self, val: Value)
Emit Op::Const followed by the u16 constant index.
Sourcepub fn current_pc(&self) -> u32
pub fn current_pc(&self) -> u32
Current code length as u32.
Sourcepub fn emit_jump(&mut self, op: Op) -> u32
pub fn emit_jump(&mut self, op: Op) -> u32
Emit a jump instruction with a placeholder i32 offset. Returns the PC of the placeholder for later backpatching.
Sourcepub fn patch_jump(&mut self, placeholder_pc: u32)
pub fn patch_jump(&mut self, placeholder_pc: u32)
Backpatch the i32 at placeholder_pc with the relative offset
from the end of the jump instruction to the current PC.
Sourcepub fn into_chunk(self) -> Chunk
pub fn into_chunk(self) -> Chunk
Consume the emitter and return the finished Chunk.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Emitter
impl RefUnwindSafe for Emitter
impl Send for Emitter
impl Sync for Emitter
impl Unpin for Emitter
impl UnsafeUnpin for Emitter
impl UnwindSafe for Emitter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more