crafting-interpreters/clox/src/chunk.h

54 lines
804 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-25 21:49:54 -07:00
OP_GET_LOCAL,
OP_SET_LOCAL,
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,
2022-05-31 23:02:18 -07:00
OP_GET_UPVALUE,
OP_SET_UPVALUE,
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,
2022-01-12 22:58:10 -08:00
OP_JUMP,
OP_JUMP_IF_FALSE,
2022-01-12 23:09:36 -08:00
OP_LOOP,
2022-03-15 00:39:11 -07:00
OP_CALL,
2022-03-23 17:00:22 -07:00
OP_CLOSURE,
2022-06-02 22:27:43 -07:00
OP_CLOSE_UPVALUE,
2021-07-08 02:24:24 -07:00
OP_RETURN,
2022-08-12 21:17:45 -07:00
OP_CLASS,
2021-07-08 02:24:24 -07:00
} 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