Implement a basic VM that is capable of simple math. Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
29 lines
417 B
C
29 lines
417 B
C
#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 */
|