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/operations/while.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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,114 +8,58 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
9
|
});
|
|
25
10
|
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
13
|
};
|
|
56
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_this.item = item;
|
|
66
|
-
return _this;
|
|
15
|
+
const context_1 = require("../context");
|
|
16
|
+
const default_1 = __importDefault(require("../types/default"));
|
|
17
|
+
const block_1 = __importDefault(require("./block"));
|
|
18
|
+
const operation_1 = __importDefault(require("./operation"));
|
|
19
|
+
class While extends operation_1.default {
|
|
20
|
+
constructor(item, target) {
|
|
21
|
+
super(null, target);
|
|
22
|
+
this.item = item;
|
|
67
23
|
}
|
|
68
|
-
|
|
69
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
case 1:
|
|
75
|
-
stack = _b.sent();
|
|
76
|
-
this.block = new block_1.default(stack);
|
|
77
|
-
_a = this;
|
|
78
|
-
return [4 /*yield*/, visit(this.item.condition)];
|
|
79
|
-
case 2:
|
|
80
|
-
_a.condition = _b.sent();
|
|
81
|
-
return [2 /*return*/, this];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
24
|
+
build(visit) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
|
|
27
|
+
this.block = new block_1.default(stack);
|
|
28
|
+
this.condition = yield visit(this.item.condition);
|
|
29
|
+
return this;
|
|
84
30
|
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
31
|
+
}
|
|
32
|
+
handle(ctx) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const whileCtx = ctx.fork({
|
|
35
|
+
type: context_1.ContextType.Loop,
|
|
36
|
+
state: context_1.ContextState.Temporary
|
|
37
|
+
});
|
|
38
|
+
const loopState = new context_1.LoopState();
|
|
39
|
+
whileCtx.loopState = loopState;
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const iteration = () => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
try {
|
|
43
|
+
const conditionResult = yield this.condition.handle(whileCtx);
|
|
44
|
+
if (!conditionResult.toTruthy()) {
|
|
45
|
+
resolve(default_1.default.Void);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
loopState.isContinue = false;
|
|
49
|
+
yield this.block.handle(whileCtx);
|
|
50
|
+
if (loopState.isBreak || ctx.isExit()) {
|
|
51
|
+
resolve(default_1.default.Void);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
process.nextTick(iteration);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
reject(err);
|
|
58
|
+
}
|
|
94
59
|
});
|
|
95
|
-
|
|
96
|
-
whileCtx.loopState = loopState;
|
|
97
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
98
|
-
var iteration = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
-
var conditionResult, err_1;
|
|
100
|
-
return __generator(this, function (_a) {
|
|
101
|
-
switch (_a.label) {
|
|
102
|
-
case 0:
|
|
103
|
-
_a.trys.push([0, 3, , 4]);
|
|
104
|
-
return [4 /*yield*/, this.condition.handle(whileCtx)];
|
|
105
|
-
case 1:
|
|
106
|
-
conditionResult = _a.sent();
|
|
107
|
-
if (!conditionResult.toTruthy()) {
|
|
108
|
-
resolve(default_1.default.Void);
|
|
109
|
-
return [2 /*return*/];
|
|
110
|
-
}
|
|
111
|
-
loopState.isContinue = false;
|
|
112
|
-
return [4 /*yield*/, this.block.handle(whileCtx)];
|
|
113
|
-
case 2:
|
|
114
|
-
_a.sent();
|
|
115
|
-
if (loopState.isBreak || ctx.isExit()) {
|
|
116
|
-
resolve(default_1.default.Void);
|
|
117
|
-
return [2 /*return*/];
|
|
118
|
-
}
|
|
119
|
-
process.nextTick(iteration);
|
|
120
|
-
return [3 /*break*/, 4];
|
|
121
|
-
case 3:
|
|
122
|
-
err_1 = _a.sent();
|
|
123
|
-
reject(err_1);
|
|
124
|
-
return [3 /*break*/, 4];
|
|
125
|
-
case 4: return [2 /*return*/];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}); };
|
|
129
|
-
iteration();
|
|
130
|
-
})];
|
|
60
|
+
iteration();
|
|
131
61
|
});
|
|
132
62
|
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
}(operation_1.default));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
136
65
|
exports.default = While;
|
package/dist/types/boolean.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CustomValue from './base';
|
|
2
2
|
export default class CustomBoolean extends CustomValue {
|
|
3
3
|
readonly value: boolean;
|
|
4
4
|
constructor(value: boolean);
|
|
@@ -9,3 +9,5 @@ export default class CustomBoolean extends CustomValue {
|
|
|
9
9
|
toInt(): number;
|
|
10
10
|
toTruthy(): boolean;
|
|
11
11
|
}
|
|
12
|
+
export declare const DefaultTrue: CustomBoolean;
|
|
13
|
+
export declare const DefaultFalse: CustomBoolean;
|
package/dist/types/boolean.js
CHANGED
|
@@ -1,46 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
17
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return _this;
|
|
6
|
+
exports.DefaultFalse = exports.DefaultTrue = void 0;
|
|
7
|
+
const base_1 = __importDefault(require("./base"));
|
|
8
|
+
class CustomBoolean extends base_1.default {
|
|
9
|
+
constructor(value) {
|
|
10
|
+
super();
|
|
11
|
+
this.value = value;
|
|
25
12
|
}
|
|
26
|
-
|
|
13
|
+
getCustomType() {
|
|
27
14
|
return 'boolean';
|
|
28
|
-
}
|
|
29
|
-
|
|
15
|
+
}
|
|
16
|
+
toString() {
|
|
30
17
|
return this.value.toString();
|
|
31
|
-
}
|
|
32
|
-
|
|
18
|
+
}
|
|
19
|
+
fork() {
|
|
33
20
|
return new CustomBoolean(this.value);
|
|
34
|
-
}
|
|
35
|
-
|
|
21
|
+
}
|
|
22
|
+
toNumber() {
|
|
36
23
|
return this.value ? 1.0 : 0.0;
|
|
37
|
-
}
|
|
38
|
-
|
|
24
|
+
}
|
|
25
|
+
toInt() {
|
|
39
26
|
return this.value ? 1 : 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
27
|
+
}
|
|
28
|
+
toTruthy() {
|
|
42
29
|
return this.value;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}(generics_1.CustomValue));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
46
32
|
exports.default = CustomBoolean;
|
|
33
|
+
exports.DefaultTrue = new CustomBoolean(true);
|
|
34
|
+
exports.DefaultFalse = new CustomBoolean(false);
|
package/dist/types/default.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import CustomBoolean from './boolean';
|
|
2
|
-
import CustomNil from './nil';
|
|
3
|
-
import CustomNumber from './number';
|
|
4
1
|
export default class Defaults {
|
|
5
|
-
static readonly Void:
|
|
6
|
-
static readonly True:
|
|
7
|
-
static readonly False:
|
|
8
|
-
static readonly NegativeOne:
|
|
9
|
-
static readonly PositiveOne:
|
|
10
|
-
static readonly Zero:
|
|
2
|
+
static readonly Void: import("./nil").default;
|
|
3
|
+
static readonly True: import("./boolean").default;
|
|
4
|
+
static readonly False: import("./boolean").default;
|
|
5
|
+
static readonly NegativeOne: import("./number").default;
|
|
6
|
+
static readonly PositiveOne: import("./number").default;
|
|
7
|
+
static readonly Zero: import("./number").default;
|
|
11
8
|
}
|
package/dist/types/default.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
Defaults.Void = new nil_1.default();
|
|
13
|
-
Defaults.True = new boolean_1.default(true);
|
|
14
|
-
Defaults.False = new boolean_1.default(false);
|
|
15
|
-
Defaults.NegativeOne = new number_1.default(-1);
|
|
16
|
-
Defaults.PositiveOne = new number_1.default(1);
|
|
17
|
-
Defaults.Zero = new number_1.default(0);
|
|
18
|
-
return Defaults;
|
|
19
|
-
}());
|
|
3
|
+
const boolean_1 = require("./boolean");
|
|
4
|
+
const nil_1 = require("./nil");
|
|
5
|
+
const number_1 = require("./number");
|
|
6
|
+
class Defaults {
|
|
7
|
+
}
|
|
20
8
|
exports.default = Defaults;
|
|
9
|
+
Defaults.Void = nil_1.Void;
|
|
10
|
+
Defaults.True = boolean_1.DefaultTrue;
|
|
11
|
+
Defaults.False = boolean_1.DefaultFalse;
|
|
12
|
+
Defaults.NegativeOne = number_1.NegativeOne;
|
|
13
|
+
Defaults.PositiveOne = number_1.PositiveOne;
|
|
14
|
+
Defaults.Zero = number_1.Zero;
|
package/dist/types/function.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import OperationContext from '../context';
|
|
2
2
|
import Operation from '../operations/operation';
|
|
3
|
-
import
|
|
3
|
+
import CustomValue from './base';
|
|
4
4
|
export interface Callback {
|
|
5
5
|
(ctx: OperationContext, self: CustomValue, args: Map<string, CustomValue>): Promise<NonNullable<CustomValue>>;
|
|
6
6
|
}
|
package/dist/types/function.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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,49 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
9
|
});
|
|
25
10
|
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
13
|
};
|
|
56
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
15
|
exports.Argument = void 0;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (defaultValue === void 0) { defaultValue = default_1.default.Void; }
|
|
16
|
+
const context_1 = require("../context");
|
|
17
|
+
const operation_1 = __importDefault(require("../operations/operation"));
|
|
18
|
+
const reference_1 = __importDefault(require("../operations/reference"));
|
|
19
|
+
const base_1 = __importDefault(require("./base"));
|
|
20
|
+
const default_1 = __importDefault(require("./default"));
|
|
21
|
+
const nil_1 = __importDefault(require("./nil"));
|
|
22
|
+
class Argument {
|
|
23
|
+
constructor(name, defaultValue = default_1.default.Void) {
|
|
67
24
|
this.name = name;
|
|
68
|
-
if (defaultValue instanceof
|
|
25
|
+
if (defaultValue instanceof base_1.default) {
|
|
69
26
|
this.defaultValue = new reference_1.default(defaultValue);
|
|
70
27
|
}
|
|
71
28
|
else if (defaultValue instanceof operation_1.default) {
|
|
@@ -75,100 +32,73 @@ var Argument = /** @class */ (function () {
|
|
|
75
32
|
throw new Error('Invalid defaultValue in argument.');
|
|
76
33
|
}
|
|
77
34
|
}
|
|
78
|
-
|
|
35
|
+
static createWithCustomValue(name, defaultValue) {
|
|
79
36
|
return new Argument(name, new reference_1.default(defaultValue));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
}());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
83
39
|
exports.Argument = Argument;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
_this.injectSelf = injectSelf;
|
|
93
|
-
_this.argumentDefs = [];
|
|
94
|
-
return _this;
|
|
40
|
+
class CustomFunction extends base_1.default {
|
|
41
|
+
constructor(scope, name, callback, injectSelf = false) {
|
|
42
|
+
super();
|
|
43
|
+
this.scope = scope;
|
|
44
|
+
this.name = name;
|
|
45
|
+
this.value = callback;
|
|
46
|
+
this.injectSelf = injectSelf;
|
|
47
|
+
this.argumentDefs = [];
|
|
95
48
|
}
|
|
96
|
-
|
|
49
|
+
static createExternalAnonymous(callback) {
|
|
97
50
|
return new CustomFunction(null, 'anonymous', callback);
|
|
98
|
-
}
|
|
99
|
-
|
|
51
|
+
}
|
|
52
|
+
static createExternal(name, callback) {
|
|
100
53
|
return new CustomFunction(null, name, callback);
|
|
101
|
-
}
|
|
102
|
-
|
|
54
|
+
}
|
|
55
|
+
static createExternalWithSelf(name, callback) {
|
|
103
56
|
return new CustomFunction(null, name, callback, true).addArgument('self');
|
|
104
|
-
}
|
|
105
|
-
|
|
57
|
+
}
|
|
58
|
+
setInjectSelf(injectSelf) {
|
|
106
59
|
this.injectSelf = injectSelf;
|
|
107
60
|
return this;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (defaultValue === void 0) { defaultValue = default_1.default.Void; }
|
|
61
|
+
}
|
|
62
|
+
addArgument(name, defaultValue = default_1.default.Void) {
|
|
111
63
|
this.argumentDefs.push(new Argument(name, defaultValue));
|
|
112
64
|
return this;
|
|
113
|
-
}
|
|
114
|
-
|
|
65
|
+
}
|
|
66
|
+
fork() {
|
|
115
67
|
return new CustomFunction(this.scope, this.name, this.value);
|
|
116
|
-
}
|
|
117
|
-
|
|
68
|
+
}
|
|
69
|
+
getCustomType() {
|
|
118
70
|
return 'function';
|
|
119
|
-
}
|
|
120
|
-
|
|
71
|
+
}
|
|
72
|
+
toNumber() {
|
|
121
73
|
return Number.NaN;
|
|
122
|
-
}
|
|
123
|
-
|
|
74
|
+
}
|
|
75
|
+
toInt() {
|
|
124
76
|
return 0;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
|
|
77
|
+
}
|
|
78
|
+
toString() {
|
|
79
|
+
const args = this.argumentDefs.map((item) => item.name);
|
|
80
|
+
return `function ${this.name}(${args.join(', ')})`;
|
|
81
|
+
}
|
|
82
|
+
toTruthy() {
|
|
131
83
|
return true;
|
|
132
|
-
}
|
|
133
|
-
|
|
84
|
+
}
|
|
85
|
+
run(self, args, callContext) {
|
|
134
86
|
var _a;
|
|
135
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
case 0:
|
|
140
|
-
fnCtx = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.fork({
|
|
141
|
-
type: context_1.ContextType.Function,
|
|
142
|
-
state: context_1.ContextState.Default
|
|
143
|
-
});
|
|
144
|
-
argMap = new Map();
|
|
145
|
-
if (this.injectSelf && !(self instanceof nil_1.default)) {
|
|
146
|
-
args.unshift(self);
|
|
147
|
-
}
|
|
148
|
-
index = 0;
|
|
149
|
-
_f.label = 1;
|
|
150
|
-
case 1:
|
|
151
|
-
if (!(index < this.argumentDefs.length)) return [3 /*break*/, 5];
|
|
152
|
-
item = this.argumentDefs[index];
|
|
153
|
-
_c = (_b = argMap).set;
|
|
154
|
-
_d = [item.name];
|
|
155
|
-
_e = args[index];
|
|
156
|
-
if (_e) return [3 /*break*/, 3];
|
|
157
|
-
return [4 /*yield*/, item.defaultValue.handle(fnCtx)];
|
|
158
|
-
case 2:
|
|
159
|
-
_e = (_f.sent());
|
|
160
|
-
_f.label = 3;
|
|
161
|
-
case 3:
|
|
162
|
-
_c.apply(_b, _d.concat([_e]));
|
|
163
|
-
_f.label = 4;
|
|
164
|
-
case 4:
|
|
165
|
-
index++;
|
|
166
|
-
return [3 /*break*/, 1];
|
|
167
|
-
case 5: return [2 /*return*/, this.value(fnCtx || callContext, self, argMap)];
|
|
168
|
-
}
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const fnCtx = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.fork({
|
|
89
|
+
type: context_1.ContextType.Function,
|
|
90
|
+
state: context_1.ContextState.Default
|
|
169
91
|
});
|
|
92
|
+
const argMap = new Map();
|
|
93
|
+
if (this.injectSelf && !(self instanceof nil_1.default)) {
|
|
94
|
+
args.unshift(self);
|
|
95
|
+
}
|
|
96
|
+
for (let index = 0; index < this.argumentDefs.length; index++) {
|
|
97
|
+
const item = this.argumentDefs[index];
|
|
98
|
+
argMap.set(item.name, args[index] || (yield item.defaultValue.handle(fnCtx)));
|
|
99
|
+
}
|
|
100
|
+
return this.value(fnCtx || callContext, self, argMap);
|
|
170
101
|
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
}(generics_1.CustomValue));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
174
104
|
exports.default = CustomFunction;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Path from '../utils/path';
|
|
2
|
+
import CustomValue from './base';
|
|
2
3
|
import CustomFunction from './function';
|
|
3
|
-
import { CustomObject
|
|
4
|
+
import { CustomObject } from './with-intrinsics';
|
|
4
5
|
export declare class CustomInterfaceIterator implements Iterator<CustomValue> {
|
|
5
6
|
next(): IteratorResult<CustomValue>;
|
|
6
7
|
}
|