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: LocationThe location emitted for each quad-byte on calls to push.
preallocate_stack_slots: u32How many stack slots to preallocate with nil values for variable lookups.
Implementations§
Source§impl Chunk
impl Chunk
Sourcepub fn emit(&mut self, what: impl EncodeInstruction) -> usize
pub fn emit(&mut self, what: 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 Freeze for Chunk
impl RefUnwindSafe for Chunk
impl !Send for Chunk
impl !Sync for Chunk
impl Unpin for Chunk
impl UnwindSafe for Chunk
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