affinirum 1.5.2 → 1.5.4

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 (121) hide show
  1. package/README.md +12 -2
  2. package/dst/Affinirum.d.ts +22 -22
  3. package/dst/Affinirum.js +88 -80
  4. package/dst/CallFrame.d.ts +11 -0
  5. package/dst/CallFrame.js +35 -0
  6. package/dst/LexicalScope.d.ts +15 -0
  7. package/dst/LexicalScope.js +31 -0
  8. package/dst/Node.d.ts +5 -4
  9. package/dst/Node.js +5 -5
  10. package/dst/ParserState.d.ts +3 -3
  11. package/dst/ParserState.js +40 -40
  12. package/dst/ScriptSpan.d.ts +10 -0
  13. package/dst/{ParserFrame.js → ScriptSpan.js} +20 -31
  14. package/dst/Type.d.ts +2 -0
  15. package/dst/Type.js +2 -0
  16. package/dst/Variable.d.ts +0 -4
  17. package/dst/Variable.js +0 -7
  18. package/dst/cjs/Affinirum.d.ts +88 -0
  19. package/dst/cjs/Affinirum.js +88 -80
  20. package/dst/cjs/Atom.d.ts +7 -0
  21. package/dst/cjs/CallFrame.d.ts +11 -0
  22. package/dst/cjs/CallFrame.js +39 -0
  23. package/dst/cjs/Constant.d.ts +13 -0
  24. package/dst/cjs/Constants.d.ts +2 -0
  25. package/dst/cjs/Functions.d.ts +2 -0
  26. package/dst/cjs/Jump.d.ts +1 -0
  27. package/dst/cjs/JumpException.d.ts +9 -0
  28. package/dst/cjs/Keywords.d.ts +1 -0
  29. package/dst/cjs/LexicalScope.d.ts +15 -0
  30. package/dst/cjs/LexicalScope.js +35 -0
  31. package/dst/cjs/Node.d.ts +14 -0
  32. package/dst/cjs/Node.js +5 -5
  33. package/dst/cjs/ParserState.d.ts +60 -0
  34. package/dst/cjs/ParserState.js +40 -40
  35. package/dst/cjs/ScriptSpan.d.ts +10 -0
  36. package/dst/cjs/{ParserFrame.js → ScriptSpan.js} +22 -33
  37. package/dst/cjs/Type.d.ts +71 -0
  38. package/dst/cjs/Type.js +2 -0
  39. package/dst/cjs/Value.d.ts +5 -0
  40. package/dst/cjs/Variable.d.ts +9 -0
  41. package/dst/cjs/Variable.js +0 -7
  42. package/dst/cjs/atom/ArrayAtom.d.ts +16 -0
  43. package/dst/cjs/atom/FunctionAtom.d.ts +22 -0
  44. package/dst/cjs/atom/ObjectAtom.d.ts +14 -0
  45. package/dst/cjs/atom/PrimitiveAtom.d.ts +12 -0
  46. package/dst/cjs/index.d.ts +3 -0
  47. package/dst/cjs/native/Aggregable.d.ts +4 -0
  48. package/dst/cjs/native/Array.d.ts +16 -0
  49. package/dst/cjs/native/Boolean.d.ts +6 -0
  50. package/dst/cjs/native/Buffer.d.ts +13 -0
  51. package/dst/cjs/native/Buffer.js +1 -1
  52. package/dst/cjs/native/Enumerable.d.ts +4 -0
  53. package/dst/cjs/native/Float.d.ts +5 -0
  54. package/dst/cjs/native/Integer.d.ts +7 -0
  55. package/dst/cjs/native/Iterable.d.ts +5 -0
  56. package/dst/cjs/native/Number.d.ts +26 -0
  57. package/dst/cjs/native/Number.js +25 -12
  58. package/dst/cjs/native/Object.d.ts +5 -0
  59. package/dst/cjs/native/String.d.ts +28 -0
  60. package/dst/cjs/native/String.js +97 -48
  61. package/dst/cjs/native/Timestamp.d.ts +22 -0
  62. package/dst/cjs/native/Unknown.d.ts +14 -0
  63. package/dst/cjs/native/Unknown.js +10 -1
  64. package/dst/cjs/native/notation/AN.d.ts +4 -0
  65. package/dst/cjs/native/notation/AN.js +2 -2
  66. package/dst/cjs/native/notation/IP.d.ts +1 -0
  67. package/dst/cjs/native/notation/JSON.d.ts +3 -0
  68. package/dst/cjs/node/ArrayNode.d.ts +14 -0
  69. package/dst/cjs/node/ArrayNode.js +4 -11
  70. package/dst/cjs/node/BlockNode.d.ts +15 -0
  71. package/dst/cjs/node/BlockNode.js +10 -6
  72. package/dst/cjs/node/CallNode.d.ts +15 -0
  73. package/dst/cjs/node/CallNode.js +15 -28
  74. package/dst/cjs/node/CastNode.d.ts +16 -0
  75. package/dst/cjs/node/CastNode.js +4 -4
  76. package/dst/cjs/node/ConstantNode.d.ts +17 -0
  77. package/dst/cjs/node/ConstantNode.js +7 -5
  78. package/dst/cjs/node/JumpNode.d.ts +16 -0
  79. package/dst/cjs/node/JumpNode.js +10 -6
  80. package/dst/cjs/node/LoopNode.d.ts +14 -0
  81. package/dst/cjs/node/LoopNode.js +5 -5
  82. package/dst/cjs/node/ObjectNode.d.ts +14 -0
  83. package/dst/cjs/node/ObjectNode.js +6 -12
  84. package/dst/cjs/node/SwitchNode.d.ts +15 -0
  85. package/dst/cjs/node/SwitchNode.js +8 -7
  86. package/dst/cjs/node/VariableNode.d.ts +15 -0
  87. package/dst/cjs/node/VariableNode.js +5 -5
  88. package/dst/cjs/node/VariadicNode.d.ts +4 -0
  89. package/dst/cjs/node/VariadicNode.js +10 -0
  90. package/dst/native/Buffer.js +1 -1
  91. package/dst/native/Number.js +25 -12
  92. package/dst/native/String.js +97 -48
  93. package/dst/native/Unknown.js +10 -1
  94. package/dst/native/notation/AN.js +2 -2
  95. package/dst/node/ArrayNode.d.ts +4 -3
  96. package/dst/node/ArrayNode.js +4 -11
  97. package/dst/node/BlockNode.d.ts +6 -3
  98. package/dst/node/BlockNode.js +10 -6
  99. package/dst/node/CallNode.d.ts +4 -3
  100. package/dst/node/CallNode.js +15 -28
  101. package/dst/node/CastNode.d.ts +4 -3
  102. package/dst/node/CastNode.js +4 -4
  103. package/dst/node/ConstantNode.d.ts +5 -3
  104. package/dst/node/ConstantNode.js +7 -5
  105. package/dst/node/JumpNode.d.ts +5 -3
  106. package/dst/node/JumpNode.js +10 -6
  107. package/dst/node/LoopNode.d.ts +4 -3
  108. package/dst/node/LoopNode.js +5 -5
  109. package/dst/node/ObjectNode.d.ts +4 -3
  110. package/dst/node/ObjectNode.js +6 -12
  111. package/dst/node/SwitchNode.d.ts +4 -3
  112. package/dst/node/SwitchNode.js +8 -7
  113. package/dst/node/VariableNode.d.ts +4 -3
  114. package/dst/node/VariableNode.js +5 -5
  115. package/dst/node/VariadicNode.d.ts +4 -0
  116. package/dst/node/VariadicNode.js +6 -0
  117. package/package.json +10 -9
  118. package/dst/ParserFrame.d.ts +0 -13
  119. package/dst/Scope.d.ts +0 -16
  120. package/dst/Scope.js +0 -49
  121. package/dst/cjs/Scope.js +0 -53
