greybel-interpreter 0.1.8 → 0.2.2
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/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +81 -73
- package/dist/context.js +412 -403
- package/dist/cps.d.ts +15 -15
- package/dist/cps.js +849 -438
- package/dist/custom-types/boolean.d.ts +10 -10
- package/dist/custom-types/boolean.js +41 -41
- package/dist/custom-types/list.d.ts +25 -25
- package/dist/custom-types/list.js +292 -292
- package/dist/custom-types/map.d.ts +28 -28
- package/dist/custom-types/map.js +289 -289
- package/dist/custom-types/nil.d.ts +8 -8
- package/dist/custom-types/nil.js +38 -38
- package/dist/custom-types/number.d.ts +10 -10
- package/dist/custom-types/number.js +41 -41
- package/dist/custom-types/string.d.ts +21 -21
- package/dist/custom-types/string.js +131 -131
- package/dist/expressions/assign.d.ts +13 -12
- package/dist/expressions/assign.js +174 -156
- package/dist/expressions/binary-negated-expression.d.ts +19 -18
- package/dist/expressions/binary-negated-expression.js +131 -115
- package/dist/expressions/call.d.ts +14 -13
- package/dist/expressions/call.js +211 -177
- package/dist/expressions/import.d.ts +14 -0
- package/dist/expressions/import.js +155 -0
- package/dist/expressions/include.d.ts +13 -0
- package/dist/expressions/include.js +132 -0
- package/dist/expressions/list.d.ts +14 -13
- package/dist/expressions/list.js +134 -119
- package/dist/expressions/logical-and-binary.d.ts +23 -22
- package/dist/expressions/logical-and-binary.js +212 -192
- package/dist/expressions/map.d.ts +19 -18
- package/dist/expressions/map.js +196 -171
- package/dist/expressions/path.d.ts +31 -30
- package/dist/expressions/path.js +364 -310
- package/dist/index.d.ts +37 -37
- package/dist/index.js +91 -91
- package/dist/interpreter.d.ts +22 -22
- package/dist/interpreter.js +122 -64
- package/dist/operations/argument.d.ts +8 -8
- package/dist/operations/argument.js +129 -129
- package/dist/operations/body.d.ts +8 -8
- package/dist/operations/body.js +144 -144
- package/dist/operations/break.d.ts +7 -7
- package/dist/operations/break.js +34 -34
- package/dist/operations/continue.d.ts +7 -7
- package/dist/operations/continue.js +34 -34
- package/dist/operations/debugger.d.ts +7 -7
- package/dist/operations/debugger.js +32 -32
- package/dist/operations/else-if.d.ts +12 -12
- package/dist/operations/else-if.js +31 -31
- package/dist/operations/else.d.ts +10 -10
- package/dist/operations/else.js +30 -30
- package/dist/operations/for.d.ts +16 -16
- package/dist/operations/for.js +143 -139
- package/dist/operations/function.d.ts +21 -21
- package/dist/operations/function.js +129 -125
- package/dist/operations/if-statement.d.ts +8 -8
- package/dist/operations/if-statement.js +138 -138
- package/dist/operations/if.d.ts +12 -12
- package/dist/operations/if.js +31 -31
- package/dist/operations/new.d.ts +11 -11
- package/dist/operations/new.js +96 -96
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +95 -95
- package/dist/operations/reference.d.ts +11 -11
- package/dist/operations/reference.js +102 -102
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +102 -102
- package/dist/operations/top.d.ts +12 -12
- package/dist/operations/top.js +87 -84
- package/dist/operations/while.d.ts +14 -14
- package/dist/operations/while.js +127 -123
- package/dist/resource.d.ts +9 -9
- package/dist/resource.js +29 -29
- package/dist/typer.d.ts +6 -6
- package/dist/typer.js +95 -95
- package/dist/types/custom-type.d.ts +19 -19
- package/dist/types/custom-type.js +58 -58
- package/dist/types/expression.d.ts +6 -6
- package/dist/types/expression.js +9 -9
- package/dist/types/operation.d.ts +9 -9
- package/dist/types/operation.js +38 -38
- package/package.json +45 -45
package/dist/context.js
CHANGED
|
@@ -1,403 +1,412 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
-
if (!m) return o;
|
|
41
|
-
var i = m.call(o), r, ar = [], e;
|
|
42
|
-
try {
|
|
43
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
-
}
|
|
45
|
-
catch (error) { e = { error: error }; }
|
|
46
|
-
finally {
|
|
47
|
-
try {
|
|
48
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
-
}
|
|
50
|
-
finally { if (e) throw e.error; }
|
|
51
|
-
}
|
|
52
|
-
return ar;
|
|
53
|
-
};
|
|
54
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
-
if (ar || !(i in from)) {
|
|
57
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
-
ar[i] = from[i];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
-
};
|
|
63
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
64
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
65
|
-
};
|
|
66
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
-
exports.OperationContext = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
|
|
68
|
-
var boolean_1 = __importDefault(require("./custom-types/boolean"));
|
|
69
|
-
var number_1 = __importDefault(require("./custom-types/number"));
|
|
70
|
-
var string_1 = __importDefault(require("./custom-types/string"));
|
|
71
|
-
var nil_1 = __importDefault(require("./custom-types/nil"));
|
|
72
|
-
var custom_type_1 = require("./types/custom-type");
|
|
73
|
-
var greybel_core_1 = require("greybel-core");
|
|
74
|
-
var ContextType;
|
|
75
|
-
(function (ContextType) {
|
|
76
|
-
ContextType["API"] = "API";
|
|
77
|
-
ContextType["GLOBAL"] = "GLOBAL";
|
|
78
|
-
ContextType["FUNCTION"] = "FUNCTION";
|
|
79
|
-
ContextType["INJECTION"] = "INJECTION";
|
|
80
|
-
ContextType["
|
|
81
|
-
ContextType["
|
|
82
|
-
ContextType["
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
ContextState["
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
me
|
|
93
|
-
me.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
me
|
|
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
|
-
!(origin instanceof
|
|
133
|
-
!(origin instanceof
|
|
134
|
-
!(origin instanceof
|
|
135
|
-
origin.
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
me
|
|
216
|
-
me.
|
|
217
|
-
me.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
me
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
me
|
|
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
|
-
console.
|
|
271
|
-
|
|
272
|
-
me.
|
|
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
|
-
me
|
|
313
|
-
me.
|
|
314
|
-
me.
|
|
315
|
-
me.
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
case
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
case
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
var me = this;
|
|
365
|
-
me.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
var me = this;
|
|
382
|
-
|
|
383
|
-
previous:
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
+
if (ar || !(i in from)) {
|
|
57
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
+
ar[i] = from[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
+
};
|
|
63
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
64
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
65
|
+
};
|
|
66
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
+
exports.OperationContext = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
|
|
68
|
+
var boolean_1 = __importDefault(require("./custom-types/boolean"));
|
|
69
|
+
var number_1 = __importDefault(require("./custom-types/number"));
|
|
70
|
+
var string_1 = __importDefault(require("./custom-types/string"));
|
|
71
|
+
var nil_1 = __importDefault(require("./custom-types/nil"));
|
|
72
|
+
var custom_type_1 = require("./types/custom-type");
|
|
73
|
+
var greybel_core_1 = require("greybel-core");
|
|
74
|
+
var ContextType;
|
|
75
|
+
(function (ContextType) {
|
|
76
|
+
ContextType["API"] = "API";
|
|
77
|
+
ContextType["GLOBAL"] = "GLOBAL";
|
|
78
|
+
ContextType["FUNCTION"] = "FUNCTION";
|
|
79
|
+
ContextType["INJECTION"] = "INJECTION";
|
|
80
|
+
ContextType["EXTERNAL"] = "EXTERNAL";
|
|
81
|
+
ContextType["LOOP"] = "LOOP";
|
|
82
|
+
ContextType["MAP"] = "MAP";
|
|
83
|
+
ContextType["CALL"] = "CALL";
|
|
84
|
+
})(ContextType = exports.ContextType || (exports.ContextType = {}));
|
|
85
|
+
var ContextState;
|
|
86
|
+
(function (ContextState) {
|
|
87
|
+
ContextState["TEMPORARY"] = "TEMPORARY";
|
|
88
|
+
ContextState["DEFAULT"] = "DEFAULT";
|
|
89
|
+
})(ContextState = exports.ContextState || (exports.ContextState = {}));
|
|
90
|
+
var Scope = /** @class */ (function () {
|
|
91
|
+
function Scope(context) {
|
|
92
|
+
var me = this;
|
|
93
|
+
me.context = context;
|
|
94
|
+
me.refs = new Map();
|
|
95
|
+
}
|
|
96
|
+
Scope.prototype.valueOf = function () {
|
|
97
|
+
return this.refs;
|
|
98
|
+
};
|
|
99
|
+
Scope.prototype.extend = function (map) {
|
|
100
|
+
if (map === void 0) { map = new Map(); }
|
|
101
|
+
var me = this;
|
|
102
|
+
me.refs = new Map(__spreadArray(__spreadArray([], __read(me.refs.entries()), false), __read(map.entries()), false));
|
|
103
|
+
return me;
|
|
104
|
+
};
|
|
105
|
+
Scope.prototype.set = function (path, value) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var me, traversalPath, refs, last, current, origin;
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
me = this;
|
|
110
|
+
traversalPath = [].concat(path);
|
|
111
|
+
refs = me.refs;
|
|
112
|
+
last = traversalPath.pop();
|
|
113
|
+
current = traversalPath.shift();
|
|
114
|
+
origin = refs;
|
|
115
|
+
if (current != null) {
|
|
116
|
+
if (origin.has(current)) {
|
|
117
|
+
origin = origin.get(current);
|
|
118
|
+
if (origin instanceof custom_type_1.CustomObjectType ||
|
|
119
|
+
origin instanceof Scope) {
|
|
120
|
+
return [2 /*return*/, origin.set(traversalPath.concat([last]), value)];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else if (me.context.previous && !me.context.previous.isProtected) {
|
|
124
|
+
me.context.previous.set(path, value);
|
|
125
|
+
return [2 /*return*/];
|
|
126
|
+
}
|
|
127
|
+
else if (traversalPath.length > 0) {
|
|
128
|
+
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (origin &&
|
|
132
|
+
!(origin instanceof boolean_1.default) &&
|
|
133
|
+
!(origin instanceof string_1.default) &&
|
|
134
|
+
!(origin instanceof number_1.default) &&
|
|
135
|
+
!(origin instanceof nil_1.default)) {
|
|
136
|
+
origin.set(last, value);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
140
|
+
}
|
|
141
|
+
return [2 /*return*/];
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
Scope.prototype.get = function (path) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
+
var me, traversalPath, refs, current, context, origin;
|
|
148
|
+
return __generator(this, function (_a) {
|
|
149
|
+
me = this;
|
|
150
|
+
traversalPath = [].concat(path);
|
|
151
|
+
refs = me.refs;
|
|
152
|
+
current = traversalPath.shift();
|
|
153
|
+
origin = refs;
|
|
154
|
+
if (current != null) {
|
|
155
|
+
if (origin.has(current)) {
|
|
156
|
+
context = origin;
|
|
157
|
+
origin = origin.get(current);
|
|
158
|
+
if (traversalPath.length > 0 &&
|
|
159
|
+
(origin instanceof custom_type_1.CustomObjectType ||
|
|
160
|
+
origin instanceof Scope)) {
|
|
161
|
+
return [2 /*return*/, origin.get(traversalPath)];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (me.context.previous) {
|
|
165
|
+
return [2 /*return*/, me.context.previous.get(path)];
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return [2 /*return*/, null];
|
|
173
|
+
}
|
|
174
|
+
return [2 /*return*/, origin];
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
Scope.prototype.getCallable = function (path) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
180
|
+
var me, traversalPath, refs, current, origin, context;
|
|
181
|
+
return __generator(this, function (_a) {
|
|
182
|
+
me = this;
|
|
183
|
+
traversalPath = [].concat(path);
|
|
184
|
+
refs = me.refs;
|
|
185
|
+
current = traversalPath.shift();
|
|
186
|
+
origin = refs;
|
|
187
|
+
if (current != null) {
|
|
188
|
+
if (origin.has(current)) {
|
|
189
|
+
context = origin;
|
|
190
|
+
origin = origin.get(current);
|
|
191
|
+
if (origin instanceof custom_type_1.CustomObjectType ||
|
|
192
|
+
origin instanceof Scope) {
|
|
193
|
+
return [2 /*return*/, origin.getCallable(traversalPath)];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else if (me.context.previous) {
|
|
197
|
+
return [2 /*return*/, me.context.previous.getCallable(path)];
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return [2 /*return*/, {
|
|
204
|
+
origin: origin,
|
|
205
|
+
context: context
|
|
206
|
+
}];
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
return Scope;
|
|
211
|
+
}());
|
|
212
|
+
exports.Scope = Scope;
|
|
213
|
+
var Debugger = /** @class */ (function () {
|
|
214
|
+
function Debugger() {
|
|
215
|
+
var me = this;
|
|
216
|
+
me.breakpoint = false;
|
|
217
|
+
me.nextStep = false;
|
|
218
|
+
me.lastContext = null;
|
|
219
|
+
}
|
|
220
|
+
Debugger.prototype.raise = function (message) {
|
|
221
|
+
var args = [];
|
|
222
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
223
|
+
args[_i - 1] = arguments[_i];
|
|
224
|
+
}
|
|
225
|
+
throw new Error(message);
|
|
226
|
+
};
|
|
227
|
+
Debugger.prototype.debug = function (message) {
|
|
228
|
+
var args = [];
|
|
229
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
230
|
+
args[_i - 1] = arguments[_i];
|
|
231
|
+
}
|
|
232
|
+
console.info.apply(console, __spreadArray([message], __read(args), false));
|
|
233
|
+
};
|
|
234
|
+
Debugger.prototype.setBreakpoint = function (state) {
|
|
235
|
+
var me = this;
|
|
236
|
+
me.breakpoint = state;
|
|
237
|
+
return me;
|
|
238
|
+
};
|
|
239
|
+
Debugger.prototype.getBreakpoint = function () {
|
|
240
|
+
return this.breakpoint;
|
|
241
|
+
};
|
|
242
|
+
Debugger.prototype.next = function () {
|
|
243
|
+
var me = this;
|
|
244
|
+
me.nextStep = true;
|
|
245
|
+
return me;
|
|
246
|
+
};
|
|
247
|
+
Debugger.prototype.resume = function () {
|
|
248
|
+
var me = this;
|
|
249
|
+
if (!me.breakpoint) {
|
|
250
|
+
return Promise.resolve();
|
|
251
|
+
}
|
|
252
|
+
return new Promise(function (resolve) {
|
|
253
|
+
var check = function () {
|
|
254
|
+
if (!me.breakpoint) {
|
|
255
|
+
resolve();
|
|
256
|
+
}
|
|
257
|
+
else if (me.nextStep) {
|
|
258
|
+
me.nextStep = false;
|
|
259
|
+
resolve();
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
setImmediate(check);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
setImmediate(check);
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
Debugger.prototype.interact = function (operationContext, item) {
|
|
269
|
+
var me = this;
|
|
270
|
+
console.warn("Debugger is not setup.");
|
|
271
|
+
console.info(operationContext);
|
|
272
|
+
me.lastContext = operationContext;
|
|
273
|
+
me.breakpoint = false;
|
|
274
|
+
};
|
|
275
|
+
Debugger.prototype.run = function (code) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
277
|
+
var me, parser, chunk, item, context, err_1;
|
|
278
|
+
return __generator(this, function (_a) {
|
|
279
|
+
switch (_a.label) {
|
|
280
|
+
case 0:
|
|
281
|
+
me = this;
|
|
282
|
+
_a.label = 1;
|
|
283
|
+
case 1:
|
|
284
|
+
_a.trys.push([1, 4, , 5]);
|
|
285
|
+
parser = new greybel_core_1.Parser(code);
|
|
286
|
+
chunk = parser.parseChunk();
|
|
287
|
+
return [4 /*yield*/, me.lastContext.cps.visit(chunk)];
|
|
288
|
+
case 2:
|
|
289
|
+
item = _a.sent();
|
|
290
|
+
context = me.lastContext.fork({
|
|
291
|
+
type: ContextType.INJECTION,
|
|
292
|
+
state: ContextState.TEMPORARY
|
|
293
|
+
});
|
|
294
|
+
return [4 /*yield*/, item.run(context)];
|
|
295
|
+
case 3:
|
|
296
|
+
_a.sent();
|
|
297
|
+
return [3 /*break*/, 5];
|
|
298
|
+
case 4:
|
|
299
|
+
err_1 = _a.sent();
|
|
300
|
+
console.error(err_1);
|
|
301
|
+
return [3 /*break*/, 5];
|
|
302
|
+
case 5: return [2 /*return*/];
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
return Debugger;
|
|
308
|
+
}());
|
|
309
|
+
exports.Debugger = Debugger;
|
|
310
|
+
var OperationContext = /** @class */ (function () {
|
|
311
|
+
function OperationContext(options) {
|
|
312
|
+
var me = this;
|
|
313
|
+
me.target = options.target || 'unknown';
|
|
314
|
+
me.previous = options.previous || null;
|
|
315
|
+
me.type = options.type || ContextType.API;
|
|
316
|
+
me.state = options.state || ContextState.DEFAULT;
|
|
317
|
+
me.scope = new Scope(me);
|
|
318
|
+
me.isProtected = options.isProtected || false;
|
|
319
|
+
me.memory = new Map();
|
|
320
|
+
me.debugger = options.debugger || new Debugger();
|
|
321
|
+
me.cps = options.cps;
|
|
322
|
+
me.processState = options.processState || {
|
|
323
|
+
exit: false
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
OperationContext.prototype.valueOf = function () {
|
|
327
|
+
return this.scope.valueOf();
|
|
328
|
+
};
|
|
329
|
+
OperationContext.prototype.extend = function (map) {
|
|
330
|
+
var _a;
|
|
331
|
+
var me = this;
|
|
332
|
+
if (me.state === ContextState.TEMPORARY) {
|
|
333
|
+
(_a = me.previous) === null || _a === void 0 ? void 0 : _a.extend(map);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
me.scope.extend(map);
|
|
337
|
+
}
|
|
338
|
+
return me;
|
|
339
|
+
};
|
|
340
|
+
OperationContext.prototype.set = function (path, value) {
|
|
341
|
+
var _a;
|
|
342
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
343
|
+
var me;
|
|
344
|
+
return __generator(this, function (_b) {
|
|
345
|
+
switch (_b.label) {
|
|
346
|
+
case 0:
|
|
347
|
+
me = this;
|
|
348
|
+
if (!(me.state === ContextState.TEMPORARY)) return [3 /*break*/, 2];
|
|
349
|
+
return [4 /*yield*/, ((_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value))];
|
|
350
|
+
case 1:
|
|
351
|
+
_b.sent();
|
|
352
|
+
return [3 /*break*/, 4];
|
|
353
|
+
case 2: return [4 /*yield*/, me.scope.set(path, value)];
|
|
354
|
+
case 3:
|
|
355
|
+
_b.sent();
|
|
356
|
+
_b.label = 4;
|
|
357
|
+
case 4: return [2 /*return*/, me];
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
OperationContext.prototype.get = function (path) {
|
|
363
|
+
var _a;
|
|
364
|
+
var me = this;
|
|
365
|
+
if (me.state === ContextState.TEMPORARY) {
|
|
366
|
+
return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.get(path);
|
|
367
|
+
}
|
|
368
|
+
return me.scope.get(path);
|
|
369
|
+
};
|
|
370
|
+
OperationContext.prototype.setMemory = function (key, value) {
|
|
371
|
+
var me = this;
|
|
372
|
+
me.memory.set(key, value);
|
|
373
|
+
return me;
|
|
374
|
+
};
|
|
375
|
+
OperationContext.prototype.getMemory = function (key) {
|
|
376
|
+
var me = this;
|
|
377
|
+
return me.memory.get(key);
|
|
378
|
+
};
|
|
379
|
+
OperationContext.prototype.getCallable = function (path) {
|
|
380
|
+
var _a;
|
|
381
|
+
var me = this;
|
|
382
|
+
if (me.state === ContextState.TEMPORARY) {
|
|
383
|
+
return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.getCallable(path);
|
|
384
|
+
}
|
|
385
|
+
return me.scope.getCallable(path);
|
|
386
|
+
};
|
|
387
|
+
OperationContext.prototype.fork = function (_a) {
|
|
388
|
+
var type = _a.type, state = _a.state, target = _a.target;
|
|
389
|
+
var me = this;
|
|
390
|
+
var opc = new OperationContext({
|
|
391
|
+
target: target || me.target,
|
|
392
|
+
previous: me,
|
|
393
|
+
type: type,
|
|
394
|
+
state: state,
|
|
395
|
+
debugger: me.debugger,
|
|
396
|
+
cps: me.cps,
|
|
397
|
+
processState: me.processState
|
|
398
|
+
});
|
|
399
|
+
if (me.type === ContextType.FUNCTION || me.type === ContextType.GLOBAL) {
|
|
400
|
+
opc.scope.refs.set('locals', opc.scope);
|
|
401
|
+
}
|
|
402
|
+
if (type !== ContextType.FUNCTION) {
|
|
403
|
+
if (type !== ContextType.LOOP) {
|
|
404
|
+
opc.setMemory('loopContext', me.getMemory('loopContext'));
|
|
405
|
+
}
|
|
406
|
+
opc.setMemory('functionContext', me.getMemory('functionContext'));
|
|
407
|
+
}
|
|
408
|
+
return opc;
|
|
409
|
+
};
|
|
410
|
+
return OperationContext;
|
|
411
|
+
}());
|
|
412
|
+
exports.OperationContext = OperationContext;
|