@mirascript/mirascript 0.1.43 → 0.1.45
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/dist/{chunk-DNM6YMFU.js → chunk-CZOIPBED.js} +331 -205
- package/dist/chunk-CZOIPBED.js.map +6 -0
- package/dist/{chunk-GBWG7BQZ.js → chunk-UI6VQ263.js} +116 -42
- package/dist/chunk-UI6VQ263.js.map +6 -0
- package/dist/compiler/diagnostic.d.ts +4 -0
- package/dist/compiler/diagnostic.d.ts.map +1 -1
- package/dist/compiler/emit/constants.d.ts +3 -0
- package/dist/compiler/emit/constants.d.ts.map +1 -1
- package/dist/compiler/emit/index.d.ts +6 -1
- package/dist/compiler/emit/index.d.ts.map +1 -1
- package/dist/compiler/emit/sourcemap.d.ts +2 -1
- package/dist/compiler/emit/sourcemap.d.ts.map +1 -1
- package/dist/compiler/worker.js +1 -1
- package/dist/index.js +2 -2
- package/dist/subtle.js +6 -2
- package/dist/subtle.js.map +1 -1
- package/dist/vm/lib/global/debug.d.ts +11 -35
- package/dist/vm/lib/global/debug.d.ts.map +1 -1
- package/dist/vm/lib/global/index.d.ts +1 -1
- package/dist/vm/lib/global/index.d.ts.map +1 -1
- package/dist/vm/lib/global/math/arr.d.ts +7 -0
- package/dist/vm/lib/global/math/arr.d.ts.map +1 -0
- package/dist/vm/lib/global/math/const.d.ts +31 -0
- package/dist/vm/lib/global/math/const.d.ts.map +1 -0
- package/dist/vm/lib/global/math/gamma.d.ts +3 -0
- package/dist/vm/lib/global/math/gamma.d.ts.map +1 -0
- package/dist/vm/lib/global/math/index.d.ts +8 -0
- package/dist/vm/lib/global/math/index.d.ts.map +1 -0
- package/dist/vm/lib/global/math/unary.d.ts +28 -0
- package/dist/vm/lib/global/math/unary.d.ts.map +1 -0
- package/dist/vm/lib/helpers.d.ts.map +1 -1
- package/dist/vm/lib/loader.d.ts.map +1 -1
- package/dist/vm/operations/common.d.ts +2 -2
- package/dist/vm/operations/common.d.ts.map +1 -1
- package/dist/vm/operations/helpers.d.ts +7 -2
- package/dist/vm/operations/helpers.d.ts.map +1 -1
- package/dist/vm/operations/type-check.d.ts +1 -1
- package/dist/vm/operations/type-check.d.ts.map +1 -1
- package/dist/vm/types/function.d.ts +2 -2
- package/dist/vm/types/function.d.ts.map +1 -1
- package/dist/vm/types/wrapper.d.ts +0 -2
- package/dist/vm/types/wrapper.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/compiler/diagnostic.ts +56 -31
- package/src/compiler/emit/constants.ts +3 -0
- package/src/compiler/emit/index.ts +62 -5
- package/src/compiler/emit/sourcemap.ts +4 -3
- package/src/vm/lib/global/debug.ts +75 -61
- package/src/vm/lib/global/index.ts +1 -1
- package/src/vm/lib/global/{math-arr.ts → math/arr.ts} +2 -2
- package/src/vm/lib/global/{math-const.ts → math/const.ts} +1 -1
- package/src/vm/lib/global/math/gamma.ts +245 -0
- package/src/vm/lib/global/{math.ts → math/index.ts} +5 -5
- package/src/vm/lib/global/{math-unary.ts → math/unary.ts} +2 -2
- package/src/vm/lib/global/string.ts +1 -1
- package/src/vm/lib/helpers.ts +12 -10
- package/src/vm/lib/loader.ts +3 -13
- package/src/vm/operations/common.ts +2 -2
- package/src/vm/operations/helpers.ts +16 -3
- package/src/vm/operations/type-check.ts +1 -1
- package/src/vm/types/function.ts +19 -6
- package/src/vm/types/wrapper.ts +0 -4
- package/dist/chunk-DNM6YMFU.js.map +0 -6
- package/dist/chunk-GBWG7BQZ.js.map +0 -6
- package/dist/vm/lib/global/math-additional.d.ts +0 -2
- package/dist/vm/lib/global/math-additional.d.ts.map +0 -1
- package/dist/vm/lib/global/math-arr.d.ts +0 -7
- package/dist/vm/lib/global/math-arr.d.ts.map +0 -1
- package/dist/vm/lib/global/math-const.d.ts +0 -31
- package/dist/vm/lib/global/math-const.d.ts.map +0 -1
- package/dist/vm/lib/global/math-unary.d.ts +0 -28
- package/dist/vm/lib/global/math-unary.d.ts.map +0 -1
- package/dist/vm/lib/global/math.d.ts +0 -8
- package/dist/vm/lib/global/math.d.ts.map +0 -1
- package/src/vm/lib/global/math-additional.ts +0 -69
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
parseDiagnostics,
|
|
47
47
|
toString,
|
|
48
48
|
values
|
|
49
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-UI6VQ263.js";
|
|
50
50
|
|
|
51
51
|
// src/compiler/load-module.ts
|
|
52
52
|
import { loadModule } from "@mirascript/bindings";
|
|
@@ -124,7 +124,7 @@ function toNumber(value, fallback) {
|
|
|
124
124
|
// src/helpers/convert/to-format.ts
|
|
125
125
|
function formatNumber(finite) {
|
|
126
126
|
if (finite === 0) return "0";
|
|
127
|
-
const
|
|
127
|
+
const s2 = finite.toString();
|
|
128
128
|
let ps;
|
|
129
129
|
const abs3 = Math.abs(finite);
|
|
130
130
|
if (abs3 >= 1e3 || abs3 < 1e-3) {
|
|
@@ -134,7 +134,7 @@ function formatNumber(finite) {
|
|
|
134
134
|
} else {
|
|
135
135
|
ps = finite.toPrecision(6);
|
|
136
136
|
}
|
|
137
|
-
return ps.length <
|
|
137
|
+
return ps.length < s2.length ? ps : s2;
|
|
138
138
|
}
|
|
139
139
|
function toFormat(value, format2) {
|
|
140
140
|
const f = format2 == null ? "" : format2.trim();
|
|
@@ -171,10 +171,6 @@ var VmWrapper = class {
|
|
|
171
171
|
describe(key) {
|
|
172
172
|
return void 0;
|
|
173
173
|
}
|
|
174
|
-
/** Convert the object to JSON */
|
|
175
|
-
toJSON() {
|
|
176
|
-
return void 0;
|
|
177
|
-
}
|
|
178
174
|
/** 转为字符串 */
|
|
179
175
|
toString(useBraces) {
|
|
180
176
|
const { type, tag } = this;
|
|
@@ -464,40 +460,6 @@ var VmExtern = class extends VmWrapper {
|
|
|
464
460
|
};
|
|
465
461
|
Object.defineProperty(VmExtern.prototype, kVmExtern, { value: true });
|
|
466
462
|
|
|
467
|
-
// src/vm/types/module.ts
|
|
468
|
-
var VmModule = class extends VmWrapper {
|
|
469
|
-
constructor(name, value) {
|
|
470
|
-
super(value);
|
|
471
|
-
this.name = name;
|
|
472
|
-
}
|
|
473
|
-
/** @inheritdoc */
|
|
474
|
-
has(key) {
|
|
475
|
-
return hasOwnEnumerable(this.value, key);
|
|
476
|
-
}
|
|
477
|
-
/** @inheritdoc */
|
|
478
|
-
get(key) {
|
|
479
|
-
if (!this.has(key)) return void 0;
|
|
480
|
-
return this.value[key] ?? null;
|
|
481
|
-
}
|
|
482
|
-
/** @inheritdoc */
|
|
483
|
-
keys() {
|
|
484
|
-
return keys(this.value);
|
|
485
|
-
}
|
|
486
|
-
/** @inheritdoc */
|
|
487
|
-
same(other) {
|
|
488
|
-
return this === other;
|
|
489
|
-
}
|
|
490
|
-
/** @inheritdoc */
|
|
491
|
-
get type() {
|
|
492
|
-
return "module";
|
|
493
|
-
}
|
|
494
|
-
/** @inheritdoc */
|
|
495
|
-
get tag() {
|
|
496
|
-
return this.name;
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
Object.defineProperty(VmModule.prototype, kVmModule, { value: true });
|
|
500
|
-
|
|
501
463
|
// src/vm/checkpoint.ts
|
|
502
464
|
var { now } = Date;
|
|
503
465
|
var TIME_ORIGIN = now() - 1e3 * 3600 * 12;
|
|
@@ -561,6 +523,11 @@ function configCheckpoint(timeout = CP_DEFAULT_TIMEOUT, checkInterval = CP_DEFAU
|
|
|
561
523
|
}
|
|
562
524
|
|
|
563
525
|
// src/vm/types/function.ts
|
|
526
|
+
var nameIfNotAnonymous = ({ name }, fallback) => {
|
|
527
|
+
if (!name) return fallback;
|
|
528
|
+
if (name === VM_FUNCTION_ANONYMOUS_NAME) return fallback;
|
|
529
|
+
return name;
|
|
530
|
+
};
|
|
564
531
|
function VmFunction(fn, option = {}) {
|
|
565
532
|
if (typeof fn != "function") {
|
|
566
533
|
throw new TypeError("Invalid function");
|
|
@@ -569,14 +536,20 @@ function VmFunction(fn, option = {}) {
|
|
|
569
536
|
if (exists) return exists;
|
|
570
537
|
let opt;
|
|
571
538
|
if (isVmFunction(option)) {
|
|
572
|
-
opt = option[kVmFunction];
|
|
539
|
+
opt = { ...option[kVmFunction], name: nameIfNotAnonymous(option, null) };
|
|
573
540
|
} else if (typeof option == "function") {
|
|
574
|
-
opt = {
|
|
541
|
+
opt = {
|
|
542
|
+
...option,
|
|
543
|
+
isLib: true,
|
|
544
|
+
injectCp: false,
|
|
545
|
+
name: nameIfNotAnonymous(option, null)
|
|
546
|
+
};
|
|
575
547
|
} else {
|
|
576
548
|
opt = option;
|
|
577
549
|
}
|
|
578
550
|
const info = {
|
|
579
|
-
|
|
551
|
+
__proto__: null,
|
|
552
|
+
fullName: opt.fullName ?? nameIfNotAnonymous(fn, ""),
|
|
580
553
|
isLib: opt.isLib ?? false,
|
|
581
554
|
summary: opt.summary || void 0,
|
|
582
555
|
params: opt.params,
|
|
@@ -773,6 +746,40 @@ function createVmContext(arg0 = null, arg1 = null, describer = null) {
|
|
|
773
746
|
return new Value2VmContext(vmValues, externValues, describer);
|
|
774
747
|
}
|
|
775
748
|
|
|
749
|
+
// src/vm/types/module.ts
|
|
750
|
+
var VmModule = class extends VmWrapper {
|
|
751
|
+
constructor(name, value) {
|
|
752
|
+
super(value);
|
|
753
|
+
this.name = name;
|
|
754
|
+
}
|
|
755
|
+
/** @inheritdoc */
|
|
756
|
+
has(key) {
|
|
757
|
+
return hasOwnEnumerable(this.value, key);
|
|
758
|
+
}
|
|
759
|
+
/** @inheritdoc */
|
|
760
|
+
get(key) {
|
|
761
|
+
if (!this.has(key)) return void 0;
|
|
762
|
+
return this.value[key] ?? null;
|
|
763
|
+
}
|
|
764
|
+
/** @inheritdoc */
|
|
765
|
+
keys() {
|
|
766
|
+
return keys(this.value);
|
|
767
|
+
}
|
|
768
|
+
/** @inheritdoc */
|
|
769
|
+
same(other) {
|
|
770
|
+
return this === other;
|
|
771
|
+
}
|
|
772
|
+
/** @inheritdoc */
|
|
773
|
+
get type() {
|
|
774
|
+
return "module";
|
|
775
|
+
}
|
|
776
|
+
/** @inheritdoc */
|
|
777
|
+
get tag() {
|
|
778
|
+
return this.name;
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
Object.defineProperty(VmModule.prototype, kVmModule, { value: true });
|
|
782
|
+
|
|
776
783
|
// src/vm/operations/index.ts
|
|
777
784
|
var operations_exports = {};
|
|
778
785
|
__export(operations_exports, {
|
|
@@ -811,6 +818,7 @@ __export(operations_exports, {
|
|
|
811
818
|
$Lt: () => $Lt,
|
|
812
819
|
$Lte: () => $Lte,
|
|
813
820
|
$Mod: () => $Mod,
|
|
821
|
+
$Module: () => $Module,
|
|
814
822
|
$Mul: () => $Mul,
|
|
815
823
|
$Naeq: () => $Naeq,
|
|
816
824
|
$Neg: () => $Neg,
|
|
@@ -1066,19 +1074,26 @@ var sliceCore = (value, start, end, exclusive) => {
|
|
|
1066
1074
|
function $Slice(value, start, end) {
|
|
1067
1075
|
$AssertInit(value);
|
|
1068
1076
|
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
1069
|
-
const
|
|
1077
|
+
const s2 = start != null ? $ToNumber(start) : 0;
|
|
1070
1078
|
const e2 = end != null ? $ToNumber(end) : value.length - 1;
|
|
1071
|
-
return sliceCore(value,
|
|
1079
|
+
return sliceCore(value, s2, e2, false);
|
|
1072
1080
|
}
|
|
1073
1081
|
function $SliceExclusive(value, start, end) {
|
|
1074
1082
|
$AssertInit(value);
|
|
1075
1083
|
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
1076
|
-
const
|
|
1084
|
+
const s2 = start != null ? $ToNumber(start) : 0;
|
|
1077
1085
|
const e2 = end != null ? $ToNumber(end) : value.length;
|
|
1078
|
-
return sliceCore(value,
|
|
1086
|
+
return sliceCore(value, s2, e2, true);
|
|
1079
1087
|
}
|
|
1080
1088
|
|
|
1081
1089
|
// src/vm/operations/helpers.ts
|
|
1090
|
+
function $Module(name, body) {
|
|
1091
|
+
const mod = create(null);
|
|
1092
|
+
for (const [key, get] of entries(body)) {
|
|
1093
|
+
defineProperty(mod, key, { __proto__: null, get, enumerable: true });
|
|
1094
|
+
}
|
|
1095
|
+
return new VmModule(name, mod);
|
|
1096
|
+
}
|
|
1082
1097
|
function $El(value) {
|
|
1083
1098
|
$AssertInit(value);
|
|
1084
1099
|
if (!isVmConst(value)) return null;
|
|
@@ -1106,23 +1121,23 @@ var isEmptyRange = (start, end) => {
|
|
|
1106
1121
|
return !isFinite(start) || !isFinite(end) || start > end;
|
|
1107
1122
|
};
|
|
1108
1123
|
function $ArrayRange(start, end) {
|
|
1109
|
-
const
|
|
1124
|
+
const s2 = $ToNumber(start);
|
|
1110
1125
|
const e2 = $ToNumber(end);
|
|
1111
|
-
if (isEmptyRange(
|
|
1112
|
-
assertArrayLength(e2 -
|
|
1126
|
+
if (isEmptyRange(s2, e2)) return [];
|
|
1127
|
+
assertArrayLength(e2 - s2 + 1);
|
|
1113
1128
|
const arr = [];
|
|
1114
|
-
for (let i =
|
|
1129
|
+
for (let i = s2; i <= e2; i++) {
|
|
1115
1130
|
arr.push(i);
|
|
1116
1131
|
}
|
|
1117
1132
|
return arr;
|
|
1118
1133
|
}
|
|
1119
1134
|
function $ArrayRangeExclusive(start, end) {
|
|
1120
|
-
const
|
|
1135
|
+
const s2 = $ToNumber(start);
|
|
1121
1136
|
const e2 = $ToNumber(end);
|
|
1122
|
-
if (isEmptyRange(
|
|
1123
|
-
assertArrayLength(e2 -
|
|
1137
|
+
if (isEmptyRange(s2, e2)) return [];
|
|
1138
|
+
assertArrayLength(e2 - s2);
|
|
1124
1139
|
const arr = [];
|
|
1125
|
-
for (let i =
|
|
1140
|
+
for (let i = s2; i < e2; i++) {
|
|
1126
1141
|
arr.push(i);
|
|
1127
1142
|
}
|
|
1128
1143
|
return arr;
|
|
@@ -1371,6 +1386,7 @@ __export(global_exports, {
|
|
|
1371
1386
|
floor: () => floor,
|
|
1372
1387
|
format: () => format,
|
|
1373
1388
|
from_json: () => from_json,
|
|
1389
|
+
gamma: () => gamma,
|
|
1374
1390
|
hypot: () => hypot,
|
|
1375
1391
|
join: () => join,
|
|
1376
1392
|
keys: () => keys3,
|
|
@@ -1571,19 +1587,21 @@ function map(data, mapper) {
|
|
|
1571
1587
|
}
|
|
1572
1588
|
function VmLib(value, option, properties) {
|
|
1573
1589
|
if (isVmFunction(value)) throw new TypeError("Cannot create VmLib from a VmFunction");
|
|
1574
|
-
const ret = typeof value == "function" ? value : { value };
|
|
1590
|
+
const ret = typeof value == "function" ? value : { __proto__: null, value };
|
|
1591
|
+
Object.defineProperties(ret, {
|
|
1592
|
+
summary: { enumerable: true, value: option.summary },
|
|
1593
|
+
params: { enumerable: true, value: option.params },
|
|
1594
|
+
paramsType: { enumerable: true, value: option.paramsType },
|
|
1595
|
+
returns: { enumerable: true, value: option.returns },
|
|
1596
|
+
returnsType: { enumerable: true, value: option.returnsType },
|
|
1597
|
+
examples: { enumerable: true, value: option.examples },
|
|
1598
|
+
deprecated: { enumerable: true, value: option.deprecated ?? void 0 }
|
|
1599
|
+
});
|
|
1575
1600
|
Object.assign(ret, properties);
|
|
1576
|
-
ret.params = option.params;
|
|
1577
|
-
ret.paramsType = option.paramsType;
|
|
1578
|
-
ret.returns = option.returns;
|
|
1579
|
-
ret.returnsType = option.returnsType;
|
|
1580
|
-
ret.summary = option.summary;
|
|
1581
|
-
ret.examples = option.examples;
|
|
1582
|
-
ret.deprecated = option.deprecated ?? void 0;
|
|
1583
1601
|
return ret;
|
|
1584
1602
|
}
|
|
1585
1603
|
|
|
1586
|
-
// src/vm/lib/global/math
|
|
1604
|
+
// src/vm/lib/global/math/arr.ts
|
|
1587
1605
|
function build(f) {
|
|
1588
1606
|
return (...values4) => {
|
|
1589
1607
|
const numbers = getNumbers(values4);
|
|
@@ -1638,7 +1656,7 @@ var product = VmLib(
|
|
|
1638
1656
|
}
|
|
1639
1657
|
);
|
|
1640
1658
|
|
|
1641
|
-
// src/vm/lib/global/math
|
|
1659
|
+
// src/vm/lib/global/math/const.ts
|
|
1642
1660
|
import { DiagnosticCode as DiagnosticCode2 } from "@mirascript/constants";
|
|
1643
1661
|
var PI = VmLib(Math.PI, {
|
|
1644
1662
|
summary: "圆周率",
|
|
@@ -1689,7 +1707,7 @@ var LOG10E = VmLib(Math.LOG10E, {
|
|
|
1689
1707
|
returnsType: "number"
|
|
1690
1708
|
});
|
|
1691
1709
|
|
|
1692
|
-
// src/vm/lib/global/math
|
|
1710
|
+
// src/vm/lib/global/math/unary.ts
|
|
1693
1711
|
function build2(f) {
|
|
1694
1712
|
return (x) => {
|
|
1695
1713
|
return f(expectNumber("x", x));
|
|
@@ -1863,54 +1881,163 @@ var cbrt = VmLib(build2(Math.cbrt), {
|
|
|
1863
1881
|
returnsType: "number"
|
|
1864
1882
|
});
|
|
1865
1883
|
|
|
1866
|
-
// src/vm/lib/global/math
|
|
1867
|
-
var {
|
|
1868
|
-
var
|
|
1869
|
-
|
|
1870
|
-
0
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1884
|
+
// src/vm/lib/global/math/gamma.ts
|
|
1885
|
+
var { PI: PI2, exp: exp2, floor: floor2, cos: cos2, sin: sin2, pow, trunc: trunc3 } = Math;
|
|
1886
|
+
var MEM = new DataView(new ArrayBuffer(8));
|
|
1887
|
+
function f64ToBits(value) {
|
|
1888
|
+
MEM.setFloat64(0, value, false);
|
|
1889
|
+
return MEM.getBigUint64(0, false);
|
|
1890
|
+
}
|
|
1891
|
+
function f64FromBits(bits) {
|
|
1892
|
+
MEM.setBigUint64(0, bits, false);
|
|
1893
|
+
return MEM.getFloat64(0, false);
|
|
1894
|
+
}
|
|
1895
|
+
function sinpi(x) {
|
|
1896
|
+
x = x * 0.5;
|
|
1897
|
+
x = 2 * (x - floor2(x));
|
|
1898
|
+
let n = trunc3(4 * x);
|
|
1899
|
+
n = trunc3((n + 1) / 2);
|
|
1900
|
+
x -= n * 0.5;
|
|
1901
|
+
x *= PI2;
|
|
1902
|
+
switch (n) {
|
|
1903
|
+
case 1:
|
|
1904
|
+
return cos2(x);
|
|
1905
|
+
case 2:
|
|
1906
|
+
return sin2(-x);
|
|
1907
|
+
case 3:
|
|
1908
|
+
return -cos2(x);
|
|
1909
|
+
default:
|
|
1910
|
+
return sin2(x);
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
var N = 12;
|
|
1914
|
+
var GMHALF = 5.52468004077673;
|
|
1915
|
+
var SNUM = [
|
|
1916
|
+
2353137688041076e-5,
|
|
1917
|
+
429198036426491e-4,
|
|
1918
|
+
3571195923735567e-5,
|
|
1919
|
+
1792103442603721e-5,
|
|
1920
|
+
6039542586352028e-6,
|
|
1921
|
+
14397204073117216e-7,
|
|
1922
|
+
24887455786205417e-8,
|
|
1923
|
+
31426415585400194e-9,
|
|
1924
|
+
2.8763706289353725e6,
|
|
1925
|
+
186056.26539522348,
|
|
1926
|
+
8071.672002365816,
|
|
1927
|
+
210.82427775157936,
|
|
1928
|
+
2.5066282746310002
|
|
1885
1929
|
];
|
|
1886
|
-
var
|
|
1930
|
+
var SDEN = [
|
|
1931
|
+
0,
|
|
1932
|
+
39916800,
|
|
1933
|
+
120543840,
|
|
1934
|
+
150917976,
|
|
1935
|
+
105258076,
|
|
1936
|
+
45995730,
|
|
1937
|
+
13339535,
|
|
1938
|
+
2637558,
|
|
1939
|
+
357423,
|
|
1940
|
+
32670,
|
|
1941
|
+
1925,
|
|
1942
|
+
66,
|
|
1943
|
+
1
|
|
1944
|
+
];
|
|
1945
|
+
function s(x) {
|
|
1946
|
+
let num2 = 0;
|
|
1947
|
+
let den = 0;
|
|
1948
|
+
if (x < 8) {
|
|
1949
|
+
for (let i = N; i >= 0; i--) {
|
|
1950
|
+
num2 = num2 * x + SNUM[i];
|
|
1951
|
+
den = den * x + SDEN[i];
|
|
1952
|
+
}
|
|
1953
|
+
} else {
|
|
1954
|
+
for (let i = 0; i <= N; i++) {
|
|
1955
|
+
num2 = num2 / x + SNUM[i];
|
|
1956
|
+
den = den / x + SDEN[i];
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
return num2 / den;
|
|
1960
|
+
}
|
|
1961
|
+
function tgamma(x) {
|
|
1962
|
+
const u = f64ToBits(x);
|
|
1963
|
+
const ix = Number(u >> 32n & 0x7fffffffn);
|
|
1964
|
+
const sign2 = u >> 63n !== 0n;
|
|
1965
|
+
if (ix >= 2146435072) {
|
|
1966
|
+
return x + PositiveInfinity;
|
|
1967
|
+
}
|
|
1968
|
+
if (ix < 1023 - 54 << 20) {
|
|
1969
|
+
return 1 / x;
|
|
1970
|
+
}
|
|
1971
|
+
if (x === floor2(x)) {
|
|
1972
|
+
if (sign2) {
|
|
1973
|
+
return NotNumber;
|
|
1974
|
+
}
|
|
1975
|
+
if (x <= FACT_MAX) {
|
|
1976
|
+
return fact(trunc3(x) - 1);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
if (ix >= 1080492032) {
|
|
1980
|
+
if (sign2) {
|
|
1981
|
+
if (floor2(x) * 0.5 === floor2(x * 0.5)) {
|
|
1982
|
+
return 0;
|
|
1983
|
+
} else {
|
|
1984
|
+
return -0;
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
const x1p1023 = f64FromBits(0x7fe0000000000000n);
|
|
1988
|
+
return x * x1p1023;
|
|
1989
|
+
}
|
|
1990
|
+
const absx = sign2 ? -x : x;
|
|
1991
|
+
const y = absx + GMHALF;
|
|
1992
|
+
let dy;
|
|
1993
|
+
if (absx > GMHALF) {
|
|
1994
|
+
dy = y - absx;
|
|
1995
|
+
dy -= GMHALF;
|
|
1996
|
+
} else {
|
|
1997
|
+
dy = y - GMHALF;
|
|
1998
|
+
dy -= absx;
|
|
1999
|
+
}
|
|
2000
|
+
let z = absx - 0.5;
|
|
2001
|
+
let r = s(absx) * exp2(-y);
|
|
2002
|
+
if (x < 0) {
|
|
2003
|
+
r = -PI2 / (sinpi(absx) * absx * r);
|
|
2004
|
+
dy = -dy;
|
|
2005
|
+
z = -z;
|
|
2006
|
+
}
|
|
2007
|
+
r += dy * (GMHALF + 0.5) * r / y;
|
|
2008
|
+
const zHalf = pow(y, 0.5 * z);
|
|
2009
|
+
return r * zHalf * zHalf;
|
|
2010
|
+
}
|
|
2011
|
+
var gamma = VmLib(
|
|
2012
|
+
(x) => {
|
|
2013
|
+
const n = expectNumber("x", x);
|
|
2014
|
+
return tgamma(n);
|
|
2015
|
+
},
|
|
2016
|
+
{
|
|
2017
|
+
summary: "返回 Gamma 函数的值",
|
|
2018
|
+
params: { x: "要计算 Gamma 函数的数值" },
|
|
2019
|
+
paramsType: { x: "number" },
|
|
2020
|
+
returnsType: "number",
|
|
2021
|
+
examples: ["gamma(5) // 24"]
|
|
2022
|
+
}
|
|
2023
|
+
);
|
|
2024
|
+
var FACT_MAX = 171;
|
|
2025
|
+
var FACT = [1, 1];
|
|
2026
|
+
function fact(n) {
|
|
2027
|
+
const cached = FACT[n];
|
|
2028
|
+
if (cached != null) return cached;
|
|
2029
|
+
let r = 1n;
|
|
2030
|
+
for (let i = 2; i <= n; i++) {
|
|
2031
|
+
r *= BigInt(i);
|
|
2032
|
+
FACT[i] = Number(r);
|
|
2033
|
+
}
|
|
2034
|
+
return FACT[n];
|
|
2035
|
+
}
|
|
1887
2036
|
var factorial = VmLib(
|
|
1888
2037
|
(x) => {
|
|
1889
|
-
|
|
2038
|
+
const n = expectNumber("x", x);
|
|
1890
2039
|
if (isNaN(n) || n < 0) return NotNumber;
|
|
1891
|
-
|
|
1892
|
-
if (isInteger(n)) {
|
|
1893
|
-
if (n === 0 || n === 1) return 1;
|
|
1894
|
-
let r = 1;
|
|
1895
|
-
for (let i = 2; i <= n; i++) {
|
|
1896
|
-
r *= i;
|
|
1897
|
-
}
|
|
1898
|
-
return r;
|
|
1899
|
-
}
|
|
1900
|
-
if (n > 85) {
|
|
1901
|
-
n = n + 1;
|
|
1902
|
-
const twoN = n * n;
|
|
1903
|
-
const threeN = twoN * n;
|
|
1904
|
-
const fourN = threeN * n;
|
|
1905
|
-
const fiveN = fourN * n;
|
|
1906
|
-
return sqrt2(2 * Math.PI / n) * pow(n / Math.E, n) * (1 + 1 / (12 * n) + 1 / (288 * twoN) - 139 / (51840 * threeN) - 571 / (2488320 * fourN) + 163879 / (209018880 * fiveN) + 5246819 / (75246796800 * fiveN * n));
|
|
1907
|
-
}
|
|
1908
|
-
let p = GAMMA_P[0];
|
|
1909
|
-
for (let i = 1; i < GAMMA_P.length; ++i) {
|
|
1910
|
-
p += GAMMA_P[i] / (n + i);
|
|
1911
|
-
}
|
|
1912
|
-
const t = n + GAMMA_G + 0.5;
|
|
1913
|
-
return SQRT_2_PI * pow(t, n + 0.5) * exp2(-t) * p;
|
|
2040
|
+
return tgamma(n + 1);
|
|
1914
2041
|
},
|
|
1915
2042
|
{
|
|
1916
2043
|
summary: "返回一个数的阶乘",
|
|
@@ -1921,7 +2048,7 @@ var factorial = VmLib(
|
|
|
1921
2048
|
}
|
|
1922
2049
|
);
|
|
1923
2050
|
|
|
1924
|
-
// src/vm/lib/global/math.ts
|
|
2051
|
+
// src/vm/lib/global/math/index.ts
|
|
1925
2052
|
var { atan2: _atan2, pow: _pow, random: _random } = Math;
|
|
1926
2053
|
var atan2 = VmLib((x, y) => _atan2(expectNumber(0, x), expectNumber(1, y)), {
|
|
1927
2054
|
summary: "返回从原点到点 (x, y) 的角度(弧度)",
|
|
@@ -2622,16 +2749,22 @@ function buildFormatString(options, args) {
|
|
|
2622
2749
|
}
|
|
2623
2750
|
}
|
|
2624
2751
|
}
|
|
2625
|
-
var
|
|
2752
|
+
var printParser = function(args) {
|
|
2626
2753
|
const [format2, values4] = buildFormatString(this, args);
|
|
2627
2754
|
const templates = [];
|
|
2628
2755
|
const formats = [];
|
|
2629
2756
|
let valIndex = 0;
|
|
2630
2757
|
if (format2.includes("%")) {
|
|
2631
2758
|
const parts = format2.split(/(%[%\w])/g);
|
|
2759
|
+
let prevIsTemplate = true;
|
|
2632
2760
|
for (let i = 0; i < parts.length; i++) {
|
|
2633
2761
|
if (i % 2 === 0) {
|
|
2634
|
-
templates.
|
|
2762
|
+
if (prevIsTemplate && templates.length) {
|
|
2763
|
+
templates[templates.length - 1] += parts[i];
|
|
2764
|
+
} else {
|
|
2765
|
+
templates.push(parts[i]);
|
|
2766
|
+
}
|
|
2767
|
+
prevIsTemplate = true;
|
|
2635
2768
|
continue;
|
|
2636
2769
|
}
|
|
2637
2770
|
let specifier = parts[i];
|
|
@@ -2642,8 +2775,10 @@ var printFormatter = function(args) {
|
|
|
2642
2775
|
} else {
|
|
2643
2776
|
templates[templates.length - 1] += specifier;
|
|
2644
2777
|
}
|
|
2778
|
+
prevIsTemplate = true;
|
|
2645
2779
|
continue;
|
|
2646
2780
|
}
|
|
2781
|
+
prevIsTemplate = false;
|
|
2647
2782
|
formats.push(specifier);
|
|
2648
2783
|
valIndex++;
|
|
2649
2784
|
}
|
|
@@ -2668,49 +2803,57 @@ var printFormatter = function(args) {
|
|
|
2668
2803
|
formats
|
|
2669
2804
|
};
|
|
2670
2805
|
};
|
|
2671
|
-
var
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2806
|
+
var printFormatter = function({
|
|
2807
|
+
templates,
|
|
2808
|
+
formats,
|
|
2809
|
+
values: values4
|
|
2810
|
+
}) {
|
|
2811
|
+
let format2 = "";
|
|
2812
|
+
const formattedValues = [];
|
|
2813
|
+
let needAwait = false;
|
|
2814
|
+
for (let i = 0; i < templates.length; i++) {
|
|
2815
|
+
format2 += templates[i].replaceAll("%", "%%");
|
|
2816
|
+
if (i < values4.length) {
|
|
2817
|
+
const f = formats[i] ?? "";
|
|
2818
|
+
const v = values4[i];
|
|
2819
|
+
const serialized = serializeValue(this, v, f);
|
|
2820
|
+
if (serialized == null) {
|
|
2821
|
+
format2 += f || (typeof v == "string" ? "%s" : "%o");
|
|
2822
|
+
formattedValues.push(v);
|
|
2823
|
+
} else if (typeof serialized == "string") {
|
|
2824
|
+
format2 += "%s";
|
|
2825
|
+
formattedValues.push(serialized);
|
|
2826
|
+
} else {
|
|
2827
|
+
needAwait = true;
|
|
2828
|
+
format2 += "%s";
|
|
2829
|
+
formattedValues.push(serialized);
|
|
2693
2830
|
}
|
|
2694
2831
|
}
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
}
|
|
2702
|
-
}
|
|
2832
|
+
}
|
|
2833
|
+
if (!needAwait) {
|
|
2834
|
+
return [format2, ...formattedValues];
|
|
2835
|
+
} else {
|
|
2836
|
+
return Promise.all(formattedValues).then((resolvedValues) => {
|
|
2837
|
+
return [format2, ...resolvedValues];
|
|
2838
|
+
});
|
|
2839
|
+
}
|
|
2703
2840
|
};
|
|
2704
|
-
var
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2841
|
+
var createPrintOptions = (consoleMethod) => {
|
|
2842
|
+
return {
|
|
2843
|
+
prefix: ["MiraScript"],
|
|
2844
|
+
serializer: defaultSerializer,
|
|
2845
|
+
parser: printParser,
|
|
2846
|
+
formatter: printFormatter,
|
|
2847
|
+
logger: consoleMethod
|
|
2848
|
+
};
|
|
2709
2849
|
};
|
|
2850
|
+
function doPrint(opt, args) {
|
|
2851
|
+
const formatResult = opt.parser(args);
|
|
2852
|
+
void Promise.resolve(opt.formatter(formatResult)).then((printed) => opt.logger(...printed));
|
|
2853
|
+
}
|
|
2710
2854
|
var debug_print = VmLib(
|
|
2711
2855
|
(...args) => {
|
|
2712
|
-
|
|
2713
|
-
debug_print.printer(formatResult);
|
|
2856
|
+
doPrint(debug_print, args);
|
|
2714
2857
|
},
|
|
2715
2858
|
{
|
|
2716
2859
|
summary: "打印调试信息到控制台",
|
|
@@ -2719,16 +2862,12 @@ var debug_print = VmLib(
|
|
|
2719
2862
|
returnsType: "nil",
|
|
2720
2863
|
examples: ['debug_print("value:", 42);']
|
|
2721
2864
|
},
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
// eslint-disable-next-line no-console
|
|
2725
|
-
printer: createPrinter(console.log)
|
|
2726
|
-
}
|
|
2865
|
+
// eslint-disable-next-line no-console
|
|
2866
|
+
createPrintOptions(console.log.bind(console))
|
|
2727
2867
|
);
|
|
2728
2868
|
var panic = VmLib(
|
|
2729
2869
|
(message) => {
|
|
2730
|
-
|
|
2731
|
-
panic.printer(formatResult);
|
|
2870
|
+
doPrint(panic, message === void 0 ? [] : [message]);
|
|
2732
2871
|
const mgsStr = toString(message, null);
|
|
2733
2872
|
const error = !mgsStr ? "panic" : "panic: " + mgsStr;
|
|
2734
2873
|
throw new VmError(error, void 0);
|
|
@@ -2740,11 +2879,8 @@ var panic = VmLib(
|
|
|
2740
2879
|
returnsType: "never",
|
|
2741
2880
|
examples: ['panic("boom");']
|
|
2742
2881
|
},
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
// eslint-disable-next-line no-console
|
|
2746
|
-
printer: createPrinter(console.error)
|
|
2747
|
-
}
|
|
2882
|
+
// eslint-disable-next-line no-console
|
|
2883
|
+
createPrintOptions(console.error.bind(console))
|
|
2748
2884
|
);
|
|
2749
2885
|
if (typeof location != "undefined") {
|
|
2750
2886
|
const badge = "%cMiraScript%c";
|
|
@@ -2873,7 +3009,7 @@ var format = VmLib(
|
|
|
2873
3009
|
// src/vm/lib/global/string.ts
|
|
2874
3010
|
var chars = VmLib(
|
|
2875
3011
|
(str) => {
|
|
2876
|
-
return
|
|
3012
|
+
return Array.from(expectString("str", str));
|
|
2877
3013
|
},
|
|
2878
3014
|
{
|
|
2879
3015
|
summary: "将字符串转换为字符数组",
|
|
@@ -2972,10 +3108,10 @@ var replace = VmLib(
|
|
|
2972
3108
|
);
|
|
2973
3109
|
var split = VmLib(
|
|
2974
3110
|
(str, separator = "") => {
|
|
2975
|
-
const
|
|
3111
|
+
const s2 = expectString("str", str);
|
|
2976
3112
|
const p = expectString("separator", separator);
|
|
2977
|
-
if (!p) return [...
|
|
2978
|
-
return
|
|
3113
|
+
if (!p) return [...s2];
|
|
3114
|
+
return s2.split(p);
|
|
2979
3115
|
},
|
|
2980
3116
|
{
|
|
2981
3117
|
summary: "将字符串拆分为子串数组",
|
|
@@ -2988,8 +3124,8 @@ var split = VmLib(
|
|
|
2988
3124
|
var join = VmLib(
|
|
2989
3125
|
(arr, separator = "") => {
|
|
2990
3126
|
expectArray("arr", arr, null);
|
|
2991
|
-
const
|
|
2992
|
-
return arr.map((v) => expectString(null, v)).join(
|
|
3127
|
+
const s2 = expectString("separator", separator);
|
|
3128
|
+
return arr.map((v) => expectString(null, v)).join(s2);
|
|
2993
3129
|
},
|
|
2994
3130
|
{
|
|
2995
3131
|
summary: "将字符串数组连接为单个字符串",
|
|
@@ -3362,11 +3498,11 @@ var multiply = VmLib(
|
|
|
3362
3498
|
$Mul,
|
|
3363
3499
|
(a2, b2, al, bl) => {
|
|
3364
3500
|
const l = Math.max(al, bl);
|
|
3365
|
-
let
|
|
3501
|
+
let s2 = 0;
|
|
3366
3502
|
for (let i = 0; i < l; i++) {
|
|
3367
|
-
|
|
3503
|
+
s2 += num(a2[i]) * num(b2[i]);
|
|
3368
3504
|
}
|
|
3369
|
-
return
|
|
3505
|
+
return s2;
|
|
3370
3506
|
},
|
|
3371
3507
|
(a2, b2, ar, ac, br, bc) => {
|
|
3372
3508
|
if (ac !== br) throwError(`Incompatible matrix dimensions`, null);
|
|
@@ -3481,20 +3617,20 @@ var invert = VmLib(
|
|
|
3481
3617
|
if (r !== c) {
|
|
3482
3618
|
if (Ar[c] !== 0) {
|
|
3483
3619
|
const f = -Ar[c] / Ac[c];
|
|
3484
|
-
for (let
|
|
3485
|
-
Ar[
|
|
3620
|
+
for (let s2 = c; s2 < cols; s2++) {
|
|
3621
|
+
Ar[s2] = Ar[s2] + f * Ac[s2];
|
|
3486
3622
|
}
|
|
3487
|
-
for (let
|
|
3488
|
-
Br[
|
|
3623
|
+
for (let s2 = 0; s2 < cols; s2++) {
|
|
3624
|
+
Br[s2] = Br[s2] + f * Bc[s2];
|
|
3489
3625
|
}
|
|
3490
3626
|
}
|
|
3491
3627
|
} else {
|
|
3492
3628
|
const f = Ac[c];
|
|
3493
|
-
for (let
|
|
3494
|
-
Ar[
|
|
3629
|
+
for (let s2 = c; s2 < cols; s2++) {
|
|
3630
|
+
Ar[s2] = Ar[s2] / f;
|
|
3495
3631
|
}
|
|
3496
|
-
for (let
|
|
3497
|
-
Br[
|
|
3632
|
+
for (let s2 = 0; s2 < cols; s2++) {
|
|
3633
|
+
Br[s2] = Br[s2] / f;
|
|
3498
3634
|
}
|
|
3499
3635
|
}
|
|
3500
3636
|
}
|
|
@@ -3510,10 +3646,10 @@ var invert = VmLib(
|
|
|
3510
3646
|
}
|
|
3511
3647
|
);
|
|
3512
3648
|
function filled(size2, value) {
|
|
3513
|
-
const
|
|
3514
|
-
if (
|
|
3515
|
-
while (
|
|
3516
|
-
const repeat2 = arrayLen(
|
|
3649
|
+
const s2 = getNumbers(size2);
|
|
3650
|
+
if (s2.length === 0) return [];
|
|
3651
|
+
while (s2.length > 0) {
|
|
3652
|
+
const repeat2 = arrayLen(s2.pop());
|
|
3517
3653
|
Cp();
|
|
3518
3654
|
const data = [];
|
|
3519
3655
|
data.length = repeat2;
|
|
@@ -3538,12 +3674,12 @@ var ones = VmLib((...size2) => filled(size2, 1), {
|
|
|
3538
3674
|
});
|
|
3539
3675
|
var identity = VmLib(
|
|
3540
3676
|
(...size2) => {
|
|
3541
|
-
let
|
|
3542
|
-
if (
|
|
3543
|
-
if (
|
|
3544
|
-
if (
|
|
3545
|
-
const m = arrayLen(
|
|
3546
|
-
const n = arrayLen(
|
|
3677
|
+
let s2 = getNumbers(size2);
|
|
3678
|
+
if (s2.length === 0) return [];
|
|
3679
|
+
if (s2.length > 2) throwError("Invalid matrix size", []);
|
|
3680
|
+
if (s2.length === 1) s2 = [s2[0], s2[0]];
|
|
3681
|
+
const m = arrayLen(s2[0]);
|
|
3682
|
+
const n = arrayLen(s2[1]);
|
|
3547
3683
|
const ret = [];
|
|
3548
3684
|
for (let i = 0; i < m; i++) {
|
|
3549
3685
|
const row = [];
|
|
@@ -3628,20 +3764,10 @@ function wrapEntry(name, value, module) {
|
|
|
3628
3764
|
return [value.value, value.summary || void 0];
|
|
3629
3765
|
}
|
|
3630
3766
|
if (value.name !== name) {
|
|
3631
|
-
defineProperty(value, "name", {
|
|
3632
|
-
value: name,
|
|
3633
|
-
configurable: true
|
|
3634
|
-
});
|
|
3767
|
+
defineProperty(value, "name", { value: name });
|
|
3635
3768
|
}
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
...value,
|
|
3639
|
-
isLib: true,
|
|
3640
|
-
injectCp: false,
|
|
3641
|
-
fullName: `${module}.${name}`
|
|
3642
|
-
}),
|
|
3643
|
-
value.summary || void 0
|
|
3644
|
-
];
|
|
3769
|
+
defineProperty(value, "fullName", { enumerable: true, value: `${module}.${name}` });
|
|
3770
|
+
return [VmFunction(value, value), value.summary || void 0];
|
|
3645
3771
|
}
|
|
3646
3772
|
function createModule(name, lib2) {
|
|
3647
3773
|
const mod = create(null);
|
|
@@ -3673,12 +3799,12 @@ export {
|
|
|
3673
3799
|
VmExtern,
|
|
3674
3800
|
wrapToVmValue,
|
|
3675
3801
|
unwrapFromVmValue,
|
|
3676
|
-
VmModule,
|
|
3677
3802
|
configCheckpoint,
|
|
3678
3803
|
VmFunction,
|
|
3679
3804
|
defineVmContextValue,
|
|
3680
3805
|
DefaultVmContext,
|
|
3681
3806
|
createVmContext,
|
|
3807
|
+
VmModule,
|
|
3682
3808
|
$GlobalFallback,
|
|
3683
3809
|
operations_exports,
|
|
3684
3810
|
wrapScript,
|
|
@@ -3687,4 +3813,4 @@ export {
|
|
|
3687
3813
|
emitScript,
|
|
3688
3814
|
lib
|
|
3689
3815
|
};
|
|
3690
|
-
//# sourceMappingURL=chunk-
|
|
3816
|
+
//# sourceMappingURL=chunk-CZOIPBED.js.map
|