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.
Files changed (243) hide show
  1. package/.cache/arrow-preview-vWvB5K/affinirum-arrow-functions.patch +155 -0
  2. package/.cache/function-syntax-tests.log +20 -0
  3. package/README.md +925 -355
  4. package/dst/Affinirum.d.ts +29 -19
  5. package/dst/Affinirum.js +399 -334
  6. package/dst/CallFrame.d.ts +12 -3
  7. package/dst/CallFrame.js +49 -10
  8. package/dst/Constant.d.ts +1 -3
  9. package/dst/Constant.js +3 -8
  10. package/dst/LexicalScope.d.ts +11 -9
  11. package/dst/LexicalScope.js +10 -6
  12. package/dst/ParserSpan.d.ts +11 -0
  13. package/dst/{ScriptSpan.js → ParserSpan.js} +8 -5
  14. package/dst/ParserState.d.ts +28 -49
  15. package/dst/ParserState.js +256 -489
  16. package/dst/Type.d.ts +34 -17
  17. package/dst/Type.js +211 -115
  18. package/dst/TypeParser.d.ts +9 -0
  19. package/dst/TypeParser.js +127 -0
  20. package/dst/Value.d.ts +1 -1
  21. package/dst/Value.js +21 -10
  22. package/dst/Variable.d.ts +16 -5
  23. package/dst/Variable.js +32 -7
  24. package/dst/atom/ArrayAtom.d.ts +10 -10
  25. package/dst/atom/ArrayAtom.js +62 -55
  26. package/dst/atom/Atom.d.ts +7 -0
  27. package/dst/atom/FunctionAtom.d.ts +13 -15
  28. package/dst/atom/FunctionAtom.js +53 -104
  29. package/dst/atom/FunctionSignature.d.ts +23 -0
  30. package/dst/atom/FunctionSignature.js +124 -0
  31. package/dst/atom/ObjectAtom.d.ts +11 -9
  32. package/dst/atom/ObjectAtom.js +73 -33
  33. package/dst/atom/PrimitiveAtom.d.ts +6 -7
  34. package/dst/atom/PrimitiveAtom.js +7 -10
  35. package/dst/cjs/Affinirum.d.ts +29 -19
  36. package/dst/cjs/Affinirum.js +398 -333
  37. package/dst/cjs/CallFrame.d.ts +12 -3
  38. package/dst/cjs/CallFrame.js +49 -10
  39. package/dst/cjs/Constant.d.ts +1 -3
  40. package/dst/cjs/Constant.js +3 -8
  41. package/dst/cjs/LexicalScope.d.ts +11 -9
  42. package/dst/cjs/LexicalScope.js +10 -6
  43. package/dst/cjs/ParserSpan.d.ts +11 -0
  44. package/dst/cjs/{ScriptSpan.js → ParserSpan.js} +10 -7
  45. package/dst/cjs/ParserState.d.ts +28 -49
  46. package/dst/cjs/ParserState.js +255 -488
  47. package/dst/cjs/Type.d.ts +34 -17
  48. package/dst/cjs/Type.js +211 -115
  49. package/dst/cjs/TypeParser.d.ts +9 -0
  50. package/dst/cjs/TypeParser.js +131 -0
  51. package/dst/cjs/Value.d.ts +1 -1
  52. package/dst/cjs/Value.js +21 -10
  53. package/dst/cjs/Variable.d.ts +16 -5
  54. package/dst/cjs/Variable.js +36 -9
  55. package/dst/cjs/atom/ArrayAtom.d.ts +10 -10
  56. package/dst/cjs/atom/ArrayAtom.js +62 -55
  57. package/dst/cjs/atom/Atom.d.ts +7 -0
  58. package/dst/cjs/atom/FunctionAtom.d.ts +13 -15
  59. package/dst/cjs/atom/FunctionAtom.js +54 -105
  60. package/dst/cjs/atom/FunctionSignature.d.ts +23 -0
  61. package/dst/cjs/atom/FunctionSignature.js +128 -0
  62. package/dst/cjs/atom/ObjectAtom.d.ts +11 -9
  63. package/dst/cjs/atom/ObjectAtom.js +73 -33
  64. package/dst/cjs/atom/PrimitiveAtom.d.ts +6 -7
  65. package/dst/cjs/atom/PrimitiveAtom.js +7 -10
  66. package/dst/cjs/dictionary/Constants.d.ts +2 -0
  67. package/dst/cjs/dictionary/Constants.js +27 -0
  68. package/dst/cjs/dictionary/Functions.d.ts +2 -0
  69. package/dst/cjs/{Functions.js → dictionary/Functions.js} +27 -25
  70. package/dst/cjs/native/Aggregable.js +10 -2
  71. package/dst/cjs/native/Array.d.ts +2 -3
  72. package/dst/cjs/native/Array.js +38 -39
  73. package/dst/cjs/native/Boolean.d.ts +1 -1
  74. package/dst/cjs/native/Boolean.js +13 -10
  75. package/dst/cjs/native/Buffer.d.ts +5 -5
  76. package/dst/cjs/native/Buffer.js +70 -46
  77. package/dst/cjs/native/Composite.d.ts +5 -0
  78. package/dst/cjs/native/Composite.js +35 -0
  79. package/dst/cjs/native/Enumerable.js +20 -8
  80. package/dst/cjs/native/Float.d.ts +3 -1
  81. package/dst/cjs/native/Float.js +51 -12
  82. package/dst/cjs/native/Integer.d.ts +4 -2
  83. package/dst/cjs/native/Integer.js +60 -25
  84. package/dst/cjs/native/Iterable.d.ts +0 -2
  85. package/dst/cjs/native/Iterable.js +9 -28
  86. package/dst/cjs/native/Number.d.ts +0 -2
  87. package/dst/cjs/native/Number.js +34 -48
  88. package/dst/cjs/native/Object.d.ts +1 -1
  89. package/dst/cjs/native/Object.js +5 -6
  90. package/dst/cjs/native/String.d.ts +7 -6
  91. package/dst/cjs/native/String.js +28 -27
  92. package/dst/cjs/native/Timestamp.d.ts +3 -3
  93. package/dst/cjs/native/Timestamp.js +34 -36
  94. package/dst/cjs/native/Unknown.d.ts +3 -3
  95. package/dst/cjs/native/Unknown.js +48 -17
  96. package/dst/cjs/native/notation/AN.d.ts +1 -1
  97. package/dst/cjs/native/notation/AN.js +37 -35
  98. package/dst/cjs/native/notation/IP.d.ts +1 -1
  99. package/dst/cjs/native/notation/IP.js +11 -12
  100. package/dst/cjs/native/notation/JSON.d.ts +1 -1
  101. package/dst/cjs/native/notation/JSON.js +7 -6
  102. package/dst/cjs/node/AccessNode.d.ts +24 -0
  103. package/dst/cjs/node/AccessNode.js +193 -0
  104. package/dst/cjs/node/ArrayNode.d.ts +7 -4
  105. package/dst/cjs/node/ArrayNode.js +26 -15
  106. package/dst/cjs/node/AssignableNode.d.ts +16 -0
  107. package/dst/cjs/node/AssignableNode.js +18 -0
  108. package/dst/cjs/node/AssignmentNode.d.ts +20 -0
  109. package/dst/cjs/node/AssignmentNode.js +66 -0
  110. package/dst/cjs/node/BlockNode.d.ts +5 -4
  111. package/dst/cjs/node/BlockNode.js +18 -11
  112. package/dst/cjs/node/CallNode.d.ts +7 -5
  113. package/dst/cjs/node/CallNode.js +40 -41
  114. package/dst/cjs/node/CastNode.d.ts +5 -6
  115. package/dst/cjs/node/CastNode.js +16 -17
  116. package/dst/cjs/node/ConstantNode.d.ts +4 -6
  117. package/dst/cjs/node/ConstantNode.js +9 -17
  118. package/dst/cjs/node/FinalNode.d.ts +19 -0
  119. package/dst/cjs/node/FinalNode.js +41 -0
  120. package/dst/cjs/node/FunctionNode.d.ts +17 -0
  121. package/dst/cjs/node/FunctionNode.js +51 -0
  122. package/dst/cjs/node/InvocationNode.d.ts +5 -0
  123. package/dst/cjs/node/InvocationNode.js +34 -0
  124. package/dst/cjs/node/JumpNode.d.ts +7 -9
  125. package/dst/cjs/node/JumpNode.js +12 -19
  126. package/dst/cjs/node/LoopNode.d.ts +7 -5
  127. package/dst/cjs/node/LoopNode.js +33 -22
  128. package/dst/cjs/node/MatchNode.d.ts +17 -0
  129. package/dst/cjs/node/MatchNode.js +65 -0
  130. package/dst/cjs/node/Node.d.ts +14 -0
  131. package/dst/cjs/{Node.js → node/Node.js} +17 -11
  132. package/dst/cjs/node/ObjectNode.d.ts +7 -4
  133. package/dst/cjs/node/ObjectNode.js +42 -11
  134. package/dst/cjs/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
  135. package/dst/cjs/node/TernaryNode.js +45 -0
  136. package/dst/cjs/node/VariableNode.d.ts +10 -6
  137. package/dst/cjs/node/VariableNode.js +50 -16
  138. package/dst/dictionary/Constants.d.ts +2 -0
  139. package/dst/dictionary/Constants.js +24 -0
  140. package/dst/dictionary/Functions.d.ts +2 -0
  141. package/dst/{Functions.js → dictionary/Functions.js} +26 -24
  142. package/dst/native/Aggregable.js +11 -3
  143. package/dst/native/Array.d.ts +2 -3
  144. package/dst/native/Array.js +37 -38
  145. package/dst/native/Boolean.d.ts +1 -1
  146. package/dst/native/Boolean.js +12 -9
  147. package/dst/native/Buffer.d.ts +5 -5
  148. package/dst/native/Buffer.js +66 -42
  149. package/dst/native/Composite.d.ts +5 -0
  150. package/dst/native/Composite.js +32 -0
  151. package/dst/native/Enumerable.js +20 -8
  152. package/dst/native/Float.d.ts +3 -1
  153. package/dst/native/Float.js +48 -11
  154. package/dst/native/Integer.d.ts +4 -2
  155. package/dst/native/Integer.js +56 -23
  156. package/dst/native/Iterable.d.ts +0 -2
  157. package/dst/native/Iterable.js +8 -27
  158. package/dst/native/Number.d.ts +0 -2
  159. package/dst/native/Number.js +34 -46
  160. package/dst/native/Object.d.ts +1 -1
  161. package/dst/native/Object.js +4 -5
  162. package/dst/native/String.d.ts +7 -6
  163. package/dst/native/String.js +24 -24
  164. package/dst/native/Timestamp.d.ts +3 -3
  165. package/dst/native/Timestamp.js +31 -33
  166. package/dst/native/Unknown.d.ts +3 -3
  167. package/dst/native/Unknown.js +49 -18
  168. package/dst/native/notation/AN.d.ts +1 -1
  169. package/dst/native/notation/AN.js +37 -35
  170. package/dst/native/notation/IP.d.ts +1 -1
  171. package/dst/native/notation/IP.js +10 -11
  172. package/dst/native/notation/JSON.d.ts +1 -1
  173. package/dst/native/notation/JSON.js +6 -5
  174. package/dst/node/AccessNode.d.ts +24 -0
  175. package/dst/node/AccessNode.js +189 -0
  176. package/dst/node/ArrayNode.d.ts +7 -4
  177. package/dst/node/ArrayNode.js +26 -15
  178. package/dst/node/AssignableNode.d.ts +16 -0
  179. package/dst/node/AssignableNode.js +14 -0
  180. package/dst/node/AssignmentNode.d.ts +20 -0
  181. package/dst/node/AssignmentNode.js +62 -0
  182. package/dst/node/BlockNode.d.ts +5 -4
  183. package/dst/node/BlockNode.js +18 -11
  184. package/dst/node/CallNode.d.ts +7 -5
  185. package/dst/node/CallNode.js +40 -41
  186. package/dst/node/CastNode.d.ts +5 -6
  187. package/dst/node/CastNode.js +16 -17
  188. package/dst/node/ConstantNode.d.ts +4 -6
  189. package/dst/node/ConstantNode.js +9 -17
  190. package/dst/node/FinalNode.d.ts +19 -0
  191. package/dst/node/FinalNode.js +37 -0
  192. package/dst/node/FunctionNode.d.ts +17 -0
  193. package/dst/node/FunctionNode.js +47 -0
  194. package/dst/node/InvocationNode.d.ts +5 -0
  195. package/dst/node/InvocationNode.js +30 -0
  196. package/dst/node/JumpNode.d.ts +7 -9
  197. package/dst/node/JumpNode.js +12 -19
  198. package/dst/node/LoopNode.d.ts +7 -5
  199. package/dst/node/LoopNode.js +33 -22
  200. package/dst/node/MatchNode.d.ts +17 -0
  201. package/dst/node/MatchNode.js +61 -0
  202. package/dst/node/Node.d.ts +14 -0
  203. package/dst/node/Node.js +28 -0
  204. package/dst/node/ObjectNode.d.ts +7 -4
  205. package/dst/node/ObjectNode.js +42 -11
  206. package/dst/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
  207. package/dst/node/TernaryNode.js +41 -0
  208. package/dst/node/VariableNode.d.ts +10 -6
  209. package/dst/node/VariableNode.js +50 -16
  210. package/package.json +4 -4
  211. package/dst/Atom.d.ts +0 -7
  212. package/dst/Constants.d.ts +0 -2
  213. package/dst/Constants.js +0 -24
  214. package/dst/Functions.d.ts +0 -2
  215. package/dst/Jump.d.ts +0 -1
  216. package/dst/Jump.js +0 -1
  217. package/dst/JumpException.d.ts +0 -9
  218. package/dst/JumpException.js +0 -14
  219. package/dst/Keywords.d.ts +0 -1
  220. package/dst/Keywords.js +0 -17
  221. package/dst/Node.d.ts +0 -14
  222. package/dst/Node.js +0 -22
  223. package/dst/ScriptSpan.d.ts +0 -10
  224. package/dst/cjs/Atom.d.ts +0 -7
  225. package/dst/cjs/Constants.d.ts +0 -2
  226. package/dst/cjs/Constants.js +0 -27
  227. package/dst/cjs/Functions.d.ts +0 -2
  228. package/dst/cjs/Jump.d.ts +0 -1
  229. package/dst/cjs/Jump.js +0 -2
  230. package/dst/cjs/JumpException.d.ts +0 -9
  231. package/dst/cjs/JumpException.js +0 -18
  232. package/dst/cjs/Keywords.d.ts +0 -1
  233. package/dst/cjs/Keywords.js +0 -20
  234. package/dst/cjs/Node.d.ts +0 -14
  235. package/dst/cjs/ScriptSpan.d.ts +0 -10
  236. package/dst/cjs/node/SwitchNode.js +0 -49
  237. package/dst/cjs/node/VariadicNode.d.ts +0 -4
  238. package/dst/cjs/node/VariadicNode.js +0 -10
  239. package/dst/node/SwitchNode.js +0 -45
  240. package/dst/node/VariadicNode.d.ts +0 -4
  241. package/dst/node/VariadicNode.js +0 -6
  242. /package/dst/{Atom.js → atom/Atom.js} +0 -0
  243. /package/dst/cjs/{Atom.js → atom/Atom.js} +0 -0
