greybel-interpreter 1.4.4 → 1.4.6
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 +5 -4
- package/dist/interpreter.js +109 -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 +101 -267
- 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 +7 -0
- package/dist/utils/object-value.js +42 -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,20 @@ 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
|
+
import ObjectValue from './utils/object-value';
|
|
9
10
|
export declare const PARAMS_PROPERTY: CustomString;
|
|
10
11
|
export interface InterpreterOptions {
|
|
11
12
|
target?: string;
|
|
12
|
-
api?:
|
|
13
|
+
api?: ObjectValue;
|
|
13
14
|
params?: Array<string>;
|
|
14
15
|
handler?: HandlerContainer;
|
|
15
16
|
debugger?: Debugger;
|
|
16
17
|
}
|
|
17
18
|
export default class Interpreter extends EventEmitter {
|
|
18
19
|
target: string;
|
|
19
|
-
api:
|
|
20
|
+
api: ObjectValue;
|
|
20
21
|
params: Array<string>;
|
|
21
22
|
handler: HandlerContainer;
|
|
22
23
|
debugger: Debugger;
|
|
@@ -26,7 +27,7 @@ export default class Interpreter extends EventEmitter {
|
|
|
26
27
|
constructor(options: InterpreterOptions);
|
|
27
28
|
setTarget(target: string): Interpreter;
|
|
28
29
|
setDebugger(dbgr: Debugger): Interpreter;
|
|
29
|
-
setApi(newApi:
|
|
30
|
+
setApi(newApi: ObjectValue): Interpreter;
|
|
30
31
|
setHandler(handler: HandlerContainer): Interpreter;
|
|
31
32
|
prepare(code: string): Promise<Operation>;
|
|
32
33
|
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,44 @@ 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"));
|
|
50
|
+
const object_value_1 = __importDefault(require("./utils/object-value"));
|
|
106
51
|
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;
|
|
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');
|
|
119
62
|
}
|
|
120
|
-
|
|
63
|
+
setTarget(target) {
|
|
121
64
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
122
65
|
throw new Error('You cannot set a target while a process is running.');
|
|
123
66
|
}
|
|
124
67
|
this.target = target;
|
|
125
|
-
|
|
68
|
+
const cpsCtx = new cps_1.CPSContext(target, this.handler);
|
|
126
69
|
this.cps = new cps_1.default(cpsCtx);
|
|
127
70
|
this.apiContext = new context_1.default({
|
|
128
|
-
target
|
|
71
|
+
target,
|
|
129
72
|
isProtected: true,
|
|
130
73
|
debugger: this.debugger,
|
|
131
74
|
handler: this.handler,
|
|
@@ -136,8 +79,8 @@ var Interpreter = /** @class */ (function (_super) {
|
|
|
136
79
|
state: context_1.ContextState.Default
|
|
137
80
|
});
|
|
138
81
|
return this;
|
|
139
|
-
}
|
|
140
|
-
|
|
82
|
+
}
|
|
83
|
+
setDebugger(dbgr) {
|
|
141
84
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
142
85
|
throw new Error('You cannot set a target while a process is running.');
|
|
143
86
|
}
|
|
@@ -145,15 +88,15 @@ var Interpreter = /** @class */ (function (_super) {
|
|
|
145
88
|
this.apiContext.debugger = dbgr;
|
|
146
89
|
this.globalContext.debugger = dbgr;
|
|
147
90
|
return this;
|
|
148
|
-
}
|
|
149
|
-
|
|
91
|
+
}
|
|
92
|
+
setApi(newApi) {
|
|
150
93
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
151
94
|
throw new Error('You cannot set a target while a process is running.');
|
|
152
95
|
}
|
|
153
96
|
this.api = newApi;
|
|
154
97
|
return this;
|
|
155
|
-
}
|
|
156
|
-
|
|
98
|
+
}
|
|
99
|
+
setHandler(handler) {
|
|
157
100
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
158
101
|
throw new Error('You cannot set a target while a process is running.');
|
|
159
102
|
}
|
|
@@ -161,152 +104,115 @@ var Interpreter = /** @class */ (function (_super) {
|
|
|
161
104
|
this.apiContext.handler = handler;
|
|
162
105
|
this.globalContext.handler = handler;
|
|
163
106
|
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
107
|
+
}
|
|
108
|
+
prepare(code) {
|
|
166
109
|
try {
|
|
167
|
-
|
|
168
|
-
|
|
110
|
+
const parser = new greybel_core_1.Parser(code);
|
|
111
|
+
const chunk = parser.parseChunk();
|
|
169
112
|
return this.cps.visit(chunk);
|
|
170
113
|
}
|
|
171
114
|
catch (err) {
|
|
172
115
|
this.handler.errorHandler.raise(err);
|
|
173
116
|
}
|
|
174
117
|
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
|
-
});
|
|
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;
|
|
202
134
|
});
|
|
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
|
-
});
|
|
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.');
|
|
214
143
|
});
|
|
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
|
-
});
|
|
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);
|
|
236
150
|
});
|
|
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
|
-
});
|
|
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;
|
|
276
183
|
});
|
|
277
|
-
}
|
|
278
|
-
|
|
184
|
+
}
|
|
185
|
+
resume() {
|
|
279
186
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
280
187
|
this.debugger.setBreakpoint(false);
|
|
281
188
|
}
|
|
282
189
|
return this;
|
|
283
|
-
}
|
|
284
|
-
|
|
190
|
+
}
|
|
191
|
+
pause() {
|
|
285
192
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
286
193
|
this.debugger.setBreakpoint(true);
|
|
287
194
|
}
|
|
288
195
|
return this;
|
|
289
|
-
}
|
|
290
|
-
|
|
196
|
+
}
|
|
197
|
+
exit() {
|
|
291
198
|
try {
|
|
292
199
|
return this.apiContext.exit();
|
|
293
200
|
}
|
|
294
201
|
catch (err) {
|
|
295
202
|
this.handler.errorHandler.raise(err);
|
|
296
203
|
}
|
|
297
|
-
}
|
|
298
|
-
|
|
204
|
+
}
|
|
205
|
+
setGlobalVariable(path, value) {
|
|
299
206
|
if (this.globalContext != null) {
|
|
300
207
|
this.globalContext.set(new string_1.default(path), value);
|
|
301
208
|
}
|
|
302
209
|
return this;
|
|
303
|
-
}
|
|
304
|
-
|
|
210
|
+
}
|
|
211
|
+
getGlobalVariable(path) {
|
|
305
212
|
if (this.globalContext != null) {
|
|
306
213
|
this.globalContext.get(new string_1.default(path));
|
|
307
214
|
}
|
|
308
215
|
return default_1.default.Void;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
}(events_1.default));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
312
218
|
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 {
|