-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvmcontext.hpp
More file actions
77 lines (63 loc) · 1.94 KB
/
vmcontext.hpp
File metadata and controls
77 lines (63 loc) · 1.94 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
#pragma once
#include <map>
#include <string>
#include <vector>
#include "script.hpp"
#include "value.hpp"
namespace Interpreter {
class VMContext : public CRefCountedThreadSafe<VMContext> {
public:
enum Type {
File,
Function,
For,
Switch,
};
protected:
enum {
CONTINUE_FLAG = (1 << 0),
BREAK_FLAG = (1 << 1),
RETURN_FLAG = (1 << 2),
EXIT_FLAG = (1 << 3),
};
VMContext* mParent;
Type mType;
int mDeepth;
int mFlags;
bool mIsEnableWarning;
Value mReturnValue;
VMContext();
VMContext(const VMContext&);
VMContext& operator=(const VMContext&);
public:
VMContext(Type type, VMContext* Parent);
~VMContext();
void SetEnableWarning(bool val) { mIsEnableWarning = val; }
bool IsTop() { return mParent == NULL; }
bool IsExecutedInterupt() { return (mFlags & 0xFF); }
void CleanContinueFlag() { mFlags &= 0xFE; }
void BreakExecuted();
void ContinueExecuted();
void ExitExecuted(Value exitCode);
void ReturnExecuted(Value retVal);
Value GetReturnValue() { return mReturnValue; }
bool IsReturnAvaliable() { return IsInFunctionContext(); }
bool IsBreakAvaliable() { return mType == For || mType == Switch; }
bool IsContinueAvaliable() { return mType == For; }
bool IsInFunctionContext();
void AddVar(const std::string& name);
void SetVarValue(const std::string& name, Value value);
bool GetVarValue(const std::string& name, Value& val);
Value GetVarValue(const std::string& name);
void AddFunction(const Instruction* function);
const Instruction* GetFunction(const std::string& name);
Value GetTotalFunction();
protected:
void LoadBuiltinVar();
bool IsBuiltinVarName(const std::string& name);
bool IsShadowName(const std::string& name);
private:
std::map<std::string, Value> mVars;
std::map<std::string, const Instruction*> mFunctions;
};
} // namespace Interpreter