aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/chunk.h
blob: c584d4ac59a7e2ca7ef63047a8723fa91e32832f (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;
    // Parameters
    StringView *params;
    // Locals.
    StringView *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