-
Notifications
You must be signed in to change notification settings - Fork 1
/
Interp.h
45 lines (34 loc) · 1.33 KB
/
Interp.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
#pragma once
#include "Printer.h"
#include "Token.h"
enum Intercept_Kind
{
INTERCEPT_STATEMENT,
INTERCEPT_PROCEDURE_CALL,
INTERCEPT_PROCEDURE_RETURN
};
typedef void(*Intercep_Proc)(struct Interpreter *interp, Intercept_Kind intercept, struct Code_Node *node);
inline void intercept_default(struct Interpreter *interp, Intercept_Kind intercept, struct Code_Node *statement){};
struct Interpreter
{
uint8_t *stack = nullptr;
uint64_t stack_size = 0;
uint8_t *global = nullptr;
uint64_t global_size = 0;
uint64_t stack_top = 0;
int64_t return_count = 0;
int64_t break_count = 0;
int64_t continue_count = 0;
struct Code_Type_Procedure *current_procedure = nullptr;
Symbol_Table *global_symbol_table = nullptr;
struct Heap_Allocator *heap = nullptr;
uint64_t current_row = 0;
struct Code_Type_Resolver *resolver = nullptr;
Intercep_Proc intercept = intercept_default;
void *user_context = nullptr;
};
void interp_init(Interpreter *interp, struct Code_Type_Resolver *resolver, size_t stack_size, size_t bss_size);
void interp_eval_globals(Interpreter *interp, Array_View<Code_Node_Assignment *> exprs);
Code_Node_Procedure_Call *interp_find_main(Interpreter *interp);
void interp_evaluate_procedure(Interpreter *interp, Code_Node_Procedure_Call *proc);
int64_t interp_evaluate_constant_expression(Code_Node_Expression *root);