-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm.h
39 lines (30 loc) · 940 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
//
// Created by JP Ramassini on 11/2/19.
//
#ifndef CLOX_VM_H
#define CLOX_VM_H
#include "chunk.h"
#include "value.h"
#include "table.h"
#define STACK_MAX 256
typedef struct {
Chunk* chunk;
uint8_t* ip; // NOTE: Point directly to instruction in bytecode array, as dereferencing is faster than an indexed array look. Also, ip stands for Instruction Pointer, just a heads up.
Value stack[STACK_MAX];
Value* stackTop;
Table strings;
Obj* objects; // This points to the head of the linked list of dynamically allocated objects.
} VM;
// NOTE: This is used to set the exit code of the interpret process.
typedef enum {
INTERPRET_OK,
INTERPRET_COMPILE_ERROR,
INTERPRET_RUNTIME_ERROR
} InterpretResult;
extern VM vm;
void initVM();
void freeVM();
InterpretResult interpret(const char* source); // NOTE: This is the main entrypoint to VM
void push(Value value);
Value pop();
#endif //CLOX_VM_H