Skip to main content

Emitter

Struct Emitter 

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

Builder for constructing bytecode chunks.

Implementations§

Source§

impl Emitter

Source

pub fn new() -> Self

Source

pub fn emit_op(&mut self, op: Op)

Source

pub fn emit_u16(&mut self, val: u16)

Source

pub fn emit_u32(&mut self, val: u32)

Source

pub fn emit_i32(&mut self, val: i32)

Source

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.

Source

pub fn emit_const(&mut self, val: Value)

Emit Op::Const followed by the u16 constant index.

Source

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

Record a source span at the current PC position.

Source

pub fn current_pc(&self) -> u32

Current code length as u32.

Source

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.

Source

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.

Source

pub fn into_chunk(self) -> Chunk

Consume the emitter and return the finished Chunk.

Trait Implementations§

Source§

impl Default for Emitter

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.