-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk.h
84 lines (61 loc) · 1.19 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef peach_chunk_h
#define peach_chunk_h
#include "common.h"
#include "value.h"
typedef enum {
OP_LOAD_CONST,
OP_LOAD_CONST_LONG,
OP_DEF_GLOBAL,
OP_DEF_GLOBAL_LONG,
OP_GET_GLOBAL,
OP_GET_GLOBAL_LONG,
OP_SET_GLOBAL,
OP_SET_GLOBAL_LONG,
OP_GET_LOCAL,
OP_GET_LOCAL_LONG,
OP_SET_LOCAL,
OP_SET_LOCAL_LONG,
OP_GET_UPVALUE,
OP_SET_UPVALUE,
OP_NIL,
OP_TRUE,
OP_FALSE,
OP_NEGATE,
OP_EQUAL,
OP_GREATER,
OP_LESS,
OP_ADD,
OP_SUB,
OP_MUL,
OP_DIV,
OP_NOT,
OP_POP,
OP_PRINT,
OP_RETURN,
OP_JUMP,
OP_JUMP_IF_FALSE,
OP_LOOP,
OP_CALL,
OP_CLOSURE,
OP_CLOSE_UPVALUE,
} OpCode;
typedef struct {
size_t line;
size_t offset;
} LineStart;
typedef struct {
size_t count;
size_t capacity;
uint8_t* code;
ValueArray constants;
LineStart* lines;
size_t line_count;
size_t line_capacity;
} Chunk;
void Chunk_init(Chunk* chunkl);
void Chunk_write(Chunk* chunk, uint8_t byte, size_t line);
void Chunk_write_constant(Chunk* chunk, Value value, size_t line);
size_t Chunk_get_line(Chunk* chunk, size_t instruction);
size_t Chunk_add_constant(Chunk *chunk, Value value);
void Chunk_free(Chunk* chunk);
#endif /* ifndef peach_chunk_h */