-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompiler.h
69 lines (56 loc) · 1.95 KB
/
Compiler.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <vector>
#include "Chunk.h"
#include "Ast.h"
#include "Value.h"
#include "Object.h"
#include "SymbolTable.h"
class COMPUTE_DUCK_API Compiler
{
public:
Compiler() = default;
~Compiler();
FunctionObject *Compile(const std::vector<Stmt *> &stmts);
private:
enum class RWState
{
READ,
WRITE,
};
void ResetStatus();
void CompileStmt(Stmt *stmt);
void CompileExprStmt(ExprStmt *stmt);
void CompileIfStmt(IfStmt *stmt);
void CompileScopeStmt(ScopeStmt *stmt);
void CompileWhileStmt(WhileStmt *stmt);
void CompileReturnStmt(ReturnStmt *stmt);
void CompileStructStmt(StructStmt *stmt);
void CompileDllImportStmt(DllImportStmt *stmt);
void CompileExpr(Expr *expr, const RWState &state = RWState::READ);
void CompileBinaryExpr(BinaryExpr *expr);
void CompileNumExpr(NumExpr *expr);
void CompileBoolExpr(BoolExpr *expr);
void CompileUnaryExpr(UnaryExpr *expr);
void CompileStrExpr(StrExpr *expr);
void CompileNilExpr(NilExpr *expr);
void CompileGroupExpr(GroupExpr *expr);
void CompileArrayExpr(ArrayExpr *expr);
void CompileIndexExpr(IndexExpr *expr, const RWState &state);
void CompileIdentifierExpr(IdentifierExpr *expr, const RWState &state = RWState::READ);
void CompileFunctionExpr(FunctionExpr *expr);
void CompileFunctionCallExpr(FunctionCallExpr *expr);
void CompileStructCallExpr(StructCallExpr *expr, const RWState &state);
void CompileRefExpr(RefExpr *expr);
void CompileStructExpr(StructExpr *expr);
void EnterScope();
void ExitScope();
Chunk &CurChunk();
uint32_t Emit(int16_t opcode);
uint32_t EmitConstant(const Value &value);
void ModifyOpCode(uint32_t pos, int16_t opcode);
void DefineSymbol(const Symbol &symbol);
void LoadSymbol(const Symbol &symbol);
void StoreSymbol(const Symbol &symbol);
std::vector<Chunk> m_ScopeChunks;
SymbolTable *m_SymbolTable{nullptr};
};