-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm.h
47 lines (37 loc) · 778 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
//
// Created by Fabian Simon on 29.09.23.
//
#ifndef FAVE_CUH_VM_H
#define FAVE_CUH_VM_H
#include "chunk.h"
#include "value.h"
#include "table.h"
#include "object.h"
#define FRAMES_MAX 64
#define STACK_MAX (FRAMES_MAX * UINT8_COUNT)
typedef struct {
ObjFunction* function;
uint8_t * ip;
Value* slots;
} CallFrame;
typedef struct {
CallFrame frames[FRAMES_MAX];
int frame_count;
Value stack[STACK_MAX];
Value* stack_top;
Table strings;
Table globals;
Obj* objects;
} VM;
typedef enum {
INTERPRET_OK,
INTERPRET_COMPILE_ERROR,
INTERPRET_RUNTIME_ERROR
} InterpretResult;
extern VM vm;
void init_VM();
void free_VM();
InterpretResult interpret(const char* src);
void push(Value val);
Value pop();
#endif //FAVE_CUH_VM_H