affinirum 1.5.2 → 1.5.3
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 +82 -75
- package/dst/CallFrame.d.ts +11 -0
- package/dst/CallFrame.js +35 -0
- package/dst/LexicalScope.d.ts +13 -0
- package/dst/LexicalScope.js +27 -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.js +82 -75
- package/dst/cjs/CallFrame.js +39 -0
- package/dst/cjs/LexicalScope.js +31 -0
- package/dst/cjs/Node.js +5 -5
- package/dst/cjs/ParserState.js +40 -40
- package/dst/cjs/{ParserFrame.js → ScriptSpan.js} +22 -33
- package/dst/cjs/Type.js +2 -0
- package/dst/cjs/Variable.js +0 -7
- package/dst/cjs/native/Number.js +24 -11
- package/dst/cjs/native/notation/AN.js +2 -2
- package/dst/cjs/node/ArrayNode.js +4 -11
- package/dst/cjs/node/BlockNode.js +10 -6
- package/dst/cjs/node/CallNode.js +15 -28
- package/dst/cjs/node/CastNode.js +4 -4
- package/dst/cjs/node/ConstantNode.js +7 -5
- package/dst/cjs/node/JumpNode.js +4 -4
- package/dst/cjs/node/LoopNode.js +5 -5
- package/dst/cjs/node/ObjectNode.js +6 -12
- package/dst/cjs/node/SwitchNode.js +8 -7
- package/dst/cjs/node/VariableNode.js +5 -5
- package/dst/cjs/node/VariadicNode.js +10 -0
- package/dst/native/Number.js +24 -11
- 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 +4 -3
- package/dst/node/JumpNode.js +4 -4
- 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/cjs/ParserState.js
CHANGED
|
@@ -10,7 +10,7 @@ const String_js_1 = require("./native/String.js");
|
|
|
10
10
|
const Timestamp_js_1 = require("./native/Timestamp.js");
|
|
11
11
|
const Constant_js_1 = require("./Constant.js");
|
|
12
12
|
const Type_js_1 = require("./Type.js");
|
|
13
|
-
const
|
|
13
|
+
const ScriptSpan_js_1 = require("./ScriptSpan.js");
|
|
14
14
|
class Literal {
|
|
15
15
|
value;
|
|
16
16
|
constructor(value) {
|
|
@@ -57,10 +57,10 @@ const idExit = Symbol();
|
|
|
57
57
|
const idReturn = Symbol();
|
|
58
58
|
const idStop = Symbol();
|
|
59
59
|
const idNext = Symbol();
|
|
60
|
-
class ParserState extends
|
|
60
|
+
class ParserState extends ScriptSpan_js_1.ScriptSpan {
|
|
61
61
|
_fragment;
|
|
62
|
-
constructor(
|
|
63
|
-
super(
|
|
62
|
+
constructor(script) {
|
|
63
|
+
super(script);
|
|
64
64
|
}
|
|
65
65
|
get literal() {
|
|
66
66
|
return this._fragment;
|
|
@@ -207,7 +207,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
207
207
|
return this;
|
|
208
208
|
}
|
|
209
209
|
clone() {
|
|
210
|
-
const state = new ParserState(this.
|
|
210
|
+
const state = new ParserState(this._script);
|
|
211
211
|
state._start = this._start;
|
|
212
212
|
state._end = this._end;
|
|
213
213
|
state._fragment = this._fragment;
|
|
@@ -215,9 +215,9 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
215
215
|
}
|
|
216
216
|
next() {
|
|
217
217
|
this._fragment = undefined;
|
|
218
|
-
while (this._end < this.
|
|
218
|
+
while (this._end < this._script.length && this._fragment == null) {
|
|
219
219
|
this._start = this._end;
|
|
220
|
-
const c = this.
|
|
220
|
+
const c = this._script.charAt(this._end);
|
|
221
221
|
++this._end;
|
|
222
222
|
switch (c) {
|
|
223
223
|
case " ":
|
|
@@ -248,7 +248,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
248
248
|
this._fragment = idSemicolon;
|
|
249
249
|
break;
|
|
250
250
|
case ":":
|
|
251
|
-
switch (this.
|
|
251
|
+
switch (this._script.charAt(this._end)) {
|
|
252
252
|
case ":":
|
|
253
253
|
++this._end;
|
|
254
254
|
this._fragment = idCast;
|
|
@@ -262,7 +262,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
262
262
|
this._fragment = idComma;
|
|
263
263
|
break;
|
|
264
264
|
case "~":
|
|
265
|
-
switch (this.
|
|
265
|
+
switch (this._script.charAt(this._end)) {
|
|
266
266
|
case ">":
|
|
267
267
|
++this._end;
|
|
268
268
|
this._fragment = idReturn;
|
|
@@ -273,7 +273,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
273
273
|
}
|
|
274
274
|
break;
|
|
275
275
|
case "?":
|
|
276
|
-
switch (this.
|
|
276
|
+
switch (this._script.charAt(this._end)) {
|
|
277
277
|
case "?":
|
|
278
278
|
++this._end;
|
|
279
279
|
this._fragment = Type_js_1.Type.Unknown;
|
|
@@ -288,7 +288,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
288
288
|
}
|
|
289
289
|
break;
|
|
290
290
|
case "|":
|
|
291
|
-
switch (this.
|
|
291
|
+
switch (this._script.charAt(this._end)) {
|
|
292
292
|
case "=":
|
|
293
293
|
++this._end;
|
|
294
294
|
this._fragment = funcOrAssignment;
|
|
@@ -299,7 +299,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
299
299
|
}
|
|
300
300
|
break;
|
|
301
301
|
case "&":
|
|
302
|
-
switch (this.
|
|
302
|
+
switch (this._script.charAt(this._end)) {
|
|
303
303
|
case "=":
|
|
304
304
|
++this._end;
|
|
305
305
|
this._fragment = funcAndAssignment;
|
|
@@ -310,7 +310,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
310
310
|
}
|
|
311
311
|
break;
|
|
312
312
|
case ">":
|
|
313
|
-
switch (this.
|
|
313
|
+
switch (this._script.charAt(this._end)) {
|
|
314
314
|
case "=":
|
|
315
315
|
++this._end;
|
|
316
316
|
this._fragment = Number_js_1.funcGreaterOrEqual;
|
|
@@ -321,7 +321,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
321
321
|
}
|
|
322
322
|
break;
|
|
323
323
|
case "<":
|
|
324
|
-
switch (this.
|
|
324
|
+
switch (this._script.charAt(this._end)) {
|
|
325
325
|
case "=":
|
|
326
326
|
++this._end;
|
|
327
327
|
this._fragment = Number_js_1.funcLessOrEqual;
|
|
@@ -332,7 +332,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
332
332
|
}
|
|
333
333
|
break;
|
|
334
334
|
case "!":
|
|
335
|
-
switch (this.
|
|
335
|
+
switch (this._script.charAt(this._end)) {
|
|
336
336
|
case "=":
|
|
337
337
|
++this._end;
|
|
338
338
|
this._fragment = Unknown_js_1.funcNotEqual;
|
|
@@ -343,7 +343,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
343
343
|
}
|
|
344
344
|
break;
|
|
345
345
|
case "=":
|
|
346
|
-
switch (this.
|
|
346
|
+
switch (this._script.charAt(this._end)) {
|
|
347
347
|
case "=":
|
|
348
348
|
++this._end;
|
|
349
349
|
this._fragment = Unknown_js_1.funcEqual;
|
|
@@ -358,7 +358,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
358
358
|
}
|
|
359
359
|
break;
|
|
360
360
|
case "+":
|
|
361
|
-
switch (this.
|
|
361
|
+
switch (this._script.charAt(this._end)) {
|
|
362
362
|
case "=":
|
|
363
363
|
++this._end;
|
|
364
364
|
this._fragment = funcAddAssignment;
|
|
@@ -369,7 +369,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
369
369
|
}
|
|
370
370
|
break;
|
|
371
371
|
case "-":
|
|
372
|
-
switch (this.
|
|
372
|
+
switch (this._script.charAt(this._end)) {
|
|
373
373
|
case "=":
|
|
374
374
|
++this._end;
|
|
375
375
|
this._fragment = funcSubtractAssignment;
|
|
@@ -380,7 +380,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
380
380
|
}
|
|
381
381
|
break;
|
|
382
382
|
case "*":
|
|
383
|
-
switch (this.
|
|
383
|
+
switch (this._script.charAt(this._end)) {
|
|
384
384
|
case "=":
|
|
385
385
|
++this._end;
|
|
386
386
|
this._fragment = funcMultiplyAssignment;
|
|
@@ -391,29 +391,29 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
391
391
|
}
|
|
392
392
|
break;
|
|
393
393
|
case "/":
|
|
394
|
-
switch (this.
|
|
394
|
+
switch (this._script.charAt(this._end)) {
|
|
395
395
|
case "=":
|
|
396
396
|
++this._end;
|
|
397
397
|
this._fragment = funcDivideAssignment;
|
|
398
398
|
break;
|
|
399
399
|
case "/":
|
|
400
|
-
if (this.
|
|
400
|
+
if (this._script.charAt(++this._end) === "/") {
|
|
401
401
|
++this._end;
|
|
402
|
-
while (this.
|
|
403
|
-
&& (this.
|
|
404
|
-
|| this.
|
|
405
|
-
|| this.
|
|
402
|
+
while (this._script.charAt(this._end) !== ""
|
|
403
|
+
&& (this._script.charAt(this._end) !== c
|
|
404
|
+
|| this._script.charAt(this._end - 1) !== c
|
|
405
|
+
|| this._script.charAt(this._end - 2) !== c)) {
|
|
406
406
|
++this._end;
|
|
407
407
|
}
|
|
408
|
-
if (this._end >= this.
|
|
409
|
-
this._start = this.
|
|
408
|
+
if (this._end >= this._script.length) {
|
|
409
|
+
this._start = this._script.length;
|
|
410
410
|
throw new Error("missing closing comment mark");
|
|
411
411
|
}
|
|
412
412
|
++this._end;
|
|
413
413
|
}
|
|
414
414
|
else {
|
|
415
|
-
while (this.
|
|
416
|
-
&& this.
|
|
415
|
+
while (this._script.charAt(this._end) !== ""
|
|
416
|
+
&& this._script.charAt(this._end) !== "\n") {
|
|
417
417
|
++this._end;
|
|
418
418
|
}
|
|
419
419
|
}
|
|
@@ -424,7 +424,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
424
424
|
}
|
|
425
425
|
break;
|
|
426
426
|
case "%":
|
|
427
|
-
switch (this.
|
|
427
|
+
switch (this._script.charAt(this._end)) {
|
|
428
428
|
case "=":
|
|
429
429
|
++this._end;
|
|
430
430
|
this._fragment = funcRemainderAssignment;
|
|
@@ -438,9 +438,9 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
438
438
|
this._fragment = Number_js_1.funcPower;
|
|
439
439
|
break;
|
|
440
440
|
case ".":
|
|
441
|
-
switch (this.
|
|
441
|
+
switch (this._script.charAt(this._end)) {
|
|
442
442
|
case ".":
|
|
443
|
-
if (this.
|
|
443
|
+
if (this._script.charAt(++this._end) === ".") {
|
|
444
444
|
++this._end;
|
|
445
445
|
this._fragment = idEllipsis;
|
|
446
446
|
}
|
|
@@ -454,30 +454,30 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
454
454
|
}
|
|
455
455
|
break;
|
|
456
456
|
case "@": {
|
|
457
|
-
const [ts, tsEnd] = (0, Timestamp_js_1.parseLiteralTimestamp)(this.
|
|
457
|
+
const [ts, tsEnd] = (0, Timestamp_js_1.parseLiteralTimestamp)(this._script, this._start);
|
|
458
458
|
this._fragment = new Literal(ts);
|
|
459
459
|
this._end = tsEnd;
|
|
460
460
|
break;
|
|
461
461
|
}
|
|
462
462
|
case "`": {
|
|
463
|
-
const [buf, bufEnd] = (0, Buffer_js_1.parseLiteralBuffer)(this.
|
|
463
|
+
const [buf, bufEnd] = (0, Buffer_js_1.parseLiteralBuffer)(this._script, this._start);
|
|
464
464
|
this._fragment = new Literal(buf);
|
|
465
465
|
this._end = bufEnd;
|
|
466
466
|
break;
|
|
467
467
|
}
|
|
468
468
|
case "\"":
|
|
469
469
|
case "'": {
|
|
470
|
-
const [str, strEnd] = (0, String_js_1.parseLiteralString)(this.
|
|
470
|
+
const [str, strEnd] = (0, String_js_1.parseLiteralString)(this._script, this._start);
|
|
471
471
|
this._fragment = new Literal(str);
|
|
472
472
|
this._end = strEnd;
|
|
473
473
|
break;
|
|
474
474
|
}
|
|
475
475
|
default:
|
|
476
476
|
if ((0, String_js_1.isTokenStartSymbol)(c)) {
|
|
477
|
-
while ((0, String_js_1.isTokenSymbol)(this.
|
|
477
|
+
while ((0, String_js_1.isTokenSymbol)(this._script.charAt(this._end))) {
|
|
478
478
|
++this._end;
|
|
479
479
|
}
|
|
480
|
-
const token = this.
|
|
480
|
+
const token = this._script.substring(this._start, this._end);
|
|
481
481
|
switch (token) {
|
|
482
482
|
case "true":
|
|
483
483
|
this._fragment = valueTrue;
|
|
@@ -549,7 +549,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
551
|
else if ((0, Number_js_1.isNumericSymbol)(c)) {
|
|
552
|
-
const [num, numEnd] = (0, Number_js_1.parseLiteralNumber)(this.
|
|
552
|
+
const [num, numEnd] = (0, Number_js_1.parseLiteralNumber)(this._script, this._start);
|
|
553
553
|
this._fragment = new Literal(num);
|
|
554
554
|
this._end = numEnd;
|
|
555
555
|
}
|
|
@@ -559,8 +559,8 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
559
559
|
break;
|
|
560
560
|
}
|
|
561
561
|
}
|
|
562
|
-
if (this._end > this.
|
|
563
|
-
this._start = this._end = this.
|
|
562
|
+
if (this._end > this._script.length) {
|
|
563
|
+
this._start = this._end = this._script.length;
|
|
564
564
|
}
|
|
565
565
|
return this;
|
|
566
566
|
}
|
|
@@ -1,44 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
_start;
|
|
7
|
-
_end;
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this._end = _end;
|
|
12
|
-
}
|
|
13
|
-
get expr() {
|
|
14
|
-
return this._expr;
|
|
15
|
-
}
|
|
16
|
-
get start() {
|
|
17
|
-
return this._start;
|
|
18
|
-
}
|
|
19
|
-
get end() {
|
|
20
|
-
return this._end;
|
|
21
|
-
}
|
|
22
|
-
starts(frame) {
|
|
23
|
-
if (frame) {
|
|
24
|
-
this._start = frame.start;
|
|
25
|
-
return this;
|
|
3
|
+
exports.ScriptSpan = void 0;
|
|
4
|
+
class ScriptSpan {
|
|
5
|
+
_script;
|
|
6
|
+
_start = 0;
|
|
7
|
+
_end = 0;
|
|
8
|
+
constructor(span) {
|
|
9
|
+
if (typeof span === "string") {
|
|
10
|
+
this._script = span;
|
|
26
11
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this._end = frame.end;
|
|
32
|
-
return this;
|
|
12
|
+
else {
|
|
13
|
+
this._script = span._script;
|
|
14
|
+
this._start = span._start;
|
|
15
|
+
this._end = span._end;
|
|
33
16
|
}
|
|
34
|
-
|
|
17
|
+
}
|
|
18
|
+
start() {
|
|
19
|
+
return new ScriptSpan(this);
|
|
20
|
+
}
|
|
21
|
+
end(span) {
|
|
22
|
+
this._end = span._end;
|
|
23
|
+
return this;
|
|
35
24
|
}
|
|
36
25
|
throwError(message) {
|
|
37
26
|
const offset = this._start < 32 ? 0 : this._start - 32;
|
|
38
27
|
const length = this._end < this._start ? 0 : this._end - this._start - 1;
|
|
39
28
|
let expr = "";
|
|
40
|
-
for (let i = 0; i < this.
|
|
41
|
-
const c = this.
|
|
29
|
+
for (let i = 0; i < this._script.length; ++i) {
|
|
30
|
+
const c = this._script[i];
|
|
42
31
|
expr += SPACE_SYMBOLS.includes(c) ? " " : c;
|
|
43
32
|
}
|
|
44
33
|
throw new Error(`error: ${message} at position ${this._start}:\n${expr.substring(offset, offset + 60)}\n` +
|
|
@@ -48,7 +37,7 @@ class ParserFrame {
|
|
|
48
37
|
return `[${this._start}:${this._end}]`;
|
|
49
38
|
}
|
|
50
39
|
}
|
|
51
|
-
exports.
|
|
40
|
+
exports.ScriptSpan = ScriptSpan;
|
|
52
41
|
const SPACE_SYMBOLS = [
|
|
53
42
|
// Whitespace and line-breaking characters
|
|
54
43
|
"\t", // tab
|
package/dst/cjs/Type.js
CHANGED
|
@@ -245,6 +245,8 @@ class Type {
|
|
|
245
245
|
static OptionalObject = Type.union(Type.Void, Type.Object);
|
|
246
246
|
static Function = Type.functionType(undefined, undefined, true);
|
|
247
247
|
static OptionalFunction = Type.union(Type.Void, Type.Function);
|
|
248
|
+
static Reference = Type.union(Type.Array, Type.Object, Type.Function);
|
|
249
|
+
static OptionalReference = Type.union(Type.Void, Type.Array, Type.Object, Type.Function);
|
|
248
250
|
static Number = Type.union(Type.Float, Type.Integer);
|
|
249
251
|
static OptionalNumber = Type.union(Type.Void, Type.Float, Type.Integer);
|
|
250
252
|
static Enumerable = Type.union(Type.Buffer, Type.String, Type.Array);
|
package/dst/cjs/Variable.js
CHANGED
|
@@ -5,17 +5,10 @@ const Type_js_1 = require("./Type.js");
|
|
|
5
5
|
class Variable {
|
|
6
6
|
_type;
|
|
7
7
|
_assignable;
|
|
8
|
-
_value;
|
|
9
8
|
constructor(_type = Type_js_1.Type.Unknown, _assignable = true) {
|
|
10
9
|
this._type = _type;
|
|
11
10
|
this._assignable = _assignable;
|
|
12
11
|
}
|
|
13
|
-
get value() {
|
|
14
|
-
return this._value;
|
|
15
|
-
}
|
|
16
|
-
set value(value) {
|
|
17
|
-
this._value = value;
|
|
18
|
-
}
|
|
19
12
|
get type() {
|
|
20
13
|
return this._type;
|
|
21
14
|
}
|
package/dst/cjs/native/Number.js
CHANGED
|
@@ -9,9 +9,10 @@ exports.isSignSymbol = isSignSymbol;
|
|
|
9
9
|
const isNumericSymbol = (c) => c >= "0" && c <= "9";
|
|
10
10
|
exports.isNumericSymbol = isNumericSymbol;
|
|
11
11
|
const formatLiteralNumber = (value) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const str = value.toString();
|
|
13
|
+
return typeof value === "number" && Number.isInteger(value) && !str.includes("e")
|
|
14
|
+
? `${str}.0`
|
|
15
|
+
: str;
|
|
15
16
|
};
|
|
16
17
|
exports.formatLiteralNumber = formatLiteralNumber;
|
|
17
18
|
const parseLiteralNumber = (value, offset = 0) => {
|
|
@@ -92,23 +93,28 @@ exports.funcPower = new Constant_js_1.Constant((value, exponent) => typeof value
|
|
|
92
93
|
? (0, Integer_js_1.boundInteger)(value ** BigInt(exponent))
|
|
93
94
|
: Number(value) ** Number(exponent), typeOperator);
|
|
94
95
|
exports.funcRoot = new Constant_js_1.Constant((value, exponent) => {
|
|
96
|
+
if (exponent <= 0) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
95
99
|
if (typeof value === "bigint" && typeof exponent === "bigint") {
|
|
96
100
|
const v = (0, Integer_js_1.boundInteger)(value);
|
|
97
101
|
const e = (0, Integer_js_1.boundInteger)(exponent);
|
|
98
|
-
|
|
102
|
+
const negative = v < 0n;
|
|
103
|
+
if (negative && e % 2n === 0n) {
|
|
99
104
|
return undefined;
|
|
100
105
|
}
|
|
101
|
-
|
|
106
|
+
const magnitude = negative ? -v : v;
|
|
107
|
+
if (magnitude <= 1n || e === 1n) {
|
|
102
108
|
return v;
|
|
103
109
|
}
|
|
104
|
-
let low = 0n, high =
|
|
110
|
+
let low = 0n, high = magnitude, result = 0n;
|
|
105
111
|
while (low <= high) {
|
|
106
112
|
const mid = low + high >> 1n;
|
|
107
113
|
const midPow = mid ** e;
|
|
108
|
-
if (midPow ===
|
|
109
|
-
return mid;
|
|
114
|
+
if (midPow === magnitude) {
|
|
115
|
+
return negative ? -mid : mid;
|
|
110
116
|
}
|
|
111
|
-
else if (midPow <
|
|
117
|
+
else if (midPow < magnitude) {
|
|
112
118
|
result = mid;
|
|
113
119
|
low = mid + 1n;
|
|
114
120
|
}
|
|
@@ -116,8 +122,15 @@ exports.funcRoot = new Constant_js_1.Constant((value, exponent) => {
|
|
|
116
122
|
high = mid - 1n;
|
|
117
123
|
}
|
|
118
124
|
}
|
|
119
|
-
return result;
|
|
125
|
+
return negative ? -result : result;
|
|
120
126
|
}
|
|
121
|
-
|
|
127
|
+
const v = Number(value);
|
|
128
|
+
const e = Number(exponent);
|
|
129
|
+
const odd = typeof exponent === "bigint"
|
|
130
|
+
? exponent % 2n !== 0n
|
|
131
|
+
: Number.isInteger(exponent) && exponent % 2 !== 0;
|
|
132
|
+
return (v < 0 || Object.is(v, -0)) && odd
|
|
133
|
+
? -Math.pow(-v, 1 / e)
|
|
134
|
+
: Math.pow(v, 1 / e);
|
|
122
135
|
}, typeOperator);
|
|
123
136
|
exports.funcNegate = new Constant_js_1.Constant((value) => value == null ? undefined : typeof value === "number" ? -value : (0, Integer_js_1.boundInteger)(-value), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer])));
|
|
@@ -13,7 +13,7 @@ const Timestamp_js_1 = require("../Timestamp.js");
|
|
|
13
13
|
const typeAN = Type_js_1.Type.union(Type_js_1.Type.Void, Type_js_1.Type.Boolean, Type_js_1.Type.Timestamp, Type_js_1.Type.Float, Type_js_1.Type.Integer, Type_js_1.Type.Buffer, Type_js_1.Type.String, Type_js_1.Type.Array, Type_js_1.Type.Object);
|
|
14
14
|
const formatAN = (value, whitespace) => {
|
|
15
15
|
if (value == null) {
|
|
16
|
-
return "";
|
|
16
|
+
return "null";
|
|
17
17
|
}
|
|
18
18
|
if (typeof value === "boolean") {
|
|
19
19
|
return value ? "true" : "false";
|
|
@@ -32,7 +32,7 @@ const formatAN = (value, whitespace) => {
|
|
|
32
32
|
}
|
|
33
33
|
if (Array.isArray(value)) {
|
|
34
34
|
const [prefix, suffix] = whitespace ? ["\n" + whitespace, "\n"] : ["", ""];
|
|
35
|
-
const lines =
|
|
35
|
+
const lines = Array.from(value, (i) => `${prefix}${(0, exports.formatAN)(i, whitespace)?.split("\n").join(prefix) ?? ""}`);
|
|
36
36
|
return lines.length ? `[${lines.join(",")}${suffix}]` : "[]";
|
|
37
37
|
}
|
|
38
38
|
if (typeof value === "object") {
|
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArrayNode = void 0;
|
|
4
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
5
|
const Type_js_1 = require("../Type.js");
|
|
8
6
|
class ArrayNode extends Node_js_1.Node {
|
|
9
7
|
_subnodes;
|
|
10
8
|
_type;
|
|
11
|
-
constructor(
|
|
12
|
-
super(
|
|
9
|
+
constructor(span, _subnodes) {
|
|
10
|
+
super(span);
|
|
13
11
|
this._subnodes = _subnodes;
|
|
14
12
|
this._type = Type_js_1.Type.arrayType(_subnodes.map((i) => i.type));
|
|
15
13
|
}
|
|
@@ -17,23 +15,18 @@ class ArrayNode extends Node_js_1.Node {
|
|
|
17
15
|
return this._type;
|
|
18
16
|
}
|
|
19
17
|
compile(type) {
|
|
20
|
-
let constant = true;
|
|
21
18
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
22
19
|
const valType = type.arrayAtomValType(i);
|
|
23
20
|
this._subnodes[i] = this._subnodes[i].compile(valType);
|
|
24
|
-
constant &&= this._subnodes[i].constant;
|
|
25
21
|
}
|
|
26
22
|
this._type = Type_js_1.Type.arrayType(this._subnodes.map((node) => node.type));
|
|
27
23
|
this._type = this.reduceType(type);
|
|
28
|
-
if (constant) {
|
|
29
|
-
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
|
|
30
|
-
}
|
|
31
24
|
return this;
|
|
32
25
|
}
|
|
33
|
-
evaluate() {
|
|
26
|
+
evaluate(frame) {
|
|
34
27
|
const result = [];
|
|
35
28
|
for (const subnode of this._subnodes) {
|
|
36
|
-
result.push(subnode.evaluate());
|
|
29
|
+
result.push(subnode.evaluate(frame));
|
|
37
30
|
}
|
|
38
31
|
return result;
|
|
39
32
|
}
|
|
@@ -5,11 +5,14 @@ const Node_js_1 = require("../Node.js");
|
|
|
5
5
|
const Constant_js_1 = require("../Constant.js");
|
|
6
6
|
const ConstantNode_js_1 = require("./ConstantNode.js");
|
|
7
7
|
const Type_js_1 = require("../Type.js");
|
|
8
|
+
const CallFrame_js_1 = require("../CallFrame.js");
|
|
8
9
|
class BlockNode extends Node_js_1.Node {
|
|
9
10
|
_subnodes;
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
_variables;
|
|
12
|
+
constructor(span, _subnodes, _variables = []) {
|
|
13
|
+
super(span);
|
|
12
14
|
this._subnodes = _subnodes;
|
|
15
|
+
this._variables = _variables;
|
|
13
16
|
}
|
|
14
17
|
get type() {
|
|
15
18
|
return this._subnodes.length ? this._subnodes[this._subnodes.length - 1].type : Type_js_1.Type.Void;
|
|
@@ -25,17 +28,18 @@ class BlockNode extends Node_js_1.Node {
|
|
|
25
28
|
constant &&= this._subnodes[i].constant;
|
|
26
29
|
}
|
|
27
30
|
if (constant) {
|
|
28
|
-
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
|
|
31
|
+
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(new CallFrame_js_1.CallFrame()), this.type));
|
|
29
32
|
}
|
|
30
|
-
if (this._subnodes.length === 1) {
|
|
33
|
+
if (this._subnodes.length === 1 && this._variables.length === 0) {
|
|
31
34
|
return this._subnodes[0];
|
|
32
35
|
}
|
|
33
36
|
return this;
|
|
34
37
|
}
|
|
35
|
-
evaluate() {
|
|
38
|
+
evaluate(frame) {
|
|
39
|
+
const subframe = this._variables.length ? frame.subframe(this._variables) : frame;
|
|
36
40
|
let result = undefined;
|
|
37
41
|
for (const subnode of this._subnodes) {
|
|
38
|
-
result = subnode.evaluate();
|
|
42
|
+
result = subnode.evaluate(subframe);
|
|
39
43
|
}
|
|
40
44
|
return result;
|
|
41
45
|
}
|
package/dst/cjs/node/CallNode.js
CHANGED
|
@@ -4,16 +4,16 @@ exports.CallNode = void 0;
|
|
|
4
4
|
const Node_js_1 = require("../Node.js");
|
|
5
5
|
const Constant_js_1 = require("../Constant.js");
|
|
6
6
|
const ConstantNode_js_1 = require("./ConstantNode.js");
|
|
7
|
-
const
|
|
7
|
+
const VariadicNode_js_1 = require("./VariadicNode.js");
|
|
8
8
|
const Value_js_1 = require("../Value.js");
|
|
9
9
|
const Type_js_1 = require("../Type.js");
|
|
10
|
-
const
|
|
10
|
+
const CallFrame_js_1 = require("../CallFrame.js");
|
|
11
11
|
class CallNode extends Node_js_1.Node {
|
|
12
12
|
_fnode;
|
|
13
13
|
_subnodes;
|
|
14
14
|
_type;
|
|
15
|
-
constructor(
|
|
16
|
-
super(
|
|
15
|
+
constructor(span, _fnode, _subnodes) {
|
|
16
|
+
super(span);
|
|
17
17
|
this._fnode = _fnode;
|
|
18
18
|
this._subnodes = _subnodes;
|
|
19
19
|
const functionAtoms = this._fnode.type.functionAtoms(Type_js_1.Type.Unknown, this._subnodes.length);
|
|
@@ -36,47 +36,34 @@ class CallNode extends Node_js_1.Node {
|
|
|
36
36
|
this.throwError(`value of type ${this._fnode.type} cannot be called with ${this._subnodes.length} argument(s) and return a type compatible with ${type}`);
|
|
37
37
|
}
|
|
38
38
|
this._type = Type_js_1.Type.union(...functionAtoms.map((i) => i.retType));
|
|
39
|
-
const
|
|
39
|
+
const variadicArity = functionAtoms[0].isVariadic
|
|
40
40
|
? Math.max(...functionAtoms.map((atom) => atom.arity))
|
|
41
41
|
: 0;
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
const vnodes = this._subnodes.splice(
|
|
45
|
-
this._subnodes.push(new
|
|
42
|
+
if (variadicArity > 0) {
|
|
43
|
+
const span = this._subnodes[variadicArity - 1].start();
|
|
44
|
+
const vnodes = this._subnodes.splice(variadicArity - 1);
|
|
45
|
+
this._subnodes.push(new VariadicNode_js_1.VariadicNode(span.end(vnodes[vnodes.length - 1]), vnodes));
|
|
46
46
|
}
|
|
47
47
|
let constant = this._fnode.constant;
|
|
48
48
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
49
49
|
const argTypes = functionAtoms.map((a) => a.argType(i));
|
|
50
|
-
const argType =
|
|
50
|
+
const argType = variadicArity > 0 && i === variadicArity - 1
|
|
51
51
|
? Type_js_1.Type.arrayType([Type_js_1.Type.union(...functionAtoms.map((a) => a.paramType(i) ?? Type_js_1.Type.Unknown))])
|
|
52
52
|
: Type_js_1.Type.union(...argTypes.filter((t) => t != null));
|
|
53
53
|
this._subnodes[i] = this._subnodes[i].compile(argType);
|
|
54
54
|
constant &&= this._subnodes[i].constant;
|
|
55
55
|
}
|
|
56
|
-
if (constant) {
|
|
57
|
-
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
|
|
56
|
+
if (constant && !this.type.intersect(Type_js_1.Type.Reference)) {
|
|
57
|
+
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(new CallFrame_js_1.CallFrame()), this.type));
|
|
58
58
|
}
|
|
59
59
|
return this;
|
|
60
60
|
}
|
|
61
|
-
evaluate() {
|
|
62
|
-
const func = this._fnode.evaluate();
|
|
61
|
+
evaluate(frame) {
|
|
62
|
+
const func = this._fnode.evaluate(frame);
|
|
63
63
|
if (typeof func !== "function") {
|
|
64
64
|
this.throwError(`function expected not ${Type_js_1.Type.of(func)}`);
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
return (0, Value_js_1.normalize)(func(...this._subnodes.map((node) => node.evaluate())));
|
|
68
|
-
}
|
|
69
|
-
catch (e) {
|
|
70
|
-
if (e instanceof JumpException_js_1.JumpException) {
|
|
71
|
-
if (e.jump === "return") {
|
|
72
|
-
return (0, Value_js_1.normalize)(e.value);
|
|
73
|
-
}
|
|
74
|
-
if (e.jump === "stop" || e.jump === "next") {
|
|
75
|
-
throw this.throwError(`unexpected ${e.jump} jump`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
throw e;
|
|
79
|
-
}
|
|
66
|
+
return (0, Value_js_1.normalize)(func(...this._subnodes.map((node) => node.evaluate(frame))));
|
|
80
67
|
}
|
|
81
68
|
toString(ident = 0) {
|
|
82
69
|
const subnodes = this._subnodes.map((s) => s.toString(ident + 1)).join("\n");
|
package/dst/cjs/node/CastNode.js
CHANGED
|
@@ -7,8 +7,8 @@ class CastNode extends Node_js_1.Node {
|
|
|
7
7
|
_subnode;
|
|
8
8
|
_target;
|
|
9
9
|
_type;
|
|
10
|
-
constructor(
|
|
11
|
-
super(
|
|
10
|
+
constructor(span, _subnode, _target) {
|
|
11
|
+
super(span);
|
|
12
12
|
this._subnode = _subnode;
|
|
13
13
|
this._target = _target;
|
|
14
14
|
this._type = _target;
|
|
@@ -25,8 +25,8 @@ class CastNode extends Node_js_1.Node {
|
|
|
25
25
|
this._type = this.reduceType(type);
|
|
26
26
|
return this;
|
|
27
27
|
}
|
|
28
|
-
evaluate() {
|
|
29
|
-
const value = this._subnode.evaluate();
|
|
28
|
+
evaluate(frame) {
|
|
29
|
+
const value = this._subnode.evaluate(frame);
|
|
30
30
|
if (!this._type.acceptValue(value)) {
|
|
31
31
|
this.throwError(`cannot cast value of type ${Type_js_1.Type.of(value)} to ${this._type}`);
|
|
32
32
|
}
|