-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner.hpp
50 lines (40 loc) · 1.14 KB
/
runner.hpp
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
#pragma once
#include "ast.hpp"
class Runner {
public:
bool _return = false;
ASTNode *error = nullptr;
Runner(ASTNode *ast, std::istream &code);
void run(void *out);
void *alloc(int size);
void generateFunction(std::string name, std::vector<ASTFunctionArg *> args,
void (*body)(Runner *, RunnerStackFrame *),
ASTType *ret = new ASTBaseType("void"));
void gc();
void enterFrame();
void exitFrame();
void errorAt(const ASTNode *node, std::string msg);
private:
ASTNode *ast_;
RunnerStackFrame *stackFrame_;
std::istream &code_;
};
class RunnerStackFrame {
public:
RunnerStackFrame(RunnerStackFrame *parent = nullptr);
~RunnerStackFrame();
class Variable {
public:
Variable(void *ptr, ASTType *type);
void *ptr_;
ASTType *type_;
};
Variable *getVariable(const std::string &name);
template <typename T>
T getVariable(const std::string &name) {
return *(T *)this->getVariable(name)->ptr_;
};
void *allocVariable(const std::string &name, ASTType *type, Runner *runner);
RunnerStackFrame *parent_;
std::map<std::string, Variable *> variables_;
};