pub struct Chunk {
pub module_name: Rc<str>,
pub codegen_location: Location,
pub preallocate_stack_slots: u32,
/* private fields */
}
Expand description
A chunk of bytecode.
Fields
module_name: Rc<str>
The name of the module where the chunk is located.
codegen_location: Location
The location emitted for each quad-byte on calls to push
.
preallocate_stack_slots: u32
How many stack slots to preallocate with nil
values for variable lookups.
Implementations
sourceimpl Chunk
impl Chunk
sourcepub fn emit(&mut self, instruction: impl EncodeInstruction) -> usize
pub fn emit(&mut self, instruction: impl EncodeInstruction) -> usize
Pushes an encodable piece of data into the chunk. Returns where it’s located.
sourcepub fn emit_number(&mut self, number: f64)
pub fn emit_number(&mut self, number: f64)
Pushes a number into the chunk.
sourcepub fn emit_string(&mut self, string: &str)
pub fn emit_string(&mut self, string: &str)
Pushes a string into the chunk.
The string is padded with zeroes such that opcodes are aligned to four bytes.
sourcepub fn patch(&mut self, position: usize, instruction: impl EncodeInstruction)
pub fn patch(&mut self, position: usize, instruction: impl EncodeInstruction)
Patches the instruction at the given position.
sourcepub unsafe fn read_instruction(&self, pc: &mut usize) -> (Opcode, Opr24)
pub unsafe fn read_instruction(&self, pc: &mut usize) -> (Opcode, Opr24)
Reads an instruction.
Safety
Assumes that pc
is within the chunk’s bounds and that the opcode at pc
is valid.
sourcepub unsafe fn read_number(&self, pc: &mut usize) -> f64
pub unsafe fn read_number(&self, pc: &mut usize) -> f64
sourcepub unsafe fn read_string(&self, pc: &mut usize) -> &str
pub unsafe fn read_string(&self, pc: &mut usize) -> &str
Reads a string.
Safety
This assumes the original string was encoded as proper UTF-8 (which it should
have been considering the only way to write a string is to use a &str
in the first place).
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Chunk
impl !Send for Chunk
impl !Sync for Chunk
impl Unpin for Chunk
impl UnwindSafe for Chunk
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more