pub struct Chunk {
pub code: Vec<u8>,
pub constants: Vec<Value>,
spans: Vec<SourceSpan>,
last_op: usize,
}
Expand description
A chunk is a representation of a sequence of bytecode instructions, associated constants and additional metadata as emitted by the compiler.
Fields§
§code: Vec<u8>
§constants: Vec<Value>
§spans: Vec<SourceSpan>
§last_op: usize
Index of the last operation (i.e. not data) written to the code vector. Some operations (e.g. jump patching) need to know this.
Implementations§
source§impl Chunk
impl Chunk
pub fn push_op(&mut self, op: Op, span: Span) -> usize
pub fn push_uvarint(&mut self, data: u64)
pub fn read_uvarint(&self, idx: usize) -> (u64, usize)
pub fn push_u16(&mut self, data: u16)
sourcepub fn patch_jump(&mut self, idx: usize)
pub fn patch_jump(&mut self, idx: usize)
Patches the argument to the jump operand of the jump at the given index to point to the next instruction that will be emitted.
pub fn read_u16(&self, idx: usize) -> u16
sourcepub fn first_span(&self) -> Span
pub fn first_span(&self) -> Span
Get the first span of a chunk, no questions asked.
sourcepub fn last_op(&self) -> Option<(Op, usize)>
pub fn last_op(&self) -> Option<(Op, usize)>
Return the last op in the chunk together with its index, if any.
pub fn push_constant(&mut self, data: Value) -> ConstantIdx
sourcepub fn get_constant(&self, constant: ConstantIdx) -> Option<&Value>
pub fn get_constant(&self, constant: ConstantIdx) -> Option<&Value>
Return a reference to the constant at the given ConstantIdx
fn push_span(&mut self, span: Span, start: usize)
sourcepub fn get_span(&self, offset: CodeIdx) -> Span
pub fn get_span(&self, offset: CodeIdx) -> Span
Retrieve the codemap::Span from which the instruction at
offset
was compiled.
sourcepub fn disassemble_op<W: Write>(
&self,
writer: &mut W,
source: &SourceCode,
width: usize,
idx: CodeIdx,
) -> Result<usize, Error>
pub fn disassemble_op<W: Write>( &self, writer: &mut W, source: &SourceCode, width: usize, idx: CodeIdx, ) -> Result<usize, Error>
Write the disassembler representation of the operation at
idx
to the specified writer, and return how many bytes in the code to
skip for the next op.
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more