Go to the documentation of this file.
1 #pragma once
6 #include "kuroko.h"
7 #include "value.h"
19 typedef struct {
20  size_t startOffset;
21  size_t line;
22 } KrkLineMap;
36 typedef struct {
37  size_t count;
38  size_t capacity;
39  uint8_t * code;
41  size_t linesCount;
42  size_t linesCapacity;
43  KrkLineMap * lines;
45  struct KrkString * filename;
46  KrkValueArray constants;
47 } KrkChunk;
53 extern void krk_initChunk(KrkChunk * chunk);
59 extern void krk_writeChunk(KrkChunk * chunk, uint8_t byte, size_t line);
65 extern void krk_freeChunk(KrkChunk * chunk);
71 extern size_t krk_addConstant(KrkChunk * chunk, KrkValue value);
77 extern void krk_emitConstant(KrkChunk * chunk, size_t ind, size_t line);
83 extern size_t krk_writeConstant(KrkChunk * chunk, KrkValue value, size_t line);
97 extern size_t krk_lineNumber(KrkChunk * chunk, size_t offset);
Top-level header with configuration macros.
Opcode chunk of a code object.
Definition: chunk.h:36
void krk_initChunk(KrkChunk *chunk)
Initialize an opcode chunk.
Definition: chunk.c:7
void krk_freeChunk(KrkChunk *chunk)
Release the resources allocated to an opcode chunk.
Definition: chunk.c:43
void krk_emitConstant(KrkChunk *chunk, size_t ind, size_t line)
Write an OP_CONSTANT(_LONG) instruction.
Definition: chunk.c:57
size_t krk_writeConstant(KrkChunk *chunk, KrkValue value, size_t line)
Add a new constant and write an instruction for it.
Definition: chunk.c:69
size_t krk_lineNumber(KrkChunk *chunk, size_t offset)
Obtain the line number for a byte offset into a bytecode chunk.
Definition: chunk.c:75
size_t krk_addConstant(KrkChunk *chunk, KrkValue value)
Add a new constant value to an opcode chunk.
Definition: chunk.c:50
void krk_writeChunk(KrkChunk *chunk, uint8_t byte, size_t line)
Append a byte to an opcode chunk.
Definition: chunk.c:31
Map entry of instruction offsets to line numbers.
Definition: chunk.h:19
Immutable sequence of Unicode codepoints.
Definition: object.h:93
Flexible vector of stack references.
Definition: value.h:75
Stack reference or primative value.
Definitions for primitive stack references.