greybel-interpreter 3.0.4 → 3.1.1
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/types.d.ts +8 -0
- package/dist/context/types.js +2 -0
- package/dist/context.d.ts +17 -5
- package/dist/context.js +47 -28
- package/dist/cps.js +6 -5
- package/dist/handler/output.d.ts +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/interpreter.d.ts +10 -3
- package/dist/interpreter.js +51 -46
- package/dist/operations/assign-globals.d.ts +11 -0
- package/dist/operations/assign-globals.js +31 -0
- package/dist/operations/assign-locals.d.ts +11 -0
- package/dist/operations/assign-locals.js +31 -0
- package/dist/operations/assign-outer.d.ts +11 -0
- package/dist/operations/assign-outer.js +31 -0
- package/dist/operations/assign-self.d.ts +11 -0
- package/dist/operations/assign-self.js +41 -0
- package/dist/operations/assign.js +16 -3
- package/dist/operations/block.js +3 -1
- package/dist/operations/call.js +16 -8
- package/dist/operations/chunk.js +0 -2
- package/dist/operations/evaluate.js +1 -1
- package/dist/operations/for.js +5 -1
- package/dist/operations/function-reference.js +6 -3
- package/dist/operations/function.d.ts +1 -1
- package/dist/operations/function.js +10 -6
- package/dist/operations/if-statement.js +5 -0
- package/dist/operations/import.js +1 -1
- package/dist/operations/reference-globals.d.ts +7 -0
- package/dist/operations/reference-globals.js +13 -0
- package/dist/operations/reference-locals.d.ts +7 -0
- package/dist/operations/reference-locals.js +13 -0
- package/dist/operations/reference-outer.d.ts +7 -0
- package/dist/operations/reference-outer.js +13 -0
- package/dist/operations/reference-self.d.ts +7 -0
- package/dist/operations/reference-self.js +13 -0
- package/dist/operations/resolve-globals.d.ts +5 -0
- package/dist/operations/resolve-globals.js +24 -0
- package/dist/operations/resolve-locals.d.ts +5 -0
- package/dist/operations/resolve-locals.js +24 -0
- package/dist/operations/resolve-outer.d.ts +5 -0
- package/dist/operations/resolve-outer.js +24 -0
- package/dist/operations/resolve-self.d.ts +5 -0
- package/dist/operations/resolve-self.js +24 -0
- package/dist/operations/resolve.d.ts +1 -1
- package/dist/operations/resolve.js +30 -18
- package/dist/operations/while.js +5 -1
- package/dist/types/base.d.ts +3 -1
- package/dist/types/function.d.ts +12 -6
- package/dist/types/function.js +47 -33
- package/dist/types/list.d.ts +6 -3
- package/dist/types/list.js +26 -7
- package/dist/types/map.d.ts +6 -3
- package/dist/types/map.js +64 -8
- package/dist/types/nil.d.ts +1 -0
- package/dist/types/nil.js +3 -0
- package/dist/types/number.d.ts +6 -3
- package/dist/types/number.js +20 -8
- package/dist/types/string.d.ts +6 -3
- package/dist/types/string.js +20 -9
- package/dist/types/with-intrinsics.d.ts +9 -1
- package/dist/types/with-intrinsics.js +6 -0
- package/dist/utils/create-assign.d.ts +3 -0
- package/dist/utils/create-assign.js +25 -0
- package/dist/utils/create-resolve.d.ts +5 -0
- package/dist/utils/create-resolve.js +51 -0
- package/dist/utils/deep-equal.js +9 -4
- package/dist/utils/error.d.ts +1 -1
- package/dist/utils/error.js +2 -2
- package/dist/utils/get-super.d.ts +3 -0
- package/dist/utils/get-super.js +12 -0
- package/dist/utils/hash.d.ts +3 -0
- package/dist/utils/hash.js +41 -0
- package/dist/utils/lookup-path.d.ts +3 -0
- package/dist/utils/lookup-path.js +16 -0
- package/dist/utils/next-tick.d.ts +1 -0
- package/dist/utils/next-tick.js +10 -0
- package/dist/utils/object-value.d.ts +11 -1
- package/dist/utils/object-value.js +54 -27
- package/dist/utils/uuid.d.ts +1 -0
- package/dist/utils/uuid.js +36 -0
- package/package.json +3 -2
package/dist/types/number.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Zero = exports.PositiveOne = exports.NegativeOne = exports.CustomNumber = exports.CustomNumberIterator = void 0;
|
|
4
|
+
const hash_1 = require("../utils/hash");
|
|
4
5
|
const object_value_1 = require("../utils/object-value");
|
|
5
6
|
const path_1 = require("../utils/path");
|
|
6
7
|
const base_1 = require("./base");
|
|
7
|
-
const nil_1 = require("./nil");
|
|
8
8
|
const with_intrinsics_1 = require("./with-intrinsics");
|
|
9
9
|
class CustomNumberIterator {
|
|
10
10
|
constructor() {
|
|
@@ -44,8 +44,9 @@ class CustomNumber extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
44
44
|
toTruthy() {
|
|
45
45
|
return !!this.value;
|
|
46
46
|
}
|
|
47
|
-
instanceOf(v) {
|
|
48
|
-
|
|
47
|
+
instanceOf(v, typeIntrinsics) {
|
|
48
|
+
var _a;
|
|
49
|
+
return v.value === ((_a = typeIntrinsics.number) !== null && _a !== void 0 ? _a : CustomNumber.intrinsics);
|
|
49
50
|
}
|
|
50
51
|
[Symbol.iterator]() {
|
|
51
52
|
return new CustomNumberIterator();
|
|
@@ -56,16 +57,27 @@ class CustomNumber extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
56
57
|
set(_path, _newValue) {
|
|
57
58
|
throw new Error('Mutable operations are not allowed on a number.');
|
|
58
59
|
}
|
|
59
|
-
get(path) {
|
|
60
|
+
get(path, typeIntrinsics) {
|
|
61
|
+
var _a;
|
|
60
62
|
if (path instanceof base_1.CustomValue) {
|
|
61
|
-
return this.get(new path_1.Path([path]));
|
|
63
|
+
return this.get(new path_1.Path([path]), typeIntrinsics);
|
|
62
64
|
}
|
|
63
65
|
const traversalPath = path.clone();
|
|
64
66
|
const current = traversalPath.next();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
const intrinsics = (_a = typeIntrinsics.number) !== null && _a !== void 0 ? _a : CustomNumber.getIntrinsics();
|
|
68
|
+
if (traversalPath.count() === 0 && intrinsics.has(current)) {
|
|
69
|
+
return intrinsics.get(current);
|
|
67
70
|
}
|
|
68
|
-
|
|
71
|
+
throw new Error(`Unknown path in number ${path.toString()}.`);
|
|
72
|
+
}
|
|
73
|
+
getWithOrigin(path, typeIntrinsics) {
|
|
74
|
+
return {
|
|
75
|
+
value: this.get(path, typeIntrinsics),
|
|
76
|
+
origin: null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
hash() {
|
|
80
|
+
return (0, hash_1.getHashCode)(this.value);
|
|
69
81
|
}
|
|
70
82
|
}
|
|
71
83
|
CustomNumber.intrinsics = new object_value_1.ObjectValue();
|
package/dist/types/string.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { ContextTypeIntrinsics } from '../context/types';
|
|
1
2
|
import { ObjectValue } from '../utils/object-value';
|
|
2
3
|
import { Path } from '../utils/path';
|
|
3
4
|
import { CustomValue } from './base';
|
|
4
|
-
import { CustomValueWithIntrinsics } from './with-intrinsics';
|
|
5
|
+
import { CustomValueWithIntrinsics, CustomValueWithIntrinsicsResult } from './with-intrinsics';
|
|
5
6
|
export declare class CustomStringIterator implements Iterator<CustomValue> {
|
|
6
7
|
value: string;
|
|
7
8
|
index: number;
|
|
@@ -23,11 +24,13 @@ export declare class CustomString extends CustomValueWithIntrinsics {
|
|
|
23
24
|
toNumber(): number;
|
|
24
25
|
toInt(): number;
|
|
25
26
|
toTruthy(): boolean;
|
|
26
|
-
instanceOf(v: CustomValue): boolean;
|
|
27
|
+
instanceOf(v: CustomValue, typeIntrinsics: ContextTypeIntrinsics): boolean;
|
|
27
28
|
slice(a: CustomValue, b: CustomValue): CustomString;
|
|
28
29
|
[Symbol.iterator](): CustomStringIterator;
|
|
29
30
|
getCharIndex(index: number): number;
|
|
30
31
|
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
31
32
|
set(_path: Path<CustomValue> | CustomValue, _newValue: CustomValue): void;
|
|
32
|
-
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
33
|
+
get(path: Path<CustomValue> | CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
|
|
34
|
+
getWithOrigin(path: Path<CustomValue> | CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValueWithIntrinsicsResult;
|
|
35
|
+
hash(): number;
|
|
33
36
|
}
|
package/dist/types/string.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomString = exports.CustomStringIterator = void 0;
|
|
4
|
+
const hash_1 = require("../utils/hash");
|
|
4
5
|
const object_value_1 = require("../utils/object-value");
|
|
5
6
|
const path_1 = require("../utils/path");
|
|
6
7
|
const base_1 = require("./base");
|
|
7
|
-
const default_1 = require("./default");
|
|
8
8
|
const number_1 = require("./number");
|
|
9
9
|
const with_intrinsics_1 = require("./with-intrinsics");
|
|
10
10
|
class CustomStringIterator {
|
|
@@ -72,8 +72,9 @@ class CustomString extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
72
72
|
toTruthy() {
|
|
73
73
|
return this.value.length > 0;
|
|
74
74
|
}
|
|
75
|
-
instanceOf(v) {
|
|
76
|
-
|
|
75
|
+
instanceOf(v, typeIntrinsics) {
|
|
76
|
+
var _a;
|
|
77
|
+
return v.value === ((_a = typeIntrinsics.string) !== null && _a !== void 0 ? _a : CustomString.intrinsics);
|
|
77
78
|
}
|
|
78
79
|
slice(a, b) {
|
|
79
80
|
return new CustomString(this.value.slice(a.toNumber(), b.toNumber()));
|
|
@@ -99,9 +100,10 @@ class CustomString extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
99
100
|
set(_path, _newValue) {
|
|
100
101
|
throw new Error('Mutable operations are not allowed on a string.');
|
|
101
102
|
}
|
|
102
|
-
get(path) {
|
|
103
|
+
get(path, typeIntrinsics) {
|
|
104
|
+
var _a;
|
|
103
105
|
if (path instanceof base_1.CustomValue) {
|
|
104
|
-
return this.get(new path_1.Path([path]));
|
|
106
|
+
return this.get(new path_1.Path([path]), typeIntrinsics);
|
|
105
107
|
}
|
|
106
108
|
const traversalPath = path.clone();
|
|
107
109
|
const current = traversalPath.next();
|
|
@@ -113,11 +115,20 @@ class CustomString extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
113
115
|
}
|
|
114
116
|
throw new Error(`Index error (string index ${currentIndex} out of range).`);
|
|
115
117
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return
|
|
118
|
+
const intrinsics = (_a = typeIntrinsics.string) !== null && _a !== void 0 ? _a : CustomString.getIntrinsics();
|
|
119
|
+
if (traversalPath.count() === 0 && intrinsics.has(current)) {
|
|
120
|
+
return intrinsics.get(current);
|
|
119
121
|
}
|
|
120
|
-
|
|
122
|
+
throw new Error(`Unknown path in string ${path.toString()}.`);
|
|
123
|
+
}
|
|
124
|
+
getWithOrigin(path, typeIntrinsics) {
|
|
125
|
+
return {
|
|
126
|
+
value: this.get(path, typeIntrinsics),
|
|
127
|
+
origin: null
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
hash() {
|
|
131
|
+
return (0, hash_1.getStringHashCode)(this.value);
|
|
121
132
|
}
|
|
122
133
|
}
|
|
123
134
|
CustomString.intrinsics = new object_value_1.ObjectValue();
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
+
import { ContextTypeIntrinsics } from '../context/types';
|
|
1
2
|
import { ObjectValue } from '../utils/object-value';
|
|
2
3
|
import { Path } from '../utils/path';
|
|
3
4
|
import { CustomValue } from './base';
|
|
4
5
|
import { CustomFunction } from './function';
|
|
6
|
+
export type CustomValueWithIntrinsicsResult = {
|
|
7
|
+
value: CustomValue;
|
|
8
|
+
origin: CustomValueWithIntrinsics;
|
|
9
|
+
};
|
|
5
10
|
export declare abstract class CustomValueWithIntrinsics extends CustomValue {
|
|
6
11
|
abstract has(path: Path<CustomValue> | CustomValue): boolean;
|
|
7
12
|
abstract set(path: Path<CustomValue> | CustomValue, value: CustomValue): void;
|
|
8
|
-
abstract get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
13
|
+
abstract get(path: Path<CustomValue> | CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
|
|
14
|
+
abstract getWithOrigin(path: Path<CustomValue> | CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValueWithIntrinsicsResult;
|
|
9
15
|
abstract [Symbol.iterator](): Iterator<CustomValue> & {
|
|
10
16
|
index: number;
|
|
11
17
|
};
|
|
12
18
|
static readonly intrinsics: ObjectValue;
|
|
13
19
|
static getIntrinsics(): ObjectValue;
|
|
14
20
|
static addIntrinsic(key: CustomValue, fn: CustomFunction): void;
|
|
21
|
+
static clearIntrinsics(): void;
|
|
22
|
+
getIntrinsics(): ObjectValue;
|
|
15
23
|
}
|
|
16
24
|
export declare abstract class CustomObject extends CustomValueWithIntrinsics {
|
|
17
25
|
}
|
|
@@ -9,6 +9,12 @@ class CustomValueWithIntrinsics extends base_1.CustomValue {
|
|
|
9
9
|
static addIntrinsic(key, fn) {
|
|
10
10
|
this.intrinsics.set(key, fn);
|
|
11
11
|
}
|
|
12
|
+
static clearIntrinsics() {
|
|
13
|
+
this.intrinsics.clear();
|
|
14
|
+
}
|
|
15
|
+
getIntrinsics() {
|
|
16
|
+
return this.constructor.intrinsics;
|
|
17
|
+
}
|
|
12
18
|
}
|
|
13
19
|
exports.CustomValueWithIntrinsics = CustomValueWithIntrinsics;
|
|
14
20
|
class CustomObject extends CustomValueWithIntrinsics {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAssign = void 0;
|
|
4
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
5
|
+
const assign_1 = require("../operations/assign");
|
|
6
|
+
const assign_globals_1 = require("../operations/assign-globals");
|
|
7
|
+
const assign_locals_1 = require("../operations/assign-locals");
|
|
8
|
+
const assign_outer_1 = require("../operations/assign-outer");
|
|
9
|
+
const assign_self_1 = require("../operations/assign-self");
|
|
10
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
11
|
+
const optAssignMap = {
|
|
12
|
+
self: assign_self_1.AssignSelf,
|
|
13
|
+
globals: assign_globals_1.AssignGlobals,
|
|
14
|
+
locals: assign_locals_1.AssignLocals,
|
|
15
|
+
outer: assign_outer_1.AssignOuter
|
|
16
|
+
};
|
|
17
|
+
function createAssign(item, target) {
|
|
18
|
+
if (item.variable instanceof miniscript_core_1.ASTIdentifier &&
|
|
19
|
+
hasOwnProperty.call(optAssignMap, item.variable.name)) {
|
|
20
|
+
const OptAssign = optAssignMap[item.variable.name];
|
|
21
|
+
return new OptAssign(item, target);
|
|
22
|
+
}
|
|
23
|
+
return new assign_1.Assign(item, target);
|
|
24
|
+
}
|
|
25
|
+
exports.createAssign = createAssign;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ASTBase, ASTIdentifier } from 'miniscript-core';
|
|
2
|
+
import { Operation } from '../operations/operation';
|
|
3
|
+
import { Resolve } from '../operations/resolve';
|
|
4
|
+
export declare function createIdentifierResolve(item: ASTIdentifier, target?: string): Operation;
|
|
5
|
+
export declare function createResolve(item: ASTBase, target?: string): Resolve;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createResolve = exports.createIdentifierResolve = void 0;
|
|
4
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
5
|
+
const reference_globals_1 = require("../operations/reference-globals");
|
|
6
|
+
const reference_locals_1 = require("../operations/reference-locals");
|
|
7
|
+
const reference_outer_1 = require("../operations/reference-outer");
|
|
8
|
+
const reference_self_1 = require("../operations/reference-self");
|
|
9
|
+
const resolve_1 = require("../operations/resolve");
|
|
10
|
+
const resolve_globals_1 = require("../operations/resolve-globals");
|
|
11
|
+
const resolve_locals_1 = require("../operations/resolve-locals");
|
|
12
|
+
const resolve_outer_1 = require("../operations/resolve-outer");
|
|
13
|
+
const resolve_self_1 = require("../operations/resolve-self");
|
|
14
|
+
const lookup_path_1 = require("./lookup-path");
|
|
15
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
16
|
+
const optIdentifierResolveMap = {
|
|
17
|
+
self: reference_self_1.ReferenceSelf,
|
|
18
|
+
globals: reference_globals_1.ReferenceGlobals,
|
|
19
|
+
locals: reference_locals_1.ReferenceLocals,
|
|
20
|
+
outer: reference_outer_1.ReferenceOuter
|
|
21
|
+
};
|
|
22
|
+
function createIdentifierResolve(item, target) {
|
|
23
|
+
if (hasOwnProperty.call(optIdentifierResolveMap, item.name)) {
|
|
24
|
+
const OptResolve = optIdentifierResolveMap[item.name];
|
|
25
|
+
return new OptResolve(item, target);
|
|
26
|
+
}
|
|
27
|
+
return new resolve_1.Resolve(item, target);
|
|
28
|
+
}
|
|
29
|
+
exports.createIdentifierResolve = createIdentifierResolve;
|
|
30
|
+
const optResolveMap = {
|
|
31
|
+
self: resolve_self_1.ResolveSelf,
|
|
32
|
+
globals: resolve_globals_1.ResolveGlobals,
|
|
33
|
+
locals: resolve_locals_1.ResolveLocals,
|
|
34
|
+
outer: resolve_outer_1.ResolveOuter
|
|
35
|
+
};
|
|
36
|
+
function createResolve(item, target) {
|
|
37
|
+
if (item instanceof miniscript_core_1.ASTMemberExpression ||
|
|
38
|
+
item instanceof miniscript_core_1.ASTIndexExpression ||
|
|
39
|
+
item instanceof miniscript_core_1.ASTSliceExpression) {
|
|
40
|
+
const path = (0, lookup_path_1.lookupPath)(item);
|
|
41
|
+
if (path.length > 0 &&
|
|
42
|
+
path[0].base instanceof miniscript_core_1.ASTIdentifier &&
|
|
43
|
+
hasOwnProperty.call(optResolveMap, path[0].base.name)) {
|
|
44
|
+
const OptResolve = optResolveMap[path[0].base.name];
|
|
45
|
+
path[0].base = null;
|
|
46
|
+
return new OptResolve(item, target);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return new resolve_1.Resolve(item, target);
|
|
50
|
+
}
|
|
51
|
+
exports.createResolve = createResolve;
|
package/dist/utils/deep-equal.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deepEqual = void 0;
|
|
4
|
+
const list_1 = require("../types/list");
|
|
5
|
+
const map_1 = require("../types/map");
|
|
4
6
|
const with_intrinsics_1 = require("../types/with-intrinsics");
|
|
5
7
|
function equalInner(a, b, maxDepth, depth = 0) {
|
|
6
8
|
if (maxDepth <= depth)
|
|
@@ -10,7 +12,7 @@ function equalInner(a, b, maxDepth, depth = 0) {
|
|
|
10
12
|
if (a && b && a instanceof with_intrinsics_1.CustomObject && b instanceof with_intrinsics_1.CustomObject) {
|
|
11
13
|
if (a.constructor !== b.constructor)
|
|
12
14
|
return false;
|
|
13
|
-
if (
|
|
15
|
+
if (a instanceof list_1.CustomList) {
|
|
14
16
|
const length = a.value.length;
|
|
15
17
|
if (length !== b.value.length)
|
|
16
18
|
return false;
|
|
@@ -19,12 +21,15 @@ function equalInner(a, b, maxDepth, depth = 0) {
|
|
|
19
21
|
return false;
|
|
20
22
|
return true;
|
|
21
23
|
}
|
|
22
|
-
if (a
|
|
24
|
+
if (a instanceof map_1.CustomMap) {
|
|
23
25
|
if (a.value.size !== b.value.size)
|
|
24
26
|
return false;
|
|
25
|
-
for (const i of a.value.keys())
|
|
26
|
-
if (!b.has(i) ||
|
|
27
|
+
for (const i of a.value.keys()) {
|
|
28
|
+
if (!b.value.has(i) ||
|
|
29
|
+
!equalInner(a.value.get(i), b.value.get(i), maxDepth, depth + 1)) {
|
|
27
30
|
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
28
33
|
return true;
|
|
29
34
|
}
|
|
30
35
|
return false;
|
package/dist/utils/error.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare class RuntimeError extends Error {
|
|
|
8
8
|
target: string;
|
|
9
9
|
stackTrace: Operation[];
|
|
10
10
|
source?: Error;
|
|
11
|
-
constructor(message: string, context
|
|
11
|
+
constructor(message: string, context?: RuntimeContext, source?: Error);
|
|
12
12
|
private createTrace;
|
|
13
13
|
}
|
|
14
14
|
interface PrepareContext {
|
package/dist/utils/error.js
CHANGED
|
@@ -5,8 +5,8 @@ class RuntimeError extends Error {
|
|
|
5
5
|
constructor(message, context, source) {
|
|
6
6
|
var _a;
|
|
7
7
|
super(message);
|
|
8
|
-
this.target = context.target;
|
|
9
|
-
this.stackTrace = (_a = context.stackTrace) !== null && _a !== void 0 ? _a : [];
|
|
8
|
+
this.target = context === null || context === void 0 ? void 0 : context.target;
|
|
9
|
+
this.stackTrace = (_a = context === null || context === void 0 ? void 0 : context.stackTrace) !== null && _a !== void 0 ? _a : [];
|
|
10
10
|
this.stack = this.createTrace();
|
|
11
11
|
this.source = source;
|
|
12
12
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSuper = void 0;
|
|
4
|
+
const map_1 = require("../types/map");
|
|
5
|
+
function getSuper(item) {
|
|
6
|
+
var _a;
|
|
7
|
+
if (item instanceof map_1.CustomMap) {
|
|
8
|
+
return (_a = item.getIsa()) !== null && _a !== void 0 ? _a : new map_1.CustomMap();
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
exports.getSuper = getSuper;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStringHashCode = exports.getHashCode = exports.rotateBits = void 0;
|
|
4
|
+
const lru_cache_1 = require("lru-cache");
|
|
5
|
+
function rotateBits(n) {
|
|
6
|
+
return (n >> 1) | (n << 31);
|
|
7
|
+
}
|
|
8
|
+
exports.rotateBits = rotateBits;
|
|
9
|
+
function getHashCode(value, offset = 0) {
|
|
10
|
+
let unsigned = value >>> 0;
|
|
11
|
+
unsigned = ((unsigned >> 16) ^ unsigned) * 0x45d9f3b;
|
|
12
|
+
unsigned = ((unsigned >> 16) ^ unsigned) * 0x45d9f3b;
|
|
13
|
+
unsigned = (unsigned >> 16) ^ unsigned;
|
|
14
|
+
return ((offset << 5) - offset + unsigned) | 0;
|
|
15
|
+
}
|
|
16
|
+
exports.getHashCode = getHashCode;
|
|
17
|
+
exports.getStringHashCode = (function () {
|
|
18
|
+
const cache = new lru_cache_1.LRUCache({
|
|
19
|
+
ttl: 1000 * 60 * 5,
|
|
20
|
+
max: 500
|
|
21
|
+
});
|
|
22
|
+
const generateHash = (value) => {
|
|
23
|
+
let hash = 0;
|
|
24
|
+
for (let i = 0; i < value.length; i++) {
|
|
25
|
+
const chr = value.charCodeAt(i);
|
|
26
|
+
hash = getHashCode(chr, hash);
|
|
27
|
+
}
|
|
28
|
+
return hash;
|
|
29
|
+
};
|
|
30
|
+
return (value) => {
|
|
31
|
+
if (value.length === 0) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
if (cache.has(value)) {
|
|
35
|
+
return cache.get(value);
|
|
36
|
+
}
|
|
37
|
+
const hash = generateHash(value);
|
|
38
|
+
cache.set(value, hash);
|
|
39
|
+
return hash;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lookupPath = void 0;
|
|
4
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
5
|
+
function lookupPath(item) {
|
|
6
|
+
const path = [item];
|
|
7
|
+
let current = item.base;
|
|
8
|
+
while (current instanceof miniscript_core_1.ASTMemberExpression ||
|
|
9
|
+
current instanceof miniscript_core_1.ASTIndexExpression ||
|
|
10
|
+
current instanceof miniscript_core_1.ASTSliceExpression) {
|
|
11
|
+
path.unshift(current);
|
|
12
|
+
current = current.base;
|
|
13
|
+
}
|
|
14
|
+
return path;
|
|
15
|
+
}
|
|
16
|
+
exports.lookupPath = lookupPath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const nextTick: () => Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nextTick = void 0;
|
|
4
|
+
const set_immediate_1 = require("./set-immediate");
|
|
5
|
+
const nextTick = () => {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
(0, set_immediate_1.setImmediate)(resolve);
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
exports.nextTick = nextTick;
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { CustomValue } from '../types/base';
|
|
2
|
-
export
|
|
2
|
+
export type ObjectValueKeyPair = [CustomValue, CustomValue];
|
|
3
|
+
export declare class ObjectValue {
|
|
4
|
+
private data;
|
|
5
|
+
constructor(entries?: ObjectValue | ObjectValueKeyPair[] | null);
|
|
3
6
|
get(mapKey: CustomValue): CustomValue;
|
|
4
7
|
has(mapKey: CustomValue): boolean;
|
|
5
8
|
set(mapKey: CustomValue, mapValue: CustomValue): this;
|
|
6
9
|
delete(mapKey: CustomValue): boolean;
|
|
10
|
+
values(): CustomValue[];
|
|
11
|
+
keys(): CustomValue[];
|
|
12
|
+
entries(): ObjectValueKeyPair[];
|
|
13
|
+
get size(): number;
|
|
14
|
+
forEach(callback: (value: CustomValue, key: CustomValue, map: ObjectValue) => any): void;
|
|
15
|
+
fork(): ObjectValue;
|
|
7
16
|
extend(objVal: ObjectValue): this;
|
|
17
|
+
clear(): void;
|
|
8
18
|
}
|
|
@@ -2,48 +2,75 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectValue = void 0;
|
|
4
4
|
const nil_1 = require("../types/nil");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
class ObjectValue {
|
|
6
|
+
constructor(entries) {
|
|
7
|
+
if (entries == null) {
|
|
8
|
+
this.data = new Map();
|
|
9
|
+
}
|
|
10
|
+
else if (entries instanceof ObjectValue) {
|
|
11
|
+
this.data = new Map(entries.data);
|
|
12
|
+
}
|
|
13
|
+
else if (Array.isArray(entries)) {
|
|
14
|
+
this.data = new Map();
|
|
15
|
+
for (const [key, value] of entries) {
|
|
16
|
+
this.set(key, value);
|
|
11
17
|
}
|
|
12
18
|
}
|
|
13
|
-
|
|
19
|
+
if (this.data == null) {
|
|
20
|
+
throw new Error('Unknown entries type.');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get(mapKey) {
|
|
24
|
+
const hash = mapKey.hash();
|
|
25
|
+
if (!this.data.has(hash))
|
|
26
|
+
return nil_1.Void;
|
|
27
|
+
return this.data.get(hash)[1];
|
|
14
28
|
}
|
|
15
29
|
has(mapKey) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
30
|
+
const hash = mapKey.hash();
|
|
31
|
+
return this.data.has(hash);
|
|
22
32
|
}
|
|
23
33
|
set(mapKey, mapValue) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
super.set(key, mapValue);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
super.set(mapKey, mapValue);
|
|
34
|
+
const hash = mapKey.hash();
|
|
35
|
+
this.data.set(hash, [mapKey, mapValue]);
|
|
31
36
|
return this;
|
|
32
37
|
}
|
|
33
38
|
delete(mapKey) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
const hash = mapKey.hash();
|
|
40
|
+
return this.data.delete(hash);
|
|
41
|
+
}
|
|
42
|
+
values() {
|
|
43
|
+
return [...this.data.values()].map(([_, v]) => v);
|
|
44
|
+
}
|
|
45
|
+
keys() {
|
|
46
|
+
return [...this.data.values()].map(([k]) => k);
|
|
47
|
+
}
|
|
48
|
+
entries() {
|
|
49
|
+
return [...this.data.values()];
|
|
50
|
+
}
|
|
51
|
+
get size() {
|
|
52
|
+
return this.data.size;
|
|
53
|
+
}
|
|
54
|
+
forEach(callback) {
|
|
55
|
+
for (const [key, value] of this.data.values()) {
|
|
56
|
+
callback(value, key, this);
|
|
39
57
|
}
|
|
40
|
-
|
|
58
|
+
}
|
|
59
|
+
fork() {
|
|
60
|
+
const newObject = new ObjectValue();
|
|
61
|
+
for (const [key, value] of this.entries()) {
|
|
62
|
+
newObject.set(key.fork(), value.fork());
|
|
63
|
+
}
|
|
64
|
+
return newObject;
|
|
41
65
|
}
|
|
42
66
|
extend(objVal) {
|
|
43
|
-
for (const [key, value] of objVal) {
|
|
67
|
+
for (const [key, value] of objVal.entries()) {
|
|
44
68
|
this.set(key, value);
|
|
45
69
|
}
|
|
46
70
|
return this;
|
|
47
71
|
}
|
|
72
|
+
clear() {
|
|
73
|
+
this.data.clear();
|
|
74
|
+
}
|
|
48
75
|
}
|
|
49
76
|
exports.ObjectValue = ObjectValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const uuid: () => string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uuid = void 0;
|
|
4
|
+
// Source: https://gist.github.com/alemures/ba4cd1b37a4b11346d7f54f05c826d24
|
|
5
|
+
function createUUIDFactory() {
|
|
6
|
+
const lut = [];
|
|
7
|
+
for (let i = 0; i < 256; i++)
|
|
8
|
+
lut[i] = (i < 16 ? '0' : '') + i.toString(16);
|
|
9
|
+
return function () {
|
|
10
|
+
const d0 = (Math.random() * 0xffffffff) | 0;
|
|
11
|
+
const d1 = (Math.random() * 0xffffffff) | 0;
|
|
12
|
+
const d2 = (Math.random() * 0xffffffff) | 0;
|
|
13
|
+
const d3 = (Math.random() * 0xffffffff) | 0;
|
|
14
|
+
return (lut[d0 & 0xff] +
|
|
15
|
+
lut[(d0 >> 8) & 0xff] +
|
|
16
|
+
lut[(d0 >> 16) & 0xff] +
|
|
17
|
+
lut[(d0 >> 24) & 0xff] +
|
|
18
|
+
'-' +
|
|
19
|
+
lut[d1 & 0xff] +
|
|
20
|
+
lut[(d1 >> 8) & 0xff] +
|
|
21
|
+
'-' +
|
|
22
|
+
lut[((d1 >> 16) & 0x0f) | 0x40] +
|
|
23
|
+
lut[(d1 >> 24) & 0xff] +
|
|
24
|
+
'-' +
|
|
25
|
+
lut[(d2 & 0x3f) | 0x80] +
|
|
26
|
+
lut[(d2 >> 8) & 0xff] +
|
|
27
|
+
'-' +
|
|
28
|
+
lut[(d2 >> 16) & 0xff] +
|
|
29
|
+
lut[(d2 >> 24) & 0xff] +
|
|
30
|
+
lut[d3 & 0xff] +
|
|
31
|
+
lut[(d3 >> 8) & 0xff] +
|
|
32
|
+
lut[(d3 >> 16) & 0xff] +
|
|
33
|
+
lut[(d3 >> 24) & 0xff]);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.uuid = createUUIDFactory();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "greybel-interpreter",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Interpreter",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"typescript": "^5.0.4"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"
|
|
51
|
+
"lru-cache": "^10.0.1",
|
|
52
|
+
"greybel-core": "^1.1.0"
|
|
52
53
|
},
|
|
53
54
|
"keywords": [
|
|
54
55
|
"miniscript"
|