-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.hpp
48 lines (41 loc) · 1.28 KB
/
Module.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
#pragma once
#include <string>
#include <iostream>
#include "Declarations.hpp"
#include "Identifier.hpp"
#include "Context.hpp"
#include "Statement.hpp"
class Module
{
public:
Module(Identifier moduleName,
Declarations declarations,
StatementSequence mainBlock = StatementSequence()):
moduleName(moduleName),
declarations(declarations),
mainBlock(mainBlock) {}
void declare()
{
//std::cerr << "Running declaration in module " << moduleName << std::endl;
moduleContext.declareType("INTEGER", new IntegerType());
moduleContext.declareType("DOUBLE", new DoubleType());
moduleContext.declareType("BOOLEAN", new BooleanType());
moduleContext.declareType("STRING", new StringType());
declarations.declare(moduleContext);
}
void runMain()
{
//std::cerr << "Running main in module " << moduleName << std::endl;
mainBlock.execute(moduleContext);
}
void runProcedure(Identifier procedureName, ActualParameters* actualParameters)
{
//std::cerr << "Running procedure " << procedureName << " in module " << moduleName << std::endl;
moduleContext.getProcedure(procedureName)->call(actualParameters, moduleContext);
}
private:
Identifier moduleName;
Declarations declarations;
StatementSequence mainBlock;
Context moduleContext;
};