KrkChunk Struct Reference

Opcode chunk of a code object. More...

#include <chunk.h>

Public Member Functions

void krk_initChunk (KrkChunk *chunk)
 Initialize an opcode chunk.
void krk_writeChunk (KrkChunk *chunk, uint8_t byte, size_t line)
 Append a byte to an opcode chunk.
void krk_freeChunk (KrkChunk *chunk)
 Release the resources allocated to an opcode chunk.
size_t krk_addConstant (KrkChunk *chunk, KrkValue value)
 Add a new constant value to an opcode chunk.
void krk_emitConstant (KrkChunk *chunk, size_t ind, size_t line)
 Write an OP_CONSTANT(_LONG) instruction.
size_t krk_writeConstant (KrkChunk *chunk, KrkValue value, size_t line)
 Add a new constant and write an instruction for it.
size_t krk_lineNumber (KrkChunk *chunk, size_t offset)
 Obtain the line number for a byte offset into a bytecode chunk. More...

Data Fields

size_t count
size_t capacity
uint8_t * code
size_t linesCount
size_t linesCapacity
struct KrkStringfilename
KrkValueArray constants

Detailed Description

Opcode chunk of a code object.

Opcode chunks are internal to code objects and I'm not really sure why we're still separating them from the KrkCodeObjects.

Stores four flexible arrays using three different formats:

  • Code, representing opcodes and operands.
  • Lines, representing offset-to-line mappings.
  • Filename, the string name of the source file.
  • Constants, an array of values referenced by the code object.

Definition at line 36 of file chunk.h.

Member Function Documentation

◆ krk_lineNumber()

size_t krk_lineNumber ( KrkChunk chunk,
size_t  offset 

Obtain the line number for a byte offset into a bytecode chunk.

Scans the line mapping table for the given chunk to find the correct line number from the original source file for the instruction at byte index 'offset'.

chunkBytecode chunk containing the instruction.
offsetByte offset of the instruction to locate.
Line number, 1-indexed.

Definition at line 75 of file chunk.c.

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