greybel-interpreter 2.6.16 → 2.7.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.
- package/dist/operations/call.js +3 -4
- package/dist/operations/function.js +2 -1
- package/dist/operations/resolve.js +12 -10
- package/dist/types/function.d.ts +5 -3
- package/dist/types/function.js +12 -4
- package/dist/types/list.d.ts +2 -1
- package/dist/types/list.js +6 -0
- package/dist/types/map.d.ts +2 -1
- package/dist/types/map.js +42 -0
- package/dist/types/number.d.ts +2 -1
- package/dist/types/number.js +6 -0
- package/dist/types/string.d.ts +2 -1
- package/dist/types/string.js +6 -0
- package/dist/types/with-intrinsics.d.ts +5 -0
- package/package.json +1 -1
package/dist/operations/call.js
CHANGED
|
@@ -13,7 +13,6 @@ exports.Call = void 0;
|
|
|
13
13
|
const default_1 = require("../types/default");
|
|
14
14
|
const function_1 = require("../types/function");
|
|
15
15
|
const create_resolve_1 = require("../utils/create-resolve");
|
|
16
|
-
const get_super_1 = require("../utils/get-super");
|
|
17
16
|
const operation_1 = require("./operation");
|
|
18
17
|
class Call extends operation_1.Operation {
|
|
19
18
|
constructor(item, target) {
|
|
@@ -44,11 +43,11 @@ class Call extends operation_1.Operation {
|
|
|
44
43
|
}
|
|
45
44
|
if (valueRef instanceof function_1.CustomFunction) {
|
|
46
45
|
const func = valueRef;
|
|
47
|
-
const next =
|
|
46
|
+
const next = func.getNextContext();
|
|
48
47
|
if (this.fnRef.path.isSuper() && ctx.functionState.context && next) {
|
|
49
|
-
return func.run(ctx.functionState.context, fnArgs, ctx
|
|
48
|
+
return func.run(ctx.functionState.context, fnArgs, ctx);
|
|
50
49
|
}
|
|
51
|
-
return func.run(resolveResult.handle, fnArgs, ctx
|
|
50
|
+
return func.run(resolveResult.handle, fnArgs, ctx);
|
|
52
51
|
}
|
|
53
52
|
return default_1.DefaultType.Void;
|
|
54
53
|
});
|
|
@@ -55,12 +55,13 @@ class FunctionOperation extends operation_1.Operation {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
handle(ctx, assignOuter = false) {
|
|
58
|
-
const func = new function_1.CustomFunction(ctx, 'anonymous', (fnCtx, self, args
|
|
58
|
+
const func = new function_1.CustomFunction(ctx, 'anonymous', (fnCtx, self, args) => __awaiter(this, void 0, void 0, function* () {
|
|
59
59
|
const functionState = new context_1.FunctionState();
|
|
60
60
|
functionState.context = self;
|
|
61
61
|
if (self instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
62
62
|
fnCtx.set(exports.SELF_PROPERTY, self);
|
|
63
63
|
}
|
|
64
|
+
const next = func.getNextContext();
|
|
64
65
|
if (next) {
|
|
65
66
|
fnCtx.set(exports.SUPER_PROPERTY, next);
|
|
66
67
|
functionState.super = next;
|
|
@@ -193,7 +193,8 @@ class Resolve extends operation_1.Operation {
|
|
|
193
193
|
traversedPath.toString() === function_1.SUPER_NAMESPACE &&
|
|
194
194
|
ctx.functionState.context &&
|
|
195
195
|
previous instanceof map_1.CustomMap) {
|
|
196
|
-
handle
|
|
196
|
+
handle.setNextContext(previous.getIsa());
|
|
197
|
+
handle = yield handle.run(ctx.functionState.context, [], ctx);
|
|
197
198
|
}
|
|
198
199
|
else {
|
|
199
200
|
handle = yield handle.run(previous || default_1.DefaultType.Void, [], ctx);
|
|
@@ -218,7 +219,6 @@ class Resolve extends operation_1.Operation {
|
|
|
218
219
|
});
|
|
219
220
|
}
|
|
220
221
|
handle(ctx, result = null, autoCall = true) {
|
|
221
|
-
var _a;
|
|
222
222
|
return __awaiter(this, void 0, void 0, function* () {
|
|
223
223
|
if (result === null) {
|
|
224
224
|
const exitObserver = ctx.processState.createExitObserver();
|
|
@@ -237,20 +237,22 @@ class Resolve extends operation_1.Operation {
|
|
|
237
237
|
}
|
|
238
238
|
if (result.handle instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
239
239
|
const customValueCtx = result.handle;
|
|
240
|
-
const
|
|
240
|
+
const { value: child, origin } = customValueCtx.getWithOrigin(result.path);
|
|
241
|
+
const next = (0, get_super_1.getSuper)(origin);
|
|
242
|
+
if (child instanceof function_1.CustomFunction) {
|
|
243
|
+
child.setNextContext(next);
|
|
244
|
+
}
|
|
241
245
|
if (this.path.isSuper() && customValueCtx instanceof map_1.CustomMap) {
|
|
242
|
-
|
|
243
|
-
if (autoCall && superChild instanceof function_1.CustomFunction) {
|
|
246
|
+
if (autoCall && child instanceof function_1.CustomFunction) {
|
|
244
247
|
if (ctx.functionState.context) {
|
|
245
|
-
return
|
|
248
|
+
return child.run(ctx.functionState.context, [], ctx);
|
|
246
249
|
}
|
|
247
|
-
return
|
|
250
|
+
return child.run(customValueCtx, [], ctx);
|
|
248
251
|
}
|
|
249
|
-
return
|
|
252
|
+
return child;
|
|
250
253
|
}
|
|
251
|
-
const child = customValueCtx.get(result.path);
|
|
252
254
|
if (autoCall && child instanceof function_1.CustomFunction) {
|
|
253
|
-
return child.run(customValueCtx, [], ctx
|
|
255
|
+
return child.run(customValueCtx, [], ctx);
|
|
254
256
|
}
|
|
255
257
|
return child;
|
|
256
258
|
}
|
package/dist/types/function.d.ts
CHANGED
|
@@ -2,9 +2,8 @@ import { OperationContext } from '../context';
|
|
|
2
2
|
import { Operation } from '../operations/operation';
|
|
3
3
|
import { ObjectValue } from '../utils/object-value';
|
|
4
4
|
import { CustomValue } from './base';
|
|
5
|
-
import { CustomMap } from './map';
|
|
6
5
|
export interface Callback {
|
|
7
|
-
(ctx: OperationContext, self: CustomValue, args: Map<string, CustomValue
|
|
6
|
+
(ctx: OperationContext, self: CustomValue, args: Map<string, CustomValue>): Promise<NonNullable<CustomValue>>;
|
|
8
7
|
}
|
|
9
8
|
export declare const DEFAULT_FUNCTION_NAME = "anonymous";
|
|
10
9
|
export declare const SELF_NAMESPACE = "self";
|
|
@@ -22,6 +21,7 @@ export declare class CustomFunction extends CustomValue {
|
|
|
22
21
|
readonly value: Callback;
|
|
23
22
|
readonly argumentDefs: Array<Argument>;
|
|
24
23
|
readonly assignOuter: boolean;
|
|
24
|
+
private _nextContext;
|
|
25
25
|
static createExternalAnonymous(callback: Callback): CustomFunction;
|
|
26
26
|
static createExternal(name: string, callback: Callback): CustomFunction;
|
|
27
27
|
static createExternalWithSelf(name: string, callback: Callback): CustomFunction;
|
|
@@ -35,6 +35,8 @@ export declare class CustomFunction extends CustomValue {
|
|
|
35
35
|
toString(): string;
|
|
36
36
|
toTruthy(): boolean;
|
|
37
37
|
instanceOf(v: CustomValue): boolean;
|
|
38
|
-
|
|
38
|
+
setNextContext(value: CustomValue): this;
|
|
39
|
+
getNextContext(): CustomValue;
|
|
40
|
+
run(self: CustomValue, args: Array<CustomValue>, callContext: OperationContext): Promise<CustomValue>;
|
|
39
41
|
hash(): number;
|
|
40
42
|
}
|
package/dist/types/function.js
CHANGED
|
@@ -18,7 +18,6 @@ const hash_1 = require("../utils/hash");
|
|
|
18
18
|
const object_value_1 = require("../utils/object-value");
|
|
19
19
|
const base_1 = require("./base");
|
|
20
20
|
const default_1 = require("./default");
|
|
21
|
-
const map_1 = require("./map");
|
|
22
21
|
const nil_1 = require("./nil");
|
|
23
22
|
const string_1 = require("./string");
|
|
24
23
|
exports.DEFAULT_FUNCTION_NAME = 'anonymous';
|
|
@@ -59,6 +58,7 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
59
58
|
this.value = callback;
|
|
60
59
|
this.argumentDefs = [];
|
|
61
60
|
this.assignOuter = assignOuter;
|
|
61
|
+
this._nextContext = null;
|
|
62
62
|
}
|
|
63
63
|
addArgument(name, defaultValue = default_1.DefaultType.Void) {
|
|
64
64
|
this.argumentDefs.push(new Argument(name, defaultValue));
|
|
@@ -106,7 +106,14 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
106
106
|
instanceOf(v) {
|
|
107
107
|
return v.value === CustomFunction.intrinsics;
|
|
108
108
|
}
|
|
109
|
-
|
|
109
|
+
setNextContext(value) {
|
|
110
|
+
this._nextContext = value;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
getNextContext() {
|
|
114
|
+
return this._nextContext;
|
|
115
|
+
}
|
|
116
|
+
run(self, args, callContext) {
|
|
110
117
|
var _a, _b, _c, _d;
|
|
111
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
119
|
if (args.length > this.argumentDefs.length) {
|
|
@@ -132,11 +139,12 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
132
139
|
argMap.set(item.name, (_d = args[argIndex - selfParam]) !== null && _d !== void 0 ? _d : (yield item.defaultValue.handle(fnCtx)));
|
|
133
140
|
}
|
|
134
141
|
const selfValue = hasSelf ? self : selfWithinArgs;
|
|
135
|
-
const isa = next !== null && next !== void 0 ? next : (self instanceof map_1.CustomMap ? self.getIsa() : null);
|
|
136
142
|
if (selfValue) {
|
|
137
143
|
argMap.set(exports.SELF_NAMESPACE, selfValue);
|
|
138
144
|
}
|
|
139
|
-
|
|
145
|
+
const result = yield this.value(fnCtx !== null && fnCtx !== void 0 ? fnCtx : callContext, selfValue, argMap);
|
|
146
|
+
this._nextContext = null;
|
|
147
|
+
return result;
|
|
140
148
|
});
|
|
141
149
|
}
|
|
142
150
|
hash() {
|
package/dist/types/list.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ObjectValue } from '../utils/object-value';
|
|
2
2
|
import { Path } from '../utils/path';
|
|
3
3
|
import { CustomValue } from './base';
|
|
4
|
-
import { CustomObject } from './with-intrinsics';
|
|
4
|
+
import { CustomObject, CustomValueWithIntrinsicsResult } from './with-intrinsics';
|
|
5
5
|
export declare class CustomListIterator implements Iterator<CustomValue> {
|
|
6
6
|
value: Array<CustomValue>;
|
|
7
7
|
index: number;
|
|
@@ -28,5 +28,6 @@ export declare class CustomList extends CustomObject {
|
|
|
28
28
|
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
29
29
|
set(path: Path<CustomValue> | CustomValue, newValue: CustomValue): void;
|
|
30
30
|
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
31
|
+
getWithOrigin(path: Path<CustomValue> | CustomValue): CustomValueWithIntrinsicsResult;
|
|
31
32
|
hash(recursionDepth?: number): number;
|
|
32
33
|
}
|
package/dist/types/list.js
CHANGED
|
@@ -157,6 +157,12 @@ class CustomList extends with_intrinsics_1.CustomObject {
|
|
|
157
157
|
}
|
|
158
158
|
throw new Error(`Unknown path in list ${path.toString()}.`);
|
|
159
159
|
}
|
|
160
|
+
getWithOrigin(path) {
|
|
161
|
+
return {
|
|
162
|
+
value: this.get(path),
|
|
163
|
+
origin: null
|
|
164
|
+
};
|
|
165
|
+
}
|
|
160
166
|
hash(recursionDepth = 0) {
|
|
161
167
|
let result = (0, hash_1.getHashCode)(this.value.length);
|
|
162
168
|
if (recursionDepth > 16)
|
package/dist/types/map.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ObjectValue } from '../utils/object-value';
|
|
|
2
2
|
import { Path } from '../utils/path';
|
|
3
3
|
import { CustomValue } from './base';
|
|
4
4
|
import { CustomString } from './string';
|
|
5
|
-
import { CustomObject } from './with-intrinsics';
|
|
5
|
+
import { CustomObject, CustomValueWithIntrinsicsResult } from './with-intrinsics';
|
|
6
6
|
export declare const CLASS_ID_PROPERTY: CustomString;
|
|
7
7
|
export declare const ISA_PROPERTY: CustomString;
|
|
8
8
|
export declare const CUSTOM_MAP_MAX_DEPTH = 2;
|
|
@@ -32,6 +32,7 @@ export declare class CustomMap extends CustomObject {
|
|
|
32
32
|
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
33
33
|
set(path: Path<CustomValue> | CustomValue, newValue: CustomValue): void;
|
|
34
34
|
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
35
|
+
getWithOrigin(path: Path<CustomValue> | CustomValue): CustomValueWithIntrinsicsResult;
|
|
35
36
|
createInstance(): CustomMap;
|
|
36
37
|
getIsa(): CustomMap | null;
|
|
37
38
|
hash(recursionDepth?: number): number;
|
package/dist/types/map.js
CHANGED
|
@@ -172,6 +172,48 @@ class CustomMap extends with_intrinsics_1.CustomObject {
|
|
|
172
172
|
}
|
|
173
173
|
throw new Error(`Unknown path in map ${path.toString()}.`);
|
|
174
174
|
}
|
|
175
|
+
getWithOrigin(path) {
|
|
176
|
+
if (path instanceof base_1.CustomValue) {
|
|
177
|
+
return this.getWithOrigin(new path_1.Path([path]));
|
|
178
|
+
}
|
|
179
|
+
const traversalPath = path.clone();
|
|
180
|
+
const current = traversalPath.next();
|
|
181
|
+
const isa = this.getIsa();
|
|
182
|
+
if (current !== null) {
|
|
183
|
+
if (this.value.has(current)) {
|
|
184
|
+
const sub = this.value.get(current);
|
|
185
|
+
if (traversalPath.count() > 0) {
|
|
186
|
+
if (sub instanceof CustomMap) {
|
|
187
|
+
return sub.getWithOrigin(traversalPath);
|
|
188
|
+
}
|
|
189
|
+
if (sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
190
|
+
return {
|
|
191
|
+
value: sub.get(traversalPath),
|
|
192
|
+
origin: this
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else if (traversalPath.count() === 0) {
|
|
197
|
+
return {
|
|
198
|
+
value: sub,
|
|
199
|
+
origin: this
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else if (isa === null || isa === void 0 ? void 0 : isa.has(current)) {
|
|
204
|
+
return isa.getWithOrigin(current);
|
|
205
|
+
}
|
|
206
|
+
else if (traversalPath.count() === 0 &&
|
|
207
|
+
CustomMap.getIntrinsics().has(current)) {
|
|
208
|
+
const intrinsics = CustomMap.getIntrinsics();
|
|
209
|
+
return {
|
|
210
|
+
value: intrinsics.get(current),
|
|
211
|
+
origin: null
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
throw new Error(`Unknown path in map ${path.toString()}.`);
|
|
216
|
+
}
|
|
175
217
|
createInstance() {
|
|
176
218
|
const newInstance = new CustomMap(new object_value_1.ObjectValue());
|
|
177
219
|
newInstance.value.set(exports.ISA_PROPERTY, this);
|
package/dist/types/number.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ObjectValue } from '../utils/object-value';
|
|
2
2
|
import { Path } from '../utils/path';
|
|
3
3
|
import { CustomValue } from './base';
|
|
4
|
-
import { CustomValueWithIntrinsics } from './with-intrinsics';
|
|
4
|
+
import { CustomValueWithIntrinsics, CustomValueWithIntrinsicsResult } from './with-intrinsics';
|
|
5
5
|
export declare class CustomNumberIterator implements Iterator<CustomValue> {
|
|
6
6
|
index: number;
|
|
7
7
|
next(): IteratorResult<CustomValue>;
|
|
@@ -22,6 +22,7 @@ export declare class CustomNumber extends CustomValueWithIntrinsics {
|
|
|
22
22
|
has(_path: Path<CustomValue> | CustomValue): boolean;
|
|
23
23
|
set(_path: Path<CustomValue> | CustomValue, _newValue: CustomValue): void;
|
|
24
24
|
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
25
|
+
getWithOrigin(path: Path<CustomValue> | CustomValue): CustomValueWithIntrinsicsResult;
|
|
25
26
|
hash(): number;
|
|
26
27
|
}
|
|
27
28
|
export declare const NegativeOne: CustomNumber;
|
package/dist/types/number.js
CHANGED
|
@@ -68,6 +68,12 @@ class CustomNumber extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
68
68
|
}
|
|
69
69
|
throw new Error(`Unknown path in number ${path.toString()}.`);
|
|
70
70
|
}
|
|
71
|
+
getWithOrigin(path) {
|
|
72
|
+
return {
|
|
73
|
+
value: this.get(path),
|
|
74
|
+
origin: null
|
|
75
|
+
};
|
|
76
|
+
}
|
|
71
77
|
hash() {
|
|
72
78
|
return (0, hash_1.getHashCode)(this.value);
|
|
73
79
|
}
|
package/dist/types/string.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ObjectValue } from '../utils/object-value';
|
|
2
2
|
import { Path } from '../utils/path';
|
|
3
3
|
import { CustomValue } from './base';
|
|
4
|
-
import { CustomValueWithIntrinsics } from './with-intrinsics';
|
|
4
|
+
import { CustomValueWithIntrinsics, CustomValueWithIntrinsicsResult } from './with-intrinsics';
|
|
5
5
|
export declare class CustomStringIterator implements Iterator<CustomValue> {
|
|
6
6
|
value: string;
|
|
7
7
|
index: number;
|
|
@@ -30,5 +30,6 @@ export declare class CustomString extends CustomValueWithIntrinsics {
|
|
|
30
30
|
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
31
31
|
set(_path: Path<CustomValue> | CustomValue, _newValue: CustomValue): void;
|
|
32
32
|
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
33
|
+
getWithOrigin(path: Path<CustomValue> | CustomValue): CustomValueWithIntrinsicsResult;
|
|
33
34
|
hash(): number;
|
|
34
35
|
}
|
package/dist/types/string.js
CHANGED
|
@@ -119,6 +119,12 @@ class CustomString extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
119
119
|
}
|
|
120
120
|
throw new Error(`Unknown path in string ${path.toString()}.`);
|
|
121
121
|
}
|
|
122
|
+
getWithOrigin(path) {
|
|
123
|
+
return {
|
|
124
|
+
value: this.get(path),
|
|
125
|
+
origin: null
|
|
126
|
+
};
|
|
127
|
+
}
|
|
122
128
|
hash() {
|
|
123
129
|
return (0, hash_1.getStringHashCode)(this.value);
|
|
124
130
|
}
|
|
@@ -2,10 +2,15 @@ import { ObjectValue } from '../utils/object-value';
|
|
|
2
2
|
import { Path } from '../utils/path';
|
|
3
3
|
import { CustomValue } from './base';
|
|
4
4
|
import { CustomFunction } from './function';
|
|
5
|
+
export type CustomValueWithIntrinsicsResult = {
|
|
6
|
+
value: CustomValue;
|
|
7
|
+
origin: CustomValueWithIntrinsics;
|
|
8
|
+
};
|
|
5
9
|
export declare abstract class CustomValueWithIntrinsics extends CustomValue {
|
|
6
10
|
abstract has(path: Path<CustomValue> | CustomValue): boolean;
|
|
7
11
|
abstract set(path: Path<CustomValue> | CustomValue, value: CustomValue): void;
|
|
8
12
|
abstract get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
13
|
+
abstract getWithOrigin(path: Path<CustomValue> | CustomValue): CustomValueWithIntrinsicsResult;
|
|
9
14
|
abstract [Symbol.iterator](): Iterator<CustomValue> & {
|
|
10
15
|
index: number;
|
|
11
16
|
};
|