greybel-interpreter 0.1.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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/context.d.ts +68 -0
  4. package/dist/context.js +399 -0
  5. package/dist/cps.d.ts +15 -0
  6. package/dist/cps.js +438 -0
  7. package/dist/custom-types/boolean.d.ts +10 -0
  8. package/dist/custom-types/boolean.js +41 -0
  9. package/dist/custom-types/list.d.ts +25 -0
  10. package/dist/custom-types/list.js +281 -0
  11. package/dist/custom-types/map.d.ts +28 -0
  12. package/dist/custom-types/map.js +289 -0
  13. package/dist/custom-types/nil.d.ts +8 -0
  14. package/dist/custom-types/nil.js +38 -0
  15. package/dist/custom-types/number.d.ts +10 -0
  16. package/dist/custom-types/number.js +41 -0
  17. package/dist/custom-types/string.d.ts +21 -0
  18. package/dist/custom-types/string.js +132 -0
  19. package/dist/expressions/assign.d.ts +12 -0
  20. package/dist/expressions/assign.js +156 -0
  21. package/dist/expressions/binary-negated-expression.d.ts +18 -0
  22. package/dist/expressions/binary-negated-expression.js +115 -0
  23. package/dist/expressions/call.d.ts +13 -0
  24. package/dist/expressions/call.js +177 -0
  25. package/dist/expressions/list.d.ts +13 -0
  26. package/dist/expressions/list.js +119 -0
  27. package/dist/expressions/logical-and-binary.d.ts +22 -0
  28. package/dist/expressions/logical-and-binary.js +188 -0
  29. package/dist/expressions/map.d.ts +18 -0
  30. package/dist/expressions/map.js +171 -0
  31. package/dist/expressions/path.d.ts +30 -0
  32. package/dist/expressions/path.js +310 -0
  33. package/dist/index.d.ts +35 -0
  34. package/dist/index.js +82 -0
  35. package/dist/interpreter.d.ts +20 -0
  36. package/dist/interpreter.js +55 -0
  37. package/dist/operations/argument.d.ts +8 -0
  38. package/dist/operations/argument.js +129 -0
  39. package/dist/operations/body.d.ts +8 -0
  40. package/dist/operations/body.js +144 -0
  41. package/dist/operations/break.d.ts +7 -0
  42. package/dist/operations/break.js +34 -0
  43. package/dist/operations/continue.d.ts +7 -0
  44. package/dist/operations/continue.js +34 -0
  45. package/dist/operations/debugger.d.ts +7 -0
  46. package/dist/operations/debugger.js +32 -0
  47. package/dist/operations/else-if.d.ts +12 -0
  48. package/dist/operations/else-if.js +31 -0
  49. package/dist/operations/else.d.ts +10 -0
  50. package/dist/operations/else.js +30 -0
  51. package/dist/operations/for.d.ts +16 -0
  52. package/dist/operations/for.js +139 -0
  53. package/dist/operations/function.d.ts +21 -0
  54. package/dist/operations/function.js +125 -0
  55. package/dist/operations/if-statement.d.ts +8 -0
  56. package/dist/operations/if-statement.js +138 -0
  57. package/dist/operations/if.d.ts +12 -0
  58. package/dist/operations/if.js +31 -0
  59. package/dist/operations/new.d.ts +11 -0
  60. package/dist/operations/new.js +96 -0
  61. package/dist/operations/not.d.ts +11 -0
  62. package/dist/operations/not.js +95 -0
  63. package/dist/operations/reference.d.ts +11 -0
  64. package/dist/operations/reference.js +102 -0
  65. package/dist/operations/return.d.ts +11 -0
  66. package/dist/operations/return.js +102 -0
  67. package/dist/operations/top.d.ts +12 -0
  68. package/dist/operations/top.js +84 -0
  69. package/dist/operations/while.d.ts +14 -0
  70. package/dist/operations/while.js +123 -0
  71. package/dist/resource.d.ts +9 -0
  72. package/dist/resource.js +29 -0
  73. package/dist/typer.d.ts +6 -0
  74. package/dist/typer.js +99 -0
  75. package/dist/types/custom-type.d.ts +19 -0
  76. package/dist/types/custom-type.js +58 -0
  77. package/dist/types/expression.d.ts +6 -0
  78. package/dist/types/expression.js +9 -0
  79. package/dist/types/operation.d.ts +9 -0
  80. package/dist/types/operation.js +38 -0
  81. package/package.json +45 -0
