Struct tvix_eval::chunk::Chunk

source ·
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

source

pub fn push_op(&mut self, op: Op, span: Span) -> usize

source

pub fn push_uvarint(&mut self, data: u64)

source

pub fn read_uvarint(&self, idx: usize) -> (u64, usize)

source

pub fn push_u16(&mut self, data: u16)

source

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.

source

pub fn read_u16(&self, idx: usize) -> u16

source

pub fn first_span(&self) -> Span

Get the first span of a chunk, no questions asked.

source

pub fn last_op(&self) -> Option<(Op, usize)>

Return the last op in the chunk together with its index, if any.

source

pub fn push_constant(&mut self, data: Value) -> ConstantIdx

source

pub fn get_constant(&self, constant: ConstantIdx) -> Option<&Value>

Return a reference to the constant at the given ConstantIdx

source

fn push_span(&mut self, span: Span, start: usize)

source

pub fn get_span(&self, offset: CodeIdx) -> Span

Retrieve the codemap::Span from which the instruction at offset was compiled.

source

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§

source§

impl Debug for Chunk

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Chunk

source§

fn default() -> Chunk

Returns the “default value” for a type. Read more

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V