greybel-interpreter 1.3.7 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +14 -14
- package/.eslintrc +47 -47
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +109 -109
- package/dist/context.js +383 -382
- package/dist/cps.d.ts +14 -14
- package/dist/cps.js +213 -213
- package/dist/handler/error.d.ts +6 -6
- package/dist/handler/error.js +35 -35
- package/dist/handler/output.d.ts +18 -18
- package/dist/handler/output.js +52 -52
- package/dist/handler/resource.d.ts +12 -12
- package/dist/handler/resource.js +51 -51
- package/dist/handler-container.d.ts +14 -14
- package/dist/handler-container.js +16 -16
- package/dist/index.d.ts +45 -45
- package/dist/index.js +131 -131
- package/dist/interpreter.d.ts +41 -41
- package/dist/interpreter.js +312 -312
- package/dist/intrinsics-container.d.ts +7 -7
- package/dist/intrinsics-container.js +19 -19
- package/dist/operations/assign.d.ts +13 -13
- package/dist/operations/assign.js +111 -111
- package/dist/operations/block.d.ts +12 -12
- package/dist/operations/block.js +108 -108
- package/dist/operations/break.d.ts +10 -10
- package/dist/operations/break.js +41 -41
- package/dist/operations/call.d.ts +13 -13
- package/dist/operations/call.js +124 -124
- package/dist/operations/chunk.d.ts +12 -12
- package/dist/operations/chunk.js +85 -85
- package/dist/operations/continue.d.ts +10 -10
- package/dist/operations/continue.js +41 -41
- package/dist/operations/debugger-statement.d.ts +10 -10
- package/dist/operations/debugger-statement.js +39 -39
- package/dist/operations/evaluate.d.ts +41 -39
- package/dist/operations/evaluate.js +439 -367
- package/dist/operations/for.d.ts +14 -14
- package/dist/operations/for.js +152 -152
- package/dist/operations/function-reference.d.ts +12 -12
- package/dist/operations/function-reference.js +103 -103
- package/dist/operations/function.d.ts +14 -14
- package/dist/operations/function.js +200 -200
- package/dist/operations/if-statement.d.ts +19 -19
- package/dist/operations/if-statement.js +181 -181
- package/dist/operations/import.d.ts +17 -17
- package/dist/operations/import.js +119 -119
- package/dist/operations/include.d.ts +13 -13
- package/dist/operations/include.js +95 -95
- package/dist/operations/list.d.ts +11 -11
- package/dist/operations/list.js +111 -111
- package/dist/operations/literal.d.ts +11 -11
- package/dist/operations/literal.js +58 -58
- package/dist/operations/map.d.ts +11 -11
- package/dist/operations/map.js +171 -171
- package/dist/operations/negated-binary.d.ts +11 -11
- package/dist/operations/negated-binary.js +109 -109
- package/dist/operations/new-instance.d.ts +11 -11
- package/dist/operations/new-instance.js +100 -100
- package/dist/operations/noop.d.ts +9 -9
- package/dist/operations/noop.js +36 -36
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +96 -96
- package/dist/operations/operation.d.ts +13 -13
- package/dist/operations/operation.js +11 -11
- package/dist/operations/reference.d.ts +9 -9
- package/dist/operations/reference.js +37 -37
- package/dist/operations/resolve.d.ts +38 -38
- package/dist/operations/resolve.js +330 -330
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +107 -107
- package/dist/operations/while.d.ts +13 -13
- package/dist/operations/while.js +136 -136
- package/dist/types/boolean.d.ts +11 -11
- package/dist/types/boolean.js +46 -46
- package/dist/types/default.d.ts +11 -11
- package/dist/types/default.js +20 -20
- package/dist/types/function.d.ts +32 -32
- package/dist/types/function.js +174 -174
- package/dist/types/generics.d.ts +18 -18
- package/dist/types/generics.js +40 -40
- package/dist/types/interface.d.ts +23 -23
- package/dist/types/interface.js +103 -103
- package/dist/types/list.d.ts +31 -31
- package/dist/types/list.js +209 -209
- package/dist/types/map.d.ts +37 -37
- package/dist/types/map.js +366 -366
- package/dist/types/nil.d.ts +10 -10
- package/dist/types/nil.js +46 -46
- package/dist/types/number.d.ts +11 -11
- package/dist/types/number.js +46 -46
- package/dist/types/string.d.ts +33 -33
- package/dist/types/string.js +145 -145
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +62 -62
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +59 -59
- package/package.json +58 -58
package/dist/context.js
CHANGED
|
@@ -1,382 +1,383 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
-
};
|
|
45
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
|
|
47
|
-
var handler_container_1 = __importDefault(require("./handler-container"));
|
|
48
|
-
var default_1 = __importDefault(require("./types/default"));
|
|
49
|
-
var generics_1 = require("./types/generics");
|
|
50
|
-
var map_1 = __importDefault(require("./types/map"));
|
|
51
|
-
var path_1 = __importDefault(require("./utils/path"));
|
|
52
|
-
var ContextType;
|
|
53
|
-
(function (ContextType) {
|
|
54
|
-
ContextType[ContextType["Api"] = 0] = "Api";
|
|
55
|
-
ContextType[ContextType["Global"] = 1] = "Global";
|
|
56
|
-
ContextType[ContextType["Function"] = 2] = "Function";
|
|
57
|
-
ContextType[ContextType["External"] = 3] = "External";
|
|
58
|
-
ContextType[ContextType["Loop"] = 4] = "Loop";
|
|
59
|
-
ContextType[ContextType["Map"] = 5] = "Map";
|
|
60
|
-
ContextType[ContextType["Call"] = 6] = "Call";
|
|
61
|
-
})(ContextType = exports.ContextType || (exports.ContextType = {}));
|
|
62
|
-
var ContextState;
|
|
63
|
-
(function (ContextState) {
|
|
64
|
-
ContextState[ContextState["Temporary"] = 0] = "Temporary";
|
|
65
|
-
ContextState[ContextState["Default"] = 1] = "Default";
|
|
66
|
-
})(ContextState = exports.ContextState || (exports.ContextState = {}));
|
|
67
|
-
var Scope = /** @class */ (function (_super) {
|
|
68
|
-
__extends(Scope, _super);
|
|
69
|
-
function Scope(context) {
|
|
70
|
-
var _this = _super.call(this) || this;
|
|
71
|
-
_this.context = context;
|
|
72
|
-
return _this;
|
|
73
|
-
}
|
|
74
|
-
Scope.prototype.get = function (path) {
|
|
75
|
-
if (path instanceof generics_1.CustomValue) {
|
|
76
|
-
return this.get(new path_1.default([path]));
|
|
77
|
-
}
|
|
78
|
-
if (path.count() === 0) {
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
var traversalPath = path.clone();
|
|
82
|
-
var current = traversalPath.next();
|
|
83
|
-
if (current.value === 'locals' || current.value === 'globals') {
|
|
84
|
-
return this.context.get(traversalPath);
|
|
85
|
-
}
|
|
86
|
-
else if (this.has(path)) {
|
|
87
|
-
return _super.prototype.get.call(this, path);
|
|
88
|
-
}
|
|
89
|
-
else if (this.context.api.scope.has(path)) {
|
|
90
|
-
return this.context.api.scope.get(path);
|
|
91
|
-
}
|
|
92
|
-
else if (path.count() === 1 &&
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.
|
|
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
|
-
console.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
this.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.
|
|
193
|
-
this.
|
|
194
|
-
this.
|
|
195
|
-
this.
|
|
196
|
-
this.
|
|
197
|
-
this.
|
|
198
|
-
this.
|
|
199
|
-
this.
|
|
200
|
-
this.
|
|
201
|
-
this.
|
|
202
|
-
this.
|
|
203
|
-
this.
|
|
204
|
-
this.
|
|
205
|
-
this.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
this.
|
|
211
|
-
this.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
var
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
var
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
var
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
OperationContext.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
ContextType.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
+
if (!m) return o;
|
|
20
|
+
var i = m.call(o), r, ar = [], e;
|
|
21
|
+
try {
|
|
22
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
+
}
|
|
24
|
+
catch (error) { e = { error: error }; }
|
|
25
|
+
finally {
|
|
26
|
+
try {
|
|
27
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
+
}
|
|
29
|
+
finally { if (e) throw e.error; }
|
|
30
|
+
}
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
+
if (ar || !(i in from)) {
|
|
36
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
+
ar[i] = from[i];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
+
};
|
|
42
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
|
|
47
|
+
var handler_container_1 = __importDefault(require("./handler-container"));
|
|
48
|
+
var default_1 = __importDefault(require("./types/default"));
|
|
49
|
+
var generics_1 = require("./types/generics");
|
|
50
|
+
var map_1 = __importDefault(require("./types/map"));
|
|
51
|
+
var path_1 = __importDefault(require("./utils/path"));
|
|
52
|
+
var ContextType;
|
|
53
|
+
(function (ContextType) {
|
|
54
|
+
ContextType[ContextType["Api"] = 0] = "Api";
|
|
55
|
+
ContextType[ContextType["Global"] = 1] = "Global";
|
|
56
|
+
ContextType[ContextType["Function"] = 2] = "Function";
|
|
57
|
+
ContextType[ContextType["External"] = 3] = "External";
|
|
58
|
+
ContextType[ContextType["Loop"] = 4] = "Loop";
|
|
59
|
+
ContextType[ContextType["Map"] = 5] = "Map";
|
|
60
|
+
ContextType[ContextType["Call"] = 6] = "Call";
|
|
61
|
+
})(ContextType = exports.ContextType || (exports.ContextType = {}));
|
|
62
|
+
var ContextState;
|
|
63
|
+
(function (ContextState) {
|
|
64
|
+
ContextState[ContextState["Temporary"] = 0] = "Temporary";
|
|
65
|
+
ContextState[ContextState["Default"] = 1] = "Default";
|
|
66
|
+
})(ContextState = exports.ContextState || (exports.ContextState = {}));
|
|
67
|
+
var Scope = /** @class */ (function (_super) {
|
|
68
|
+
__extends(Scope, _super);
|
|
69
|
+
function Scope(context) {
|
|
70
|
+
var _this = _super.call(this) || this;
|
|
71
|
+
_this.context = context;
|
|
72
|
+
return _this;
|
|
73
|
+
}
|
|
74
|
+
Scope.prototype.get = function (path) {
|
|
75
|
+
if (path instanceof generics_1.CustomValue) {
|
|
76
|
+
return this.get(new path_1.default([path]));
|
|
77
|
+
}
|
|
78
|
+
if (path.count() === 0) {
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
var traversalPath = path.clone();
|
|
82
|
+
var current = traversalPath.next();
|
|
83
|
+
if (current.value === 'locals' || current.value === 'globals') {
|
|
84
|
+
return this.context.get(traversalPath);
|
|
85
|
+
}
|
|
86
|
+
else if (this.has(path)) {
|
|
87
|
+
return _super.prototype.get.call(this, path);
|
|
88
|
+
}
|
|
89
|
+
else if (this.context.api.scope.has(path)) {
|
|
90
|
+
return this.context.api.scope.get(path);
|
|
91
|
+
}
|
|
92
|
+
else if (path.count() === 1 &&
|
|
93
|
+
map_1.default.getIntrinsics().has(current.toString())) {
|
|
94
|
+
return map_1.default.getIntrinsics().get(current.toString());
|
|
95
|
+
}
|
|
96
|
+
else if (this.context.previous !== null) {
|
|
97
|
+
return this.context.previous.get(path);
|
|
98
|
+
}
|
|
99
|
+
throw new Error("Unknown path ".concat(path.toString(), "."));
|
|
100
|
+
};
|
|
101
|
+
return Scope;
|
|
102
|
+
}(map_1.default));
|
|
103
|
+
exports.Scope = Scope;
|
|
104
|
+
var Debugger = /** @class */ (function () {
|
|
105
|
+
function Debugger() {
|
|
106
|
+
this.breakpoint = false;
|
|
107
|
+
this.nextStep = false;
|
|
108
|
+
/* eslint-disable no-use-before-define */
|
|
109
|
+
this.lastContext = null;
|
|
110
|
+
}
|
|
111
|
+
Debugger.prototype.getLastContext = function () {
|
|
112
|
+
return this.lastContext;
|
|
113
|
+
};
|
|
114
|
+
Debugger.prototype.debug = function () {
|
|
115
|
+
var segments = [];
|
|
116
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
117
|
+
segments[_i] = arguments[_i];
|
|
118
|
+
}
|
|
119
|
+
console.debug.apply(console, __spreadArray([], __read(segments), false));
|
|
120
|
+
return default_1.default.Void;
|
|
121
|
+
};
|
|
122
|
+
Debugger.prototype.setBreakpoint = function (breakpoint) {
|
|
123
|
+
this.breakpoint = breakpoint;
|
|
124
|
+
return this;
|
|
125
|
+
};
|
|
126
|
+
Debugger.prototype.getBreakpoint = function (_ctx) {
|
|
127
|
+
return this.breakpoint;
|
|
128
|
+
};
|
|
129
|
+
Debugger.prototype.next = function () {
|
|
130
|
+
this.nextStep = true;
|
|
131
|
+
return this;
|
|
132
|
+
};
|
|
133
|
+
Debugger.prototype.resume = function () {
|
|
134
|
+
var _this = this;
|
|
135
|
+
if (!this.breakpoint) {
|
|
136
|
+
return Promise.resolve();
|
|
137
|
+
}
|
|
138
|
+
return new Promise(function (resolve) {
|
|
139
|
+
var check = function () {
|
|
140
|
+
if (!_this.breakpoint) {
|
|
141
|
+
resolve();
|
|
142
|
+
}
|
|
143
|
+
else if (_this.nextStep) {
|
|
144
|
+
_this.nextStep = false;
|
|
145
|
+
resolve();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
setTimeout(check);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
check();
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
Debugger.prototype.interact = function (ctx, _ast, _op) {
|
|
155
|
+
var me = this;
|
|
156
|
+
console.warn('Debugger is not setup.');
|
|
157
|
+
console.info(ctx);
|
|
158
|
+
me.breakpoint = false;
|
|
159
|
+
};
|
|
160
|
+
return Debugger;
|
|
161
|
+
}());
|
|
162
|
+
exports.Debugger = Debugger;
|
|
163
|
+
var ProcessState = /** @class */ (function () {
|
|
164
|
+
function ProcessState() {
|
|
165
|
+
this.isExit = false;
|
|
166
|
+
this.isPending = false;
|
|
167
|
+
/* eslint-disable no-use-before-define */
|
|
168
|
+
this.last = null;
|
|
169
|
+
}
|
|
170
|
+
return ProcessState;
|
|
171
|
+
}());
|
|
172
|
+
exports.ProcessState = ProcessState;
|
|
173
|
+
var LoopState = /** @class */ (function () {
|
|
174
|
+
function LoopState() {
|
|
175
|
+
this.isBreak = false;
|
|
176
|
+
this.isContinue = false;
|
|
177
|
+
}
|
|
178
|
+
return LoopState;
|
|
179
|
+
}());
|
|
180
|
+
exports.LoopState = LoopState;
|
|
181
|
+
var FunctionState = /** @class */ (function () {
|
|
182
|
+
function FunctionState() {
|
|
183
|
+
this.value = default_1.default.Void;
|
|
184
|
+
this.isReturn = false;
|
|
185
|
+
}
|
|
186
|
+
return FunctionState;
|
|
187
|
+
}());
|
|
188
|
+
exports.FunctionState = FunctionState;
|
|
189
|
+
var OperationContext = /** @class */ (function () {
|
|
190
|
+
function OperationContext(options) {
|
|
191
|
+
if (options === void 0) { options = {}; }
|
|
192
|
+
this.target = options.target || 'unknown';
|
|
193
|
+
this.stackItem = null;
|
|
194
|
+
this.previous = options.previous || null;
|
|
195
|
+
this.type = options.type || ContextType.Api;
|
|
196
|
+
this.state = options.state || ContextState.Default;
|
|
197
|
+
this.scope = new Scope(this);
|
|
198
|
+
this.isProtected = options.isProtected || false;
|
|
199
|
+
this.injected = options.injected || false;
|
|
200
|
+
this.debugger = options.debugger || new Debugger();
|
|
201
|
+
this.handler = options.handler || new handler_container_1.default();
|
|
202
|
+
this.cps = options.cps || null;
|
|
203
|
+
this.processState = options.processState || new ProcessState();
|
|
204
|
+
this.api = this.lookupApi();
|
|
205
|
+
this.globals = this.lookupGlobals();
|
|
206
|
+
this.locals = this.lookupLocals() || this;
|
|
207
|
+
}
|
|
208
|
+
OperationContext.prototype.step = function (op) {
|
|
209
|
+
if (!this.injected) {
|
|
210
|
+
this.stackItem = op.item;
|
|
211
|
+
this.target = op.target || this.target;
|
|
212
|
+
this.setLastActive(this);
|
|
213
|
+
if (this.debugger.getBreakpoint(this)) {
|
|
214
|
+
this.debugger.interact(this, op.item, op);
|
|
215
|
+
return this.debugger.resume();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return Promise.resolve();
|
|
219
|
+
};
|
|
220
|
+
OperationContext.prototype.setLastActive = function (ctx) {
|
|
221
|
+
if (!ctx.injected) {
|
|
222
|
+
this.processState.last = ctx;
|
|
223
|
+
}
|
|
224
|
+
return this;
|
|
225
|
+
};
|
|
226
|
+
OperationContext.prototype.getLastActive = function () {
|
|
227
|
+
return this.processState.last;
|
|
228
|
+
};
|
|
229
|
+
OperationContext.prototype.isExit = function () {
|
|
230
|
+
return this.processState.isExit;
|
|
231
|
+
};
|
|
232
|
+
OperationContext.prototype.isPending = function () {
|
|
233
|
+
return this.processState.isPending;
|
|
234
|
+
};
|
|
235
|
+
OperationContext.prototype.setPending = function (pending) {
|
|
236
|
+
this.processState.isPending = pending;
|
|
237
|
+
return this;
|
|
238
|
+
};
|
|
239
|
+
OperationContext.prototype.lookupAllOfType = function (validate) {
|
|
240
|
+
var me = this;
|
|
241
|
+
var result = [];
|
|
242
|
+
if (validate(me.type)) {
|
|
243
|
+
result.push(me);
|
|
244
|
+
}
|
|
245
|
+
var current = me.previous;
|
|
246
|
+
while (current) {
|
|
247
|
+
if (validate(current.type)) {
|
|
248
|
+
result.push(current);
|
|
249
|
+
}
|
|
250
|
+
current = current.previous;
|
|
251
|
+
}
|
|
252
|
+
return result;
|
|
253
|
+
};
|
|
254
|
+
OperationContext.prototype.exit = function () {
|
|
255
|
+
var _this = this;
|
|
256
|
+
if (this.processState.isPending) {
|
|
257
|
+
this.processState.isExit = true;
|
|
258
|
+
return new Promise(function (resolve) {
|
|
259
|
+
var check = function () {
|
|
260
|
+
if (!_this.processState.isPending) {
|
|
261
|
+
_this.processState.isExit = false;
|
|
262
|
+
resolve(_this);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
setTimeout(check);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
check();
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return Promise.reject(new Error('No running process found.'));
|
|
272
|
+
};
|
|
273
|
+
OperationContext.prototype.lookupType = function (allowedTypes) {
|
|
274
|
+
if (allowedTypes.includes(this.type)) {
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
277
|
+
var current = this.previous;
|
|
278
|
+
while (current !== null) {
|
|
279
|
+
if (allowedTypes.includes(current.type)) {
|
|
280
|
+
return current;
|
|
281
|
+
}
|
|
282
|
+
current = current.previous;
|
|
283
|
+
}
|
|
284
|
+
return null;
|
|
285
|
+
};
|
|
286
|
+
OperationContext.prototype.lookupAllScopes = function () {
|
|
287
|
+
return this.lookupAllOfType(function (type) {
|
|
288
|
+
return [ContextType.Global, ContextType.Function].includes(type);
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
OperationContext.prototype.lookupApi = function () {
|
|
292
|
+
return this.lookupType(OperationContext.lookupApiType);
|
|
293
|
+
};
|
|
294
|
+
OperationContext.prototype.lookupGlobals = function () {
|
|
295
|
+
return this.lookupType(OperationContext.lookupGlobalsType);
|
|
296
|
+
};
|
|
297
|
+
OperationContext.prototype.lookupLocals = function () {
|
|
298
|
+
return this.lookupType(OperationContext.lookupLocalsType);
|
|
299
|
+
};
|
|
300
|
+
OperationContext.prototype.extend = function (map) {
|
|
301
|
+
var _a;
|
|
302
|
+
if (this.state === ContextState.Temporary) {
|
|
303
|
+
(_a = this.previous) === null || _a === void 0 ? void 0 : _a.extend(map);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
this.scope.extend(map);
|
|
307
|
+
}
|
|
308
|
+
return this;
|
|
309
|
+
};
|
|
310
|
+
OperationContext.prototype.set = function (path, value) {
|
|
311
|
+
var _a;
|
|
312
|
+
if (path instanceof generics_1.CustomValue) {
|
|
313
|
+
this.set(new path_1.default([path]), value);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
var traversalPath = path.clone();
|
|
317
|
+
var current = traversalPath.next();
|
|
318
|
+
if (current.value === 'locals') {
|
|
319
|
+
this.locals.set(traversalPath, value);
|
|
320
|
+
}
|
|
321
|
+
else if (current.value === 'globals') {
|
|
322
|
+
this.globals.set(traversalPath, value);
|
|
323
|
+
}
|
|
324
|
+
else if (this.state === ContextState.Temporary) {
|
|
325
|
+
(_a = this.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
this.locals.scope.set(path, value);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
OperationContext.prototype.get = function (path) {
|
|
332
|
+
var _a;
|
|
333
|
+
if (path instanceof generics_1.CustomValue) {
|
|
334
|
+
return this.get(new path_1.default([path]));
|
|
335
|
+
}
|
|
336
|
+
if (path.count() === 0) {
|
|
337
|
+
return this.scope;
|
|
338
|
+
}
|
|
339
|
+
var traversalPath = path.clone();
|
|
340
|
+
var current = traversalPath.next();
|
|
341
|
+
if (current.value === 'locals') {
|
|
342
|
+
return this.locals.get(traversalPath);
|
|
343
|
+
}
|
|
344
|
+
else if (current.value === 'globals') {
|
|
345
|
+
return this.globals.get(traversalPath);
|
|
346
|
+
}
|
|
347
|
+
else if (this.state === ContextState.Temporary) {
|
|
348
|
+
return (_a = this.previous) === null || _a === void 0 ? void 0 : _a.get(path);
|
|
349
|
+
}
|
|
350
|
+
return this.locals.scope.get(path);
|
|
351
|
+
};
|
|
352
|
+
OperationContext.prototype.fork = function (options) {
|
|
353
|
+
var newContext = new OperationContext({
|
|
354
|
+
target: options.target || this.target,
|
|
355
|
+
previous: this,
|
|
356
|
+
type: options.type,
|
|
357
|
+
state: options.state,
|
|
358
|
+
isProtected: false,
|
|
359
|
+
injected: this.injected,
|
|
360
|
+
debugger: this.debugger,
|
|
361
|
+
handler: this.handler,
|
|
362
|
+
cps: this.cps,
|
|
363
|
+
processState: this.processState
|
|
364
|
+
});
|
|
365
|
+
if (this.type !== ContextType.Function) {
|
|
366
|
+
if (this.type !== ContextType.Loop) {
|
|
367
|
+
newContext.loopState = this.loopState;
|
|
368
|
+
}
|
|
369
|
+
newContext.functionState = this.functionState;
|
|
370
|
+
}
|
|
371
|
+
return newContext;
|
|
372
|
+
};
|
|
373
|
+
OperationContext.lookupApiType = [ContextType.Api];
|
|
374
|
+
OperationContext.lookupGlobalsType = [
|
|
375
|
+
ContextType.Global
|
|
376
|
+
];
|
|
377
|
+
OperationContext.lookupLocalsType = [
|
|
378
|
+
ContextType.Global,
|
|
379
|
+
ContextType.Function
|
|
380
|
+
];
|
|
381
|
+
return OperationContext;
|
|
382
|
+
}());
|
|
383
|
+
exports.default = OperationContext;
|