-
Notifications
You must be signed in to change notification settings - Fork 2
/
vm.h
56 lines (42 loc) · 876 Bytes
/
vm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef clox_vm_h
#define clox_vm_h
#include "chunk.h"
#include "value.h"
#include "object.h"
#include "table.h"
#define FRAMES_MAX 64
#define STACK_MAX (FRAMES_MAX * UINT8_COUNT)
typedef struct {
ObjClosure* closure;
uint8_t* ip;
Value* slots;
} CallFrame;
typedef struct
{
CallFrame frames[FRAMES_MAX];
int frameCount;
Value stack[STACK_MAX];
Value* stackTop;
Table globals;
Table strings;
Obj* objects;
ObjUpvalue* openUpvalues;
size_t bytesAllocated;
size_t nextGC;
int grayCount;
int grayCapacity;
Obj** grayStack;
ObjString* initString;
}VM;
typedef enum {
INTERPRET_OK,
INTERPRET_RUNTIME_ERROR,
INTERPRET_COMPILE_ERROR,
} InterpretResult;
extern VM vm;
void initVM();
void freeVM();
InterpretResult interpret(const char* source);
void push(Value value);
Value pop();
#endif