greybel-interpreter 0.1.0

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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/context.d.ts +68 -0
  4. package/dist/context.js +399 -0
  5. package/dist/cps.d.ts +15 -0
  6. package/dist/cps.js +438 -0
  7. package/dist/custom-types/boolean.d.ts +10 -0
  8. package/dist/custom-types/boolean.js +41 -0
  9. package/dist/custom-types/list.d.ts +25 -0
  10. package/dist/custom-types/list.js +281 -0
  11. package/dist/custom-types/map.d.ts +28 -0
  12. package/dist/custom-types/map.js +289 -0
  13. package/dist/custom-types/nil.d.ts +8 -0
  14. package/dist/custom-types/nil.js +38 -0
  15. package/dist/custom-types/number.d.ts +10 -0
  16. package/dist/custom-types/number.js +41 -0
  17. package/dist/custom-types/string.d.ts +21 -0
  18. package/dist/custom-types/string.js +132 -0
  19. package/dist/expressions/assign.d.ts +12 -0
  20. package/dist/expressions/assign.js +156 -0
  21. package/dist/expressions/binary-negated-expression.d.ts +18 -0
  22. package/dist/expressions/binary-negated-expression.js +115 -0
  23. package/dist/expressions/call.d.ts +13 -0
  24. package/dist/expressions/call.js +177 -0
  25. package/dist/expressions/list.d.ts +13 -0
  26. package/dist/expressions/list.js +119 -0
  27. package/dist/expressions/logical-and-binary.d.ts +22 -0
  28. package/dist/expressions/logical-and-binary.js +188 -0
  29. package/dist/expressions/map.d.ts +18 -0
  30. package/dist/expressions/map.js +171 -0
  31. package/dist/expressions/path.d.ts +30 -0
  32. package/dist/expressions/path.js +310 -0
  33. package/dist/index.d.ts +35 -0
  34. package/dist/index.js +82 -0
  35. package/dist/interpreter.d.ts +20 -0
  36. package/dist/interpreter.js +55 -0
  37. package/dist/operations/argument.d.ts +8 -0
  38. package/dist/operations/argument.js +129 -0
  39. package/dist/operations/body.d.ts +8 -0
  40. package/dist/operations/body.js +144 -0
  41. package/dist/operations/break.d.ts +7 -0
  42. package/dist/operations/break.js +34 -0
  43. package/dist/operations/continue.d.ts +7 -0
  44. package/dist/operations/continue.js +34 -0
  45. package/dist/operations/debugger.d.ts +7 -0
  46. package/dist/operations/debugger.js +32 -0
  47. package/dist/operations/else-if.d.ts +12 -0
  48. package/dist/operations/else-if.js +31 -0
  49. package/dist/operations/else.d.ts +10 -0
  50. package/dist/operations/else.js +30 -0
  51. package/dist/operations/for.d.ts +16 -0
  52. package/dist/operations/for.js +139 -0
  53. package/dist/operations/function.d.ts +21 -0
  54. package/dist/operations/function.js +125 -0
  55. package/dist/operations/if-statement.d.ts +8 -0
  56. package/dist/operations/if-statement.js +138 -0
  57. package/dist/operations/if.d.ts +12 -0
  58. package/dist/operations/if.js +31 -0
  59. package/dist/operations/new.d.ts +11 -0
  60. package/dist/operations/new.js +96 -0
  61. package/dist/operations/not.d.ts +11 -0
  62. package/dist/operations/not.js +95 -0
  63. package/dist/operations/reference.d.ts +11 -0
  64. package/dist/operations/reference.js +102 -0
  65. package/dist/operations/return.d.ts +11 -0
  66. package/dist/operations/return.js +102 -0
  67. package/dist/operations/top.d.ts +12 -0
  68. package/dist/operations/top.js +84 -0
  69. package/dist/operations/while.d.ts +14 -0
  70. package/dist/operations/while.js +123 -0
  71. package/dist/resource.d.ts +9 -0
  72. package/dist/resource.js +29 -0
  73. package/dist/typer.d.ts +6 -0
  74. package/dist/typer.js +99 -0
  75. package/dist/types/custom-type.d.ts +19 -0
  76. package/dist/types/custom-type.js +58 -0
  77. package/dist/types/expression.d.ts +6 -0
  78. package/dist/types/expression.js +9 -0
  79. package/dist/types/operation.d.ts +9 -0
  80. package/dist/types/operation.js +38 -0
  81. package/package.json +45 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 swe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # greybel-interpreter