package/dst/Node.js DELETED
@@ -1,22 +0,0 @@
1
- import { ScriptSpan } from "./ScriptSpan.js";
2
- export class Node extends ScriptSpan {
3
- constructor(span) {
4
- super(span);
5
- }
6
- get constant() {
7
- return false;
8
- }
9
- reduceType(type) {
10
- const compiledType = this.type.reduce(type);
11
- if (compiledType) {
12
- return compiledType;
13
- }
14
- this.throwTypeError(type);
15
- }
16
- throwTypeError(type) {
17
- return this.throwError(`type ${this.type} mismatch with expected type ${type}`);
18
- }
19
- toString(ident = 0) {
20
- return " ".repeat(ident) + `[${this._start}:${this._end}] <${this.type}>`;
21
- }
22
- }
@@ -1,10 +0,0 @@
1
- export declare class ScriptSpan {
2
- protected readonly _script: string;
3
- protected _start: number;
4
- protected _end: number;
5
- protected constructor(span: ScriptSpan | string);
6
- start(): ScriptSpan;
7
- end(span: ScriptSpan): this;
8
- throwError(message: string): never;
9
- toString(): string;
10
- }
package/dst/cjs/Atom.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export interface IAtom {
2
- equate(atom: IAtom): boolean;
3
- accept(atom: IAtom): boolean;
4
- intersect(atom: IAtom): boolean;
5
- weight(): number;
6
- toString(): string;
7
- }
@@ -1,2 +0,0 @@
1
- import { Constant } from "./Constant.js";
2
- export declare const Constants: [string, Record<string, Constant>][];
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Constants = void 0;
4
- const Array_js_1 = require("./native/Array.js");
5
- const Boolean_js_1 = require("./native/Boolean.js");
6
- const Buffer_js_1 = require("./native/Buffer.js");
7
- const Integer_js_1 = require("./native/Integer.js");
8
- const Float_js_1 = require("./native/Float.js");
9
- const Object_js_1 = require("./native/Object.js");
10
- const String_js_1 = require("./native/String.js");
11
- const Timestamp_js_1 = require("./native/Timestamp.js");
12
- const AN_js_1 = require("./native/notation/AN.js");
13
- const IP_js_1 = require("./native/notation/IP.js");
14
- const JSON_js_1 = require("./native/notation/JSON.js");
15
- exports.Constants = [
16
- ["Array", Array_js_1.constArray],
17
- ["Boolean", Boolean_js_1.constBoolean],
18
- ["Buffer", Buffer_js_1.constBuffer],
19
- ["Float", Float_js_1.constFloat],
20
- ["Integer", Integer_js_1.constInteger],
21
- ["Object", Object_js_1.constObject],
22
- ["String", String_js_1.constString],
23
- ["Timestamp", Timestamp_js_1.constTimestamp],
24
- ["AN", AN_js_1.constAN],
25
- ["IP", IP_js_1.constIP],
26
- ["JSON", JSON_js_1.constJSON],
27
- ];
@@ -1,2 +0,0 @@
1
- import { Constant } from "./Constant.js";
2
- export declare const Functions: [string, Constant][];
package/dst/cjs/Jump.d.ts DELETED
@@ -1 +0,0 @@
1
- export type Jump = "exit" | "return" | "stop" | "next";
package/dst/cjs/Jump.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import { Jump } from "./Jump.js";
2
- import { Value } from "./Value.js";
3
- export declare class JumpException {
4
- private readonly _jump;
5
- private readonly _value?;
6
- constructor(_jump: Jump, _value?: Value);
7
- get jump(): Jump;
8
- get value(): Value;
9
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JumpException = void 0;
4
- class JumpException {
5
- _jump;
6
- _value;
7
- constructor(_jump, _value) {
8
- this._jump = _jump;
9
- this._value = _value;
10
- }
11
- get jump() {
12
- return this._jump;
13
- }
14
- get value() {
15
- return this._value;
16
- }
17
- }
18
- exports.JumpException = JumpException;
@@ -1 +0,0 @@
1
- export declare const Keywords: string[];
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Keywords = void 0;
4
- exports.Keywords = [
5
- "true", "false",
6
- "null", "void",
7
- "bool", "boolean",
8
- "time", "timestamp",
9
- "f64", "float",
10
- "i64", "integer",
11
- "buffer",
12
- "string",
13
- "array",
14
- "object",
15
- "function",
16
- "var",
17
- "val",
18
- "if", "else",
19
- "while", "stop", "next",
20
- ];
package/dst/cjs/Node.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { ScriptSpan } from "./ScriptSpan.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 ScriptSpan {
6
- constructor(span: ScriptSpan);
7
- abstract type: Type;
8
- abstract compile(type: Type): Node;
9
- abstract evaluate(frame: CallFrame): Value;
10
- get constant(): boolean;
11
- protected reduceType(type: Type): Type;
12
- protected throwTypeError(type: Type): never;
13
- toString(ident?: number): string;
14
- }
@@ -1,10 +0,0 @@
1
- export declare class ScriptSpan {
2
- protected readonly _script: string;
3
- protected _start: number;
4
- protected _end: number;
5
- protected constructor(span: ScriptSpan | string);
6
- start(): ScriptSpan;
7
- end(span: ScriptSpan): this;
8
- throwError(message: string): never;
9
- toString(): string;
10
- }
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwitchNode = void 0;
4
- const Node_js_1 = require("../Node.js");
5
- const Constant_js_1 = require("../Constant.js");
6
- const ConstantNode_js_1 = require("./ConstantNode.js");
7
- const Type_js_1 = require("../Type.js");
8
- const CallFrame_js_1 = require("../CallFrame.js");
9
- class SwitchNode extends Node_js_1.Node {
10
- _cnode;
11
- _subnodes;
12
- _type;
13
- constructor(span, _cnode, _subnodes) {
14
- super(span);
15
- this._cnode = _cnode;
16
- this._subnodes = _subnodes;
17
- if (_subnodes.length !== 2) {
18
- this.throwError(`switch requires 2 subnodes not ${_subnodes.length}`);
19
- }
20
- this._type = Type_js_1.Type.union(...this._subnodes.map((i) => i.type));
21
- }
22
- get type() {
23
- return Type_js_1.Type.union(...this._subnodes.map((i) => i.type));
24
- }
25
- compile(type) {
26
- this._cnode = this._cnode.compile(Type_js_1.Type.Boolean);
27
- this._type = type;
28
- let constant = this._cnode.constant;
29
- for (let i = 0; i < this._subnodes.length; ++i) {
30
- this._subnodes[i] = this._subnodes[i].compile(type);
31
- constant &&= this._subnodes[i].constant;
32
- }
33
- if (constant) {
34
- return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(new CallFrame_js_1.CallFrame()), this.type));
35
- }
36
- return this;
37
- }
38
- evaluate(frame) {
39
- return this._cnode.evaluate(frame)
40
- ? this._subnodes[0].evaluate(frame)
41
- : this._subnodes[1].evaluate(frame);
42
- }
43
- toString(ident = 0) {
44
- const subnodes = this._subnodes.map((s) => s.toString(ident + 1)).join("\n");
45
- return `${super.toString(ident)} switch node cnode:\n${this._cnode.toString(ident + 1)}\n`
46
- + `${super.toString(ident)} switch node subnodes:\n${subnodes}`;
47
- }
48
- }
49
- exports.SwitchNode = SwitchNode;
@@ -1,4 +0,0 @@
1
- import { ArrayNode } from "./ArrayNode.js";
2
- export declare class VariadicNode extends ArrayNode {
3
- get constant(): boolean;
4
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VariadicNode = void 0;
4
- const ArrayNode_js_1 = require("./ArrayNode.js");
5
- class VariadicNode extends ArrayNode_js_1.ArrayNode {
6
- get constant() {
7
- return this._subnodes.every((node) => node.constant);
8
- }
9
- }
10
- exports.VariadicNode = VariadicNode;
@@ -1,45 +0,0 @@
1
- import { Node } from "../Node.js";
2
- import { Constant } from "../Constant.js";
3
- import { ConstantNode } from "./ConstantNode.js";
4
- import { Type } from "../Type.js";
5
- import { CallFrame } from "../CallFrame.js";
6
- export class SwitchNode extends Node {
7
- _cnode;
8
- _subnodes;
9
- _type;
10
- constructor(span, _cnode, _subnodes) {
11
- super(span);
12
- this._cnode = _cnode;
13
- this._subnodes = _subnodes;
14
- if (_subnodes.length !== 2) {
15
- this.throwError(`switch requires 2 subnodes not ${_subnodes.length}`);
16
- }
17
- this._type = Type.union(...this._subnodes.map((i) => i.type));
18
- }
19
- get type() {
20
- return Type.union(...this._subnodes.map((i) => i.type));
21
- }
22
- compile(type) {
23
- this._cnode = this._cnode.compile(Type.Boolean);
24
- this._type = type;
25
- let constant = this._cnode.constant;
26
- for (let i = 0; i < this._subnodes.length; ++i) {
27
- this._subnodes[i] = this._subnodes[i].compile(type);
28
- constant &&= this._subnodes[i].constant;
29
- }
30
- if (constant) {
31
- return new ConstantNode(this, new Constant(this.evaluate(new CallFrame()), this.type));
32
- }
33
- return this;
34
- }
35
- evaluate(frame) {
36
- return this._cnode.evaluate(frame)
37
- ? this._subnodes[0].evaluate(frame)
38
- : this._subnodes[1].evaluate(frame);
39
- }
40
- toString(ident = 0) {
41
- const subnodes = this._subnodes.map((s) => s.toString(ident + 1)).join("\n");
42
- return `${super.toString(ident)} switch node cnode:\n${this._cnode.toString(ident + 1)}\n`
43
- + `${super.toString(ident)} switch node subnodes:\n${subnodes}`;
44
- }
45
- }
@@ -1,4 +0,0 @@
1
- import { ArrayNode } from "./ArrayNode.js";
2
- export declare class VariadicNode extends ArrayNode {
3
- get constant(): boolean;
4
- }
@@ -1,6 +0,0 @@
1
- import { ArrayNode } from "./ArrayNode.js";
2
- export class VariadicNode extends ArrayNode {
3
- get constant() {
4
- return this._subnodes.every((node) => node.constant);
5
- }
6
- }
File without changes
File without changes