@@ -4,8 +4,8 @@ import { JumpException } from "../JumpException.js";
4
4
  export class LoopNode extends Node {
5
5
  _cnode;
6
6
  _subnode;
7
- constructor(frame, _cnode, _subnode) {
8
- super(frame);
7
+ constructor(span, _cnode, _subnode) {
8
+ super(span);
9
9
  this._cnode = _cnode;
10
10
  this._subnode = _subnode;
11
11
  }
@@ -17,11 +17,11 @@ export class LoopNode extends Node {
17
17
  this._subnode = this._subnode.compile(type);
18
18
  return this;
19
19
  }
20
- evaluate() {
20
+ evaluate(frame) {
21
21
  let result = undefined;
22
- while (this._cnode.evaluate()) {
22
+ while (this._cnode.evaluate(frame)) {
23
23
  try {
24
- result = this._subnode.evaluate();
24
+ result = this._subnode.evaluate(frame);
25
25
  }
26
26
  catch (e) {
27
27
  if (e instanceof JumpException) {
@@ -1,13 +1,14 @@
1
1
  import { Node } from "../Node.js";
2
- import { ParserFrame } from "../ParserFrame.js";
2
+ import { ScriptSpan } from "../ScriptSpan.js";
3
3
  import { Value } from "../Value.js";
4
4
  import { Type } from "../Type.js";
5
+ import { CallFrame } from "../CallFrame.js";
5
6
  export declare class ObjectNode extends Node {
6
7
  protected _subnodes: [Node, Node][];
7
8
  protected _type: Type;
8
- constructor(frame: ParserFrame, _subnodes: [Node, Node][]);
9
+ constructor(span: ScriptSpan, _subnodes: [Node, Node][]);
9
10
  get type(): Type;
10
11
  compile(type: Type): Node;
11
- evaluate(): Value;
12
+ evaluate(frame: CallFrame): Value;
12
13
  toString(ident?: number): string;
13
14
  }
@@ -1,36 +1,30 @@
1
1
  import { Node } from "../Node.js";
2
- import { Constant } from "../Constant.js";
3
2
  import { ConstantNode } from "./ConstantNode.js";
4
3
  import { Type } from "../Type.js";
4
+ import { CallFrame } from "../CallFrame.js";
5
5
  export class ObjectNode extends Node {
6
6
  _subnodes;
7
7
  _type;
8
- constructor(frame, _subnodes) {
9
- super(frame);
8
+ constructor(span, _subnodes) {
9
+ super(span);
10
10
  this._subnodes = _subnodes;
11
- this._type = Type.objectType(_subnodes.filter(([i]) => i instanceof ConstantNode && i.constant).map(([k, v]) => [k.evaluate(), v.type]));
11
+ this._type = Type.objectType(_subnodes.filter(([i]) => i instanceof ConstantNode && i.constant).map(([k, v]) => [k.evaluate(new CallFrame()), v.type]));
12
12
  }
13
13
  get type() {
14
14
  return this._type;
15
15
  }
16
16
  compile(type) {
17
17
  this._type = this.reduceType(type);
18
- let constant = true;
19
18
  for (let i = 0; i < this._subnodes.length; ++i) {
20
19
  this._subnodes[i][0] = this._subnodes[i][0].compile(Type.String);
21
- constant &&= this._subnodes[i][0].constant;
22
20
  this._subnodes[i][1] = this._subnodes[i][1].compile(Type.Unknown);
23
- constant &&= this._subnodes[i][1].constant;
24
- }
25
- if (constant) {
26
- return new ConstantNode(this, new Constant(this.evaluate(), this.type));
27
21
  }
28
22
  return this;
29
23
  }
30
- evaluate() {
24
+ evaluate(frame) {
31
25
  const result = Object.create(null);
32
26
  for (const [key, value] of this._subnodes) {
33
- result[key.evaluate()] = value.evaluate();
27
+ result[key.evaluate(frame)] = value.evaluate(frame);
34
28
  }
35
29
  return result;
36
30
  }
@@ -1,14 +1,15 @@
1
1
  import { Node } from "../Node.js";
2
- import { ParserFrame } from "../ParserFrame.js";
2
+ import { ScriptSpan } from "../ScriptSpan.js";
3
3
  import { Value } from "../Value.js";
4
4
  import { Type } from "../Type.js";
5
+ import { CallFrame } from "../CallFrame.js";
5
6
  export declare class SwitchNode extends Node {
6
7
  protected _cnode: Node;
7
8
  protected _subnodes: Node[];
8
9
  protected _type: Type;
9
- constructor(frame: ParserFrame, _cnode: Node, _subnodes: Node[]);
10
+ constructor(span: ScriptSpan, _cnode: Node, _subnodes: Node[]);
10
11
  get type(): Type;
11
12
  compile(type: Type): Node;
12
- evaluate(): Value;
13
+ evaluate(frame: CallFrame): Value;
13
14
  toString(ident?: number): string;
14
15
  }
@@ -2,12 +2,13 @@ import { Node } from "../Node.js";
2
2
  import { Constant } from "../Constant.js";
3
3
  import { ConstantNode } from "./ConstantNode.js";
4
4
  import { Type } from "../Type.js";
5
+ import { CallFrame } from "../CallFrame.js";
5
6
  export class SwitchNode extends Node {
6
7
  _cnode;
7
8
  _subnodes;
8
9
  _type;
9
- constructor(frame, _cnode, _subnodes) {
10
- super(frame);
10
+ constructor(span, _cnode, _subnodes) {
11
+ super(span);
11
12
  this._cnode = _cnode;
12
13
  this._subnodes = _subnodes;
13
14
  if (_subnodes.length !== 2) {
@@ -27,14 +28,14 @@ export class SwitchNode extends Node {
27
28
  constant &&= this._subnodes[i].constant;
28
29
  }
29
30
  if (constant) {
30
- return new ConstantNode(this, new Constant(this.evaluate(), this.type));
31
+ return new ConstantNode(this, new Constant(this.evaluate(new CallFrame()), this.type));
31
32
  }
32
33
  return this;
33
34
  }
34
- evaluate() {
35
- return this._cnode.evaluate()
36
- ? this._subnodes[0].evaluate()
37
- : this._subnodes[1].evaluate();
35
+ evaluate(frame) {
36
+ return this._cnode.evaluate(frame)
37
+ ? this._subnodes[0].evaluate(frame)
38
+ : this._subnodes[1].evaluate(frame);
38
39
  }
39
40
  toString(ident = 0) {
40
41
  const subnodes = this._subnodes.map((s) => s.toString(ident + 1)).join("\n");
@@ -1,14 +1,15 @@
1
1
  import { Node } from "../Node.js";
2
- import { ParserFrame } from "../ParserFrame.js";
2
+ import { ScriptSpan } from "../ScriptSpan.js";
3
3
  import { Variable } from "../Variable.js";
4
4
  import { Value } from "../Value.js";
5
5
  import { Type } from "../Type.js";
6
+ import { CallFrame } from "../CallFrame.js";
6
7
  export declare class VariableNode extends Node {
7
8
  protected readonly _variable: Variable;
8
9
  protected _subnode?: Node | undefined;
9
- constructor(frame: ParserFrame, _variable: Variable, _subnode?: Node | undefined);
10
+ constructor(span: ScriptSpan, _variable: Variable, _subnode?: Node | undefined);
10
11
  get type(): Type;
11
12
  compile(type: Type): Node;
12
- evaluate(): Value;
13
+ evaluate(frame: CallFrame): Value;
13
14
  toString(ident?: number): string;
14
15
  }
@@ -2,8 +2,8 @@ import { Node } from "../Node.js";
2
2
  export class VariableNode extends Node {
3
3
  _variable;
4
4
  _subnode;
5
- constructor(frame, _variable, _subnode) {
6
- super(frame);
5
+ constructor(span, _variable, _subnode) {
6
+ super(span);
7
7
  this._variable = _variable;
8
8
  this._subnode = _subnode;
9
9
  }
@@ -15,10 +15,10 @@ export class VariableNode extends Node {
15
15
  this._variable.type = this.reduceType(this._subnode?.type ?? type);
16
16
  return this;
17
17
  }
18
- evaluate() {
18
+ evaluate(frame) {
19
19
  return this._subnode
20
- ? this._variable.value = this._subnode.evaluate()
21
- : this._variable.value;
20
+ ? frame.set(this._variable, this._subnode.evaluate(frame))
21
+ : frame.get(this._variable);
22
22
  }
23
23
  toString(ident = 0) {
24
24
  return this._subnode
@@ -0,0 +1,4 @@
1
+ import { ArrayNode } from "./ArrayNode.js";
2
+ export declare class VariadicNode extends ArrayNode {
3
+ get constant(): boolean;
4
+ }
@@ -0,0 +1,6 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "affinirum",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "Affinirum Scripting Language",
5
5
  "main": "dst/cjs/index.js",
6
6
  "module": "dst/index.js",
@@ -36,12 +36,12 @@
36
36
  "scripts": {
37
37
  "clean": "rimraf --glob dst/* && rimraf --glob *.tgz",
38
38
  "prebuild": "npm run clean",
39
- "build": "tsc --build tsconfig.esm.json && tsc --build tsconfig.cjs.json",
40
- "pretest": "npm run clean && tsc --build tsconfig.spec.json",
41
- "test": "jasmine",
42
- "lint": "eslint ./src ./spec",
43
- "lint-fix": "eslint ./src ./spec --fix",
44
- "prepare": "npm run build && copyfiles ./cjs/package.json ./dst"
39
+ "build": "tsc --build tsconfig.esm.json && tsc --build tsconfig.cjs.json && copyfiles ./cjs/package.json ./dst",
40
+ "pretest": "npm run clean && tsc --build tsconfig.test.json",
41
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
42
+ "lint": "eslint ./src ./spc",
43
+ "lint-fix": "eslint ./src ./spc --fix",
44
+ "prepare": "npm run build"
45
45
  },
46
46
  "license": "AGPLv3.0",
47
47
  "repository": {
@@ -58,10 +58,11 @@
58
58
  "devDependencies": {
59
59
  "@eslint/js": "10.0.1",
60
60
  "@stylistic/eslint-plugin": "~5.10.0",
61
- "@types/jasmine": "~6.0.0",
61
+ "@types/jest": "~30.0.0",
62
+ "@types/node": "~24.19.2",
62
63
  "copyfiles": "~2.4.1",
63
64
  "eslint": "~10.11.0",
64
- "jasmine": "~7.0.0",
65
+ "jest": "~30.5.2",
65
66
  "rimraf": "~6.1.3",
66
67
  "typescript": "~6.0.3",
67
68
  "typescript-eslint": "~8.70.1"
@@ -1,13 +0,0 @@
1
- export declare class ParserFrame {
2
- protected readonly _expr: string;
3
- protected _start: number;
4
- protected _end: number;
5
- constructor(_expr: string, _start?: number, _end?: number);
6
- get expr(): string;
7
- get start(): number;
8
- get end(): number;
9
- starts(frame?: ParserFrame): ParserFrame;
10
- ends(frame?: ParserFrame): ParserFrame;
11
- throwError(message: string): never;
12
- toString(): string;
13
- }
package/dst/Scope.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Value } from "./Value.js";
2
- import { Variable } from "./Variable.js";
3
- export declare class Scope {
4
- protected readonly _subscopes: Scope[];
5
- protected readonly _superscope?: Scope;
6
- protected readonly _variables: Map<string, Variable>;
7
- protected readonly _boundary: boolean;
8
- constructor(superscope?: Scope, variables?: Map<string, Variable>);
9
- has(name: string): boolean;
10
- get(name: string): Variable | undefined;
11
- set(name: string, variable: Variable): void;
12
- subscope(variables?: Map<string, Variable>): Scope;
13
- enter(values?: Map<Variable, Value>): Map<Variable, Value>;
14
- leave(values: Map<Variable, Value>): void;
15
- clear(): void;
16
- }
package/dst/Scope.js DELETED
@@ -1,49 +0,0 @@
1
- export class Scope {
2
- _subscopes = [];
3
- _superscope;
4
- _variables;
5
- _boundary;
6
- constructor(superscope, variables) {
7
- superscope?._subscopes.push(this);
8
- this._superscope = superscope;
9
- this._variables = variables ?? new Map();
10
- this._boundary = Boolean(variables);
11
- }
12
- has(name) {
13
- return this._variables.has(name) || Boolean(this._superscope?.has(name));
14
- }
15
- get(name) {
16
- return this._variables.get(name) ?? this._superscope?.get(name);
17
- }
18
- set(name, variable) {
19
- this._variables.set(name, variable);
20
- }
21
- subscope(variables) {
22
- return new Scope(this, variables);
23
- }
24
- enter(values = new Map()) {
25
- for (const variable of this._variables.values()) {
26
- values.set(variable, variable.value);
27
- variable.value = undefined;
28
- }
29
- for (const subscope of this._subscopes) {
30
- if (!subscope._boundary) {
31
- subscope.enter(values);
32
- }
33
- }
34
- return values;
35
- }
36
- leave(values) {
37
- for (const [variable, value] of values) {
38
- variable.value = value;
39
- }
40
- }
41
- clear() {
42
- for (const variable of this._variables.values()) {
43
- variable.value = undefined;
44
- }
45
- for (const subscope of this._subscopes) {
46
- subscope.clear();
47
- }
48
- }
49
- }
package/dst/cjs/Scope.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Scope = void 0;
4
- class Scope {
5
- _subscopes = [];
6
- _superscope;
7
- _variables;
8
- _boundary;
9
- constructor(superscope, variables) {
10
- superscope?._subscopes.push(this);
11
- this._superscope = superscope;
12
- this._variables = variables ?? new Map();
13
- this._boundary = Boolean(variables);
14
- }
15
- has(name) {
16
- return this._variables.has(name) || Boolean(this._superscope?.has(name));
17
- }
18
- get(name) {
19
- return this._variables.get(name) ?? this._superscope?.get(name);
20
- }
21
- set(name, variable) {
22
- this._variables.set(name, variable);
23
- }
24
- subscope(variables) {
25
- return new Scope(this, variables);
26
- }
27
- enter(values = new Map()) {
28
- for (const variable of this._variables.values()) {
29
- values.set(variable, variable.value);
30
- variable.value = undefined;
31
- }
32
- for (const subscope of this._subscopes) {
33
- if (!subscope._boundary) {
34
- subscope.enter(values);
35
- }
36
- }
37
- return values;
38
- }
39
- leave(values) {
40
- for (const [variable, value] of values) {
41
- variable.value = value;
42
- }
43
- }
44
- clear() {
45
- for (const variable of this._variables.values()) {
46
- variable.value = undefined;
47
- }
48
- for (const subscope of this._subscopes) {
49
- subscope.clear();
50
- }
51
- }
52
- }
53
- exports.Scope = Scope;