greybel-interpreter 0.2.3 → 0.2.4

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
@@ -1,3 +1,4 @@
1
+ import CustomMap from './custom-types/map';
1
2
  import { Operation } from './types/operation';
2
3
  import { Expression } from './types/expression';
3
4
  import { Callable } from './types/custom-type';
@@ -16,12 +17,9 @@ export declare enum ContextState {
16
17
  TEMPORARY = "TEMPORARY",
17
18
  DEFAULT = "DEFAULT"
18
19
  }
19
- export declare class Scope {
20
+ export declare class Scope extends CustomMap {
20
21
  context: OperationContext;
21
- refs: Map<string, any>;
22
22
  constructor(context: OperationContext);
23
- valueOf(): Map<string, any>;
24
- extend(map?: Map<string, any>): Scope;
25
23
  set(path: string[], value: any): Promise<void>;
26
24
  get(path: string[]): Promise<any>;
27
25
  getCallable(path: string[]): Promise<Callable>;
@@ -71,12 +69,12 @@ export declare class OperationContext {
71
69
  cps: CPS | null;
72
70
  processState: OperationContextProcessState;
73
71
  constructor(options: OperationContextOptions);
74
- valueOf(): Map<string, any>;
72
+ valueOf(): CustomMap;
75
73
  extend(map: Map<string, any>): OperationContext;
76
- set(path: any[], value: any): Promise<OperationContext>;
77
- get(path: any[]): any;
74
+ set(path: any[], value: any): Promise<void>;
75
+ get(path: any[]): Promise<any>;
76
+ getCallable(path: string[]): Promise<Callable>;
78
77
  setMemory(key: string, value: any): OperationContext;
79
78
  getMemory(key: string): any;
80
- getCallable(path: string[]): Promise<Callable>;
81
79
  fork({ type, state, target }: OperationContextForkOptions): OperationContext;
82
80
  }
package/dist/context.js CHANGED
@@ -1,4 +1,19 @@
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
+ })();
2
17
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
18
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
19
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -65,11 +80,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
65
80
  };
66
81
  Object.defineProperty(exports, "__esModule", { value: true });
67
82
  exports.OperationContext = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
68
- var boolean_1 = __importDefault(require("./custom-types/boolean"));
69
- var number_1 = __importDefault(require("./custom-types/number"));
70
- var string_1 = __importDefault(require("./custom-types/string"));
71
- var nil_1 = __importDefault(require("./custom-types/nil"));
72
- var custom_type_1 = require("./types/custom-type");
83
+ var map_1 = __importDefault(require("./custom-types/map"));
73
84
  var greybel_core_1 = require("greybel-core");
74
85
  var ContextType;
75
86
  (function (ContextType) {
@@ -87,128 +98,158 @@ var ContextState;
87
98
  ContextState["TEMPORARY"] = "TEMPORARY";
88
99
  ContextState["DEFAULT"] = "DEFAULT";
89
100
  })(ContextState = exports.ContextState || (exports.ContextState = {}));
