-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk.h
42 lines (36 loc) · 927 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
38
39
40
41
42
//
// Created by JP Ramassini on 10/23/2019.
//
#ifndef CLOX_CHUNK_H
#define CLOX_CHUNK_H
#include "common.h"
#include "value.h"
// Enum to hold all possible opcodes.
typedef enum {
OP_CONSTANT,
OP_NIL,
OP_TRUE,
OP_FALSE,
OP_EQUAL,
OP_GREATER,
OP_LESS,
OP_ADD,
OP_SUBTRACT,
OP_MULTIPLY,
OP_DIVIDE,
OP_NOT,
OP_NEGATE,
OP_RETURN, // Used to tell VM to return from current function.
} OpCode;
typedef struct {
int count; // How many elements are in use.
int capacity;
uint8_t* code; // Note: We don't know how much memory a chunk will require on instantiation,
ValueArray constants; // hence the pointer to a dynamic array.
int* lines;
} Chunk;
void initChunk(Chunk* chunk);
void freeChunk(Chunk* chunk);
void writeChunk(Chunk* chunk, uint8_t byte, int line);
int addConstant(Chunk* chunk, Value value);
#endif // CLOX_CHUNK_H