-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm.h
executable file
·52 lines (41 loc) · 975 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
#ifndef CLOX_VM_H
#define CLOX_VM_H
#include "chunk.h"
#include "object.h"
#include "table.h"
#include "value.h"
#define FRAMES_MAX 64
#define STACK_MAX (FRAMES_MAX * UINT8_COUNT)
typedef struct {
obj_closure_t* closure;
uint8_t* ip;
value_t* slots;
} call_frame_t;
typedef struct {
call_frame_t frames[STACK_MAX];
int frame_count;
value_t stack[STACK_MAX];
value_t *stack_top;
table_t globals;
table_t strings;
obj_string_t* init_string;
obj_upvalue_t* open_upvalues;
size_t bytes_allocated;
size_t next_gc;
object_t* objects;
int gray_count;
int gray_capacity;
object_t** gray_stack;
} vm_t;
typedef enum {
INTERPRET_OK,
INTERPRET_COMPILE_ERROR,
INTERPRET_RUNTIME_ERROR
} interpret_result_t;
extern vm_t vm;
void init_vm();
void free_vm();
interpret_result_t interpret(const char* source);
void push(value_t value);
value_t pop();
#endif