clox/include/vm.h

33 lines
482 B
C
Raw Normal View History

2024-09-08 20:57:08 +00:00
#ifndef VM_H
#define VM_H
2024-09-01 22:43:28 +00:00
#include "chunk.h"
2024-09-02 22:15:41 +00:00
#include "value.h"
2024-09-01 22:43:28 +00:00
2024-09-02 22:15:41 +00:00
#define STACK_MAX 256
2024-09-01 22:43:28 +00:00
typedef struct {
Chunk *chunk;
2024-09-02 22:15:41 +00:00
uint8_t *ip;
Value stack[STACK_MAX];
Value *stackTop;
2024-09-01 22:43:28 +00:00
} VM;
2024-09-02 22:15:41 +00:00
typedef enum {
INTERPRET_OK,
INTERPRET_COMPILE_ERROR,
INTERPRET_RUNTIME_ERROR,
INTERPRET_RESULT_COUNT,
} InterpretResult;
2024-09-08 20:57:08 +00:00
extern VM vm;
2024-09-01 22:43:28 +00:00
void initVM(void);
void freeVM(void);
2024-09-08 20:57:08 +00:00
InterpretResult interpret(const char *source);
2024-09-02 22:15:41 +00:00
void push(Value value);
Value pop();
2024-09-01 22:43:28 +00:00
#endif