greybel-interpreter 0.7.2 → 1.0.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/.editorconfig +15 -0
- package/.eslintrc +48 -0
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +109 -98
- package/dist/context.js +378 -456
- package/dist/cps.d.ts +15 -17
- package/dist/cps.js +220 -872
- package/dist/handler/error.d.ts +6 -0
- package/dist/{operations/debugger.js → handler/error.js} +35 -32
- package/dist/handler/output.d.ts +6 -0
- package/dist/{operations/if.js → handler/output.js} +35 -31
- package/dist/handler/resource.d.ts +12 -0
- package/dist/handler/resource.js +51 -0
- package/dist/handler-container.d.ts +14 -0
- package/dist/handler-container.js +16 -0
- package/dist/index.d.ts +44 -36
- package/dist/index.js +129 -93
- package/dist/interpreter.d.ts +39 -29
- package/dist/interpreter.js +292 -210
- package/dist/intrinsics-container.d.ts +7 -0
- package/dist/intrinsics-container.js +19 -0
- package/dist/operations/assign.d.ts +13 -0
- package/dist/operations/assign.js +111 -0
- package/dist/operations/block.d.ts +12 -0
- package/dist/operations/{body.js → block.js} +108 -140
- package/dist/operations/break.d.ts +10 -7
- package/dist/operations/break.js +41 -34
- package/dist/operations/call.d.ts +13 -0
- package/dist/operations/call.js +124 -0
- package/dist/operations/chunk.d.ts +12 -0
- package/dist/operations/chunk.js +85 -0
- package/dist/operations/continue.d.ts +10 -7
- package/dist/operations/continue.js +41 -34
- package/dist/operations/debugger-statement.d.ts +10 -0
- package/dist/operations/{else-if.js → debugger-statement.js} +39 -31
- package/dist/operations/evaluate.d.ts +39 -0
- package/dist/operations/evaluate.js +366 -0
- package/dist/operations/for.d.ts +15 -16
- package/dist/operations/for.js +146 -143
- package/dist/operations/function-reference.d.ts +12 -0
- package/dist/operations/function-reference.js +103 -0
- package/dist/operations/function.d.ts +12 -26
- package/dist/operations/function.js +198 -145
- package/dist/operations/if-statement.d.ts +19 -8
- package/dist/operations/if-statement.js +181 -169
- package/dist/operations/import.d.ts +14 -0
- package/dist/{expressions/include.js → operations/import.js} +115 -132
- package/dist/operations/include.d.ts +13 -0
- package/dist/operations/include.js +95 -0
- package/dist/operations/list.d.ts +11 -0
- package/dist/{expressions → operations}/list.js +111 -142
- package/dist/operations/literal.d.ts +11 -0
- package/dist/operations/literal.js +58 -0
- package/dist/operations/map.d.ts +11 -0
- package/dist/operations/{argument.js → map.js} +167 -145
- package/dist/operations/negated-binary.d.ts +11 -0
- package/dist/{expressions/binary-negated-expression.js → operations/negated-binary.js} +109 -127
- package/dist/operations/new-instance.d.ts +11 -0
- package/dist/operations/{new.js → new-instance.js} +100 -97
- package/dist/operations/noop.d.ts +9 -0
- package/dist/operations/{else.js → noop.js} +36 -30
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +96 -96
- package/dist/operations/operation.d.ts +13 -0
- package/dist/operations/operation.js +11 -0
- package/dist/operations/reference.d.ts +9 -11
- package/dist/operations/reference.js +37 -103
- package/dist/operations/resolve.d.ts +38 -0
- package/dist/operations/resolve.js +330 -0
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +107 -106
- package/dist/operations/while.d.ts +13 -14
- package/dist/operations/while.js +129 -145
- package/dist/types/boolean.d.ts +11 -0
- package/dist/{custom-types → types}/boolean.js +46 -47
- package/dist/types/default.d.ts +11 -0
- package/dist/types/default.js +20 -0
- package/dist/types/function.d.ts +32 -0
- package/dist/types/function.js +174 -0
- package/dist/types/generics.d.ts +17 -0
- package/dist/types/{operation.js → generics.js} +40 -38
- package/dist/types/interface.d.ts +22 -0
- package/dist/types/interface.js +102 -0
- package/dist/types/list.d.ts +31 -0
- package/dist/types/list.js +227 -0
- package/dist/types/map.d.ts +30 -0
- package/dist/types/map.js +224 -0
- package/dist/types/nil.d.ts +9 -0
- package/dist/{custom-types → types}/nil.js +44 -44
- package/dist/types/number.d.ts +11 -0
- package/dist/{custom-types → types}/number.js +46 -47
- package/dist/types/string.d.ts +33 -0
- package/dist/types/string.js +149 -0
- package/dist/utils/path.d.ts +10 -0
- package/dist/utils/path.js +59 -0
- package/package.json +58 -44
- package/dist/custom-types/boolean.d.ts +0 -12
- package/dist/custom-types/list.d.ts +0 -26
- package/dist/custom-types/list.js +0 -236
- package/dist/custom-types/map.d.ts +0 -26
- package/dist/custom-types/map.js +0 -245
- package/dist/custom-types/nil.d.ts +0 -10
- package/dist/custom-types/number.d.ts +0 -12
- package/dist/custom-types/string.d.ts +0 -25
- package/dist/custom-types/string.js +0 -172
- package/dist/expressions/assign.d.ts +0 -13
- package/dist/expressions/assign.js +0 -174
- package/dist/expressions/binary-negated-expression.d.ts +0 -18
- package/dist/expressions/call.d.ts +0 -14
- package/dist/expressions/call.js +0 -209
- package/dist/expressions/import.d.ts +0 -14
- package/dist/expressions/import.js +0 -155
- package/dist/expressions/include.d.ts +0 -13
- package/dist/expressions/list.d.ts +0 -14
- package/dist/expressions/logical-and-binary.d.ts +0 -22
- package/dist/expressions/logical-and-binary.js +0 -222
- package/dist/expressions/map.d.ts +0 -19
- package/dist/expressions/map.js +0 -197
- package/dist/expressions/path.d.ts +0 -31
- package/dist/expressions/path.js +0 -384
- package/dist/operations/argument.d.ts +0 -8
- package/dist/operations/body.d.ts +0 -8
- package/dist/operations/debugger.d.ts +0 -7
- package/dist/operations/else-if.d.ts +0 -12
- package/dist/operations/else.d.ts +0 -10
- package/dist/operations/if.d.ts +0 -12
- package/dist/operations/new.d.ts +0 -11
- package/dist/resource.d.ts +0 -9
- package/dist/resource.js +0 -29
- package/dist/typer.d.ts +0 -6
- package/dist/typer.js +0 -95
- package/dist/types/custom-type.d.ts +0 -22
- package/dist/types/custom-type.js +0 -67
- package/dist/types/expression.d.ts +0 -7
- package/dist/types/expression.js +0 -9
- package/dist/types/operation.d.ts +0 -10
package/dist/interpreter.d.ts
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
import OperationContext, { Debugger } from './context';
|
|
4
|
+
import CPS from './cps';
|
|
5
|
+
import HandlerContainer from './handler-container';
|
|
6
|
+
import Operation from './operations/operation';
|
|
7
|
+
import { CustomValue } from './types/generics';
|
|
8
|
+
export interface InterpreterOptions {
|
|
9
|
+
target?: string;
|
|
10
|
+
api?: Map<string, CustomValue>;
|
|
11
|
+
params?: Array<string>;
|
|
12
|
+
handler?: HandlerContainer;
|
|
13
|
+
debugger?: Debugger;
|
|
14
|
+
}
|
|
15
|
+
export default class Interpreter extends EventEmitter {
|
|
16
|
+
target: string;
|
|
17
|
+
api: Map<string, CustomValue>;
|
|
18
|
+
params: Array<string>;
|
|
19
|
+
handler: HandlerContainer;
|
|
20
|
+
debugger: Debugger;
|
|
21
|
+
apiContext: OperationContext;
|
|
22
|
+
globalContext: OperationContext;
|
|
23
|
+
cps: CPS;
|
|
24
|
+
constructor(options: InterpreterOptions);
|
|
25
|
+
setTarget(target: string): Interpreter;
|
|
26
|
+
setDebugger(dbgr: Debugger): Interpreter;
|
|
27
|
+
setApi(newApi: Map<string, CustomValue>): Interpreter;
|
|
28
|
+
setHandler(handler: HandlerContainer): Interpreter;
|
|
29
|
+
prepare(code: string): Promise<Operation>;
|
|
30
|
+
inject(code: string, context?: OperationContext): Promise<Interpreter>;
|
|
31
|
+
injectInLastContext(code: string): Promise<Interpreter>;
|
|
32
|
+
run(customCode?: string): Promise<Interpreter>;
|
|
33
|
+
start(top: Operation): Promise<Interpreter>;
|
|
34
|
+
resume(): Interpreter;
|
|
35
|
+
pause(): Interpreter;
|
|
36
|
+
exit(): Promise<OperationContext>;
|
|
37
|
+
setGlobalVariable(path: string, value: CustomValue): Interpreter;
|
|
38
|
+
getGlobalVariable(path: string): CustomValue;
|
|
39
|
+
}
|
package/dist/interpreter.js
CHANGED
|
@@ -1,210 +1,292 @@
|
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
Interpreter.prototype.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return [4 /*yield*/,
|
|
169
|
-
case
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return [3 /*break*/,
|
|
184
|
-
case
|
|
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
|
-
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
50
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
+
function step(op) {
|
|
54
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
+
while (_) try {
|
|
56
|
+
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;
|
|
57
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
+
switch (op[0]) {
|
|
59
|
+
case 0: case 1: t = op; break;
|
|
60
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
+
default:
|
|
64
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
+
if (t[2]) _.ops.pop();
|
|
69
|
+
_.trys.pop(); continue;
|
|
70
|
+
}
|
|
71
|
+
op = body.call(thisArg, _);
|
|
72
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
77
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
78
|
+
};
|
|
79
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
80
|
+
var events_1 = __importDefault(require("events"));
|
|
81
|
+
var greybel_core_1 = require("greybel-core");
|
|
82
|
+
var context_1 = __importStar(require("./context"));
|
|
83
|
+
var cps_1 = __importStar(require("./cps"));
|
|
84
|
+
var handler_container_1 = __importDefault(require("./handler-container"));
|
|
85
|
+
var noop_1 = __importDefault(require("./operations/noop"));
|
|
86
|
+
var default_1 = __importDefault(require("./types/default"));
|
|
87
|
+
var list_1 = __importDefault(require("./types/list"));
|
|
88
|
+
var string_1 = __importDefault(require("./types/string"));
|
|
89
|
+
var Interpreter = /** @class */ (function (_super) {
|
|
90
|
+
__extends(Interpreter, _super);
|
|
91
|
+
function Interpreter(options) {
|
|
92
|
+
var _this = _super.call(this) || this;
|
|
93
|
+
_this.handler = options.handler || new handler_container_1.default();
|
|
94
|
+
_this.debugger = options.debugger || new context_1.Debugger();
|
|
95
|
+
_this.api = options.api || new Map();
|
|
96
|
+
_this.params = options.params || [];
|
|
97
|
+
_this.apiContext = null;
|
|
98
|
+
_this.globalContext = null;
|
|
99
|
+
_this.setTarget(options.target || 'unknown');
|
|
100
|
+
return _this;
|
|
101
|
+
}
|
|
102
|
+
Interpreter.prototype.setTarget = function (target) {
|
|
103
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
104
|
+
throw new Error('You cannot set a target while a process is running.');
|
|
105
|
+
}
|
|
106
|
+
this.target = target;
|
|
107
|
+
var cpsCtx = new cps_1.CPSContext(target, this.handler);
|
|
108
|
+
this.cps = new cps_1.default(cpsCtx);
|
|
109
|
+
this.apiContext = new context_1.default({
|
|
110
|
+
target: target,
|
|
111
|
+
isProtected: true,
|
|
112
|
+
debugger: this.debugger,
|
|
113
|
+
handler: this.handler,
|
|
114
|
+
cps: this.cps
|
|
115
|
+
});
|
|
116
|
+
this.globalContext = this.apiContext.fork({
|
|
117
|
+
type: context_1.ContextType.Global,
|
|
118
|
+
state: context_1.ContextState.Default
|
|
119
|
+
});
|
|
120
|
+
return this;
|
|
121
|
+
};
|
|
122
|
+
Interpreter.prototype.setDebugger = function (dbgr) {
|
|
123
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
124
|
+
throw new Error('You cannot set a target while a process is running.');
|
|
125
|
+
}
|
|
126
|
+
this.debugger = dbgr;
|
|
127
|
+
this.apiContext.debugger = dbgr;
|
|
128
|
+
this.globalContext.debugger = dbgr;
|
|
129
|
+
return this;
|
|
130
|
+
};
|
|
131
|
+
Interpreter.prototype.setApi = function (newApi) {
|
|
132
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
133
|
+
throw new Error('You cannot set a target while a process is running.');
|
|
134
|
+
}
|
|
135
|
+
this.api = newApi;
|
|
136
|
+
return this;
|
|
137
|
+
};
|
|
138
|
+
Interpreter.prototype.setHandler = function (handler) {
|
|
139
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
140
|
+
throw new Error('You cannot set a target while a process is running.');
|
|
141
|
+
}
|
|
142
|
+
this.handler = handler;
|
|
143
|
+
this.apiContext.handler = handler;
|
|
144
|
+
this.globalContext.handler = handler;
|
|
145
|
+
return this;
|
|
146
|
+
};
|
|
147
|
+
Interpreter.prototype.prepare = function (code) {
|
|
148
|
+
try {
|
|
149
|
+
var parser = new greybel_core_1.Parser(code);
|
|
150
|
+
var chunk = parser.parseChunk();
|
|
151
|
+
return this.cps.visit(chunk);
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
this.handler.errorHandler.raise(err);
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
this.apiContext.setPending(false);
|
|
158
|
+
}
|
|
159
|
+
return Promise.resolve(new noop_1.default());
|
|
160
|
+
};
|
|
161
|
+
Interpreter.prototype.inject = function (code, context) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
163
|
+
var top, injectionCtx, err_1;
|
|
164
|
+
return __generator(this, function (_a) {
|
|
165
|
+
switch (_a.label) {
|
|
166
|
+
case 0:
|
|
167
|
+
_a.trys.push([0, 3, , 4]);
|
|
168
|
+
return [4 /*yield*/, this.prepare(code)];
|
|
169
|
+
case 1:
|
|
170
|
+
top = _a.sent();
|
|
171
|
+
injectionCtx = (context || this.globalContext).fork({
|
|
172
|
+
type: context_1.ContextType.Call,
|
|
173
|
+
state: context_1.ContextState.Temporary,
|
|
174
|
+
injected: true
|
|
175
|
+
});
|
|
176
|
+
return [4 /*yield*/, top.handle(injectionCtx)];
|
|
177
|
+
case 2:
|
|
178
|
+
_a.sent();
|
|
179
|
+
return [3 /*break*/, 4];
|
|
180
|
+
case 3:
|
|
181
|
+
err_1 = _a.sent();
|
|
182
|
+
this.handler.errorHandler.raise(err_1);
|
|
183
|
+
return [3 /*break*/, 4];
|
|
184
|
+
case 4: return [2 /*return*/, this];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
Interpreter.prototype.injectInLastContext = function (code) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
191
|
+
var last;
|
|
192
|
+
return __generator(this, function (_a) {
|
|
193
|
+
last = this.apiContext.getLastActive();
|
|
194
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
195
|
+
return [2 /*return*/, this.inject(code, last)];
|
|
196
|
+
}
|
|
197
|
+
throw new Error('Unable to inject into last context.');
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
Interpreter.prototype.run = function (customCode) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
var code, _a, top;
|
|
204
|
+
return __generator(this, function (_b) {
|
|
205
|
+
switch (_b.label) {
|
|
206
|
+
case 0:
|
|
207
|
+
_a = customCode;
|
|
208
|
+
if (_a) return [3 /*break*/, 2];
|
|
209
|
+
return [4 /*yield*/, this.handler.resourceHandler.get(this.target)];
|
|
210
|
+
case 1:
|
|
211
|
+
_a = (_b.sent());
|
|
212
|
+
_b.label = 2;
|
|
213
|
+
case 2:
|
|
214
|
+
code = _a;
|
|
215
|
+
return [4 /*yield*/, this.prepare(code)];
|
|
216
|
+
case 3:
|
|
217
|
+
top = _b.sent();
|
|
218
|
+
return [2 /*return*/, this.start(top)];
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
Interpreter.prototype.start = function (top) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
+
var newParams, process_1, err_2;
|
|
226
|
+
return __generator(this, function (_a) {
|
|
227
|
+
switch (_a.label) {
|
|
228
|
+
case 0:
|
|
229
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
230
|
+
throw new Error('Process already running.');
|
|
231
|
+
}
|
|
232
|
+
this.apiContext.extend(this.api);
|
|
233
|
+
newParams = new list_1.default(this.params.map(function (item) { return new string_1.default(item); }));
|
|
234
|
+
this.globalContext.scope.set('params', newParams);
|
|
235
|
+
_a.label = 1;
|
|
236
|
+
case 1:
|
|
237
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
238
|
+
this.apiContext.setPending(true);
|
|
239
|
+
process_1 = top.handle(this.globalContext);
|
|
240
|
+
this.emit('start', this);
|
|
241
|
+
return [4 /*yield*/, process_1];
|
|
242
|
+
case 2:
|
|
243
|
+
_a.sent();
|
|
244
|
+
return [3 /*break*/, 5];
|
|
245
|
+
case 3:
|
|
246
|
+
err_2 = _a.sent();
|
|
247
|
+
this.handler.errorHandler.raise(err_2);
|
|
248
|
+
return [3 /*break*/, 5];
|
|
249
|
+
case 4:
|
|
250
|
+
this.apiContext.setPending(false);
|
|
251
|
+
this.emit('exit', this);
|
|
252
|
+
return [7 /*endfinally*/];
|
|
253
|
+
case 5: return [2 /*return*/, this];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
Interpreter.prototype.resume = function () {
|
|
259
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
260
|
+
this.debugger.setBreakpoint(false);
|
|
261
|
+
}
|
|
262
|
+
return this;
|
|
263
|
+
};
|
|
264
|
+
Interpreter.prototype.pause = function () {
|
|
265
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
266
|
+
this.debugger.setBreakpoint(true);
|
|
267
|
+
}
|
|
268
|
+
return this;
|
|
269
|
+
};
|
|
270
|
+
Interpreter.prototype.exit = function () {
|
|
271
|
+
try {
|
|
272
|
+
return this.apiContext.exit();
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
this.handler.errorHandler.raise(err);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
Interpreter.prototype.setGlobalVariable = function (path, value) {
|
|
279
|
+
if (this.globalContext != null) {
|
|
280
|
+
this.globalContext.set(path, value);
|
|
281
|
+
}
|
|
282
|
+
return this;
|
|
283
|
+
};
|
|
284
|
+
Interpreter.prototype.getGlobalVariable = function (path) {
|
|
285
|
+
if (this.globalContext != null) {
|
|
286
|
+
this.globalContext.get(path);
|
|
287
|
+
}
|
|
288
|
+
return default_1.default.Void;
|
|
289
|
+
};
|
|
290
|
+
return Interpreter;
|
|
291
|
+
}(events_1.default));
|
|
292
|
+
exports.default = Interpreter;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var IntrinsicsContainer = /** @class */ (function () {
|
|
4
|
+
function IntrinsicsContainer() {
|
|
5
|
+
this.intrinsics = new Map();
|
|
6
|
+
}
|
|
7
|
+
IntrinsicsContainer.prototype.add = function (name, fn) {
|
|
8
|
+
this.intrinsics.set(name, fn);
|
|
9
|
+
return this;
|
|
10
|
+
};
|
|
11
|
+
IntrinsicsContainer.prototype.has = function (name) {
|
|
12
|
+
return this.intrinsics.has(name);
|
|
13
|
+
};
|
|
14
|
+
IntrinsicsContainer.prototype.get = function (name) {
|
|
15
|
+
return this.intrinsics.get(name) || null;
|
|
16
|
+
};
|
|
17
|
+
return IntrinsicsContainer;
|
|
18
|
+
}());
|
|
19
|
+
exports.default = IntrinsicsContainer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ASTAssignmentStatement } from 'greyscript-core';
|
|
2
|
+
import OperationContext from '../context';
|
|
3
|
+
import { CustomValue } from '../types/generics';
|
|
4
|
+
import Operation, { CPSVisit } from './operation';
|
|
5
|
+
import Resolve from './resolve';
|
|
6
|
+
export default class Assign extends Operation {
|
|
7
|
+
readonly item: ASTAssignmentStatement;
|
|
8
|
+
left: Resolve;
|
|
9
|
+
right: Operation;
|
|
10
|
+
constructor(item: ASTAssignmentStatement, target?: string);
|
|
11
|
+
build(visit: CPSVisit): Promise<Operation>;
|
|
12
|
+
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
13
|
+
}
|