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.
Files changed (93) hide show
  1. package/dist/context.d.ts +3 -2
  2. package/dist/context.js +113 -190
  3. package/dist/cps.js +135 -188
  4. package/dist/handler/error.js +6 -29
  5. package/dist/handler/output.js +15 -38
  6. package/dist/handler/resource.js +16 -39
  7. package/dist/handler-container.js +6 -8
  8. package/dist/index.d.ts +4 -3
  9. package/dist/index.js +10 -9
  10. package/dist/interpreter.d.ts +5 -4
  11. package/dist/interpreter.js +109 -203
  12. package/dist/operations/assign.d.ts +1 -1
  13. package/dist/operations/assign.js +28 -93
  14. package/dist/operations/block.d.ts +1 -1
  15. package/dist/operations/block.js +33 -89
  16. package/dist/operations/break.d.ts +1 -1
  17. package/dist/operations/break.js +11 -29
  18. package/dist/operations/call.d.ts +1 -1
  19. package/dist/operations/call.js +31 -106
  20. package/dist/operations/chunk.d.ts +1 -1
  21. package/dist/operations/chunk.js +15 -67
  22. package/dist/operations/continue.d.ts +1 -1
  23. package/dist/operations/continue.js +11 -29
  24. package/dist/operations/debugger-statement.d.ts +1 -1
  25. package/dist/operations/debugger-statement.js +11 -29
  26. package/dist/operations/evaluate.d.ts +1 -1
  27. package/dist/operations/evaluate.js +143 -247
  28. package/dist/operations/for.d.ts +1 -1
  29. package/dist/operations/for.js +62 -133
  30. package/dist/operations/function-reference.d.ts +1 -1
  31. package/dist/operations/function-reference.js +25 -84
  32. package/dist/operations/function.d.ts +1 -1
  33. package/dist/operations/function.js +49 -177
  34. package/dist/operations/if-statement.d.ts +1 -1
  35. package/dist/operations/if-statement.js +58 -154
  36. package/dist/operations/import.d.ts +1 -1
  37. package/dist/operations/import.js +35 -97
  38. package/dist/operations/include.d.ts +1 -1
  39. package/dist/operations/include.js +19 -73
  40. package/dist/operations/list.d.ts +1 -1
  41. package/dist/operations/list.js +24 -93
  42. package/dist/operations/literal.d.ts +1 -1
  43. package/dist/operations/literal.js +15 -33
  44. package/dist/operations/map.d.ts +1 -1
  45. package/dist/operations/map.js +26 -153
  46. package/dist/operations/negated-binary.d.ts +1 -1
  47. package/dist/operations/negated-binary.js +24 -91
  48. package/dist/operations/new-instance.d.ts +1 -1
  49. package/dist/operations/new-instance.js +21 -82
  50. package/dist/operations/noop.d.ts +1 -1
  51. package/dist/operations/noop.js +10 -27
  52. package/dist/operations/not.d.ts +1 -1
  53. package/dist/operations/not.js +17 -78
  54. package/dist/operations/operation.d.ts +2 -2
  55. package/dist/operations/operation.js +3 -5
  56. package/dist/operations/reference.d.ts +1 -1
  57. package/dist/operations/reference.js +10 -28
  58. package/dist/operations/resolve.d.ts +1 -1
  59. package/dist/operations/resolve.js +161 -281
  60. package/dist/operations/return.d.ts +1 -1
  61. package/dist/operations/return.js +27 -89
  62. package/dist/operations/while.d.ts +1 -1
  63. package/dist/operations/while.js +45 -116
  64. package/dist/types/base.d.ts +9 -0
  65. package/dist/types/base.js +5 -0
  66. package/dist/types/boolean.d.ts +3 -1
  67. package/dist/types/boolean.js +24 -36
  68. package/dist/types/default.d.ts +6 -9
  69. package/dist/types/default.js +11 -17
  70. package/dist/types/function.d.ts +1 -1
  71. package/dist/types/function.js +60 -130
  72. package/dist/types/interface.d.ts +2 -1
  73. package/dist/types/interface.js +44 -64
  74. package/dist/types/list.d.ts +4 -6
  75. package/dist/types/list.js +77 -128
  76. package/dist/types/map.d.ts +11 -15
  77. package/dist/types/map.js +101 -267
  78. package/dist/types/nil.d.ts +2 -1
  79. package/dist/types/nil.js +23 -36
  80. package/dist/types/number.d.ts +16 -2
  81. package/dist/types/number.js +60 -37
  82. package/dist/types/string.d.ts +4 -6
  83. package/dist/types/string.js +66 -90
  84. package/dist/types/{generics.d.ts → with-intrinsics.d.ts} +6 -9
  85. package/dist/types/with-intrinsics.js +19 -0
  86. package/dist/utils/deep-equal.js +9 -34
  87. package/dist/utils/object-value.d.ts +7 -0
  88. package/dist/utils/object-value.js +42 -0
  89. package/dist/utils/path.js +16 -43
  90. package/package.json +3 -3
  91. package/dist/intrinsics-container.d.ts +0 -7
  92. package/dist/intrinsics-container.js +0 -19
  93. package/dist/types/generics.js +0 -40
@@ -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,89 +8,35 @@ 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
- var list_1 = __importDefault(require("../types/list"));
58
- var operation_1 = __importDefault(require("./operation"));
59
- var List = /** @class */ (function (_super) {
60
- __extends(List, _super);
61
- function List(item, target) {
62
- var _this = _super.call(this, null, target) || this;
63
- _this.item = item;
64
- return _this;
15
+ const list_1 = __importDefault(require("../types/list"));
16
+ const operation_1 = __importDefault(require("./operation"));
17
+ class List extends operation_1.default {
18
+ constructor(item, target) {
19
+ super(null, target);
20
+ this.item = item;
65
21
  }
66
- List.prototype.build = function (visit) {
67
- return __awaiter(this, void 0, void 0, function () {
68
- var _a;
69
- return __generator(this, function (_b) {
70
- switch (_b.label) {
71
- case 0:
72
- _a = this;
73
- return [4 /*yield*/, Promise.all(this.item.fields.map(function (child) {
74
- var listValue = child;
75
- return visit(listValue.value);
76
- }))];
77
- case 1:
78
- _a.fields = _b.sent();
79
- return [2 /*return*/, this];
80
- }
81
- });
22
+ build(visit) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ this.fields = yield Promise.all(this.item.fields.map((child) => {
25
+ const listValue = child;
26
+ return visit(listValue.value);
27
+ }));
28
+ return this;
82
29
  });
83
- };
84
- List.prototype.handle = function (ctx) {
85
- return __awaiter(this, void 0, void 0, function () {
86
- var fields, index, child, _a, _b;
87
- return __generator(this, function (_c) {
88
- switch (_c.label) {
89
- case 0:
90
- fields = [];
91
- index = 0;
92
- _c.label = 1;
93
- case 1:
94
- if (!(index < this.fields.length)) return [3 /*break*/, 4];
95
- child = this.fields[index];
96
- _b = (_a = fields).push;
97
- return [4 /*yield*/, child.handle(ctx)];
98
- case 2:
99
- _b.apply(_a, [_c.sent()]);
100
- _c.label = 3;
101
- case 3:
102
- index++;
103
- return [3 /*break*/, 1];
104
- case 4: return [2 /*return*/, new list_1.default(fields)];
105
- }
106
- });
30
+ }
31
+ handle(ctx) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const fields = [];
34
+ for (let index = 0; index < this.fields.length; index++) {
35
+ const child = this.fields[index];
36
+ fields.push(yield child.handle(ctx));
37
+ }
38
+ return new list_1.default(fields);
107
39
  });
108
- };
109
- return List;
110
- }(operation_1.default));
40
+ }
41
+ }
111
42
  exports.default = List;
