-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunk.h
73 lines (63 loc) · 1.11 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
#ifndef FILANG_CHUNK_H
#define FILANG_CHUNK_H
#include <stdint.h>
#include <stddef.h>
#include "value.h"
typedef enum {
OP_ERROR,
OP_RETURN,
OP_ADD,
OP_SUBTRACT,
OP_MULTIPLY,
OP_DIVIDE,
OP_MODULO,
OP_NEGATE,
OP_POW,
OP_NOT,
OP_AND,
OP_OR,
OP_BW_AND,
OP_BW_OR,
OP_XOR,
OP_BW_NOT,
OP_SHIFT_LEFT,
OP_SHIFT_RIGHT,
OP_TERNARY,
OP_PRINT,
OP_GREATER,
OP_LESS,
OP_EQUALS,
OP_NIL,
OP_TRUE,
OP_FALSE,
OP_CONSTANT,
OP_CONSTANT_LONG,
OP_CONSTANT_LONG_LONG,
OP_POP,
OP_DEFINE_GLOBAL,
OP_GET_GLOBAL,
OP_SET_GLOBAL,
OP_GET_LOCAL,
OP_SET_LOCAL,
OP_CLOCK,
OP_TYPEOF,
OP_JUMP,
OP_JUMP_IF_FALSE,
} OpCode;
typedef struct {
int count;
int capacity;
int *ends;
} Lines;
typedef struct {
uint8_t *code;
int count;
int capacity;
Lines lines;
ValueArray constants;
} Chunk;
void init_chunk(Chunk *chunk);
void free_chunk(Chunk *chunk);
void write_chunk(Chunk *chunk, uint8_t byte, int line);
int write_constant(Chunk *chunk, Value value);
#endif //FILANG_CHUNK_H