greybel-interpreter 2.2.16 → 2.2.17

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.
@@ -42,7 +42,7 @@ class Call extends operation_1.Operation {
42
42
  if (this.fnRef.path.isSuper() &&
43
43
  ctx.functionState.context &&
44
44
  resolveResult.handle instanceof map_1.CustomMap) {
45
- return func.run(ctx.functionState.context, fnArgs, ctx, resolveResult.handle.isa);
45
+ return func.run(ctx.functionState.context, fnArgs, ctx, resolveResult.handle.getIsa());
46
46
  }
47
47
  return func.run(resolveResult.handle, fnArgs, ctx);
48
48
  }
@@ -156,6 +156,9 @@ class Resolve extends operation_1.Operation {
156
156
  const maxIndex = this.path.count();
157
157
  const lastIndex = maxIndex - 1;
158
158
  for (let index = 0; index < maxIndex; index++) {
159
+ if (ctx.isExit()) {
160
+ return null;
161
+ }
159
162
  const current = this.path.at(index);
160
163
  if (current instanceof OperationSegment) {
161
164
  const opSegment = current;
@@ -184,7 +187,7 @@ class Resolve extends operation_1.Operation {
184
187
  traversedPath.toString() === function_1.SUPER_NAMESPACE &&
185
188
  ctx.functionState.context &&
186
189
  previous instanceof map_1.CustomMap) {
187
- handle = yield handle.run(ctx.functionState.context, [], ctx, previous.isa);
190
+ handle = yield handle.run(ctx.functionState.context, [], ctx, previous.getIsa());
188
191
  }
189
192
  else {
190
193
  handle = yield handle.run(previous || default_1.DefaultType.Void, [], ctx);
@@ -208,9 +211,13 @@ class Resolve extends operation_1.Operation {
208
211
  });
209
212
  }
210
213
  handle(ctx, result = null, autoCall = true) {
214
+ var _a;
211
215
  return __awaiter(this, void 0, void 0, function* () {
212
216
  if (result === null) {
213
217
  result = yield this.getResult(ctx);
218
+ if (result === null && ctx.isExit()) {
219
+ return default_1.DefaultType.Void;
220
+ }
214
221
  }
215
222
  if (!(result.handle instanceof ResolveNil)) {
216
223
  if (result.path.count() === 0) {
@@ -222,10 +229,10 @@ class Resolve extends operation_1.Operation {
222
229
  if (result.handle instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
223
230
  const customValueCtx = result.handle;
224
231
  if (this.path.isSuper() && customValueCtx instanceof map_1.CustomMap) {
225
- const superChild = customValueCtx.isa.get(result.path);
232
+ const superChild = (_a = customValueCtx.getIsa()) === null || _a === void 0 ? void 0 : _a.get(result.path);
226
233
  if (autoCall && superChild instanceof function_1.CustomFunction) {
227
234
  if (ctx.functionState.context) {
228
- return superChild.run(ctx.functionState.context, [], ctx, customValueCtx.isa);
235
+ return superChild.run(ctx.functionState.context, [], ctx, customValueCtx.getIsa());
229
236
  }
230
237
  return superChild.run(customValueCtx, [], ctx);
231
238
  }
@@ -136,7 +136,7 @@ class CustomFunction extends base_1.CustomValue {
136
136
  if (!isSelfNull) {
137
137
  argMap.set(exports.SELF_NAMESPACE, self);
138
138
  }
139
- const isa = next !== null && next !== void 0 ? next : (self instanceof map_1.CustomMap ? self.isa : null);
139
+ const isa = next !== null && next !== void 0 ? next : (self instanceof map_1.CustomMap ? self.getIsa() : null);
140
140
  return this.value(fnCtx !== null && fnCtx !== void 0 ? fnCtx : callContext, self, argMap, isa);
141
141
  });
142
142
  }
@@ -16,10 +16,9 @@ export declare class CustomMapIterator implements Iterator<CustomValue> {
16
16
  export declare class CustomMap extends CustomObject {
17
17
  static readonly intrinsics: ObjectValue;
18
18
  value: ObjectValue;
19
- readonly isa: CustomMap | null;
20
19
  private isInstance;
21
20
  static createWithInitialValue(value: ObjectValue): CustomMap;
22
- constructor(value?: ObjectValue, isa?: CustomMap);
21
+ constructor(value?: ObjectValue);
23
22
  getCustomType(): string;
24
23
  toJSON(depth?: number): string;
25
24
  toString(depth?: number): string;
@@ -34,4 +33,5 @@ export declare class CustomMap extends CustomObject {
34
33
  set(path: Path<CustomValue> | CustomValue, newValue: CustomValue): void;
35
34
  get(path: Path<CustomValue> | CustomValue): CustomValue;
36
35
  createInstance(): CustomMap;
36
+ getIsa(): CustomMap | null;
37
37
  }
package/dist/types/map.js CHANGED
@@ -43,11 +43,10 @@ class CustomMap extends with_intrinsics_1.CustomObject {
43
43
  map.value = value;
44
44
  return map;
45
45
  }
46
- constructor(value, isa = null) {
46
+ constructor(value) {
47
47
  super();
48
48
  this.isInstance = false;
49
49
  this.value = new object_value_1.ObjectValue(value);
50
- this.isa = isa;
51
50
  }
52
51
  getCustomType() {
53
52
  if (this.value.has(exports.CLASS_ID_PROPERTY)) {
@@ -63,9 +62,6 @@ class CustomMap extends with_intrinsics_1.CustomObject {
63
62
  if (exports.CUSTOM_MAP_MAX_DEPTH < depth) {
64
63
  return exports.CUSTOM_MAP_MAX_DEPTH_VALUE;
65
64
  }
66
- if (this.isa) {
67
- fields.push(`${exports.ISA_PROPERTY.toJSON()}:${this.isa.toJSON(depth + 1)}`);
68
- }
69
65
  for (const [key, value] of this.value.entries()) {
70
66
  fields.push(`${key instanceof CustomMap ? key.toJSON(depth + 1) : key.toJSON(depth)}:${value instanceof CustomMap
71
67
  ? value.toJSON(depth + 1)
@@ -88,7 +84,7 @@ class CustomMap extends with_intrinsics_1.CustomObject {
88
84
  instanceOf(v) {
89
85
  if (v instanceof CustomMap) {
90
86
  let current = this;
91
- while ((current = current.isa)) {
87
+ while ((current = current.getIsa())) {
92
88
  if (current === v) {
93
89
  return true;
94
90
  }
@@ -122,7 +118,8 @@ class CustomMap extends with_intrinsics_1.CustomObject {
122
118
  }
123
119
  return traversalPath.count() === 0;
124
120
  }
125
- return this.isa ? this.isa.has(current) : false;
121
+ const isa = this.getIsa();
122
+ return isa ? isa.has(current) : false;
126
123
  }
127
124
  return false;
128
125
  }
@@ -146,12 +143,12 @@ class CustomMap extends with_intrinsics_1.CustomObject {
146
143
  this.value.set(last, newValue);
147
144
  }
148
145
  get(path) {
149
- var _a, _b;
150
146
  if (path instanceof base_1.CustomValue) {
151
147
  return this.get(new path_1.Path([path]));
152
148
  }
153
149
  const traversalPath = path.clone();
154
150
  const current = traversalPath.next();
151
+ const isa = this.getIsa();
155
152
  if (current !== null) {
156
153
  if (this.value.has(current)) {
157
154
  const sub = this.value.get(current);
@@ -164,19 +161,8 @@ class CustomMap extends with_intrinsics_1.CustomObject {
164
161
  return sub;
165
162
  }
166
163
  }
167
- else if ((_a = this.isa) === null || _a === void 0 ? void 0 : _a.has(current)) {
168
- return this.isa.get(current);
169
- }
170
- else if (current.toString() === exports.ISA_PROPERTY.toString()) {
171
- if (path.count() === 1) {
172
- return this.isa;
173
- }
174
- else {
175
- const ahead = traversalPath.next();
176
- if ((_b = this.isa) === null || _b === void 0 ? void 0 : _b.has(ahead)) {
177
- return this.isa.get(ahead);
178
- }
179
- }
164
+ else if (isa === null || isa === void 0 ? void 0 : isa.has(current)) {
165
+ return isa.get(current);
180
166
  }
181
167
  else if (path.count() === 1 && CustomMap.getIntrinsics().has(current)) {
182
168
  return CustomMap.getIntrinsics().get(current);
@@ -185,10 +171,15 @@ class CustomMap extends with_intrinsics_1.CustomObject {
185
171
  throw new Error(`Unknown path in map ${path.toString()}.`);
186
172
  }
187
173
  createInstance() {
188
- const newInstance = new CustomMap(new object_value_1.ObjectValue(), this);
174
+ const newInstance = new CustomMap(new object_value_1.ObjectValue());
175
+ newInstance.value.set(exports.ISA_PROPERTY, this);
189
176
  newInstance.isInstance = true;
190
177
  return newInstance;
191
178
  }
179
+ getIsa() {
180
+ const isa = this.value.get(exports.ISA_PROPERTY);
181
+ return isa instanceof CustomMap ? isa : null;
182
+ }
192
183
  }
193
184
  CustomMap.intrinsics = new object_value_1.ObjectValue();
194
185
  exports.CustomMap = CustomMap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "2.2.16",
3
+ "version": "2.2.17",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",