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.
- package/README.md +12 -2
- package/dst/Affinirum.d.ts +22 -22
- package/dst/Affinirum.js +88 -80
- package/dst/CallFrame.d.ts +11 -0
- package/dst/CallFrame.js +35 -0
- package/dst/LexicalScope.d.ts +15 -0
- package/dst/LexicalScope.js +31 -0
- package/dst/Node.d.ts +5 -4
- package/dst/Node.js +5 -5
- package/dst/ParserState.d.ts +3 -3
- package/dst/ParserState.js +40 -40
- package/dst/ScriptSpan.d.ts +10 -0
- package/dst/{ParserFrame.js → ScriptSpan.js} +20 -31
- package/dst/Type.d.ts +2 -0
- package/dst/Type.js +2 -0
- package/dst/Variable.d.ts +0 -4
- package/dst/Variable.js +0 -7
- package/dst/cjs/Affinirum.d.ts +88 -0
- package/dst/cjs/Affinirum.js +88 -80
- package/dst/cjs/Atom.d.ts +7 -0
- package/dst/cjs/CallFrame.d.ts +11 -0
- package/dst/cjs/CallFrame.js +39 -0
- package/dst/cjs/Constant.d.ts +13 -0
- package/dst/cjs/Constants.d.ts +2 -0
- package/dst/cjs/Functions.d.ts +2 -0
- package/dst/cjs/Jump.d.ts +1 -0
- package/dst/cjs/JumpException.d.ts +9 -0
- package/dst/cjs/Keywords.d.ts +1 -0
- package/dst/cjs/LexicalScope.d.ts +15 -0
- package/dst/cjs/LexicalScope.js +35 -0
- package/dst/cjs/Node.d.ts +14 -0
- package/dst/cjs/Node.js +5 -5
- package/dst/cjs/ParserState.d.ts +60 -0
- package/dst/cjs/ParserState.js +40 -40
- package/dst/cjs/ScriptSpan.d.ts +10 -0
- package/dst/cjs/{ParserFrame.js → ScriptSpan.js} +22 -33
- package/dst/cjs/Type.d.ts +71 -0
- package/dst/cjs/Type.js +2 -0
- package/dst/cjs/Value.d.ts +5 -0
- package/dst/cjs/Variable.d.ts +9 -0
- package/dst/cjs/Variable.js +0 -7
- package/dst/cjs/atom/ArrayAtom.d.ts +16 -0
- package/dst/cjs/atom/FunctionAtom.d.ts +22 -0
- package/dst/cjs/atom/ObjectAtom.d.ts +14 -0
- package/dst/cjs/atom/PrimitiveAtom.d.ts +12 -0
- package/dst/cjs/index.d.ts +3 -0
- package/dst/cjs/native/Aggregable.d.ts +4 -0
- package/dst/cjs/native/Array.d.ts +16 -0
- package/dst/cjs/native/Boolean.d.ts +6 -0
- package/dst/cjs/native/Buffer.d.ts +13 -0
- package/dst/cjs/native/Buffer.js +1 -1
- package/dst/cjs/native/Enumerable.d.ts +4 -0
- package/dst/cjs/native/Float.d.ts +5 -0
- package/dst/cjs/native/Integer.d.ts +7 -0
- package/dst/cjs/native/Iterable.d.ts +5 -0
- package/dst/cjs/native/Number.d.ts +26 -0
- package/dst/cjs/native/Number.js +25 -12
- package/dst/cjs/native/Object.d.ts +5 -0
- package/dst/cjs/native/String.d.ts +28 -0
- package/dst/cjs/native/String.js +97 -48
- package/dst/cjs/native/Timestamp.d.ts +22 -0
- package/dst/cjs/native/Unknown.d.ts +14 -0
- package/dst/cjs/native/Unknown.js +10 -1
- package/dst/cjs/native/notation/AN.d.ts +4 -0
- package/dst/cjs/native/notation/AN.js +2 -2
- package/dst/cjs/native/notation/IP.d.ts +1 -0
- package/dst/cjs/native/notation/JSON.d.ts +3 -0
- package/dst/cjs/node/ArrayNode.d.ts +14 -0
- package/dst/cjs/node/ArrayNode.js +4 -11
- package/dst/cjs/node/BlockNode.d.ts +15 -0
- package/dst/cjs/node/BlockNode.js +10 -6
- package/dst/cjs/node/CallNode.d.ts +15 -0
- package/dst/cjs/node/CallNode.js +15 -28
- package/dst/cjs/node/CastNode.d.ts +16 -0
- package/dst/cjs/node/CastNode.js +4 -4
- package/dst/cjs/node/ConstantNode.d.ts +17 -0
- package/dst/cjs/node/ConstantNode.js +7 -5
- package/dst/cjs/node/JumpNode.d.ts +16 -0
- package/dst/cjs/node/JumpNode.js +10 -6
- package/dst/cjs/node/LoopNode.d.ts +14 -0
- package/dst/cjs/node/LoopNode.js +5 -5
- package/dst/cjs/node/ObjectNode.d.ts +14 -0
- package/dst/cjs/node/ObjectNode.js +6 -12
- package/dst/cjs/node/SwitchNode.d.ts +15 -0
- package/dst/cjs/node/SwitchNode.js +8 -7
- package/dst/cjs/node/VariableNode.d.ts +15 -0
- package/dst/cjs/node/VariableNode.js +5 -5
- package/dst/cjs/node/VariadicNode.d.ts +4 -0
- package/dst/cjs/node/VariadicNode.js +10 -0
- package/dst/native/Buffer.js +1 -1
- package/dst/native/Number.js +25 -12
- package/dst/native/String.js +97 -48
- package/dst/native/Unknown.js +10 -1
- package/dst/native/notation/AN.js +2 -2
- package/dst/node/ArrayNode.d.ts +4 -3
- package/dst/node/ArrayNode.js +4 -11
- package/dst/node/BlockNode.d.ts +6 -3
- package/dst/node/BlockNode.js +10 -6
- package/dst/node/CallNode.d.ts +4 -3
- package/dst/node/CallNode.js +15 -28
- package/dst/node/CastNode.d.ts +4 -3
- package/dst/node/CastNode.js +4 -4
- package/dst/node/ConstantNode.d.ts +5 -3
- package/dst/node/ConstantNode.js +7 -5
- package/dst/node/JumpNode.d.ts +5 -3
- package/dst/node/JumpNode.js +10 -6
- package/dst/node/LoopNode.d.ts +4 -3
- package/dst/node/LoopNode.js +5 -5
- package/dst/node/ObjectNode.d.ts +4 -3
- package/dst/node/ObjectNode.js +6 -12
- package/dst/node/SwitchNode.d.ts +4 -3
- package/dst/node/SwitchNode.js +8 -7
- package/dst/node/VariableNode.d.ts +4 -3
- package/dst/node/VariableNode.js +5 -5
- package/dst/node/VariadicNode.d.ts +4 -0
- package/dst/node/VariadicNode.js +6 -0
- package/package.json +10 -9
- package/dst/ParserFrame.d.ts +0 -13
- package/dst/Scope.d.ts +0 -16
- package/dst/Scope.js +0 -49
- package/dst/cjs/Scope.js +0 -53
package/dst/native/String.js
CHANGED
|
@@ -75,24 +75,48 @@ export const equateStrings = (value1, value2, ignoreCaseSpaceEtc) => {
|
|
|
75
75
|
if (value1 == null || value2 == null) {
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
78
|
+
if (value1 === value2) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
78
81
|
if (!ignoreCaseSpaceEtc) {
|
|
79
|
-
return
|
|
82
|
+
return false;
|
|
80
83
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
++i1;
|
|
84
|
+
for (let i1 = 0, i2 = 0; i1 < value1.length || i2 < value2.length;) {
|
|
85
|
+
let code1 = 0, code2 = 0;
|
|
86
|
+
while (i1 < value1.length && !code1) {
|
|
87
|
+
code1 = alphanumericCode(value1, i1++);
|
|
86
88
|
}
|
|
87
|
-
while (
|
|
88
|
-
++
|
|
89
|
+
while (i2 < value2.length && !code2) {
|
|
90
|
+
code2 = alphanumericCode(value2, i2++);
|
|
89
91
|
}
|
|
90
|
-
if (
|
|
92
|
+
if (code1 !== code2) {
|
|
91
93
|
return false;
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
return true;
|
|
95
97
|
};
|
|
98
|
+
const alphanumericCode = (value, index) => {
|
|
99
|
+
let code = value.charCodeAt(index);
|
|
100
|
+
if (code > 0x7f) {
|
|
101
|
+
// Preserve Unicode lowercase mappings to ASCII, such as İ and K.
|
|
102
|
+
code = value.charAt(index).toLowerCase().charCodeAt(0);
|
|
103
|
+
}
|
|
104
|
+
code |= 0x20;
|
|
105
|
+
return code >= 0x61 && code <= 0x7a || code >= 0x30 && code <= 0x39 ? code : 0;
|
|
106
|
+
};
|
|
107
|
+
const createSearchPrefixes = (pattern) => {
|
|
108
|
+
const prefixes = new Uint32Array(pattern.length);
|
|
109
|
+
for (let i = 1, matched = 0; i < pattern.length; ++i) {
|
|
110
|
+
while (matched > 0 && pattern[i] !== pattern[matched]) {
|
|
111
|
+
matched = prefixes[matched - 1];
|
|
112
|
+
}
|
|
113
|
+
if (pattern[i] === pattern[matched]) {
|
|
114
|
+
++matched;
|
|
115
|
+
}
|
|
116
|
+
prefixes[i] = matched;
|
|
117
|
+
}
|
|
118
|
+
return prefixes;
|
|
119
|
+
};
|
|
96
120
|
export const containsString = (value, search, startPos, ignoreCaseSpaceEtc) => {
|
|
97
121
|
if (value == null) {
|
|
98
122
|
return false;
|
|
@@ -103,33 +127,62 @@ export const containsString = (value, search, startPos, ignoreCaseSpaceEtc) => {
|
|
|
103
127
|
if (!ignoreCaseSpaceEtc) {
|
|
104
128
|
return value.includes(search, startPos);
|
|
105
129
|
}
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
130
|
+
const pattern = [];
|
|
131
|
+
for (let i = 0; i < search.length; ++i) {
|
|
132
|
+
const code = alphanumericCode(search, i);
|
|
133
|
+
if (code) {
|
|
134
|
+
pattern.push(code);
|
|
135
|
+
}
|
|
110
136
|
}
|
|
111
|
-
if (
|
|
137
|
+
if (pattern.length === 0) {
|
|
112
138
|
return true;
|
|
113
139
|
}
|
|
114
140
|
const pos = startPos == null ? 0 : startPos < 0 ? value.length + startPos : startPos;
|
|
115
|
-
|
|
141
|
+
const start = Math.max(0, Math.trunc(pos) || 0);
|
|
142
|
+
if (pattern.length > value.length - start) {
|
|
116
143
|
return false;
|
|
117
144
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
145
|
+
// Build KMP fallback lengths only when a partial match first fails.
|
|
146
|
+
let prefixes;
|
|
147
|
+
const first = pattern[0];
|
|
148
|
+
for (let i = start, matched = 0; i < value.length; ++i) {
|
|
149
|
+
if (matched === 0) {
|
|
150
|
+
while (i < value.length) {
|
|
151
|
+
const code = value.charCodeAt(i) | 0x20;
|
|
152
|
+
if (code === first || code > 0x7f && alphanumericCode(value, i) === first) {
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
++i;
|
|
156
|
+
}
|
|
157
|
+
if (i === value.length) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
if (pattern.length === 1) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
matched = 1;
|
|
164
|
+
continue;
|
|
121
165
|
}
|
|
122
|
-
|
|
123
|
-
|
|
166
|
+
let code = value.charCodeAt(i) | 0x20;
|
|
167
|
+
if (code > 0x7f) {
|
|
168
|
+
code = alphanumericCode(value, i);
|
|
124
169
|
}
|
|
125
|
-
|
|
126
|
-
++
|
|
170
|
+
if (code === pattern[matched]) {
|
|
171
|
+
if (++matched === pattern.length) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
127
174
|
}
|
|
128
|
-
if (
|
|
129
|
-
|
|
175
|
+
else if (matched > 0 && (code >= 0x61 && code <= 0x7a || code >= 0x30 && code <= 0x39)) {
|
|
176
|
+
prefixes ??= createSearchPrefixes(pattern);
|
|
177
|
+
do {
|
|
178
|
+
matched = prefixes[matched - 1];
|
|
179
|
+
} while (matched > 0 && code !== pattern[matched]);
|
|
180
|
+
if (code === pattern[matched]) {
|
|
181
|
+
++matched;
|
|
182
|
+
}
|
|
130
183
|
}
|
|
131
184
|
}
|
|
132
|
-
return
|
|
185
|
+
return false;
|
|
133
186
|
};
|
|
134
187
|
export const startsWithString = (value, search, startPos, ignoreCaseSpaceEtc) => {
|
|
135
188
|
if (value == null) {
|
|
@@ -141,20 +194,18 @@ export const startsWithString = (value, search, startPos, ignoreCaseSpaceEtc) =>
|
|
|
141
194
|
if (!ignoreCaseSpaceEtc) {
|
|
142
195
|
return value.startsWith(search, startPos);
|
|
143
196
|
}
|
|
144
|
-
const valueStr = value.toLowerCase();
|
|
145
|
-
const searchStr = search.toLowerCase();
|
|
146
|
-
if (valueStr.length < searchStr.length) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
197
|
const pos = startPos == null ? 0 : startPos < 0 ? value.length + startPos : startPos;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
198
|
+
let valueIndex = Math.max(0, Math.trunc(pos) || 0);
|
|
199
|
+
for (let i = 0; i < search.length; ++i) {
|
|
200
|
+
const searchCode = alphanumericCode(search, i);
|
|
201
|
+
if (!searchCode) {
|
|
202
|
+
continue;
|
|
153
203
|
}
|
|
154
|
-
|
|
155
|
-
|
|
204
|
+
let valueCode = 0;
|
|
205
|
+
while (valueIndex < value.length && !valueCode) {
|
|
206
|
+
valueCode = alphanumericCode(value, valueIndex++);
|
|
156
207
|
}
|
|
157
|
-
if (
|
|
208
|
+
if (valueCode !== searchCode) {
|
|
158
209
|
return false;
|
|
159
210
|
}
|
|
160
211
|
}
|
|
@@ -170,20 +221,18 @@ export const endsWithString = (value, search, endPos, ignoreCaseSpaceEtc) => {
|
|
|
170
221
|
if (!ignoreCaseSpaceEtc) {
|
|
171
222
|
return value.endsWith(search, endPos);
|
|
172
223
|
}
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
for (let i1 = pos - 1, i2 = searchStr.length - 1; i1 > -1 && i2 > -1; --i1, --i2) {
|
|
180
|
-
while (!isAlphanumericSymbol(valueStr[i1]) && i1 > -1) {
|
|
181
|
-
--i1;
|
|
224
|
+
const pos = endPos == null ? value.length : endPos < 0 ? value.length + endPos : endPos;
|
|
225
|
+
let valueIndex = Math.min(value.length, Math.max(0, Math.trunc(pos) || 0)) - 1;
|
|
226
|
+
for (let i = search.length - 1; i >= 0; --i) {
|
|
227
|
+
const searchCode = alphanumericCode(search, i);
|
|
228
|
+
if (!searchCode) {
|
|
229
|
+
continue;
|
|
182
230
|
}
|
|
183
|
-
|
|
184
|
-
|
|
231
|
+
let valueCode = 0;
|
|
232
|
+
while (valueIndex >= 0 && !valueCode) {
|
|
233
|
+
valueCode = alphanumericCode(value, valueIndex--);
|
|
185
234
|
}
|
|
186
|
-
if (
|
|
235
|
+
if (valueCode !== searchCode) {
|
|
187
236
|
return false;
|
|
188
237
|
}
|
|
189
238
|
}
|
package/dst/native/Unknown.js
CHANGED
|
@@ -12,7 +12,7 @@ export const equate = (value1, value2) => {
|
|
|
12
12
|
}
|
|
13
13
|
if (typeof value1 !== typeof value2) {
|
|
14
14
|
if (typeof value1 === "number" && typeof value2 === "bigint") {
|
|
15
|
-
return value1 ===
|
|
15
|
+
return Number.isInteger(value1) && BigInt(value1) === value2;
|
|
16
16
|
}
|
|
17
17
|
if (typeof value1 === "bigint" && typeof value2 === "number") {
|
|
18
18
|
return Number.isInteger(value2) && value1 === BigInt(value2);
|
|
@@ -28,9 +28,15 @@ export const equate = (value1, value2) => {
|
|
|
28
28
|
if (value1 instanceof Date && value2 instanceof Date) {
|
|
29
29
|
return value1.getTime() === value2.getTime();
|
|
30
30
|
}
|
|
31
|
+
if (value1 instanceof Date || value2 instanceof Date) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
31
34
|
if (value1 instanceof ArrayBuffer && value2 instanceof ArrayBuffer) {
|
|
32
35
|
return equateBuffers(value1, value2);
|
|
33
36
|
}
|
|
37
|
+
if (value1 instanceof ArrayBuffer || value2 instanceof ArrayBuffer) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
34
40
|
if (Array.isArray(value1) && Array.isArray(value2)) {
|
|
35
41
|
if (value1.length === value2.length) {
|
|
36
42
|
for (let i = 0; i < value1.length; ++i) {
|
|
@@ -42,6 +48,9 @@ export const equate = (value1, value2) => {
|
|
|
42
48
|
}
|
|
43
49
|
return false;
|
|
44
50
|
}
|
|
51
|
+
if (Array.isArray(value1) || Array.isArray(value2)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
45
54
|
const props = new Set([...Object.getOwnPropertyNames(value1), ...Object.getOwnPropertyNames(value2)]);
|
|
46
55
|
for (const prop of props) {
|
|
47
56
|
if (!equate(value1[prop], value2[prop])) {
|
|
@@ -10,7 +10,7 @@ import { formatLiteralTimestamp } from "../Timestamp.js";
|
|
|
10
10
|
const typeAN = Type.union(Type.Void, Type.Boolean, Type.Timestamp, Type.Float, Type.Integer, Type.Buffer, Type.String, Type.Array, Type.Object);
|
|
11
11
|
export const formatAN = (value, whitespace) => {
|
|
12
12
|
if (value == null) {
|
|
13
|
-
return "";
|
|
13
|
+
return "null";
|
|
14
14
|
}
|
|
15
15
|
if (typeof value === "boolean") {
|
|
16
16
|
return value ? "true" : "false";
|
|
@@ -29,7 +29,7 @@ export const formatAN = (value, whitespace) => {
|
|
|
29
29
|
}
|
|
30
30
|
if (Array.isArray(value)) {
|
|
31
31
|
const [prefix, suffix] = whitespace ? ["\n" + whitespace, "\n"] : ["", ""];
|
|
32
|
-
const lines =
|
|
32
|
+
const lines = Array.from(value, (i) => `${prefix}${formatAN(i, whitespace)?.split("\n").join(prefix) ?? ""}`);
|
|
33
33
|
return lines.length ? `[${lines.join(",")}${suffix}]` : "[]";
|
|
34
34
|
}
|
|
35
35
|
if (typeof value === "object") {
|
package/dst/node/ArrayNode.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Node } from "../Node.js";
|
|
2
|
-
import {
|
|
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 ArrayNode extends Node {
|
|
6
7
|
protected _subnodes: Node[];
|
|
7
8
|
protected _type: Type;
|
|
8
|
-
constructor(
|
|
9
|
+
constructor(span: ScriptSpan, _subnodes: 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
|
}
|
package/dst/node/ArrayNode.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Node } from "../Node.js";
|
|
2
|
-
import { Constant } from "../Constant.js";
|
|
3
|
-
import { ConstantNode } from "./ConstantNode.js";
|
|
4
2
|
import { Type } from "../Type.js";
|
|
5
3
|
export class ArrayNode extends Node {
|
|
6
4
|
_subnodes;
|
|
7
5
|
_type;
|
|
8
|
-
constructor(
|
|
9
|
-
super(
|
|
6
|
+
constructor(span, _subnodes) {
|
|
7
|
+
super(span);
|
|
10
8
|
this._subnodes = _subnodes;
|
|
11
9
|
this._type = Type.arrayType(_subnodes.map((i) => i.type));
|
|
12
10
|
}
|
|
@@ -14,23 +12,18 @@ export class ArrayNode extends Node {
|
|
|
14
12
|
return this._type;
|
|
15
13
|
}
|
|
16
14
|
compile(type) {
|
|
17
|
-
let constant = true;
|
|
18
15
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
19
16
|
const valType = type.arrayAtomValType(i);
|
|
20
17
|
this._subnodes[i] = this._subnodes[i].compile(valType);
|
|
21
|
-
constant &&= this._subnodes[i].constant;
|
|
22
18
|
}
|
|
23
19
|
this._type = Type.arrayType(this._subnodes.map((node) => node.type));
|
|
24
20
|
this._type = this.reduceType(type);
|
|
25
|
-
if (constant) {
|
|
26
|
-
return new ConstantNode(this, new Constant(this.evaluate(), this.type));
|
|
27
|
-
}
|
|
28
21
|
return this;
|
|
29
22
|
}
|
|
30
|
-
evaluate() {
|
|
23
|
+
evaluate(frame) {
|
|
31
24
|
const result = [];
|
|
32
25
|
for (const subnode of this._subnodes) {
|
|
33
|
-
result.push(subnode.evaluate());
|
|
26
|
+
result.push(subnode.evaluate(frame));
|
|
34
27
|
}
|
|
35
28
|
return result;
|
|
36
29
|
}
|
package/dst/node/BlockNode.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Node } from "../Node.js";
|
|
2
|
-
import {
|
|
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";
|
|
6
|
+
import { Variable } from "../Variable.js";
|
|
5
7
|
export declare class BlockNode extends Node {
|
|
6
8
|
protected _subnodes: Node[];
|
|
7
|
-
|
|
9
|
+
protected readonly _variables: Variable[];
|
|
10
|
+
constructor(span: ScriptSpan, _subnodes: Node[], _variables?: Variable[]);
|
|
8
11
|
get type(): Type;
|
|
9
12
|
compile(type: Type): Node;
|
|
10
|
-
evaluate(): Value;
|
|
13
|
+
evaluate(frame: CallFrame): Value;
|
|
11
14
|
toString(ident?: number): string;
|
|
12
15
|
}
|
package/dst/node/BlockNode.js
CHANGED
|
@@ -2,11 +2,14 @@ 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 BlockNode extends Node {
|
|
6
7
|
_subnodes;
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
_variables;
|
|
9
|
+
constructor(span, _subnodes, _variables = []) {
|
|
10
|
+
super(span);
|
|
9
11
|
this._subnodes = _subnodes;
|
|
12
|
+
this._variables = _variables;
|
|
10
13
|
}
|
|
11
14
|
get type() {
|
|
12
15
|
return this._subnodes.length ? this._subnodes[this._subnodes.length - 1].type : Type.Void;
|
|
@@ -22,17 +25,18 @@ export class BlockNode extends Node {
|
|
|
22
25
|
constant &&= this._subnodes[i].constant;
|
|
23
26
|
}
|
|
24
27
|
if (constant) {
|
|
25
|
-
return new ConstantNode(this, new Constant(this.evaluate(), this.type));
|
|
28
|
+
return new ConstantNode(this, new Constant(this.evaluate(new CallFrame()), this.type));
|
|
26
29
|
}
|
|
27
|
-
if (this._subnodes.length === 1) {
|
|
30
|
+
if (this._subnodes.length === 1 && this._variables.length === 0) {
|
|
28
31
|
return this._subnodes[0];
|
|
29
32
|
}
|
|
30
33
|
return this;
|
|
31
34
|
}
|
|
32
|
-
evaluate() {
|
|
35
|
+
evaluate(frame) {
|
|
36
|
+
const subframe = this._variables.length ? frame.subframe(this._variables) : frame;
|
|
33
37
|
let result = undefined;
|
|
34
38
|
for (const subnode of this._subnodes) {
|
|
35
|
-
result = subnode.evaluate();
|
|
39
|
+
result = subnode.evaluate(subframe);
|
|
36
40
|
}
|
|
37
41
|
return result;
|
|
38
42
|
}
|
package/dst/node/CallNode.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Node } from "../Node.js";
|
|
2
|
-
import {
|
|
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 CallNode extends Node {
|
|
6
7
|
protected _fnode: Node;
|
|
7
8
|
protected _subnodes: Node[];
|
|
8
9
|
protected _type: Type;
|
|
9
|
-
constructor(
|
|
10
|
+
constructor(span: ScriptSpan, _fnode: 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
|
}
|
package/dst/node/CallNode.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Node } from "../Node.js";
|
|
2
2
|
import { Constant } from "../Constant.js";
|
|
3
3
|
import { ConstantNode } from "./ConstantNode.js";
|
|
4
|
-
import {
|
|
4
|
+
import { VariadicNode } from "./VariadicNode.js";
|
|
5
5
|
import { normalize } from "../Value.js";
|
|
6
6
|
import { Type } from "../Type.js";
|
|
7
|
-
import {
|
|
7
|
+
import { CallFrame } from "../CallFrame.js";
|
|
8
8
|
export class CallNode extends Node {
|
|
9
9
|
_fnode;
|
|
10
10
|
_subnodes;
|
|
11
11
|
_type;
|
|
12
|
-
constructor(
|
|
13
|
-
super(
|
|
12
|
+
constructor(span, _fnode, _subnodes) {
|
|
13
|
+
super(span);
|
|
14
14
|
this._fnode = _fnode;
|
|
15
15
|
this._subnodes = _subnodes;
|
|
16
16
|
const functionAtoms = this._fnode.type.functionAtoms(Type.Unknown, this._subnodes.length);
|
|
@@ -33,47 +33,34 @@ export class CallNode extends Node {
|
|
|
33
33
|
this.throwError(`value of type ${this._fnode.type} cannot be called with ${this._subnodes.length} argument(s) and return a type compatible with ${type}`);
|
|
34
34
|
}
|
|
35
35
|
this._type = Type.union(...functionAtoms.map((i) => i.retType));
|
|
36
|
-
const
|
|
36
|
+
const variadicArity = functionAtoms[0].isVariadic
|
|
37
37
|
? Math.max(...functionAtoms.map((atom) => atom.arity))
|
|
38
38
|
: 0;
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
41
|
-
const vnodes = this._subnodes.splice(
|
|
42
|
-
this._subnodes.push(new
|
|
39
|
+
if (variadicArity > 0) {
|
|
40
|
+
const span = this._subnodes[variadicArity - 1].start();
|
|
41
|
+
const vnodes = this._subnodes.splice(variadicArity - 1);
|
|
42
|
+
this._subnodes.push(new VariadicNode(span.end(vnodes[vnodes.length - 1]), vnodes));
|
|
43
43
|
}
|
|
44
44
|
let constant = this._fnode.constant;
|
|
45
45
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
46
46
|
const argTypes = functionAtoms.map((a) => a.argType(i));
|
|
47
|
-
const argType =
|
|
47
|
+
const argType = variadicArity > 0 && i === variadicArity - 1
|
|
48
48
|
? Type.arrayType([Type.union(...functionAtoms.map((a) => a.paramType(i) ?? Type.Unknown))])
|
|
49
49
|
: Type.union(...argTypes.filter((t) => t != null));
|
|
50
50
|
this._subnodes[i] = this._subnodes[i].compile(argType);
|
|
51
51
|
constant &&= this._subnodes[i].constant;
|
|
52
52
|
}
|
|
53
|
-
if (constant) {
|
|
54
|
-
return new ConstantNode(this, new Constant(this.evaluate(), this.type));
|
|
53
|
+
if (constant && !this.type.intersect(Type.Reference)) {
|
|
54
|
+
return new ConstantNode(this, new Constant(this.evaluate(new CallFrame()), this.type));
|
|
55
55
|
}
|
|
56
56
|
return this;
|
|
57
57
|
}
|
|
58
|
-
evaluate() {
|
|
59
|
-
const func = this._fnode.evaluate();
|
|
58
|
+
evaluate(frame) {
|
|
59
|
+
const func = this._fnode.evaluate(frame);
|
|
60
60
|
if (typeof func !== "function") {
|
|
61
61
|
this.throwError(`function expected not ${Type.of(func)}`);
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
return normalize(func(...this._subnodes.map((node) => node.evaluate())));
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
if (e instanceof JumpException) {
|
|
68
|
-
if (e.jump === "return") {
|
|
69
|
-
return normalize(e.value);
|
|
70
|
-
}
|
|
71
|
-
if (e.jump === "stop" || e.jump === "next") {
|
|
72
|
-
throw this.throwError(`unexpected ${e.jump} jump`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
throw e;
|
|
76
|
-
}
|
|
63
|
+
return normalize(func(...this._subnodes.map((node) => node.evaluate(frame))));
|
|
77
64
|
}
|
|
78
65
|
toString(ident = 0) {
|
|
79
66
|
const subnodes = this._subnodes.map((s) => s.toString(ident + 1)).join("\n");
|
package/dst/node/CastNode.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Node } from "../Node.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ScriptSpan } from "../ScriptSpan.js";
|
|
3
3
|
import { Type } from "../Type.js";
|
|
4
4
|
import { Value } from "../Value.js";
|
|
5
|
+
import { CallFrame } from "../CallFrame.js";
|
|
5
6
|
export declare class CastNode extends Node {
|
|
6
7
|
protected _subnode: Node;
|
|
7
8
|
protected readonly _target: Type;
|
|
8
9
|
protected _type: Type;
|
|
9
|
-
constructor(
|
|
10
|
+
constructor(span: ScriptSpan, _subnode: Node, _target: Type);
|
|
10
11
|
get type(): Type;
|
|
11
12
|
compile(type: Type): Node;
|
|
12
|
-
evaluate(): Value;
|
|
13
|
+
evaluate(frame: CallFrame): Value;
|
|
13
14
|
get constant(): boolean;
|
|
14
15
|
toString(ident?: number): string;
|
|
15
16
|
}
|
package/dst/node/CastNode.js
CHANGED
|
@@ -4,8 +4,8 @@ export class CastNode extends Node {
|
|
|
4
4
|
_subnode;
|
|
5
5
|
_target;
|
|
6
6
|
_type;
|
|
7
|
-
constructor(
|
|
8
|
-
super(
|
|
7
|
+
constructor(span, _subnode, _target) {
|
|
8
|
+
super(span);
|
|
9
9
|
this._subnode = _subnode;
|
|
10
10
|
this._target = _target;
|
|
11
11
|
this._type = _target;
|
|
@@ -22,8 +22,8 @@ export class CastNode extends Node {
|
|
|
22
22
|
this._type = this.reduceType(type);
|
|
23
23
|
return this;
|
|
24
24
|
}
|
|
25
|
-
evaluate() {
|
|
26
|
-
const value = this._subnode.evaluate();
|
|
25
|
+
evaluate(frame) {
|
|
26
|
+
const value = this._subnode.evaluate(frame);
|
|
27
27
|
if (!this._type.acceptValue(value)) {
|
|
28
28
|
this.throwError(`cannot cast value of type ${Type.of(value)} to ${this._type}`);
|
|
29
29
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Node } from "../Node.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ScriptSpan } from "../ScriptSpan.js";
|
|
3
3
|
import { Constant } from "../Constant.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 ConstantNode extends Node {
|
|
7
8
|
protected readonly _constant: Constant;
|
|
8
9
|
protected _subnode?: Node | undefined;
|
|
9
|
-
|
|
10
|
+
protected readonly _factory?: ((frame: CallFrame) => Value) | undefined;
|
|
11
|
+
constructor(span: ScriptSpan, _constant: Constant, _subnode?: Node | undefined, _factory?: ((frame: CallFrame) => Value) | undefined);
|
|
10
12
|
get type(): Type;
|
|
11
13
|
compile(type: Type): Node;
|
|
12
|
-
evaluate(): Value;
|
|
14
|
+
evaluate(frame: CallFrame): Value;
|
|
13
15
|
get constant(): boolean;
|
|
14
16
|
toString(ident?: number): string;
|
|
15
17
|
}
|
package/dst/node/ConstantNode.js
CHANGED
|
@@ -2,10 +2,12 @@ import { Node } from "../Node.js";
|
|
|
2
2
|
export class ConstantNode extends Node {
|
|
3
3
|
_constant;
|
|
4
4
|
_subnode;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
_factory;
|
|
6
|
+
constructor(span, _constant, _subnode, _factory) {
|
|
7
|
+
super(span);
|
|
7
8
|
this._constant = _constant;
|
|
8
9
|
this._subnode = _subnode;
|
|
10
|
+
this._factory = _factory;
|
|
9
11
|
}
|
|
10
12
|
get type() {
|
|
11
13
|
return this._constant.type;
|
|
@@ -15,11 +17,11 @@ export class ConstantNode extends Node {
|
|
|
15
17
|
this._subnode = this._subnode?.compile(this._constant.type.functionAtomRetType(type));
|
|
16
18
|
return this;
|
|
17
19
|
}
|
|
18
|
-
evaluate() {
|
|
19
|
-
return this._constant.value;
|
|
20
|
+
evaluate(frame) {
|
|
21
|
+
return this._factory ? this._factory(frame) : this._constant.value;
|
|
20
22
|
}
|
|
21
23
|
get constant() {
|
|
22
|
-
return !this._subnode && this._constant.deterministic;
|
|
24
|
+
return !this._factory && !this._subnode && this._constant.deterministic;
|
|
23
25
|
}
|
|
24
26
|
toString(ident = 0) {
|
|
25
27
|
return this._subnode
|
package/dst/node/JumpNode.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Node } from "../Node.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ScriptSpan } from "../ScriptSpan.js";
|
|
3
3
|
import { Value } from "../Value.js";
|
|
4
4
|
import { Type } from "../Type.js";
|
|
5
5
|
import { Jump } from "../Jump.js";
|
|
6
|
+
import { CallFrame } from "../CallFrame.js";
|
|
6
7
|
export declare class JumpNode extends Node {
|
|
7
8
|
protected _jump: Jump;
|
|
8
9
|
protected _subnode?: Node | undefined;
|
|
9
|
-
|
|
10
|
+
protected _type?: Type | undefined;
|
|
11
|
+
constructor(span: ScriptSpan, _jump: Jump, _subnode?: Node | undefined, _type?: Type | undefined);
|
|
10
12
|
get type(): Type;
|
|
11
13
|
compile(type: Type): Node;
|
|
12
|
-
evaluate(): Value;
|
|
14
|
+
evaluate(frame: CallFrame): Value;
|
|
13
15
|
toString(ident?: number): string;
|
|
14
16
|
}
|
package/dst/node/JumpNode.js
CHANGED
|
@@ -4,20 +4,24 @@ import { JumpException } from "../JumpException.js";
|
|
|
4
4
|
export class JumpNode extends Node {
|
|
5
5
|
_jump;
|
|
6
6
|
_subnode;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
_type;
|
|
8
|
+
constructor(span, _jump, _subnode, _type) {
|
|
9
|
+
super(span);
|
|
9
10
|
this._jump = _jump;
|
|
10
11
|
this._subnode = _subnode;
|
|
12
|
+
this._type = _type;
|
|
11
13
|
}
|
|
12
14
|
get type() {
|
|
13
|
-
return this._subnode?.type ?? Type.Void;
|
|
15
|
+
return this._type ?? this._subnode?.type ?? Type.Void;
|
|
14
16
|
}
|
|
15
17
|
compile(type) {
|
|
16
|
-
this._subnode = this._subnode?.compile(
|
|
18
|
+
this._subnode = this._subnode?.compile(this._jump === "exit" || this._jump === "return"
|
|
19
|
+
? this._type ?? Type.Unknown
|
|
20
|
+
: type);
|
|
17
21
|
return this;
|
|
18
22
|
}
|
|
19
|
-
evaluate() {
|
|
20
|
-
throw new JumpException(this._jump, this._subnode?.evaluate());
|
|
23
|
+
evaluate(frame) {
|
|
24
|
+
throw new JumpException(this._jump, this._subnode?.evaluate(frame));
|
|
21
25
|
}
|
|
22
26
|
toString(ident = 0) {
|
|
23
27
|
return this._subnode
|
package/dst/node/LoopNode.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Node } from "../Node.js";
|
|
2
|
-
import {
|
|
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 LoopNode extends Node {
|
|
6
7
|
protected _cnode: Node;
|
|
7
8
|
protected _subnode: Node;
|
|
8
|
-
constructor(
|
|
9
|
+
constructor(span: ScriptSpan, _cnode: Node, _subnode: 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
|
}
|