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