Sen API
Sen Libraries
Loading...
Searching...
No Matches
sen::lang::Chunk Class Reference

A chunk of byte code. It holds code and constants needed by the code. Constants are accessed by index. More...

#include <vm.h>

Public Member Functions

 Chunk ()=default
 ~Chunk ()=default
void disassemble (const std::string &name) const
 Prints a human-readable view of the chunk.
uint8_t addConstant (const Value &value)
 Stores a constant and returns the index that can be used to refer to it.
const ValuegetConstant (uint8_t offset) const
 The constant stored at a given slot.
void addCode (uint8_t byte)
 Appends a byte to the code. The line is just for debugging.
Span< const std::string > getVariables () const
 The variables used by this chunk.
uint8_t getOrRegisterVariable (const std::string &name)
 Registers a variable and obtains the index.
bool isValid () const noexcept
 Returns true if it contains code.
const uint8_t * code () const noexcept
 The stored code.
int count () const noexcept
 The size of the code.
void patch (std::size_t offset, uint8_t byte)
 Patches the a code byte at some offset.
std::size_t disassembleInstruction (std::size_t offset) const
 Prints a human-readable view of the instruction at a given offset.

Static Public Member Functions

static void printValue (const Value &value)
 Prints a value.

Detailed Description

A chunk of byte code. It holds code and constants needed by the code. Constants are accessed by index.

Constructor & Destructor Documentation

◆ Chunk()

sen::lang::Chunk::Chunk ( )
default

◆ ~Chunk()

sen::lang::Chunk::~Chunk ( )
default

Member Function Documentation

◆ disassemble()

void sen::lang::Chunk::disassemble ( const std::string & name) const

Prints a human-readable view of the chunk.

◆ addConstant()

uint8_t sen::lang::Chunk::addConstant ( const Value & value)
nodiscard

Stores a constant and returns the index that can be used to refer to it.

◆ getConstant()

const Value & sen::lang::Chunk::getConstant ( uint8_t offset) const
nodiscard

The constant stored at a given slot.

◆ addCode()

void sen::lang::Chunk::addCode ( uint8_t byte)

Appends a byte to the code. The line is just for debugging.

◆ getVariables()

Span< const std::string > sen::lang::Chunk::getVariables ( ) const
nodiscard

The variables used by this chunk.

◆ getOrRegisterVariable()

uint8_t sen::lang::Chunk::getOrRegisterVariable ( const std::string & name)
nodiscard

Registers a variable and obtains the index.

◆ isValid()

bool sen::lang::Chunk::isValid ( ) const
nodiscardnoexcept

Returns true if it contains code.

◆ code()

const uint8_t * sen::lang::Chunk::code ( ) const
nodiscardnoexcept

The stored code.

◆ count()

int sen::lang::Chunk::count ( ) const
nodiscardnoexcept

The size of the code.

◆ patch()

void sen::lang::Chunk::patch ( std::size_t offset,
uint8_t byte )

Patches the a code byte at some offset.

◆ disassembleInstruction()

std::size_t sen::lang::Chunk::disassembleInstruction ( std::size_t offset) const
nodiscard

Prints a human-readable view of the instruction at a given offset.

◆ printValue()

void sen::lang::Chunk::printValue ( const Value & value)
static

Prints a value.


The documentation for this class was generated from the following file: