greybel-interpreter 0.5.7 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/context.d.ts CHANGED
@@ -18,7 +18,6 @@ export declare enum ContextState {
18
18
  export declare class Scope extends CustomMap {
19
19
  context: OperationContext;
20
20
  constructor(context: OperationContext);
21
- set(path: string[], value: any): Promise<void>;
22
21
  get(path: string[]): Promise<any>;
23
22
  getCallable(path: string[]): Promise<Callable>;
24
23
  }
@@ -70,9 +69,9 @@ export declare class OperationContext {
70
69
  processState: OperationContextProcessState;
71
70
  isProtected: boolean;
72
71
  injected: boolean;
73
- api: Scope | null;
74
- locals: Scope | null;
75
- globals: Scope | null;
72
+ api: OperationContext | null;
73
+ locals: OperationContext | null;
74
+ globals: OperationContext | null;
76
75
  constructor(options: OperationContextOptions);
77
76
  step(item: ASTBase): Promise<void>;
78
77
  setLastActive(opc: OperationContext): OperationContext;
@@ -81,10 +80,12 @@ export declare class OperationContext {
81
80
  exit(): Promise<OperationContext>;
82
81
  isPending(): boolean;
83
82
  setPending(pending: boolean): OperationContext;
84
- lookupType(validate: (type: ContextType) => boolean): Scope;
85
- lookupAPI(): Scope;
86
- lookupGlobals(): Scope;
87
- lookupLocals(): Scope;
83
+ lookupAllOfType(validate: (type: ContextType) => boolean): OperationContext[];
84
+ lookupType(validate: (type: ContextType) => boolean): OperationContext;
85
+ lookupAllScopes(): OperationContext[];
86
+ lookupAPI(): OperationContext;
87
+ lookupGlobals(): OperationContext;
88
+ lookupLocals(): OperationContext;
88
89
  valueOf(): CustomMap;
89
90
  extend(map: Map<string, any>): OperationContext;
90
91
  set(path: any[], value: any): Promise<void>;
package/dist/context.js CHANGED
@@ -14,6 +14,42 @@ 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 __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
+ };
17
53
  var __read = (this && this.__read) || function (o, n) {
18
54
  var m = typeof Symbol === "function" && o[Symbol.iterator];
19
55
  if (!m) return o;
@@ -67,96 +103,81 @@ var Scope = /** @class */ (function (_super) {
67
103
  _this.context = context;
68
104
  return _this;
69
105
  }
70
- Scope.prototype.set = function (path, value) {
71
- var me = this;
72
- var traversalPath = [].concat(path);
73
- var current = traversalPath.shift();
74
- if (current != null) {
75
- if (current === 'locals') {
76
- return me.context.locals.set(traversalPath, value);
77
- }
78
- else if (current === 'globals') {
79
- return me.context.globals.set(traversalPath, value);
80
- }
81
- else if (me.context.locals != null) {
82
- return map_1.default.prototype.set.call(me.context.locals, path, value);
83
- }
84
- else {
85
- throw new Error("Cannot set path ".concat(path.join('.')));
86
- }
87
- }
88
- };
89
106
  Scope.prototype.get = function (path) {
90
- var _a, _b, _c;
91
- var me = this;
92
- var traversalPath = [].concat(path);
93
- var current = traversalPath.shift();
94
- if (current != null) {
95
- if (current === 'locals') {
96
- return traversalPath.length === 0
97
- ? Promise.resolve(me.context.locals)
98
- : me.context.locals.get(traversalPath);
99
- }
100
- else if (current === 'globals') {
101
- return traversalPath.length === 0
102
- ? Promise.resolve(me.context.globals)
103
- : me.context.globals.get(traversalPath);
104
- }
105
- else if ((_a = me.context.locals) === null || _a === void 0 ? void 0 : _a.value.has(current)) {
106
- return map_1.default.prototype.get.call(me.context.locals, path);
107
- }
108
- else if ((_b = me.context.globals) === null || _b === void 0 ? void 0 : _b.value.has(current)) {
109
- return map_1.default.prototype.get.call(me.context.globals, path);
110
- }
111
- else if ((_c = me.context.api) === null || _c === void 0 ? void 0 : _c.value.has(current)) {
112
- return map_1.default.prototype.get.call(me.context.api, path);
113
- }
114
- else if (me.value.has(current)) {
115
- return _super.prototype.get.call(this, path);
116
- }
117
- else if (me.context.previous) {
118
- return map_1.default.prototype.get.call(me.context.previous.scope, path);
119
- }
120
- else {
121
- throw new Error("Cannot get path ".concat(path.join('.')));
122
- }
123
- }
124
- return null;
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ var me, traversalPath, current;
109
+ return __generator(this, function (_a) {
110
+ switch (_a.label) {
111
+ case 0:
112
+ me = this;
113
+ traversalPath = [].concat(path);
114
+ current = traversalPath.shift();
115
+ if (path.length === 0) {
116
+ return [2 /*return*/, Promise.resolve(me)];
117
+ }
118
+ if (!(current === 'locals' || current === 'globals')) return [3 /*break*/, 1];
119
+ return [2 /*return*/, me.context.get(path)];
120
+ case 1: return [4 /*yield*/, me.has(path)];
121
+ case 2:
122
+ if (!_a.sent()) return [3 /*break*/, 3];
123
+ return [2 /*return*/, _super.prototype.get.call(this, path)];
124
+ case 3: return [4 /*yield*/, me.context.api.scope.has(path)];
125
+ case 4:
126
+ if (_a.sent()) {
127
+ return [2 /*return*/, me.context.api.get(path)];
128
+ }
129
+ else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
130
+ return [2 /*return*/, Promise.resolve(map_1.default.intrinsics.get(current).bind(null, me))];
131
+ }
132
+ else if (me.context.previous) {
133
+ return [2 /*return*/, me.context.previous.get(path)];
134
+ }
135
+ else {
136
+ throw new Error("Cannot get path ".concat(path.join('.')));
137
+ }
138
+ _a.label = 5;
139
+ case 5: return [2 /*return*/];
140
+ }
141
+ });
142
+ });
125
143
  };
126
144
  Scope.prototype.getCallable = function (path) {
127
- var _a, _b, _c;
128
- var me = this;
129
- var traversalPath = [].concat(path);
130
- var current = traversalPath.shift();
131
- if (current != null) {
132
- if (current === 'locals') {
133
- return me.context.locals.getCallable(traversalPath);
134
- }
135
- else if (current === 'globals') {
136
- return me.context.globals.getCallable(traversalPath);
137
- }
138
- else if ((_a = me.context.locals) === null || _a === void 0 ? void 0 : _a.value.has(current)) {
139
- return map_1.default.prototype.getCallable.call(me.context.locals, path);
140
- }
141
- else if ((_b = me.context.globals) === null || _b === void 0 ? void 0 : _b.value.has(current)) {
142
- return map_1.default.prototype.getCallable.call(me.context.globals, path);
143
- }
144
- else if ((_c = me.context.api) === null || _c === void 0 ? void 0 : _c.value.has(current)) {
145
- return map_1.default.prototype.getCallable.call(me.context.api, path);
146
- }
147
- else if (me.value.has(current)) {
148
- return _super.prototype.getCallable.call(this, path);
149
- }
150
- else if (me.context.previous) {
151
- return map_1.default.prototype.getCallable.call(me.context.previous.scope, path);
152
- }
153
- else {
154
- throw new Error("Cannot get callable path ".concat(path.join('.')));
155
- }
156
- }
157
- return Promise.resolve({
158
- origin: me,
159
- context: null
145
+ return __awaiter(this, void 0, void 0, function () {
146
+ var me, traversalPath, current;
147
+ return __generator(this, function (_a) {
148
+ switch (_a.label) {
149
+ case 0:
150
+ me = this;
151
+ traversalPath = [].concat(path);
152
+ current = traversalPath.shift();
153
+ if (current === 'locals' || current === 'globals') {
154
+ return [2 /*return*/, me.context.getCallable(path)];
155
+ }
156
+ return [4 /*yield*/, me.has(path)];
157
+ case 1:
158
+ if (!_a.sent()) return [3 /*break*/, 2];
159
+ return [2 /*return*/, _super.prototype.getCallable.call(this, path)];
160
+ case 2: return [4 /*yield*/, me.context.api.scope.has(path)];
161
+ case 3:
162
+ if (_a.sent()) {
163
+ return [2 /*return*/, me.context.api.getCallable(path)];
164
+ }
165
+ else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
166
+ return [2 /*return*/, Promise.resolve({
167
+ origin: map_1.default.intrinsics.get(current).bind(null, me),
168
+ context: me
169
+ })];
170
+ }
171
+ else if (me.context.previous) {
172
+ return [2 /*return*/, me.context.previous.getCallable(path)];
173
+ }
174
+ else {
175
+ throw new Error("Cannot get callable path ".concat(path.join('.')));
176
+ }
177
+ _a.label = 4;
178
+ case 4: return [2 /*return*/];
179
+ }
180
+ });
160
181
  });
161
182
  };
162
183
  return Scope;
@@ -247,7 +268,7 @@ var OperationContext = /** @class */ (function () {
247
268
  };
248
269
  me.api = me.lookupAPI();
249
270
  me.globals = me.lookupGlobals();
250
- me.locals = me.lookupLocals();
271
+ me.locals = me.lookupLocals() || me;
251
272
  }
252
273
  OperationContext.prototype.step = function (item) {
253
274
  var me = this;
@@ -303,20 +324,38 @@ var OperationContext = /** @class */ (function () {
303
324
  me.processState.pending = pending;
304
325
  return me;
305
326
  };
327
+ OperationContext.prototype.lookupAllOfType = function (validate) {
328
+ var me = this;
329
+ var result = [];
330
+ if (validate(me.type)) {
331
+ result.push(me);
332
+ }
333
+ var current = me.previous;
334
+ while (current) {
335
+ if (validate(current.type)) {
336
+ result.push(current);
337
+ }
338
+ current = current.previous;
339
+ }
340
+ return result;
341
+ };
306
342
  OperationContext.prototype.lookupType = function (validate) {
307
343
  var me = this;
308
344
  if (validate(me.type)) {
309
- return me.scope;
345
+ return me;
310
346
  }
311
347
  var current = me.previous;
312
348
  while (current) {
313
349
  if (validate(current.type)) {
314
- return current.scope;
350
+ return current;
315
351
  }
316
352
  current = current.previous;
317
353
  }
318
354
  return null;
319
355
  };
356
+ OperationContext.prototype.lookupAllScopes = function () {
357
+ return this.lookupAllOfType(function (type) { return [ContextType.GLOBAL, ContextType.FUNCTION].includes(type); });
358
+ };
320
359
  OperationContext.prototype.lookupAPI = function () {
321
360
  return this.lookupType(function (type) { return [ContextType.API].includes(type); });
322
361
  };
@@ -327,7 +366,7 @@ var OperationContext = /** @class */ (function () {
327
366
  return this.lookupType(function (type) { return [ContextType.GLOBAL, ContextType.FUNCTION].includes(type); });
328
367
  };
329
368
  OperationContext.prototype.valueOf = function () {
330
- return this.scope.valueOf();
369
+ return this.scope;
331
370
  };
332
371
  OperationContext.prototype.extend = function (map) {
333
372
  var _a;
@@ -343,28 +382,46 @@ var OperationContext = /** @class */ (function () {
343
382
  OperationContext.prototype.set = function (path, value) {
344
383
  var _a;
345
384
  var me = this;
385
+ var traversalPath = [].concat(path);
386
+ var current = traversalPath.shift();
387
+ if (current === 'locals') {
388
+ return me.locals.set(traversalPath, value);
389
+ }
390
+ else if (current === 'globals') {
391
+ return me.globals.set(traversalPath, value);
392
+ }
346
393
  if (me.state === ContextState.TEMPORARY) {
347
394
  return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
348
395
  }
349
- else {
350
- return me.scope.set(path, value);
351
- }
396
+ return me.locals.scope.set(path, value);
352
397
  };
353
398
  OperationContext.prototype.get = function (path) {
354
399
  var _a;
355
400
  var me = this;
356
- if (me.state === ContextState.TEMPORARY) {
401
+ var traversalPath = [].concat(path);
402
+ var current = traversalPath.shift();
403
+ if (current === 'locals') {
404
+ return me.locals.get(traversalPath);
405
+ }
406
+ else if (current === 'globals') {
407
+ return me.globals.get(traversalPath);
408
+ }
409
+ else if (me.state === ContextState.TEMPORARY) {
357
410
  return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.get(path);
358
411
  }
359
- return me.scope.get(path);
412
+ return me.locals.scope.get(path);
360
413
  };
361
414
  OperationContext.prototype.getCallable = function (path) {
362
- var _a;
363
415
  var me = this;
364
- if (me.state === ContextState.TEMPORARY) {
365
- return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.getCallable(path);
416
+ var traversalPath = [].concat(path);
417
+ var current = traversalPath.shift();
418
+ if (current === 'locals') {
419
+ return me.locals.getCallable(traversalPath);
420
+ }
421
+ else if (current === 'globals') {
422
+ return me.globals.getCallable(traversalPath);
366
423
  }
367
- return me.scope.getCallable(path);
424
+ return me.locals.scope.getCallable(path);
368
425
  };
369
426
  OperationContext.prototype.setMemory = function (key, value) {
370
427
  var me = this;
@@ -187,9 +187,6 @@ var CustomList = /** @class */ (function (_super) {
187
187
  else if (path.length === 1 && CustomList.intrinsics.has(current)) {
188
188
  return [2 /*return*/, CustomList.intrinsics.get(current).bind(null, me)];
189
189
  }
190
- else {
191
- throw new Error("Cannot get path ".concat(path.join('.')));
192
- }
193
190
  }
194
191
  return [2 /*return*/, null];
195
192
  });
@@ -223,12 +220,9 @@ var CustomList = /** @class */ (function (_super) {
223
220
  context: me
224
221
  }];
225
222
  }
226
- else {
227
- throw new Error("Cannot get path ".concat(path.join('.')));
228
- }
229
223
  }
230
224
  return [2 /*return*/, {
231
- origin: refs,
225
+ origin: null,
232
226
  context: me
233
227
  }];
234
228
  });
@@ -16,6 +16,7 @@ export default class CustomMap extends CustomObjectType implements Iterable<Cust
16
16
  constructor(value?: Map<string, any>);
17
17
  [Symbol.iterator](): CustomMapIterator;
18
18
  extend(value: Map<string, any>): CustomMap;
19
+ has(path: string[]): Promise<boolean>;
19
20
  set(path: string[], value: any): Promise<void>;
20
21
  get(path: string[]): Promise<any>;
21
22
  getCallable(path: string[]): Promise<Callable>;
@@ -87,8 +87,33 @@ var CustomMap = /** @class */ (function (_super) {
87
87
  me.value = new Map(__spreadArray(__spreadArray([], __read(me.value.entries()), false), __read(value.entries()), false));
88
88
  return me;
89
89
  };
90
+ CustomMap.prototype.has = function (path) {
91
+ var me = this;
92
+ if (path.length === 0) {
93
+ return Promise.resolve(true);
94
+ }
95
+ var traversalPath = [].concat(path);
96
+ var refs = me.value;
97
+ var current = traversalPath.shift();
98
+ if (current != null) {
99
+ if (refs.has(current)) {
100
+ var sub = refs.get(current);
101
+ if (traversalPath.length > 0 && sub instanceof custom_type_1.CustomObjectType) {
102
+ return sub.has(traversalPath);
103
+ }
104
+ if (traversalPath.length === 0) {
105
+ return Promise.resolve(true);
106
+ }
107
+ }
108
+ }
109
+ return Promise.resolve(false);
110
+ };
90
111
  CustomMap.prototype.set = function (path, value) {
91
112
  var me = this;
113
+ if (!path) {
114
+ console.warn('Cannot set empty path for ', me);
115
+ return;
116
+ }
92
117
  var traversalPath = [].concat(path);
93
118
  var refs = me.value;
94
119
  var last = traversalPath.pop();
@@ -100,9 +125,8 @@ var CustomMap = /** @class */ (function (_super) {
100
125
  return sub.set(traversalPath.concat(last), value);
101
126
  }
102
127
  }
103
- else {
104
- throw new Error("Cannot set path ".concat(path.join('.')));
105
- }
128
+ console.warn("Cannot set path ".concat(path === null || path === void 0 ? void 0 : path.join('.')));
129
+ return;
106
130
  }
107
131
  if (value instanceof operation_1.FunctionOperationBase) {
108
132
  refs.set(last, value.fork(me));
@@ -140,12 +164,6 @@ var CustomMap = /** @class */ (function (_super) {
140
164
  };
141
165
  CustomMap.prototype.getCallable = function (path) {
142
166
  var me = this;
143
- if (path.length === 0) {
144
- return Promise.resolve({
145
- origin: me.value,
146
- context: me
147
- });
148
- }
149
167
  var traversalPath = [].concat(path);
150
168
  var refs = me.value;
151
169
  var current = traversalPath.shift();
@@ -169,10 +187,13 @@ var CustomMap = /** @class */ (function (_super) {
169
187
  });
170
188
  }
171
189
  else {
172
- throw new Error("Cannot get path ".concat(path.join('.')));
190
+ throw new Error("Cannot get callable path ".concat(path.join('.')));
173
191
  }
174
192
  }
175
- return Promise.resolve(null);
193
+ return Promise.resolve({
194
+ origin: null,
195
+ context: me
196
+ });
176
197
  };
177
198
  CustomMap.prototype.callMethod = function (method) {
178
199
  var _a;
@@ -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
  });
@@ -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.7",
3
+ "version": "0.5.8",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",