affinirum 1.5.4 → 1.6.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 (44) hide show
  1. package/README.md +589 -316
  2. package/dst/Affinirum.d.ts +2 -2
  3. package/dst/Affinirum.js +22 -19
  4. package/dst/Functions.js +1 -3
  5. package/dst/Keywords.js +2 -1
  6. package/dst/Node.d.ts +1 -1
  7. package/dst/Node.js +4 -0
  8. package/dst/ParserState.d.ts +2 -2
  9. package/dst/ParserState.js +10 -10
  10. package/dst/cjs/Affinirum.d.ts +2 -2
  11. package/dst/cjs/Affinirum.js +22 -19
  12. package/dst/cjs/Functions.js +0 -2
  13. package/dst/cjs/Keywords.js +2 -1
  14. package/dst/cjs/Node.d.ts +1 -1
  15. package/dst/cjs/Node.js +4 -0
  16. package/dst/cjs/ParserState.d.ts +2 -2
  17. package/dst/cjs/ParserState.js +10 -10
  18. package/dst/cjs/native/Array.d.ts +0 -2
  19. package/dst/cjs/native/Array.js +5 -13
  20. package/dst/cjs/node/JumpNode.d.ts +5 -8
  21. package/dst/cjs/node/JumpNode.js +9 -20
  22. package/dst/cjs/node/LoopNode.js +4 -4
  23. package/dst/cjs/node/ReturnNode.d.ts +18 -0
  24. package/dst/cjs/node/ReturnNode.js +38 -0
  25. package/dst/cjs/node/{SwitchNode.d.ts → TernaryNode.d.ts} +1 -1
  26. package/dst/cjs/node/{SwitchNode.js → TernaryNode.js} +3 -3
  27. package/dst/native/Array.d.ts +0 -2
  28. package/dst/native/Array.js +4 -12
  29. package/dst/node/JumpNode.d.ts +5 -8
  30. package/dst/node/JumpNode.js +9 -20
  31. package/dst/node/LoopNode.js +4 -4
  32. package/dst/node/ReturnNode.d.ts +18 -0
  33. package/dst/node/ReturnNode.js +34 -0
  34. package/dst/node/{SwitchNode.d.ts → TernaryNode.d.ts} +1 -1
  35. package/dst/node/{SwitchNode.js → TernaryNode.js} +1 -1
  36. package/package.json +3 -3
  37. package/dst/Jump.d.ts +0 -1
  38. package/dst/Jump.js +0 -1
  39. package/dst/JumpException.d.ts +0 -9
  40. package/dst/JumpException.js +0 -14
  41. package/dst/cjs/Jump.d.ts +0 -1
  42. package/dst/cjs/Jump.js +0 -2
  43. package/dst/cjs/JumpException.d.ts +0 -9
  44. package/dst/cjs/JumpException.js +0 -18
@@ -4,7 +4,7 @@ import { Value } from "./Value.js";
4
4
  import { Type } from "./Type.js";
5
5
  import { Node } from "./Node.js";
6
6
  import { LoopNode } from "./node/LoopNode.js";
7
- import { SwitchNode } from "./node/SwitchNode.js";
7
+ import { TernaryNode } from "./node/TernaryNode.js";
8
8
  import { ScriptSpan } from "./ScriptSpan.js";
9
9
  import { ParserState } from "./ParserState.js";
10
10
  import { LexicalScope } from "./LexicalScope.js";
@@ -83,6 +83,6 @@ export declare class Affinirum {
83
83
  protected _term(state: ParserState, scope: LexicalScope): Node;
84
84
  protected _function(state: ParserState, scope: LexicalScope): Node;
85
85
  protected _loop(state: ParserState, scope: LexicalScope): LoopNode;
86
- protected _switch(state: ParserState, scope: LexicalScope): SwitchNode;
86
+ protected _ternary(state: ParserState, scope: LexicalScope): TernaryNode;
87
87
  protected _type(state: ParserState, scope: LexicalScope): Type;
88
88
  }
