greybel-interpreter 1.4.6 → 1.4.8

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 (101) hide show
  1. package/.editorconfig +14 -14
  2. package/.eslintrc +47 -47
  3. package/LICENSE +21 -21
  4. package/README.md +2 -2
  5. package/dist/context.d.ts +110 -110
  6. package/dist/context.js +306 -306
  7. package/dist/cps.d.ts +14 -14
  8. package/dist/cps.js +160 -160
  9. package/dist/handler/error.d.ts +6 -6
  10. package/dist/handler/error.js +12 -12
  11. package/dist/handler/output.d.ts +18 -18
  12. package/dist/handler/output.js +29 -29
  13. package/dist/handler/resource.d.ts +12 -12
  14. package/dist/handler/resource.js +28 -28
  15. package/dist/handler-container.d.ts +14 -14
  16. package/dist/handler-container.js +14 -14
  17. package/dist/index.d.ts +46 -46
  18. package/dist/index.js +132 -132
  19. package/dist/interpreter.d.ts +42 -42
  20. package/dist/interpreter.js +218 -218
  21. package/dist/operations/assign.d.ts +13 -13
  22. package/dist/operations/assign.js +46 -46
  23. package/dist/operations/block.d.ts +12 -12
  24. package/dist/operations/block.js +52 -52
  25. package/dist/operations/break.d.ts +10 -10
  26. package/dist/operations/break.js +23 -23
  27. package/dist/operations/call.d.ts +13 -13
  28. package/dist/operations/call.js +49 -49
  29. package/dist/operations/chunk.d.ts +12 -12
  30. package/dist/operations/chunk.js +33 -33
  31. package/dist/operations/continue.d.ts +10 -10
  32. package/dist/operations/continue.js +23 -23
  33. package/dist/operations/debugger-statement.d.ts +10 -10
  34. package/dist/operations/debugger-statement.js +21 -21
  35. package/dist/operations/evaluate.d.ts +40 -40
  36. package/dist/operations/evaluate.js +334 -334
  37. package/dist/operations/for.d.ts +14 -14
  38. package/dist/operations/for.js +81 -81
  39. package/dist/operations/function-reference.d.ts +12 -12
  40. package/dist/operations/function-reference.js +44 -44
  41. package/dist/operations/function.d.ts +14 -14
  42. package/dist/operations/function.js +72 -72
  43. package/dist/operations/if-statement.d.ts +19 -19
  44. package/dist/operations/if-statement.js +85 -85
  45. package/dist/operations/import.d.ts +17 -17
  46. package/dist/operations/import.js +57 -57
  47. package/dist/operations/include.d.ts +13 -13
  48. package/dist/operations/include.js +41 -41
  49. package/dist/operations/list.d.ts +11 -11
  50. package/dist/operations/list.js +42 -42
  51. package/dist/operations/literal.d.ts +11 -11
  52. package/dist/operations/literal.js +40 -40
  53. package/dist/operations/map.d.ts +11 -11
  54. package/dist/operations/map.js +44 -44
  55. package/dist/operations/negated-binary.d.ts +11 -11
  56. package/dist/operations/negated-binary.js +42 -42
  57. package/dist/operations/new-instance.d.ts +11 -11
  58. package/dist/operations/new-instance.js +39 -39
  59. package/dist/operations/noop.d.ts +9 -9
  60. package/dist/operations/noop.js +19 -19
  61. package/dist/operations/not.d.ts +11 -11
  62. package/dist/operations/not.js +35 -35
  63. package/dist/operations/operation.d.ts +13 -13
  64. package/dist/operations/operation.js +9 -9
  65. package/dist/operations/reference.d.ts +9 -9
  66. package/dist/operations/reference.js +19 -19
  67. package/dist/operations/resolve.d.ts +38 -38
  68. package/dist/operations/resolve.js +210 -210
  69. package/dist/operations/return.d.ts +11 -11
  70. package/dist/operations/return.js +45 -45
  71. package/dist/operations/while.d.ts +13 -13
  72. package/dist/operations/while.js +65 -65
  73. package/dist/types/base.d.ts +9 -9
  74. package/dist/types/base.js +5 -5
  75. package/dist/types/boolean.d.ts +13 -13
  76. package/dist/types/boolean.js +34 -34
  77. package/dist/types/default.d.ts +8 -8
  78. package/dist/types/default.js +14 -14
  79. package/dist/types/function.d.ts +32 -32
  80. package/dist/types/function.js +104 -104
  81. package/dist/types/interface.d.ts +24 -24
  82. package/dist/types/interface.js +83 -83
  83. package/dist/types/list.d.ts +29 -29
  84. package/dist/types/list.js +158 -158
  85. package/dist/types/map.d.ts +33 -33
  86. package/dist/types/map.js +200 -200
  87. package/dist/types/nil.d.ts +11 -11
  88. package/dist/types/nil.js +33 -33
  89. package/dist/types/number.d.ts +25 -25
  90. package/dist/types/number.js +69 -69
  91. package/dist/types/string.d.ts +31 -31
  92. package/dist/types/string.js +121 -121
  93. package/dist/types/with-intrinsics.d.ts +15 -15
  94. package/dist/types/with-intrinsics.js +19 -19
  95. package/dist/utils/deep-equal.d.ts +1 -1
  96. package/dist/utils/deep-equal.js +37 -37
  97. package/dist/utils/object-value.d.ts +7 -7
  98. package/dist/utils/object-value.js +42 -42
  99. package/dist/utils/path.d.ts +10 -10
  100. package/dist/utils/path.js +32 -32
  101. package/package.json +58 -58
