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/cjs/node/CastNode.js
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CastNode = void 0;
|
|
4
|
-
const Node_js_1 = require("
|
|
4
|
+
const Node_js_1 = require("./Node.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
6
|
class CastNode extends Node_js_1.Node {
|
|
7
7
|
_subnode;
|
|
8
|
-
_target;
|
|
9
8
|
_type;
|
|
10
|
-
constructor(span,
|
|
9
|
+
constructor(span, subnode, type) {
|
|
11
10
|
super(span);
|
|
12
|
-
this._subnode =
|
|
13
|
-
this.
|
|
14
|
-
this._type = _target;
|
|
11
|
+
this._subnode = subnode;
|
|
12
|
+
this._type = type;
|
|
15
13
|
}
|
|
16
14
|
get type() {
|
|
17
|
-
return this._type;
|
|
15
|
+
return this._subnode.type.isNever ? Type_js_1.Type.Never : this._type;
|
|
18
16
|
}
|
|
19
|
-
compile(type) {
|
|
20
|
-
this._subnode = this._subnode.compile(Type_js_1.Type.
|
|
21
|
-
if (
|
|
22
|
-
this.throwError(
|
|
17
|
+
compile(type = Type_js_1.Type.Any) {
|
|
18
|
+
this._subnode = this._subnode.compile(Type_js_1.Type.Any);
|
|
19
|
+
if (this._subnode.type.isNever) {
|
|
20
|
+
this._subnode.throwError("cast operand must produce a value");
|
|
23
21
|
}
|
|
24
|
-
this._type
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
if (!this._subnode.type.intersects(this._type)) {
|
|
23
|
+
this.throwError(`cannot cast type ${this._subnode.type} to type ${this._type}`);
|
|
24
|
+
}
|
|
25
|
+
return super.compile(type);
|
|
27
26
|
}
|
|
28
27
|
evaluate(frame) {
|
|
29
28
|
const value = this._subnode.evaluate(frame);
|
|
30
|
-
if (!this._type.
|
|
31
|
-
this.throwError(`cannot cast value of type ${Type_js_1.Type.of(value)} to ${this._type}`);
|
|
29
|
+
if (!this._type.acceptsValue(value)) {
|
|
30
|
+
this.throwError(`cannot cast value of type ${Type_js_1.Type.of(value)} to type ${this._type}`);
|
|
32
31
|
}
|
|
33
32
|
return value;
|
|
34
33
|
}
|
|
@@ -36,7 +35,7 @@ class CastNode extends Node_js_1.Node {
|
|
|
36
35
|
return this._subnode.constant;
|
|
37
36
|
}
|
|
38
37
|
toString(ident = 0) {
|
|
39
|
-
return `${super.toString(ident)} cast node target
|
|
38
|
+
return `${super.toString(ident)} cast node target type ${this._type}:\n${this._subnode.toString(ident + 1)}`;
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
exports.CastNode = CastNode;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { Node } from "
|
|
2
|
-
import {
|
|
1
|
+
import { Node } from "./Node.js";
|
|
2
|
+
import { ParserSpan } from "../ParserSpan.js";
|
|
3
3
|
import { Constant } from "../Constant.js";
|
|
4
4
|
import { Value } from "../Value.js";
|
|
5
5
|
import { Type } from "../Type.js";
|
|
6
6
|
import { CallFrame } from "../CallFrame.js";
|
|
7
7
|
export declare class ConstantNode extends Node {
|
|
8
8
|
protected readonly _constant: Constant;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(span: ScriptSpan, _constant: Constant, _subnode?: Node | undefined, _factory?: ((frame: CallFrame) => Value) | undefined);
|
|
9
|
+
constructor(span: ParserSpan, constant: Constant);
|
|
10
|
+
get value(): Value;
|
|
12
11
|
get type(): Type;
|
|
13
|
-
compile(type: Type): Node;
|
|
14
12
|
evaluate(frame: CallFrame): Value;
|
|
15
13
|
get constant(): boolean;
|
|
16
14
|
toString(ident?: number): string;
|
|
@@ -1,35 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConstantNode = void 0;
|
|
4
|
-
const Node_js_1 = require("
|
|
4
|
+
const Node_js_1 = require("./Node.js");
|
|
5
5
|
class ConstantNode extends Node_js_1.Node {
|
|
6
6
|
_constant;
|
|
7
|
-
|
|
8
|
-
_factory;
|
|
9
|
-
constructor(span, _constant, _subnode, _factory) {
|
|
7
|
+
constructor(span, constant) {
|
|
10
8
|
super(span);
|
|
11
|
-
this._constant =
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
this._constant = constant;
|
|
10
|
+
}
|
|
11
|
+
get value() {
|
|
12
|
+
return this._constant.value;
|
|
14
13
|
}
|
|
15
14
|
get type() {
|
|
16
15
|
return this._constant.type;
|
|
17
16
|
}
|
|
18
|
-
compile(type) {
|
|
19
|
-
this._constant.type = this.reduceType(type);
|
|
20
|
-
this._subnode = this._subnode?.compile(this._constant.type.functionAtomRetType(type));
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
17
|
evaluate(frame) {
|
|
24
|
-
return
|
|
18
|
+
return frame.define(this._constant.value, this.type);
|
|
25
19
|
}
|
|
26
20
|
get constant() {
|
|
27
|
-
return !this.
|
|
21
|
+
return !this._constant.type.isVolatileFunction;
|
|
28
22
|
}
|
|
29
23
|
toString(ident = 0) {
|
|
30
|
-
return
|
|
31
|
-
? `${super.toString(ident)} constant node subnode:\n${this._subnode.toString(ident + 1)}`
|
|
32
|
-
: `${super.toString(ident)} constant node`;
|
|
24
|
+
return `${super.toString(ident)} constant node`;
|
|
33
25
|
}
|
|
34
26
|
}
|
|
35
27
|
exports.ConstantNode = ConstantNode;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Node } from "./Node.js";
|
|
2
|
+
import { ParserSpan } from "../ParserSpan.js";
|
|
3
|
+
import { Value } from "../Value.js";
|
|
4
|
+
import { Type } from "../Type.js";
|
|
5
|
+
import { CallFrame } from "../CallFrame.js";
|
|
6
|
+
export declare class FinalNode extends Node {
|
|
7
|
+
protected _level: "result" | "return";
|
|
8
|
+
protected _subnode: Node;
|
|
9
|
+
protected readonly _type: Type;
|
|
10
|
+
protected _value: Value;
|
|
11
|
+
constructor(span: ParserSpan, level: "result" | "return", subnode: Node, type: Type);
|
|
12
|
+
get level(): "result" | "return";
|
|
13
|
+
get value(): Value;
|
|
14
|
+
get valueType(): Type;
|
|
15
|
+
get type(): Type;
|
|
16
|
+
compile(): Node;
|
|
17
|
+
evaluate(frame: CallFrame): Value;
|
|
18
|
+
toString(ident?: number): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FinalNode = void 0;
|
|
4
|
+
const Node_js_1 = require("./Node.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
class FinalNode extends Node_js_1.Node {
|
|
7
|
+
_level;
|
|
8
|
+
_subnode;
|
|
9
|
+
_type;
|
|
10
|
+
_value;
|
|
11
|
+
constructor(span, level, subnode, type) {
|
|
12
|
+
super(span);
|
|
13
|
+
this._level = level;
|
|
14
|
+
this._subnode = subnode;
|
|
15
|
+
this._type = type;
|
|
16
|
+
}
|
|
17
|
+
get level() {
|
|
18
|
+
return this._level;
|
|
19
|
+
}
|
|
20
|
+
get value() {
|
|
21
|
+
return this._value;
|
|
22
|
+
}
|
|
23
|
+
get valueType() {
|
|
24
|
+
return this._subnode.type;
|
|
25
|
+
}
|
|
26
|
+
get type() {
|
|
27
|
+
return Type_js_1.Type.Never;
|
|
28
|
+
}
|
|
29
|
+
compile() {
|
|
30
|
+
this._subnode = this._subnode.compile(this._type);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
evaluate(frame) {
|
|
34
|
+
this._value = this._subnode.evaluate(frame);
|
|
35
|
+
throw this;
|
|
36
|
+
}
|
|
37
|
+
toString(ident = 0) {
|
|
38
|
+
return `${super.toString(ident)} ${this._level} node subnode:\n${this._subnode.toString(ident + 1)}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.FinalNode = FinalNode;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Node } from "./Node.js";
|
|
2
|
+
import { ParserSpan } from "../ParserSpan.js";
|
|
3
|
+
import { Variable } from "../Variable.js";
|
|
4
|
+
import { Type } from "../Type.js";
|
|
5
|
+
import { Value } from "../Value.js";
|
|
6
|
+
import { CallFrame } from "../CallFrame.js";
|
|
7
|
+
export declare class FunctionNode extends Node {
|
|
8
|
+
protected _subnode: Node;
|
|
9
|
+
protected readonly _variables: readonly Variable[];
|
|
10
|
+
protected readonly _arguments: readonly Variable[];
|
|
11
|
+
protected _type: Type;
|
|
12
|
+
constructor(span: ParserSpan, subnode: Node, variables: readonly Variable[], args: readonly Variable[], type: Type);
|
|
13
|
+
get type(): Type;
|
|
14
|
+
compile(type?: Type): Node;
|
|
15
|
+
evaluate(frame: CallFrame): Value;
|
|
16
|
+
toString(ident?: number): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FunctionNode = void 0;
|
|
4
|
+
const Node_js_1 = require("./Node.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
const FinalNode_js_1 = require("./FinalNode.js");
|
|
7
|
+
class FunctionNode extends Node_js_1.Node {
|
|
8
|
+
_subnode;
|
|
9
|
+
_variables;
|
|
10
|
+
_arguments;
|
|
11
|
+
_type;
|
|
12
|
+
constructor(span, subnode, variables, args, type) {
|
|
13
|
+
super(span);
|
|
14
|
+
this._subnode = subnode;
|
|
15
|
+
this._arguments = args;
|
|
16
|
+
this._variables = variables;
|
|
17
|
+
this._type = type;
|
|
18
|
+
}
|
|
19
|
+
get type() {
|
|
20
|
+
return this._type;
|
|
21
|
+
}
|
|
22
|
+
compile(type = Type_js_1.Type.Any) {
|
|
23
|
+
const retType = this._type.functionAtomRetType() ?? Type_js_1.Type.Any;
|
|
24
|
+
this._subnode = this._subnode.compile(retType);
|
|
25
|
+
return super.compile(type);
|
|
26
|
+
}
|
|
27
|
+
evaluate(frame) {
|
|
28
|
+
const index = this._type.isVariadicFunction ? this._arguments.length - 1 : -1;
|
|
29
|
+
return (...values) => {
|
|
30
|
+
frame.timer();
|
|
31
|
+
const subframe = frame.subframe(this._variables);
|
|
32
|
+
try {
|
|
33
|
+
this._arguments.forEach((arg, ix) => {
|
|
34
|
+
subframe.set(arg, ix === index ? values.slice(ix) : values[ix]);
|
|
35
|
+
});
|
|
36
|
+
return this._subnode.evaluate(subframe);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
if (e instanceof FinalNode_js_1.FinalNode && e.level === "return") {
|
|
40
|
+
return e.value;
|
|
41
|
+
}
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
toString(ident = 0) {
|
|
47
|
+
return `${super.toString(ident)} function node subnode:\n`
|
|
48
|
+
+ this._subnode.toString(ident + 1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.FunctionNode = FunctionNode;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvocationNode = void 0;
|
|
4
|
+
const Node_js_1 = require("./Node.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
class InvocationNode extends Node_js_1.Node {
|
|
7
|
+
compileArguments(functionType, args, compiledCount = 0) {
|
|
8
|
+
const argc = args.length;
|
|
9
|
+
const candidateGroups = functionType.functionAtoms().map((atom) => atom.signatures(argc));
|
|
10
|
+
const candidates = candidateGroups.flat();
|
|
11
|
+
let hints = candidates.filter((signature) => args.every((node, index) => node.type.isNever || node.type.intersects(signature.paramType(index) ?? Type_js_1.Type.Any)));
|
|
12
|
+
for (let i = compiledCount; i < argc; ++i) {
|
|
13
|
+
const parameters = (hints.length ? hints : candidates).map((signature) => signature.paramType(i) ?? Type_js_1.Type.Any);
|
|
14
|
+
const union = Type_js_1.Type.union(...parameters);
|
|
15
|
+
// An inferred union must fit a candidate parameter to stay a concrete type.
|
|
16
|
+
const hint = parameters.some((type) => type.accepts(union)) ? union : Type_js_1.Type.Any;
|
|
17
|
+
const node = args[i] = args[i].compile(hint);
|
|
18
|
+
hints = hints.filter((signature) => node.type.isNever || node.type.intersects(signature.paramType(i) ?? Type_js_1.Type.Any));
|
|
19
|
+
}
|
|
20
|
+
const compiledArgTypes = args.map((node) => node.type);
|
|
21
|
+
if (functionType.isNever || functionType.isFunction && compiledArgTypes.some((type) => type.isNever)) {
|
|
22
|
+
return Type_js_1.Type.Never;
|
|
23
|
+
}
|
|
24
|
+
const groups = candidateGroups.map((group) => group.filter((signature) => args.every((node, i) => node.satisfies(signature.paramType(i) ?? Type_js_1.Type.Any)) &&
|
|
25
|
+
signature.acceptsVariadic(compiledArgTypes)));
|
|
26
|
+
if (!functionType.isFunction || groups.some((group) => !group.length)) {
|
|
27
|
+
this.throwError(`value of type ${functionType} cannot be called with ${argc} argument(s)`);
|
|
28
|
+
}
|
|
29
|
+
const dynamic = compiledArgTypes.some((type) => type.isAny);
|
|
30
|
+
const signatures = groups.flatMap((group) => dynamic ? group : group.slice(0, 1));
|
|
31
|
+
return Type_js_1.Type.union(...signatures.map((signature) => signature.retType));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.InvocationNode = InvocationNode;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { Node } from "
|
|
2
|
-
import {
|
|
1
|
+
import { Node } from "./Node.js";
|
|
2
|
+
import { ParserSpan } from "../ParserSpan.js";
|
|
3
3
|
import { Value } from "../Value.js";
|
|
4
4
|
import { Type } from "../Type.js";
|
|
5
|
-
import { Jump } from "../Jump.js";
|
|
6
5
|
import { CallFrame } from "../CallFrame.js";
|
|
7
6
|
export declare class JumpNode extends Node {
|
|
8
|
-
protected
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(span: ScriptSpan, _jump: Jump, _subnode?: Node | undefined, _type?: Type | undefined);
|
|
7
|
+
protected _action: "exit" | "next";
|
|
8
|
+
constructor(span: ParserSpan, action: "exit" | "next");
|
|
9
|
+
get action(): "next" | "exit";
|
|
12
10
|
get type(): Type;
|
|
13
|
-
compile(
|
|
14
|
-
evaluate(
|
|
11
|
+
compile(): Node;
|
|
12
|
+
evaluate(_: CallFrame): Value;
|
|
15
13
|
toString(ident?: number): string;
|
|
16
14
|
}
|
package/dst/cjs/node/JumpNode.js
CHANGED
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JumpNode = void 0;
|
|
4
|
-
const Node_js_1 = require("
|
|
4
|
+
const Node_js_1 = require("./Node.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
|
-
const JumpException_js_1 = require("../JumpException.js");
|
|
7
6
|
class JumpNode extends Node_js_1.Node {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
_type;
|
|
11
|
-
constructor(span, _jump, _subnode, _type) {
|
|
7
|
+
_action;
|
|
8
|
+
constructor(span, action) {
|
|
12
9
|
super(span);
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
this._action = action;
|
|
11
|
+
}
|
|
12
|
+
get action() {
|
|
13
|
+
return this._action;
|
|
16
14
|
}
|
|
17
15
|
get type() {
|
|
18
|
-
return
|
|
16
|
+
return Type_js_1.Type.Never;
|
|
19
17
|
}
|
|
20
|
-
compile(
|
|
21
|
-
this._subnode = this._subnode?.compile(this._jump === "exit" || this._jump === "return"
|
|
22
|
-
? this._type ?? Type_js_1.Type.Unknown
|
|
23
|
-
: type);
|
|
18
|
+
compile() {
|
|
24
19
|
return this;
|
|
25
20
|
}
|
|
26
|
-
evaluate(
|
|
27
|
-
throw
|
|
21
|
+
evaluate(_) {
|
|
22
|
+
throw this;
|
|
28
23
|
}
|
|
29
24
|
toString(ident = 0) {
|
|
30
|
-
return this.
|
|
31
|
-
? `${super.toString(ident)} ${this._jump} node subnode:\n${this._subnode.toString(ident + 1)}`
|
|
32
|
-
: `${super.toString(ident)} ${this._jump} node`;
|
|
25
|
+
return `${super.toString(ident)} ${this._action} node`;
|
|
33
26
|
}
|
|
34
27
|
}
|
|
35
28
|
exports.JumpNode = JumpNode;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { Node } from "
|
|
2
|
-
import {
|
|
1
|
+
import { Node } from "./Node.js";
|
|
2
|
+
import { ParserSpan } from "../ParserSpan.js";
|
|
3
3
|
import { Value } from "../Value.js";
|
|
4
4
|
import { Type } from "../Type.js";
|
|
5
5
|
import { CallFrame } from "../CallFrame.js";
|
|
6
6
|
export declare class LoopNode extends Node {
|
|
7
|
-
protected _cnode: Node;
|
|
8
7
|
protected _subnode: Node;
|
|
9
|
-
|
|
8
|
+
protected _wnode: Node | undefined;
|
|
9
|
+
protected _unode: Node | undefined;
|
|
10
|
+
constructor(span: ParserSpan, subnode: Node, wnode: Node | undefined, unode: Node | undefined);
|
|
10
11
|
get type(): Type;
|
|
11
|
-
|
|
12
|
+
satisfies(type: Type): boolean;
|
|
13
|
+
compile(type?: Type): Node;
|
|
12
14
|
evaluate(frame: CallFrame): Value;
|
|
13
15
|
toString(ident?: number): string;
|
|
14
16
|
}
|
package/dst/cjs/node/LoopNode.js
CHANGED
|
@@ -1,48 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LoopNode = void 0;
|
|
4
|
-
const Node_js_1 = require("
|
|
4
|
+
const Node_js_1 = require("./Node.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
|
-
const
|
|
6
|
+
const JumpNode_js_1 = require("./JumpNode.js");
|
|
7
7
|
class LoopNode extends Node_js_1.Node {
|
|
8
|
-
_cnode;
|
|
9
8
|
_subnode;
|
|
10
|
-
|
|
9
|
+
_wnode;
|
|
10
|
+
_unode;
|
|
11
|
+
constructor(span, subnode, wnode, unode) {
|
|
11
12
|
super(span);
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
13
|
+
this._subnode = subnode;
|
|
14
|
+
this._wnode = wnode;
|
|
15
|
+
this._unode = unode;
|
|
14
16
|
}
|
|
15
17
|
get type() {
|
|
16
|
-
return this._subnode.type;
|
|
18
|
+
return this._wnode?.type.isNever ? Type_js_1.Type.Never : this._subnode.type.toOptional();
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
satisfies(type) {
|
|
21
|
+
return this.type.isNever || super.satisfies(type) && this._subnode.satisfies(type);
|
|
22
|
+
}
|
|
23
|
+
compile(type = Type_js_1.Type.Any) {
|
|
24
|
+
this._wnode = this._wnode?.compile(Type_js_1.Type.Boolean);
|
|
25
|
+
this._unode = this._unode?.compile(Type_js_1.Type.Boolean);
|
|
26
|
+
this._subnode = this._subnode.compile(this._wnode?.type.isNever ? Type_js_1.Type.Any : type);
|
|
27
|
+
return super.compile(type);
|
|
22
28
|
}
|
|
23
29
|
evaluate(frame) {
|
|
24
30
|
let result = undefined;
|
|
25
|
-
while (
|
|
31
|
+
while (true) {
|
|
32
|
+
frame.timer();
|
|
33
|
+
if (this._wnode && !this._wnode.evaluate(frame)) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
26
36
|
try {
|
|
27
37
|
result = this._subnode.evaluate(frame);
|
|
28
38
|
}
|
|
29
39
|
catch (e) {
|
|
30
|
-
if (e instanceof
|
|
31
|
-
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
if (e.jump === "next") {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
40
|
+
if (!(e instanceof JumpNode_js_1.JumpNode)) {
|
|
41
|
+
throw e;
|
|
37
42
|
}
|
|
38
|
-
|
|
43
|
+
if (e.action === "exit") {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (this._unode && this._unode.evaluate(frame)) {
|
|
48
|
+
break;
|
|
39
49
|
}
|
|
40
50
|
}
|
|
41
51
|
return result;
|
|
42
52
|
}
|
|
43
53
|
toString(ident = 0) {
|
|
44
|
-
return `${super.toString(ident)} loop node
|
|
45
|
-
|
|
54
|
+
return `${super.toString(ident)} loop node subnode:\n${this._subnode.toString(ident + 1)}` +
|
|
55
|
+
(this._wnode ? `\n${super.toString(ident)} loop node while node:\n${this._wnode.toString(ident + 1)}` : "") +
|
|
56
|
+
(this._unode ? `\n${super.toString(ident)} loop node until node:\n${this._unode.toString(ident + 1)}` : "");
|
|
46
57
|
}
|
|
47
58
|
}
|
|
48
59
|
exports.LoopNode = LoopNode;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Node } from "./Node.js";
|
|
2
|
+
import { ParserSpan } from "../ParserSpan.js";
|
|
3
|
+
import { Type } from "../Type.js";
|
|
4
|
+
import { Value } from "../Value.js";
|
|
5
|
+
import { CallFrame } from "../CallFrame.js";
|
|
6
|
+
export declare class MatchNode extends Node {
|
|
7
|
+
protected _vnode: Node;
|
|
8
|
+
protected _subnodes: [Node, Node][];
|
|
9
|
+
protected _enode: Node;
|
|
10
|
+
constructor(span: ParserSpan, vnode: Node, subnodes: [Node, Node][], enode?: Node);
|
|
11
|
+
get type(): Type;
|
|
12
|
+
satisfies(type: Type): boolean;
|
|
13
|
+
compile(type?: Type): Node;
|
|
14
|
+
evaluate(frame: CallFrame): Value;
|
|
15
|
+
toString(ident?: number): string;
|
|
16
|
+
private _results;
|
|
17
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MatchNode = void 0;
|
|
4
|
+
const Node_js_1 = require("./Node.js");
|
|
5
|
+
const ConstantNode_js_1 = require("./ConstantNode.js");
|
|
6
|
+
const Constant_js_1 = require("../Constant.js");
|
|
7
|
+
const Type_js_1 = require("../Type.js");
|
|
8
|
+
const Unknown_js_1 = require("../native/Unknown.js");
|
|
9
|
+
class MatchNode extends Node_js_1.Node {
|
|
10
|
+
_vnode;
|
|
11
|
+
_subnodes;
|
|
12
|
+
_enode;
|
|
13
|
+
constructor(span, vnode, subnodes, enode = new ConstantNode_js_1.ConstantNode(span, Constant_js_1.Constant.Null)) {
|
|
14
|
+
super(span);
|
|
15
|
+
this._vnode = vnode;
|
|
16
|
+
this._subnodes = subnodes;
|
|
17
|
+
this._enode = enode;
|
|
18
|
+
}
|
|
19
|
+
get type() {
|
|
20
|
+
const results = this._results();
|
|
21
|
+
return results.length ? Type_js_1.Type.union(...results.map((node) => node.type)) : Type_js_1.Type.Never;
|
|
22
|
+
}
|
|
23
|
+
satisfies(type) {
|
|
24
|
+
return this._results().every((node) => node.satisfies(type));
|
|
25
|
+
}
|
|
26
|
+
compile(type = Type_js_1.Type.Any) {
|
|
27
|
+
this._vnode = this._vnode.compile();
|
|
28
|
+
let reachable = !this._vnode.type.isNever;
|
|
29
|
+
this._subnodes = this._subnodes.map(([key, result]) => {
|
|
30
|
+
const compiledKey = key.compile();
|
|
31
|
+
reachable &&= !compiledKey.type.isNever;
|
|
32
|
+
return [compiledKey, result.compile(reachable ? type : Type_js_1.Type.Any)];
|
|
33
|
+
});
|
|
34
|
+
this._enode = this._enode.compile(reachable ? type : Type_js_1.Type.Any);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
evaluate(frame) {
|
|
38
|
+
const subject = this._vnode.evaluate(frame);
|
|
39
|
+
for (const [key, result] of this._subnodes) {
|
|
40
|
+
if ((0, Unknown_js_1.equals)(subject, key.evaluate(frame))) {
|
|
41
|
+
return result.evaluate(frame);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return this._enode.evaluate(frame);
|
|
45
|
+
}
|
|
46
|
+
toString(ident = 0) {
|
|
47
|
+
const children = [this._vnode, ...this._subnodes.flat(), this._enode];
|
|
48
|
+
return `${super.toString(ident)} match node:\n` + children.map((node) => node.toString(ident + 1)).join("\n");
|
|
49
|
+
}
|
|
50
|
+
_results() {
|
|
51
|
+
const results = [];
|
|
52
|
+
if (this._vnode.type.isNever) {
|
|
53
|
+
return results;
|
|
54
|
+
}
|
|
55
|
+
for (const [key, value] of this._subnodes) {
|
|
56
|
+
if (key.type.isNever) {
|
|
57
|
+
return results;
|
|
58
|
+
}
|
|
59
|
+
results.push(value);
|
|
60
|
+
}
|
|
61
|
+
results.push(this._enode);
|
|
62
|
+
return results;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.MatchNode = MatchNode;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ParserSpan } from "../ParserSpan.js";
|
|
2
|
+
import { Type } from "../Type.js";
|
|
3
|
+
import { Value } from "../Value.js";
|
|
4
|
+
import { CallFrame } from "../CallFrame.js";
|
|
5
|
+
export declare abstract class Node extends ParserSpan {
|
|
6
|
+
constructor(span: ParserSpan);
|
|
7
|
+
get type(): Type;
|
|
8
|
+
compile(type?: Type): Node;
|
|
9
|
+
abstract evaluate(frame: CallFrame): Value;
|
|
10
|
+
satisfies(type: Type): boolean;
|
|
11
|
+
get constant(): boolean;
|
|
12
|
+
toString(ident?: number): string;
|
|
13
|
+
protected _throwTypeError(type: Type): never;
|
|
14
|
+
}
|
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Node = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const ParserSpan_js_1 = require("../ParserSpan.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
class Node extends ParserSpan_js_1.ParserSpan {
|
|
6
7
|
constructor(span) {
|
|
7
8
|
super(span);
|
|
8
9
|
}
|
|
9
|
-
get
|
|
10
|
-
return
|
|
10
|
+
get type() {
|
|
11
|
+
return Type_js_1.Type.Null;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return compiledType;
|
|
13
|
+
compile(type = Type_js_1.Type.Any) {
|
|
14
|
+
if (!this.satisfies(type)) {
|
|
15
|
+
this._throwTypeError(type);
|
|
16
16
|
}
|
|
17
|
-
this
|
|
17
|
+
return this;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
return
|
|
19
|
+
satisfies(type) {
|
|
20
|
+
return type.accepts(this.type);
|
|
21
|
+
}
|
|
22
|
+
get constant() {
|
|
23
|
+
return false;
|
|
21
24
|
}
|
|
22
25
|
toString(ident = 0) {
|
|
23
26
|
return " ".repeat(ident) + `[${this._start}:${this._end}] <${this.type}>`;
|
|
24
27
|
}
|
|
28
|
+
_throwTypeError(type) {
|
|
29
|
+
return this.throwError(`type ${this.type} mismatch with expected type ${type}`);
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
32
|
exports.Node = Node;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { Node } from "
|
|
2
|
-
import {
|
|
1
|
+
import { Node } from "./Node.js";
|
|
2
|
+
import { ParserSpan } from "../ParserSpan.js";
|
|
3
3
|
import { Value } from "../Value.js";
|
|
4
4
|
import { Type } from "../Type.js";
|
|
5
5
|
import { CallFrame } from "../CallFrame.js";
|
|
6
6
|
export declare class ObjectNode extends Node {
|
|
7
7
|
protected _subnodes: [Node, Node][];
|
|
8
|
+
protected _uniform: boolean;
|
|
8
9
|
protected _type: Type;
|
|
9
|
-
constructor(span:
|
|
10
|
+
constructor(span: ParserSpan, subnodes: [Node, Node][], uniform?: boolean);
|
|
10
11
|
get type(): Type;
|
|
11
|
-
|
|
12
|
+
satisfies(type: Type): boolean;
|
|
13
|
+
compile(type?: Type): Node;
|
|
12
14
|
evaluate(frame: CallFrame): Value;
|
|
15
|
+
get constant(): boolean;
|
|
13
16
|
toString(ident?: number): string;
|
|
14
17
|
}
|