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.
- package/.editorconfig +14 -14
- package/.eslintrc +47 -47
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +110 -110
- package/dist/context.js +306 -306
- package/dist/cps.d.ts +14 -14
- package/dist/cps.js +160 -160
- package/dist/handler/error.d.ts +6 -6
- package/dist/handler/error.js +12 -12
- package/dist/handler/output.d.ts +18 -18
- package/dist/handler/output.js +29 -29
- package/dist/handler/resource.d.ts +12 -12
- package/dist/handler/resource.js +28 -28
- package/dist/handler-container.d.ts +14 -14
- package/dist/handler-container.js +14 -14
- package/dist/index.d.ts +46 -46
- package/dist/index.js +132 -132
- package/dist/interpreter.d.ts +42 -42
- package/dist/interpreter.js +218 -218
- package/dist/operations/assign.d.ts +13 -13
- package/dist/operations/assign.js +46 -46
- package/dist/operations/block.d.ts +12 -12
- package/dist/operations/block.js +52 -52
- package/dist/operations/break.d.ts +10 -10
- package/dist/operations/break.js +23 -23
- package/dist/operations/call.d.ts +13 -13
- package/dist/operations/call.js +49 -49
- package/dist/operations/chunk.d.ts +12 -12
- package/dist/operations/chunk.js +33 -33
- package/dist/operations/continue.d.ts +10 -10
- package/dist/operations/continue.js +23 -23
- package/dist/operations/debugger-statement.d.ts +10 -10
- package/dist/operations/debugger-statement.js +21 -21
- package/dist/operations/evaluate.d.ts +40 -40
- package/dist/operations/evaluate.js +334 -334
- package/dist/operations/for.d.ts +14 -14
- package/dist/operations/for.js +81 -81
- package/dist/operations/function-reference.d.ts +12 -12
- package/dist/operations/function-reference.js +44 -44
- package/dist/operations/function.d.ts +14 -14
- package/dist/operations/function.js +72 -72
- package/dist/operations/if-statement.d.ts +19 -19
- package/dist/operations/if-statement.js +85 -85
- package/dist/operations/import.d.ts +17 -17
- package/dist/operations/import.js +57 -57
- package/dist/operations/include.d.ts +13 -13
- package/dist/operations/include.js +41 -41
- package/dist/operations/list.d.ts +11 -11
- package/dist/operations/list.js +42 -42
- package/dist/operations/literal.d.ts +11 -11
- package/dist/operations/literal.js +40 -40
- package/dist/operations/map.d.ts +11 -11
- package/dist/operations/map.js +44 -44
- package/dist/operations/negated-binary.d.ts +11 -11
- package/dist/operations/negated-binary.js +42 -42
- package/dist/operations/new-instance.d.ts +11 -11
- package/dist/operations/new-instance.js +39 -39
- package/dist/operations/noop.d.ts +9 -9
- package/dist/operations/noop.js +19 -19
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +35 -35
- package/dist/operations/operation.d.ts +13 -13
- package/dist/operations/operation.js +9 -9
- package/dist/operations/reference.d.ts +9 -9
- package/dist/operations/reference.js +19 -19
- package/dist/operations/resolve.d.ts +38 -38
- package/dist/operations/resolve.js +210 -210
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +45 -45
- package/dist/operations/while.d.ts +13 -13
- package/dist/operations/while.js +65 -65
- package/dist/types/base.d.ts +9 -9
- package/dist/types/base.js +5 -5
- package/dist/types/boolean.d.ts +13 -13
- package/dist/types/boolean.js +34 -34
- package/dist/types/default.d.ts +8 -8
- package/dist/types/default.js +14 -14
- package/dist/types/function.d.ts +32 -32
- package/dist/types/function.js +104 -104
- package/dist/types/interface.d.ts +24 -24
- package/dist/types/interface.js +83 -83
- package/dist/types/list.d.ts +29 -29
- package/dist/types/list.js +158 -158
- package/dist/types/map.d.ts +33 -33
- package/dist/types/map.js +200 -200
- package/dist/types/nil.d.ts +11 -11
- package/dist/types/nil.js +33 -33
- package/dist/types/number.d.ts +25 -25
- package/dist/types/number.js +69 -69
- package/dist/types/string.d.ts +31 -31
- package/dist/types/string.js +121 -121
- package/dist/types/with-intrinsics.d.ts +15 -15
- package/dist/types/with-intrinsics.js +19 -19
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +37 -37
- package/dist/utils/object-value.d.ts +7 -7
- package/dist/utils/object-value.js +42 -42
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +32 -32
- package/package.json +58 -58
package/dist/interpreter.js
CHANGED
|
@@ -1,218 +1,218 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.PARAMS_PROPERTY = void 0;
|
|
39
|
-
const events_1 = __importDefault(require("events"));
|
|
40
|
-
const greybel_core_1 = require("greybel-core");
|
|
41
|
-
const context_1 = __importStar(require("./context"));
|
|
42
|
-
const cps_1 = __importStar(require("./cps"));
|
|
43
|
-
const handler_container_1 = __importDefault(require("./handler-container"));
|
|
44
|
-
const noop_1 = __importDefault(require("./operations/noop"));
|
|
45
|
-
const default_1 = __importDefault(require("./types/default"));
|
|
46
|
-
const list_1 = __importDefault(require("./types/list"));
|
|
47
|
-
const map_1 = __importDefault(require("./types/map"));
|
|
48
|
-
const number_1 = __importDefault(require("./types/number"));
|
|
49
|
-
const string_1 = __importDefault(require("./types/string"));
|
|
50
|
-
const object_value_1 = __importDefault(require("./utils/object-value"));
|
|
51
|
-
exports.PARAMS_PROPERTY = new string_1.default('params');
|
|
52
|
-
class Interpreter extends events_1.default {
|
|
53
|
-
constructor(options) {
|
|
54
|
-
super();
|
|
55
|
-
this.handler = options.handler || new handler_container_1.default();
|
|
56
|
-
this.debugger = options.debugger || new context_1.Debugger();
|
|
57
|
-
this.api = options.api || new object_value_1.default();
|
|
58
|
-
this.params = options.params || [];
|
|
59
|
-
this.apiContext = null;
|
|
60
|
-
this.globalContext = null;
|
|
61
|
-
this.setTarget(options.target || 'unknown');
|
|
62
|
-
}
|
|
63
|
-
setTarget(target) {
|
|
64
|
-
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
65
|
-
throw new Error('You cannot set a target while a process is running.');
|
|
66
|
-
}
|
|
67
|
-
this.target = target;
|
|
68
|
-
const cpsCtx = new cps_1.CPSContext(target, this.handler);
|
|
69
|
-
this.cps = new cps_1.default(cpsCtx);
|
|
70
|
-
this.apiContext = new context_1.default({
|
|
71
|
-
target,
|
|
72
|
-
isProtected: true,
|
|
73
|
-
debugger: this.debugger,
|
|
74
|
-
handler: this.handler,
|
|
75
|
-
cps: this.cps
|
|
76
|
-
});
|
|
77
|
-
this.globalContext = this.apiContext.fork({
|
|
78
|
-
type: context_1.ContextType.Global,
|
|
79
|
-
state: context_1.ContextState.Default
|
|
80
|
-
});
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
setDebugger(dbgr) {
|
|
84
|
-
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
85
|
-
throw new Error('You cannot set a target while a process is running.');
|
|
86
|
-
}
|
|
87
|
-
this.debugger = dbgr;
|
|
88
|
-
this.apiContext.debugger = dbgr;
|
|
89
|
-
this.globalContext.debugger = dbgr;
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
setApi(newApi) {
|
|
93
|
-
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
94
|
-
throw new Error('You cannot set a target while a process is running.');
|
|
95
|
-
}
|
|
96
|
-
this.api = newApi;
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
setHandler(handler) {
|
|
100
|
-
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
101
|
-
throw new Error('You cannot set a target while a process is running.');
|
|
102
|
-
}
|
|
103
|
-
this.handler = handler;
|
|
104
|
-
this.apiContext.handler = handler;
|
|
105
|
-
this.globalContext.handler = handler;
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
prepare(code) {
|
|
109
|
-
try {
|
|
110
|
-
const parser = new greybel_core_1.Parser(code);
|
|
111
|
-
const chunk = parser.parseChunk();
|
|
112
|
-
return this.cps.visit(chunk);
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
this.handler.errorHandler.raise(err);
|
|
116
|
-
}
|
|
117
|
-
return Promise.resolve(new noop_1.default());
|
|
118
|
-
}
|
|
119
|
-
inject(code, context) {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
try {
|
|
122
|
-
const top = yield this.prepare(code);
|
|
123
|
-
const injectionCtx = (context || this.globalContext).fork({
|
|
124
|
-
type: context_1.ContextType.Call,
|
|
125
|
-
state: context_1.ContextState.Temporary,
|
|
126
|
-
injected: true
|
|
127
|
-
});
|
|
128
|
-
yield top.handle(injectionCtx);
|
|
129
|
-
}
|
|
130
|
-
catch (err) {
|
|
131
|
-
this.handler.errorHandler.raise(err);
|
|
132
|
-
}
|
|
133
|
-
return this;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
injectInLastContext(code) {
|
|
137
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
const last = this.apiContext.getLastActive();
|
|
139
|
-
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
140
|
-
return this.inject(code, last);
|
|
141
|
-
}
|
|
142
|
-
throw new Error('Unable to inject into last context.');
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
run(customCode) {
|
|
146
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
const code = customCode || (yield this.handler.resourceHandler.get(this.target));
|
|
148
|
-
const top = yield this.prepare(code);
|
|
149
|
-
return this.start(top);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
start(top) {
|
|
153
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
155
|
-
throw new Error('Process already running.');
|
|
156
|
-
}
|
|
157
|
-
const stringIntrinsics = map_1.default.createWithInitialValue(string_1.default.intrinsics);
|
|
158
|
-
const numberIntrinsics = map_1.default.createWithInitialValue(number_1.default.intrinsics);
|
|
159
|
-
const listIntrinsics = map_1.default.createWithInitialValue(list_1.default.intrinsics);
|
|
160
|
-
const mapIntrinsics = map_1.default.createWithInitialValue(map_1.default.intrinsics);
|
|
161
|
-
this.apiContext.set(new string_1.default('string'), stringIntrinsics);
|
|
162
|
-
this.apiContext.set(new string_1.default('number'), numberIntrinsics);
|
|
163
|
-
this.apiContext.set(new string_1.default('list'), listIntrinsics);
|
|
164
|
-
this.apiContext.set(new string_1.default('map'), mapIntrinsics);
|
|
165
|
-
this.apiContext.extend(this.api);
|
|
166
|
-
const newParams = new list_1.default(this.params.map((item) => new string_1.default(item)));
|
|
167
|
-
this.globalContext.scope.set(exports.PARAMS_PROPERTY, newParams);
|
|
168
|
-
this.globalContext.set(new string_1.default('globals'), this.globalContext.scope);
|
|
169
|
-
try {
|
|
170
|
-
this.apiContext.setPending(true);
|
|
171
|
-
const process = top.handle(this.globalContext);
|
|
172
|
-
this.emit('start', this);
|
|
173
|
-
yield process;
|
|
174
|
-
}
|
|
175
|
-
catch (err) {
|
|
176
|
-
this.handler.errorHandler.raise(err);
|
|
177
|
-
}
|
|
178
|
-
finally {
|
|
179
|
-
this.apiContext.setPending(false);
|
|
180
|
-
this.emit('exit', this);
|
|
181
|
-
}
|
|
182
|
-
return this;
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
resume() {
|
|
186
|
-
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
187
|
-
this.debugger.setBreakpoint(false);
|
|
188
|
-
}
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
pause() {
|
|
192
|
-
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
193
|
-
this.debugger.setBreakpoint(true);
|
|
194
|
-
}
|
|
195
|
-
return this;
|
|
196
|
-
}
|
|
197
|
-
exit() {
|
|
198
|
-
try {
|
|
199
|
-
return this.apiContext.exit();
|
|
200
|
-
}
|
|
201
|
-
catch (err) {
|
|
202
|
-
this.handler.errorHandler.raise(err);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
setGlobalVariable(path, value) {
|
|
206
|
-
if (this.globalContext != null) {
|
|
207
|
-
this.globalContext.set(new string_1.default(path), value);
|
|
208
|
-
}
|
|
209
|
-
return this;
|
|
210
|
-
}
|
|
211
|
-
getGlobalVariable(path) {
|
|
212
|
-
if (this.globalContext != null) {
|
|
213
|
-
this.globalContext.get(new string_1.default(path));
|
|
214
|
-
}
|
|
215
|
-
return default_1.default.Void;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
exports.default = Interpreter;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.PARAMS_PROPERTY = void 0;
|
|
39
|
+
const events_1 = __importDefault(require("events"));
|
|
40
|
+
const greybel_core_1 = require("greybel-core");
|
|
41
|
+
const context_1 = __importStar(require("./context"));
|
|
42
|
+
const cps_1 = __importStar(require("./cps"));
|
|
43
|
+
const handler_container_1 = __importDefault(require("./handler-container"));
|
|
44
|
+
const noop_1 = __importDefault(require("./operations/noop"));
|
|
45
|
+
const default_1 = __importDefault(require("./types/default"));
|
|
46
|
+
const list_1 = __importDefault(require("./types/list"));
|
|
47
|
+
const map_1 = __importDefault(require("./types/map"));
|
|
48
|
+
const number_1 = __importDefault(require("./types/number"));
|
|
49
|
+
const string_1 = __importDefault(require("./types/string"));
|
|
50
|
+
const object_value_1 = __importDefault(require("./utils/object-value"));
|
|
51
|
+
exports.PARAMS_PROPERTY = new string_1.default('params');
|
|
52
|
+
class Interpreter extends events_1.default {
|
|
53
|
+
constructor(options) {
|
|
54
|
+
super();
|
|
55
|
+
this.handler = options.handler || new handler_container_1.default();
|
|
56
|
+
this.debugger = options.debugger || new context_1.Debugger();
|
|
57
|
+
this.api = options.api || new object_value_1.default();
|
|
58
|
+
this.params = options.params || [];
|
|
59
|
+
this.apiContext = null;
|
|
60
|
+
this.globalContext = null;
|
|
61
|
+
this.setTarget(options.target || 'unknown');
|
|
62
|
+
}
|
|
63
|
+
setTarget(target) {
|
|
64
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
65
|
+
throw new Error('You cannot set a target while a process is running.');
|
|
66
|
+
}
|
|
67
|
+
this.target = target;
|
|
68
|
+
const cpsCtx = new cps_1.CPSContext(target, this.handler);
|
|
69
|
+
this.cps = new cps_1.default(cpsCtx);
|
|
70
|
+
this.apiContext = new context_1.default({
|
|
71
|
+
target,
|
|
72
|
+
isProtected: true,
|
|
73
|
+
debugger: this.debugger,
|
|
74
|
+
handler: this.handler,
|
|
75
|
+
cps: this.cps
|
|
76
|
+
});
|
|
77
|
+
this.globalContext = this.apiContext.fork({
|
|
78
|
+
type: context_1.ContextType.Global,
|
|
79
|
+
state: context_1.ContextState.Default
|
|
80
|
+
});
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
setDebugger(dbgr) {
|
|
84
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
85
|
+
throw new Error('You cannot set a target while a process is running.');
|
|
86
|
+
}
|
|
87
|
+
this.debugger = dbgr;
|
|
88
|
+
this.apiContext.debugger = dbgr;
|
|
89
|
+
this.globalContext.debugger = dbgr;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
setApi(newApi) {
|
|
93
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
94
|
+
throw new Error('You cannot set a target while a process is running.');
|
|
95
|
+
}
|
|
96
|
+
this.api = newApi;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
setHandler(handler) {
|
|
100
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
101
|
+
throw new Error('You cannot set a target while a process is running.');
|
|
102
|
+
}
|
|
103
|
+
this.handler = handler;
|
|
104
|
+
this.apiContext.handler = handler;
|
|
105
|
+
this.globalContext.handler = handler;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
prepare(code) {
|
|
109
|
+
try {
|
|
110
|
+
const parser = new greybel_core_1.Parser(code);
|
|
111
|
+
const chunk = parser.parseChunk();
|
|
112
|
+
return this.cps.visit(chunk);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
this.handler.errorHandler.raise(err);
|
|
116
|
+
}
|
|
117
|
+
return Promise.resolve(new noop_1.default());
|
|
118
|
+
}
|
|
119
|
+
inject(code, context) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
try {
|
|
122
|
+
const top = yield this.prepare(code);
|
|
123
|
+
const injectionCtx = (context || this.globalContext).fork({
|
|
124
|
+
type: context_1.ContextType.Call,
|
|
125
|
+
state: context_1.ContextState.Temporary,
|
|
126
|
+
injected: true
|
|
127
|
+
});
|
|
128
|
+
yield top.handle(injectionCtx);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
this.handler.errorHandler.raise(err);
|
|
132
|
+
}
|
|
133
|
+
return this;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
injectInLastContext(code) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const last = this.apiContext.getLastActive();
|
|
139
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
140
|
+
return this.inject(code, last);
|
|
141
|
+
}
|
|
142
|
+
throw new Error('Unable to inject into last context.');
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
run(customCode) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const code = customCode || (yield this.handler.resourceHandler.get(this.target));
|
|
148
|
+
const top = yield this.prepare(code);
|
|
149
|
+
return this.start(top);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
start(top) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
155
|
+
throw new Error('Process already running.');
|
|
156
|
+
}
|
|
157
|
+
const stringIntrinsics = map_1.default.createWithInitialValue(string_1.default.intrinsics);
|
|
158
|
+
const numberIntrinsics = map_1.default.createWithInitialValue(number_1.default.intrinsics);
|
|
159
|
+
const listIntrinsics = map_1.default.createWithInitialValue(list_1.default.intrinsics);
|
|
160
|
+
const mapIntrinsics = map_1.default.createWithInitialValue(map_1.default.intrinsics);
|
|
161
|
+
this.apiContext.set(new string_1.default('string'), stringIntrinsics);
|
|
162
|
+
this.apiContext.set(new string_1.default('number'), numberIntrinsics);
|
|
163
|
+
this.apiContext.set(new string_1.default('list'), listIntrinsics);
|
|
164
|
+
this.apiContext.set(new string_1.default('map'), mapIntrinsics);
|
|
165
|
+
this.apiContext.extend(this.api);
|
|
166
|
+
const newParams = new list_1.default(this.params.map((item) => new string_1.default(item)));
|
|
167
|
+
this.globalContext.scope.set(exports.PARAMS_PROPERTY, newParams);
|
|
168
|
+
this.globalContext.set(new string_1.default('globals'), this.globalContext.scope);
|
|
169
|
+
try {
|
|
170
|
+
this.apiContext.setPending(true);
|
|
171
|
+
const process = top.handle(this.globalContext);
|
|
172
|
+
this.emit('start', this);
|
|
173
|
+
yield process;
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
this.handler.errorHandler.raise(err);
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
this.apiContext.setPending(false);
|
|
180
|
+
this.emit('exit', this);
|
|
181
|
+
}
|
|
182
|
+
return this;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
resume() {
|
|
186
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
187
|
+
this.debugger.setBreakpoint(false);
|
|
188
|
+
}
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
pause() {
|
|
192
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
193
|
+
this.debugger.setBreakpoint(true);
|
|
194
|
+
}
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
exit() {
|
|
198
|
+
try {
|
|
199
|
+
return this.apiContext.exit();
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
this.handler.errorHandler.raise(err);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
setGlobalVariable(path, value) {
|
|
206
|
+
if (this.globalContext != null) {
|
|
207
|
+
this.globalContext.set(new string_1.default(path), value);
|
|
208
|
+
}
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
getGlobalVariable(path) {
|
|
212
|
+
if (this.globalContext != null) {
|
|
213
|
+
this.globalContext.get(new string_1.default(path));
|
|
214
|
+
}
|
|
215
|
+
return default_1.default.Void;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.default = Interpreter;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ASTAssignmentStatement } from 'greyscript-core';
|
|
2
|
-
import OperationContext from '../context';
|
|
3
|
-
import CustomValue from '../types/base';
|
|
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
|
-
}
|
|
1
|
+
import { ASTAssignmentStatement } from 'greyscript-core';
|
|
2
|
+
import OperationContext from '../context';
|
|
3
|
+
import CustomValue from '../types/base';
|
|
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
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const default_1 = __importDefault(require("../types/default"));
|
|
16
|
-
const operation_1 = __importDefault(require("./operation"));
|
|
17
|
-
const resolve_1 = __importDefault(require("./resolve"));
|
|
18
|
-
class Assign extends operation_1.default {
|
|
19
|
-
constructor(item, target) {
|
|
20
|
-
super(null, target);
|
|
21
|
-
this.item = item;
|
|
22
|
-
}
|
|
23
|
-
build(visit) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
this.left = new resolve_1.default(this.item.variable);
|
|
26
|
-
yield this.left.build(visit);
|
|
27
|
-
this.right = yield visit(this.item.init);
|
|
28
|
-
return this;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
handle(ctx) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const resolveResult = yield this.left.getResult(ctx);
|
|
34
|
-
const rightValue = yield this.right.handle(ctx);
|
|
35
|
-
if (resolveResult.handle !== default_1.default.Void) {
|
|
36
|
-
const resultValueCtx = resolveResult.handle;
|
|
37
|
-
resultValueCtx.set(resolveResult.path, rightValue);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
ctx.set(resolveResult.path, rightValue);
|
|
41
|
-
}
|
|
42
|
-
return default_1.default.Void;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.default = Assign;
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const default_1 = __importDefault(require("../types/default"));
|
|
16
|
+
const operation_1 = __importDefault(require("./operation"));
|
|
17
|
+
const resolve_1 = __importDefault(require("./resolve"));
|
|
18
|
+
class Assign extends operation_1.default {
|
|
19
|
+
constructor(item, target) {
|
|
20
|
+
super(null, target);
|
|
21
|
+
this.item = item;
|
|
22
|
+
}
|
|
23
|
+
build(visit) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
this.left = new resolve_1.default(this.item.variable);
|
|
26
|
+
yield this.left.build(visit);
|
|
27
|
+
this.right = yield visit(this.item.init);
|
|
28
|
+
return this;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
handle(ctx) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const resolveResult = yield this.left.getResult(ctx);
|
|
34
|
+
const rightValue = yield this.right.handle(ctx);
|
|
35
|
+
if (resolveResult.handle !== default_1.default.Void) {
|
|
36
|
+
const resultValueCtx = resolveResult.handle;
|
|
37
|
+
resultValueCtx.set(resolveResult.path, rightValue);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
ctx.set(resolveResult.path, rightValue);
|
|
41
|
+
}
|
|
42
|
+
return default_1.default.Void;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.default = Assign;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import OperationContext from '../context';
|
|
2
|
-
import CustomValue from '../types/base';
|
|
3
|
-
import Operation, { CPSVisit } from './operation';
|
|
4
|
-
export interface IsEOL {
|
|
5
|
-
(): boolean;
|
|
6
|
-
}
|
|
7
|
-
export default class Block extends Operation {
|
|
8
|
-
readonly stack: Array<Operation>;
|
|
9
|
-
constructor(stack: Array<Operation>);
|
|
10
|
-
build(_visit: CPSVisit): Promise<Block>;
|
|
11
|
-
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
12
|
-
}
|
|
1
|
+
import OperationContext from '../context';
|
|
2
|
+
import CustomValue from '../types/base';
|
|
3
|
+
import Operation, { CPSVisit } from './operation';
|
|
4
|
+
export interface IsEOL {
|
|
5
|
+
(): boolean;
|
|
6
|
+
}
|
|
7
|
+
export default class Block extends Operation {
|
|
8
|
+
readonly stack: Array<Operation>;
|
|
9
|
+
constructor(stack: Array<Operation>);
|
|
10
|
+
build(_visit: CPSVisit): Promise<Block>;
|
|
11
|
+
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
12
|
+
}
|