greybel-interpreter 1.4.4 → 1.4.5
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/dist/context.d.ts +3 -2
- package/dist/context.js +113 -190
- package/dist/cps.js +135 -188
- package/dist/handler/error.js +6 -29
- package/dist/handler/output.js +15 -38
- package/dist/handler/resource.js +16 -39
- package/dist/handler-container.js +6 -8
- package/dist/index.d.ts +4 -3
- package/dist/index.js +10 -9
- package/dist/interpreter.d.ts +4 -4
- package/dist/interpreter.js +108 -203
- package/dist/operations/assign.d.ts +1 -1
- package/dist/operations/assign.js +28 -93
- package/dist/operations/block.d.ts +1 -1
- package/dist/operations/block.js +33 -89
- package/dist/operations/break.d.ts +1 -1
- package/dist/operations/break.js +11 -29
- package/dist/operations/call.d.ts +1 -1
- package/dist/operations/call.js +31 -106
- package/dist/operations/chunk.d.ts +1 -1
- package/dist/operations/chunk.js +15 -67
- package/dist/operations/continue.d.ts +1 -1
- package/dist/operations/continue.js +11 -29
- package/dist/operations/debugger-statement.d.ts +1 -1
- package/dist/operations/debugger-statement.js +11 -29
- package/dist/operations/evaluate.d.ts +1 -1
- package/dist/operations/evaluate.js +143 -247
- package/dist/operations/for.d.ts +1 -1
- package/dist/operations/for.js +62 -133
- package/dist/operations/function-reference.d.ts +1 -1
- package/dist/operations/function-reference.js +25 -84
- package/dist/operations/function.d.ts +1 -1
- package/dist/operations/function.js +49 -177
- package/dist/operations/if-statement.d.ts +1 -1
- package/dist/operations/if-statement.js +58 -154
- package/dist/operations/import.d.ts +1 -1
- package/dist/operations/import.js +35 -97
- package/dist/operations/include.d.ts +1 -1
- package/dist/operations/include.js +19 -73
- package/dist/operations/list.d.ts +1 -1
- package/dist/operations/list.js +24 -93
- package/dist/operations/literal.d.ts +1 -1
- package/dist/operations/literal.js +15 -33
- package/dist/operations/map.d.ts +1 -1
- package/dist/operations/map.js +26 -153
- package/dist/operations/negated-binary.d.ts +1 -1
- package/dist/operations/negated-binary.js +24 -91
- package/dist/operations/new-instance.d.ts +1 -1
- package/dist/operations/new-instance.js +21 -82
- package/dist/operations/noop.d.ts +1 -1
- package/dist/operations/noop.js +10 -27
- package/dist/operations/not.d.ts +1 -1
- package/dist/operations/not.js +17 -78
- package/dist/operations/operation.d.ts +2 -2
- package/dist/operations/operation.js +3 -5
- package/dist/operations/reference.d.ts +1 -1
- package/dist/operations/reference.js +10 -28
- package/dist/operations/resolve.d.ts +1 -1
- package/dist/operations/resolve.js +161 -281
- package/dist/operations/return.d.ts +1 -1
- package/dist/operations/return.js +27 -89
- package/dist/operations/while.d.ts +1 -1
- package/dist/operations/while.js +45 -116
- package/dist/types/base.d.ts +9 -0
- package/dist/types/base.js +5 -0
- package/dist/types/boolean.d.ts +3 -1
- package/dist/types/boolean.js +24 -36
- package/dist/types/default.d.ts +6 -9
- package/dist/types/default.js +11 -17
- package/dist/types/function.d.ts +1 -1
- package/dist/types/function.js +60 -130
- package/dist/types/interface.d.ts +2 -1
- package/dist/types/interface.js +44 -64
- package/dist/types/list.d.ts +4 -6
- package/dist/types/list.js +77 -128
- package/dist/types/map.d.ts +11 -15
- package/dist/types/map.js +102 -266
- package/dist/types/nil.d.ts +2 -1
- package/dist/types/nil.js +23 -36
- package/dist/types/number.d.ts +16 -2
- package/dist/types/number.js +60 -37
- package/dist/types/string.d.ts +4 -6
- package/dist/types/string.js +66 -90
- package/dist/types/{generics.d.ts → with-intrinsics.d.ts} +6 -9
- package/dist/types/with-intrinsics.js +19 -0
- package/dist/utils/deep-equal.js +9 -34
- package/dist/utils/object-value.d.ts +6 -0
- package/dist/utils/object-value.js +36 -0
- package/dist/utils/path.js +16 -43
- package/package.json +3 -3
- package/dist/intrinsics-container.d.ts +0 -7
- package/dist/intrinsics-container.js +0 -19
- package/dist/types/generics.js +0 -40
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Noop = exports.NewInstance = exports.NegatedBinary = exports.MapOperation = exports.Literal = exports.List = exports.Include = exports.Import = exports.IfStatement = exports.Clause = exports.FunctionOpertion = exports.For = exports.StringProcessorHandler = exports.NumberProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.
|
|
7
|
-
exports.Path = exports.
|
|
6
|
+
exports.Not = exports.Noop = exports.NewInstance = exports.NegatedBinary = exports.MapOperation = exports.Literal = exports.List = exports.Include = exports.Import = exports.IfStatement = exports.Clause = exports.FunctionOpertion = exports.For = exports.StringProcessorHandler = exports.NumberProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.handleString = exports.handleNumber = exports.handleMap = exports.handleList = exports.handleInterface = exports.handle = exports.GenericProcessorHandler = exports.Evaluate = exports.DebuggerStatement = exports.Continue = exports.Chunk = exports.Call = exports.Break = exports.Block = exports.Assign = exports.Interpreter = exports.HandlerContainer = exports.ResourceHandler = exports.DefaultResourceHandler = exports.OutputHandler = exports.DefaultOutputHandler = exports.ErrorHandler = exports.DefaultErrorHandler = exports.CPSContext = exports.CPS = exports.Scope = exports.ProcessState = exports.OperationContext = exports.LoopState = exports.FunctionState = exports.Debugger = exports.ContextType = exports.ContextState = void 0;
|
|
7
|
+
exports.Path = exports.ObjectValue = exports.deepEqual = exports.CustomValueWithIntrinsics = exports.CustomObject = exports.CustomStringIterator = exports.CustomString = exports.CustomNumber = exports.CustomNil = exports.CustomMapIterator = exports.CustomMap = exports.CustomListIterator = exports.CustomList = exports.CustomInterfaceIterator = exports.CustomInterface = exports.CustomFunction = exports.Argument = exports.Defaults = exports.CustomBoolean = exports.CustomValue = exports.While = exports.Return = exports.ResolveResult = exports.Resolve = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.Reference = exports.Operation = void 0;
|
|
8
8
|
var context_1 = require("./context");
|
|
9
9
|
Object.defineProperty(exports, "ContextState", { enumerable: true, get: function () { return context_1.ContextState; } });
|
|
10
10
|
Object.defineProperty(exports, "ContextType", { enumerable: true, get: function () { return context_1.ContextType; } });
|
|
@@ -30,8 +30,6 @@ var handler_container_1 = require("./handler-container");
|
|
|
30
30
|
Object.defineProperty(exports, "HandlerContainer", { enumerable: true, get: function () { return __importDefault(handler_container_1).default; } });
|
|
31
31
|
var interpreter_1 = require("./interpreter");
|
|
32
32
|
Object.defineProperty(exports, "Interpreter", { enumerable: true, get: function () { return __importDefault(interpreter_1).default; } });
|
|
33
|
-
var intrinsics_container_1 = require("./intrinsics-container");
|
|
34
|
-
Object.defineProperty(exports, "IntrinsicsContainer", { enumerable: true, get: function () { return __importDefault(intrinsics_container_1).default; } });
|
|
35
33
|
var assign_1 = require("./operations/assign");
|
|
36
34
|
Object.defineProperty(exports, "Assign", { enumerable: true, get: function () { return __importDefault(assign_1).default; } });
|
|
37
35
|
var block_1 = require("./operations/block");
|
|
@@ -50,11 +48,11 @@ var evaluate_1 = require("./operations/evaluate");
|
|
|
50
48
|
Object.defineProperty(exports, "Evaluate", { enumerable: true, get: function () { return __importDefault(evaluate_1).default; } });
|
|
51
49
|
Object.defineProperty(exports, "GenericProcessorHandler", { enumerable: true, get: function () { return evaluate_1.GenericProcessorHandler; } });
|
|
52
50
|
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return evaluate_1.handle; } });
|
|
51
|
+
Object.defineProperty(exports, "handleInterface", { enumerable: true, get: function () { return evaluate_1.handleInterface; } });
|
|
53
52
|
Object.defineProperty(exports, "handleList", { enumerable: true, get: function () { return evaluate_1.handleList; } });
|
|
54
53
|
Object.defineProperty(exports, "handleMap", { enumerable: true, get: function () { return evaluate_1.handleMap; } });
|
|
55
54
|
Object.defineProperty(exports, "handleNumber", { enumerable: true, get: function () { return evaluate_1.handleNumber; } });
|
|
56
55
|
Object.defineProperty(exports, "handleString", { enumerable: true, get: function () { return evaluate_1.handleString; } });
|
|
57
|
-
Object.defineProperty(exports, "handleInterface", { enumerable: true, get: function () { return evaluate_1.handleInterface; } });
|
|
58
56
|
Object.defineProperty(exports, "ListProcessorHandler", { enumerable: true, get: function () { return evaluate_1.ListProcessorHandler; } });
|
|
59
57
|
Object.defineProperty(exports, "MapProcessorHandler", { enumerable: true, get: function () { return evaluate_1.MapProcessorHandler; } });
|
|
60
58
|
Object.defineProperty(exports, "NumberProcessorHandler", { enumerable: true, get: function () { return evaluate_1.NumberProcessorHandler; } });
|
|
@@ -98,6 +96,8 @@ var return_1 = require("./operations/return");
|
|
|
98
96
|
Object.defineProperty(exports, "Return", { enumerable: true, get: function () { return __importDefault(return_1).default; } });
|
|
99
97
|
var while_1 = require("./operations/while");
|
|
100
98
|
Object.defineProperty(exports, "While", { enumerable: true, get: function () { return __importDefault(while_1).default; } });
|
|
99
|
+
var base_1 = require("./types/base");
|
|
100
|
+
Object.defineProperty(exports, "CustomValue", { enumerable: true, get: function () { return __importDefault(base_1).default; } });
|
|
101
101
|
var boolean_1 = require("./types/boolean");
|
|
102
102
|
Object.defineProperty(exports, "CustomBoolean", { enumerable: true, get: function () { return __importDefault(boolean_1).default; } });
|
|
103
103
|
var default_1 = require("./types/default");
|
|
@@ -105,10 +105,6 @@ Object.defineProperty(exports, "Defaults", { enumerable: true, get: function ()
|
|
|
105
105
|
var function_2 = require("./types/function");
|
|
106
106
|
Object.defineProperty(exports, "Argument", { enumerable: true, get: function () { return function_2.Argument; } });
|
|
107
107
|
Object.defineProperty(exports, "CustomFunction", { enumerable: true, get: function () { return __importDefault(function_2).default; } });
|
|
108
|
-
var generics_1 = require("./types/generics");
|
|
109
|
-
Object.defineProperty(exports, "CustomObject", { enumerable: true, get: function () { return generics_1.CustomObject; } });
|
|
110
|
-
Object.defineProperty(exports, "CustomValue", { enumerable: true, get: function () { return generics_1.CustomValue; } });
|
|
111
|
-
Object.defineProperty(exports, "CustomValueWithIntrinsics", { enumerable: true, get: function () { return generics_1.CustomValueWithIntrinsics; } });
|
|
112
108
|
var interface_1 = require("./types/interface");
|
|
113
109
|
Object.defineProperty(exports, "CustomInterface", { enumerable: true, get: function () { return __importDefault(interface_1).default; } });
|
|
114
110
|
Object.defineProperty(exports, "CustomInterfaceIterator", { enumerable: true, get: function () { return interface_1.CustomInterfaceIterator; } });
|
|
@@ -125,7 +121,12 @@ Object.defineProperty(exports, "CustomNumber", { enumerable: true, get: function
|
|
|
125
121
|
var string_1 = require("./types/string");
|
|
126
122
|
Object.defineProperty(exports, "CustomString", { enumerable: true, get: function () { return __importDefault(string_1).default; } });
|
|
127
123
|
Object.defineProperty(exports, "CustomStringIterator", { enumerable: true, get: function () { return string_1.CustomStringIterator; } });
|
|
124
|
+
var with_intrinsics_1 = require("./types/with-intrinsics");
|
|
125
|
+
Object.defineProperty(exports, "CustomObject", { enumerable: true, get: function () { return with_intrinsics_1.CustomObject; } });
|
|
126
|
+
Object.defineProperty(exports, "CustomValueWithIntrinsics", { enumerable: true, get: function () { return with_intrinsics_1.CustomValueWithIntrinsics; } });
|
|
128
127
|
var deep_equal_1 = require("./utils/deep-equal");
|
|
129
128
|
Object.defineProperty(exports, "deepEqual", { enumerable: true, get: function () { return __importDefault(deep_equal_1).default; } });
|
|
129
|
+
var object_value_1 = require("./utils/object-value");
|
|
130
|
+
Object.defineProperty(exports, "ObjectValue", { enumerable: true, get: function () { return __importDefault(object_value_1).default; } });
|
|
130
131
|
var path_1 = require("./utils/path");
|
|
131
132
|
Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return __importDefault(path_1).default; } });
|
package/dist/interpreter.d.ts
CHANGED
|
@@ -4,19 +4,19 @@ import OperationContext, { Debugger } from './context';
|
|
|
4
4
|
import CPS from './cps';
|
|
5
5
|
import HandlerContainer from './handler-container';
|
|
6
6
|
import Operation from './operations/operation';
|
|
7
|
-
import
|
|
7
|
+
import CustomValue from './types/base';
|
|
8
8
|
import CustomString from './types/string';
|
|
9
9
|
export declare const PARAMS_PROPERTY: CustomString;
|
|
10
10
|
export interface InterpreterOptions {
|
|
11
11
|
target?: string;
|
|
12
|
-
api?: Map<
|
|
12
|
+
api?: Map<CustomValue, CustomValue>;
|
|
13
13
|
params?: Array<string>;
|
|
14
14
|
handler?: HandlerContainer;
|
|
15
15
|
debugger?: Debugger;
|
|
16
16
|
}
|
|
17
17
|
export default class Interpreter extends EventEmitter {
|
|
18
18
|
target: string;
|
|
19
|
-
api: Map<
|
|
19
|
+
api: Map<CustomValue, CustomValue>;
|
|
20
20
|
params: Array<string>;
|
|
21
21
|
handler: HandlerContainer;
|
|
22
22
|
debugger: Debugger;
|
|
@@ -26,7 +26,7 @@ export default class Interpreter extends EventEmitter {
|
|
|
26
26
|
constructor(options: InterpreterOptions);
|
|
27
27
|
setTarget(target: string): Interpreter;
|
|
28
28
|
setDebugger(dbgr: Debugger): Interpreter;
|
|
29
|
-
setApi(newApi: Map<
|
|
29
|
+
setApi(newApi: Map<CustomValue, CustomValue>): Interpreter;
|
|
30
30
|
setHandler(handler: HandlerContainer): Interpreter;
|
|
31
31
|
prepare(code: string): Promise<Operation>;
|
|
32
32
|
inject(code: string, context?: OperationContext): Promise<Interpreter>;
|
package/dist/interpreter.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
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
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
3
|
if (k2 === undefined) k2 = k;
|
|
19
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -46,86 +31,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
46
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
32
|
});
|
|
48
33
|
};
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
77
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
78
|
-
if (!m) return o;
|
|
79
|
-
var i = m.call(o), r, ar = [], e;
|
|
80
|
-
try {
|
|
81
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
82
|
-
}
|
|
83
|
-
catch (error) { e = { error: error }; }
|
|
84
|
-
finally {
|
|
85
|
-
try {
|
|
86
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
87
|
-
}
|
|
88
|
-
finally { if (e) throw e.error; }
|
|
89
|
-
}
|
|
90
|
-
return ar;
|
|
91
|
-
};
|
|
92
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
93
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
94
36
|
};
|
|
95
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
96
38
|
exports.PARAMS_PROPERTY = void 0;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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"));
|
|
106
50
|
exports.PARAMS_PROPERTY = new string_1.default('params');
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
_this.setTarget(options.target || 'unknown');
|
|
118
|
-
return _this;
|
|
51
|
+
class Interpreter extends events_1.default {
|
|
52
|
+
constructor(options) {
|
|
53
|
+
super();
|
|
54
|
+
this.handler = options.handler || new handler_container_1.default();
|
|
55
|
+
this.debugger = options.debugger || new context_1.Debugger();
|
|
56
|
+
this.api = options.api || new Map();
|
|
57
|
+
this.params = options.params || [];
|
|
58
|
+
this.apiContext = null;
|
|
59
|
+
this.globalContext = null;
|
|
60
|
+
this.setTarget(options.target || 'unknown');
|
|
119
61
|
}
|
|
120
|
-
|
|
62
|
+
setTarget(target) {
|
|
121
63
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
122
64
|
throw new Error('You cannot set a target while a process is running.');
|
|
123
65
|
}
|
|
124
66
|
this.target = target;
|
|
125
|
-
|
|
67
|
+
const cpsCtx = new cps_1.CPSContext(target, this.handler);
|
|
126
68
|
this.cps = new cps_1.default(cpsCtx);
|
|
127
69
|
this.apiContext = new context_1.default({
|
|
128
|
-
target
|
|
70
|
+
target,
|
|
129
71
|
isProtected: true,
|
|
130
72
|
debugger: this.debugger,
|
|
131
73
|
handler: this.handler,
|
|
@@ -136,8 +78,8 @@ var Interpreter = /** @class */ (function (_super) {
|
|
|
136
78
|
state: context_1.ContextState.Default
|
|
137
79
|
});
|
|
138
80
|
return this;
|
|
139
|
-
}
|
|
140
|
-
|
|
81
|
+
}
|
|
82
|
+
setDebugger(dbgr) {
|
|
141
83
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
142
84
|
throw new Error('You cannot set a target while a process is running.');
|
|
143
85
|
}
|
|
@@ -145,15 +87,15 @@ var Interpreter = /** @class */ (function (_super) {
|
|
|
145
87
|
this.apiContext.debugger = dbgr;
|
|
146
88
|
this.globalContext.debugger = dbgr;
|
|
147
89
|
return this;
|
|
148
|
-
}
|
|
149
|
-
|
|
90
|
+
}
|
|
91
|
+
setApi(newApi) {
|
|
150
92
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
151
93
|
throw new Error('You cannot set a target while a process is running.');
|
|
152
94
|
}
|
|
153
95
|
this.api = newApi;
|
|
154
96
|
return this;
|
|
155
|
-
}
|
|
156
|
-
|
|
97
|
+
}
|
|
98
|
+
setHandler(handler) {
|
|
157
99
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
158
100
|
throw new Error('You cannot set a target while a process is running.');
|
|
159
101
|
}
|
|
@@ -161,152 +103,115 @@ var Interpreter = /** @class */ (function (_super) {
|
|
|
161
103
|
this.apiContext.handler = handler;
|
|
162
104
|
this.globalContext.handler = handler;
|
|
163
105
|
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
106
|
+
}
|
|
107
|
+
prepare(code) {
|
|
166
108
|
try {
|
|
167
|
-
|
|
168
|
-
|
|
109
|
+
const parser = new greybel_core_1.Parser(code);
|
|
110
|
+
const chunk = parser.parseChunk();
|
|
169
111
|
return this.cps.visit(chunk);
|
|
170
112
|
}
|
|
171
113
|
catch (err) {
|
|
172
114
|
this.handler.errorHandler.raise(err);
|
|
173
115
|
}
|
|
174
116
|
return Promise.resolve(new noop_1.default());
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return [4 /*yield*/, top.handle(injectionCtx)];
|
|
192
|
-
case 2:
|
|
193
|
-
_a.sent();
|
|
194
|
-
return [3 /*break*/, 4];
|
|
195
|
-
case 3:
|
|
196
|
-
err_1 = _a.sent();
|
|
197
|
-
this.handler.errorHandler.raise(err_1);
|
|
198
|
-
return [3 /*break*/, 4];
|
|
199
|
-
case 4: return [2 /*return*/, this];
|
|
200
|
-
}
|
|
201
|
-
});
|
|
117
|
+
}
|
|
118
|
+
inject(code, context) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
try {
|
|
121
|
+
const top = yield this.prepare(code);
|
|
122
|
+
const injectionCtx = (context || this.globalContext).fork({
|
|
123
|
+
type: context_1.ContextType.Call,
|
|
124
|
+
state: context_1.ContextState.Temporary,
|
|
125
|
+
injected: true
|
|
126
|
+
});
|
|
127
|
+
yield top.handle(injectionCtx);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
this.handler.errorHandler.raise(err);
|
|
131
|
+
}
|
|
132
|
+
return this;
|
|
202
133
|
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
throw new Error('Unable to inject into last context.');
|
|
213
|
-
});
|
|
134
|
+
}
|
|
135
|
+
injectInLastContext(code) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const last = this.apiContext.getLastActive();
|
|
138
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
139
|
+
return this.inject(code, last);
|
|
140
|
+
}
|
|
141
|
+
throw new Error('Unable to inject into last context.');
|
|
214
142
|
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
case 0:
|
|
222
|
-
_a = customCode;
|
|
223
|
-
if (_a) return [3 /*break*/, 2];
|
|
224
|
-
return [4 /*yield*/, this.handler.resourceHandler.get(this.target)];
|
|
225
|
-
case 1:
|
|
226
|
-
_a = (_b.sent());
|
|
227
|
-
_b.label = 2;
|
|
228
|
-
case 2:
|
|
229
|
-
code = _a;
|
|
230
|
-
return [4 /*yield*/, this.prepare(code)];
|
|
231
|
-
case 3:
|
|
232
|
-
top = _b.sent();
|
|
233
|
-
return [2 /*return*/, this.start(top)];
|
|
234
|
-
}
|
|
235
|
-
});
|
|
143
|
+
}
|
|
144
|
+
run(customCode) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const code = customCode || (yield this.handler.resourceHandler.get(this.target));
|
|
147
|
+
const top = yield this.prepare(code);
|
|
148
|
+
return this.start(top);
|
|
236
149
|
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
case 4:
|
|
270
|
-
this.apiContext.setPending(false);
|
|
271
|
-
this.emit('exit', this);
|
|
272
|
-
return [7 /*endfinally*/];
|
|
273
|
-
case 5: return [2 /*return*/, this];
|
|
274
|
-
}
|
|
275
|
-
});
|
|
150
|
+
}
|
|
151
|
+
start(top) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
154
|
+
throw new Error('Process already running.');
|
|
155
|
+
}
|
|
156
|
+
const stringIntrinsics = map_1.default.createWithInitialValue(string_1.default.intrinsics);
|
|
157
|
+
const numberIntrinsics = map_1.default.createWithInitialValue(number_1.default.intrinsics);
|
|
158
|
+
const listIntrinsics = map_1.default.createWithInitialValue(list_1.default.intrinsics);
|
|
159
|
+
const mapIntrinsics = map_1.default.createWithInitialValue(map_1.default.intrinsics);
|
|
160
|
+
this.apiContext.set(new string_1.default('string'), stringIntrinsics);
|
|
161
|
+
this.apiContext.set(new string_1.default('number'), numberIntrinsics);
|
|
162
|
+
this.apiContext.set(new string_1.default('list'), listIntrinsics);
|
|
163
|
+
this.apiContext.set(new string_1.default('map'), mapIntrinsics);
|
|
164
|
+
this.apiContext.extend(this.api);
|
|
165
|
+
const newParams = new list_1.default(this.params.map((item) => new string_1.default(item)));
|
|
166
|
+
this.globalContext.scope.set(exports.PARAMS_PROPERTY, newParams);
|
|
167
|
+
this.globalContext.set(new string_1.default('globals'), this.globalContext.scope);
|
|
168
|
+
try {
|
|
169
|
+
this.apiContext.setPending(true);
|
|
170
|
+
const process = top.handle(this.globalContext);
|
|
171
|
+
this.emit('start', this);
|
|
172
|
+
yield process;
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
this.handler.errorHandler.raise(err);
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
this.apiContext.setPending(false);
|
|
179
|
+
this.emit('exit', this);
|
|
180
|
+
}
|
|
181
|
+
return this;
|
|
276
182
|
});
|
|
277
|
-
}
|
|
278
|
-
|
|
183
|
+
}
|
|
184
|
+
resume() {
|
|
279
185
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
280
186
|
this.debugger.setBreakpoint(false);
|
|
281
187
|
}
|
|
282
188
|
return this;
|
|
283
|
-
}
|
|
284
|
-
|
|
189
|
+
}
|
|
190
|
+
pause() {
|
|
285
191
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
286
192
|
this.debugger.setBreakpoint(true);
|
|
287
193
|
}
|
|
288
194
|
return this;
|
|
289
|
-
}
|
|
290
|
-
|
|
195
|
+
}
|
|
196
|
+
exit() {
|
|
291
197
|
try {
|
|
292
198
|
return this.apiContext.exit();
|
|
293
199
|
}
|
|
294
200
|
catch (err) {
|
|
295
201
|
this.handler.errorHandler.raise(err);
|
|
296
202
|
}
|
|
297
|
-
}
|
|
298
|
-
|
|
203
|
+
}
|
|
204
|
+
setGlobalVariable(path, value) {
|
|
299
205
|
if (this.globalContext != null) {
|
|
300
206
|
this.globalContext.set(new string_1.default(path), value);
|
|
301
207
|
}
|
|
302
208
|
return this;
|
|
303
|
-
}
|
|
304
|
-
|
|
209
|
+
}
|
|
210
|
+
getGlobalVariable(path) {
|
|
305
211
|
if (this.globalContext != null) {
|
|
306
212
|
this.globalContext.get(new string_1.default(path));
|
|
307
213
|
}
|
|
308
214
|
return default_1.default.Void;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
}(events_1.default));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
312
217
|
exports.default = Interpreter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ASTAssignmentStatement } from 'greyscript-core';
|
|
2
2
|
import OperationContext from '../context';
|
|
3
|
-
import
|
|
3
|
+
import CustomValue from '../types/base';
|
|
4
4
|
import Operation, { CPSVisit } from './operation';
|
|
5
5
|
import Resolve from './resolve';
|
|
6
6
|
export default class Assign extends Operation {
|