90
- var Scope = /** @class */ (function () {
101
+ var Scope = /** @class */ (function (_super) {
102
+ __extends(Scope, _super);
91
103
  function Scope(context) {
92
- var me = this;
93
- me.context = context;
94
- me.refs = new Map();
104
+ var _this = _super.call(this) || this;
105
+ _this.context = context;
106
+ return _this;
95
107
  }
96
- Scope.prototype.valueOf = function () {
97
- return this.refs;
98
- };
99
- Scope.prototype.extend = function (map) {
100
- if (map === void 0) { map = new Map(); }
101
- var me = this;
102
- me.refs = new Map(__spreadArray(__spreadArray([], __read(me.refs.entries()), false), __read(map.entries()), false));
103
- return me;
104
- };
105
108
  Scope.prototype.set = function (path, value) {
106
- return __awaiter(this, void 0, void 0, function () {
107
- var me, traversalPath, refs, last, current, origin;
108
- return __generator(this, function (_a) {
109
- me = this;
110
- traversalPath = [].concat(path);
111
- refs = me.refs;
112
- last = traversalPath.pop();
113
- current = traversalPath.shift();
114
- origin = refs;
115
- if (current != null) {
116
- if (origin.has(current)) {
117
- origin = origin.get(current);
118
- if (origin instanceof custom_type_1.CustomObjectType ||
119
- origin instanceof Scope) {
120
- return [2 /*return*/, origin.set(traversalPath.concat([last]), value)];
121
- }
122
- }
123
- else if (me.context.previous && !me.context.previous.isProtected) {
124
- me.context.previous.set(path, value);
125
- return [2 /*return*/];
126
- }
127
- else if (traversalPath.length > 0) {
128
- throw new Error("Cannot set path ".concat(path.join('.')));
129
- }
109
+ var me = this;
110
+ var traversalPath = [].concat(path);
111
+ var current = traversalPath.shift();
112
+ if (current != null) {
113
+ if (current === 'globals') {
114
+ if (me.context.type === ContextType.GLOBAL) {
115
+ return me.set(traversalPath, value);
130
116
  }
131
- if (origin &&
132
- !(origin instanceof boolean_1.default) &&
133
- !(origin instanceof string_1.default) &&
134
- !(origin instanceof number_1.default) &&
135
- !(origin instanceof nil_1.default)) {
136
- origin.set(last, value);
117
+ else if (me.context.previous && !me.context.previous.isProtected) {
118
+ return me.context.previous.set(traversalPath, value);
137
119
  }
138
120
  else {
139
- throw new Error("Cannot set path ".concat(path.join('.')));
121
+ throw new Error("Cannot set globals scope for ".concat(path.join('.')));
140
122
  }
141
- return [2 /*return*/];
142
- });
143
- });
123
+ }
124
+ else if (current === 'locals') {
125
+ if (me.context.type === ContextType.GLOBAL ||
126
+ me.context.type === ContextType.FUNCTION) {
127
+ return me.set(traversalPath, value);
128
+ }
129
+ else if (me.context.previous && !me.context.previous.isProtected) {
130
+ return me.context.previous.set(traversalPath, value);
131
+ }
132
+ else {
133
+ throw new Error("Cannot set locals scope for ".concat(path.join('.')));
134
+ }
135
+ }
136
+ else {
137
+ return _super.prototype.set.call(this, path, value);
138
+ }
139
+ }
144
140
  };
145
141
  Scope.prototype.get = function (path) {
146
- return __awaiter(this, void 0, void 0, function () {
147
- var me, traversalPath, refs, current, context, origin;
148
- return __generator(this, function (_a) {
149
- me = this;
150
- traversalPath = [].concat(path);
151
- refs = me.refs;
152
- current = traversalPath.shift();
153
- origin = refs;
154
- if (current != null) {
155
- if (origin.has(current)) {
156
- context = origin;
157
- origin = origin.get(current);
158
- if (traversalPath.length > 0 &&
159
- (origin instanceof custom_type_1.CustomObjectType ||
160
- origin instanceof Scope)) {
161
- return [2 /*return*/, origin.get(traversalPath)];
162
- }
163
- }
164
- else if (me.context.previous) {
165
- return [2 /*return*/, me.context.previous.get(path)];
142
+ var me = this;
143
+ var traversalPath = [].concat(path);
144
+ var current = traversalPath.shift();
145
+ if (current != null) {
146
+ if (me.value.has(current)) {
147
+ return _super.prototype.get.call(this, path);
148
+ }
149
+ else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
150
+ return map_1.default.intrinsics.get(current).bind(null, me);
151
+ }
152
+ else if (current === 'globals') {
153
+ if (me.context.type === ContextType.GLOBAL) {
154
+ if (path.length === 1) {
155
+ return Promise.resolve(me);
166
156
  }
167
- else {
168
- throw new Error("Cannot get path ".concat(path.join('.')));
157
+ return me.get(traversalPath);
158
+ }
159
+ else if (me.context.previous) {
160
+ return me.context.previous.get(traversalPath);
161
+ }
162
+ else {
163
+ throw new Error("Cannot find globals scope for ".concat(path.join('.')));
164
+ }
165
+ }
166
+ else if (current === 'locals') {
167
+ if (me.context.type === ContextType.GLOBAL ||
168
+ me.context.type === ContextType.FUNCTION) {
169
+ if (path.length === 1) {
170
+ return Promise.resolve(me);
169
171
  }
172
+ return me.get(traversalPath);
173
+ }
174
+ else if (me.context.previous) {
175
+ return me.context.previous.get(traversalPath);
170
176
  }
171
177
  else {
172
- return [2 /*return*/, null];
178
+ throw new Error("Cannot find locals scope for ".concat(path.join('.')));
173
179
  }
174
- return [2 /*return*/, origin];
175
- });
176
- });
180
+ }
181
+ else if (me.context.previous) {
182
+ return me.context.previous.get(path);
183
+ }
184
+ else {
185
+ throw new Error("Cannot get path ".concat(path.join('.')));
186
+ }
187
+ }
188
+ return null;
177
189
  };
178
190
  Scope.prototype.getCallable = function (path) {
179
- return __awaiter(this, void 0, void 0, function () {
180
- var me, traversalPath, refs, current, origin, context;
181
- return __generator(this, function (_a) {
182
- me = this;
183
- traversalPath = [].concat(path);
184
- refs = me.refs;
185
- current = traversalPath.shift();
186
- origin = refs;
187
- if (current != null) {
188
- if (origin.has(current)) {
189
- context = origin;
190
- origin = origin.get(current);
191
- if (origin instanceof custom_type_1.CustomObjectType ||
192
- origin instanceof Scope) {
193
- return [2 /*return*/, origin.getCallable(traversalPath)];
194
- }
195
- }
196
- else if (me.context.previous) {
197
- return [2 /*return*/, me.context.previous.getCallable(path)];
191
+ var me = this;
192
+ var traversalPath = [].concat(path);
193
+ var current = traversalPath.shift();
194
+ if (current != null) {
195
+ if (me.value.has(current)) {
196
+ return _super.prototype.getCallable.call(this, path);
197
+ }
198
+ else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
199
+ return Promise.resolve({
200
+ origin: map_1.default.intrinsics.get(current).bind(null, me),
201
+ context: me
202
+ });
203
+ }
204
+ else if (current === 'globals') {
205
+ if (me.context.type === ContextType.GLOBAL) {
206
+ if (path.length === 1) {
207
+ return Promise.resolve({
208
+ origin: me,
209
+ context: null
210
+ });
198
211
  }
199
- else {
200
- throw new Error("Cannot get path ".concat(path.join('.')));
212
+ return me.getCallable(traversalPath);
213
+ }
214
+ else if (me.context.previous) {
215
+ return me.context.previous.getCallable(traversalPath);
216
+ }
217
+ else {
218
+ throw new Error("Cannot find callable in globals scope for ".concat(path.join('.')));
219
+ }
220
+ }
221
+ else if (current === 'locals') {
222
+ if (me.context.type === ContextType.GLOBAL ||
223
+ me.context.type === ContextType.FUNCTION) {
224
+ if (path.length === 1) {
225
+ return Promise.resolve({
226
+ origin: me,
227
+ context: null
228
+ });
201
229
  }
230
+ return me.getCallable(traversalPath);
202
231
  }
203
- return [2 /*return*/, {
204
- origin: origin,
205
- context: context
206
- }];
207
- });
232
+ else if (me.context.previous) {
233
+ return me.context.previous.getCallable(traversalPath);
234
+ }
235
+ else {
236
+ throw new Error("Cannot find callable in locals scope for ".concat(path.join('.')));
237
+ }
238
+ }
239
+ else if (me.context.previous) {
240
+ return me.context.previous.getCallable(path);
241
+ }
242
+ else {
243
+ throw new Error("Cannot get callable path ".concat(path.join('.')));
244
+ }
245
+ }
246
+ return Promise.resolve({
247
+ origin: me,
248
+ context: null
208
249
  });
209
250
  };
210
251
  return Scope;
211
- }());
252
+ }(map_1.default));
212
253
  exports.Scope = Scope;
213
254
  var Debugger = /** @class */ (function () {
214
255
  function Debugger() {
@@ -340,25 +381,13 @@ var OperationContext = /** @class */ (function () {
340
381
  };
341
382
  OperationContext.prototype.set = function (path, value) {
342
383
  var _a;
343
- return __awaiter(this, void 0, void 0, function () {
344
- var me;
345
- return __generator(this, function (_b) {
346
- switch (_b.label) {
347
- case 0:
348
- me = this;
349
- if (!(me.state === ContextState.TEMPORARY)) return [3 /*break*/, 2];
350
- return [4 /*yield*/, ((_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value))];
351
- case 1:
352
- _b.sent();
353
- return [3 /*break*/, 4];
354
- case 2: return [4 /*yield*/, me.scope.set(path, value)];
355
- case 3:
356
- _b.sent();
357
- _b.label = 4;
358
- case 4: return [2 /*return*/, me];
359
- }
360
- });
361
- });
384
+ var me = this;
385
+ if (me.state === ContextState.TEMPORARY) {
386
+ return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
387
+ }
388
+ else {
389
+ return me.scope.set(path, value);
390
+ }
362
391
  };
363
392
  OperationContext.prototype.get = function (path) {
364
393
  var _a;
@@ -368,6 +397,14 @@ var OperationContext = /** @class */ (function () {
368
397
  }
369
398
  return me.scope.get(path);
370
399
  };
400
+ OperationContext.prototype.getCallable = function (path) {
401
+ var _a;
402
+ var me = this;
403
+ if (me.state === ContextState.TEMPORARY) {
404
+ return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.getCallable(path);
405
+ }
406
+ return me.scope.getCallable(path);
407
+ };
371
408
  OperationContext.prototype.setMemory = function (key, value) {
372
409
  var me = this;
373
410
  me.memory.set(key, value);
@@ -377,14 +414,6 @@ var OperationContext = /** @class */ (function () {
377
414
  var me = this;
378
415
  return me.memory.get(key);
379
416
  };
380
- OperationContext.prototype.getCallable = function (path) {
381
- var _a;
382
- var me = this;
383
- if (me.state === ContextState.TEMPORARY) {
384
- return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.getCallable(path);
385
- }
386
- return me.scope.getCallable(path);
387
- };
388
417
  OperationContext.prototype.fork = function (_a) {
389
418
  var type = _a.type, state = _a.state, target = _a.target;
390
419
  var me = this;
@@ -397,9 +426,6 @@ var OperationContext = /** @class */ (function () {
397
426
  cps: me.cps,
398
427
  processState: me.processState
399
428
  });
400
- if (me.type === ContextType.FUNCTION || me.type === ContextType.GLOBAL) {
401
- opc.scope.refs.set('locals', opc.scope);
402
- }
403
429
  if (type !== ContextType.FUNCTION) {
404
430
  if (type !== ContextType.LOOP) {
405
431
  opc.setMemory('loopContext', me.getMemory('loopContext'));
@@ -13,14 +13,14 @@ export default class CustomMap extends CustomObjectType implements Iterable<Cust
13
13
  static intrinsics: Map<string, Function>;
14
14
  value: Map<string, any>;
15
15
  isInstance: boolean;
16
- constructor(value: Map<string, any>);
16
+ constructor(value?: Map<string, any>);
17
17
  [Symbol.iterator](): CustomMapIterator;
18
18
  extend(value: Map<string, any>): CustomMap;
19
19
  set(path: string[], value: any): Promise<void>;
20
20
  get(path: string[]): Promise<any>;
21
21
  getCallable(path: string[]): Promise<Callable>;
22
22
  callMethod(method: string[], ...args: any[]): any;
23
- createInstancefunction(): CustomMap;
23
+ createInstance(): CustomMap;
24
24
  getType(): string;
25
25
  valueOf(): CustomMap | null;
26
26
  toString(): string;
@@ -14,42 +14,6 @@ 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
- };
53
17
  var __read = (this && this.__read) || function (o, n) {
54
18
  var m = typeof Symbol === "function" && o[Symbol.iterator];
55
19
  if (!m) return o;
@@ -111,7 +75,7 @@ var CustomMap = /** @class */ (function (_super) {
111
75
  function CustomMap(value) {
112
76
  var _this = _super.call(this) || this;
113
77
  var me = _this;
114
- me.value = new Map(__spreadArray([], __read(value.entries()), false));
78
+ me.value = value || new Map();
115
79
  me.isInstance = false;
116
80
  return _this;
117
81
  }
@@ -124,107 +88,92 @@ var CustomMap = /** @class */ (function (_super) {
124
88
  return me;
125
89
  };
126
90
  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('.')));
91
+ var me = this;
92
+ var traversalPath = [].concat(path);
93
+ var refs = me.value;
94
+ var last = traversalPath.pop();
95
+ var current = traversalPath.shift();
96
+ var origin = refs;
97
+ if (current != null) {
98
+ if (origin.has(current)) {
99
+ origin = origin.get(current);
100
+ if (origin instanceof custom_type_1.CustomObjectType) {
101
+ return origin.set(traversalPath.concat(last), value);
157
102
  }
158
- return [2 /*return*/];
159
- });
160
- });
103
+ }
104
+ else {
105
+ throw new Error("Cannot set path ".concat(path.join('.')));
106
+ }
107
+ }
108
+ if (origin) {
109
+ if (value instanceof operation_1.FunctionOperationBase) {
110
+ origin.set(last, value.fork(me));
111
+ }
112
+ else {
113
+ origin.set(last, value);
114
+ }
115
+ }
116
+ else {
117
+ throw new Error("Cannot set path ".concat(path.join('.')));
118
+ }
161
119
  };
162
120
  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).bind(null, me)];
184
- }
185
- else {
186
- throw new Error("Cannot get path ".concat(path.join('.')));
187
- }
188
- }
189
- else {
190
- return [2 /*return*/, null];
121
+ var me = this;
122
+ if (path.length === 0) {
123
+ return Promise.resolve(me);
124
+ }
125
+ var traversalPath = [].concat(path);
126
+ var refs = me.value;
127
+ var current = traversalPath.shift();
128
+ var currentValue = current.valueOf();
129
+ var origin = refs;
130
+ if (currentValue != null) {
131
+ if (origin.has(currentValue)) {
132
+ origin = origin.get(currentValue);
133
+ if (traversalPath.length > 0 && origin instanceof custom_type_1.CustomObjectType) {
134
+ return origin.get(traversalPath);
191
135
  }
192
- return [2 /*return*/, origin];
193
- });
194
- });
136
+ }
137
+ else if (path.length === 1 && CustomMap.intrinsics.has(currentValue)) {
138
+ return Promise.resolve(CustomMap.intrinsics.get(currentValue).bind(null, me));
139
+ }
140
+ else {
141
+ throw new Error("Cannot get path ".concat(path.join('.')));
142
+ }
143
+ }
144
+ else {
145
+ return null;
146
+ }
147
+ return Promise.resolve(origin);
195
148
  };
196
149
  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).bind(null, me),
216
- context: me
217
- }];
218
- }
219
- else {
220
- throw new Error("Cannot get path ".concat(path.join('.')));
221
- }
150
+ var me = this;
151
+ var traversalPath = [].concat(path);
152
+ var refs = me.value;
153
+ var current = traversalPath.shift();
154
+ var origin = refs;
155
+ var context;
156
+ if (current != null) {
157
+ if (origin.has(current)) {
158
+ context = origin;
159
+ origin = origin.get(current);
160
+ if (origin instanceof custom_type_1.CustomObjectType) {
161
+ return origin.getCallable(traversalPath);
222
162
  }
223
- return [2 /*return*/, {
224
- origin: origin,
225
- context: context
226
- }];
227
- });
163
+ }
164
+ else if (path.length === 1 && CustomMap.intrinsics.has(current)) {
165
+ return Promise.resolve({
166
+ origin: CustomMap.intrinsics.get(current).bind(null, me),
167
+ context: me
168
+ });
169
+ }
170
+ else {
171
+ throw new Error("Cannot get path ".concat(path.join('.')));
172
+ }
173
+ }
174
+ return Promise.resolve({
175
+ origin: origin,
176
+ context: context
228
177
  });
