-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBoxProgram.h
More file actions
93 lines (75 loc) · 1.78 KB
/
BoxProgram.h
File metadata and controls
93 lines (75 loc) · 1.78 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef BOXPROGRAM_H
#define BOXPROGRAM_H
#include "BoxInfo.h"
#include "ProgramMonitor.h"
#include "InvokeBox.h"
#include "Execute.h"
#include "OperationFormat.h"
#include "BoxInstruction.h"
#include "BoxInstructionSet.h"
#include "BoxTrace.h"
#define DATA_TYPE_END '@'
class BoxProgram {
public:
void invoke(char *);
void initStack();
void initHeap();
void addArgument(Data *data);
void initInstructions();
void execute();
protected:
InvokeBox boxfile;
Stack stack;
Heap heap;
BoxInstructionSet boxInstructionSet;
};
void BoxProgram::invoke(char *boxFilePath)
{
TRACE("BOX_PROGRAM", "invoke(\"%s\")", boxFilePath);
boxfile.invoke(boxFilePath);
}
void BoxProgram::initStack()
{
Type datatype = 0;
char buffer[MAX_BUFFER_WORD] = { 0 };
TRACE("BOX_PROGRAM", "initStack()");
while (EOK)
{
boxfile.read((Byte *)&datatype, 1);
if (datatype == DATA_TYPE_END)
return;
boxfile.read(buffer, DATA_TYPES_SIZE[datatype]);
stack.addData(datatype, buffer);
}
}
void BoxProgram::initHeap()
{
Type datatype = 0;
TRACE("BOX_PROGRAM", "initHeap()");
while (1)
{
boxfile.read((Byte *)&datatype, 1);
if (datatype == START)
break;
heap.addPointer(datatype);
}
}
void BoxProgram::addArgument(Data *data)
{
stack.addData(data->getType(), data->getAddress());
}
void BoxProgram::execute()
{
TRACE("BOX_PROGRAM", "execute()");
boxInstructionSet.execute(heap);
}
void BoxProgram::initInstructions()
{
OperationFormat *programCounter = (OperationFormat *)boxfile.getPc();
do
{
programCounter++;
boxInstructionSet.add(programCounter, heap, stack);
} while (programCounter->opCode != ESTART);
}
#endif //BOXPROGRAM_H