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

Constructs an empty chunk.

Pushes an encodable piece of data into the chunk. Returns where it’s located.

Pushes a number into the chunk.

Pushes a string into the chunk.

The string is padded with zeroes such that opcodes are aligned to four bytes.

Patches the instruction at the given position.

Reads an instruction.

Safety

Assumes that pc is within the chunk’s bounds and that the opcode at pc is valid.

Reads a number.

Safety

Assumes that pc is within the chunk’s bounds, skipping any checks.

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).

Returns the length of the chunk (in bytes).

Returns whether the chunk is empty.

Returns the location (in file) of the program counter.

Returns whether the given program counter is at the end of the chunk.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.