package/dist/context.js CHANGED
@@ -1,306 +1,306 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
7
- const handler_container_1 = __importDefault(require("./handler-container"));
8
- const base_1 = __importDefault(require("./types/base"));
9
- const default_1 = __importDefault(require("./types/default"));
10
- const map_1 = __importDefault(require("./types/map"));
11
- const path_1 = __importDefault(require("./utils/path"));
12
- var ContextType;
13
- (function (ContextType) {
14
- ContextType[ContextType["Api"] = 0] = "Api";
15
- ContextType[ContextType["Global"] = 1] = "Global";
16
- ContextType[ContextType["Function"] = 2] = "Function";
17
- ContextType[ContextType["External"] = 3] = "External";
18
- ContextType[ContextType["Loop"] = 4] = "Loop";
19
- ContextType[ContextType["Map"] = 5] = "Map";
20
- ContextType[ContextType["Call"] = 6] = "Call";
21
- })(ContextType = exports.ContextType || (exports.ContextType = {}));
22
- var ContextState;
23
- (function (ContextState) {
24
- ContextState[ContextState["Temporary"] = 0] = "Temporary";
25
- ContextState[ContextState["Default"] = 1] = "Default";
26
- })(ContextState = exports.ContextState || (exports.ContextState = {}));
27
- class Scope extends map_1.default {
28
- constructor(context) {
29
- super();
30
- this.context = context;
31
- }
32
- get(path) {
33
- if (path instanceof base_1.default) {
34
- return this.get(new path_1.default([path]));
35
- }
36
- if (path.count() === 0) {
37
- return this;
38
- }
39
- const traversalPath = path.clone();
40
- const current = traversalPath.next();
41
- if (this.has(path)) {
42
- return super.get(path);
43
- }
44
- else if (this.context.api.scope.has(path)) {
45
- return this.context.api.scope.get(path);
46
- }
47
- else if (path.count() === 1 && map_1.default.getIntrinsics().has(current)) {
48
- return map_1.default.getIntrinsics().get(current);
49
- }
50
- else if (this.context.previous !== null) {
51
- return this.context.previous.get(path);
52
- }
53
- throw new Error(`Unknown path ${path.toString()}.`);
54
- }
55
- }
56
- exports.Scope = Scope;
57
- class Debugger {
58
- constructor() {
59
- this.breakpoint = false;
60
- this.nextStep = false;
61
- /* eslint-disable no-use-before-define */
62
- this.lastContext = null;
63
- }
64
- getLastContext() {
65
- return this.lastContext;
66
- }
67
- debug(...segments) {
68
- console.debug(...segments);
69
- return default_1.default.Void;
70
- }
71
- setBreakpoint(breakpoint) {
72
- this.breakpoint = breakpoint;
73
- return this;
74
- }
75
- getBreakpoint(_ctx) {
76
- return this.breakpoint;
77
- }
78
- next() {
79
- this.nextStep = true;
80
- return this;
81
- }
82
- resume() {
83
- if (!this.breakpoint) {
84
- return Promise.resolve();
85
- }
86
- return new Promise((resolve) => {
87
- const check = () => {
88
- if (!this.breakpoint) {
89
- resolve();
90
- }
91
- else if (this.nextStep) {
92
- this.nextStep = false;
93
- resolve();
94
- }
95
- else {
96
- setTimeout(check);
97
- }
98
- };
99
- check();
100
- });
101
- }
102
- interact(ctx, _ast, _op) {
103
- const me = this;
104
- console.warn('Debugger is not setup.');
105
- console.info(ctx);
106
- me.breakpoint = false;
107
- }
108
- }
109
- exports.Debugger = Debugger;
110
- class ProcessState {
111
- constructor() {
112
- this.isExit = false;
113
- this.isPending = false;
114
- /* eslint-disable no-use-before-define */
115
- this.last = null;
116
- }
117
- }
118
- exports.ProcessState = ProcessState;
119
- class LoopState {
120
- constructor() {
121
- this.isBreak = false;
122
- this.isContinue = false;
123
- }
124
- }
125
- exports.LoopState = LoopState;
126
- class FunctionState {
127
- constructor() {
128
- this.value = default_1.default.Void;
129
- this.isReturn = false;
130
- }
131
- }
132
- exports.FunctionState = FunctionState;
133
- class OperationContext {
134
- constructor(options = {}) {
135
- this.target = options.target || 'unknown';
136
- this.stackItem = null;
137
- this.previous = options.previous || null;
138
- this.type = options.type || ContextType.Api;
139
- this.state = options.state || ContextState.Default;
140
- this.scope = new Scope(this);
141
- this.isProtected = options.isProtected || false;
142
- this.injected = options.injected || false;
143
- this.debugger = options.debugger || new Debugger();
144
- this.handler = options.handler || new handler_container_1.default();
145
- this.cps = options.cps || null;
146
- this.processState = options.processState || new ProcessState();
147
- this.api = this.lookupApi();
148
- this.globals = this.lookupGlobals();
149
- this.locals = this.lookupLocals() || this;
150
- }
151
- step(op) {
152
- if (!this.injected) {
153
- this.stackItem = op.item;
154
- this.target = op.target || this.target;
155
- this.setLastActive(this);
156
- if (this.debugger.getBreakpoint(this)) {
157
- this.debugger.interact(this, op.item, op);
158
- return this.debugger.resume();
159
- }
160
- }
161
- return Promise.resolve();
162
- }
163
- setLastActive(ctx) {
164
- if (!ctx.injected) {
165
- this.processState.last = ctx;
166
- }
167
- return this;
168
- }
169
- getLastActive() {
170
- return this.processState.last;
171
- }
172
- isExit() {
173
- return this.processState.isExit;
174
- }
175
- isPending() {
176
- return this.processState.isPending;
177
- }
178
- setPending(pending) {
179
- this.processState.isPending = pending;
180
- return this;
181
- }
182
- lookupAllOfType(validate) {
183
- const me = this;
184
- const result = [];
185
- if (validate(me.type)) {
186
- result.push(me);
187
- }
188
- let current = me.previous;
189
- while (current) {
190
- if (validate(current.type)) {
191
- result.push(current);
192
- }
193
- current = current.previous;
194
- }
195
- return result;
196
- }
197
- exit() {
198
- if (this.processState.isPending) {
199
- this.processState.isExit = true;
200
- return new Promise((resolve) => {
201
- const check = () => {
202
- if (!this.processState.isPending) {
203
- this.processState.isExit = false;
204
- resolve(this);
205
- }
206
- else {
207
- setTimeout(check);
208
- }
209
- };
210
- check();
211
- });
212
- }
213
- return Promise.reject(new Error('No running process found.'));
214
- }
215
- lookupType(allowedTypes) {
216
- if (allowedTypes.includes(this.type)) {
217
- return this;
218
- }
219
- let current = this.previous;
220
- while (current !== null) {
221
- if (allowedTypes.includes(current.type)) {
222
- return current;
223
- }
224
- current = current.previous;
225
- }
226
- return null;
227
- }
228
- lookupAllScopes() {
229
- return this.lookupAllOfType((type) => [ContextType.Global, ContextType.Function].includes(type));
230
- }
231
- lookupApi() {
232
- return this.lookupType(OperationContext.lookupApiType);
233
- }
234
- lookupGlobals() {
235
- return this.lookupType(OperationContext.lookupGlobalsType);
236
- }
237
- lookupLocals() {
238
- return this.lookupType(OperationContext.lookupLocalsType);
239
- }
240
- extend(map) {
241
- var _a;
242
- if (this.state === ContextState.Temporary) {
243
- (_a = this.previous) === null || _a === void 0 ? void 0 : _a.extend(map);
244
- }
245
- else {
246
- this.scope.extend(map);
247
- }
248
- return this;
249
- }
250
- set(path, value) {
251
- var _a;
252
- if (path instanceof base_1.default) {
253
- this.set(new path_1.default([path]), value);
254
- return;
255
- }
256
- if (this.state === ContextState.Temporary) {
257
- (_a = this.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
258
- }
259
- else {
260
- this.locals.scope.set(path, value);
261
- }
262
- }
263
- get(path) {
264
- var _a;
265
- if (path instanceof base_1.default) {
266
- return this.get(new path_1.default([path]));
267
- }
268
- if (path.count() === 0) {
269
- return this.scope;
270
- }
271
- if (this.state === ContextState.Temporary) {
272
- return (_a = this.previous) === null || _a === void 0 ? void 0 : _a.get(path);
273
- }
274
- return this.locals.scope.get(path);
275
- }
276
- fork(options) {
277
- const newContext = new OperationContext({
278
- target: options.target || this.target,
279
- previous: this,
280
- type: options.type,
281
- state: options.state,
282
- isProtected: false,
283
- injected: this.injected,
284
- debugger: this.debugger,
285
- handler: this.handler,
286
- cps: this.cps,
287
- processState: this.processState
288
- });
289
- if (this.type !== ContextType.Function) {
290
- if (this.type !== ContextType.Loop) {
291
- newContext.loopState = this.loopState;
292
- }
293
- newContext.functionState = this.functionState;
294
- }
295
- return newContext;
296
- }
297
- }
298
- exports.default = OperationContext;
299
- OperationContext.lookupApiType = [ContextType.Api];
300
- OperationContext.lookupGlobalsType = [
301
- ContextType.Global
302
- ];
303
- OperationContext.lookupLocalsType = [
304
- ContextType.Global,
305
- ContextType.Function
306
- ];
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
7
+ const handler_container_1 = __importDefault(require("./handler-container"));
8
+ const base_1 = __importDefault(require("./types/base"));
9
+ const default_1 = __importDefault(require("./types/default"));
10
+ const map_1 = __importDefault(require("./types/map"));
11
+ const path_1 = __importDefault(require("./utils/path"));
12
+ var ContextType;
13
+ (function (ContextType) {
14
+ ContextType[ContextType["Api"] = 0] = "Api";
15
+ ContextType[ContextType["Global"] = 1] = "Global";
16
+ ContextType[ContextType["Function"] = 2] = "Function";
17
+ ContextType[ContextType["External"] = 3] = "External";
18
+ ContextType[ContextType["Loop"] = 4] = "Loop";
19
+ ContextType[ContextType["Map"] = 5] = "Map";
20
+ ContextType[ContextType["Call"] = 6] = "Call";
21
+ })(ContextType = exports.ContextType || (exports.ContextType = {}));
22
+ var ContextState;
23
+ (function (ContextState) {
24
+ ContextState[ContextState["Temporary"] = 0] = "Temporary";
25
+ ContextState[ContextState["Default"] = 1] = "Default";
26
+ })(ContextState = exports.ContextState || (exports.ContextState = {}));
27
+ class Scope extends map_1.default {
28
+ constructor(context) {
29
+ super();
30
+ this.context = context;
31
+ }
32
+ get(path) {
33
+ if (path instanceof base_1.default) {
34
+ return this.get(new path_1.default([path]));
35
+ }
36
+ if (path.count() === 0) {
37
+ return this;
38
+ }
39
+ const traversalPath = path.clone();
40
+ const current = traversalPath.next();
41
+ if (this.has(path)) {
42
+ return super.get(path);
43
+ }
44
+ else if (this.context.api.scope.has(path)) {
45
+ return this.context.api.scope.get(path);
46
+ }
47
+ else if (path.count() === 1 && map_1.default.getIntrinsics().has(current)) {
48
+ return map_1.default.getIntrinsics().get(current);
49
+ }
50
+ else if (this.context.previous !== null) {
51
+ return this.context.previous.get(path);
52
+ }
53
+ throw new Error(`Unknown path ${path.toString()}.`);
54
+ }
55
+ }
56
+ exports.Scope = Scope;
57
+ class Debugger {
58
+ constructor() {
59
+ this.breakpoint = false;
60
+ this.nextStep = false;
61
+ /* eslint-disable no-use-before-define */
62
+ this.lastContext = null;
63
+ }
64
+ getLastContext() {
65
+ return this.lastContext;
66
+ }
67
+ debug(...segments) {
68
+ console.debug(...segments);
69
+ return default_1.default.Void;
70
+ }
71
+ setBreakpoint(breakpoint) {
72
+ this.breakpoint = breakpoint;
73
+ return this;
74
+ }
75
+ getBreakpoint(_ctx) {
76
+ return this.breakpoint;
77
+ }
78
+ next() {
79
+ this.nextStep = true;
80
+ return this;
81
+ }
82
+ resume() {
83
+ if (!this.breakpoint) {
84
+ return Promise.resolve();
85
+ }
86
+ return new Promise((resolve) => {
87
+ const check = () => {
88
+ if (!this.breakpoint) {
89
+ resolve();
90
+ }
91
+ else if (this.nextStep) {
92
+ this.nextStep = false;
93
+ resolve();
94
+ }
95
+ else {
96
+ setTimeout(check);
97
+ }
98
+ };
99
+ check();
100
+ });
101
+ }
102
+ interact(ctx, _ast, _op) {
103
+ const me = this;
104
+ console.warn('Debugger is not setup.');
105
+ console.info(ctx);
106
+ me.breakpoint = false;
107
+ }
108
+ }
109
+ exports.Debugger = Debugger;
110
+ class ProcessState {
111
+ constructor() {
112
+ this.isExit = false;
113
+ this.isPending = false;
114
+ /* eslint-disable no-use-before-define */
115
+ this.last = null;
116
+ }
117
+ }
118
+ exports.ProcessState = ProcessState;
119
+ class LoopState {
120
+ constructor() {
121
+ this.isBreak = false;
122
+ this.isContinue = false;
123
+ }
124
+ }
125
+ exports.LoopState = LoopState;
126
+ class FunctionState {
127
+ constructor() {
128
+ this.value = default_1.default.Void;
129
+ this.isReturn = false;
130
+ }
131
+ }
132
+ exports.FunctionState = FunctionState;
133
+ class OperationContext {
134
+ constructor(options = {}) {
135
+ this.target = options.target || 'unknown';
136
+ this.stackItem = null;
137
+ this.previous = options.previous || null;
138
+ this.type = options.type || ContextType.Api;
139
+ this.state = options.state || ContextState.Default;
140
+ this.scope = new Scope(this);
141
+ this.isProtected = options.isProtected || false;
142
+ this.injected = options.injected || false;
143
+ this.debugger = options.debugger || new Debugger();
144
+ this.handler = options.handler || new handler_container_1.default();
145
+ this.cps = options.cps || null;
146
+ this.processState = options.processState || new ProcessState();
147
+ this.api = this.lookupApi();
148
+ this.globals = this.lookupGlobals();
149
+ this.locals = this.lookupLocals() || this;
150
+ }
151
+ step(op) {
152
+ if (!this.injected) {
153
+ this.stackItem = op.item;
154
+ this.target = op.target || this.target;
155
+ this.setLastActive(this);
156
+ if (this.debugger.getBreakpoint(this)) {
157
+ this.debugger.interact(this, op.item, op);
158
+ return this.debugger.resume();
159
+ }
160
+ }
161
+ return Promise.resolve();
162
+ }
163
+ setLastActive(ctx) {
164
+ if (!ctx.injected) {
165
+ this.processState.last = ctx;
166
+ }
167
+ return this;
168
+ }
169
+ getLastActive() {
170
+ return this.processState.last;
171
+ }
172
+ isExit() {
173
+ return this.processState.isExit;
174
+ }
175
+ isPending() {
176
+ return this.processState.isPending;
177
+ }
178
+ setPending(pending) {
179
+ this.processState.isPending = pending;
180
+ return this;
181
+ }
182
+ lookupAllOfType(validate) {
183
+ const me = this;
184
+ const result = [];
185
+ if (validate(me.type)) {
186
+ result.push(me);
187
+ }
188
+ let current = me.previous;
189
+ while (current) {
190
+ if (validate(current.type)) {
191
+ result.push(current);
192
+ }
193
+ current = current.previous;
194
+ }
195
+ return result;
196
+ }
197
+ exit() {
198
+ if (this.processState.isPending) {
199
+ this.processState.isExit = true;
200
+ return new Promise((resolve) => {
201
+ const check = () => {
202
+ if (!this.processState.isPending) {
203
+ this.processState.isExit = false;
204
+ resolve(this);
205
+ }
206
+ else {
207
+ setTimeout(check);
208
+ }
209
+ };
210
+ check();
211
+ });
212
+ }
213
+ return Promise.reject(new Error('No running process found.'));
214
+ }
215
+ lookupType(allowedTypes) {
216
+ if (allowedTypes.includes(this.type)) {
217
+ return this;
218
+ }
219
+ let current = this.previous;
220
+ while (current !== null) {
221
+ if (allowedTypes.includes(current.type)) {
222
+ return current;
223
+ }
224
+ current = current.previous;
225
+ }
226
+ return null;
227
+ }
228
+ lookupAllScopes() {
229
+ return this.lookupAllOfType((type) => [ContextType.Global, ContextType.Function].includes(type));
230
+ }
231
+ lookupApi() {
232
+ return this.lookupType(OperationContext.lookupApiType);
233
+ }
234
+ lookupGlobals() {
235
+ return this.lookupType(OperationContext.lookupGlobalsType);
236
+ }
237
+ lookupLocals() {
238
+ return this.lookupType(OperationContext.lookupLocalsType);
239
+ }
240
+ extend(map) {
241
+ var _a;
242
+ if (this.state === ContextState.Temporary) {
243
+ (_a = this.previous) === null || _a === void 0 ? void 0 : _a.extend(map);
244
+ }
245
+ else {
246
+ this.scope.extend(map);
247
+ }
248
+ return this;
249
+ }
250
+ set(path, value) {
251
+ var _a;
252
+ if (path instanceof base_1.default) {
253
+ this.set(new path_1.default([path]), value);
254
+ return;
255
+ }
256
+ if (this.state === ContextState.Temporary) {
257
+ (_a = this.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
258
+ }
259
+ else {
260
+ this.locals.scope.set(path, value);
261
+ }
262
+ }
263
+ get(path) {
264
+ var _a;
265
+ if (path instanceof base_1.default) {
266
+ return this.get(new path_1.default([path]));
267
+ }
268
+ if (path.count() === 0) {
269
+ return this.scope;
270
+ }
271
+ if (this.state === ContextState.Temporary) {
272
+ return (_a = this.previous) === null || _a === void 0 ? void 0 : _a.get(path);
273
+ }
274
+ return this.locals.scope.get(path);
275
+ }
276
+ fork(options) {
277
+ const newContext = new OperationContext({
278
+ target: options.target || this.target,
279
+ previous: this,
280
+ type: options.type,
281
+ state: options.state,
282
+ isProtected: false,
283
+ injected: this.injected,
284
+ debugger: this.debugger,
285
+ handler: this.handler,
286
+ cps: this.cps,
287
+ processState: this.processState
288
+ });
289
+ if (this.type !== ContextType.Function) {
290
+ if (this.type !== ContextType.Loop) {
291
+ newContext.loopState = this.loopState;
292
+ }
293
+ newContext.functionState = this.functionState;
294
+ }
295
+ return newContext;
296
+ }
297
+ }
298
+ exports.default = OperationContext;
299
+ OperationContext.lookupApiType = [ContextType.Api];
300
+ OperationContext.lookupGlobalsType = [
301
+ ContextType.Global
302
+ ];
303
+ OperationContext.lookupLocalsType = [
304
+ ContextType.Global,
305
+ ContextType.Function
306
+ ];
package/dist/cps.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { ASTBase } from 'greyscript-core';
2
- import HandlerContainer from './handler-container';
3
- import Operation from './operations/operation';
4
- export declare class CPSContext {
5
- readonly target: string;
6
- readonly handler: HandlerContainer;
7
- constructor(target: string, handler: HandlerContainer);
8
- }
9
- export default class CPS {
10
- private readonly context;
11
- private __visit;
12
- constructor(context: CPSContext);
13
- visit(item: ASTBase): Promise<Operation>;
14
- }
1
+ import { ASTBase } from 'greyscript-core';
2
+ import HandlerContainer from './handler-container';
3
+ import Operation from './operations/operation';
4
+ export declare class CPSContext {
5
+ readonly target: string;
6
+ readonly handler: HandlerContainer;
7
+ constructor(target: string, handler: HandlerContainer);
8
+ }
9
+ export default class CPS {
10
+ private readonly context;
11
+ private __visit;
12
+ constructor(context: CPSContext);
13
+ visit(item: ASTBase): Promise<Operation>;
14
+ }