@mirascript/mirascript 0.1.62-alpha.8 → 0.1.63
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 +46 -0
- package/dist/{chunk-6CAGNGY6.js → chunk-5BBTXV5A.js} +270 -269
- package/dist/chunk-5BBTXV5A.js.map +6 -0
- package/dist/{chunk-VRGQ23AK.js → chunk-HZYARHEQ.js} +30 -38
- package/dist/chunk-HZYARHEQ.js.map +6 -0
- package/dist/compiler/emit/consts.d.ts.map +1 -1
- package/dist/compiler/emit-script.d.ts +7 -2
- package/dist/compiler/emit-script.d.ts.map +1 -1
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/index.d.ts.map +1 -1
- package/dist/compiler/worker.js +1 -1
- package/dist/helpers/constants.d.ts +1 -10
- package/dist/helpers/constants.d.ts.map +1 -1
- package/dist/helpers/serialize.d.ts.map +1 -1
- package/dist/helpers/types.d.ts +5 -1
- package/dist/helpers/types.d.ts.map +1 -1
- package/dist/helpers/utils.d.ts +7 -1
- package/dist/helpers/utils.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/subtle.js +3 -3
- package/dist/subtle.js.map +1 -1
- package/dist/vm/checkpoint.d.ts +3 -3
- package/dist/vm/checkpoint.d.ts.map +1 -1
- package/dist/vm/lib/global/debug.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/entries.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/with.d.ts.map +1 -1
- package/dist/vm/operations/array-range.d.ts +6 -0
- package/dist/vm/operations/array-range.d.ts.map +1 -0
- package/dist/vm/operations/call.d.ts.map +1 -1
- package/dist/vm/operations/common.d.ts +1 -1
- package/dist/vm/operations/common.d.ts.map +1 -1
- package/dist/vm/operations/compound.d.ts +10 -10
- package/dist/vm/operations/compound.d.ts.map +1 -1
- package/dist/vm/operations/convert.d.ts +4 -4
- package/dist/vm/operations/convert.d.ts.map +1 -1
- package/dist/vm/operations/helpers.d.ts +7 -13
- package/dist/vm/operations/helpers.d.ts.map +1 -1
- package/dist/vm/operations/index.d.ts +1 -0
- package/dist/vm/operations/index.d.ts.map +1 -1
- package/dist/vm/operations/operator.d.ts +22 -22
- package/dist/vm/operations/operator.d.ts.map +1 -1
- package/dist/vm/operations/slice.d.ts +2 -2
- package/dist/vm/operations/slice.d.ts.map +1 -1
- package/dist/vm/operations/type-check.d.ts +7 -7
- package/dist/vm/operations/type-check.d.ts.map +1 -1
- package/dist/vm/operations/utils.d.ts +2 -2
- package/dist/vm/operations/utils.d.ts.map +1 -1
- package/dist/vm/types/boundary.d.ts +1 -1
- package/dist/vm/types/boundary.d.ts.map +1 -1
- package/dist/vm/types/context.d.ts.map +1 -1
- package/dist/vm/types/function.d.ts +0 -4
- package/dist/vm/types/function.d.ts.map +1 -1
- package/dist/vm/types/index.d.ts +1 -1
- package/dist/vm/types/index.d.ts.map +1 -1
- package/package.json +21 -8
- package/src/compiler/diagnostic.ts +2 -2
- package/src/compiler/emit/consts.ts +1 -0
- package/src/compiler/emit/index.ts +5 -5
- package/src/compiler/emit-script.ts +15 -6
- package/src/compiler/index.ts +3 -2
- package/src/helpers/analyze.ts +1 -1
- package/src/helpers/constants.ts +1 -11
- package/src/helpers/serialize.ts +1 -1
- package/src/helpers/types.ts +16 -0
- package/src/helpers/utils.ts +2 -1
- package/src/vm/checkpoint.ts +6 -6
- package/src/vm/lib/global/debug.ts +0 -1
- package/src/vm/lib/global/sequence/entries.ts +2 -0
- package/src/vm/lib/global/sequence/map-filter.ts +4 -4
- package/src/vm/lib/global/sequence/with.ts +3 -2
- package/src/vm/lib/loader.ts +2 -2
- package/src/vm/operations/array-range.ts +37 -0
- package/src/vm/operations/call.ts +8 -7
- package/src/vm/operations/common.ts +2 -2
- package/src/vm/operations/compound.ts +24 -25
- package/src/vm/operations/convert.ts +8 -8
- package/src/vm/operations/helpers.ts +17 -51
- package/src/vm/operations/index.ts +1 -0
- package/src/vm/operations/operator.ts +64 -54
- package/src/vm/operations/slice.ts +5 -4
- package/src/vm/operations/type-check.ts +16 -19
- package/src/vm/operations/utils.ts +4 -4
- package/src/vm/types/boundary.ts +2 -2
- package/src/vm/types/context.ts +1 -2
- package/src/vm/types/function.ts +2 -21
- package/src/vm/types/index.ts +1 -0
- package/bench/index.ts +0 -45
- package/dist/chunk-6CAGNGY6.js.map +0 -6
- package/dist/chunk-VRGQ23AK.js.map +0 -6
|
@@ -15,9 +15,11 @@ import {
|
|
|
15
15
|
emit,
|
|
16
16
|
entries,
|
|
17
17
|
formatDiagnostics,
|
|
18
|
+
freeze,
|
|
18
19
|
fromEntries,
|
|
19
20
|
getOwnPropertyNames,
|
|
20
21
|
getPrototypeOf,
|
|
22
|
+
getVmType,
|
|
21
23
|
hasOwn,
|
|
22
24
|
hasOwnEnumerable,
|
|
23
25
|
innerToString,
|
|
@@ -46,7 +48,7 @@ import {
|
|
|
46
48
|
parseDiagnostics,
|
|
47
49
|
toString,
|
|
48
50
|
values
|
|
49
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-HZYARHEQ.js";
|
|
50
52
|
|
|
51
53
|
// src/compiler/load-module.ts
|
|
52
54
|
import { loadModule } from "@mirascript/bindings";
|
|
@@ -181,21 +183,22 @@ var VmWrapper = class {
|
|
|
181
183
|
Object.defineProperty(VmWrapper.prototype, kVmWrapper, { value: true });
|
|
182
184
|
|
|
183
185
|
// src/vm/operations/common.ts
|
|
184
|
-
|
|
186
|
+
var $AssertInit = (value) => {
|
|
185
187
|
if (value === void 0) throw new VmError(`Uninitialized value`, null);
|
|
186
|
-
}
|
|
188
|
+
};
|
|
187
189
|
|
|
188
190
|
// src/vm/operations/call.ts
|
|
189
191
|
function $Call(func, args) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
+
const argsLen = args.length;
|
|
193
|
+
for (let i = 0; i < argsLen; i++) {
|
|
194
|
+
$AssertInit(args[i]);
|
|
195
|
+
}
|
|
196
|
+
if (typeof func == "function") {
|
|
197
|
+
return func(...args) ?? null;
|
|
192
198
|
}
|
|
193
199
|
if (isVmExtern(func)) {
|
|
194
200
|
return func.call(args) ?? null;
|
|
195
201
|
}
|
|
196
|
-
if (isVmFunction(func)) {
|
|
197
|
-
return func(...args) ?? null;
|
|
198
|
-
}
|
|
199
202
|
throw new VmError(`Value is not callable: ${display(func)}`, null);
|
|
200
203
|
}
|
|
201
204
|
function $VArgs(varags) {
|
|
@@ -460,68 +463,6 @@ var VmExtern = class extends VmWrapper {
|
|
|
460
463
|
};
|
|
461
464
|
Object.defineProperty(VmExtern.prototype, kVmExtern, { value: true });
|
|
462
465
|
|
|
463
|
-
// src/vm/checkpoint.ts
|
|
464
|
-
var { now } = Date;
|
|
465
|
-
var TIME_ORIGIN = now() - 1e3 * 3600 * 12;
|
|
466
|
-
var timestamp = () => now() - TIME_ORIGIN | 0;
|
|
467
|
-
var CP_DEFAULT_INTERVAL = 100;
|
|
468
|
-
var MAX_DEPTH = 128;
|
|
469
|
-
var CP_UNSET = -1;
|
|
470
|
-
var CP_DEFAULT_TIMEOUT = 100;
|
|
471
|
-
var cpTimeout = CP_DEFAULT_TIMEOUT | 0;
|
|
472
|
-
var cpInterval = CP_DEFAULT_INTERVAL | 0;
|
|
473
|
-
var cpDepth = 0;
|
|
474
|
-
var cp = CP_UNSET | 0;
|
|
475
|
-
var cpCounter = 0;
|
|
476
|
-
function Cp() {
|
|
477
|
-
if ((cpCounter = cpCounter + 1 | 0) % (cpInterval | 0) !== 0) {
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
cpCounter = 0;
|
|
481
|
-
if ((cp | 0) === (CP_UNSET | 0)) {
|
|
482
|
-
cp = timestamp() | 0;
|
|
483
|
-
} else if ((timestamp() | 0) - (cp | 0) >= (cpTimeout | 0)) {
|
|
484
|
-
throw new RangeError("Execution timed out");
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
function CpEnter() {
|
|
488
|
-
cpDepth = (cpDepth | 0) + 1;
|
|
489
|
-
if ((cpDepth | 0) <= 1) {
|
|
490
|
-
cp = CP_UNSET | 0;
|
|
491
|
-
cpCounter = 0;
|
|
492
|
-
cpDepth = 1;
|
|
493
|
-
} else if ((cpDepth | 0) > MAX_DEPTH) {
|
|
494
|
-
throw new RangeError("Maximum call depth exceeded");
|
|
495
|
-
} else {
|
|
496
|
-
Cp();
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
function CpExit() {
|
|
500
|
-
cpDepth = (cpDepth | 0) - 1;
|
|
501
|
-
if ((cpDepth | 0) < 1) {
|
|
502
|
-
cp = CP_UNSET | 0;
|
|
503
|
-
cpCounter = 0;
|
|
504
|
-
cpDepth = 0;
|
|
505
|
-
} else {
|
|
506
|
-
Cp();
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
var INT_MAX = 2147483647;
|
|
510
|
-
function configCheckpoint(timeout = CP_DEFAULT_TIMEOUT, checkInterval = CP_DEFAULT_INTERVAL) {
|
|
511
|
-
if (typeof timeout !== "number" || timeout <= 0 || isNaN(timeout)) {
|
|
512
|
-
throw new RangeError("Invalid timeout value");
|
|
513
|
-
} else if (timeout > INT_MAX) {
|
|
514
|
-
timeout = INT_MAX;
|
|
515
|
-
}
|
|
516
|
-
if (typeof checkInterval !== "number" || checkInterval <= 0 || isNaN(checkInterval)) {
|
|
517
|
-
throw new RangeError("Invalid check interval value");
|
|
518
|
-
} else if (checkInterval > INT_MAX) {
|
|
519
|
-
checkInterval = INT_MAX;
|
|
520
|
-
}
|
|
521
|
-
cpTimeout = timeout | 0;
|
|
522
|
-
cpInterval = checkInterval | 0;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
466
|
// src/vm/types/function.ts
|
|
526
467
|
var nameIfNotAnonymous = ({ name }, fallback) => {
|
|
527
468
|
if (!name) return fallback;
|
|
@@ -541,7 +482,6 @@ function VmFunction(fn, option = {}) {
|
|
|
541
482
|
opt = {
|
|
542
483
|
...option,
|
|
543
484
|
isLib: true,
|
|
544
|
-
injectCp: false,
|
|
545
485
|
name: nameIfNotAnonymous(option, null)
|
|
546
486
|
};
|
|
547
487
|
} else {
|
|
@@ -560,26 +500,12 @@ function VmFunction(fn, option = {}) {
|
|
|
560
500
|
deprecated: opt.deprecated ?? void 0
|
|
561
501
|
};
|
|
562
502
|
const name = opt.name ?? fn.name;
|
|
563
|
-
if (opt.injectCp) {
|
|
564
|
-
const original = fn;
|
|
565
|
-
info.original = original;
|
|
566
|
-
fn = ((...args) => {
|
|
567
|
-
try {
|
|
568
|
-
CpEnter();
|
|
569
|
-
const ret = original(...args);
|
|
570
|
-
return ret;
|
|
571
|
-
} finally {
|
|
572
|
-
CpExit();
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
503
|
defineProperty(fn, "name", { value: name, configurable: true });
|
|
577
|
-
defineProperty(fn, kVmFunction, { value:
|
|
504
|
+
defineProperty(fn, kVmFunction, { value: freeze(info) });
|
|
578
505
|
return fn;
|
|
579
506
|
}
|
|
580
507
|
|
|
581
508
|
// src/vm/types/context.ts
|
|
582
|
-
var { freeze } = Object;
|
|
583
509
|
var VM_SHARED_CONTEXT = create(null);
|
|
584
510
|
var VM_SHARED_CONTEXT_DESCRIPTIONS = create(null);
|
|
585
511
|
var VM_SHARED_CONTEXT_KEYS = null;
|
|
@@ -780,6 +706,68 @@ var VmModule = class extends VmWrapper {
|
|
|
780
706
|
};
|
|
781
707
|
Object.defineProperty(VmModule.prototype, kVmModule, { value: true });
|
|
782
708
|
|
|
709
|
+
// src/vm/checkpoint.ts
|
|
710
|
+
var { now } = Date;
|
|
711
|
+
var TIME_ORIGIN = now() - 1e3 * 3600 * 12;
|
|
712
|
+
var timestamp = () => now() - TIME_ORIGIN | 0;
|
|
713
|
+
var CP_DEFAULT_INTERVAL = 100;
|
|
714
|
+
var MAX_DEPTH = 128;
|
|
715
|
+
var CP_UNSET = -1;
|
|
716
|
+
var CP_DEFAULT_TIMEOUT = 100;
|
|
717
|
+
var cpTimeout = CP_DEFAULT_TIMEOUT | 0;
|
|
718
|
+
var cpInterval = CP_DEFAULT_INTERVAL | 0;
|
|
719
|
+
var cpDepth = 0;
|
|
720
|
+
var cp = CP_UNSET | 0;
|
|
721
|
+
var cpCounter = 0;
|
|
722
|
+
var Cp = () => {
|
|
723
|
+
if ((cpCounter = cpCounter + 1 | 0) % (cpInterval | 0) !== 0) {
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
cpCounter = 0;
|
|
727
|
+
if ((cp | 0) === (CP_UNSET | 0)) {
|
|
728
|
+
cp = timestamp() | 0;
|
|
729
|
+
} else if ((timestamp() | 0) - (cp | 0) >= (cpTimeout | 0)) {
|
|
730
|
+
throw new RangeError("Execution timed out");
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
var CpEnter = () => {
|
|
734
|
+
cpDepth = (cpDepth | 0) + 1;
|
|
735
|
+
if ((cpDepth | 0) <= 1) {
|
|
736
|
+
cp = CP_UNSET | 0;
|
|
737
|
+
cpCounter = 0;
|
|
738
|
+
cpDepth = 1;
|
|
739
|
+
} else if ((cpDepth | 0) > MAX_DEPTH) {
|
|
740
|
+
throw new RangeError("Maximum call depth exceeded");
|
|
741
|
+
} else {
|
|
742
|
+
Cp();
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
var CpExit = () => {
|
|
746
|
+
cpDepth = (cpDepth | 0) - 1;
|
|
747
|
+
if ((cpDepth | 0) < 1) {
|
|
748
|
+
cp = CP_UNSET | 0;
|
|
749
|
+
cpCounter = 0;
|
|
750
|
+
cpDepth = 0;
|
|
751
|
+
} else {
|
|
752
|
+
Cp();
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
var INT_MAX = 2147483647;
|
|
756
|
+
function configCheckpoint(timeout = CP_DEFAULT_TIMEOUT, checkInterval = CP_DEFAULT_INTERVAL) {
|
|
757
|
+
if (typeof timeout !== "number" || timeout <= 0 || isNaN(timeout)) {
|
|
758
|
+
throw new RangeError("Invalid timeout value");
|
|
759
|
+
} else if (timeout > INT_MAX) {
|
|
760
|
+
timeout = INT_MAX;
|
|
761
|
+
}
|
|
762
|
+
if (typeof checkInterval !== "number" || checkInterval <= 0 || isNaN(checkInterval)) {
|
|
763
|
+
throw new RangeError("Invalid check interval value");
|
|
764
|
+
} else if (checkInterval > INT_MAX) {
|
|
765
|
+
checkInterval = INT_MAX;
|
|
766
|
+
}
|
|
767
|
+
cpTimeout = timeout | 0;
|
|
768
|
+
cpInterval = checkInterval | 0;
|
|
769
|
+
}
|
|
770
|
+
|
|
783
771
|
// src/vm/operations/index.ts
|
|
784
772
|
var operations_exports = {};
|
|
785
773
|
__export(operations_exports, {
|
|
@@ -845,67 +833,64 @@ __export(operations_exports, {
|
|
|
845
833
|
});
|
|
846
834
|
|
|
847
835
|
// src/vm/operations/convert.ts
|
|
848
|
-
|
|
836
|
+
var $ToBoolean = (value) => {
|
|
849
837
|
if (typeof value == "boolean") return value;
|
|
850
838
|
$AssertInit(value);
|
|
851
839
|
return toBoolean(value, void 0);
|
|
852
|
-
}
|
|
853
|
-
|
|
840
|
+
};
|
|
841
|
+
var $ToString = (value) => {
|
|
854
842
|
if (typeof value == "string") return value;
|
|
855
843
|
$AssertInit(value);
|
|
856
844
|
return toString(value, void 0);
|
|
857
|
-
}
|
|
858
|
-
|
|
845
|
+
};
|
|
846
|
+
var $ToNumber = (value) => {
|
|
859
847
|
if (typeof value == "number") return value;
|
|
860
848
|
$AssertInit(value);
|
|
861
849
|
return toNumber(value, void 0);
|
|
862
|
-
}
|
|
863
|
-
|
|
850
|
+
};
|
|
851
|
+
var $Format = (value, format2) => {
|
|
864
852
|
$AssertInit(value);
|
|
865
853
|
return toFormat(value, format2);
|
|
866
|
-
}
|
|
854
|
+
};
|
|
867
855
|
|
|
868
856
|
// src/vm/operations/type-check.ts
|
|
869
|
-
|
|
857
|
+
var $Type = (value) => {
|
|
870
858
|
if (value == null) return "nil";
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
return typeof value;
|
|
875
|
-
}
|
|
876
|
-
function $IsBoolean(value) {
|
|
859
|
+
return getVmType(value);
|
|
860
|
+
};
|
|
861
|
+
var $IsBoolean = (value) => {
|
|
877
862
|
$AssertInit(value);
|
|
878
863
|
return typeof value == "boolean";
|
|
879
|
-
}
|
|
880
|
-
|
|
864
|
+
};
|
|
865
|
+
var $IsNumber = (value) => {
|
|
881
866
|
$AssertInit(value);
|
|
882
867
|
return typeof value == "number";
|
|
883
|
-
}
|
|
884
|
-
|
|
868
|
+
};
|
|
869
|
+
var $IsString = (value) => {
|
|
885
870
|
$AssertInit(value);
|
|
886
871
|
return typeof value == "string";
|
|
887
|
-
}
|
|
888
|
-
|
|
872
|
+
};
|
|
873
|
+
var $IsRecord = (value) => {
|
|
889
874
|
$AssertInit(value);
|
|
890
875
|
return isVmRecord(value);
|
|
891
|
-
}
|
|
892
|
-
|
|
876
|
+
};
|
|
877
|
+
var $IsArray = (value) => {
|
|
893
878
|
$AssertInit(value);
|
|
894
879
|
return isVmArray(value);
|
|
895
|
-
}
|
|
896
|
-
|
|
880
|
+
};
|
|
881
|
+
var $AssertNonNil = (value) => {
|
|
897
882
|
$AssertInit(value);
|
|
898
883
|
if (value !== null) return;
|
|
899
884
|
throw new VmError(`Expected non-nil value`, null);
|
|
900
|
-
}
|
|
885
|
+
};
|
|
901
886
|
|
|
902
887
|
// src/vm/operations/utils.ts
|
|
903
|
-
|
|
888
|
+
var overloadNumberString = (a, b) => {
|
|
904
889
|
if (typeof a == "number" || typeof b == "number") return true;
|
|
905
890
|
if (typeof a == "string" || typeof b == "string") return false;
|
|
906
891
|
return true;
|
|
907
|
-
}
|
|
908
|
-
|
|
892
|
+
};
|
|
893
|
+
var isSame = (a, b) => {
|
|
909
894
|
if (typeof a == "number" && typeof b == "number") {
|
|
910
895
|
return a === b || isNaN(a) && isNaN(b);
|
|
911
896
|
}
|
|
@@ -942,84 +927,94 @@ function isSame(a, b) {
|
|
|
942
927
|
return true;
|
|
943
928
|
}
|
|
944
929
|
return false;
|
|
945
|
-
}
|
|
930
|
+
};
|
|
946
931
|
|
|
947
932
|
// src/vm/operations/operator.ts
|
|
948
933
|
function $Concat(...args) {
|
|
949
934
|
return args.map((a) => toFormat(a, null)).join("");
|
|
950
935
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
return
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
return
|
|
983
|
-
}
|
|
984
|
-
|
|
936
|
+
var $Pos = $ToNumber;
|
|
937
|
+
var $Neg = (a) => -$ToNumber(a);
|
|
938
|
+
var $Not = (a) => !$ToBoolean(a);
|
|
939
|
+
var add = (a, b) => $ToNumber(a) + $ToNumber(b);
|
|
940
|
+
var $Add = (a, b) => {
|
|
941
|
+
if (typeof a == "number" && typeof b == "number") return a + b;
|
|
942
|
+
return add(a, b);
|
|
943
|
+
};
|
|
944
|
+
var sub = (a, b) => $ToNumber(a) - $ToNumber(b);
|
|
945
|
+
var $Sub = (a, b) => {
|
|
946
|
+
if (typeof a == "number" && typeof b == "number") return a - b;
|
|
947
|
+
return sub(a, b);
|
|
948
|
+
};
|
|
949
|
+
var mul = (a, b) => $ToNumber(a) * $ToNumber(b);
|
|
950
|
+
var $Mul = (a, b) => {
|
|
951
|
+
if (typeof a == "number" && typeof b == "number") return a * b;
|
|
952
|
+
return mul(a, b);
|
|
953
|
+
};
|
|
954
|
+
var div = (a, b) => $ToNumber(a) / $ToNumber(b);
|
|
955
|
+
var $Div = (a, b) => {
|
|
956
|
+
if (typeof a == "number" && typeof b == "number") return a / b;
|
|
957
|
+
return div(a, b);
|
|
958
|
+
};
|
|
959
|
+
var mod = (a, b) => $ToNumber(a) % $ToNumber(b);
|
|
960
|
+
var $Mod = (a, b) => {
|
|
961
|
+
if (typeof a == "number" && typeof b == "number") return a % b;
|
|
962
|
+
return mod(a, b);
|
|
963
|
+
};
|
|
964
|
+
var pow = (a, b) => $ToNumber(a) ** $ToNumber(b);
|
|
965
|
+
var $Pow = (a, b) => {
|
|
966
|
+
if (typeof a == "number" && typeof b == "number") return a ** b;
|
|
967
|
+
return pow(a, b);
|
|
968
|
+
};
|
|
969
|
+
var and = (a, b) => $ToBoolean(a) && $ToBoolean(b);
|
|
970
|
+
var $And = (a, b) => {
|
|
971
|
+
if (typeof a == "boolean" && typeof b == "boolean") return a && b;
|
|
972
|
+
return and(a, b);
|
|
973
|
+
};
|
|
974
|
+
var or = (a, b) => $ToBoolean(a) || $ToBoolean(b);
|
|
975
|
+
var $Or = (a, b) => {
|
|
976
|
+
if (typeof a == "boolean" && typeof b == "boolean") return a || b;
|
|
977
|
+
return or(a, b);
|
|
978
|
+
};
|
|
979
|
+
var $Gt = (a, b) => {
|
|
985
980
|
if (overloadNumberString(a, b)) {
|
|
986
981
|
return $ToNumber(a) > $ToNumber(b);
|
|
987
982
|
} else {
|
|
988
983
|
return $ToString(a) > $ToString(b);
|
|
989
984
|
}
|
|
990
|
-
}
|
|
991
|
-
|
|
985
|
+
};
|
|
986
|
+
var $Gte = (a, b) => {
|
|
992
987
|
if (overloadNumberString(a, b)) {
|
|
993
988
|
return $ToNumber(a) >= $ToNumber(b);
|
|
994
989
|
} else {
|
|
995
990
|
return $ToString(a) >= $ToString(b);
|
|
996
991
|
}
|
|
997
|
-
}
|
|
998
|
-
|
|
992
|
+
};
|
|
993
|
+
var $Lt = (a, b) => {
|
|
999
994
|
if (overloadNumberString(a, b)) {
|
|
1000
995
|
return $ToNumber(a) < $ToNumber(b);
|
|
1001
996
|
} else {
|
|
1002
997
|
return $ToString(a) < $ToString(b);
|
|
1003
998
|
}
|
|
1004
|
-
}
|
|
1005
|
-
|
|
999
|
+
};
|
|
1000
|
+
var $Lte = (a, b) => {
|
|
1006
1001
|
if (overloadNumberString(a, b)) {
|
|
1007
1002
|
return $ToNumber(a) <= $ToNumber(b);
|
|
1008
1003
|
} else {
|
|
1009
1004
|
return $ToString(a) <= $ToString(b);
|
|
1010
1005
|
}
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1006
|
+
};
|
|
1007
|
+
var $Eq = (a, b) => {
|
|
1013
1008
|
$AssertInit(a);
|
|
1014
1009
|
$AssertInit(b);
|
|
1015
1010
|
if (typeof a == "number" && typeof b == "number") return a === b;
|
|
1016
1011
|
return isSame(a, b);
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1012
|
+
};
|
|
1013
|
+
var $Neq = (a, b) => {
|
|
1019
1014
|
return !$Eq(a, b);
|
|
1020
|
-
}
|
|
1015
|
+
};
|
|
1021
1016
|
var { abs, min } = Math;
|
|
1022
|
-
|
|
1017
|
+
var $Aeq = (a, b) => {
|
|
1023
1018
|
if (overloadNumberString(a, b)) {
|
|
1024
1019
|
const an = $ToNumber(a);
|
|
1025
1020
|
const bn = $ToNumber(b);
|
|
@@ -1041,18 +1036,18 @@ function $Aeq(a, b) {
|
|
|
1041
1036
|
const bn = bi.normalize("NFC");
|
|
1042
1037
|
return an === bn;
|
|
1043
1038
|
}
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1039
|
+
};
|
|
1040
|
+
var $Naeq = (a, b) => {
|
|
1046
1041
|
return !$Aeq(a, b);
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1042
|
+
};
|
|
1043
|
+
var $Same = (a, b) => {
|
|
1049
1044
|
$AssertInit(a);
|
|
1050
1045
|
$AssertInit(b);
|
|
1051
1046
|
return isSame(a, b);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1047
|
+
};
|
|
1048
|
+
var $Nsame = (a, b) => {
|
|
1054
1049
|
return !$Same(a, b);
|
|
1055
|
-
}
|
|
1050
|
+
};
|
|
1056
1051
|
|
|
1057
1052
|
// src/vm/operations/slice.ts
|
|
1058
1053
|
var { ceil } = Math;
|
|
@@ -1071,85 +1066,55 @@ var sliceCore = (value, start, end, exclusive) => {
|
|
|
1071
1066
|
}
|
|
1072
1067
|
return slice.call(value, start, end);
|
|
1073
1068
|
};
|
|
1074
|
-
|
|
1069
|
+
var $Slice = (value, start, end) => {
|
|
1075
1070
|
$AssertInit(value);
|
|
1076
1071
|
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
1077
1072
|
const s2 = start != null ? $ToNumber(start) : 0;
|
|
1078
1073
|
const e2 = end != null ? $ToNumber(end) : value.length - 1;
|
|
1079
1074
|
return sliceCore(value, s2, e2, false);
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1075
|
+
};
|
|
1076
|
+
var $SliceExclusive = (value, start, end) => {
|
|
1082
1077
|
$AssertInit(value);
|
|
1083
1078
|
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
1084
1079
|
const s2 = start != null ? $ToNumber(start) : 0;
|
|
1085
1080
|
const e2 = end != null ? $ToNumber(end) : value.length;
|
|
1086
1081
|
return sliceCore(value, s2, e2, true);
|
|
1087
|
-
}
|
|
1082
|
+
};
|
|
1088
1083
|
|
|
1089
1084
|
// src/vm/operations/helpers.ts
|
|
1090
|
-
|
|
1091
|
-
const
|
|
1085
|
+
var $Module = (name, body) => {
|
|
1086
|
+
const mod2 = create(null);
|
|
1092
1087
|
for (const [key, get] of entries(body)) {
|
|
1093
|
-
defineProperty(
|
|
1088
|
+
defineProperty(mod2, key, { __proto__: null, get, enumerable: true, configurable: true });
|
|
1094
1089
|
}
|
|
1095
|
-
return new VmModule(name,
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1090
|
+
return new VmModule(name, mod2);
|
|
1091
|
+
};
|
|
1092
|
+
var $El = (value) => {
|
|
1098
1093
|
$AssertInit(value);
|
|
1099
1094
|
if (!isVmConst(value)) return null;
|
|
1100
1095
|
return value;
|
|
1101
|
-
}
|
|
1096
|
+
};
|
|
1102
1097
|
var EMPTY = create(null);
|
|
1103
|
-
|
|
1098
|
+
var $ElOpt = (key, value) => {
|
|
1104
1099
|
$AssertInit(value);
|
|
1105
1100
|
if (value == null || !isVmConst(value)) return EMPTY;
|
|
1106
1101
|
return { __proto__: null, [key]: value };
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
return VmFunction(fn, { isLib: false,
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1102
|
+
};
|
|
1103
|
+
var $Fn = (name, fn) => {
|
|
1104
|
+
return VmFunction(fn, { isLib: false, name: name || VM_FUNCTION_ANONYMOUS_NAME });
|
|
1105
|
+
};
|
|
1106
|
+
var $Upvalue = (value) => {
|
|
1112
1107
|
$AssertInit(value);
|
|
1113
1108
|
return value;
|
|
1114
|
-
}
|
|
1115
|
-
var assertArrayLength = (len2) => {
|
|
1116
|
-
if (len2 > VM_ARRAY_MAX_LENGTH) {
|
|
1117
|
-
throw new RangeError(`Array length exceeds maximum limit of ${VM_ARRAY_MAX_LENGTH}`);
|
|
1118
|
-
}
|
|
1119
1109
|
};
|
|
1120
|
-
var
|
|
1121
|
-
return !isFinite(start) || !isFinite(end) || start > end;
|
|
1122
|
-
};
|
|
1123
|
-
function $ArrayRange(start, end) {
|
|
1124
|
-
const s2 = $ToNumber(start);
|
|
1125
|
-
const e2 = $ToNumber(end);
|
|
1126
|
-
if (isEmptyRange(s2, e2)) return [];
|
|
1127
|
-
assertArrayLength(e2 - s2 + 1);
|
|
1128
|
-
const arr = [];
|
|
1129
|
-
for (let i = s2; i <= e2; i++) {
|
|
1130
|
-
arr.push(i);
|
|
1131
|
-
}
|
|
1132
|
-
return arr;
|
|
1133
|
-
}
|
|
1134
|
-
function $ArrayRangeExclusive(start, end) {
|
|
1135
|
-
const s2 = $ToNumber(start);
|
|
1136
|
-
const e2 = $ToNumber(end);
|
|
1137
|
-
if (isEmptyRange(s2, e2)) return [];
|
|
1138
|
-
assertArrayLength(e2 - s2);
|
|
1139
|
-
const arr = [];
|
|
1140
|
-
for (let i = s2; i < e2; i++) {
|
|
1141
|
-
arr.push(i);
|
|
1142
|
-
}
|
|
1143
|
-
return arr;
|
|
1144
|
-
}
|
|
1145
|
-
function $GlobalFallback() {
|
|
1110
|
+
var $GlobalFallback = () => {
|
|
1146
1111
|
return DefaultVmContext;
|
|
1147
|
-
}
|
|
1112
|
+
};
|
|
1148
1113
|
|
|
1149
1114
|
// src/vm/operations/compound.ts
|
|
1150
1115
|
var { trunc } = Math;
|
|
1151
1116
|
var { at } = Array.prototype;
|
|
1152
|
-
|
|
1117
|
+
var $In = (value, iterable) => {
|
|
1153
1118
|
$AssertInit(value);
|
|
1154
1119
|
$AssertInit(iterable);
|
|
1155
1120
|
if (iterable == null) return false;
|
|
@@ -1165,17 +1130,17 @@ function $In(value, iterable) {
|
|
|
1165
1130
|
const key = toString(value, void 0);
|
|
1166
1131
|
if (isVmWrapper(iterable)) return iterable.has(key);
|
|
1167
1132
|
return hasOwnEnumerable(iterable, key);
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1133
|
+
};
|
|
1134
|
+
var $Length = (value) => {
|
|
1170
1135
|
$AssertInit(value);
|
|
1171
1136
|
if (isVmArray(value)) return value.length;
|
|
1172
1137
|
if (isVmRecord(value)) return keys(value).length;
|
|
1173
1138
|
if (isVmWrapper(value)) return value.keys().length;
|
|
1174
1139
|
throw new VmError(`Value has no length: ${display(value)}`, 0);
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1140
|
+
};
|
|
1141
|
+
var $Omit = (value, omitted) => {
|
|
1177
1142
|
$AssertInit(value);
|
|
1178
|
-
if (
|
|
1143
|
+
if (!isVmRecord(value)) return {};
|
|
1179
1144
|
const result = {};
|
|
1180
1145
|
const valueKeys = keys(value);
|
|
1181
1146
|
const omittedSet = new Set(omitted.map($ToString));
|
|
@@ -1185,10 +1150,10 @@ function $Omit(value, omitted) {
|
|
|
1185
1150
|
}
|
|
1186
1151
|
}
|
|
1187
1152
|
return result;
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1153
|
+
};
|
|
1154
|
+
var $Pick = (value, picked) => {
|
|
1190
1155
|
$AssertInit(value);
|
|
1191
|
-
if (
|
|
1156
|
+
if (!isVmRecord(value)) return {};
|
|
1192
1157
|
const result = {};
|
|
1193
1158
|
for (const key of picked) {
|
|
1194
1159
|
const k = $ToString(key);
|
|
@@ -1197,20 +1162,20 @@ function $Pick(value, picked) {
|
|
|
1197
1162
|
}
|
|
1198
1163
|
}
|
|
1199
1164
|
return result;
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1165
|
+
};
|
|
1166
|
+
var $Has = (obj, key) => {
|
|
1202
1167
|
$AssertInit(obj);
|
|
1203
1168
|
const pk = $ToString(key);
|
|
1204
1169
|
if (obj == null || typeof obj != "object") return false;
|
|
1205
1170
|
if (isVmWrapper(obj)) return obj.has(pk);
|
|
1206
1171
|
return hasOwnEnumerable(obj, pk);
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1172
|
+
};
|
|
1173
|
+
var $Get = (obj, key) => {
|
|
1209
1174
|
$AssertInit(obj);
|
|
1210
1175
|
if (isVmArray(obj)) {
|
|
1211
1176
|
$AssertInit(key);
|
|
1212
1177
|
const index = toNumber(key, NotNumber);
|
|
1213
|
-
if (
|
|
1178
|
+
if (!isFinite(index)) return null;
|
|
1214
1179
|
return $El(at.call(obj, trunc(index)) ?? null);
|
|
1215
1180
|
}
|
|
1216
1181
|
const pk = $ToString(key);
|
|
@@ -1228,23 +1193,22 @@ function $Get(obj, key) {
|
|
|
1228
1193
|
}
|
|
1229
1194
|
if (!hasOwnEnumerable(obj, pk)) return null;
|
|
1230
1195
|
return $El(obj[pk] ?? null);
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1196
|
+
};
|
|
1197
|
+
var $Set = (obj, key, value) => {
|
|
1233
1198
|
$AssertInit(obj);
|
|
1234
1199
|
$AssertInit(value);
|
|
1235
1200
|
const pk = $ToString(key);
|
|
1236
|
-
if (obj == null) return;
|
|
1237
1201
|
if (!isVmExtern(obj)) throw new VmError(`Expected extern, got ${display(obj)}`, void 0);
|
|
1238
1202
|
obj.set(pk, value);
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1203
|
+
};
|
|
1204
|
+
var $Iterable = (value) => {
|
|
1241
1205
|
$AssertInit(value);
|
|
1242
1206
|
if (isVmWrapper(value)) return value.keys();
|
|
1243
1207
|
if (isVmArray(value)) return value;
|
|
1244
1208
|
if (value != null && typeof value == "object") return keys(value);
|
|
1245
1209
|
throw new VmError(`Value is not iterable: ${display(value)}`, isVmFunction(value) ? [] : [value]);
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1210
|
+
};
|
|
1211
|
+
var $RecordSpread = (record) => {
|
|
1248
1212
|
$AssertInit(record);
|
|
1249
1213
|
if (record == null || isVmRecord(record)) return record;
|
|
1250
1214
|
if (isVmArray(record)) {
|
|
@@ -1267,8 +1231,8 @@ function $RecordSpread(record) {
|
|
|
1267
1231
|
return result;
|
|
1268
1232
|
}
|
|
1269
1233
|
throw new VmError(`Expected record, array, extern or nil, got ${display(record)}`, null);
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1234
|
+
};
|
|
1235
|
+
var $ArraySpread = (array) => {
|
|
1272
1236
|
$AssertInit(array);
|
|
1273
1237
|
if (array == null) return [];
|
|
1274
1238
|
if (isVmArray(array)) return array;
|
|
@@ -1289,7 +1253,39 @@ function $ArraySpread(array) {
|
|
|
1289
1253
|
}
|
|
1290
1254
|
}
|
|
1291
1255
|
throw new VmError(`Expected array, iterable extern or nil, got ${display(array)}`, []);
|
|
1292
|
-
}
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
// src/vm/operations/array-range.ts
|
|
1259
|
+
var assertArrayLength = (len2) => {
|
|
1260
|
+
if (len2 > VM_ARRAY_MAX_LENGTH) {
|
|
1261
|
+
throw new RangeError(`Array length exceeds maximum limit of ${VM_ARRAY_MAX_LENGTH}`);
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
var isEmptyRange = (start, end) => {
|
|
1265
|
+
return !isFinite(start) || !isFinite(end) || start > end;
|
|
1266
|
+
};
|
|
1267
|
+
var $ArrayRange = (start, end) => {
|
|
1268
|
+
const s2 = $ToNumber(start);
|
|
1269
|
+
const e2 = $ToNumber(end);
|
|
1270
|
+
if (isEmptyRange(s2, e2)) return [];
|
|
1271
|
+
assertArrayLength(e2 - s2 + 1);
|
|
1272
|
+
const arr = [];
|
|
1273
|
+
for (let i = s2; i <= e2; i++) {
|
|
1274
|
+
arr.push(i);
|
|
1275
|
+
}
|
|
1276
|
+
return arr;
|
|
1277
|
+
};
|
|
1278
|
+
var $ArrayRangeExclusive = (start, end) => {
|
|
1279
|
+
const s2 = $ToNumber(start);
|
|
1280
|
+
const e2 = $ToNumber(end);
|
|
1281
|
+
if (isEmptyRange(s2, e2)) return [];
|
|
1282
|
+
assertArrayLength(e2 - s2);
|
|
1283
|
+
const arr = [];
|
|
1284
|
+
for (let i = s2; i < e2; i++) {
|
|
1285
|
+
arr.push(i);
|
|
1286
|
+
}
|
|
1287
|
+
return arr;
|
|
1288
|
+
};
|
|
1293
1289
|
|
|
1294
1290
|
// src/compiler/create-script.ts
|
|
1295
1291
|
function wrapScript(source, mode, script) {
|
|
@@ -1326,15 +1322,20 @@ return ${code}`)(...values2);
|
|
|
1326
1322
|
}
|
|
1327
1323
|
|
|
1328
1324
|
// src/compiler/emit-script.ts
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1325
|
+
var CompileError = class extends Error {
|
|
1326
|
+
constructor(source, diagnostics, fileName) {
|
|
1327
|
+
const parsed = parseDiagnostics(source, diagnostics);
|
|
1328
|
+
const messages = formatDiagnostics(parsed.errors, source, fileName);
|
|
1329
|
+
super(`Failed to compile:
|
|
1333
1330
|
${messages.join("\n")}`);
|
|
1334
|
-
|
|
1331
|
+
this.fileName = fileName;
|
|
1332
|
+
this.name = "CompileError";
|
|
1333
|
+
this.diagnostics = messages;
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1335
1336
|
function emitScript(source, [code, diagnostics], options) {
|
|
1336
1337
|
if (!code) {
|
|
1337
|
-
|
|
1338
|
+
throw new CompileError(source, diagnostics, options.fileName);
|
|
1338
1339
|
}
|
|
1339
1340
|
const sourcemaps = options.sourceMap ? parseDiagnostics(source, diagnostics, (c) => c === DiagnosticCode.SourceMap).sourcemaps : [];
|
|
1340
1341
|
const target = emit(source, code, sourcemaps, options);
|
|
@@ -1402,7 +1403,7 @@ __export(global_exports, {
|
|
|
1402
1403
|
new_record: () => new_record,
|
|
1403
1404
|
panic: () => panic,
|
|
1404
1405
|
pi: () => pi,
|
|
1405
|
-
pow: () =>
|
|
1406
|
+
pow: () => pow3,
|
|
1406
1407
|
product: () => product,
|
|
1407
1408
|
random: () => random,
|
|
1408
1409
|
repeat: () => repeat,
|
|
@@ -1908,7 +1909,7 @@ var round = VmLib(
|
|
|
1908
1909
|
);
|
|
1909
1910
|
|
|
1910
1911
|
// src/vm/lib/global/math/gamma.ts
|
|
1911
|
-
var { PI: PI2, exp: exp2, floor: floor2, cos: cos2, sin: sin2, pow, trunc: trunc3 } = Math;
|
|
1912
|
+
var { PI: PI2, exp: exp2, floor: floor2, cos: cos2, sin: sin2, pow: pow2, trunc: trunc3 } = Math;
|
|
1912
1913
|
var MEM = new DataView(new ArrayBuffer(8));
|
|
1913
1914
|
function f64ToBits(value) {
|
|
1914
1915
|
MEM.setFloat64(0, value, false);
|
|
@@ -2031,7 +2032,7 @@ function tgamma(x) {
|
|
|
2031
2032
|
z = -z;
|
|
2032
2033
|
}
|
|
2033
2034
|
r += dy * (GMHALF + 0.5) * r / y;
|
|
2034
|
-
const zHalf =
|
|
2035
|
+
const zHalf = pow2(y, 0.5 * z);
|
|
2035
2036
|
return r * zHalf * zHalf;
|
|
2036
2037
|
}
|
|
2037
2038
|
var gamma = VmLib(
|
|
@@ -2082,7 +2083,7 @@ var atan2 = VmLib((x, y) => _atan2(expectNumber(0, x), expectNumber(1, y)), {
|
|
|
2082
2083
|
paramsType: { x: "number", y: "number" },
|
|
2083
2084
|
returnsType: "number"
|
|
2084
2085
|
});
|
|
2085
|
-
var
|
|
2086
|
+
var pow3 = VmLib((x, y) => _pow(expectNumber(0, x), expectNumber(1, y)), {
|
|
2086
2087
|
summary: "返回 x 的 y 次幂",
|
|
2087
2088
|
params: { x: "底数", y: "指数" },
|
|
2088
2089
|
paramsType: { x: "number", y: "number" },
|
|
@@ -2213,7 +2214,7 @@ var withInner = (obj, key, keyIndex, value) => {
|
|
|
2213
2214
|
}
|
|
2214
2215
|
if (isArray(result)) {
|
|
2215
2216
|
const index = arrIndex(k);
|
|
2216
|
-
while (index
|
|
2217
|
+
while (index >= result.length) {
|
|
2217
2218
|
result.push(null);
|
|
2218
2219
|
}
|
|
2219
2220
|
result[index] = withInner(result[index], key, keyIndex + 1, value);
|
|
@@ -2237,7 +2238,8 @@ var normalizeEntries = (data, entries3) => {
|
|
|
2237
2238
|
if (isVmArray(key)) {
|
|
2238
2239
|
if (key.length === 0 || key.includes(null) || key.includes(void 0)) {
|
|
2239
2240
|
continue;
|
|
2240
|
-
}
|
|
2241
|
+
}
|
|
2242
|
+
if (key.length === 1) {
|
|
2241
2243
|
key = key[0];
|
|
2242
2244
|
}
|
|
2243
2245
|
}
|
|
@@ -2414,7 +2416,7 @@ var map2 = VmLib(
|
|
|
2414
2416
|
f: "fn(value: any, key: number | string, input: type(data)) -> any"
|
|
2415
2417
|
},
|
|
2416
2418
|
returnsType: "type(data)",
|
|
2417
|
-
examples: ["map([1, 2, 3], fn
|
|
2419
|
+
examples: ["map([1, 2, 3], fn { it * it }) // [1, 4, 9]"]
|
|
2418
2420
|
}
|
|
2419
2421
|
);
|
|
2420
2422
|
var filter = VmLib(
|
|
@@ -2433,7 +2435,7 @@ var filter = VmLib(
|
|
|
2433
2435
|
predicate: "fn(value: any, key: number | string, input: type(data)) -> boolean"
|
|
2434
2436
|
},
|
|
2435
2437
|
returnsType: "type(data)",
|
|
2436
|
-
examples: ["filter([1, 2, 3, 4], fn
|
|
2438
|
+
examples: ["filter([1, 2, 3, 4], fn { it % 2 == 0 }) // [2, 4]"]
|
|
2437
2439
|
}
|
|
2438
2440
|
);
|
|
2439
2441
|
var filter_map = VmLib(
|
|
@@ -2442,7 +2444,7 @@ var filter_map = VmLib(
|
|
|
2442
2444
|
return ret ?? void 0;
|
|
2443
2445
|
}),
|
|
2444
2446
|
{
|
|
2445
|
-
summary: "对数组或记录中的每个元素应用函数,并返回非 nil 的结果",
|
|
2447
|
+
summary: "对数组或记录中的每个元素应用函数,并返回非 `nil` 的结果",
|
|
2446
2448
|
params: {
|
|
2447
2449
|
data: "要映射的数组或记录",
|
|
2448
2450
|
f: "应用于每个元素的函数"
|
|
@@ -2452,7 +2454,7 @@ var filter_map = VmLib(
|
|
|
2452
2454
|
f: "fn(value: any, key: number | string, input: type(data)) -> any | nil"
|
|
2453
2455
|
},
|
|
2454
2456
|
returnsType: "type(data)",
|
|
2455
|
-
examples: ["filter_map([1, 2, 3], fn
|
|
2457
|
+
examples: ["filter_map([1, 2, 3], fn {\n if it % 2 == 0 { it * it } else { nil } \n}) // [4]"]
|
|
2456
2458
|
}
|
|
2457
2459
|
);
|
|
2458
2460
|
|
|
@@ -2949,7 +2951,6 @@ var printParser = function(args) {
|
|
|
2949
2951
|
formats.push("");
|
|
2950
2952
|
templates.push(i < values4.length - 1 ? " " : "");
|
|
2951
2953
|
}
|
|
2952
|
-
valIndex++;
|
|
2953
2954
|
}
|
|
2954
2955
|
return {
|
|
2955
2956
|
templates,
|
|
@@ -3411,7 +3412,7 @@ __export(mod_exports, {
|
|
|
3411
3412
|
// src/vm/lib/mod/matrix.ts
|
|
3412
3413
|
var matrix_exports = {};
|
|
3413
3414
|
__export(matrix_exports, {
|
|
3414
|
-
add: () =>
|
|
3415
|
+
add: () => add2,
|
|
3415
3416
|
diagonal: () => diagonal,
|
|
3416
3417
|
entrywise: () => entrywise,
|
|
3417
3418
|
entrywise_divide: () => entrywise_divide,
|
|
@@ -3596,7 +3597,7 @@ var entrywise = VmLib(
|
|
|
3596
3597
|
examples: [`matrix.entrywise([1, 2], [3, 4], fn (x, y) { x + y }) // [4, 6]`]
|
|
3597
3598
|
}
|
|
3598
3599
|
);
|
|
3599
|
-
var
|
|
3600
|
+
var add2 = VmLib(
|
|
3600
3601
|
(a, b) => {
|
|
3601
3602
|
expectConst("a", a, null);
|
|
3602
3603
|
expectConst("b", b, null);
|
|
@@ -3934,14 +3935,14 @@ function wrapEntry(name, value, module) {
|
|
|
3934
3935
|
return [VmFunction(value, value), value.summary || void 0];
|
|
3935
3936
|
}
|
|
3936
3937
|
function createModule(name, lib2) {
|
|
3937
|
-
const
|
|
3938
|
+
const mod2 = create(null);
|
|
3938
3939
|
const descriptions = create(null);
|
|
3939
3940
|
for (const [key, value] of entries(lib2)) {
|
|
3940
3941
|
const [wrappedValue, description] = wrapEntry(key, value, name);
|
|
3941
|
-
|
|
3942
|
+
mod2[key] = wrappedValue;
|
|
3942
3943
|
descriptions[key] = description;
|
|
3943
3944
|
}
|
|
3944
|
-
return new VmBuiltinModule(name,
|
|
3945
|
+
return new VmBuiltinModule(name, mod2, descriptions);
|
|
3945
3946
|
}
|
|
3946
3947
|
|
|
3947
3948
|
// src/vm/lib/index.ts
|
|
@@ -3951,8 +3952,8 @@ for (const [name, value] of entries(global_exports)) {
|
|
|
3951
3952
|
VM_SHARED_CONTEXT_DESCRIPTIONS[name] = description;
|
|
3952
3953
|
}
|
|
3953
3954
|
for (const [name, value] of entries(mod_exports)) {
|
|
3954
|
-
const
|
|
3955
|
-
const [wrappedValue, description] = wrapEntry(name,
|
|
3955
|
+
const mod2 = createModule(name, value);
|
|
3956
|
+
const [wrappedValue, description] = wrapEntry(name, mod2, "global");
|
|
3956
3957
|
VM_SHARED_CONTEXT[name] = wrappedValue;
|
|
3957
3958
|
VM_SHARED_CONTEXT_DESCRIPTIONS[name] = description;
|
|
3958
3959
|
}
|
|
@@ -3963,18 +3964,18 @@ export {
|
|
|
3963
3964
|
VmExtern,
|
|
3964
3965
|
wrapToVmValue,
|
|
3965
3966
|
unwrapFromVmValue,
|
|
3966
|
-
configCheckpoint,
|
|
3967
3967
|
VmFunction,
|
|
3968
3968
|
defineVmContextValue,
|
|
3969
3969
|
DefaultVmContext,
|
|
3970
3970
|
createVmContext,
|
|
3971
3971
|
VmModule,
|
|
3972
3972
|
$GlobalFallback,
|
|
3973
|
+
configCheckpoint,
|
|
3973
3974
|
operations_exports,
|
|
3974
3975
|
wrapScript,
|
|
3975
3976
|
createScript,
|
|
3976
|
-
|
|
3977
|
+
CompileError,
|
|
3977
3978
|
emitScript,
|
|
3978
3979
|
lib
|
|
3979
3980
|
};
|
|
3980
|
-
//# sourceMappingURL=chunk-
|
|
3981
|
+
//# sourceMappingURL=chunk-5BBTXV5A.js.map
|