package/dst/Affinirum.js CHANGED
@@ -16,15 +16,15 @@ import { BlockNode } from "./node/BlockNode.js";
16
16
  import { CallNode } from "./node/CallNode.js";
17
17
  import { CastNode } from "./node/CastNode.js";
18
18
  import { ConstantNode } from "./node/ConstantNode.js";
19
+ import { ReturnNode } from "./node/ReturnNode.js";
19
20
  import { JumpNode } from "./node/JumpNode.js";
20
21
  import { LoopNode } from "./node/LoopNode.js";
21
22
  import { ObjectNode } from "./node/ObjectNode.js";
22
- import { SwitchNode } from "./node/SwitchNode.js";
23
+ import { TernaryNode } from "./node/TernaryNode.js";
23
24
  import { VariableNode } from "./node/VariableNode.js";
24
25
  import { ParserState } from "./ParserState.js";
25
26
  import { LexicalScope } from "./LexicalScope.js";
26
27
  import { CallFrame } from "./CallFrame.js";
27
- import { JumpException } from "./JumpException.js";
28
28
  export class Affinirum {
29
29
  static keywords = [...Keywords, ...Constants.map((c) => c[0])];
30
30
  _script;
@@ -111,14 +111,17 @@ export class Affinirum {
111
111
  return normalize(this._root.evaluate(frame) ?? undefined);
112
112
  }
113
113
  catch (e) {
114
- if (e instanceof JumpException) {
115
- if (e.jump === "exit") {
114
+ if (e instanceof ReturnNode) {
115
+ if (e.scope === "global") {
116
116
  return normalize(e.value ?? undefined);
117
117
  }
118
118
  else {
119
- throw this._root.throwError(`unexpected ${e.jump} jump`);
119
+ throw this._root.throwError(`unexpected ${e.scope} return`);
120
120
  }
121
121
  }
122
+ if (e instanceof JumpNode) {
123
+ this._root.throwError(`unexpected ${e.action} jump`);
124
+ }
122
125
  throw e;
123
126
  }
124
127
  }
@@ -448,19 +451,19 @@ export class Affinirum {
448
451
  return this._function(state, scope);
449
452
  }
450
453
  else if (state.isIf) {
451
- return this._switch(state, scope);
454
+ return this._ternary(state, scope);
452
455
  }
453
456
  else if (state.isWhile) {
454
457
  return this._loop(state, scope);
455
458
  }
456
- else if (state.isExit) {
457
- return new JumpNode(state, "exit", this._unit(state.next(), scope), this._scope.type());
458
- }
459
459
  else if (state.isReturn) {
460
- return new JumpNode(state, "return", this._unit(state.next(), scope), scope.type());
460
+ return new ReturnNode(state, "function", this._unit(state.next(), scope), scope.type());
461
+ }
462
+ else if (state.isResult) {
463
+ return new ReturnNode(state, "global", this._unit(state.next(), scope), this._scope.type());
461
464
  }
462
- else if (state.isStop) {
463
- const node = new JumpNode(state, "stop");
465
+ else if (state.isExit) {
466
+ const node = new JumpNode(state, "exit");
464
467
  state.next();
465
468
  return node;
466
469
  }
@@ -524,13 +527,13 @@ export class Affinirum {
524
527
  return normalize(subnode.evaluate(subframe));
525
528
  }
526
529
  catch (e) {
527
- if (e instanceof JumpException) {
528
- if (e.jump === "return") {
530
+ if (e instanceof ReturnNode) {
531
+ if (e.scope === "function") {
529
532
  return normalize(e.value);
530
533
  }
531
- if (e.jump === "stop" || e.jump === "next") {
532
- subnode.throwError(`unexpected ${e.jump} jump`);
533
- }
534
+ }
535
+ if (e instanceof JumpNode) {
536
+ subnode.throwError(`unexpected ${e.action} jump`);
534
537
  }
535
538
  throw e;
536
539
  }
@@ -544,7 +547,7 @@ export class Affinirum {
544
547
  span.end(state);
545
548
  return new LoopNode(span, cnode, this._unit(state, scope));
546
549
  }
547
- _switch(state, scope) {
550
+ _ternary(state, scope) {
548
551
  const span = state.start();
549
552
  const cnode = this._unit(state.next(), scope);
550
553
  span.end(state);
@@ -552,7 +555,7 @@ export class Affinirum {
552
555
  const celse = state.isElse
553
556
  ? this._unit(state.next(), scope)
554
557
  : new ConstantNode(state.start(), Constant.Null);
555
- return new SwitchNode(span, cnode, [cthen, celse]);
558
+ return new TernaryNode(span, cnode, [cthen, celse]);
556
559
  }
557
560
  _type(state, scope) {
558
561
  if (state.isType) { // literal type
package/dst/Functions.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { funcAdd } from "./native/Aggregable.js";
2
- import { funcFirst, funcLast, funcFirstIndex, funcLastIndex, funcEvery, funcAny, funcFlatten, funcReverse, funcDerive, funcFilter, funcReduce, funcCompose, funcPrepend, funcAppend } from "./native/Array.js";
2
+ import { funcFirst, funcLast, funcFirstIndex, funcLastIndex, funcEvery, funcAny, funcFlatten, funcReverse, funcDerive, funcFilter, funcReduce, funcCompose } from "./native/Array.js";
3
3
  import { funcBoolean } from "./native/Boolean.js";
4
4
  import { funcByte } from "./native/Buffer.js";
5
5
  import { funcSlice, funcSplice, funcInject } from "./native/Enumerable.js";
@@ -27,8 +27,6 @@ export const Functions = [
27
27
  ["Filter", funcFilter],
28
28
  ["Reduce", funcReduce],
29
29
  ["Compose", funcCompose],
30
- ["Prepend", funcPrepend],
31
- ["Append", funcAppend],
32
30
  // Buffer
33
31
  ["Byte", funcByte],
34
32
  // Enumerable
package/dst/Keywords.js CHANGED
@@ -13,5 +13,6 @@ export const Keywords = [
13
13
  "var",
14
14
  "val",
15
15
  "if", "else",
16
- "while", "stop", "next",
16
+ "while",
17
+ "next", "exit",
17
18
  ];
package/dst/Node.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Value } from "./Value.js";
4
4
  import { CallFrame } from "./CallFrame.js";
5
5
  export declare abstract class Node extends ScriptSpan {
6
6
  constructor(span: ScriptSpan);
7
- abstract type: Type;
7
+ get type(): Type;
8
8
  abstract compile(type: Type): Node;
9
9
  abstract evaluate(frame: CallFrame): Value;
10
10
  get constant(): boolean;
package/dst/Node.js CHANGED
@@ -1,8 +1,12 @@
1
1
  import { ScriptSpan } from "./ScriptSpan.js";
2
+ import { Type } from "./Type.js";
2
3
  export class Node extends ScriptSpan {
3
4
  constructor(span) {
4
5
  super(span);
5
6
  }
7
+ get type() {
8
+ return Type.Void;
9
+ }
6
10
  get constant() {
7
11
  return false;
8
12
  }
@@ -42,9 +42,9 @@ export declare class ParserState extends ScriptSpan {
42
42
  get isIf(): boolean;
43
43
  get isElse(): boolean;
44
44
  get isWhile(): boolean;
45
- get isExit(): boolean;
45
+ get isResult(): boolean;
46
46
  get isReturn(): boolean;
47
- get isStop(): boolean;
47
+ get isExit(): boolean;
48
48
  get isNext(): boolean;
49
49
  get isEmpty(): boolean;
50
50
  openParentheses(): this;
@@ -50,9 +50,9 @@ const idVal = Symbol();
50
50
  const idIf = Symbol();
51
51
  const idElse = Symbol();
52
52
  const idWhile = Symbol();
53
- const idExit = Symbol();
53
+ const idResult = Symbol();
54
54
  const idReturn = Symbol();
55
- const idStop = Symbol();
55
+ const idExit = Symbol();
56
56
  const idNext = Symbol();
57
57
  export class ParserState extends ScriptSpan {
58
58
  _fragment;
@@ -146,14 +146,14 @@ export class ParserState extends ScriptSpan {
146
146
  get isWhile() {
147
147
  return this._fragment === idWhile;
148
148
  }
149
- get isExit() {
150
- return this._fragment === idExit;
149
+ get isResult() {
150
+ return this._fragment === idResult;
151
151
  }
152
152
  get isReturn() {
153
153
  return this._fragment === idReturn;
154
154
  }
155
- get isStop() {
156
- return this._fragment === idStop;
155
+ get isExit() {
156
+ return this._fragment === idExit;
157
157
  }
158
158
  get isNext() {
159
159
  return this._fragment === idNext;
@@ -347,7 +347,7 @@ export class ParserState extends ScriptSpan {
347
347
  break;
348
348
  case ">":
349
349
  ++this._end;
350
- this._fragment = idExit;
350
+ this._fragment = idResult;
351
351
  break;
352
352
  default:
353
353
  this._fragment = funcAssignment;
@@ -534,12 +534,12 @@ export class ParserState extends ScriptSpan {
534
534
  case "while":
535
535
  this._fragment = idWhile;
536
536
  break;
537
- case "stop":
538
- this._fragment = idStop;
539
- break;
540
537
  case "next":
541
538
  this._fragment = idNext;
542
539
  break;
540
+ case "exit":
541
+ this._fragment = idExit;
542
+ break;
543
543
  default:
544
544
  this._fragment = token;
545
545
  break;
@@ -4,7 +4,7 @@ import { Value } from "./Value.js";
4
4
  import { Type } from "./Type.js";
5
5
  import { Node } from "./Node.js";
6
6
  import { LoopNode } from "./node/LoopNode.js";
7
- import { SwitchNode } from "./node/SwitchNode.js";
7
+ import { TernaryNode } from "./node/TernaryNode.js";
8
8
  import { ScriptSpan } from "./ScriptSpan.js";
9
9
  import { ParserState } from "./ParserState.js";
10
10
  import { LexicalScope } from "./LexicalScope.js";
@@ -83,6 +83,6 @@ export declare class Affinirum {
83
83
  protected _term(state: ParserState, scope: LexicalScope): Node;
84
84
  protected _function(state: ParserState, scope: LexicalScope): Node;
85
85
  protected _loop(state: ParserState, scope: LexicalScope): LoopNode;
86
- protected _switch(state: ParserState, scope: LexicalScope): SwitchNode;
86
+ protected _ternary(state: ParserState, scope: LexicalScope): TernaryNode;
87
87
  protected _type(state: ParserState, scope: LexicalScope): Type;
88
88
  }
@@ -19,15 +19,15 @@ const BlockNode_js_1 = require("./node/BlockNode.js");
19
19
  const CallNode_js_1 = require("./node/CallNode.js");
20
20
  const CastNode_js_1 = require("./node/CastNode.js");
21
21
  const ConstantNode_js_1 = require("./node/ConstantNode.js");
22
+ const ReturnNode_js_1 = require("./node/ReturnNode.js");
22
23
  const JumpNode_js_1 = require("./node/JumpNode.js");
23
24
  const LoopNode_js_1 = require("./node/LoopNode.js");
24
25
  const ObjectNode_js_1 = require("./node/ObjectNode.js");
25
- const SwitchNode_js_1 = require("./node/SwitchNode.js");
26
+ const TernaryNode_js_1 = require("./node/TernaryNode.js");
26
27
  const VariableNode_js_1 = require("./node/VariableNode.js");
27
28
  const ParserState_js_1 = require("./ParserState.js");
28
29
  const LexicalScope_js_1 = require("./LexicalScope.js");
29
30
  const CallFrame_js_1 = require("./CallFrame.js");
30
- const JumpException_js_1 = require("./JumpException.js");
31
31
  class Affinirum {
32
32
  static keywords = [...Keywords_js_1.Keywords, ...Constants_js_1.Constants.map((c) => c[0])];
33
33
  _script;
@@ -114,14 +114,17 @@ class Affinirum {
114
114
  return (0, Value_js_1.normalize)(this._root.evaluate(frame) ?? undefined);
115
115
  }
116
116
  catch (e) {
117
- if (e instanceof JumpException_js_1.JumpException) {
118
- if (e.jump === "exit") {
117
+ if (e instanceof ReturnNode_js_1.ReturnNode) {
118
+ if (e.scope === "global") {
119
119
  return (0, Value_js_1.normalize)(e.value ?? undefined);
120
120
  }
121
121
  else {
122
- throw this._root.throwError(`unexpected ${e.jump} jump`);
122
+ throw this._root.throwError(`unexpected ${e.scope} return`);
123
123
  }
124
124
  }
125
+ if (e instanceof JumpNode_js_1.JumpNode) {
126
+ this._root.throwError(`unexpected ${e.action} jump`);
127
+ }
125
128
  throw e;
126
129
  }
127
130
  }
@@ -451,19 +454,19 @@ class Affinirum {
451
454
  return this._function(state, scope);
452
455
  }
453
456
  else if (state.isIf) {
454
- return this._switch(state, scope);
457
+ return this._ternary(state, scope);
455
458
  }
456
459
  else if (state.isWhile) {
457
460
  return this._loop(state, scope);
458
461
  }
459
- else if (state.isExit) {
460
- return new JumpNode_js_1.JumpNode(state, "exit", this._unit(state.next(), scope), this._scope.type());
461
- }
462
462
  else if (state.isReturn) {
463
- return new JumpNode_js_1.JumpNode(state, "return", this._unit(state.next(), scope), scope.type());
463
+ return new ReturnNode_js_1.ReturnNode(state, "function", this._unit(state.next(), scope), scope.type());
464
+ }
465
+ else if (state.isResult) {
466
+ return new ReturnNode_js_1.ReturnNode(state, "global", this._unit(state.next(), scope), this._scope.type());
464
467
  }
465
- else if (state.isStop) {
466
- const node = new JumpNode_js_1.JumpNode(state, "stop");
468
+ else if (state.isExit) {
469
+ const node = new JumpNode_js_1.JumpNode(state, "exit");
467
470
  state.next();
468
471
  return node;
469
472
  }
@@ -527,13 +530,13 @@ class Affinirum {
527
530
  return (0, Value_js_1.normalize)(subnode.evaluate(subframe));
528
531
  }
529
532
  catch (e) {
530
- if (e instanceof JumpException_js_1.JumpException) {
531
- if (e.jump === "return") {
533
+ if (e instanceof ReturnNode_js_1.ReturnNode) {
534
+ if (e.scope === "function") {
532
535
  return (0, Value_js_1.normalize)(e.value);
533
536
  }
534
- if (e.jump === "stop" || e.jump === "next") {
535
- subnode.throwError(`unexpected ${e.jump} jump`);
536
- }
537
+ }
538
+ if (e instanceof JumpNode_js_1.JumpNode) {
539
+ subnode.throwError(`unexpected ${e.action} jump`);
537
540
  }
538
541
  throw e;
539
542
  }
@@ -547,7 +550,7 @@ class Affinirum {
547
550
  span.end(state);
548
551
  return new LoopNode_js_1.LoopNode(span, cnode, this._unit(state, scope));
549
552
  }
550
- _switch(state, scope) {
553
+ _ternary(state, scope) {
551
554
  const span = state.start();
552
555
  const cnode = this._unit(state.next(), scope);
553
556
  span.end(state);
@@ -555,7 +558,7 @@ class Affinirum {
555
558
  const celse = state.isElse
556
559
  ? this._unit(state.next(), scope)
557
560
  : new ConstantNode_js_1.ConstantNode(state.start(), Constant_js_1.Constant.Null);
558
- return new SwitchNode_js_1.SwitchNode(span, cnode, [cthen, celse]);
561
+ return new TernaryNode_js_1.TernaryNode(span, cnode, [cthen, celse]);
559
562
  }
560
563
  _type(state, scope) {
561
564
  if (state.isType) { // literal type
@@ -30,8 +30,6 @@ exports.Functions = [
30
30
  ["Filter", Array_js_1.funcFilter],
31
31
  ["Reduce", Array_js_1.funcReduce],
32
32
  ["Compose", Array_js_1.funcCompose],
33
- ["Prepend", Array_js_1.funcPrepend],
34
- ["Append", Array_js_1.funcAppend],
35
33
  // Buffer
36
34
  ["Byte", Buffer_js_1.funcByte],
37
35
  // Enumerable
@@ -16,5 +16,6 @@ exports.Keywords = [
16
16
  "var",
17
17
  "val",
18
18
  "if", "else",
19
- "while", "stop", "next",
19
+ "while",
20
+ "next", "exit",
20
21
  ];
package/dst/cjs/Node.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Value } from "./Value.js";
4
4
  import { CallFrame } from "./CallFrame.js";
5
5
  export declare abstract class Node extends ScriptSpan {
6
6
  constructor(span: ScriptSpan);
7
- abstract type: Type;
7
+ get type(): Type;
8
8
  abstract compile(type: Type): Node;
9
9
  abstract evaluate(frame: CallFrame): Value;
10
10
  get constant(): boolean;
package/dst/cjs/Node.js CHANGED
@@ -2,10 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Node = void 0;
4
4
  const ScriptSpan_js_1 = require("./ScriptSpan.js");
5
+ const Type_js_1 = require("./Type.js");
5
6
  class Node extends ScriptSpan_js_1.ScriptSpan {
6
7
  constructor(span) {
7
8
  super(span);
8
9
  }
10
+ get type() {
11
+ return Type_js_1.Type.Void;
12
+ }
9
13
  get constant() {
10
14
  return false;
11
15
  }
@@ -42,9 +42,9 @@ export declare class ParserState extends ScriptSpan {
42
42
  get isIf(): boolean;
43
43
  get isElse(): boolean;
44
44
  get isWhile(): boolean;
45
- get isExit(): boolean;
45
+ get isResult(): boolean;
46
46
  get isReturn(): boolean;
47
- get isStop(): boolean;
47
+ get isExit(): boolean;
48
48
  get isNext(): boolean;
49
49
  get isEmpty(): boolean;
50
50
  openParentheses(): this;
@@ -53,9 +53,9 @@ const idVal = Symbol();
53
53
  const idIf = Symbol();
54
54
  const idElse = Symbol();
55
55
  const idWhile = Symbol();
56
- const idExit = Symbol();
56
+ const idResult = Symbol();
57
57
  const idReturn = Symbol();
58
- const idStop = Symbol();
58
+ const idExit = Symbol();
59
59
  const idNext = Symbol();
60
60
  class ParserState extends ScriptSpan_js_1.ScriptSpan {
61
61
  _fragment;
@@ -149,14 +149,14 @@ class ParserState extends ScriptSpan_js_1.ScriptSpan {
149
149
  get isWhile() {
150
150
  return this._fragment === idWhile;
151
151
  }
152
- get isExit() {
153
- return this._fragment === idExit;
152
+ get isResult() {
153
+ return this._fragment === idResult;
154
154
  }
155
155
  get isReturn() {
156
156
  return this._fragment === idReturn;
157
157
  }
158
- get isStop() {
159
- return this._fragment === idStop;
158
+ get isExit() {
159
+ return this._fragment === idExit;
160
160
  }
161
161
  get isNext() {
162
162
  return this._fragment === idNext;
@@ -350,7 +350,7 @@ class ParserState extends ScriptSpan_js_1.ScriptSpan {
350
350
  break;
351
351
  case ">":
352
352
  ++this._end;
353
- this._fragment = idExit;
353
+ this._fragment = idResult;
354
354
  break;
355
355
  default:
356
356
  this._fragment = funcAssignment;
@@ -537,12 +537,12 @@ class ParserState extends ScriptSpan_js_1.ScriptSpan {
537
537
  case "while":
538
538
  this._fragment = idWhile;
539
539
  break;
540
- case "stop":
541
- this._fragment = idStop;
542
- break;
543
540
  case "next":
544
541
  this._fragment = idNext;
545
542
  break;
543
+ case "exit":
544
+ this._fragment = idExit;
545
+ break;
546
546
  default:
547
547
  this._fragment = token;
548
548
  break;
@@ -11,6 +11,4 @@ export declare const funcDerive: Constant;
11
11
  export declare const funcFilter: Constant;
12
12
  export declare const funcReduce: Constant;
13
13
  export declare const funcCompose: Constant;
14
- export declare const funcPrepend: Constant;
15
- export declare const funcAppend: Constant;
16
14
  export declare const constArray: any;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.constArray = exports.funcAppend = exports.funcPrepend = exports.funcCompose = exports.funcReduce = exports.funcFilter = exports.funcDerive = exports.funcReverse = exports.funcFlatten = exports.funcAny = exports.funcEvery = exports.funcLastIndex = exports.funcFirstIndex = exports.funcLast = exports.funcFirst = void 0;
3
+ exports.constArray = exports.funcCompose = exports.funcReduce = exports.funcFilter = exports.funcDerive = exports.funcReverse = exports.funcFlatten = exports.funcAny = exports.funcEvery = exports.funcLastIndex = exports.funcFirstIndex = exports.funcLast = exports.funcFirst = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
6
  const Integer_js_1 = require("./Integer.js");
@@ -9,7 +9,6 @@ const typePredicate = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_
9
9
  const typeItemFinder = Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Array, typePredicate]);
10
10
  const typeIndexFinder = Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.Array, typePredicate]);
11
11
  const typeConditionSet = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Array, typePredicate]);
12
- const typeVariadicInsert = Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Array], true);
13
12
  const typeArrayOperator = Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Array]);
14
13
  exports.funcFirst = new Constant_js_1.Constant((value, predicate) => value?.find((v, i, a) => predicate(v, BigInt(i), a)), typeItemFinder);
15
14
  exports.funcLast = new Constant_js_1.Constant((value, predicate) => {
@@ -54,22 +53,15 @@ exports.funcCompose = new Constant_js_1.Constant((value, callback) => {
54
53
  if (value == null) {
55
54
  return undefined;
56
55
  }
57
- const obj = Object.create(null);
56
+ let obj = Object.create(null);
58
57
  for (let i = 0; i < value.length; ++i) {
59
58
  const key = value[i];
60
- obj[key] = callback(obj, key, BigInt(i), value);
59
+ const item = callback(obj, key, BigInt(i), value);
60
+ obj = Object.assign(Object.create(null), obj, { [key]: item });
61
61
  }
62
62
  return obj;
63
63
  }, Type_js_1.Type.functionType(Type_js_1.Type.Object, [Type_js_1.Type.Array, Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Object, Type_js_1.Type.String, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalArray])]));
64
- exports.funcPrepend = new Constant_js_1.Constant((value, items) => {
65
- value?.unshift(items);
66
- return value;
67
- }, typeVariadicInsert);
68
- exports.funcAppend = new Constant_js_1.Constant((value, items) => {
69
- value?.push(items);
70
- return value;
71
- }, typeVariadicInsert);
72
- const funcJoin = new Constant_js_1.Constant((values) => values.flat(Infinity), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.arrayType([Type_js_1.Type.Array])], true));
64
+ const funcJoin = new Constant_js_1.Constant((values) => values.flat(), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.arrayType([Type_js_1.Type.Array])], true));
73
65
  const funcRange = new Constant_js_1.Constant((value1, value2) => {
74
66
  const v1 = (0, Integer_js_1.boundInteger)(value1);
75
67
  const v2 = (0, Integer_js_1.boundInteger)(value2);
@@ -2,15 +2,12 @@ import { Node } from "../Node.js";
2
2
  import { ScriptSpan } from "../ScriptSpan.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 _jump: Jump;
9
- protected _subnode?: Node | undefined;
10
- protected _type?: Type | undefined;
11
- constructor(span: ScriptSpan, _jump: Jump, _subnode?: Node | undefined, _type?: Type | undefined);
12
- get type(): Type;
13
- compile(type: Type): Node;
14
- evaluate(frame: CallFrame): Value;
7
+ protected _action: "exit" | "next";
8
+ constructor(span: ScriptSpan, _action: "exit" | "next");
9
+ get action(): "next" | "exit";
10
+ compile(_: Type): Node;
11
+ evaluate(_: CallFrame): Value;
15
12
  toString(ident?: number): string;
16
13
  }
@@ -2,34 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JumpNode = void 0;
4
4
  const Node_js_1 = require("../Node.js");
5
- const Type_js_1 = require("../Type.js");
6
- const JumpException_js_1 = require("../JumpException.js");
7
5
  class JumpNode extends Node_js_1.Node {
8
- _jump;
9
- _subnode;
10
- _type;
11
- constructor(span, _jump, _subnode, _type) {
6
+ _action;
7
+ constructor(span, _action) {
12
8
  super(span);
13
- this._jump = _jump;
14
- this._subnode = _subnode;
15
- this._type = _type;
9
+ this._action = _action;
16
10
  }
17
- get type() {
18
- return this._type ?? this._subnode?.type ?? Type_js_1.Type.Void;
11
+ get action() {
12
+ return this._action;
19
13
  }
20
- compile(type) {
21
- this._subnode = this._subnode?.compile(this._jump === "exit" || this._jump === "return"
22
- ? this._type ?? Type_js_1.Type.Unknown
23
- : type);
14
+ compile(_) {
24
15
  return this;
25
16
  }
26
- evaluate(frame) {
27
- throw new JumpException_js_1.JumpException(this._jump, this._subnode?.evaluate(frame));
17
+ evaluate(_) {
18
+ throw this;
28
19
  }
29
20
  toString(ident = 0) {
30
- return this._subnode
31
- ? `${super.toString(ident)} ${this._jump} node subnode:\n${this._subnode.toString(ident + 1)}`
32
- : `${super.toString(ident)} ${this._jump} node`;
21
+ return `${super.toString(ident)} ${this._action} node`;
33
22
  }
34
23
  }
35
24
  exports.JumpNode = JumpNode;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LoopNode = void 0;
4
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");
6
+ const JumpNode_js_1 = require("./JumpNode.js");
7
7
  class LoopNode extends Node_js_1.Node {
8
8
  _cnode;
9
9
  _subnode;
@@ -27,11 +27,11 @@ class LoopNode extends Node_js_1.Node {
27
27
  result = this._subnode.evaluate(frame);
28
28
  }
29
29
  catch (e) {
30
- if (e instanceof JumpException_js_1.JumpException) {
31
- if (e.jump === "stop") {
30
+ if (e instanceof JumpNode_js_1.JumpNode) {
31
+ if (e.action === "exit") {
32
32
  break;
33
33
  }
34
- if (e.jump === "next") {
34
+ if (e.action === "next") {
35
35
  continue;
36
36
  }
37
37
  }
@@ -0,0 +1,18 @@
1
+ import { Node } from "../Node.js";
2
+ import { ScriptSpan } from "../ScriptSpan.js";
3
+ import { Value } from "../Value.js";
4
+ import { Type } from "../Type.js";
5
+ import { CallFrame } from "../CallFrame.js";
6
+ export declare class ReturnNode extends Node {
7
+ protected _scope: "global" | "function";
8
+ protected _subnode: Node;
9
+ protected _type: Type;
10
+ protected _value?: Value;
11
+ constructor(span: ScriptSpan, _scope: "global" | "function", _subnode: Node, _type: Type, _value?: Value);
12
+ get scope(): "function" | "global";
13
+ get value(): Value;
14
+ get type(): Type;
15
+ compile(): Node;
16
+ evaluate(frame: CallFrame): Value;
17
+ toString(ident?: number): string;
18
+ }