KrkCodeObject Struct Reference

Code object. More...

#include <object.h>

Inheritance diagram for KrkCodeObject:

Public Member Functions

void krk_debug_addExpression (KrkCodeObject *codeobject, uint8_t start, uint8_t midStart, uint8_t midEnd, uint8_t end)
 Add an expression mapping to the bytecode chunk. More...
 
int krk_debug_expressionUnderline (const KrkCodeObject *codeobject, uint8_t *start, uint8_t *midStart, uint8_t *endStart, uint8_t *end, size_t instruction)
 Extract expression mapping from chunk. More...
 
KrkCodeObjectkrk_newCodeObject (void)
 Create a new, uninitialized code object. More...
 

Data Fields

unsigned short requiredArgs
 Arity of required (non-default) arguments.
 
unsigned short keywordArgs
 Arity of keyword (default) arguments.
 
unsigned short potentialPositionals
 Precalculated positional arguments for complex argument processing.
 
unsigned short totalArguments
 Total argument cells we can fill in complex argument processing.
 
size_t upvalueCount
 Number of upvalues this function collects as a closure.
 
KrkChunk chunk
 Bytecode data.
 
KrkStringname
 Name of the function.
 
KrkStringdocstring
 Docstring attached to the function.
 
KrkValueArray positionalArgNames
 Array of names for positional arguments (and *args)
 
KrkValueArray keywordArgNames
 Array of names for keyword-only arguments (and **kwargs)
 
size_t localNameCapacity
 Capacity of localNames.
 
size_t localNameCount
 Number of entries in localNames.
 
KrkLocalEntrylocalNames
 Stores the names of local variables used in the function, for debugging.
 
KrkStringqualname
 The dotted name of the function.
 
size_t expressionsCapacity
 Capacity of expressions.
 
size_t expressionsCount
 Number of entries in expressions.
 
KrkExpressionsMapexpressions
 Mapping of bytecode offsets to expression spans for debugging.
 
KrkValue jumpTargets
 Possibly a set of jump targets...
 
KrkOverlongJumpoverlongJumps
 Pessimal overlong jump container.
 
size_t overlongJumpsCapacity
 Number of possible entries in pessimal jump table.
 
size_t overlongJumpsCount
 Number of entries in pessimal jump table.
 
- Data Fields inherited from KrkObj
uint16_t type
 Tag indicating core type.
 
uint16_t flags
 General object flags, mostly related to garbage collection.
 
uint32_t hash
 Cached hash value for table keys.
 
struct KrkObjnext
 Invasive linked list of all objects in the VM.
 

Protected Attributes

KrkObj obj
 Base.
 

Detailed Description

Code object.

Contains the static data associated with a chunk of bytecode.

Definition at line 163 of file object.h.

Member Function Documentation

◆ krk_debug_addExpression()

void krk_debug_addExpression ( KrkCodeObject codeobject,
uint8_t  start,
uint8_t  midStart,
uint8_t  midEnd,
uint8_t  end 
)

Add an expression mapping to the bytecode chunk.

Associates a span of columns representing an expression with the current opcode offset. Used to supply debug information displayed in tracebacks with tildes and carets.

Parameters
codeobjectCodeobject containing the instruction.
startFirst column, 1-indexed, of tildes, left side of expression.
midStartFirst column, 1-indexed, of carets, main token of expression.
midEndLast column, 1-indexed, of carets, main token of expression.
endLast column, 1-indexed, of tildes, right side of expression.

Definition at line 705 of file debug.c.

◆ krk_debug_expressionUnderline()

int krk_debug_expressionUnderline ( const KrkCodeObject codeobject,
uint8_t *  start,
uint8_t *  midStart,
uint8_t *  endStart,
uint8_t *  end,
size_t  instruction 
)

Extract expression mapping from chunk.

Searches the debug information for the requested instruction to find an expression mapping and extracts the column values for underlining.

Parameters
codeobjectCodeobject containing the instruction.
startFirst column, 1-indexed, of tildes, left side of expression.
midStartFirst column, 1-indexed, of carets, main token of expression.
midEndLast column, 1-indexed, of carets, main token of expression.
endLast column, 1-indexed, of tildes, right side of expression.
instructionOffset of the last byte of an opcode, as is stored in a traceback entry.
Returns
Non-zero if a mapping was found.

Definition at line 726 of file debug.c.

◆ krk_newCodeObject()

KrkCodeObject * krk_newCodeObject ( void  )

Create a new, uninitialized code object.

The code object will have an empty bytecode chunk and no assigned names or docstrings. This is intended only to be used by a compiler directly.

Definition at line 264 of file object.c.


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