2021-07-22 10:09:11 +02:00
|
|
|
#ifndef clox_vm_h
|
|
|
|
#define clox_vm_h
|
|
|
|
|
|
|
|
#include "chunk.h"
|
2021-09-18 20:10:11 +02:00
|
|
|
#include "table.h"
|
2021-07-28 07:21:40 +02:00
|
|
|
#include "value.h"
|
|
|
|
|
|
|
|
#define STACK_MAX 256
|
2021-07-22 10:09:11 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Chunk *chunk;
|
|
|
|
uint8_t *ip;
|
2021-07-28 07:21:40 +02:00
|
|
|
Value stack[STACK_MAX];
|
2021-08-03 03:09:03 +02:00
|
|
|
Value *stackTop;
|
2021-09-21 06:47:41 +02:00
|
|
|
Table globals;
|
2021-09-18 20:10:11 +02:00
|
|
|
Table strings;
|
2021-09-10 07:57:03 +02:00
|
|
|
Obj *objects;
|
2021-07-22 10:09:11 +02:00
|
|
|
} VM;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
INTERPRET_OK,
|
|
|
|
INTERPRET_COMPILE_ERROR,
|
|
|
|
INTERPRET_RUNTIME_ERROR
|
|
|
|
} InterpretResult;
|
|
|
|
|
2021-09-10 07:57:03 +02:00
|
|
|
extern VM vm;
|
|
|
|
|
2021-07-22 10:09:11 +02:00
|
|
|
void initVM();
|
|
|
|
void freeVM();
|
2021-08-03 03:09:03 +02:00
|
|
|
InterpretResult interpret(const char *source);
|
2021-07-28 07:21:40 +02:00
|
|
|
void push(Value value);
|
|
|
|
Value pop();
|
2021-07-22 10:09:11 +02:00
|
|
|
|
|
|
|
#endif
|