crafting-interpreters/clox/src/chunk.h

43 lines
637 B
C
Raw Normal View History

2021-07-08 02:24:24 -07:00
#ifndef clox_chunk_h
#define clox_chunk_h
#include "common.h"
#include "value.h"
typedef enum {
OP_CONSTANT,
2021-09-06 02:03:31 -07:00
OP_NIL,
OP_TRUE,
OP_FALSE,
2021-09-20 21:47:41 -07:00
OP_POP,
2021-10-11 00:13:15 -07:00
OP_GET_GLOBAL,
2021-09-20 21:47:41 -07:00
OP_DEFINE_GLOBAL,
2021-10-21 19:51:01 -07:00
OP_SET_GLOBAL,
2021-09-06 02:03:31 -07:00
OP_EQUAL,
OP_GREATER,
OP_LESS,
2021-07-29 23:56:42 -07:00
OP_ADD,
OP_SUBTRACT,
OP_MULTIPLY,
OP_DIVIDE,
2021-09-06 02:03:31 -07:00
OP_NOT,
2021-07-29 23:38:20 -07:00
OP_NEGATE,
2021-09-20 21:47:41 -07:00
OP_PRINT,
2021-07-08 02:24:24 -07:00
OP_RETURN,
} OpCode;
typedef struct {
int count;
int capacity;
2021-07-29 23:38:20 -07:00
uint8_t *code;
int *lines;
2021-07-08 02:24:24 -07:00
ValueArray constants;
} Chunk;
2021-07-29 23:38:20 -07:00
void initChunk(Chunk *chunk);
void freeChunk(Chunk *chunk);
void writeChunk(Chunk *chunk, uint8_t byte, int line);
int addConstant(Chunk *chunk, Value value);
2021-07-08 02:24:24 -07:00
#endif