greybel-interpreter 0.5.6 → 0.6.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.
@@ -14,33 +14,44 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
- var __read = (this && this.__read) || function (o, n) {
18
- var m = typeof Symbol === "function" && o[Symbol.iterator];
19
- if (!m) return o;
20
- var i = m.call(o), r, ar = [], e;
21
- try {
22
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23
- }
24
- catch (error) { e = { error: error }; }
25
- finally {
26
- try {
27
- if (r && !r.done && (m = i["return"])) m.call(i);
28
- }
29
- finally { if (e) throw e.error; }
30
- }
31
- return ar;
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
+ });
32
25
  };
33
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
35
- if (ar || !(i in from)) {
36
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
37
- ar[i] = from[i];
38
- }
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 };
39
51
  }
40
- return to.concat(ar || Array.prototype.slice.call(from));
41
52
  };
42
53
  Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.CustomStringIterator = void 0;
54
+ exports.itemAtIndex = exports.CustomStringIterator = void 0;
44
55
  var custom_type_1 = require("../types/custom-type");
45
56
  var CustomStringIterator = /** @class */ (function () {
46
57
  function CustomStringIterator(value) {
@@ -64,6 +75,17 @@ var CustomStringIterator = /** @class */ (function () {
64
75
  return CustomStringIterator;
65
76
  }());
66
77
  exports.CustomStringIterator = CustomStringIterator;
78
+ function itemAtIndex(str, n) {
79
+ if (Number.isNaN(n))
80
+ return null;
81
+ n = Math.trunc(n) || 0;
82
+ if (n < 0)
83
+ n += str.length;
84
+ if (n < 0 || n >= str.length)
85
+ return -1;
86
+ return n;
87
+ }
88
+ exports.itemAtIndex = itemAtIndex;
67
89
  var CustomString = /** @class */ (function (_super) {
68
90
  __extends(CustomString, _super);
69
91
  function CustomString(value) {
@@ -80,37 +102,51 @@ var CustomString = /** @class */ (function (_super) {
80
102
  CustomString.prototype[Symbol.iterator] = function () {
81
103
  return new CustomStringIterator(this.value);
82
104
  };
83
- CustomString.prototype.toIndex = function (value) {
84
- var me = this;
85
- var casted = Number(value);
86
- return casted < 0 ? me.value.length + casted : casted;
105
+ CustomString.prototype.get = function (path) {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ var me, traversalPath, str, current, currentIndex;
108
+ return __generator(this, function (_a) {
109
+ me = this;
110
+ if (path.length === 0) {
111
+ return [2 /*return*/, me];
112
+ }
113
+ traversalPath = [].concat(path);
114
+ str = me.value;
115
+ current = traversalPath.shift();
116
+ if (current != null) {
117
+ currentIndex = itemAtIndex(str, Number(current));
118
+ if (currentIndex != null && str.charAt(currentIndex) != null) {
119
+ return [2 /*return*/, new CustomString(str.charAt(currentIndex))];
120
+ }
121
+ else if (path.length === 1 && CustomString.intrinsics.has(current)) {
122
+ return [2 /*return*/, CustomString.intrinsics.get(current).bind(null, me)];
123
+ }
124
+ }
125
+ return [2 /*return*/, null];
126
+ });
127
+ });
87
128
  };
88
- CustomString.prototype.callMethod = function (method) {
89
- var args = [];
90
- for (var _i = 1; _i < arguments.length; _i++) {
91
- args[_i - 1] = arguments[_i];
92
- }
93
- if (method.length === 0) {
94
- throw new Error('Unexpected method length');
95
- }
96
- var me = this;
97
- var member = method[0].valueOf();
98
- if (CustomString.isNumber(member)) {
99
- var index = me.toIndex(member);
100
- if (!me.value[index]) {
101
- console.error(method, member, args);
102
- throw new Error("Unexpected index ".concat(index));
103
- }
104
- var value = new CustomString(me.value[index]);
105
- if (method.length > 1) {
106
- return value.callMethod.apply(value, __spreadArray([method.slice(1)], __read(args), false));
107
- }
108
- return value;
109
- }
110
- if (!CustomString.intrinsics.has(member)) {
111
- throw new Error("Cannot access ".concat(member, " in string"));
112
- }
113
- return CustomString.intrinsics.get(member).apply(void 0, __spreadArray([me], __read(args), false));
129
+ CustomString.prototype.getCallable = function (path) {
130
+ return __awaiter(this, void 0, void 0, function () {
131
+ var me, traversalPath, current;
132
+ return __generator(this, function (_a) {
133
+ me = this;
134
+ traversalPath = [].concat(path);
135
+ current = traversalPath.shift();
136
+ if (current != null) {
137
+ if (path.length === 1 && CustomString.intrinsics.has(current)) {
138
+ return [2 /*return*/, {
139
+ origin: CustomString.intrinsics.get(current).bind(null, me),
140
+ context: me
141
+ }];
142
+ }
143
+ }
144
+ return [2 /*return*/, {
145
+ origin: null,
146
+ context: me
147
+ }];
148
+ });
149
+ });
114
150
  };
115
151
  CustomString.prototype.getType = function () {
116
152
  return 'string';
@@ -152,25 +152,27 @@ var CallExpression = /** @class */ (function (_super) {
152
152
  var evaluate = function (node) {
153
153
  return __awaiter(this, void 0, void 0, function () {
154
154
  var args, pathExpr, callable_1, _a, callable, _b;
155
- var _c, _d, _e;
156
- return __generator(this, function (_f) {
157
- switch (_f.label) {
155
+ var _c, _d;
156
+ return __generator(this, function (_e) {
157
+ switch (_e.label) {
158
158
  case 0:
159
159
  if (node instanceof expression_1.Expression) {
160
160
  return [2 /*return*/, node.get(opc)];
161
161
  }
162
162
  return [4 /*yield*/, node.resolveArgs(operationContext)];
163
163
  case 1:
164
- args = _f.sent();
164
+ args = _e.sent();
165
165
  return [4 /*yield*/, node.path.get(opc, me.expr)];
166
166
  case 2:
167
- pathExpr = _f.sent();
167
+ pathExpr = _e.sent();
168
168
  operationContext.debugger.debug('Line', me.ast.start.line, 'CallExpression', 'pathExpr', pathExpr);
169
- if (!pathExpr.handle) return [3 /*break*/, 8];
170
- if (!(0, typer_1.isCustomMap)(pathExpr.handle)) return [3 /*break*/, 7];
169
+ if (!pathExpr.handle) return [3 /*break*/, 7];
170
+ if (!((0, typer_1.isCustomMap)(pathExpr.handle) ||
171
+ (0, typer_1.isCustomList)(pathExpr.handle) ||
172
+ (0, typer_1.isCustomString)(pathExpr.handle))) return [3 /*break*/, 6];
171
173
  return [4 /*yield*/, pathExpr.handle.getCallable(pathExpr.path)];
172
174
  case 3:
173
- callable_1 = _f.sent();
175
+ callable_1 = _e.sent();
174
176
  if (!(callable_1.origin instanceof operation_1.Operation)) return [3 /*break*/, 4];
175
177
  opc.setMemory('args', args);
176
178
  return [2 /*return*/, callable_1.origin.run(opc)];
@@ -178,23 +180,22 @@ var CallExpression = /** @class */ (function (_super) {
178
180
  if (!(callable_1.origin instanceof Function)) return [3 /*break*/, 6];
179
181
  _a = typer_1.cast;
180
182
  return [4 /*yield*/, (_c = callable_1.origin).call.apply(_c, __spreadArray([pathExpr.handle], __read(args), false))];
181
- case 5: return [2 /*return*/, _a.apply(void 0, [_f.sent()])];
183
+ case 5: return [2 /*return*/, _a.apply(void 0, [_e.sent()])];
182
184
  case 6:
183
- operationContext.debugger.raise('Unexpected handle call', me, callable_1);
184
- _f.label = 7;
185
- case 7: return [2 /*return*/, (0, typer_1.cast)((_d = pathExpr.handle).callMethod.apply(_d, __spreadArray([pathExpr.path], __read(args), false)))];
186
- case 8: return [4 /*yield*/, opc.getCallable(pathExpr.path)];
187
- case 9:
188
- callable = _f.sent();
185
+ operationContext.debugger.raise('Unexpected handle call', me, pathExpr);
186
+ _e.label = 7;
187
+ case 7: return [4 /*yield*/, opc.getCallable(pathExpr.path)];
188
+ case 8:
189
+ callable = _e.sent();
189
190
  opc.setMemory('args', args);
190
- if (!(callable.origin instanceof operation_1.Operation)) return [3 /*break*/, 10];
191
+ if (!(callable.origin instanceof operation_1.Operation)) return [3 /*break*/, 9];
191
192
  return [2 /*return*/, callable.origin.run(opc)];
192
- case 10:
193
- if (!(callable.origin instanceof Function)) return [3 /*break*/, 12];
193
+ case 9:
194
+ if (!(callable.origin instanceof Function)) return [3 /*break*/, 11];
194
195
  _b = typer_1.cast;
195
- return [4 /*yield*/, (_e = callable.origin).call.apply(_e, __spreadArray([callable.context], __read(args), false))];
196
- case 11: return [2 /*return*/, _b.apply(void 0, [_f.sent()])];
197
- case 12: return [2 /*return*/, (0, typer_1.cast)(callable.origin)];
196
+ return [4 /*yield*/, (_d = callable.origin).call.apply(_d, __spreadArray([callable.context], __read(args), false))];
197
+ case 10: return [2 /*return*/, _b.apply(void 0, [_e.sent()])];
198
+ case 11: return [2 /*return*/, (0, typer_1.cast)(callable.origin)];
198
199
  }
199
200
  });
200
201
  });
@@ -67,6 +67,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
67
67
  Object.defineProperty(exports, "__esModule", { value: true });
68
68
  exports.ExpressionSegment = exports.ValuesSegment = void 0;
69
69
  var expression_1 = require("../types/expression");
70
+ var operation_1 = require("../types/operation");
70
71
  var map_1 = __importDefault(require("../custom-types/map"));
71
72
  var typer_1 = require("../typer");
72
73
  var ValuesSegment = /** @class */ (function () {
@@ -138,46 +139,52 @@ var MapExpression = /** @class */ (function (_super) {
138
139
  map = new Map();
139
140
  _b.label = 1;
140
141
  case 1:
141
- _b.trys.push([1, 9, 10, 11]);
142
+ _b.trys.push([1, 11, 12, 13]);
142
143
  values_1 = __values(values), values_1_1 = values_1.next();
143
144
  _b.label = 2;
144
145
  case 2:
145
- if (!!values_1_1.done) return [3 /*break*/, 8];
146
+ if (!!values_1_1.done) return [3 /*break*/, 10];
146
147
  current = values_1_1.value;
147
148
  key = void 0;
148
149
  value = void 0;
149
150
  key = current.key;
150
151
  if (!(0, typer_1.isCustomValue)(current.value)) return [3 /*break*/, 3];
151
152
  value = current.value;
152
- return [3 /*break*/, 6];
153
+ return [3 /*break*/, 8];
153
154
  case 3:
154
155
  if (!(current.value instanceof expression_1.Expression)) return [3 /*break*/, 5];
155
156
  return [4 /*yield*/, current.value.get(operationContext)];
156
157
  case 4:
157
158
  value = _b.sent();
158
- return [3 /*break*/, 6];
159
+ return [3 /*break*/, 8];
159
160
  case 5:
160
- operationContext.debugger.raise('Unexpected value', me, current.value);
161
- _b.label = 6;
161
+ if (!(current.value instanceof operation_1.Operation)) return [3 /*break*/, 7];
162
+ return [4 /*yield*/, current.value.get(operationContext)];
162
163
  case 6:
164
+ value = _b.sent();
165
+ return [3 /*break*/, 8];
166
+ case 7:
167
+ operationContext.debugger.raise('Unexpected value', me, current.value);
168
+ _b.label = 8;
169
+ case 8:
163
170
  // @ts-ignore: Key is always a literal
164
171
  map.set(key, value);
165
- _b.label = 7;
166
- case 7:
172
+ _b.label = 9;
173
+ case 9:
167
174
  values_1_1 = values_1.next();
168
175
  return [3 /*break*/, 2];
169
- case 8: return [3 /*break*/, 11];
170
- case 9:
176
+ case 10: return [3 /*break*/, 13];
177
+ case 11:
171
178
  e_1_1 = _b.sent();
172
179
  e_1 = { error: e_1_1 };
173
- return [3 /*break*/, 11];
174
- case 10:
180
+ return [3 /*break*/, 13];
181
+ case 12:
175
182
  try {
176
183
  if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
177
184
  }
178
185
  finally { if (e_1) throw e_1.error; }
179
186
  return [7 /*endfinally*/];
180
- case 11: return [2 /*return*/, new map_1.default(map)];
187
+ case 13: return [2 /*return*/, new map_1.default(map)];
181
188
  }
182
189
  });
183
190
  });
@@ -198,14 +198,14 @@ var PathExpression = /** @class */ (function (_super) {
198
198
  me = this;
199
199
  evaluate = function (node) {
200
200
  return __awaiter(this, void 0, void 0, function () {
201
- var traverselPath, traversedPath, position, handle, current, functionContext, origin, value, origin, left, right;
202
- return __generator(this, function (_a) {
203
- switch (_a.label) {
201
+ var traverselPath, traversedPath, position, handle, current, functionContext, origin, _a, value, origin, left, right;
202
+ return __generator(this, function (_b) {
203
+ switch (_b.label) {
204
204
  case 0:
205
205
  traverselPath = [].concat(node.value);
206
206
  traversedPath = [];
207
207
  position = 0;
208
- _a.label = 1;
208
+ _b.label = 1;
209
209
  case 1:
210
210
  if (!(current = traverselPath.shift())) return [3 /*break*/, 30];
211
211
  if (!(0, typer_1.isCustomValue)(current)) return [3 /*break*/, 2];
@@ -215,13 +215,13 @@ var PathExpression = /** @class */ (function (_super) {
215
215
  if (!(current instanceof expression_1.Expression)) return [3 /*break*/, 4];
216
216
  return [4 /*yield*/, current.get(operationContext, me.expr)];
217
217
  case 3:
218
- handle = _a.sent();
218
+ handle = _b.sent();
219
219
  return [3 /*break*/, 29];
220
220
  case 4:
221
221
  if (!(current instanceof operation_1.Operation)) return [3 /*break*/, 6];
222
222
  return [4 /*yield*/, current.get(operationContext)];
223
223
  case 5:
224
- handle = _a.sent();
224
+ handle = _b.sent();
225
225
  return [3 /*break*/, 29];
226
226
  case 6:
227
227
  if (!(current instanceof PathSegment)) return [3 /*break*/, 12];
@@ -239,18 +239,19 @@ var PathExpression = /** @class */ (function (_super) {
239
239
  if (!(traverselPath.length > 0)) return [3 /*break*/, 11];
240
240
  return [4 /*yield*/, (handle || operationContext).get(traversedPath)];
241
241
  case 8:
242
- origin = _a.sent();
242
+ origin = _b.sent();
243
243
  if (!(0, typer_1.isCustomValue)(origin)) return [3 /*break*/, 9];
244
244
  handle = origin;
245
245
  traversedPath = [];
246
246
  return [3 /*break*/, 11];
247
247
  case 9:
248
248
  if (!(origin instanceof Function)) return [3 /*break*/, 11];
249
+ _a = typer_1.cast;
249
250
  return [4 /*yield*/, origin.call(handle)];
250
251
  case 10:
251
- handle = _a.sent();
252
+ handle = _a.apply(void 0, [_b.sent()]);
252
253
  traversedPath = [];
253
- _a.label = 11;
254
+ _b.label = 11;
254
255
  case 11: return [3 /*break*/, 29];
255
256
  case 12:
256
257
  if (!(current instanceof IndexSegment)) return [3 /*break*/, 19];
@@ -262,31 +263,31 @@ var PathExpression = /** @class */ (function (_super) {
262
263
  if (!(current instanceof expression_1.Expression)) return [3 /*break*/, 15];
263
264
  return [4 /*yield*/, current.get(operationContext)];
264
265
  case 14:
265
- value = _a.sent();
266
+ value = _b.sent();
266
267
  traversedPath.push(value.toString());
267
268
  return [3 /*break*/, 16];
268
269
  case 15:
269
270
  operationContext.debugger.raise('Unexpected index', me, current);
270
- _a.label = 16;
271
+ _b.label = 16;
271
272
  case 16:
272
273
  if (!(handle && !parentExpr)) return [3 /*break*/, 18];
273
274
  return [4 /*yield*/, handle.get(traversedPath, me.expr)];
274
275
  case 17:
275
- origin = _a.sent();
276
+ origin = _b.sent();
276
277
  if (origin instanceof Function || origin instanceof function_1.default) {
277
278
  handle = origin;
278
279
  traversedPath = [];
279
280
  }
280
- _a.label = 18;
281
+ _b.label = 18;
281
282
  case 18: return [3 /*break*/, 29];
282
283
  case 19:
283
284
  if (!(current instanceof SliceSegment)) return [3 /*break*/, 28];
284
285
  if (!!handle) return [3 /*break*/, 21];
285
286
  return [4 /*yield*/, operationContext.get(traversedPath)];
286
287
  case 20:
287
- handle = _a.sent();
288
+ handle = _b.sent();
288
289
  traversedPath = [];
289
- _a.label = 21;
290
+ _b.label = 21;
290
291
  case 21:
291
292
  if (!(0, typer_1.isCustomList)(handle) && !(0, typer_1.isCustomString)(handle)) {
292
293
  operationContext.debugger.raise('Invalid type for slice', me, handle);
@@ -299,8 +300,8 @@ var PathExpression = /** @class */ (function (_super) {
299
300
  if (!(left instanceof expression_1.Expression)) return [3 /*break*/, 24];
300
301
  return [4 /*yield*/, left.get(operationContext)];
301
302
  case 23:
302
- left = _a.sent();
303
- _a.label = 24;
303
+ left = _b.sent();
304
+ _b.label = 24;
304
305
  case 24:
305
306
  right = current.right;
306
307
  if (!(0, typer_1.isCustomValue)(right)) return [3 /*break*/, 25];
@@ -310,14 +311,14 @@ var PathExpression = /** @class */ (function (_super) {
310
311
  if (!(right instanceof expression_1.Expression)) return [3 /*break*/, 27];
311
312
  return [4 /*yield*/, right.get(operationContext)];
312
313
  case 26:
313
- right = _a.sent();
314
- _a.label = 27;
314
+ right = _b.sent();
315
+ _b.label = 27;
315
316
  case 27:
316
317
  handle = handle.slice(left, right);
317
318
  return [3 /*break*/, 29];
318
319
  case 28:
319
320
  operationContext.debugger.raise('Unexpected handle', me, current);
320
- _a.label = 29;
321
+ _b.label = 29;
321
322
  case 29:
322
323
  position++;
323
324
  return [3 /*break*/, 1];
@@ -338,7 +339,9 @@ var PathExpression = /** @class */ (function (_super) {
338
339
  if (!(resultExpr.path.length === 0)) return [3 /*break*/, 2];
339
340
  return [2 /*return*/, resultExpr.handle];
340
341
  case 2:
341
- if (!(0, typer_1.isCustomMap)(resultExpr.handle)) return [3 /*break*/, 7];
342
+ if (!((0, typer_1.isCustomMap)(resultExpr.handle) ||
343
+ (0, typer_1.isCustomList)(resultExpr.handle) ||
344
+ (0, typer_1.isCustomString)(resultExpr.handle))) return [3 /*break*/, 7];
342
345
  context = resultExpr.handle;
343
346
  return [4 /*yield*/, context.get(resultExpr.path)];
344
347
  case 3:
@@ -351,7 +354,9 @@ var PathExpression = /** @class */ (function (_super) {
351
354
  return [4 /*yield*/, value_1.call(context)];
352
355
  case 5: return [2 /*return*/, _a.apply(void 0, [_c.sent()])];
353
356
  case 6: return [2 /*return*/, value_1];
354
- case 7: return [2 /*return*/, (0, typer_1.cast)(resultExpr.handle.callMethod(resultExpr.path))];
357
+ case 7:
358
+ operationContext.debugger.raise('Unexpected handle get', me, resultExpr);
359
+ _c.label = 8;
355
360
  case 8: return [4 /*yield*/, operationContext.get(resultExpr.path)];
356
361
  case 9:
357
362
  value = _c.sent();
@@ -81,19 +81,19 @@ var ArgumentOperation = /** @class */ (function (_super) {
81
81
  }
82
82
  ArgumentOperation.prototype.get = function (operationContext) {
83
83
  return __awaiter(this, void 0, void 0, function () {
84
- var me, stack, args, stack_1, stack_1_1, entity, _a, _b, arg, e_1_1;
85
- var e_1, _c;
86
- return __generator(this, function (_d) {
87
- switch (_d.label) {
84
+ var me, stack, args, stack_1, stack_1_1, entity, arg, arg, e_1_1;
85
+ var e_1, _a;
86
+ return __generator(this, function (_b) {
87
+ switch (_b.label) {
88
88
  case 0:
89
89
  me = this;
90
90
  stack = me.stack;
91
91
  args = [];
92
- _d.label = 1;
92
+ _b.label = 1;
93
93
  case 1:
94
- _d.trys.push([1, 11, 12, 13]);
94
+ _b.trys.push([1, 11, 12, 13]);
95
95
  stack_1 = __values(stack), stack_1_1 = stack_1.next();
96
- _d.label = 2;
96
+ _b.label = 2;
97
97
  case 2:
98
98
  if (!!stack_1_1.done) return [3 /*break*/, 10];
99
99
  entity = stack_1_1.value;
@@ -104,34 +104,34 @@ var ArgumentOperation = /** @class */ (function (_super) {
104
104
  if (!(entity instanceof assign_1.default)) return [3 /*break*/, 6];
105
105
  return [4 /*yield*/, entity.get(operationContext, me)];
106
106
  case 4:
107
- _d.sent();
108
- _b = (_a = args).push;
109
- return [4 /*yield*/, entity.expr.left.get(operationContext)];
107
+ _b.sent();
108
+ return [4 /*yield*/, entity.expr.left.get(operationContext, me)];
110
109
  case 5:
111
- _b.apply(_a, [_d.sent()]);
110
+ arg = _b.sent();
111
+ args.push(arg);
112
112
  return [3 /*break*/, 9];
113
113
  case 6:
114
114
  if (!(entity instanceof path_1.default)) return [3 /*break*/, 8];
115
115
  return [4 /*yield*/, entity.get(operationContext, me)];
116
116
  case 7:
117
- arg = _d.sent();
117
+ arg = _b.sent();
118
118
  operationContext.set(arg.path, new nil_1.default());
119
119
  args.push(arg);
120
120
  return [3 /*break*/, 9];
121
121
  case 8:
122
122
  operationContext.debugger.raise('Unexpected argument', me, entity);
123
- _d.label = 9;
123
+ _b.label = 9;
124
124
  case 9:
125
125
  stack_1_1 = stack_1.next();
126
126
  return [3 /*break*/, 2];
127
127
  case 10: return [3 /*break*/, 13];
128
128
  case 11:
129
- e_1_1 = _d.sent();
129
+ e_1_1 = _b.sent();
130
130
  e_1 = { error: e_1_1 };
131
131
  return [3 /*break*/, 13];
132
132
  case 12:
133
133
  try {
134
- if (stack_1_1 && !stack_1_1.done && (_c = stack_1.return)) _c.call(stack_1);
134
+ if (stack_1_1 && !stack_1_1.done && (_a = stack_1.return)) _a.call(stack_1);
135
135
  }
136
136
  finally { if (e_1) throw e_1.error; }
137
137
  return [7 /*endfinally*/];
@@ -50,10 +50,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
50
50
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
51
  }
52
52
  };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
53
56
  Object.defineProperty(exports, "__esModule", { value: true });
54
57
  var operation_1 = require("../types/operation");
55
58
  var expression_1 = require("../types/expression");
56
59
  var typer_1 = require("../typer");
60
+ var nil_1 = __importDefault(require("../custom-types/nil"));
57
61
  var ReturnOperation = /** @class */ (function (_super) {
58
62
  __extends(ReturnOperation, _super);
59
63
  function ReturnOperation(ast, options) {
@@ -87,7 +91,7 @@ var ReturnOperation = /** @class */ (function (_super) {
87
91
  arg = _a.sent();
88
92
  return [3 /*break*/, 6];
89
93
  case 5:
90
- operationContext.debugger.raise('Unexpected return value', me, me.arg);
94
+ arg = new nil_1.default();
91
95
  _a.label = 6;
92
96
  case 6:
93
97
  functionContext.value = arg;
@@ -82,7 +82,7 @@ var WhileOperation = /** @class */ (function (_super) {
82
82
  };
83
83
  resolveCondition = function () {
84
84
  return __awaiter(this, void 0, void 0, function () {
85
- var value;
85
+ var value, value;
86
86
  return __generator(this, function (_a) {
87
87
  switch (_a.label) {
88
88
  case 0:
@@ -90,13 +90,19 @@ var WhileOperation = /** @class */ (function (_super) {
90
90
  return [4 /*yield*/, me.condition.get(opc)];
91
91
  case 1:
92
92
  value = _a.sent();
93
- return [2 /*return*/, value.valueOf()];
93
+ return [2 /*return*/, !!(value === null || value === void 0 ? void 0 : value.valueOf())];
94
94
  case 2:
95
+ if (!(me.condition instanceof operation_1.Operation)) return [3 /*break*/, 4];
96
+ return [4 /*yield*/, me.condition.get(opc)];
97
+ case 3:
98
+ value = _a.sent();
99
+ return [2 /*return*/, !!(value === null || value === void 0 ? void 0 : value.valueOf())];
100
+ case 4:
95
101
  if ((0, typer_1.isCustomValue)(me.condition)) {
96
102
  return [2 /*return*/, me.condition.valueOf()];
97
103
  }
98
- _a.label = 3;
99
- case 3:
104
+ _a.label = 5;
105
+ case 5:
100
106
  operationContext.debugger.raise('Unexpected condition', me, me.condition);
101
107
  return [2 /*return*/];
102
108
  }
@@ -9,6 +9,7 @@ export declare abstract class CustomLiteralType extends CustomType {
9
9
  }
10
10
  export declare abstract class CustomObjectType extends CustomType {
11
11
  value: any;
12
+ has(path: any[]): Promise<boolean>;
12
13
  set(path: any[], value: any): Promise<void>;
13
14
  get(path: any[]): Promise<any>;
14
15
  getCallable(path: any[]): Promise<Callable>;
@@ -44,6 +44,9 @@ var CustomObjectType = /** @class */ (function (_super) {
44
44
  function CustomObjectType() {
45
45
  return _super !== null && _super.apply(this, arguments) || this;
46
46
  }
47
+ CustomObjectType.prototype.has = function (path) {
48
+ throw new Error('Implentation of "has" missing');
49
+ };
47
50
  CustomObjectType.prototype.set = function (path, value) {
48
51
  throw new Error('Implentation of "set" missing');
49
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "0.5.6",
3
+ "version": "0.6.0",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",