Repository navigation
Expand file tree
/
Copy pathVM.cs
More file actions
203 lines (177 loc) · 4.85 KB
/
Copy pathVM.cs
File metadata and controls
203 lines (177 loc) · 4.85 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Xml.Serialization;
using QsScript.Help;
namespace QsScript {
public enum BreakType
{
None = 0,
Continue = 1,
Break = 2,
Return = 4,
Throw = 8,
Exit = 16,
Loop = Continue | Break,
Method = Return,
}
[Serializable]
public static class VM {
public readonly static XmlSerializer Serializer = new XmlSerializer(typeof(Expression));
private readonly static Stack Scops = new Stack();
public readonly static Stack CleanedScop = new Stack();
public readonly static Stack DirtyScops = new Stack();
public static void Reset() {
JumperCode = 0;
IsBreak = false;
IsContinue = false;
IsReturn = false;
IsThrow = false;
BreakValue = null;
ReturnValue = null;
ThrowValue = null;
while(Scops.Count > 0) {
var s = Scops.Pop();
if(s == null)
continue;
s.Dispose();
CleanedScop.Push(s);
}
OpenScop();
GlobalScop = CurrentScop;
}
internal static BasicObject ImportAssemblyFromUrl(string assembly) {
throw new NotImplementedException();
}
internal static BasicObject ImportAssemblyFromFile(string assembly) {
throw new NotImplementedException();
}
internal static BasicObject ImportAssemblyFromGaG(string assembly) {
throw new NotImplementedException();
}
public static BasicObject CurrentScop { get; private set; }
static VM() {
OpenScop();
}
public static BasicObject GlobalScop { get; private set; }
public static void OpenScop() {
Scops.Push(CurrentScop);
CurrentScop = CleanedScop.Pop() ?? new Scop(null) { isMultiScops = true };
CurrentScop.Initialize();
}
internal static void SetScop(BasicObject scop) {
Scops.Push(CurrentScop);
CurrentScop = scop;
}
public static void OpenScop(BasicObject scop) {
Scops.Push(CurrentScop);
CurrentScop = scop;
scop.Initialize();
}
public static void CloseScop(bool safe = false) {
if(!safe) {
CurrentScop.Dispose();
CleanedScop.Push(CurrentScop);
}
CurrentScop = Scops.Pop();
}
internal static void AddFunction(Function function) {
CurrentScop.Add(function);
}
public static int JumperCode { get; private set; }
#region Throw
public static bool IsThrow { get; private set; }
private static BasicObject ThrowValue;
internal static void SetThrow(BasicObject value) {
JumperCode = 5;
IsThrow = true;
ThrowValue = value;
}
internal static BasicObject StopThrow() {
JumperCode = 0;
IsThrow = false;
var l = ThrowValue;
ThrowValue = null;
return l;
}
#endregion
#region Return
public static bool IsReturn { get; private set; }
private static BasicObject ReturnValue;
internal static BasicObject GetCleanScop(BasicObject scop) {
var x = CleanedScop.Pop();
if(x == null)
return new Scop(scop) { isMultiScops = true };
if(x is Scop)
((Scop) x).Base = scop;
return x;
}
internal static void SetReturn(BasicObject value) {
JumperCode = 4;
ReturnValue = value;
IsReturn = true;
}
internal static BasicObject StopReturn() {
JumperCode = 0;
IsReturn = false;
var l = ReturnValue;
ReturnValue = null;
return l;
}
#endregion
#region Break
public static int _breakType = 0;
public static bool IsLoopBreak => (_breakType & (int)BreakType.Loop) != 0;
public static bool IsFunctionBreak => (_breakType & (int)BreakType.Method) != 0;
public static BreakType Break
{
get => (BreakType)_breakType; set
{
if (_breakType != 0) throw new System.Exception("CodeBreack {" + (BreakType)_breakType + "} cannot be applyied");
_breakType = (int)value;
}
}
public static bool CanBlockContinue => _breakType != (int)BreakType.None;
public static bool CanLoopContinue => _breakType > (int)BreakType.Continue;
public static bool IsBreak { get; private set; }
private static BasicObject BreakValue;
internal static void SetBreak(BasicObject value) {
JumperCode = 3;
IsBreak = true;
BreakValue = value;
}
internal static BasicObject StopBreak() {
JumperCode = 0;
IsBreak = false;
var l = BreakValue;
BreakValue = null;
return l;
}
#endregion
#region Continue
public static bool IsContinue { get; private set; }
internal static void SetContinue() {
JumperCode = 2;
IsContinue = true;
}
internal static void StopContinue() {
JumperCode = 0;
IsContinue = false;
}
#endregion
#region Back
public static bool IsBack { get; private set; }
private static BasicObject BackValue;
internal static void SetBack(BasicObject value) {
JumperCode = 1;
IsBack = true;
BackValue = value;
}
internal static BasicObject StopBack() {
JumperCode = 0;
IsBack = false;
var l = BackValue;
BackValue = null;
return l;
}
#endregion
}
}