greybel-interpreter 0.7.2 → 1.0.2

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.
Files changed (137) hide show
  1. package/.editorconfig +15 -0
  2. package/.eslintrc +48 -0
  3. package/LICENSE +21 -21
  4. package/README.md +2 -2
  5. package/dist/context.d.ts +109 -98
  6. package/dist/context.js +378 -456
  7. package/dist/cps.d.ts +15 -17
  8. package/dist/cps.js +220 -872
  9. package/dist/handler/error.d.ts +6 -0
  10. package/dist/{operations/debugger.js → handler/error.js} +35 -32
  11. package/dist/handler/output.d.ts +6 -0
  12. package/dist/{operations/if.js → handler/output.js} +35 -31
  13. package/dist/handler/resource.d.ts +12 -0
  14. package/dist/handler/resource.js +51 -0
  15. package/dist/handler-container.d.ts +14 -0
  16. package/dist/handler-container.js +16 -0
  17. package/dist/index.d.ts +44 -36
  18. package/dist/index.js +129 -93
  19. package/dist/interpreter.d.ts +39 -29
  20. package/dist/interpreter.js +292 -210
  21. package/dist/intrinsics-container.d.ts +7 -0
  22. package/dist/intrinsics-container.js +19 -0
  23. package/dist/operations/assign.d.ts +13 -0
  24. package/dist/operations/assign.js +111 -0
  25. package/dist/operations/block.d.ts +12 -0
  26. package/dist/operations/{body.js → block.js} +108 -140
  27. package/dist/operations/break.d.ts +10 -7
  28. package/dist/operations/break.js +41 -34
  29. package/dist/operations/call.d.ts +13 -0
  30. package/dist/operations/call.js +124 -0
  31. package/dist/operations/chunk.d.ts +12 -0
  32. package/dist/operations/chunk.js +85 -0
  33. package/dist/operations/continue.d.ts +10 -7
  34. package/dist/operations/continue.js +41 -34
  35. package/dist/operations/debugger-statement.d.ts +10 -0
  36. package/dist/operations/{else-if.js → debugger-statement.js} +39 -31
  37. package/dist/operations/evaluate.d.ts +39 -0
  38. package/dist/operations/evaluate.js +366 -0
  39. package/dist/operations/for.d.ts +15 -16
  40. package/dist/operations/for.js +146 -143
  41. package/dist/operations/function-reference.d.ts +12 -0
  42. package/dist/operations/function-reference.js +103 -0
  43. package/dist/operations/function.d.ts +12 -26
  44. package/dist/operations/function.js +198 -145
  45. package/dist/operations/if-statement.d.ts +19 -8
  46. package/dist/operations/if-statement.js +181 -169
  47. package/dist/operations/import.d.ts +14 -0
  48. package/dist/{expressions/include.js → operations/import.js} +115 -132
  49. package/dist/operations/include.d.ts +13 -0
  50. package/dist/operations/include.js +95 -0
  51. package/dist/operations/list.d.ts +11 -0
  52. package/dist/{expressions → operations}/list.js +111 -142
  53. package/dist/operations/literal.d.ts +11 -0
  54. package/dist/operations/literal.js +58 -0
  55. package/dist/operations/map.d.ts +11 -0
  56. package/dist/operations/{argument.js → map.js} +167 -145
  57. package/dist/operations/negated-binary.d.ts +11 -0
  58. package/dist/{expressions/binary-negated-expression.js → operations/negated-binary.js} +109 -127
  59. package/dist/operations/new-instance.d.ts +11 -0
  60. package/dist/operations/{new.js → new-instance.js} +100 -97
  61. package/dist/operations/noop.d.ts +9 -0
  62. package/dist/operations/{else.js → noop.js} +36 -30
  63. package/dist/operations/not.d.ts +11 -11
  64. package/dist/operations/not.js +96 -96
  65. package/dist/operations/operation.d.ts +13 -0
  66. package/dist/operations/operation.js +11 -0
  67. package/dist/operations/reference.d.ts +9 -11
  68. package/dist/operations/reference.js +37 -103
  69. package/dist/operations/resolve.d.ts +38 -0
  70. package/dist/operations/resolve.js +330 -0
  71. package/dist/operations/return.d.ts +11 -11
  72. package/dist/operations/return.js +107 -106
  73. package/dist/operations/while.d.ts +13 -14
  74. package/dist/operations/while.js +129 -145
  75. package/dist/types/boolean.d.ts +11 -0
  76. package/dist/{custom-types → types}/boolean.js +46 -47
  77. package/dist/types/default.d.ts +11 -0
  78. package/dist/types/default.js +20 -0
  79. package/dist/types/function.d.ts +32 -0
  80. package/dist/types/function.js +174 -0
  81. package/dist/types/generics.d.ts +17 -0
  82. package/dist/types/{operation.js → generics.js} +40 -38
  83. package/dist/types/interface.d.ts +22 -0
  84. package/dist/types/interface.js +102 -0
  85. package/dist/types/list.d.ts +31 -0
  86. package/dist/types/list.js +227 -0
  87. package/dist/types/map.d.ts +30 -0
  88. package/dist/types/map.js +224 -0
  89. package/dist/types/nil.d.ts +9 -0
  90. package/dist/{custom-types → types}/nil.js +44 -44
  91. package/dist/types/number.d.ts +11 -0
  92. package/dist/{custom-types → types}/number.js +46 -47
  93. package/dist/types/string.d.ts +33 -0
  94. package/dist/types/string.js +149 -0
  95. package/dist/utils/path.d.ts +10 -0
  96. package/dist/utils/path.js +59 -0
  97. package/package.json +58 -44
  98. package/dist/custom-types/boolean.d.ts +0 -12
  99. package/dist/custom-types/list.d.ts +0 -26
  100. package/dist/custom-types/list.js +0 -236
  101. package/dist/custom-types/map.d.ts +0 -26
  102. package/dist/custom-types/map.js +0 -245
  103. package/dist/custom-types/nil.d.ts +0 -10
  104. package/dist/custom-types/number.d.ts +0 -12
  105. package/dist/custom-types/string.d.ts +0 -25
  106. package/dist/custom-types/string.js +0 -172
  107. package/dist/expressions/assign.d.ts +0 -13
  108. package/dist/expressions/assign.js +0 -174
  109. package/dist/expressions/binary-negated-expression.d.ts +0 -18
  110. package/dist/expressions/call.d.ts +0 -14
  111. package/dist/expressions/call.js +0 -209
  112. package/dist/expressions/import.d.ts +0 -14
  113. package/dist/expressions/import.js +0 -155
  114. package/dist/expressions/include.d.ts +0 -13
  115. package/dist/expressions/list.d.ts +0 -14
  116. package/dist/expressions/logical-and-binary.d.ts +0 -22
  117. package/dist/expressions/logical-and-binary.js +0 -222
  118. package/dist/expressions/map.d.ts +0 -19
  119. package/dist/expressions/map.js +0 -197
  120. package/dist/expressions/path.d.ts +0 -31
  121. package/dist/expressions/path.js +0 -384
  122. package/dist/operations/argument.d.ts +0 -8
  123. package/dist/operations/body.d.ts +0 -8
  124. package/dist/operations/debugger.d.ts +0 -7
  125. package/dist/operations/else-if.d.ts +0 -12
  126. package/dist/operations/else.d.ts +0 -10
  127. package/dist/operations/if.d.ts +0 -12
  128. package/dist/operations/new.d.ts +0 -11
  129. package/dist/resource.d.ts +0 -9
  130. package/dist/resource.js +0 -29
  131. package/dist/typer.d.ts +0 -6
  132. package/dist/typer.js +0 -95
  133. package/dist/types/custom-type.d.ts +0 -22
  134. package/dist/types/custom-type.js +0 -67
  135. package/dist/types/expression.d.ts +0 -7
  136. package/dist/types/expression.js +0 -9
  137. package/dist/types/operation.d.ts +0 -10
