-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterpreter.h
112 lines (84 loc) · 1.9 KB
/
Interpreter.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Interpreter.h
* lex
*
* Created by Alexandru Chiculita on 9/12/09.
*
*/
#ifndef INTERPRETER_H
#define INTERPRETER_H
#include <vector>
#include <string>
#include "Collector.h"
union Bytecode;
class GlobalData;
class CollectorRef;
class ObjectType;
class VectorType;
class RefString: public CollectorRef
{
public:
RefString(std::string value)
: Value (value)
{
}
std::string Value;
virtual Type* GetType() const;
};
class RefObject: public CollectorRef
{
public:
RefObject(ObjectType* type);
virtual ~RefObject();
virtual void Mark();
template <typename T>
T ReadAtOffset(int offset)
{
return *(reinterpret_cast<T*>(&m_buffer[offset]));
}
template <typename T>
void WriteAtOffset(int offset, T value)
{
*(reinterpret_cast<T*>(&m_buffer[offset])) = value;
}
virtual Type* GetType() const;
private:
ObjectType* m_type;
char* m_buffer;
};
class RefVector: public CollectorRef
{
public:
RefVector(VectorType* type, int size);
virtual ~RefVector();
virtual void Mark();
template <typename T>
T ReadAtOffset(int offset)
{
CheckSpace(offset);
return *(reinterpret_cast<T*>(&m_buffer[offset]));
}
template <typename T>
void WriteAtOffset(int offset, T value)
{
CheckSpace(offset);
*(reinterpret_cast<T*>(&m_buffer[offset])) = value;
}
char* GetBuffer() const { return m_buffer; }
int GetSize() const { return m_size; }
virtual Type* GetType() const;
private:
void CheckSpace(int offset);
VectorType* m_type;
char* m_buffer;
int m_bufferSize;
int m_size;
};
union RegisterValue
{
int asInt;
double asFloat;
CollectorRef* asReference;
};
void Interpret(GlobalData* globalData, RegisterValue* registers, std::vector<Bytecode>* buffer);
#endif // INTERPRETER_H