-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm.h
53 lines (40 loc) · 1.23 KB
/
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
#ifndef file_vm_h
#define file_vm_h
#include "chunk.h"
#include "table.h"
#include "value.h"
#include "object.h"
#include "include/roto.h"
#define FRAMES_MAX 64
#define STACK_MAX (FRAMES_MAX * UINT8_COUNT)
//single ongoing function call
typedef struct{
ObjClosure* closure;
uint8_t* ip;
Value* slots;//points to VMs value stack at the first slot the function can use
} CallFrame;
struct _rotoVM{
CallFrame frames[FRAMES_MAX];
int frameCount;//height of the callframe stack
Value stack[STACK_MAX];//stack
Value *stack_top; //the top or beginning of the stack
Table strings; //for string interning
ObjString* init_string;
Table globals; //for globals
Table listMethods;
ObjUpvalue* open_upvalues;
uint8_t next_op_wide;
size_t bytes_alocated;//running total of no of bytes of managed memory
size_t next_gc;//threshold that triggers next collection
Obj* objects;
int gray_count;
int gray_capacity;
Obj** gray_stack;
};
void push(RotoVM* vm, Value value);
Value pop(RotoVM* vm);
void append_to_list(RotoVM* vm,ObjList* list, Value value);
bool is_valid_list_index(ObjList* list, int index);
void delete_from_list(ObjList* list, int index);
void runtime_error(RotoVM* vm,const char *format, ...);
#endif