greybel-interpreter 2.2.15 → 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
  }
@@ -29,31 +29,27 @@ class FunctionOperation extends operation_1.Operation {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
30
  const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
31
31
  this.block = new block_1.Block(this.item, stack);
32
- this.args = [];
33
- const defers = this.item.parameters.map((child) => __awaiter(this, void 0, void 0, function* () {
32
+ this.args = yield Promise.all(this.item.parameters.map((child) => __awaiter(this, void 0, void 0, function* () {
34
33
  switch (child.type) {
35
34
  case greyscript_core_1.ASTType.AssignmentStatement: {
36
35
  const assignStatement = child;
37
36
  const assignKey = assignStatement.variable;
38
- this.args.push({
37
+ return {
39
38
  name: assignKey.name,
40
39
  op: yield visit(assignStatement.init)
41
- });
42
- break;
40
+ };
43
41
  }
44
42
  case greyscript_core_1.ASTType.Identifier: {
45
43
  const identifierKey = child;
46
- this.args.push({
44
+ return {
47
45
  name: identifierKey.name,
48
46
  op: new reference_1.Reference(default_1.DefaultType.Void)
49
- });
50
- break;
47
+ };
51
48
  }
52
49
  default:
53
50
  throw new Error('Unexpected operation in arguments.');
54
51
  }
55
- }));
56
- yield Promise.all(defers);
52
+ })));
57
53
  return this;
58
54
  });
59
55
  }
@@ -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
  }
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CustomFunction = exports.Argument = exports.SUPER_NAMESPACE = exports.SELF_NAMESPACE = exports.DEFAULT_FUNCTION_NAME = void 0;
13
13
  const context_1 = require("../context");
14
+ const literal_1 = require("../operations/literal");
14
15
  const operation_1 = require("../operations/operation");
15
16
  const reference_1 = require("../operations/reference");
16
17
  const object_value_1 = require("../utils/object-value");
@@ -18,6 +19,7 @@ const base_1 = require("./base");
18
19
  const default_1 = require("./default");
19
20
  const map_1 = require("./map");
20
21
  const nil_1 = require("./nil");
22
+ const string_1 = require("./string");
21
23
  exports.DEFAULT_FUNCTION_NAME = 'anonymous';
22
24
  exports.SELF_NAMESPACE = 'self';
23
25
  exports.SUPER_NAMESPACE = 'super';
@@ -76,7 +78,23 @@ class CustomFunction extends base_1.CustomValue {
76
78
  return this.toString();
77
79
  }
78
80
  toString() {
79
- const args = this.argumentDefs.map((item) => item.name);
81
+ let refs = 1;
82
+ const args = this.argumentDefs.map((item) => {
83
+ if (item.defaultValue instanceof literal_1.Literal) {
84
+ const value = item.defaultValue.value;
85
+ if (value instanceof nil_1.CustomNil) {
86
+ return item.name;
87
+ }
88
+ else if (value instanceof string_1.CustomString) {
89
+ return `${item.name}="${value.value}"`;
90
+ }
91
+ return `${item.name}=${value.value}`;
92
+ }
93
+ else if (item.defaultValue.item != null) {
94
+ return `${item.name}=_${refs++}`;
95
+ }
96
+ return item.name;
97
+ });
80
98
  return `FUNCTION(${args.join(', ')})`;
81
99
  }
82
100
  toTruthy() {
@@ -118,7 +136,7 @@ class CustomFunction extends base_1.CustomValue {
118
136
  if (!isSelfNull) {
119
137
  argMap.set(exports.SELF_NAMESPACE, self);
120
138
  }
121
- 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);
122
140
  return this.value(fnCtx !== null && fnCtx !== void 0 ? fnCtx : callContext, self, argMap, isa);
123
141
  });
124
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.15",
3
+ "version": "2.2.17",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",