-
Notifications
You must be signed in to change notification settings - Fork 1
/
chunk.h
37 lines (30 loc) · 813 Bytes
/
chunk.h
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
37
#ifndef clox_chunk_h
#define clox_chunk_h
#include "opcodes.h"
#include "value.h"
typedef uint8_t Upvalue; // lower 7 bits index, highest bit set if local
#define UV_INDEX(u) ((u)&0x7f)
#define UV_ISLOC(u) ((u)&0x80)
#define LOCAL_MASK 0x80
#define ARITY_MASK 0x7f
#define REST_PARM_MASK 0x80
typedef struct {
int16_t offset;
int16_t line;
} LineStart;
typedef struct {
int16_t count;
int16_t capacity;
uint8_t* code;
int16_t lineCount;
int16_t lineCapacity;
LineStart* lines;
ValueArray constants;
} Chunk;
void initChunk(Chunk* chunk);
void freeChunk(Chunk* chunk);
void freezeChunk(Chunk* chunk);
void writeChunk(Chunk* chunk, int byte, int line);
int addConstant(Chunk* chunk, Value value);
int getLine(Chunk* chunk, int offset);
#endif