229
178
  };
230
179
  CustomMap.prototype.callMethod = function (method) {
@@ -249,7 +198,7 @@ var CustomMap = /** @class */ (function (_super) {
249
198
  }
250
199
  return CustomMap.intrinsics.get(key).apply(void 0, __spreadArray([me], __read(args), false));
251
200
  };
252
- CustomMap.prototype.createInstancefunction = function () {
201
+ CustomMap.prototype.createInstance = function () {
253
202
  var me = this;
254
203
  var value = new Map();
255
204
  var newInstance = new CustomMap(value);
@@ -262,8 +211,9 @@ var CustomMap = /** @class */ (function (_super) {
262
211
  return newInstance;
263
212
  };
264
213
  CustomMap.prototype.getType = function () {
214
+ var _a;
265
215
  var me = this;
266
- return me.value.get('classID') || 'map';
216
+ return ((_a = me.value.get('classID')) === null || _a === void 0 ? void 0 : _a.toString()) || 'map';
267
217
  };
268
218
  CustomMap.prototype.valueOf = function () {
269
219
  var me = this;
@@ -99,7 +99,9 @@ var Interpreter = /** @class */ (function () {
99
99
  topOperation = new (_b.apply(top_1.default, _c.concat([(_d.body = _e.sent(),
100
100
  _d)])))();
101
101
  mainContext.extend(me.api);
102
- mainContext.scope.refs.set('params', (0, typer_1.cast)(me.params));
102
+ return [4 /*yield*/, mainContext.set(['params'], (0, typer_1.cast)(me.params))];
103
+ case 4:
104
+ _e.sent();
103
105
  me.context = mainContext;
104
106
  return [2 /*return*/, topOperation.run(mainContext)
105
107
  .catch(function (err) {
@@ -73,7 +73,6 @@ var TopOperation = /** @class */ (function (_super) {
73
73
  type: context_1.ContextType.GLOBAL,
74
74
  state: context_1.ContextState.DEFAULT
75
75
  });
76
- opc.scope.refs.set('globals', opc.scope);
77
76
  return [4 /*yield*/, me.body.run(opc)];
78
77
  case 1:
79
78
  _a.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",