@@ -0,0 +1,281 @@
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 __read = (this && this.__read) || function (o, n) {
54
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
55
+ if (!m) return o;
56
+ var i = m.call(o), r, ar = [], e;
57
+ try {
58
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
+ }
60
+ catch (error) { e = { error: error }; }
61
+ finally {
62
+ try {
63
+ if (r && !r.done && (m = i["return"])) m.call(i);
64
+ }
65
+ finally { if (e) throw e.error; }
66
+ }
67
+ return ar;
68
+ };
69
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
70
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
71
+ if (ar || !(i in from)) {
72
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
73
+ ar[i] = from[i];
74
+ }
75
+ }
76
+ return to.concat(ar || Array.prototype.slice.call(from));
77
+ };
78
+ var __importDefault = (this && this.__importDefault) || function (mod) {
79
+ return (mod && mod.__esModule) ? mod : { "default": mod };
80
+ };
81
+ Object.defineProperty(exports, "__esModule", { value: true });
82
+ exports.CustomListIterator = void 0;
83
+ var function_1 = __importDefault(require("../operations/function"));
84
+ var custom_type_1 = require("../types/custom-type");
85
+ var CustomListIterator = /** @class */ (function () {
86
+ function CustomListIterator(value) {
87
+ var me = this;
88
+ me.value = value;
89
+ me.index = 0;
90
+ }
91
+ CustomListIterator.prototype.next = function () {
92
+ var me = this;
93
+ if (me.index === me.value.length) {
94
+ return {
95
+ value: null,
96
+ done: true
97
+ };
98
+ }
99
+ return {
100
+ value: me.value[me.index++],
101
+ done: false
102
+ };
103
+ };
104
+ return CustomListIterator;
105
+ }());
106
+ exports.CustomListIterator = CustomListIterator;
107
+ var CustomList = /** @class */ (function (_super) {
108
+ __extends(CustomList, _super);
109
+ function CustomList(value) {
110
+ var _this = _super.call(this) || this;
111
+ _this.slice = function (a, b) {
112
+ return new CustomList(this.value.slice(a.valueOf(), b.valueOf()));
113
+ };
114
+ _this.value = value;
115
+ return _this;
116
+ }
117
+ CustomList.isNumber = function (value) {
118
+ return !Number.isNaN(Number(value));
119
+ };
120
+ CustomList.prototype[Symbol.iterator] = function () {
121
+ return new CustomListIterator(this.value);
122
+ };
123
+ CustomList.prototype.concat = function (list) {
124
+ return new CustomList(this.value.concat(list.value));
125
+ };
126
+ CustomList.prototype.toIndex = function (value) {
127
+ var me = this;
128
+ var casted = Number(value);
129
+ return casted < 0 ? me.value.length + casted : casted;
130
+ };
131
+ CustomList.prototype.set = function (path, value) {
132
+ return __awaiter(this, void 0, void 0, function () {
133
+ var me, traversalPath, refs, last, current, origin;
134
+ return __generator(this, function (_a) {
135
+ me = this;
136
+ traversalPath = [].concat(path);
137
+ refs = me.value;
138
+ last = traversalPath.pop();
139
+ current = traversalPath.shift();
140
+ origin = refs;
141
+ if (current != null) {
142
+ if (current in origin) {
143
+ origin = origin[current];
144
+ if (origin instanceof custom_type_1.CustomObjectType) {
145
+ return [2 /*return*/, origin.set(traversalPath.concat([last]), value)];
146
+ }
147
+ }
148
+ else {
149
+ throw new Error("Cannot set path ".concat(path.join('.')));
150
+ }
151
+ }
152
+ if (origin) {
153
+ if (value instanceof function_1.default) {
154
+ origin[last] = value.fork(me);
155
+ }
156
+ else {
157
+ origin[last] = value;
158
+ }
159
+ }
160
+ else {
161
+ throw new Error("Cannot set path ".concat(path.join('.')));
162
+ }
163
+ return [2 /*return*/];
164
+ });
165
+ });
166
+ };
167
+ CustomList.prototype.get = function (path) {
168
+ return __awaiter(this, void 0, void 0, function () {
169
+ var me, traversalPath, refs, current, currentValue, origin;
170
+ return __generator(this, function (_a) {
171
+ me = this;
172
+ if (path.length === 0) {
173
+ return [2 /*return*/, me];
174
+ }
175
+ traversalPath = [].concat(path);
176
+ refs = me.value;
177
+ current = traversalPath.shift();
178
+ currentValue = current.valueOf();
179
+ origin = refs;
180
+ if (currentValue != null) {
181
+ if (currentValue in origin) {
182
+ origin = origin[currentValue];
183
+ if (traversalPath.length > 0 && origin instanceof custom_type_1.CustomObjectType) {
184
+ return [2 /*return*/, origin.get(traversalPath)];
185
+ }
186
+ }
187
+ else if (path.length === 1 && CustomList.intrinsics.has(currentValue)) {
188
+ return [2 /*return*/, CustomList.intrinsics.get(currentValue)];
189
+ }
190
+ else {
191
+ throw new Error("Cannot get path ".concat(path.join('.')));
192
+ }
193
+ }
194
+ else {
195
+ return [2 /*return*/, null];
196
+ }
197
+ return [2 /*return*/, origin];
198
+ });
199
+ });
200
+ };
201
+ CustomList.prototype.getCallable = function (path) {
202
+ return __awaiter(this, void 0, void 0, function () {
203
+ var me, traversalPath, refs, current, origin, context;
204
+ return __generator(this, function (_a) {
205
+ me = this;
206
+ traversalPath = [].concat(path);
207
+ refs = me.value;
208
+ current = traversalPath.shift();
209
+ origin = refs;
210
+ if (current != null) {
211
+ if (current in origin) {
212
+ context = origin;
213
+ origin = origin[current];
214
+ if (origin instanceof custom_type_1.CustomObjectType) {
215
+ return [2 /*return*/, origin.getCallable(traversalPath)];
216
+ }
217
+ }
218
+ else if (path.length === 1 && CustomList.intrinsics.has(current)) {
219
+ return [2 /*return*/, {
220
+ origin: CustomList.intrinsics.get(current),
221
+ context: me
222
+ }];
223
+ }
224
+ else {
225
+ throw new Error("Cannot get path ".concat(path.join('.')));
226
+ }
227
+ }
228
+ return [2 /*return*/, {
229
+ origin: origin,
230
+ context: context
231
+ }];
232
+ });
233
+ });
234
+ };
235
+ CustomList.prototype.callMethod = function (method) {
236
+ var _a, _b;
237
+ var args = [];
238
+ for (var _i = 1; _i < arguments.length; _i++) {
239
+ args[_i - 1] = arguments[_i];
240
+ }
241
+ if (method.length === 0) {
242
+ throw new Error('Unexpected method length');
243
+ }
244
+ var me = this;
245
+ var member = method[0].valueOf();
246
+ if (CustomList.isNumber(member)) {
247
+ var index = me.toIndex(member);
248
+ if (!me.value.hasOwnProperty(index)) {
249
+ console.error(method, member, args);
250
+ throw new Error("Unexpected index");
251
+ }
252
+ if (method.length > 1) {
253
+ return (_a = me.value[index]).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
254
+ }
255
+ return me.value[index];
256
+ }
257
+ if (!CustomList.intrinsics.has(member)) {
258
+ throw new Error("Cannot access ".concat(member, " in list"));
259
+ }
260
+ return (_b = CustomList.intrinsics.get(member)).call.apply(_b, __spreadArray([me], __read(args), false));
261
+ };
262
+ CustomList.prototype.getType = function () {
263
+ return 'list';
264
+ };
265
+ CustomList.prototype.valueOf = function () {
266
+ var me = this;
267
+ var value = me.value;
268
+ return value.length === 0 ? null : me;
269
+ };
270
+ CustomList.prototype.toString = function () {
271
+ var me = this;
272
+ var body = me.value.map(function (item) { var _a; return (_a = item === null || item === void 0 ? void 0 : item.valueOf()) === null || _a === void 0 ? void 0 : _a.toString(); });
273
+ return "[".concat(body.join(','), "]");
274
+ };
275
+ CustomList.prototype.fork = function () {
276
+ return new CustomList(this.value);
277
+ };
278
+ CustomList.intrinsics = new Map();
279
+ return CustomList;
280
+ }(custom_type_1.CustomObjectType));
281
+ exports.default = CustomList;
@@ -0,0 +1,28 @@
1
+ import { CustomObjectType, Callable } from '../types/custom-type';
2
+ export interface CustomMapIterableItem {
3
+ key: string;
4
+ value: any;
5
+ }
6
+ export declare class CustomMapIterator implements Iterator<CustomMapIterableItem> {
7
+ value: any;
8
+ index: number;
9
+ constructor(value: any);
10
+ next(): IteratorResult<CustomMapIterableItem>;
11
+ }
12
+ export default class CustomMap extends CustomObjectType implements Iterable<CustomMapIterableItem> {
13
+ static intrinsics: Map<string, Function>;
14
+ value: Map<string, any>;
15
+ isInstance: boolean;
16
+ constructor(value: Map<string, any>);
17
+ [Symbol.iterator](): CustomMapIterator;
18
+ extend(value: Map<string, any>): CustomMap;
19
+ set(path: string[], value: any): Promise<void>;
20
+ get(path: string[]): Promise<any>;
21
+ getCallable(path: string[]): Promise<Callable>;
22
+ callMethod(method: string[], ...args: any[]): any;
23
+ createInstancefunction(): CustomMap;
24
+ getType(): string;
25
+ valueOf(): CustomMap | null;
26
+ toString(): string;
27
+ fork(): CustomMap;
28
+ }
@@ -0,0 +1,289 @@
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 __read = (this && this.__read) || function (o, n) {
54
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
55
+ if (!m) return o;
56
+ var i = m.call(o), r, ar = [], e;
57
+ try {
58
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
+ }
60
+ catch (error) { e = { error: error }; }
61
+ finally {
62
+ try {
63
+ if (r && !r.done && (m = i["return"])) m.call(i);
64
+ }
65
+ finally { if (e) throw e.error; }
66
+ }
67
+ return ar;
68
+ };
69
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
70
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
71
+ if (ar || !(i in from)) {
72
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
73
+ ar[i] = from[i];
74
+ }
75
+ }
76
+ return to.concat(ar || Array.prototype.slice.call(from));
77
+ };
78
+ Object.defineProperty(exports, "__esModule", { value: true });
79
+ exports.CustomMapIterator = void 0;
80
+ var custom_type_1 = require("../types/custom-type");
81
+ var operation_1 = require("../types/operation");
82
+ var CustomMapIterator = /** @class */ (function () {
83
+ function CustomMapIterator(value) {
84
+ var me = this;
85
+ me.value = value;
86
+ me.index = 0;
87
+ }
88
+ CustomMapIterator.prototype.next = function () {
89
+ var me = this;
90
+ var keys = Object.keys(me.value);
91
+ if (me.index === keys.length) {
92
+ return {
93
+ value: null,
94
+ done: true
95
+ };
96
+ }
97
+ var key = keys[me.index++];
98
+ return {
99
+ value: {
100
+ key: key,
101
+ value: me.value[key]
102
+ },
103
+ done: false
104
+ };
105
+ };
106
+ return CustomMapIterator;
107
+ }());
108
+ exports.CustomMapIterator = CustomMapIterator;
109
+ var CustomMap = /** @class */ (function (_super) {
110
+ __extends(CustomMap, _super);
111
+ function CustomMap(value) {
112
+ var _this = _super.call(this) || this;
113
+ var me = _this;
114
+ me.value = new Map(__spreadArray([], __read(value.entries()), false));
115
+ me.isInstance = false;
116
+ return _this;
117
+ }
118
+ CustomMap.prototype[Symbol.iterator] = function () {
119
+ return new CustomMapIterator(this.value);
120
+ };
121
+ CustomMap.prototype.extend = function (value) {
122
+ var me = this;
123
+ me.value = new Map(__spreadArray(__spreadArray([], __read(me.value.entries()), false), __read(value.entries()), false));
124
+ return me;
125
+ };
126
+ CustomMap.prototype.set = function (path, value) {
127
+ return __awaiter(this, void 0, void 0, function () {
128
+ var me, traversalPath, refs, last, current, origin;
129
+ return __generator(this, function (_a) {
130
+ me = this;
131
+ traversalPath = [].concat(path);
132
+ refs = me.value;
133
+ last = traversalPath.pop();
134
+ current = traversalPath.shift();
135
+ origin = refs;
136
+ if (current != null) {
137
+ if (origin.has(current)) {
138
+ origin = origin.get(current);
139
+ if (origin instanceof custom_type_1.CustomObjectType) {
140
+ return [2 /*return*/, origin.set(traversalPath.concat(last), value)];
141
+ }
142
+ }
143
+ else {
144
+ throw new Error("Cannot set path ".concat(path.join('.')));
145
+ }
146
+ }
147
+ if (origin) {
148
+ if (value instanceof operation_1.FunctionOperationBase) {
149
+ origin.set(last, value.fork(me));
150
+ }
151
+ else {
152
+ origin.set(last, value);
153
+ }
154
+ }
155
+ else {
156
+ throw new Error("Cannot set path ".concat(path.join('.')));
157
+ }
158
+ return [2 /*return*/];
159
+ });
160
+ });
161
+ };
162
+ CustomMap.prototype.get = function (path) {
163
+ return __awaiter(this, void 0, void 0, function () {
164
+ var me, traversalPath, refs, current, currentValue, origin;
165
+ return __generator(this, function (_a) {
166
+ me = this;
167
+ if (path.length === 0) {
168
+ return [2 /*return*/, me];
169
+ }
170
+ traversalPath = [].concat(path);
171
+ refs = me.value;
172
+ current = traversalPath.shift();
173
+ currentValue = current.valueOf();
174
+ origin = refs;
175
+ if (currentValue != null) {
176
+ if (origin.has(currentValue)) {
177
+ origin = origin.get(currentValue);
178
+ if (traversalPath.length > 0 && origin instanceof custom_type_1.CustomObjectType) {
179
+ return [2 /*return*/, origin.get(traversalPath)];
180
+ }
181
+ }
182
+ else if (path.length === 1 && CustomMap.intrinsics.has(currentValue)) {
183
+ return [2 /*return*/, CustomMap.intrinsics.get(currentValue)];
184
+ }
185
+ else {
186
+ throw new Error("Cannot get path ".concat(path.join('.')));
187
+ }
188
+ }
189
+ else {
190
+ return [2 /*return*/, null];
191
+ }
192
+ return [2 /*return*/, origin];
193
+ });
194
+ });
195
+ };
196
+ CustomMap.prototype.getCallable = function (path) {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ var me, traversalPath, refs, current, origin, context;
199
+ return __generator(this, function (_a) {
200
+ me = this;
201
+ traversalPath = [].concat(path);
202
+ refs = me.value;
203
+ current = traversalPath.shift();
204
+ origin = refs;
205
+ if (current != null) {
206
+ if (origin.has(current)) {
207
+ context = origin;
208
+ origin = origin.get(current);
209
+ if (origin instanceof custom_type_1.CustomObjectType) {
210
+ return [2 /*return*/, origin.getCallable(traversalPath)];
211
+ }
212
+ }
213
+ else if (path.length === 1 && CustomMap.intrinsics.has(current)) {
214
+ return [2 /*return*/, {
215
+ origin: CustomMap.intrinsics.get(current),
216
+ context: me
217
+ }];
218
+ }
219
+ else {
220
+ throw new Error("Cannot get path ".concat(path.join('.')));
221
+ }
222
+ }
223
+ return [2 /*return*/, {
224
+ origin: origin,
225
+ context: context
226
+ }];
227
+ });
228
+ });
229
+ };
230
+ CustomMap.prototype.callMethod = function (method) {
231
+ var _a, _b;
232
+ var args = [];
233
+ for (var _i = 1; _i < arguments.length; _i++) {
234
+ args[_i - 1] = arguments[_i];
235
+ }
236
+ if (method.length === 0) {
237
+ throw new Error('Unexpected method length');
238
+ }
239
+ var me = this;
240
+ var key = method[0].valueOf();
241
+ if (method.length > 1) {
242
+ if (me.value.has(key)) {
243
+ return (_a = me.value.get(key)).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
244
+ }
245
+ throw new Error("Unexpected method path");
246
+ }
247
+ if (!CustomMap.intrinsics.has(key)) {
248
+ throw new Error("Cannot access ".concat(key, " in map"));
249
+ }
250
+ return (_b = CustomMap.intrinsics.get(key)).call.apply(_b, __spreadArray([me], __read(args), false));
251
+ };
252
+ CustomMap.prototype.createInstancefunction = function () {
253
+ var me = this;
254
+ var value = new Map();
255
+ var newInstance = new CustomMap(value);
256
+ newInstance.isInstance = true;
257
+ me.value.forEach(function (item, key) {
258
+ value.set(key, item instanceof operation_1.FunctionOperationBase
259
+ ? item.fork(newInstance)
260
+ : item);
261
+ });
262
+ return newInstance;
263
+ };
264
+ CustomMap.prototype.getType = function () {
265
+ var me = this;
266
+ return me.value.get('classID') || 'map';
267
+ };
268
+ CustomMap.prototype.valueOf = function () {
269
+ var me = this;
270
+ var value = me.value;
271
+ return value.size === 0 ? null : me;
272
+ };
273
+ CustomMap.prototype.toString = function () {
274
+ var me = this;
275
+ var body = Object
276
+ .entries(me.value)
277
+ .map(function (_a) {
278
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
279
+ return "\"".concat(key, "\": ").concat(value.valueOf().toString());
280
+ });
281
+ return "{".concat(body.join(','), "}");
282
+ };
283
+ CustomMap.prototype.fork = function () {
284
+ return new CustomMap(this.value);
285
+ };
286
+ CustomMap.intrinsics = new Map();
287
+ return CustomMap;
288
+ }(custom_type_1.CustomObjectType));
289
+ exports.default = CustomMap;
@@ -0,0 +1,8 @@
1
+ import { CustomLiteralType } from '../types/custom-type';
2
+ export default class CustomNil extends CustomLiteralType {
3
+ static intrinsics: Map<string, Function>;
4
+ value: null;
5
+ getType(): string;
6
+ valueOf(): null;
7
+ toString(): string;
8
+ }
@@ -0,0 +1,38 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ var custom_type_1 = require("../types/custom-type");
19
+ var CustomNil = /** @class */ (function (_super) {
20
+ __extends(CustomNil, _super);
21
+ function CustomNil() {
22
+ var _this = _super !== null && _super.apply(this, arguments) || this;
23
+ _this.value = null;
24
+ return _this;
25
+ }
26
+ CustomNil.prototype.getType = function () {
27
+ return 'null';
28
+ };
29
+ CustomNil.prototype.valueOf = function () {
30
+ return null;
31
+ };
32
+ CustomNil.prototype.toString = function () {
33
+ return 'null';
34
+ };
35
+ CustomNil.intrinsics = new Map();
36
+ return CustomNil;
37
+ }(custom_type_1.CustomLiteralType));
38
+ exports.default = CustomNil;
@@ -0,0 +1,10 @@
1
+ import { CustomLiteralType } from '../types/custom-type';
2
+ export default class CustomNumber extends CustomLiteralType {
3
+ static intrinsics: Map<string, Function>;
4
+ value: number;
5
+ constructor(value: number);
6
+ getType(): string;
7
+ valueOf(): number;
8
+ toString(): string;
9
+ fork(): CustomNumber;
10
+ }