affinirum 1.5.4 → 2.0.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/.cache/arrow-preview-vWvB5K/affinirum-arrow-functions.patch +155 -0
- package/.cache/function-syntax-tests.log +20 -0
- package/README.md +925 -355
- package/dst/Affinirum.d.ts +29 -19
- package/dst/Affinirum.js +399 -334
- package/dst/CallFrame.d.ts +12 -3
- package/dst/CallFrame.js +49 -10
- package/dst/Constant.d.ts +1 -3
- package/dst/Constant.js +3 -8
- package/dst/LexicalScope.d.ts +11 -9
- package/dst/LexicalScope.js +10 -6
- package/dst/ParserSpan.d.ts +11 -0
- package/dst/{ScriptSpan.js → ParserSpan.js} +8 -5
- package/dst/ParserState.d.ts +28 -49
- package/dst/ParserState.js +256 -489
- package/dst/Type.d.ts +34 -17
- package/dst/Type.js +211 -115
- package/dst/TypeParser.d.ts +9 -0
- package/dst/TypeParser.js +127 -0
- package/dst/Value.d.ts +1 -1
- package/dst/Value.js +21 -10
- package/dst/Variable.d.ts +16 -5
- package/dst/Variable.js +32 -7
- package/dst/atom/ArrayAtom.d.ts +10 -10
- package/dst/atom/ArrayAtom.js +62 -55
- package/dst/atom/Atom.d.ts +7 -0
- package/dst/atom/FunctionAtom.d.ts +13 -15
- package/dst/atom/FunctionAtom.js +53 -104
- package/dst/atom/FunctionSignature.d.ts +23 -0
- package/dst/atom/FunctionSignature.js +124 -0
- package/dst/atom/ObjectAtom.d.ts +11 -9
- package/dst/atom/ObjectAtom.js +73 -33
- package/dst/atom/PrimitiveAtom.d.ts +6 -7
- package/dst/atom/PrimitiveAtom.js +7 -10
- package/dst/cjs/Affinirum.d.ts +29 -19
- package/dst/cjs/Affinirum.js +398 -333
- package/dst/cjs/CallFrame.d.ts +12 -3
- package/dst/cjs/CallFrame.js +49 -10
- package/dst/cjs/Constant.d.ts +1 -3
- package/dst/cjs/Constant.js +3 -8
- package/dst/cjs/LexicalScope.d.ts +11 -9
- package/dst/cjs/LexicalScope.js +10 -6
- package/dst/cjs/ParserSpan.d.ts +11 -0
- package/dst/cjs/{ScriptSpan.js → ParserSpan.js} +10 -7
- package/dst/cjs/ParserState.d.ts +28 -49
- package/dst/cjs/ParserState.js +255 -488
- package/dst/cjs/Type.d.ts +34 -17
- package/dst/cjs/Type.js +211 -115
- package/dst/cjs/TypeParser.d.ts +9 -0
- package/dst/cjs/TypeParser.js +131 -0
- package/dst/cjs/Value.d.ts +1 -1
- package/dst/cjs/Value.js +21 -10
- package/dst/cjs/Variable.d.ts +16 -5
- package/dst/cjs/Variable.js +36 -9
- package/dst/cjs/atom/ArrayAtom.d.ts +10 -10
- package/dst/cjs/atom/ArrayAtom.js +62 -55
- package/dst/cjs/atom/Atom.d.ts +7 -0
- package/dst/cjs/atom/FunctionAtom.d.ts +13 -15
- package/dst/cjs/atom/FunctionAtom.js +54 -105
- package/dst/cjs/atom/FunctionSignature.d.ts +23 -0
- package/dst/cjs/atom/FunctionSignature.js +128 -0
- package/dst/cjs/atom/ObjectAtom.d.ts +11 -9
- package/dst/cjs/atom/ObjectAtom.js +73 -33
- package/dst/cjs/atom/PrimitiveAtom.d.ts +6 -7
- package/dst/cjs/atom/PrimitiveAtom.js +7 -10
- package/dst/cjs/dictionary/Constants.d.ts +2 -0
- package/dst/cjs/dictionary/Constants.js +27 -0
- package/dst/cjs/dictionary/Functions.d.ts +2 -0
- package/dst/cjs/{Functions.js → dictionary/Functions.js} +27 -25
- package/dst/cjs/native/Aggregable.js +10 -2
- package/dst/cjs/native/Array.d.ts +2 -3
- package/dst/cjs/native/Array.js +38 -39
- package/dst/cjs/native/Boolean.d.ts +1 -1
- package/dst/cjs/native/Boolean.js +13 -10
- package/dst/cjs/native/Buffer.d.ts +5 -5
- package/dst/cjs/native/Buffer.js +70 -46
- package/dst/cjs/native/Composite.d.ts +5 -0
- package/dst/cjs/native/Composite.js +35 -0
- package/dst/cjs/native/Enumerable.js +20 -8
- package/dst/cjs/native/Float.d.ts +3 -1
- package/dst/cjs/native/Float.js +51 -12
- package/dst/cjs/native/Integer.d.ts +4 -2
- package/dst/cjs/native/Integer.js +60 -25
- package/dst/cjs/native/Iterable.d.ts +0 -2
- package/dst/cjs/native/Iterable.js +9 -28
- package/dst/cjs/native/Number.d.ts +0 -2
- package/dst/cjs/native/Number.js +34 -48
- package/dst/cjs/native/Object.d.ts +1 -1
- package/dst/cjs/native/Object.js +5 -6
- package/dst/cjs/native/String.d.ts +7 -6
- package/dst/cjs/native/String.js +28 -27
- package/dst/cjs/native/Timestamp.d.ts +3 -3
- package/dst/cjs/native/Timestamp.js +34 -36
- package/dst/cjs/native/Unknown.d.ts +3 -3
- package/dst/cjs/native/Unknown.js +48 -17
- package/dst/cjs/native/notation/AN.d.ts +1 -1
- package/dst/cjs/native/notation/AN.js +37 -35
- package/dst/cjs/native/notation/IP.d.ts +1 -1
- package/dst/cjs/native/notation/IP.js +11 -12
- package/dst/cjs/native/notation/JSON.d.ts +1 -1
- package/dst/cjs/native/notation/JSON.js +7 -6
- package/dst/cjs/node/AccessNode.d.ts +24 -0
- package/dst/cjs/node/AccessNode.js +193 -0
- package/dst/cjs/node/ArrayNode.d.ts +7 -4
- package/dst/cjs/node/ArrayNode.js +26 -15
- package/dst/cjs/node/AssignableNode.d.ts +16 -0
- package/dst/cjs/node/AssignableNode.js +18 -0
- package/dst/cjs/node/AssignmentNode.d.ts +20 -0
- package/dst/cjs/node/AssignmentNode.js +66 -0
- package/dst/cjs/node/BlockNode.d.ts +5 -4
- package/dst/cjs/node/BlockNode.js +18 -11
- package/dst/cjs/node/CallNode.d.ts +7 -5
- package/dst/cjs/node/CallNode.js +40 -41
- package/dst/cjs/node/CastNode.d.ts +5 -6
- package/dst/cjs/node/CastNode.js +16 -17
- package/dst/cjs/node/ConstantNode.d.ts +4 -6
- package/dst/cjs/node/ConstantNode.js +9 -17
- package/dst/cjs/node/FinalNode.d.ts +19 -0
- package/dst/cjs/node/FinalNode.js +41 -0
- package/dst/cjs/node/FunctionNode.d.ts +17 -0
- package/dst/cjs/node/FunctionNode.js +51 -0
- package/dst/cjs/node/InvocationNode.d.ts +5 -0
- package/dst/cjs/node/InvocationNode.js +34 -0
- package/dst/cjs/node/JumpNode.d.ts +7 -9
- package/dst/cjs/node/JumpNode.js +12 -19
- package/dst/cjs/node/LoopNode.d.ts +7 -5
- package/dst/cjs/node/LoopNode.js +33 -22
- package/dst/cjs/node/MatchNode.d.ts +17 -0
- package/dst/cjs/node/MatchNode.js +65 -0
- package/dst/cjs/node/Node.d.ts +14 -0
- package/dst/cjs/{Node.js → node/Node.js} +17 -11
- package/dst/cjs/node/ObjectNode.d.ts +7 -4
- package/dst/cjs/node/ObjectNode.js +42 -11
- package/dst/cjs/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
- package/dst/cjs/node/TernaryNode.js +45 -0
- package/dst/cjs/node/VariableNode.d.ts +10 -6
- package/dst/cjs/node/VariableNode.js +50 -16
- package/dst/dictionary/Constants.d.ts +2 -0
- package/dst/dictionary/Constants.js +24 -0
- package/dst/dictionary/Functions.d.ts +2 -0
- package/dst/{Functions.js → dictionary/Functions.js} +26 -24
- package/dst/native/Aggregable.js +11 -3
- package/dst/native/Array.d.ts +2 -3
- package/dst/native/Array.js +37 -38
- package/dst/native/Boolean.d.ts +1 -1
- package/dst/native/Boolean.js +12 -9
- package/dst/native/Buffer.d.ts +5 -5
- package/dst/native/Buffer.js +66 -42
- package/dst/native/Composite.d.ts +5 -0
- package/dst/native/Composite.js +32 -0
- package/dst/native/Enumerable.js +20 -8
- package/dst/native/Float.d.ts +3 -1
- package/dst/native/Float.js +48 -11
- package/dst/native/Integer.d.ts +4 -2
- package/dst/native/Integer.js +56 -23
- package/dst/native/Iterable.d.ts +0 -2
- package/dst/native/Iterable.js +8 -27
- package/dst/native/Number.d.ts +0 -2
- package/dst/native/Number.js +34 -46
- package/dst/native/Object.d.ts +1 -1
- package/dst/native/Object.js +4 -5
- package/dst/native/String.d.ts +7 -6
- package/dst/native/String.js +24 -24
- package/dst/native/Timestamp.d.ts +3 -3
- package/dst/native/Timestamp.js +31 -33
- package/dst/native/Unknown.d.ts +3 -3
- package/dst/native/Unknown.js +49 -18
- package/dst/native/notation/AN.d.ts +1 -1
- package/dst/native/notation/AN.js +37 -35
- package/dst/native/notation/IP.d.ts +1 -1
- package/dst/native/notation/IP.js +10 -11
- package/dst/native/notation/JSON.d.ts +1 -1
- package/dst/native/notation/JSON.js +6 -5
- package/dst/node/AccessNode.d.ts +24 -0
- package/dst/node/AccessNode.js +189 -0
- package/dst/node/ArrayNode.d.ts +7 -4
- package/dst/node/ArrayNode.js +26 -15
- package/dst/node/AssignableNode.d.ts +16 -0
- package/dst/node/AssignableNode.js +14 -0
- package/dst/node/AssignmentNode.d.ts +20 -0
- package/dst/node/AssignmentNode.js +62 -0
- package/dst/node/BlockNode.d.ts +5 -4
- package/dst/node/BlockNode.js +18 -11
- package/dst/node/CallNode.d.ts +7 -5
- package/dst/node/CallNode.js +40 -41
- package/dst/node/CastNode.d.ts +5 -6
- package/dst/node/CastNode.js +16 -17
- package/dst/node/ConstantNode.d.ts +4 -6
- package/dst/node/ConstantNode.js +9 -17
- package/dst/node/FinalNode.d.ts +19 -0
- package/dst/node/FinalNode.js +37 -0
- package/dst/node/FunctionNode.d.ts +17 -0
- package/dst/node/FunctionNode.js +47 -0
- package/dst/node/InvocationNode.d.ts +5 -0
- package/dst/node/InvocationNode.js +30 -0
- package/dst/node/JumpNode.d.ts +7 -9
- package/dst/node/JumpNode.js +12 -19
- package/dst/node/LoopNode.d.ts +7 -5
- package/dst/node/LoopNode.js +33 -22
- package/dst/node/MatchNode.d.ts +17 -0
- package/dst/node/MatchNode.js +61 -0
- package/dst/node/Node.d.ts +14 -0
- package/dst/node/Node.js +28 -0
- package/dst/node/ObjectNode.d.ts +7 -4
- package/dst/node/ObjectNode.js +42 -11
- package/dst/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
- package/dst/node/TernaryNode.js +41 -0
- package/dst/node/VariableNode.d.ts +10 -6
- package/dst/node/VariableNode.js +50 -16
- package/package.json +4 -4
- package/dst/Atom.d.ts +0 -7
- package/dst/Constants.d.ts +0 -2
- package/dst/Constants.js +0 -24
- package/dst/Functions.d.ts +0 -2
- package/dst/Jump.d.ts +0 -1
- package/dst/Jump.js +0 -1
- package/dst/JumpException.d.ts +0 -9
- package/dst/JumpException.js +0 -14
- package/dst/Keywords.d.ts +0 -1
- package/dst/Keywords.js +0 -17
- package/dst/Node.d.ts +0 -14
- package/dst/Node.js +0 -22
- package/dst/ScriptSpan.d.ts +0 -10
- package/dst/cjs/Atom.d.ts +0 -7
- package/dst/cjs/Constants.d.ts +0 -2
- package/dst/cjs/Constants.js +0 -27
- package/dst/cjs/Functions.d.ts +0 -2
- package/dst/cjs/Jump.d.ts +0 -1
- package/dst/cjs/Jump.js +0 -2
- package/dst/cjs/JumpException.d.ts +0 -9
- package/dst/cjs/JumpException.js +0 -18
- package/dst/cjs/Keywords.d.ts +0 -1
- package/dst/cjs/Keywords.js +0 -20
- package/dst/cjs/Node.d.ts +0 -14
- package/dst/cjs/ScriptSpan.d.ts +0 -10
- package/dst/cjs/node/SwitchNode.js +0 -49
- package/dst/cjs/node/VariadicNode.d.ts +0 -4
- package/dst/cjs/node/VariadicNode.js +0 -10
- package/dst/node/SwitchNode.js +0 -45
- package/dst/node/VariadicNode.d.ts +0 -4
- package/dst/node/VariadicNode.js +0 -6
- /package/dst/{Atom.js → atom/Atom.js} +0 -0
- /package/dst/cjs/{Atom.js → atom/Atom.js} +0 -0
package/dst/Value.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export type PrimitiveValue = undefined | null | number | boolean | Date | bigint
|
|
|
2
2
|
export type Value = PrimitiveValue | Value[] | {
|
|
3
3
|
[key: string]: Value;
|
|
4
4
|
} | ((...args: any[]) => Value);
|
|
5
|
-
export declare const normalize: (value: Value) => Value;
|
|
5
|
+
export declare const normalize: (value: Value, composites?: WeakMap<object, Value>) => Value;
|
package/dst/Value.js
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
const
|
|
1
|
+
export const normalize = (value, composites) => {
|
|
2
2
|
if (typeof value === "bigint") {
|
|
3
3
|
return BigInt.asIntN(64, value);
|
|
4
4
|
}
|
|
5
|
-
if (value == null || typeof value !== "object" || value instanceof Date || value instanceof ArrayBuffer
|
|
5
|
+
if (value == null || typeof value !== "object" || value instanceof Date || value instanceof ArrayBuffer) {
|
|
6
6
|
return value;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
composites ??= new WeakMap();
|
|
9
|
+
const existing = composites.get(value);
|
|
10
|
+
if (existing !== undefined) {
|
|
11
|
+
return existing;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
const copy = new Array(value.length);
|
|
15
|
+
composites.set(value, copy);
|
|
16
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
17
|
+
const index = Number(key);
|
|
18
|
+
if (Number.isInteger(index) && index >= 0 && index < copy.length && String(index) === key) {
|
|
19
|
+
copy[index] = normalize(value[index], composites);
|
|
20
|
+
}
|
|
15
21
|
}
|
|
22
|
+
return copy;
|
|
23
|
+
}
|
|
24
|
+
const copy = Object.create(null);
|
|
25
|
+
composites.set(value, copy);
|
|
26
|
+
for (const key of Object.keys(value)) {
|
|
27
|
+
copy[key] = normalize(value[key], composites);
|
|
16
28
|
}
|
|
17
|
-
return
|
|
29
|
+
return copy;
|
|
18
30
|
};
|
|
19
|
-
export const normalize = (value) => normalizeValue(value, new WeakSet());
|
package/dst/Variable.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { Type } from "./Type.js";
|
|
2
|
-
export declare class Variable {
|
|
3
|
-
protected _type: Type;
|
|
4
|
-
|
|
5
|
-
constructor(_type?: Type, _assignable?: boolean);
|
|
2
|
+
export declare abstract class Variable {
|
|
3
|
+
protected _type: Type | undefined;
|
|
4
|
+
constructor(type?: Type);
|
|
6
5
|
get type(): Type;
|
|
7
|
-
|
|
6
|
+
get declared(): boolean;
|
|
7
|
+
abstract declare(type: Type): void;
|
|
8
|
+
}
|
|
9
|
+
export declare class LocalVariable extends Variable {
|
|
10
|
+
protected readonly _assignable: boolean;
|
|
11
|
+
constructor(type?: Type, assignable?: boolean);
|
|
12
|
+
declare(type: Type): void;
|
|
8
13
|
get assignable(): boolean;
|
|
9
14
|
}
|
|
15
|
+
export declare class InputVariable extends Variable {
|
|
16
|
+
protected readonly _declared: boolean;
|
|
17
|
+
constructor(type?: Type);
|
|
18
|
+
declare(type: Type): void;
|
|
19
|
+
get declared(): boolean;
|
|
20
|
+
}
|
package/dst/Variable.js
CHANGED
|
@@ -1,18 +1,43 @@
|
|
|
1
1
|
import { Type } from "./Type.js";
|
|
2
2
|
export class Variable {
|
|
3
3
|
_type;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this._type = _type;
|
|
7
|
-
this._assignable = _assignable;
|
|
4
|
+
constructor(type) {
|
|
5
|
+
this._type = type;
|
|
8
6
|
}
|
|
9
7
|
get type() {
|
|
10
|
-
return this._type;
|
|
8
|
+
return this._type ?? Type.Any;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
this._type
|
|
10
|
+
get declared() {
|
|
11
|
+
return Boolean(this._type);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class LocalVariable extends Variable {
|
|
15
|
+
_assignable;
|
|
16
|
+
constructor(type, assignable) {
|
|
17
|
+
super(type);
|
|
18
|
+
this._assignable = assignable ?? false;
|
|
19
|
+
}
|
|
20
|
+
declare(type) {
|
|
21
|
+
if (!this._type) {
|
|
22
|
+
this._type = type;
|
|
23
|
+
}
|
|
14
24
|
}
|
|
15
25
|
get assignable() {
|
|
16
26
|
return this._assignable;
|
|
17
27
|
}
|
|
18
28
|
}
|
|
29
|
+
export class InputVariable extends Variable {
|
|
30
|
+
_declared;
|
|
31
|
+
constructor(type) {
|
|
32
|
+
super(type);
|
|
33
|
+
this._declared = Boolean(type);
|
|
34
|
+
}
|
|
35
|
+
declare(type) {
|
|
36
|
+
if (!this._declared) {
|
|
37
|
+
this._type = this._type ? Type.union(this._type, type) : type;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
get declared() {
|
|
41
|
+
return this._declared;
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dst/atom/ArrayAtom.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { IAtom } from "
|
|
1
|
+
import { IAtom } from "./Atom.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
3
|
export declare class ArrayAtom implements IAtom {
|
|
4
|
-
protected readonly _valTypes: Type[];
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
private _intersectLength;
|
|
4
|
+
protected readonly _valTypes: Type | readonly Type[];
|
|
5
|
+
constructor(valTypes?: Type | readonly Type[]);
|
|
6
|
+
get isUniform(): boolean;
|
|
8
7
|
get isTuple(): boolean;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
get types(): Type | readonly Type[];
|
|
9
|
+
valTypes(): readonly Type[];
|
|
10
|
+
valType(index: number | undefined): Type | undefined;
|
|
11
|
+
equals(atom: IAtom): boolean;
|
|
12
|
+
accepts(atom: IAtom): boolean;
|
|
13
|
+
intersects(atom: IAtom): boolean;
|
|
14
14
|
weight(): number;
|
|
15
15
|
toString(): string;
|
|
16
16
|
}
|
package/dst/atom/ArrayAtom.js
CHANGED
|
@@ -1,73 +1,79 @@
|
|
|
1
1
|
import { Type } from "../Type.js";
|
|
2
2
|
export class ArrayAtom {
|
|
3
3
|
_valTypes;
|
|
4
|
-
constructor(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
constructor(valTypes = []) {
|
|
5
|
+
if (Array.isArray(valTypes)) {
|
|
6
|
+
this._valTypes = valTypes.length === 0 ? Type.Any : [...valTypes];
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
this._valTypes = valTypes;
|
|
10
|
+
}
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
return !
|
|
12
|
+
get isUniform() {
|
|
13
|
+
return !Array.isArray(this._valTypes);
|
|
12
14
|
}
|
|
13
15
|
get isTuple() {
|
|
14
|
-
return this._valTypes
|
|
16
|
+
return Array.isArray(this._valTypes);
|
|
15
17
|
}
|
|
16
|
-
|
|
18
|
+
get types() {
|
|
17
19
|
return this._valTypes;
|
|
18
20
|
}
|
|
21
|
+
valTypes() {
|
|
22
|
+
const types = this._valTypes;
|
|
23
|
+
return types instanceof Type ? [types] : types;
|
|
24
|
+
}
|
|
19
25
|
valType(index) {
|
|
20
|
-
|
|
26
|
+
const types = this._valTypes;
|
|
27
|
+
if (types instanceof Type) {
|
|
28
|
+
return types;
|
|
29
|
+
}
|
|
30
|
+
return index == null ? undefined : types[index];
|
|
21
31
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
equals(atom) {
|
|
33
|
+
if (!(atom instanceof ArrayAtom)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const types = this._valTypes;
|
|
37
|
+
const other = atom._valTypes;
|
|
38
|
+
if (types instanceof Type) {
|
|
39
|
+
return other instanceof Type && types.equals(other);
|
|
40
|
+
}
|
|
41
|
+
return !(other instanceof Type) &&
|
|
42
|
+
types.length === other.length &&
|
|
43
|
+
types.every((type, index) => type.equals(other[index]));
|
|
26
44
|
}
|
|
27
|
-
|
|
28
|
-
if (atom instanceof ArrayAtom) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
? atom.valType(i) ?? Type.Void
|
|
36
|
-
: atom.valType(0);
|
|
37
|
-
if (!vtype || !this._valTypes[i].accept(vtype)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
for (let i = 0; i < atom.valTypes().length; ++i) {
|
|
44
|
-
const vtype = atom.valType(i);
|
|
45
|
-
if (!vtype || !this._valTypes[0].accept(vtype)) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
45
|
+
accepts(atom) {
|
|
46
|
+
if (!(atom instanceof ArrayAtom)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const types = this._valTypes;
|
|
50
|
+
const other = atom._valTypes;
|
|
51
|
+
if (types instanceof Type) {
|
|
52
|
+
return atom.valTypes().every((type) => types.accepts(type));
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
if (other instanceof Type) {
|
|
55
|
+
return types.every((type) => type.isOptional && type.accepts(other));
|
|
56
|
+
}
|
|
57
|
+
return types.every((type, index) => type.accepts(other[index] ?? Type.Null));
|
|
53
58
|
}
|
|
54
|
-
|
|
59
|
+
intersects(atom) {
|
|
55
60
|
if (!(atom instanceof ArrayAtom)) {
|
|
56
61
|
return false;
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
const types = this._valTypes;
|
|
64
|
+
const other = atom._valTypes;
|
|
65
|
+
if (types instanceof Type) {
|
|
66
|
+
// Any two uniform arrays can both be empty.
|
|
67
|
+
return other instanceof Type || atom.intersects(this);
|
|
60
68
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
&& this._intersectLength(i)
|
|
70
|
-
&& atom._intersectLength(i);
|
|
69
|
+
for (let index = 0; index < types.length; ++index) {
|
|
70
|
+
const otherType = other instanceof Type ? other : other[index];
|
|
71
|
+
if (!otherType) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (!types[index].intersects(otherType)) {
|
|
75
|
+
return types.slice(index).every((type) => type.isOptional) &&
|
|
76
|
+
(other instanceof Type || other.slice(index).every((type) => type.isOptional));
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
return true;
|
|
@@ -76,9 +82,10 @@ export class ArrayAtom {
|
|
|
76
82
|
return 0x10000 + this.valTypes().reduce((acc, i) => acc + i.weight(), 0);
|
|
77
83
|
}
|
|
78
84
|
toString() {
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
const types = this._valTypes;
|
|
86
|
+
if (types instanceof Type) {
|
|
87
|
+
return types.isAny ? "[]" : `[...${types}]`;
|
|
81
88
|
}
|
|
82
|
-
return `[${
|
|
89
|
+
return `[${types.join(",")}]`;
|
|
83
90
|
}
|
|
84
91
|
}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { IAtom } from "
|
|
1
|
+
import { IAtom } from "./Atom.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
|
+
import { FunctionSignature } from "./FunctionSignature.js";
|
|
4
|
+
export { FunctionSignature };
|
|
3
5
|
export declare class FunctionAtom implements IAtom {
|
|
4
|
-
protected readonly
|
|
5
|
-
protected readonly
|
|
6
|
-
|
|
7
|
-
protected readonly _minArity: number;
|
|
8
|
-
constructor(_retType?: Type, _argTypes?: Type[], _isVariadic?: boolean);
|
|
9
|
-
private get _undefined();
|
|
10
|
-
get retType(): Type;
|
|
11
|
-
get minArity(): number;
|
|
12
|
-
get maxArity(): number;
|
|
6
|
+
protected readonly _signatures: readonly FunctionSignature[];
|
|
7
|
+
protected readonly _isVolatile: boolean;
|
|
8
|
+
constructor(signatures: readonly [retType: Type, argTypes: readonly Type[], variadic?: boolean][], volatile?: boolean);
|
|
13
9
|
get isVariadic(): boolean;
|
|
14
|
-
get
|
|
10
|
+
get isVolatile(): boolean;
|
|
11
|
+
signatures(argc?: number): FunctionSignature[];
|
|
12
|
+
retType(): Type;
|
|
15
13
|
argType(index: number): Type | undefined;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
firstArgOptional(): FunctionAtom;
|
|
15
|
+
equals(atom: IAtom): boolean;
|
|
16
|
+
accepts(atom: IAtom): boolean;
|
|
17
|
+
intersects(atom: IAtom): boolean;
|
|
20
18
|
weight(): number;
|
|
21
19
|
toString(): string;
|
|
22
20
|
}
|
package/dst/atom/FunctionAtom.js
CHANGED
|
@@ -1,125 +1,74 @@
|
|
|
1
1
|
import { Type } from "../Type.js";
|
|
2
|
+
import { FunctionSignature } from "./FunctionSignature.js";
|
|
3
|
+
export { FunctionSignature };
|
|
2
4
|
export class FunctionAtom {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this._retType = _retType;
|
|
9
|
-
this._argTypes = _argTypes;
|
|
10
|
-
this._isVariadic = _isVariadic;
|
|
11
|
-
let ix = 0;
|
|
12
|
-
while (ix < _argTypes.length && !_argTypes[ix].isOptional) {
|
|
13
|
-
++ix;
|
|
5
|
+
_signatures;
|
|
6
|
+
_isVolatile;
|
|
7
|
+
constructor(signatures, volatile = false) {
|
|
8
|
+
if (!signatures.length) {
|
|
9
|
+
throw new Error("a function must have at least one signature");
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (ix < _argTypes.length) {
|
|
21
|
-
throw new Error("a required parameter illegally follows an optional one");
|
|
11
|
+
const unique = [];
|
|
12
|
+
for (const s of signatures) {
|
|
13
|
+
const signature = new FunctionSignature(...s);
|
|
14
|
+
if (!unique.some((i) => i.equate(signature))) {
|
|
15
|
+
unique.push(signature);
|
|
22
16
|
}
|
|
23
17
|
}
|
|
18
|
+
this._signatures = unique;
|
|
19
|
+
this._isVolatile = volatile;
|
|
24
20
|
}
|
|
25
|
-
get
|
|
26
|
-
return this.
|
|
27
|
-
}
|
|
28
|
-
get retType() {
|
|
29
|
-
return this._retType;
|
|
30
|
-
}
|
|
31
|
-
get minArity() {
|
|
32
|
-
return this._minArity;
|
|
21
|
+
get isVariadic() {
|
|
22
|
+
return this._signatures.every((signature) => signature.isVariadic);
|
|
33
23
|
}
|
|
34
|
-
get
|
|
35
|
-
return this.
|
|
24
|
+
get isVolatile() {
|
|
25
|
+
return this._isVolatile;
|
|
36
26
|
}
|
|
37
|
-
|
|
38
|
-
return this.
|
|
27
|
+
signatures(argc) {
|
|
28
|
+
return this._signatures.filter((signature) => argc === undefined || signature.minArity <= argc && argc <= signature.maxArity);
|
|
39
29
|
}
|
|
40
|
-
|
|
41
|
-
return this.
|
|
30
|
+
retType() {
|
|
31
|
+
return Type.union(...this._signatures.map((signature) => signature.retType));
|
|
42
32
|
}
|
|
43
33
|
argType(index) {
|
|
44
|
-
|
|
34
|
+
const types = this._signatures.map((signature) => signature.argType(index)).filter((type) => type !== undefined);
|
|
35
|
+
return types.length ? Type.union(...types) : undefined;
|
|
45
36
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
37
|
+
firstArgOptional() {
|
|
38
|
+
const signatures = this._signatures.flatMap((signature) => {
|
|
39
|
+
const retType = signature.retType.toOptional();
|
|
40
|
+
const argTypes = [...signature.argTypes];
|
|
41
|
+
if (signature.isVariadic && signature.arity === 1) {
|
|
42
|
+
return argTypes[0].arrayAtoms().map((array) => {
|
|
43
|
+
const itemType = array.valTypes()[0];
|
|
44
|
+
return [retType, [itemType.toOptional(), Type.arrayType(itemType)], true];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (argTypes.length) {
|
|
48
|
+
argTypes[0] = argTypes[0].toOptional();
|
|
49
|
+
}
|
|
50
|
+
return [[retType, argTypes, signature.isVariadic]];
|
|
51
|
+
});
|
|
52
|
+
return new FunctionAtom(signatures, this._isVolatile);
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
return atom instanceof FunctionAtom
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
&& this._argTypes.every((type, index) => type.equate(atom._argTypes[index]));
|
|
54
|
+
equals(atom) {
|
|
55
|
+
return atom instanceof FunctionAtom &&
|
|
56
|
+
this._isVolatile === atom._isVolatile &&
|
|
57
|
+
this._signatures.length === atom._signatures.length &&
|
|
58
|
+
this._signatures.every((signature) => atom._signatures.some((i) => signature.equate(i)));
|
|
66
59
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
if (this._undefined || atom._undefined) {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
if (this._isVariadic !== atom._isVariadic
|
|
75
|
-
|| this._isVariadic && this.arity !== atom.arity
|
|
76
|
-
|| !this._retType.accept(atom._retType)
|
|
77
|
-
|| this.minArity > atom.maxArity
|
|
78
|
-
|| this.maxArity < atom.minArity) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const argc = Math.min(this.arity, atom.arity);
|
|
82
|
-
for (let i = 0; i < argc; ++i) {
|
|
83
|
-
const type = this.argType(i)?.toMandatory();
|
|
84
|
-
const atype = atom.argType(i);
|
|
85
|
-
if (type && (!atype || !atype.accept(type))) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return true;
|
|
60
|
+
accepts(atom) {
|
|
61
|
+
return atom instanceof FunctionAtom &&
|
|
62
|
+
this._signatures.every((signature) => atom._signatures.some((i) => signature.accept(i)));
|
|
90
63
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
if (this._undefined || atom._undefined) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
if (this._isVariadic !== atom._isVariadic
|
|
99
|
-
|| this._isVariadic && this.arity !== atom.arity
|
|
100
|
-
|| !this._retType.intersect(atom._retType)
|
|
101
|
-
|| this.minArity > atom.maxArity
|
|
102
|
-
|| this.maxArity < atom.minArity) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
const argc = Math.max(this.minArity, atom.minArity);
|
|
106
|
-
for (let i = 0; i < argc; ++i) {
|
|
107
|
-
const type = this.argType(i);
|
|
108
|
-
const atype = atom.argType(i);
|
|
109
|
-
if (!type || !atype || !type.intersect(atype)) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return true;
|
|
64
|
+
intersects(atom) {
|
|
65
|
+
return atom instanceof FunctionAtom &&
|
|
66
|
+
this._signatures.some((signature) => atom._signatures.some((i) => signature.intersect(i)));
|
|
114
67
|
}
|
|
115
68
|
weight() {
|
|
116
|
-
return 0x1000000000000 + this.
|
|
69
|
+
return 0x1000000000000 + this._signatures.reduce((acc, signature) => acc + signature.weight(), 0);
|
|
117
70
|
}
|
|
118
71
|
toString() {
|
|
119
|
-
|
|
120
|
-
return "function";
|
|
121
|
-
}
|
|
122
|
-
const argTypes = this._argTypes.map((i, ix) => ix === this._argTypes.length - 1 && this.isVariadic ? `...${i.toString()}` : i.toString()).join(",");
|
|
123
|
-
return `~(${argTypes}):${this._retType.toString()}`;
|
|
72
|
+
return this._signatures.map((signature) => signature.toString()).join("&");
|
|
124
73
|
}
|
|
125
74
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Type } from "../Type.js";
|
|
2
|
+
export declare class FunctionSignature {
|
|
3
|
+
protected readonly _retType: Type;
|
|
4
|
+
protected readonly _argTypes: readonly Type[];
|
|
5
|
+
protected readonly _minArity: number;
|
|
6
|
+
protected readonly _isVariadic: boolean;
|
|
7
|
+
constructor(retType: Type, argTypes?: readonly Type[], variadic?: boolean);
|
|
8
|
+
get retType(): Type;
|
|
9
|
+
get argTypes(): readonly Type[];
|
|
10
|
+
get minArity(): number;
|
|
11
|
+
get maxArity(): number;
|
|
12
|
+
get arity(): number;
|
|
13
|
+
get isVariadic(): boolean;
|
|
14
|
+
get isGeneric(): boolean;
|
|
15
|
+
argType(index: number): Type | undefined;
|
|
16
|
+
paramType(index: number): Type | undefined;
|
|
17
|
+
acceptsVariadic(argTypes: readonly Type[]): boolean;
|
|
18
|
+
equate(signature: FunctionSignature): boolean;
|
|
19
|
+
accept(signature: FunctionSignature): boolean;
|
|
20
|
+
intersect(signature: FunctionSignature): boolean;
|
|
21
|
+
weight(): number;
|
|
22
|
+
toString(): string;
|
|
23
|
+
}
|