blob: 9457fa96abe4a136c051a719115db98ef283a923 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#ifndef BDL_CHUNK_H
#define BDL_CHUNK_H
#include "darray.h"
#include "string_view.h"
typedef struct Object Object;
typedef struct LineInfo {
size_t line;
size_t col;
} LineInfo;
typedef struct Chunk {
// Program code.
u8 *code;
// Compile time constants.
Object *constants;
// Contains debugging information for every code operation.
LineInfo *lines;
// Chunk name.
char *name;
// Number of locals and parameters.
size_t n_params;
size_t n_locals;
} Chunk;
#define NEW_CHUNK(NAME) chunk_init((StringView){(NAME), sizeof(NAME) - 1})
Chunk * chunk_init(StringView name);
void add_code(Chunk *chunk, u8 byte, size_t line, size_t col);
size_t add_constant(Chunk *chunk, Object obj);
void chunk_free(Chunk *chunk);
#endif // BDL_CHUNK_H
|