Finish Chapter 15

Implement a basic VM that is capable of simple math.

Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
2025-08-21 20:30:02 -05:00
parent cb203282e5
commit 8df0ffb7e5
6 changed files with 152 additions and 0 deletions

28
include/vm.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef clox_vm_h
#define clox_vm_h
#include "chunk.h"
#define STACK_MAX 256
typedef struct {
Chunk *chunk;
uint8_t *ip;
Value stack[STACK_MAX];
Value *stackTop;
} VM;
typedef enum {
INTERPRET_OK,
INTERPRET_COMPILE_ERROR,
INTERPRET_RUNTIME_ERROR
} InterpretResult;
void initVM();
void freeVM();
InterpretResult interpret(Chunk *chunk);
void push(Value value);
Value pop();
#endif /* clox_vm_h */