@@ -1,169 +1,181 @@
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 __values = (this && this.__values) || function(o) {
54
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
55
- if (m) return m.call(o);
56
- if (o && typeof o.length === "number") return {
57
- next: function () {
58
- if (o && i >= o.length) o = void 0;
59
- return { value: o && o[i++], done: !o };
60
- }
61
- };
62
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
63
- };
64
- var __importDefault = (this && this.__importDefault) || function (mod) {
65
- return (mod && mod.__esModule) ? mod : { "default": mod };
66
- };
67
- Object.defineProperty(exports, "__esModule", { value: true });
68
- var operation_1 = require("../types/operation");
69
- var expression_1 = require("../types/expression");
70
- var if_1 = __importDefault(require("./if"));
71
- var else_if_1 = __importDefault(require("./else-if"));
72
- var else_1 = __importDefault(require("./else"));
73
- var typer_1 = require("../typer");
74
- var IfStatementOperation = /** @class */ (function (_super) {
75
- __extends(IfStatementOperation, _super);
76
- function IfStatementOperation(ast) {
77
- var _this = _super.call(this) || this;
78
- var me = _this;
79
- me.ast = ast;
80
- me.clauses = [];
81
- return _this;
82
- }
83
- IfStatementOperation.prototype.run = function (operationContext) {
84
- return __awaiter(this, void 0, void 0, function () {
85
- var me, clauses, clauses_1, clauses_1_1, clause, condition, resolveCondition, e_1_1;
86
- var e_1, _a;
87
- return __generator(this, function (_b) {
88
- switch (_b.label) {
89
- case 0:
90
- me = this;
91
- clauses = me.clauses;
92
- _b.label = 1;
93
- case 1:
94
- _b.trys.push([1, 11, 12, 13]);
95
- clauses_1 = __values(clauses), clauses_1_1 = clauses_1.next();
96
- _b.label = 2;
97
- case 2:
98
- if (!!clauses_1_1.done) return [3 /*break*/, 10];
99
- clause = clauses_1_1.value;
100
- if (!(clause instanceof if_1.default || clause instanceof else_if_1.default)) return [3 /*break*/, 6];
101
- condition = clause.condition;
102
- resolveCondition = function (item) {
103
- return __awaiter(this, void 0, void 0, function () {
104
- var value, value;
105
- return __generator(this, function (_a) {
106
- switch (_a.label) {
107
- case 0:
108
- if (!(item instanceof expression_1.Expression)) return [3 /*break*/, 2];
109
- return [4 /*yield*/, item.get(operationContext)];
110
- case 1:
111
- value = _a.sent();
112
- return [2 /*return*/, value.toTruthy()];
113
- case 2:
114
- if (!(item instanceof operation_1.Operation)) return [3 /*break*/, 4];
115
- return [4 /*yield*/, item.get(operationContext)];
116
- case 3:
117
- value = _a.sent();
118
- return [2 /*return*/, value.toTruthy()];
119
- case 4:
120
- if ((0, typer_1.isCustomValue)(item)) {
121
- return [2 /*return*/, item.toTruthy()];
122
- }
123
- _a.label = 5;
124
- case 5:
125
- operationContext.debugger.raise("Unexpected object in condition ".concat(item === null || item === void 0 ? void 0 : item.toString(), "."), me, item);
126
- return [2 /*return*/];
127
- }
128
- });
129
- });
130
- };
131
- return [4 /*yield*/, resolveCondition(condition)];
132
- case 3:
133
- if (!_b.sent()) return [3 /*break*/, 5];
134
- return [4 /*yield*/, clause.body.run(operationContext)];
135
- case 4:
136
- _b.sent();
137
- return [3 /*break*/, 10];
138
- case 5: return [3 /*break*/, 9];
139
- case 6:
140
- if (!(clause instanceof else_1.default)) return [3 /*break*/, 8];
141
- return [4 /*yield*/, clause.body.run(operationContext)];
142
- case 7:
143
- _b.sent();
144
- return [3 /*break*/, 10];
145
- case 8:
146
- operationContext.debugger.raise("Unexpected operation in if statement ".concat(clause === null || clause === void 0 ? void 0 : clause.toString(), "."), me, clause);
147
- _b.label = 9;
148
- case 9:
149
- clauses_1_1 = clauses_1.next();
150
- return [3 /*break*/, 2];
151
- case 10: return [3 /*break*/, 13];
152
- case 11:
153
- e_1_1 = _b.sent();
154
- e_1 = { error: e_1_1 };
155
- return [3 /*break*/, 13];
156
- case 12:
157
- try {
158
- if (clauses_1_1 && !clauses_1_1.done && (_a = clauses_1.return)) _a.call(clauses_1);
159
- }
160
- finally { if (e_1) throw e_1.error; }
161
- return [7 /*endfinally*/];
162
- case 13: return [2 /*return*/];
163
- }
164
- });
165
- });
166
- };
167
- return IfStatementOperation;
168
- }(operation_1.Operation));
169
- exports.default = IfStatementOperation;
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.Clause = void 0;
58
+ var greyscript_core_1 = require("greyscript-core");
59
+ var boolean_1 = __importDefault(require("../types/boolean"));
60
+ var default_1 = __importDefault(require("../types/default"));
61
+ var block_1 = __importDefault(require("./block"));
62
+ var operation_1 = __importDefault(require("./operation"));
63
+ var reference_1 = __importDefault(require("./reference"));
64
+ var Clause = /** @class */ (function () {
65
+ function Clause(condition, block) {
66
+ this.condition = condition;
67
+ this.block = block;
68
+ }
69
+ return Clause;
70
+ }());
71
+ exports.Clause = Clause;
72
+ var IfStatement = /** @class */ (function (_super) {
73
+ __extends(IfStatement, _super);
74
+ function IfStatement(item, target) {
75
+ var _this = _super.call(this, null, target) || this;
76
+ _this.item = item;
77
+ return _this;
78
+ }
79
+ IfStatement.prototype.buildIfClause = function (node, visit) {
80
+ return __awaiter(this, void 0, void 0, function () {
81
+ var condition, stack, block;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0: return [4 /*yield*/, visit(node.condition)];
85
+ case 1:
86
+ condition = _a.sent();
87
+ return [4 /*yield*/, Promise.all(node.body.map(function (child) { return visit(child); }))];
88
+ case 2:
89
+ stack = _a.sent();
90
+ block = new block_1.default(stack);
91
+ this.clauses.push(new Clause(condition, block));
92
+ return [2 /*return*/];
93
+ }
94
+ });
95
+ });
96
+ };
97
+ IfStatement.prototype.buildElseClause = function (node, visit) {
98
+ return __awaiter(this, void 0, void 0, function () {
99
+ var condition, stack, block;
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0:
103
+ condition = new reference_1.default(new boolean_1.default(true));
104
+ return [4 /*yield*/, Promise.all(node.body.map(function (child) { return visit(child); }))];
105
+ case 1:
106
+ stack = _a.sent();
107
+ block = new block_1.default(stack);
108
+ this.clauses.push(new Clause(condition, block));
109
+ return [2 /*return*/];
110
+ }
111
+ });
112
+ });
113
+ };
114
+ IfStatement.prototype.build = function (visit) {
115
+ return __awaiter(this, void 0, void 0, function () {
116
+ var index, child, _a;
117
+ return __generator(this, function (_b) {
118
+ switch (_b.label) {
119
+ case 0:
120
+ this.clauses = [];
121
+ index = 0;
122
+ _b.label = 1;
123
+ case 1:
124
+ if (!(index < this.item.clauses.length)) return [3 /*break*/, 7];
125
+ child = this.item.clauses[index];
126
+ _a = child.type;
127
+ switch (_a) {
128
+ case greyscript_core_1.ASTType.IfClause: return [3 /*break*/, 2];
129
+ case greyscript_core_1.ASTType.IfShortcutClause: return [3 /*break*/, 2];
130
+ case greyscript_core_1.ASTType.ElseifClause: return [3 /*break*/, 2];
131
+ case greyscript_core_1.ASTType.ElseifShortcutClause: return [3 /*break*/, 2];
132
+ case greyscript_core_1.ASTType.ElseClause: return [3 /*break*/, 4];
133
+ case greyscript_core_1.ASTType.ElseShortcutClause: return [3 /*break*/, 4];
134
+ }
135
+ return [3 /*break*/, 6];
136
+ case 2: return [4 /*yield*/, this.buildIfClause(child, visit)];
137
+ case 3:
138
+ _b.sent();
139
+ return [3 /*break*/, 6];
140
+ case 4: return [4 /*yield*/, this.buildElseClause(child, visit)];
141
+ case 5:
142
+ _b.sent();
143
+ return [3 /*break*/, 6];
144
+ case 6:
145
+ index++;
146
+ return [3 /*break*/, 1];
147
+ case 7: return [2 /*return*/, this];
148
+ }
149
+ });
150
+ });
151
+ };
152
+ IfStatement.prototype.handle = function (ctx) {
153
+ return __awaiter(this, void 0, void 0, function () {
154
+ var index, clause, clauseResult;
155
+ return __generator(this, function (_a) {
156
+ switch (_a.label) {
157
+ case 0:
158
+ index = 0;
159
+ _a.label = 1;
160
+ case 1:
161
+ if (!(index < this.clauses.length)) return [3 /*break*/, 5];
162
+ clause = this.clauses[index];
163
+ return [4 /*yield*/, clause.condition.handle(ctx)];
164
+ case 2:
165
+ clauseResult = _a.sent();
166
+ if (!clauseResult.toTruthy()) return [3 /*break*/, 4];
167
+ return [4 /*yield*/, clause.block.handle(ctx)];
168
+ case 3:
169
+ _a.sent();
170
+ return [3 /*break*/, 5];
171
+ case 4:
172
+ index++;
173
+ return [3 /*break*/, 1];
174
+ case 5: return [2 /*return*/, default_1.default.Void];
175
+ }
176
+ });
177
+ });
178
+ };
179
+ return IfStatement;
180
+ }(operation_1.default));
181
+ exports.default = IfStatement;
@@ -0,0 +1,14 @@
1
+ import { ASTFeatureImportExpression } from 'greybel-core';
2
+ import { ASTBase } from 'greyscript-core';
3
+ import context from '../context';
4
+ import { CustomValue } from '../types/generics';
5
+ import Operation, { CPSVisit } from './operation';
6
+ export default class Include extends Operation {
7
+ readonly item: ASTFeatureImportExpression;
8
+ code: string;
9
+ chunk: ASTBase;
10
+ top: Operation;
11
+ constructor(item: ASTFeatureImportExpression, target: string, code: string);
12
+ build(visit: CPSVisit): Promise<Operation>;
13
+ handle(ctx: context): Promise<CustomValue>;
14
+ }
@@ -1,132 +1,115 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.ExpressionSegment = void 0;
55
- var greybel_core_1 = require("greybel-core");
56
- var expression_1 = require("../types/expression");
57
- var context_1 = require("../context");
58
- var ExpressionSegment = /** @class */ (function () {
59
- function ExpressionSegment(body) {
60
- var me = this;
61
- me.body = body;
62
- }
63
- return ExpressionSegment;
64
- }());
65
- exports.ExpressionSegment = ExpressionSegment;
66
- var IncludeExpression = /** @class */ (function (_super) {
67
- __extends(IncludeExpression, _super);
68
- function IncludeExpression(ast, target, code) {
69
- var _this = _super.call(this) || this;
70
- var me = _this;
71
- me.ast = ast;
72
- me.expr = null;
73
- me.target = target;
74
- me.code = code;
75
- return _this;
76
- }
77
- IncludeExpression.prototype.prepare = function (visit) {
78
- return __awaiter(this, void 0, void 0, function () {
79
- var me, node, parser, chunk, _a, _b;
80
- return __generator(this, function (_c) {
81
- switch (_c.label) {
82
- case 0:
83
- me = this;
84
- node = me.ast;
85
- parser = new greybel_core_1.Parser(me.code);
86
- chunk = parser.parseChunk();
87
- _a = me;
88
- _b = ExpressionSegment.bind;
89
- return [4 /*yield*/, visit(chunk)];
90
- case 1:
91
- _a.expr = new (_b.apply(ExpressionSegment, [void 0, _c.sent()]))();
92
- return [2 /*return*/, me];
93
- }
94
- });
95
- });
96
- };
97
- IncludeExpression.prototype.get = function (operationContext, parentExpr) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var me, evaluate;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
102
- case 0:
103
- me = this;
104
- evaluate = function (node) {
105
- return __awaiter(this, void 0, void 0, function () {
106
- var opc;
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
109
- case 0:
110
- opc = operationContext.fork({
111
- type: context_1.ContextType.EXTERNAL,
112
- state: context_1.ContextState.TEMPORARY,
113
- target: me.target
114
- });
115
- return [4 /*yield*/, node.body.run(opc)];
116
- case 1:
117
- _a.sent();
118
- return [2 /*return*/, true];
119
- }
120
- });
121
- });
122
- };
123
- operationContext.debugger.debug('Line', me.ast.start.line, 'IncludeExpression', 'get', 'expr', me.expr);
124
- return [4 /*yield*/, evaluate(me.expr)];
125
- case 1: return [2 /*return*/, _a.sent()];
126
- }
127
- });
128
- });
129
- };
130
- return IncludeExpression;
131
- }(expression_1.Expression));
132
- exports.default = IncludeExpression;
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
+ var greybel_core_1 = require("greybel-core");
58
+ var context_1 = require("../context");
59
+ var default_1 = __importDefault(require("../types/default"));
60
+ var map_1 = __importDefault(require("../types/map"));
61
+ var operation_1 = __importDefault(require("./operation"));
62
+ var Include = /** @class */ (function (_super) {
63
+ __extends(Include, _super);
64
+ function Include(item, target, code) {
65
+ var _this = _super.call(this, null, target) || this;
66
+ _this.item = item;
67
+ _this.code = code;
68
+ return _this;
69
+ }
70
+ Include.prototype.build = function (visit) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var parser, _a;
73
+ return __generator(this, function (_b) {
74
+ switch (_b.label) {
75
+ case 0:
76
+ parser = new greybel_core_1.Parser(this.code);
77
+ this.chunk = parser.parseChunk();
78
+ _a = this;
79
+ return [4 /*yield*/, visit(this.chunk)];
80
+ case 1:
81
+ _a.top = _b.sent();
82
+ return [2 /*return*/, this];
83
+ }
84
+ });
85
+ });
86
+ };
87
+ Include.prototype.handle = function (ctx) {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ var importCtx, moduleMap, item, identifier;
90
+ return __generator(this, function (_a) {
91
+ switch (_a.label) {
92
+ case 0:
93
+ importCtx = ctx.fork({
94
+ type: context_1.ContextType.External,
95
+ state: context_1.ContextState.Temporary,
96
+ target: this.target
97
+ });
98
+ moduleMap = new map_1.default();
99
+ importCtx.set('module', moduleMap);
100
+ return [4 /*yield*/, this.top.handle(importCtx)];
101
+ case 1:
102
+ _a.sent();
103
+ item = moduleMap.has('exports')
104
+ ? moduleMap.get('exports')
105
+ : default_1.default.Void;
106
+ identifier = this.item.name;
107
+ ctx.set(identifier.name, item);
108
+ return [2 /*return*/, default_1.default.Void];
109
+ }
110
+ });
111
+ });
112
+ };
113
+ return Include;
114
+ }(operation_1.default));
115
+ exports.default = Include;