@@ -1,6 +1,6 @@
1
1
  import { ASTLiteral } from 'greyscript-core';
2
2
  import context from '../context';
3
- import { CustomValue } from '../types/generics';
3
+ import CustomValue from '../types/base';
4
4
  import Operation, { CPSVisit } from './operation';
5
5
  export default class Literal extends Operation {
6
6
  readonly item: ASTLiteral;
@@ -1,37 +1,20 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
18
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
4
  };
20
5
  Object.defineProperty(exports, "__esModule", { value: true });
21
- var greyscript_core_1 = require("greyscript-core");
22
- var boolean_1 = __importDefault(require("../types/boolean"));
23
- var default_1 = __importDefault(require("../types/default"));
24
- var number_1 = __importDefault(require("../types/number"));
25
- var string_1 = __importDefault(require("../types/string"));
26
- var operation_1 = __importDefault(require("./operation"));
27
- var Literal = /** @class */ (function (_super) {
28
- __extends(Literal, _super);
29
- function Literal(item, target) {
30
- var _this = _super.call(this, null, target) || this;
31
- _this.item = item;
32
- return _this;
6
+ const greyscript_core_1 = require("greyscript-core");
7
+ const boolean_1 = __importDefault(require("../types/boolean"));
8
+ const default_1 = __importDefault(require("../types/default"));
9
+ const number_1 = __importDefault(require("../types/number"));
10
+ const string_1 = __importDefault(require("../types/string"));
11
+ const operation_1 = __importDefault(require("./operation"));
12
+ class Literal extends operation_1.default {
13
+ constructor(item, target) {
14
+ super(null, target);
15
+ this.item = item;
33
16
  }
34
- Literal.prototype.build = function (_visit) {
17
+ build(_visit) {
35
18
  switch (this.item.type) {
36
19
  case greyscript_core_1.ASTType.BooleanLiteral:
37
20
  this.value = new boolean_1.default(this.item.value);
@@ -49,10 +32,9 @@ var Literal = /** @class */ (function (_super) {
49
32
  throw new Error('Unexpected literal type.');
50
33
  }
51
34
  return Promise.resolve(this);
52
- };
53
- Literal.prototype.handle = function (_ctx) {
35
+ }
36
+ handle(_ctx) {
54
37
  return Promise.resolve(this.value);
55
- };
56
- return Literal;
57
- }(operation_1.default));
38
+ }
39
+ }
58
40
  exports.default = Literal;
@@ -1,6 +1,6 @@
1
1
  import { ASTMapConstructorExpression } from 'greyscript-core';
2
2
  import context from '../context';
3
- import { CustomValue } from '../types/generics';
3
+ import CustomValue from '../types/base';
4
4
  import Operation, { CPSVisit } from './operation';
5
5
  export default class MapOperation extends Operation {
6
6
  readonly item: ASTMapConstructorExpression;
@@ -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,149 +8,37 @@ 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
- 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 __read = (this && this.__read) || function (o, n) {
65
- var m = typeof Symbol === "function" && o[Symbol.iterator];
66
- if (!m) return o;
67
- var i = m.call(o), r, ar = [], e;
68
- try {
69
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
70
- }
71
- catch (error) { e = { error: error }; }
72
- finally {
73
- try {
74
- if (r && !r.done && (m = i["return"])) m.call(i);
75
- }
76
- finally { if (e) throw e.error; }
77
- }
78
- return ar;
79
- };
80
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
81
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
82
13
  };
83
14
  Object.defineProperty(exports, "__esModule", { value: true });
84
- var map_1 = __importDefault(require("../types/map"));
85
- var operation_1 = __importDefault(require("./operation"));
86
- var MapOperation = /** @class */ (function (_super) {
87
- __extends(MapOperation, _super);
88
- function MapOperation(item, target) {
89
- var _this = _super.call(this, null, target) || this;
90
- _this.item = item;
91
- return _this;
15
+ const map_1 = __importDefault(require("../types/map"));
16
+ const object_value_1 = __importDefault(require("../utils/object-value"));
17
+ const operation_1 = __importDefault(require("./operation"));
18
+ class MapOperation extends operation_1.default {
19
+ constructor(item, target) {
20
+ super(null, target);
21
+ this.item = item;
92
22
  }
93
- MapOperation.prototype.build = function (visit) {
94
- return __awaiter(this, void 0, void 0, function () {
95
- var defers;
96
- var _this = this;
97
- return __generator(this, function (_a) {
98
- switch (_a.label) {
99
- case 0:
100
- this.fields = new Map();
101
- defers = this.item.fields.map(function (child) { return __awaiter(_this, void 0, void 0, function () {
102
- var mapKeyString, _a, _b, _c;
103
- return __generator(this, function (_d) {
104
- switch (_d.label) {
105
- case 0:
106
- mapKeyString = child;
107
- _b = (_a = this.fields).set;
108
- return [4 /*yield*/, visit(mapKeyString.key)];
109
- case 1:
110
- _c = [_d.sent()];
111
- return [4 /*yield*/, visit(mapKeyString.value)];
112
- case 2:
113
- _b.apply(_a, _c.concat([_d.sent()]));
114
- return [2 /*return*/];
115
- }
116
- });
117
- }); });
118
- return [4 /*yield*/, Promise.all(defers)];
119
- case 1:
120
- _a.sent();
121
- return [2 /*return*/, this];
122
- }
123
- });
23
+ build(visit) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ this.fields = new Map();
26
+ const defers = this.item.fields.map((child) => __awaiter(this, void 0, void 0, function* () {
27
+ const mapKeyString = child;
28
+ this.fields.set(yield visit(mapKeyString.key), yield visit(mapKeyString.value));
29
+ }));
30
+ yield Promise.all(defers);
31
+ return this;
124
32
  });
125
- };
126
- MapOperation.prototype.handle = function (ctx) {
127
- return __awaiter(this, void 0, void 0, function () {
128
- var newMap, _a, _b, _c, key, value, _d, _e, _f, e_1_1;
129
- var e_1, _g;
130
- return __generator(this, function (_h) {
131
- switch (_h.label) {
132
- case 0:
133
- newMap = new Map();
134
- _h.label = 1;
135
- case 1:
136
- _h.trys.push([1, 7, 8, 9]);
137
- _a = __values(this.fields), _b = _a.next();
138
- _h.label = 2;
139
- case 2:
140
- if (!!_b.done) return [3 /*break*/, 6];
141
- _c = __read(_b.value, 2), key = _c[0], value = _c[1];
142
- _e = (_d = newMap).set;
143
- return [4 /*yield*/, key.handle(ctx)];
144
- case 3:
145
- _f = [_h.sent()];
146
- return [4 /*yield*/, value.handle(ctx)];
147
- case 4:
148
- _e.apply(_d, _f.concat([_h.sent()]));
149
- _h.label = 5;
150
- case 5:
151
- _b = _a.next();
152
- return [3 /*break*/, 2];
153
- case 6: return [3 /*break*/, 9];
154
- case 7:
155
- e_1_1 = _h.sent();
156
- e_1 = { error: e_1_1 };
157
- return [3 /*break*/, 9];
158
- case 8:
159
- try {
160
- if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
161
- }
162
- finally { if (e_1) throw e_1.error; }
163
- return [7 /*endfinally*/];
164
- case 9: return [2 /*return*/, new map_1.default(newMap)];
165
- }
166
- });
33
+ }
34
+ handle(ctx) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const newMap = new object_value_1.default();
37
+ for (const [key, value] of this.fields) {
38
+ newMap.set(yield key.handle(ctx), yield value.handle(ctx));
39
+ }
40
+ return new map_1.default(newMap);
167
41
  });
168
- };
169
- return MapOperation;
170
- }(operation_1.default));
42
+ }
43
+ }
171
44
  exports.default = MapOperation;
@@ -1,6 +1,6 @@
1
1
  import { ASTUnaryExpression } from 'greyscript-core';
2
2
  import context from '../context';
3
- import { CustomValue } from '../types/generics';
3
+ import CustomValue from '../types/base';
4
4
  import Operation, { CPSVisit } from './operation';
5
5
  export default class NegatedBinary extends Operation {
6
6
  readonly item: ASTUnaryExpression;
@@ -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,87 +8,35 @@ 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
- var greyscript_core_1 = require("greyscript-core");
58
- var number_1 = __importDefault(require("../types/number"));
59
- var operation_1 = __importDefault(require("./operation"));
60
- var NegatedBinary = /** @class */ (function (_super) {
61
- __extends(NegatedBinary, _super);
62
- function NegatedBinary(item, target) {
63
- var _this = _super.call(this, null, target) || this;
64
- _this.item = item;
65
- return _this;
15
+ const greyscript_core_1 = require("greyscript-core");
16
+ const number_1 = __importDefault(require("../types/number"));
17
+ const operation_1 = __importDefault(require("./operation"));
18
+ class NegatedBinary extends operation_1.default {
19
+ constructor(item, target) {
20
+ super(null, target);
21
+ this.item = item;
66
22
  }
67
- NegatedBinary.prototype.build = function (visit) {
68
- return __awaiter(this, void 0, void 0, function () {
69
- var _a;
70
- return __generator(this, function (_b) {
71
- switch (_b.label) {
72
- case 0:
73
- _a = this;
74
- return [4 /*yield*/, visit(this.item.argument)];
75
- case 1:
76
- _a.arg = _b.sent();
77
- return [2 /*return*/, this];
78
- }
79
- });
23
+ build(visit) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ this.arg = yield visit(this.item.argument);
26
+ return this;
80
27
  });
81
- };
82
- NegatedBinary.prototype.handle = function (ctx) {
83
- return __awaiter(this, void 0, void 0, function () {
84
- var _a, _b, _c;
85
- return __generator(this, function (_d) {
86
- switch (_d.label) {
87
- case 0:
88
- _a = this.item.operator;
89
- switch (_a) {
90
- case greyscript_core_1.Operator.Minus: return [3 /*break*/, 1];
91
- case greyscript_core_1.Operator.Plus: return [3 /*break*/, 3];
92
- }
93
- return [3 /*break*/, 5];
94
- case 1:
95
- _b = number_1.default.bind;
96
- return [4 /*yield*/, this.arg.handle(ctx)];
97
- case 2: return [2 /*return*/, new (_b.apply(number_1.default, [void 0, -(_d.sent()).toNumber()]))()];
98
- case 3:
99
- _c = number_1.default.bind;
100
- return [4 /*yield*/, this.arg.handle(ctx)];
101
- case 4: return [2 /*return*/, new (_c.apply(number_1.default, [void 0, +(_d.sent()).toNumber()]))()];
102
- case 5: throw new Error('Unexpected negation operator.');
103
- }
104
- });
28
+ }
29
+ handle(ctx) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ switch (this.item.operator) {
32
+ case greyscript_core_1.Operator.Minus:
33
+ return new number_1.default(-(yield this.arg.handle(ctx)).toNumber());
34
+ case greyscript_core_1.Operator.Plus:
35
+ return new number_1.default(+(yield this.arg.handle(ctx)).toNumber());
36
+ default:
37
+ throw new Error('Unexpected negation operator.');
38
+ }
105
39
  });
106
- };
107
- return NegatedBinary;
108
- }(operation_1.default));
40
+ }
41
+ }
109
42
  exports.default = NegatedBinary;
@@ -1,6 +1,6 @@
1
1
  import { ASTUnaryExpression } from 'greyscript-core';
2
2
  import context from '../context';
3
- import { CustomValue } from '../types/generics';
3
+ import CustomValue from '../types/base';
4
4
  import Operation, { CPSVisit } from './operation';
5
5
  export default class NewInstance extends Operation {
6
6
  readonly item: ASTUnaryExpression;