2
+
3
+ [![greybel-interpreter](https://circleci.com/gh/ayecue/greybel-interpreter.svg?style=svg)](https://circleci.com/gh/ayecue/greybel-interpreter)
@@ -0,0 +1,68 @@
1
+ import { Operation } from './types/operation';
2
+ import { Expression } from './types/expression';
3
+ import { Callable } from './types/custom-type';
4
+ import CPS from './cps';
5
+ export declare enum ContextType {
6
+ API = "API",
7
+ GLOBAL = "GLOBAL",
8
+ FUNCTION = "FUNCTION",
9
+ INJECTION = "INJECTION",
10
+ LOOP = "LOOP",
11
+ MAP = "MAP",
12
+ CALL = "CALL"
13
+ }
14
+ export declare enum ContextState {
15
+ TEMPORARY = "TEMPORARY",
16
+ DEFAULT = "DEFAULT"
17
+ }
18
+ export declare class Scope {
19
+ context: OperationContext;
20
+ refs: Map<string, any>;
21
+ constructor(context: OperationContext);
22
+ valueOf(): Map<string, any>;
23
+ extend(map?: Map<string, any>): Scope;
24
+ set(path: string[], value: any): Promise<void>;
25
+ get(path: string[]): Promise<any>;
26
+ getCallable(path: string[]): Promise<Callable>;
27
+ }
28
+ export declare class Debugger {
29
+ breakpoint: boolean;
30
+ nextStep: boolean;
31
+ lastContext: OperationContext | null;
32
+ constructor();
33
+ raise(message: string, ...args: any[]): void;
34
+ debug(message: string, ...args: any[]): void;
35
+ setBreakpoint(state: boolean): Debugger;
36
+ getBreakpoint(): boolean;
37
+ next(): Debugger;
38
+ resume(): Promise<void>;
39
+ interact(operationContext: OperationContext, item: Operation | Expression): void;
40
+ run(code: string): Promise<void>;
41
+ }
42
+ export interface OperationContextOptions {
43
+ isProtected?: boolean;
44
+ type?: string;
45
+ state?: string;
46
+ previous?: OperationContext;
47
+ debugger?: Debugger;
48
+ cps?: CPS;
49
+ }
50
+ export declare class OperationContext {
51
+ debugger: Debugger;
52
+ previous: OperationContext | null;
53
+ type: string;
54
+ state: string;
55
+ scope: Scope;
56
+ isProtected: boolean;
57
+ memory: Map<string, any>;
58
+ cps: CPS | null;
59
+ constructor(options: OperationContextOptions);
60
+ valueOf(): Map<string, any>;
61
+ extend(map: Map<string, any>): OperationContext;
62
+ set(path: any[], value: any): Promise<OperationContext>;
63
+ get(path: any[]): any;
64
+ setMemory(key: string, value: any): OperationContext;
65
+ getMemory(key: string): any;
66
+ getCallable(path: string[]): Promise<Callable>;
67
+ fork(type: string, state: string): OperationContext;
68
+ }
@@ -0,0 +1,399 @@
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["LOOP"] = "LOOP";
81
+ ContextType["MAP"] = "MAP";
82
+ ContextType["CALL"] = "CALL";
83
+ })(ContextType = exports.ContextType || (exports.ContextType = {}));
84
+ var ContextState;
85
+ (function (ContextState) {
86
+ ContextState["TEMPORARY"] = "TEMPORARY";
87
+ ContextState["DEFAULT"] = "DEFAULT";
88
+ })(ContextState = exports.ContextState || (exports.ContextState = {}));
89
+ var Scope = /** @class */ (function () {
90
+ function Scope(context) {
91
+ var me = this;
92
+ me.context = context;
93
+ me.refs = new Map();
94
+ }
95
+ Scope.prototype.valueOf = function () {
96
+ return this.refs;
97
+ };
98
+ Scope.prototype.extend = function (map) {
99
+ if (map === void 0) { map = new Map(); }
100
+ var me = this;
101
+ me.refs = new Map(__spreadArray(__spreadArray([], __read(me.refs.entries()), false), __read(map.entries()), false));
102
+ return me;
103
+ };
104
+ Scope.prototype.set = function (path, value) {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var me, traversalPath, refs, last, current, origin;
107
+ return __generator(this, function (_a) {
108
+ me = this;
109
+ traversalPath = [].concat(path);
110
+ refs = me.refs;
111
+ last = traversalPath.pop();
112
+ current = traversalPath.shift();
113
+ origin = refs;
114
+ if (current != null) {
115
+ if (origin.has(current)) {
116
+ origin = origin.get(current);
117
+ if (origin instanceof custom_type_1.CustomObjectType ||
118
+ origin instanceof Scope) {
119
+ return [2 /*return*/, origin.set(traversalPath.concat([last]), value)];
120
+ }
121
+ }
122
+ else if (me.context.previous && !me.context.previous.isProtected) {
123
+ me.context.previous.set(path, value);
124
+ return [2 /*return*/];
125
+ }
126
+ else if (traversalPath.length > 0) {
127
+ throw new Error("Cannot set path ".concat(path.join('.')));
128
+ }
129
+ }
130
+ if (origin &&
131
+ !(origin instanceof boolean_1.default) &&
132
+ !(origin instanceof string_1.default) &&
133
+ !(origin instanceof number_1.default) &&
134
+ !(origin instanceof nil_1.default)) {
135
+ origin.set(last, value);
136
+ }
137
+ else {
138
+ throw new Error("Cannot set path ".concat(path.join('.')));
139
+ }
140
+ return [2 /*return*/];
141
+ });
142
+ });
143
+ };
144
+ Scope.prototype.get = function (path) {
145
+ return __awaiter(this, void 0, void 0, function () {
146
+ var me, traversalPath, refs, current, context, origin;
147
+ return __generator(this, function (_a) {
148
+ me = this;
149
+ traversalPath = [].concat(path);
150
+ refs = me.refs;
151
+ current = traversalPath.shift();
152
+ origin = refs;
153
+ if (current != null) {
154
+ if (origin.has(current)) {
155
+ context = origin;
156
+ origin = origin.get(current);
157
+ if (traversalPath.length > 0 &&
158
+ (origin instanceof custom_type_1.CustomObjectType ||
159
+ origin instanceof Scope)) {
160
+ return [2 /*return*/, origin.get(traversalPath)];
161
+ }
162
+ }
163
+ else if (me.context.previous) {
164
+ return [2 /*return*/, me.context.previous.get(path)];
165
+ }
166
+ else {
167
+ throw new Error("Cannot get path ".concat(path.join('.')));
168
+ }
169
+ }
170
+ else {
171
+ return [2 /*return*/, null];
172
+ }
173
+ return [2 /*return*/, origin];
174
+ });
175
+ });
176
+ };
177
+ Scope.prototype.getCallable = function (path) {
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ var me, traversalPath, refs, current, origin, context;
180
+ return __generator(this, function (_a) {
181
+ me = this;
182
+ traversalPath = [].concat(path);
183
+ refs = me.refs;
184
+ current = traversalPath.shift();
185
+ origin = refs;
186
+ if (current != null) {
187
+ if (origin.has(current)) {
188
+ context = origin;
189
+ origin = origin.get(current);
190
+ if (origin instanceof custom_type_1.CustomObjectType ||
191
+ origin instanceof Scope) {
192
+ return [2 /*return*/, origin.getCallable(traversalPath)];
193
+ }
194
+ }
195
+ else if (me.context.previous) {
196
+ return [2 /*return*/, me.context.previous.getCallable(path)];
197
+ }
198
+ else {
199
+ throw new Error("Cannot get path ".concat(path.join('.')));
200
+ }
201
+ }
202
+ return [2 /*return*/, {
203
+ origin: origin,
204
+ context: context
205
+ }];
206
+ });
207
+ });
208
+ };
209
+ return Scope;
210
+ }());
211
+ exports.Scope = Scope;
212
+ var Debugger = /** @class */ (function () {
213
+ function Debugger() {
214
+ var me = this;
215
+ me.breakpoint = false;
216
+ me.nextStep = false;
217
+ me.lastContext = null;
218
+ }
219
+ Debugger.prototype.raise = function (message) {
220
+ var args = [];
221
+ for (var _i = 1; _i < arguments.length; _i++) {
222
+ args[_i - 1] = arguments[_i];
223
+ }
224
+ throw new Error(message);
225
+ };
226
+ Debugger.prototype.debug = function (message) {
227
+ var args = [];
228
+ for (var _i = 1; _i < arguments.length; _i++) {
229
+ args[_i - 1] = arguments[_i];
230
+ }
231
+ console.info.apply(console, __spreadArray([message], __read(args), false));
232
+ };
233
+ Debugger.prototype.setBreakpoint = function (state) {
234
+ var me = this;
235
+ me.breakpoint = state;
236
+ return me;
237
+ };
238
+ Debugger.prototype.getBreakpoint = function () {
239
+ return this.breakpoint;
240
+ };
241
+ Debugger.prototype.next = function () {
242
+ var me = this;
243
+ me.nextStep = true;
244
+ return me;
245
+ };
246
+ Debugger.prototype.resume = function () {
247
+ var me = this;
248
+ if (!me.breakpoint) {
249
+ return Promise.resolve();
250
+ }
251
+ return new Promise(function (resolve) {
252
+ var check = function () {
253
+ if (!me.breakpoint) {
254
+ resolve();
255
+ }
256
+ else if (me.nextStep) {
257
+ me.nextStep = false;
258
+ resolve();
259
+ }
260
+ else {
261
+ setImmediate(check);
262
+ }
263
+ };
264
+ setImmediate(check);
265
+ });
266
+ };
267
+ Debugger.prototype.interact = function (operationContext, item) {
268
+ var me = this;
269
+ console.warn("Debugger is not setup.");
270
+ console.info(operationContext);
271
+ me.lastContext = operationContext;
272
+ me.breakpoint = false;
273
+ };
274
+ Debugger.prototype.run = function (code) {
275
+ return __awaiter(this, void 0, void 0, function () {
276
+ var me, parser, chunk, item, context, err_1;
277
+ return __generator(this, function (_a) {
278
+ switch (_a.label) {
279
+ case 0:
280
+ me = this;
281
+ _a.label = 1;
282
+ case 1:
283
+ _a.trys.push([1, 3, , 4]);
284
+ parser = new greybel_core_1.Parser(code);
285
+ chunk = parser.parseChunk();
286
+ item = me.lastContext.cps.visit(chunk);
287
+ context = me.lastContext.fork(ContextType.INJECTION, ContextState.TEMPORARY);
288
+ return [4 /*yield*/, item.run(context)];
289
+ case 2:
290
+ _a.sent();
291
+ return [3 /*break*/, 4];
292
+ case 3:
293
+ err_1 = _a.sent();
294
+ console.error(err_1);
295
+ return [3 /*break*/, 4];
296
+ case 4: return [2 /*return*/];
297
+ }
298
+ });
299
+ });
300
+ };
301
+ return Debugger;
302
+ }());
303
+ exports.Debugger = Debugger;
304
+ var OperationContext = /** @class */ (function () {
305
+ function OperationContext(options) {
306
+ var me = this;
307
+ me.previous = options.previous || null;
308
+ me.type = options.type || ContextType.API;
309
+ me.state = options.state || ContextState.DEFAULT;
310
+ me.scope = new Scope(me);
311
+ me.isProtected = options.isProtected || false;
312
+ me.memory = new Map();
313
+ me.debugger = options.debugger || new Debugger();
314
+ me.cps = options.cps;
315
+ }
316
+ OperationContext.prototype.valueOf = function () {
317
+ return this.scope.valueOf();
318
+ };
319
+ OperationContext.prototype.extend = function (map) {
320
+ var _a;
321
+ var me = this;
322
+ if (me.state === ContextState.TEMPORARY) {
323
+ (_a = me.previous) === null || _a === void 0 ? void 0 : _a.extend(map);
324
+ }
325
+ else {
326
+ me.scope.extend(map);
327
+ }
328
+ return me;
329
+ };
330
+ OperationContext.prototype.set = function (path, value) {
331
+ var _a;
332
+ return __awaiter(this, void 0, void 0, function () {
333
+ var me;
334
+ return __generator(this, function (_b) {
335
+ switch (_b.label) {
336
+ case 0:
337
+ me = this;
338
+ if (!(me.state === ContextState.TEMPORARY)) return [3 /*break*/, 2];
339
+ return [4 /*yield*/, ((_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value))];
340
+ case 1:
341
+ _b.sent();
342
+ return [3 /*break*/, 4];
343
+ case 2: return [4 /*yield*/, me.scope.set(path, value)];
344
+ case 3:
345
+ _b.sent();
346
+ _b.label = 4;
347
+ case 4: return [2 /*return*/, me];
348
+ }
349
+ });
350
+ });
351
+ };
352
+ OperationContext.prototype.get = function (path) {
353
+ var _a;
354
+ var me = this;
355
+ if (me.state === ContextState.TEMPORARY) {
356
+ return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.get(path);
357
+ }
358
+ return me.scope.get(path);
359
+ };
360
+ OperationContext.prototype.setMemory = function (key, value) {
361
+ var me = this;
362
+ me.memory.set(key, value);
363
+ return me;
364
+ };
365
+ OperationContext.prototype.getMemory = function (key) {
366
+ var me = this;
367
+ return me.memory.get(key);
368
+ };
369
+ OperationContext.prototype.getCallable = function (path) {
370
+ var _a;
371
+ var me = this;
372
+ if (me.state === ContextState.TEMPORARY) {
373
+ return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.getCallable(path);
374
+ }
375
+ return me.scope.getCallable(path);
376
+ };
377
+ OperationContext.prototype.fork = function (type, state) {
378
+ var me = this;
379
+ var opc = new OperationContext({
380
+ previous: me,
381
+ type: type,
382
+ state: state,
383
+ debugger: me.debugger,
384
+ cps: me.cps
385
+ });
386
+ if (me.type === ContextType.FUNCTION || me.type === ContextType.GLOBAL) {
387
+ opc.scope.refs.set('locals', opc.scope);
388
+ }
389
+ if (type !== ContextType.FUNCTION) {
390
+ if (type !== ContextType.LOOP) {
391
+ opc.setMemory('loopContext', me.getMemory('loopContext'));
392
+ }
393
+ opc.setMemory('functionContext', me.getMemory('functionContext'));
394
+ }
395
+ return opc;
396
+ };
397
+ return OperationContext;
398
+ }());
399
+ exports.OperationContext = OperationContext;
package/dist/cps.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { ASTBase } from 'greybel-core';
2
+ import { ResourceHandler } from './resource';
3
+ export interface CPSMapType {
4
+ [key: string]: (item: ASTBase) => any;
5
+ }
6
+ export interface CPSMapContext {
7
+ target: string;
8
+ resourceHandler: ResourceHandler;
9
+ }
10
+ export declare const CPSMap: (visit: (o: ASTBase) => any, context: CPSMapContext) => CPSMapType;
11
+ export default class CPS {
12
+ cpsMap: CPSMapType;
13
+ constructor(context: CPSMapContext);
14
+ visit(o: ASTBase): any;
15
+ }