greybel-interpreter 0.7.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +15 -0
- package/.eslintrc +48 -0
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +107 -98
- package/dist/context.js +358 -456
- package/dist/cps.d.ts +15 -17
- package/dist/cps.js +220 -872
- package/dist/handler/error.d.ts +6 -0
- package/dist/{operations/debugger.js → handler/error.js} +35 -32
- package/dist/handler/output.d.ts +6 -0
- package/dist/{operations/if.js → handler/output.js} +35 -31
- package/dist/handler/resource.d.ts +12 -0
- package/dist/handler/resource.js +51 -0
- package/dist/handler-container.d.ts +14 -0
- package/dist/handler-container.js +16 -0
- package/dist/index.d.ts +44 -36
- package/dist/index.js +129 -93
- package/dist/interpreter.d.ts +39 -29
- package/dist/interpreter.js +292 -210
- package/dist/intrinsics-container.d.ts +7 -0
- package/dist/intrinsics-container.js +19 -0
- package/dist/operations/assign.d.ts +13 -0
- package/dist/operations/assign.js +111 -0
- package/dist/operations/block.d.ts +12 -0
- package/dist/operations/{body.js → block.js} +108 -140
- package/dist/operations/break.d.ts +10 -7
- package/dist/operations/break.js +41 -34
- package/dist/operations/call.d.ts +13 -0
- package/dist/operations/call.js +124 -0
- package/dist/operations/chunk.d.ts +12 -0
- package/dist/operations/chunk.js +85 -0
- package/dist/operations/continue.d.ts +10 -7
- package/dist/operations/continue.js +41 -34
- package/dist/operations/debugger-statement.d.ts +10 -0
- package/dist/operations/{else-if.js → debugger-statement.js} +39 -31
- package/dist/operations/evaluate.d.ts +39 -0
- package/dist/operations/evaluate.js +366 -0
- package/dist/operations/for.d.ts +15 -16
- package/dist/operations/for.js +146 -143
- package/dist/operations/function-reference.d.ts +12 -0
- package/dist/operations/function-reference.js +103 -0
- package/dist/operations/function.d.ts +12 -26
- package/dist/operations/function.js +198 -145
- package/dist/operations/if-statement.d.ts +19 -8
- package/dist/operations/if-statement.js +181 -169
- package/dist/operations/import.d.ts +14 -0
- package/dist/{expressions/include.js → operations/import.js} +115 -132
- package/dist/operations/include.d.ts +13 -0
- package/dist/operations/include.js +95 -0
- package/dist/operations/list.d.ts +11 -0
- package/dist/{expressions → operations}/list.js +111 -142
- package/dist/operations/literal.d.ts +11 -0
- package/dist/operations/literal.js +58 -0
- package/dist/operations/map.d.ts +11 -0
- package/dist/operations/{argument.js → map.js} +167 -145
- package/dist/operations/negated-binary.d.ts +11 -0
- package/dist/{expressions/binary-negated-expression.js → operations/negated-binary.js} +109 -127
- package/dist/operations/new-instance.d.ts +11 -0
- package/dist/operations/{new.js → new-instance.js} +100 -97
- package/dist/operations/noop.d.ts +9 -0
- package/dist/operations/{else.js → noop.js} +36 -30
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +96 -96
- package/dist/operations/operation.d.ts +13 -0
- package/dist/operations/operation.js +11 -0
- package/dist/operations/reference.d.ts +9 -11
- package/dist/operations/reference.js +37 -103
- package/dist/operations/resolve.d.ts +38 -0
- package/dist/operations/resolve.js +330 -0
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +101 -106
- package/dist/operations/while.d.ts +13 -14
- package/dist/operations/while.js +129 -145
- package/dist/types/boolean.d.ts +11 -0
- package/dist/{custom-types → types}/boolean.js +46 -47
- package/dist/types/default.d.ts +11 -0
- package/dist/types/default.js +20 -0
- package/dist/types/function.d.ts +32 -0
- package/dist/types/function.js +174 -0
- package/dist/types/generics.d.ts +17 -0
- package/dist/types/{operation.js → generics.js} +40 -38
- package/dist/types/interface.d.ts +22 -0
- package/dist/types/interface.js +102 -0
- package/dist/types/list.d.ts +31 -0
- package/dist/types/list.js +227 -0
- package/dist/types/map.d.ts +30 -0
- package/dist/types/map.js +224 -0
- package/dist/types/nil.d.ts +9 -0
- package/dist/{custom-types → types}/nil.js +44 -44
- package/dist/types/number.d.ts +11 -0
- package/dist/{custom-types → types}/number.js +46 -47
- package/dist/types/string.d.ts +33 -0
- package/dist/types/string.js +149 -0
- package/dist/utils/path.d.ts +10 -0
- package/dist/utils/path.js +59 -0
- package/package.json +58 -44
- package/dist/custom-types/boolean.d.ts +0 -12
- package/dist/custom-types/list.d.ts +0 -26
- package/dist/custom-types/list.js +0 -236
- package/dist/custom-types/map.d.ts +0 -26
- package/dist/custom-types/map.js +0 -245
- package/dist/custom-types/nil.d.ts +0 -10
- package/dist/custom-types/number.d.ts +0 -12
- package/dist/custom-types/string.d.ts +0 -25
- package/dist/custom-types/string.js +0 -172
- package/dist/expressions/assign.d.ts +0 -13
- package/dist/expressions/assign.js +0 -174
- package/dist/expressions/binary-negated-expression.d.ts +0 -18
- package/dist/expressions/call.d.ts +0 -14
- package/dist/expressions/call.js +0 -209
- package/dist/expressions/import.d.ts +0 -14
- package/dist/expressions/import.js +0 -155
- package/dist/expressions/include.d.ts +0 -13
- package/dist/expressions/list.d.ts +0 -14
- package/dist/expressions/logical-and-binary.d.ts +0 -22
- package/dist/expressions/logical-and-binary.js +0 -222
- package/dist/expressions/map.d.ts +0 -19
- package/dist/expressions/map.js +0 -197
- package/dist/expressions/path.d.ts +0 -31
- package/dist/expressions/path.js +0 -384
- package/dist/operations/argument.d.ts +0 -8
- package/dist/operations/body.d.ts +0 -8
- package/dist/operations/debugger.d.ts +0 -7
- package/dist/operations/else-if.d.ts +0 -12
- package/dist/operations/else.d.ts +0 -10
- package/dist/operations/if.d.ts +0 -12
- package/dist/operations/new.d.ts +0 -11
- package/dist/resource.d.ts +0 -9
- package/dist/resource.js +0 -29
- package/dist/typer.d.ts +0 -6
- package/dist/typer.js +0 -95
- package/dist/types/custom-type.d.ts +0 -22
- package/dist/types/custom-type.js +0 -67
- package/dist/types/expression.d.ts +0 -7
- package/dist/types/expression.js +0 -9
- package/dist/types/operation.d.ts +0 -10
|
@@ -1,103 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
var operation_1 = require("../types/operation");
|
|
55
|
-
var expression_1 = require("../types/expression");
|
|
56
|
-
var custom_type_1 = require("../types/custom-type");
|
|
57
|
-
var typer_1 = require("../typer");
|
|
58
|
-
var ReferenceOperation = /** @class */ (function (_super) {
|
|
59
|
-
__extends(ReferenceOperation, _super);
|
|
60
|
-
function ReferenceOperation(ast, options) {
|
|
61
|
-
var _this = _super.call(this) || this;
|
|
62
|
-
var me = _this;
|
|
63
|
-
me.ast = ast;
|
|
64
|
-
me.arg = options.arg;
|
|
65
|
-
return _this;
|
|
66
|
-
}
|
|
67
|
-
ReferenceOperation.prototype.get = function (operationContext) {
|
|
68
|
-
var _a, _b;
|
|
69
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
var me, arg;
|
|
71
|
-
return __generator(this, function (_c) {
|
|
72
|
-
switch (_c.label) {
|
|
73
|
-
case 0:
|
|
74
|
-
me = this;
|
|
75
|
-
if (!(0, typer_1.isCustomValue)(me.arg)) return [3 /*break*/, 1];
|
|
76
|
-
return [2 /*return*/, me.arg];
|
|
77
|
-
case 1:
|
|
78
|
-
if (!(me.arg instanceof expression_1.Expression)) return [3 /*break*/, 3];
|
|
79
|
-
return [4 /*yield*/, me.arg.get(operationContext, me)];
|
|
80
|
-
case 2:
|
|
81
|
-
arg = _c.sent();
|
|
82
|
-
return [3 /*break*/, 4];
|
|
83
|
-
case 3:
|
|
84
|
-
operationContext.debugger.raise("Unexpected reference ".concat((_a = me.arg) === null || _a === void 0 ? void 0 : _a.toString(), "."), me, me.arg);
|
|
85
|
-
_c.label = 4;
|
|
86
|
-
case 4:
|
|
87
|
-
if ((0, typer_1.isCustomValue)(arg)) {
|
|
88
|
-
return [2 /*return*/, arg];
|
|
89
|
-
}
|
|
90
|
-
else if (arg.handle) {
|
|
91
|
-
if (arg.handle instanceof custom_type_1.CustomObjectType) {
|
|
92
|
-
return [2 /*return*/, arg.handle.get(arg.path)];
|
|
93
|
-
}
|
|
94
|
-
operationContext.debugger.raise("Unexpected object as reference ".concat((_b = arg.handle) === null || _b === void 0 ? void 0 : _b.toString(), "."), me, arg.handle);
|
|
95
|
-
}
|
|
96
|
-
return [2 /*return*/, operationContext.get(arg.path)];
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
return ReferenceOperation;
|
|
102
|
-
}(operation_1.Operation));
|
|
103
|
-
exports.default = ReferenceOperation;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var operation_1 = __importDefault(require("./operation"));
|
|
22
|
+
var Reference = /** @class */ (function (_super) {
|
|
23
|
+
__extends(Reference, _super);
|
|
24
|
+
function Reference(value) {
|
|
25
|
+
var _this = _super.call(this, null, 'native') || this;
|
|
26
|
+
_this.value = value;
|
|
27
|
+
return _this;
|
|
28
|
+
}
|
|
29
|
+
Reference.prototype.build = function (_visit) {
|
|
30
|
+
return Promise.resolve(this);
|
|
31
|
+
};
|
|
32
|
+
Reference.prototype.handle = function (_ctx) {
|
|
33
|
+
return Promise.resolve(this.value);
|
|
34
|
+
};
|
|
35
|
+
return Reference;
|
|
36
|
+
}(operation_1.default));
|
|
37
|
+
exports.default = Reference;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ASTBase } from 'greyscript-core';
|
|
2
|
+
import OperationContext from '../context';
|
|
3
|
+
import { CustomValue } from '../types/generics';
|
|
4
|
+
import Path from '../utils/path';
|
|
5
|
+
import Operation, { CPSVisit } from './operation';
|
|
6
|
+
export declare class SliceSegment {
|
|
7
|
+
readonly left: Operation;
|
|
8
|
+
readonly right: Operation;
|
|
9
|
+
constructor(left: Operation, right: Operation);
|
|
10
|
+
}
|
|
11
|
+
export declare class IdentifierSegment {
|
|
12
|
+
readonly value: string;
|
|
13
|
+
constructor(value: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class IndexSegment {
|
|
16
|
+
readonly op: Operation;
|
|
17
|
+
constructor(op: Operation);
|
|
18
|
+
}
|
|
19
|
+
export declare class OperationSegment {
|
|
20
|
+
readonly op: Operation;
|
|
21
|
+
constructor(op: Operation);
|
|
22
|
+
}
|
|
23
|
+
export declare type Segment = SliceSegment | IdentifierSegment | IndexSegment | OperationSegment;
|
|
24
|
+
export declare class ResolveResult {
|
|
25
|
+
readonly path: Path<string>;
|
|
26
|
+
readonly handle: CustomValue;
|
|
27
|
+
constructor(path: Path<string>, handle: CustomValue);
|
|
28
|
+
}
|
|
29
|
+
export default class Resolve extends Operation {
|
|
30
|
+
readonly item: ASTBase;
|
|
31
|
+
path: Array<Segment>;
|
|
32
|
+
last: Segment;
|
|
33
|
+
constructor(item: ASTBase, target?: string);
|
|
34
|
+
buildProcessor(node: ASTBase, visit: CPSVisit): Promise<void>;
|
|
35
|
+
build(visit: CPSVisit): Promise<Resolve>;
|
|
36
|
+
getResult(ctx: OperationContext): Promise<ResolveResult>;
|
|
37
|
+
handle(ctx: OperationContext, result?: ResolveResult, autoCall?: boolean): Promise<CustomValue>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.ResolveResult = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.SliceSegment = void 0;
|
|
58
|
+
var greyscript_core_1 = require("greyscript-core");
|
|
59
|
+
var default_1 = __importDefault(require("../types/default"));
|
|
60
|
+
var function_1 = __importDefault(require("../types/function"));
|
|
61
|
+
var generics_1 = require("../types/generics");
|
|
62
|
+
var list_1 = __importDefault(require("../types/list"));
|
|
63
|
+
var string_1 = __importDefault(require("../types/string"));
|
|
64
|
+
var path_1 = __importDefault(require("../utils/path"));
|
|
65
|
+
var operation_1 = __importDefault(require("./operation"));
|
|
66
|
+
var SliceSegment = /** @class */ (function () {
|
|
67
|
+
function SliceSegment(left, right) {
|
|
68
|
+
this.left = left;
|
|
69
|
+
this.right = right;
|
|
70
|
+
}
|
|
71
|
+
return SliceSegment;
|
|
72
|
+
}());
|
|
73
|
+
exports.SliceSegment = SliceSegment;
|
|
74
|
+
var IdentifierSegment = /** @class */ (function () {
|
|
75
|
+
function IdentifierSegment(value) {
|
|
76
|
+
this.value = value;
|
|
77
|
+
}
|
|
78
|
+
return IdentifierSegment;
|
|
79
|
+
}());
|
|
80
|
+
exports.IdentifierSegment = IdentifierSegment;
|
|
81
|
+
var IndexSegment = /** @class */ (function () {
|
|
82
|
+
function IndexSegment(op) {
|
|
83
|
+
this.op = op;
|
|
84
|
+
}
|
|
85
|
+
return IndexSegment;
|
|
86
|
+
}());
|
|
87
|
+
exports.IndexSegment = IndexSegment;
|
|
88
|
+
var OperationSegment = /** @class */ (function () {
|
|
89
|
+
function OperationSegment(op) {
|
|
90
|
+
this.op = op;
|
|
91
|
+
}
|
|
92
|
+
return OperationSegment;
|
|
93
|
+
}());
|
|
94
|
+
exports.OperationSegment = OperationSegment;
|
|
95
|
+
var ResolveResult = /** @class */ (function () {
|
|
96
|
+
function ResolveResult(path, handle) {
|
|
97
|
+
this.path = path;
|
|
98
|
+
this.handle = handle;
|
|
99
|
+
}
|
|
100
|
+
return ResolveResult;
|
|
101
|
+
}());
|
|
102
|
+
exports.ResolveResult = ResolveResult;
|
|
103
|
+
var Resolve = /** @class */ (function (_super) {
|
|
104
|
+
__extends(Resolve, _super);
|
|
105
|
+
function Resolve(item, target) {
|
|
106
|
+
var _this = _super.call(this, null, target) || this;
|
|
107
|
+
_this.item = item;
|
|
108
|
+
return _this;
|
|
109
|
+
}
|
|
110
|
+
Resolve.prototype.buildProcessor = function (node, visit) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var _a, memberExpr, indexExpr, sliceExpr, left, right, sliceSegment, indexSegment, _b, identifier, identifierSegment, opSegment, _c;
|
|
113
|
+
return __generator(this, function (_d) {
|
|
114
|
+
switch (_d.label) {
|
|
115
|
+
case 0:
|
|
116
|
+
_a = node.type;
|
|
117
|
+
switch (_a) {
|
|
118
|
+
case greyscript_core_1.ASTType.MemberExpression: return [3 /*break*/, 1];
|
|
119
|
+
case greyscript_core_1.ASTType.IndexExpression: return [3 /*break*/, 4];
|
|
120
|
+
case greyscript_core_1.ASTType.Identifier: return [3 /*break*/, 11];
|
|
121
|
+
}
|
|
122
|
+
return [3 /*break*/, 12];
|
|
123
|
+
case 1:
|
|
124
|
+
memberExpr = node;
|
|
125
|
+
return [4 /*yield*/, this.buildProcessor(memberExpr.base, visit)];
|
|
126
|
+
case 2:
|
|
127
|
+
_d.sent();
|
|
128
|
+
return [4 /*yield*/, this.buildProcessor(memberExpr.identifier, visit)];
|
|
129
|
+
case 3:
|
|
130
|
+
_d.sent();
|
|
131
|
+
return [3 /*break*/, 14];
|
|
132
|
+
case 4:
|
|
133
|
+
indexExpr = node;
|
|
134
|
+
return [4 /*yield*/, this.buildProcessor(indexExpr.base, visit)];
|
|
135
|
+
case 5:
|
|
136
|
+
_d.sent();
|
|
137
|
+
if (!(indexExpr.index.type === greyscript_core_1.ASTType.SliceExpression)) return [3 /*break*/, 8];
|
|
138
|
+
sliceExpr = indexExpr.index;
|
|
139
|
+
return [4 /*yield*/, visit(sliceExpr.left)];
|
|
140
|
+
case 6:
|
|
141
|
+
left = _d.sent();
|
|
142
|
+
return [4 /*yield*/, visit(sliceExpr.right)];
|
|
143
|
+
case 7:
|
|
144
|
+
right = _d.sent();
|
|
145
|
+
sliceSegment = new SliceSegment(left, right);
|
|
146
|
+
this.path.push(sliceSegment);
|
|
147
|
+
return [3 /*break*/, 10];
|
|
148
|
+
case 8:
|
|
149
|
+
_b = IndexSegment.bind;
|
|
150
|
+
return [4 /*yield*/, visit(indexExpr.index)];
|
|
151
|
+
case 9:
|
|
152
|
+
indexSegment = new (_b.apply(IndexSegment, [void 0, _d.sent()]))();
|
|
153
|
+
this.path.push(indexSegment);
|
|
154
|
+
_d.label = 10;
|
|
155
|
+
case 10: return [3 /*break*/, 14];
|
|
156
|
+
case 11:
|
|
157
|
+
{
|
|
158
|
+
identifier = node;
|
|
159
|
+
identifierSegment = new IdentifierSegment(identifier.name);
|
|
160
|
+
this.path.push(identifierSegment);
|
|
161
|
+
return [3 /*break*/, 14];
|
|
162
|
+
}
|
|
163
|
+
_d.label = 12;
|
|
164
|
+
case 12:
|
|
165
|
+
_c = OperationSegment.bind;
|
|
166
|
+
return [4 /*yield*/, visit(node)];
|
|
167
|
+
case 13:
|
|
168
|
+
opSegment = new (_c.apply(OperationSegment, [void 0, _d.sent()]))();
|
|
169
|
+
this.path.push(opSegment);
|
|
170
|
+
return [3 /*break*/, 14];
|
|
171
|
+
case 14: return [2 /*return*/];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
Resolve.prototype.build = function (visit) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
+
return __generator(this, function (_a) {
|
|
179
|
+
switch (_a.label) {
|
|
180
|
+
case 0:
|
|
181
|
+
this.path = [];
|
|
182
|
+
return [4 /*yield*/, this.buildProcessor(this.item, visit)];
|
|
183
|
+
case 1:
|
|
184
|
+
_a.sent();
|
|
185
|
+
this.last = this.path[this.path.length - 1];
|
|
186
|
+
return [2 /*return*/, this];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
Resolve.prototype.getResult = function (ctx) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
+
var traversedPath, handle, maxIndex, lastIndex, index, current, opSegment, identifierSegment, previous, customValueCtx, indexSegment, indexValue, customValueCtx, sliceSegment, left, right;
|
|
194
|
+
return __generator(this, function (_a) {
|
|
195
|
+
switch (_a.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
traversedPath = new path_1.default();
|
|
198
|
+
handle = default_1.default.Void;
|
|
199
|
+
maxIndex = this.path.length;
|
|
200
|
+
lastIndex = maxIndex - 1;
|
|
201
|
+
index = 0;
|
|
202
|
+
_a.label = 1;
|
|
203
|
+
case 1:
|
|
204
|
+
if (!(index < maxIndex)) return [3 /*break*/, 12];
|
|
205
|
+
current = this.path[index];
|
|
206
|
+
if (!(current instanceof OperationSegment)) return [3 /*break*/, 3];
|
|
207
|
+
opSegment = current;
|
|
208
|
+
return [4 /*yield*/, opSegment.op.handle(ctx)];
|
|
209
|
+
case 2:
|
|
210
|
+
handle = _a.sent();
|
|
211
|
+
return [3 /*break*/, 11];
|
|
212
|
+
case 3:
|
|
213
|
+
if (!(current instanceof IdentifierSegment)) return [3 /*break*/, 6];
|
|
214
|
+
identifierSegment = current;
|
|
215
|
+
traversedPath.add(identifierSegment.value);
|
|
216
|
+
if (index === lastIndex) {
|
|
217
|
+
return [3 /*break*/, 12];
|
|
218
|
+
}
|
|
219
|
+
previous = handle;
|
|
220
|
+
if (handle !== default_1.default.Void) {
|
|
221
|
+
if (handle instanceof generics_1.CustomValueWithIntrinsics) {
|
|
222
|
+
customValueCtx = handle;
|
|
223
|
+
handle = customValueCtx.get(traversedPath);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
throw new Error('Handle has no properties.');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
handle = ctx.get(traversedPath);
|
|
231
|
+
}
|
|
232
|
+
if (!(handle instanceof function_1.default)) return [3 /*break*/, 5];
|
|
233
|
+
return [4 /*yield*/, handle.run(previous || default_1.default.Void, [])];
|
|
234
|
+
case 4:
|
|
235
|
+
handle = _a.sent();
|
|
236
|
+
_a.label = 5;
|
|
237
|
+
case 5:
|
|
238
|
+
traversedPath = new path_1.default();
|
|
239
|
+
return [3 /*break*/, 11];
|
|
240
|
+
case 6:
|
|
241
|
+
if (!(current instanceof IndexSegment)) return [3 /*break*/, 8];
|
|
242
|
+
indexSegment = current;
|
|
243
|
+
return [4 /*yield*/, indexSegment.op.handle(ctx)];
|
|
244
|
+
case 7:
|
|
245
|
+
indexValue = _a.sent();
|
|
246
|
+
traversedPath.add(indexValue.toString());
|
|
247
|
+
if (index === lastIndex) {
|
|
248
|
+
return [3 /*break*/, 12];
|
|
249
|
+
}
|
|
250
|
+
if (handle !== default_1.default.Void) {
|
|
251
|
+
if (handle instanceof generics_1.CustomValueWithIntrinsics) {
|
|
252
|
+
customValueCtx = handle;
|
|
253
|
+
handle = customValueCtx.get(traversedPath);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
throw new Error('Handle has no properties.');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
handle = ctx.get(traversedPath);
|
|
261
|
+
}
|
|
262
|
+
traversedPath = new path_1.default();
|
|
263
|
+
return [3 /*break*/, 11];
|
|
264
|
+
case 8:
|
|
265
|
+
if (!(current instanceof SliceSegment)) return [3 /*break*/, 11];
|
|
266
|
+
sliceSegment = current;
|
|
267
|
+
return [4 /*yield*/, sliceSegment.left.handle(ctx)];
|
|
268
|
+
case 9:
|
|
269
|
+
left = _a.sent();
|
|
270
|
+
return [4 /*yield*/, sliceSegment.right.handle(ctx)];
|
|
271
|
+
case 10:
|
|
272
|
+
right = _a.sent();
|
|
273
|
+
if (handle instanceof list_1.default || handle instanceof string_1.default) {
|
|
274
|
+
handle = handle.slice(left, right);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
throw new Error("Unexpected slice attempt. ".concat(handle.getCustomType(), " does not seem to support slicing."));
|
|
278
|
+
}
|
|
279
|
+
_a.label = 11;
|
|
280
|
+
case 11:
|
|
281
|
+
index++;
|
|
282
|
+
return [3 /*break*/, 1];
|
|
283
|
+
case 12: return [2 /*return*/, new ResolveResult(traversedPath, handle)];
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
Resolve.prototype.handle = function (ctx, result, autoCall) {
|
|
289
|
+
if (result === void 0) { result = null; }
|
|
290
|
+
if (autoCall === void 0) { autoCall = true; }
|
|
291
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
292
|
+
var customValueCtx, child, handle;
|
|
293
|
+
return __generator(this, function (_a) {
|
|
294
|
+
switch (_a.label) {
|
|
295
|
+
case 0:
|
|
296
|
+
if (!(result === null)) return [3 /*break*/, 2];
|
|
297
|
+
return [4 /*yield*/, this.getResult(ctx)];
|
|
298
|
+
case 1:
|
|
299
|
+
result = _a.sent();
|
|
300
|
+
_a.label = 2;
|
|
301
|
+
case 2:
|
|
302
|
+
if (result.handle !== default_1.default.Void) {
|
|
303
|
+
if (result.path.count() === 0) {
|
|
304
|
+
if (autoCall && result.handle instanceof function_1.default) {
|
|
305
|
+
return [2 /*return*/, result.handle.run(default_1.default.Void, [])];
|
|
306
|
+
}
|
|
307
|
+
return [2 /*return*/, result.handle];
|
|
308
|
+
}
|
|
309
|
+
customValueCtx = result.handle;
|
|
310
|
+
child = customValueCtx.get(result.path);
|
|
311
|
+
if (autoCall &&
|
|
312
|
+
child instanceof function_1.default &&
|
|
313
|
+
// support index bug in greyscript
|
|
314
|
+
!(this.last instanceof IndexSegment)) {
|
|
315
|
+
return [2 /*return*/, child.run(customValueCtx, [])];
|
|
316
|
+
}
|
|
317
|
+
return [2 /*return*/, child];
|
|
318
|
+
}
|
|
319
|
+
handle = ctx.get(result.path);
|
|
320
|
+
if (autoCall && handle instanceof function_1.default) {
|
|
321
|
+
return [2 /*return*/, handle.run(default_1.default.Void, [])];
|
|
322
|
+
}
|
|
323
|
+
return [2 /*return*/, handle];
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
return Resolve;
|
|
329
|
+
}(operation_1.default));
|
|
330
|
+
exports.default = Resolve;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
1
|
+
import { ASTReturnStatement } from 'greyscript-core';
|
|
2
|
+
import context from '../context';
|
|
3
|
+
import { CustomValue } from '../types/generics';
|
|
4
|
+
import Operation, { CPSVisit } from './operation';
|
|
5
|
+
export default class Return extends Operation {
|
|
6
|
+
readonly item: ASTReturnStatement;
|
|
7
|
+
arg: Operation;
|
|
8
|
+
constructor(item: ASTReturnStatement, target?: string);
|
|
9
|
+
build(visit: CPSVisit): Promise<Operation>;
|
|
10
|
+
handle(ctx: context): Promise<CustomValue>;
|
|
11
|
+
}
|