@mirascript/mirascript 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-3RUWGMBP.js → chunk-JB6LPPFJ.js} +190 -24
- package/dist/chunk-JB6LPPFJ.js.map +6 -0
- package/dist/{chunk-AOINGBRS.js → chunk-RYSPVMVZ.js} +189 -191
- package/dist/chunk-RYSPVMVZ.js.map +6 -0
- package/dist/cli/execute.d.ts +1 -1
- package/dist/cli/execute.d.ts.map +1 -1
- package/dist/cli/index.js +42 -21
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/print.d.ts.map +1 -1
- package/dist/compiler/diagnostic.d.ts +14 -3
- package/dist/compiler/diagnostic.d.ts.map +1 -1
- package/dist/compiler/emit.d.ts +2 -1
- package/dist/compiler/emit.d.ts.map +1 -1
- package/dist/compiler/index.d.ts.map +1 -1
- package/dist/compiler/worker.d.ts.map +1 -1
- package/dist/compiler/worker.js +6 -3
- package/dist/compiler/worker.js.map +1 -1
- package/dist/helpers/serialize.d.ts +10 -2
- package/dist/helpers/serialize.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/subtle.d.ts +1 -1
- package/dist/subtle.d.ts.map +1 -1
- package/dist/subtle.js +17 -7
- package/dist/vm/lib/_helpers.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/with.d.ts +2 -2
- package/dist/vm/lib/global/sequence/with.d.ts.map +1 -1
- package/dist/vm/operations.d.ts.map +1 -1
- package/dist/vm/types/boundary.d.ts.map +1 -1
- package/dist/vm/types/checker.d.ts +1 -1
- package/dist/vm/types/checker.d.ts.map +1 -1
- package/dist/vm/types/context.d.ts +14 -6
- package/dist/vm/types/context.d.ts.map +1 -1
- package/dist/vm/types/extern.d.ts +2 -0
- package/dist/vm/types/extern.d.ts.map +1 -1
- package/dist/vm/types/index.d.ts +6 -10
- package/dist/vm/types/index.d.ts.map +1 -1
- package/dist/vm/types/module.d.ts +2 -0
- package/dist/vm/types/module.d.ts.map +1 -1
- package/dist/vm/types/wrapper.d.ts +2 -0
- package/dist/vm/types/wrapper.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/cli/execute.ts +8 -3
- package/src/cli/index.ts +22 -5
- package/src/cli/print.ts +13 -9
- package/src/compiler/diagnostic.ts +32 -14
- package/src/compiler/emit.ts +45 -19
- package/src/compiler/index.ts +10 -2
- package/src/compiler/worker.ts +5 -1
- package/src/helpers/serialize.ts +6 -6
- package/src/subtle.ts +11 -1
- package/src/vm/lib/_helpers.ts +2 -10
- package/src/vm/lib/global/math-arr.ts +1 -1
- package/src/vm/lib/global/sequence/with.ts +111 -17
- package/src/vm/operations.ts +23 -24
- package/src/vm/types/boundary.ts +4 -4
- package/src/vm/types/checker.ts +8 -15
- package/src/vm/types/context.ts +28 -16
- package/src/vm/types/extern.ts +11 -2
- package/src/vm/types/index.ts +7 -26
- package/src/vm/types/module.ts +7 -0
- package/src/vm/types/wrapper.ts +10 -1
- package/dist/chunk-3RUWGMBP.js.map +0 -6
- package/dist/chunk-AOINGBRS.js.map +0 -6
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DiagnosticCode,
|
|
2
3
|
__export,
|
|
4
|
+
apply,
|
|
5
|
+
create,
|
|
6
|
+
defineProperty,
|
|
3
7
|
emit,
|
|
8
|
+
entries,
|
|
9
|
+
formatDiagnostic,
|
|
10
|
+
fromEntries,
|
|
4
11
|
generateBytecode,
|
|
5
12
|
generateBytecodeSync,
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
getPrototypeOf,
|
|
14
|
+
hasOwn,
|
|
15
|
+
hasOwnEnumerable,
|
|
16
|
+
isArray,
|
|
17
|
+
isFinite,
|
|
18
|
+
isInteger,
|
|
19
|
+
isNaN,
|
|
20
|
+
isSafeInteger,
|
|
21
|
+
keys,
|
|
22
|
+
loadModule,
|
|
23
|
+
parseDiagnostics,
|
|
24
|
+
values
|
|
25
|
+
} from "./chunk-JB6LPPFJ.js";
|
|
8
26
|
|
|
9
27
|
// src/helpers/constants.ts
|
|
10
28
|
var constants_exports = {};
|
|
@@ -15,16 +33,6 @@ __export(constants_exports, {
|
|
|
15
33
|
var REG_IDENTIFIER = /(?:_+|@+|\$+|\p{XID_Start})\p{XID_Continue}*/u;
|
|
16
34
|
var REG_ORDINAL = /(?:0|[1-9]\d{0,8}|1\d{9}|20\d{8}|21[0-3]\d{7}|214[0-6]\d{6}|2147[0-3]\d{5}|21474[0-7]\d{4}|214748[0-2]\d{3}|2147483[0-5]\d{2}|21474836[0-3]\d|214748364[0-7])/;
|
|
17
35
|
|
|
18
|
-
// src/helpers/utils.ts
|
|
19
|
-
var { isArray } = Array;
|
|
20
|
-
var { isFinite, isNaN, isInteger, isSafeInteger } = Number;
|
|
21
|
-
var { hasOwn, keys, values, entries, create, getPrototypeOf, fromEntries, defineProperty } = Object;
|
|
22
|
-
var { apply } = Reflect;
|
|
23
|
-
var hasOwnEnumerable = Function.call.bind(
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
25
|
-
Object.prototype.propertyIsEnumerable
|
|
26
|
-
);
|
|
27
|
-
|
|
28
36
|
// src/vm/error.ts
|
|
29
37
|
var VmError = class _VmError extends Error {
|
|
30
38
|
constructor(message, recovered) {
|
|
@@ -64,9 +72,16 @@ var VmWrapper = class {
|
|
|
64
72
|
}
|
|
65
73
|
/** 转为字符串 */
|
|
66
74
|
toString() {
|
|
67
|
-
|
|
75
|
+
const { type, describe } = this;
|
|
76
|
+
if (!describe) return `<${type}>`;
|
|
77
|
+
return `<${type} ${describe}>`;
|
|
68
78
|
}
|
|
69
79
|
};
|
|
80
|
+
var kVmWrapper = Symbol.for("mirascript.vm.wrapper");
|
|
81
|
+
Object.defineProperty(VmWrapper.prototype, kVmWrapper, { value: true });
|
|
82
|
+
function isVmWrapper(value) {
|
|
83
|
+
return value != null && typeof value == "object" && kVmWrapper in value;
|
|
84
|
+
}
|
|
70
85
|
|
|
71
86
|
// src/vm/helpers.ts
|
|
72
87
|
var helpers_exports = {};
|
|
@@ -143,8 +158,8 @@ var isSame = (a, b) => {
|
|
|
143
158
|
if (typeof a == "number" && typeof b == "number") return a === b || isNaN(a) && isNaN(b);
|
|
144
159
|
if (a === b) return true;
|
|
145
160
|
if (a == null || typeof a != "object" || b == null || typeof b != "object") return false;
|
|
146
|
-
if (a
|
|
147
|
-
if (b
|
|
161
|
+
if (isVmWrapper(a)) return a.same(b);
|
|
162
|
+
if (isVmWrapper(b)) return b.same(a);
|
|
148
163
|
if (isVmArray(a) && isVmArray(b)) {
|
|
149
164
|
const len2 = a.length;
|
|
150
165
|
if (len2 !== b.length) {
|
|
@@ -241,11 +256,6 @@ var $Eq = (a, b) => {
|
|
|
241
256
|
var $Neq = (a, b) => {
|
|
242
257
|
return !$Eq(a, b);
|
|
243
258
|
};
|
|
244
|
-
var stringComparer = new Intl.Collator("en", {
|
|
245
|
-
usage: "sort",
|
|
246
|
-
numeric: false,
|
|
247
|
-
sensitivity: "base"
|
|
248
|
-
});
|
|
249
259
|
var $Aeq = (a, b) => {
|
|
250
260
|
if (overloadNumberString(a, b)) {
|
|
251
261
|
const an = $ToNumber(a);
|
|
@@ -261,7 +271,12 @@ var $Aeq = (a, b) => {
|
|
|
261
271
|
const as = $ToString(a);
|
|
262
272
|
const bs = $ToString(b);
|
|
263
273
|
if (as === bs) return true;
|
|
264
|
-
|
|
274
|
+
const ai = as.toLowerCase();
|
|
275
|
+
const bi = bs.toLowerCase();
|
|
276
|
+
if (ai === bi) return true;
|
|
277
|
+
const an = ai.normalize("NFC");
|
|
278
|
+
const bn = bi.normalize("NFC");
|
|
279
|
+
return an === bn;
|
|
265
280
|
}
|
|
266
281
|
};
|
|
267
282
|
var $Naeq = (a, b) => {
|
|
@@ -290,7 +305,7 @@ var $In = (value, iterable) => {
|
|
|
290
305
|
value;
|
|
291
306
|
return iterable.some((item = null) => isSame(item, value));
|
|
292
307
|
}
|
|
293
|
-
if (iterable
|
|
308
|
+
if (isVmWrapper(iterable)) return iterable.has($ToString(value));
|
|
294
309
|
if (typeof iterable == "object") return hasOwnEnumerable(iterable, $ToString(value));
|
|
295
310
|
iterable;
|
|
296
311
|
return false;
|
|
@@ -311,7 +326,7 @@ var $Length = (value) => {
|
|
|
311
326
|
$AssertInit(value);
|
|
312
327
|
if (isVmArray(value)) return value.length;
|
|
313
328
|
if (isVmRecord(value)) return keys(value).length;
|
|
314
|
-
if (value
|
|
329
|
+
if (isVmWrapper(value)) {
|
|
315
330
|
return value.keys().length;
|
|
316
331
|
}
|
|
317
332
|
return Number.NaN;
|
|
@@ -376,7 +391,7 @@ var $Call = (func, args) => {
|
|
|
376
391
|
for (const a of args) {
|
|
377
392
|
$AssertInit(a);
|
|
378
393
|
}
|
|
379
|
-
if (func
|
|
394
|
+
if (isVmExtern(func)) {
|
|
380
395
|
return func.call(args) ?? null;
|
|
381
396
|
}
|
|
382
397
|
if (isVmFunction(func)) {
|
|
@@ -386,8 +401,8 @@ var $Call = (func, args) => {
|
|
|
386
401
|
};
|
|
387
402
|
var $Type = (value) => {
|
|
388
403
|
if (value === void 0 || value === null) return "nil";
|
|
389
|
-
if (value
|
|
390
|
-
if (value
|
|
404
|
+
if (isVmExtern(value)) return "extern";
|
|
405
|
+
if (isVmModule(value)) return "module";
|
|
391
406
|
if (isVmArray(value)) return "array";
|
|
392
407
|
if (typeof value == "object") return "record";
|
|
393
408
|
return typeof value;
|
|
@@ -404,7 +419,7 @@ function numberToString(value) {
|
|
|
404
419
|
}
|
|
405
420
|
function innerToString(value, useBraces) {
|
|
406
421
|
if (value == null) return "nil";
|
|
407
|
-
if (value
|
|
422
|
+
if (isVmWrapper(value)) return value.toString();
|
|
408
423
|
if (typeof value == "function") {
|
|
409
424
|
const name = getVmFunctionInfo(value)?.fullName;
|
|
410
425
|
return name ? `<function ${name}>` : `<function>`;
|
|
@@ -481,7 +496,7 @@ var $Has = (obj, key) => {
|
|
|
481
496
|
$AssertInit(obj);
|
|
482
497
|
const pk = $ToString(key);
|
|
483
498
|
if (obj == null || typeof obj != "object") return false;
|
|
484
|
-
if (obj
|
|
499
|
+
if (isVmWrapper(obj)) return obj.has(pk);
|
|
485
500
|
return hasOwnEnumerable(obj, pk);
|
|
486
501
|
};
|
|
487
502
|
var $Get = (obj, key) => {
|
|
@@ -493,7 +508,7 @@ var $Get = (obj, key) => {
|
|
|
493
508
|
}
|
|
494
509
|
const pk = $ToString(key);
|
|
495
510
|
if (obj == null || typeof obj != "object") return null;
|
|
496
|
-
if (obj
|
|
511
|
+
if (isVmWrapper(obj)) return obj.get(pk) ?? null;
|
|
497
512
|
if (!hasOwnEnumerable(obj, pk)) return null;
|
|
498
513
|
return obj[pk] ?? null;
|
|
499
514
|
};
|
|
@@ -507,7 +522,7 @@ var $Set = (obj, key, value) => {
|
|
|
507
522
|
};
|
|
508
523
|
var $Iterable = (value) => {
|
|
509
524
|
$AssertInit(value);
|
|
510
|
-
if (value
|
|
525
|
+
if (isVmWrapper(value)) return value.keys();
|
|
511
526
|
if (isVmArray(value)) return value;
|
|
512
527
|
if (value != null && typeof value == "object") return keys(value);
|
|
513
528
|
throw new VmError(`Value is not iterable`, isVmFunction(value) ? [] : [value]);
|
|
@@ -766,7 +781,7 @@ function wrapToVmValue(value, thisArg = null, assumeVmValue) {
|
|
|
766
781
|
return new VmExtern(value, thisArg);
|
|
767
782
|
}
|
|
768
783
|
case "object": {
|
|
769
|
-
if (value
|
|
784
|
+
if (isVmWrapper(value)) return value;
|
|
770
785
|
if (value instanceof Date) return value.valueOf();
|
|
771
786
|
if (assumeVmValue?.(value)) return value;
|
|
772
787
|
return new VmExtern(value);
|
|
@@ -788,7 +803,7 @@ function unwrapFromVmValue(value) {
|
|
|
788
803
|
return toVmFunctionProxy(value);
|
|
789
804
|
}
|
|
790
805
|
if (value == null || typeof value != "object") return value;
|
|
791
|
-
if (!(value
|
|
806
|
+
if (!isVmExtern(value)) return value;
|
|
792
807
|
if (value.thisArg == null || typeof value.value != "function") {
|
|
793
808
|
return value.value;
|
|
794
809
|
}
|
|
@@ -804,7 +819,8 @@ function unwrapFromVmValue(value) {
|
|
|
804
819
|
// src/vm/types/extern.ts
|
|
805
820
|
var ObjectPrototype = Object.prototype;
|
|
806
821
|
var ObjectToString = ObjectPrototype.toString;
|
|
807
|
-
var
|
|
822
|
+
var FunctionToString = Function.prototype.toString;
|
|
823
|
+
var VmExtern = class extends VmWrapper {
|
|
808
824
|
constructor(value, thisArg = null) {
|
|
809
825
|
super(value);
|
|
810
826
|
this.thisArg = thisArg;
|
|
@@ -871,13 +887,13 @@ var VmExtern = class _VmExtern extends VmWrapper {
|
|
|
871
887
|
}
|
|
872
888
|
/** @inheritdoc */
|
|
873
889
|
same(other) {
|
|
874
|
-
if (!(other
|
|
890
|
+
if (!isVmExtern(other)) return false;
|
|
875
891
|
return this.value === other.value && this.thisArg === other.thisArg;
|
|
876
892
|
}
|
|
877
893
|
/** @inheritdoc */
|
|
878
894
|
toString() {
|
|
879
895
|
const { toString } = this.value;
|
|
880
|
-
if (typeof toString != "function" || toString === ObjectToString) {
|
|
896
|
+
if (typeof toString != "function" || toString === ObjectToString || toString === FunctionToString) {
|
|
881
897
|
return super.toString();
|
|
882
898
|
}
|
|
883
899
|
try {
|
|
@@ -915,6 +931,11 @@ var VmExtern = class _VmExtern extends VmWrapper {
|
|
|
915
931
|
return tag;
|
|
916
932
|
}
|
|
917
933
|
};
|
|
934
|
+
var kVmExtern = Symbol.for("mirascript.vm.extern");
|
|
935
|
+
Object.defineProperty(VmExtern.prototype, kVmExtern, { value: true });
|
|
936
|
+
function isVmExtern(value) {
|
|
937
|
+
return value != null && typeof value == "object" && kVmExtern in value;
|
|
938
|
+
}
|
|
918
939
|
|
|
919
940
|
// src/vm/types/module.ts
|
|
920
941
|
var VmModule = class extends VmWrapper {
|
|
@@ -948,6 +969,11 @@ var VmModule = class extends VmWrapper {
|
|
|
948
969
|
return this.name;
|
|
949
970
|
}
|
|
950
971
|
};
|
|
972
|
+
var kVmModule = Symbol.for("mirascript.vm.module");
|
|
973
|
+
Object.defineProperty(VmModule.prototype, kVmModule, { value: true });
|
|
974
|
+
function isVmModule(value) {
|
|
975
|
+
return value != null && typeof value == "object" && kVmModule in value;
|
|
976
|
+
}
|
|
951
977
|
|
|
952
978
|
// src/vm/types/script.ts
|
|
953
979
|
var kVmScript = Symbol.for("mirascript.vm.script");
|
|
@@ -990,7 +1016,7 @@ function isVmConstInner(value, depth) {
|
|
|
990
1016
|
return true;
|
|
991
1017
|
case "object":
|
|
992
1018
|
if (value == null) return true;
|
|
993
|
-
if (value
|
|
1019
|
+
if (isVmWrapper(value)) return false;
|
|
994
1020
|
if (isArray(value)) {
|
|
995
1021
|
return isVmArrayDeep(value, depth);
|
|
996
1022
|
} else {
|
|
@@ -1011,7 +1037,7 @@ function isVmConst(value, checkDeep = false) {
|
|
|
1011
1037
|
return true;
|
|
1012
1038
|
case "object":
|
|
1013
1039
|
if (value == null) return true;
|
|
1014
|
-
if (value
|
|
1040
|
+
if (isVmWrapper(value)) return false;
|
|
1015
1041
|
if (!checkDeep) {
|
|
1016
1042
|
if (isArray(value)) {
|
|
1017
1043
|
return isVmArrayDeep(value, 0);
|
|
@@ -1030,7 +1056,7 @@ function isVmConst(value, checkDeep = false) {
|
|
|
1030
1056
|
}
|
|
1031
1057
|
}
|
|
1032
1058
|
function isVmImmutable(value, checkDeep = false) {
|
|
1033
|
-
return value
|
|
1059
|
+
return isVmModule(value) || isVmFunction(value) || isVmConst(value, checkDeep);
|
|
1034
1060
|
}
|
|
1035
1061
|
function isVmValue(value, checkDeep = false) {
|
|
1036
1062
|
if (value === void 0) return false;
|
|
@@ -1045,7 +1071,7 @@ function isVmAny(value, checkDeep) {
|
|
|
1045
1071
|
return true;
|
|
1046
1072
|
case "object":
|
|
1047
1073
|
if (value == null) return true;
|
|
1048
|
-
if (value
|
|
1074
|
+
if (isVmWrapper(value)) return true;
|
|
1049
1075
|
return isVmConst(value, checkDeep);
|
|
1050
1076
|
case "function":
|
|
1051
1077
|
return isVmFunction(value);
|
|
@@ -1064,7 +1090,7 @@ function isVmArray(value) {
|
|
|
1064
1090
|
}
|
|
1065
1091
|
function isVmRecord(value) {
|
|
1066
1092
|
if (value == null || typeof value !== "object") return false;
|
|
1067
|
-
if (value
|
|
1093
|
+
if (isVmWrapper(value)) return false;
|
|
1068
1094
|
if (isVmArray(value)) return false;
|
|
1069
1095
|
value;
|
|
1070
1096
|
return true;
|
|
@@ -1077,15 +1103,9 @@ function isVmPrimitive(value) {
|
|
|
1077
1103
|
}
|
|
1078
1104
|
return false;
|
|
1079
1105
|
}
|
|
1080
|
-
function isVmExtern(value) {
|
|
1081
|
-
return value instanceof VmExtern;
|
|
1082
|
-
}
|
|
1083
1106
|
function isVmCallable(value) {
|
|
1084
1107
|
return isVmFunction(value) || isVmExtern(value) && typeof value.value == "function";
|
|
1085
1108
|
}
|
|
1086
|
-
function isVmModule(value) {
|
|
1087
|
-
return value instanceof VmModule;
|
|
1088
|
-
}
|
|
1089
1109
|
var VM_ARRAY_MAX_LENGTH = 2 ** 31 - 1;
|
|
1090
1110
|
|
|
1091
1111
|
// src/vm/types/context.ts
|
|
@@ -1122,8 +1142,9 @@ var DefaultVmContext = Object.freeze({
|
|
|
1122
1142
|
var _a;
|
|
1123
1143
|
_a = kVmContext;
|
|
1124
1144
|
var ValueVmContext = class {
|
|
1125
|
-
constructor(env) {
|
|
1145
|
+
constructor(env, describe) {
|
|
1126
1146
|
this.env = env;
|
|
1147
|
+
this.describe = describe;
|
|
1127
1148
|
this[_a] = true;
|
|
1128
1149
|
this.cachedKeys = null;
|
|
1129
1150
|
}
|
|
@@ -1144,9 +1165,10 @@ var ValueVmContext = class {
|
|
|
1144
1165
|
var _a2;
|
|
1145
1166
|
_a2 = kVmContext;
|
|
1146
1167
|
var FactoryVmContext = class {
|
|
1147
|
-
constructor(getter, enumerator) {
|
|
1168
|
+
constructor(getter, enumerator, describe) {
|
|
1148
1169
|
this.getter = getter;
|
|
1149
1170
|
this.enumerator = enumerator;
|
|
1171
|
+
this.describe = describe;
|
|
1150
1172
|
this[_a2] = true;
|
|
1151
1173
|
}
|
|
1152
1174
|
/** @inheritdoc */
|
|
@@ -1170,9 +1192,10 @@ function createVmContext(...args) {
|
|
|
1170
1192
|
return { ...DefaultVmContext };
|
|
1171
1193
|
}
|
|
1172
1194
|
if (typeof args[0] == "function") {
|
|
1173
|
-
|
|
1195
|
+
const [getter, enumerator, describer2] = args;
|
|
1196
|
+
return new FactoryVmContext(getter, enumerator ?? void 0, describer2 ?? void 0);
|
|
1174
1197
|
}
|
|
1175
|
-
const [vmValues, externValues] = args;
|
|
1198
|
+
const [vmValues, externValues, describer] = args;
|
|
1176
1199
|
const env = create(VmSharedContext);
|
|
1177
1200
|
if (vmValues) {
|
|
1178
1201
|
for (const [key, value] of entries(vmValues)) {
|
|
@@ -1185,7 +1208,7 @@ function createVmContext(...args) {
|
|
|
1185
1208
|
env[key] = value == null ? null : wrapToVmValue(value, null);
|
|
1186
1209
|
}
|
|
1187
1210
|
}
|
|
1188
|
-
return new ValueVmContext(env);
|
|
1211
|
+
return new ValueVmContext(env, describer ?? void 0);
|
|
1189
1212
|
}
|
|
1190
1213
|
function isVmContext(context) {
|
|
1191
1214
|
if (context == null || typeof context != "object") return false;
|
|
@@ -1359,11 +1382,7 @@ function map(data, mapper) {
|
|
|
1359
1382
|
Cp();
|
|
1360
1383
|
const ret = mapper(data[i] ?? null, i, data);
|
|
1361
1384
|
if (ret === void 0) continue;
|
|
1362
|
-
|
|
1363
|
-
result.push(ret);
|
|
1364
|
-
} else {
|
|
1365
|
-
result.push(null);
|
|
1366
|
-
}
|
|
1385
|
+
result.push(ret);
|
|
1367
1386
|
}
|
|
1368
1387
|
return result;
|
|
1369
1388
|
} else {
|
|
@@ -1372,11 +1391,7 @@ function map(data, mapper) {
|
|
|
1372
1391
|
Cp();
|
|
1373
1392
|
const ret = mapper(value ?? null, key, data);
|
|
1374
1393
|
if (ret === void 0) continue;
|
|
1375
|
-
|
|
1376
|
-
e.push([key, ret]);
|
|
1377
|
-
} else {
|
|
1378
|
-
e.push([key, null]);
|
|
1379
|
-
}
|
|
1394
|
+
e.push([key, ret]);
|
|
1380
1395
|
}
|
|
1381
1396
|
return fromEntries(e);
|
|
1382
1397
|
}
|
|
@@ -1425,7 +1440,7 @@ var hypot = VmLib(build(Math.hypot), {
|
|
|
1425
1440
|
var sum = VmLib(
|
|
1426
1441
|
(...values4) => {
|
|
1427
1442
|
const numbers = getNumbers(values4);
|
|
1428
|
-
return numbers.reduce((a, b) => a + b, 0);
|
|
1443
|
+
return numbers.reduce((a, b) => a + b, -0);
|
|
1429
1444
|
},
|
|
1430
1445
|
{
|
|
1431
1446
|
summary: "返回一组数的总和",
|
|
@@ -1783,40 +1798,123 @@ var shr = VmLib(
|
|
|
1783
1798
|
);
|
|
1784
1799
|
|
|
1785
1800
|
// src/vm/lib/global/sequence/with.ts
|
|
1801
|
+
var arrIndex = (index) => {
|
|
1802
|
+
const idx = Math.trunc($ToNumber(index));
|
|
1803
|
+
if (!isSafeInteger(idx) || idx < 0 || idx >= VM_ARRAY_MAX_LENGTH) {
|
|
1804
|
+
return -1;
|
|
1805
|
+
}
|
|
1806
|
+
return idx;
|
|
1807
|
+
};
|
|
1808
|
+
var withInner = (obj, key, keyIndex, value) => {
|
|
1809
|
+
if (keyIndex >= key.length) {
|
|
1810
|
+
return value;
|
|
1811
|
+
}
|
|
1812
|
+
const k = key[keyIndex];
|
|
1813
|
+
let result;
|
|
1814
|
+
if (isVmArray(obj)) {
|
|
1815
|
+
result = [...obj];
|
|
1816
|
+
} else if (isVmRecord(obj)) {
|
|
1817
|
+
result = { ...obj };
|
|
1818
|
+
} else if (arrIndex(k) === k) {
|
|
1819
|
+
result = [];
|
|
1820
|
+
} else {
|
|
1821
|
+
result = {};
|
|
1822
|
+
}
|
|
1823
|
+
if (isArray(result)) {
|
|
1824
|
+
const index = arrIndex(k);
|
|
1825
|
+
while (index > result.length) {
|
|
1826
|
+
result.push(null);
|
|
1827
|
+
}
|
|
1828
|
+
result[index] = withInner(result[index], key, keyIndex + 1, value);
|
|
1829
|
+
} else {
|
|
1830
|
+
const prop = $ToString(k);
|
|
1831
|
+
result[prop] = withInner(result[prop], key, keyIndex + 1, value);
|
|
1832
|
+
}
|
|
1833
|
+
return result;
|
|
1834
|
+
};
|
|
1835
|
+
var normalizeEntries = (data, entries3) => {
|
|
1836
|
+
if (entries3.length % 2 !== 0) {
|
|
1837
|
+
throwError("Expected even number of entries", data);
|
|
1838
|
+
}
|
|
1839
|
+
const entryData = /* @__PURE__ */ new Map();
|
|
1840
|
+
for (let i = 0; i < entries3.length; i += 2) {
|
|
1841
|
+
let key = entries3[i];
|
|
1842
|
+
expectConst("key", key, data);
|
|
1843
|
+
if (key == null) {
|
|
1844
|
+
continue;
|
|
1845
|
+
}
|
|
1846
|
+
if (isVmArray(key)) {
|
|
1847
|
+
if (key.length === 0 || key.includes(null) || key.includes(void 0)) {
|
|
1848
|
+
continue;
|
|
1849
|
+
} else if (key.length === 1) {
|
|
1850
|
+
key = key[0];
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
const value = entries3[i + 1];
|
|
1854
|
+
entryData.set(key, Element(value));
|
|
1855
|
+
}
|
|
1856
|
+
return entryData;
|
|
1857
|
+
};
|
|
1786
1858
|
var _with = VmLib(
|
|
1787
1859
|
(data, ...entries3) => {
|
|
1788
1860
|
expectArrayOrRecord("data", data, data);
|
|
1789
|
-
if (entries3.length
|
|
1790
|
-
|
|
1861
|
+
if (entries3.length === 0) {
|
|
1862
|
+
return data;
|
|
1791
1863
|
}
|
|
1864
|
+
const entryData = normalizeEntries(data, entries3);
|
|
1792
1865
|
if (isVmArray(data)) {
|
|
1793
1866
|
const result = [...data];
|
|
1794
|
-
for (
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1867
|
+
for (const [key, value] of entryData) {
|
|
1868
|
+
let index;
|
|
1869
|
+
let val;
|
|
1870
|
+
if (isVmArray(key)) {
|
|
1871
|
+
index = arrIndex(key[0]);
|
|
1872
|
+
if (index < 0) continue;
|
|
1873
|
+
val = withInner(result[index], key, 1, value);
|
|
1874
|
+
} else {
|
|
1875
|
+
index = arrIndex(key);
|
|
1876
|
+
if (index < 0) continue;
|
|
1877
|
+
val = value;
|
|
1878
|
+
}
|
|
1798
1879
|
while (index > result.length) {
|
|
1799
1880
|
result.push(null);
|
|
1800
1881
|
}
|
|
1801
|
-
result[index] =
|
|
1882
|
+
result[index] = val;
|
|
1802
1883
|
}
|
|
1803
1884
|
return result;
|
|
1804
1885
|
} else {
|
|
1805
1886
|
const result = { ...data };
|
|
1806
|
-
for (
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1887
|
+
for (const [key, value] of entryData) {
|
|
1888
|
+
let prop;
|
|
1889
|
+
let val;
|
|
1890
|
+
if (isVmArray(key)) {
|
|
1891
|
+
const firstKey = key[0];
|
|
1892
|
+
prop = $ToString(firstKey);
|
|
1893
|
+
val = withInner(result[prop], key, 1, value);
|
|
1894
|
+
} else {
|
|
1895
|
+
prop = $ToString(key);
|
|
1896
|
+
val = value;
|
|
1897
|
+
}
|
|
1898
|
+
result[prop] = val;
|
|
1810
1899
|
}
|
|
1811
1900
|
return result;
|
|
1812
1901
|
}
|
|
1813
1902
|
},
|
|
1814
1903
|
{
|
|
1815
1904
|
summary: "在数组或记录中设置多个键值对",
|
|
1816
|
-
params: {
|
|
1817
|
-
|
|
1905
|
+
params: {
|
|
1906
|
+
data: "要设置的数组或记录",
|
|
1907
|
+
"..entries": "要设置的键值对,成对出现"
|
|
1908
|
+
},
|
|
1909
|
+
paramsType: {
|
|
1910
|
+
data: "array | record",
|
|
1911
|
+
"..entries": `[..[string | number | (string | number)[], any][]]`
|
|
1912
|
+
},
|
|
1818
1913
|
returnsType: "type(data)",
|
|
1819
|
-
examples: [
|
|
1914
|
+
examples: [
|
|
1915
|
+
`with([10, 20], 2, 99, 3 ,100) // [10, 20, 99, 100]`,
|
|
1916
|
+
`(a: 1)::with(["b", 1], 2) // (a: 1, b: [nil, 2])`
|
|
1917
|
+
]
|
|
1820
1918
|
}
|
|
1821
1919
|
);
|
|
1822
1920
|
|
|
@@ -3307,113 +3405,6 @@ function serialize(value, options) {
|
|
|
3307
3405
|
return serializeImpl(value, 0, getSerializeOptions(options));
|
|
3308
3406
|
}
|
|
3309
3407
|
|
|
3310
|
-
// src/compiler/diagnostic.ts
|
|
3311
|
-
import { DiagnosticCode, wasm } from "@mirascript/wasm";
|
|
3312
|
-
var diagnosticMessages = /* @__PURE__ */ new Map();
|
|
3313
|
-
function getDiagnosticMessage(code) {
|
|
3314
|
-
if (!isSafeInteger(code) || code < 0 || code >= 65535) {
|
|
3315
|
-
throw new RangeError(`Invalid DiagnosticCode: ${code}`);
|
|
3316
|
-
}
|
|
3317
|
-
if (diagnosticMessages.has(code)) {
|
|
3318
|
-
return diagnosticMessages.get(code);
|
|
3319
|
-
}
|
|
3320
|
-
const msg = wasm.get_diagnostic_message(code);
|
|
3321
|
-
diagnosticMessages.set(code, msg);
|
|
3322
|
-
return msg;
|
|
3323
|
-
}
|
|
3324
|
-
function parseDiagnostics(source, diagnostics) {
|
|
3325
|
-
const parsed = [];
|
|
3326
|
-
const bufLen = diagnostics.length;
|
|
3327
|
-
for (let i = 0; i < bufLen; i += 5) {
|
|
3328
|
-
const startLineNumber = diagnostics[i];
|
|
3329
|
-
const startColumn = diagnostics[i + 1];
|
|
3330
|
-
const endLineNumber = diagnostics[i + 2];
|
|
3331
|
-
const endColumn = diagnostics[i + 3];
|
|
3332
|
-
const error = diagnostics[i + 4];
|
|
3333
|
-
parsed.push({
|
|
3334
|
-
code: error,
|
|
3335
|
-
range: {
|
|
3336
|
-
startLineNumber,
|
|
3337
|
-
startColumn,
|
|
3338
|
-
endLineNumber,
|
|
3339
|
-
endColumn
|
|
3340
|
-
}
|
|
3341
|
-
});
|
|
3342
|
-
}
|
|
3343
|
-
const _errors = [];
|
|
3344
|
-
const _warnings = [];
|
|
3345
|
-
const _infos = [];
|
|
3346
|
-
const _hints = [];
|
|
3347
|
-
const _tags = [];
|
|
3348
|
-
const _references = [];
|
|
3349
|
-
const _tagsReferences = [];
|
|
3350
|
-
for (let i = 0; i < parsed.length; i++) {
|
|
3351
|
-
const diagnostic = parsed[i];
|
|
3352
|
-
const { code } = diagnostic;
|
|
3353
|
-
if (code > DiagnosticCode.ErrorStart && code < DiagnosticCode.ErrorEnd) {
|
|
3354
|
-
_errors.push(diagnostic);
|
|
3355
|
-
} else if (code > DiagnosticCode.WarningStart && code < DiagnosticCode.WarningEnd) {
|
|
3356
|
-
_warnings.push(diagnostic);
|
|
3357
|
-
} else if (code > DiagnosticCode.InfoStart && code < DiagnosticCode.InfoEnd) {
|
|
3358
|
-
_infos.push(diagnostic);
|
|
3359
|
-
} else if (code > DiagnosticCode.HintStart && code < DiagnosticCode.HintEnd) {
|
|
3360
|
-
_hints.push(diagnostic);
|
|
3361
|
-
} else if (code > DiagnosticCode.TagStart && code < DiagnosticCode.TagEnd) {
|
|
3362
|
-
_tags.push(diagnostic);
|
|
3363
|
-
} else {
|
|
3364
|
-
continue;
|
|
3365
|
-
}
|
|
3366
|
-
diagnostic.references = [];
|
|
3367
|
-
while (i + 1 < parsed.length) {
|
|
3368
|
-
const ref = parsed[i + 1];
|
|
3369
|
-
let isRef = false;
|
|
3370
|
-
if (ref.code > DiagnosticCode.TagRefStart && ref.code < DiagnosticCode.TagRefEnd) {
|
|
3371
|
-
isRef = true;
|
|
3372
|
-
_tagsReferences.push(ref);
|
|
3373
|
-
}
|
|
3374
|
-
if (ref.code > DiagnosticCode.ReferenceStart && ref.code < DiagnosticCode.ReferenceEnd) {
|
|
3375
|
-
isRef = true;
|
|
3376
|
-
_references.push(ref);
|
|
3377
|
-
}
|
|
3378
|
-
if (!isRef) {
|
|
3379
|
-
break;
|
|
3380
|
-
}
|
|
3381
|
-
i++;
|
|
3382
|
-
ref.diagnostic = diagnostic;
|
|
3383
|
-
diagnostic.references.push(ref);
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
return {
|
|
3387
|
-
errors: _errors,
|
|
3388
|
-
warnings: _warnings,
|
|
3389
|
-
infos: _infos,
|
|
3390
|
-
hints: _hints,
|
|
3391
|
-
tags: _tags,
|
|
3392
|
-
references: _references,
|
|
3393
|
-
tagsReferences: _tagsReferences
|
|
3394
|
-
};
|
|
3395
|
-
}
|
|
3396
|
-
function formatRange(range) {
|
|
3397
|
-
if (range.startLineNumber === range.endLineNumber) {
|
|
3398
|
-
if (range.startColumn === range.endColumn) {
|
|
3399
|
-
return `${range.startLineNumber}:${range.startColumn}`;
|
|
3400
|
-
}
|
|
3401
|
-
return `${range.startLineNumber}:${range.startColumn}-${range.endColumn}`;
|
|
3402
|
-
}
|
|
3403
|
-
return `${range.startLineNumber}:${range.startColumn}-${range.endLineNumber}:${range.endColumn}`;
|
|
3404
|
-
}
|
|
3405
|
-
function formatDiagnostic(diagnostic) {
|
|
3406
|
-
const range = formatRange(diagnostic.range);
|
|
3407
|
-
const codeName = DiagnosticCode[diagnostic.code] || `Unknown(${diagnostic.code})`;
|
|
3408
|
-
let message = getDiagnosticMessage(diagnostic.code);
|
|
3409
|
-
for (const ref of diagnostic.references) {
|
|
3410
|
-
const refRange = formatRange(ref.range);
|
|
3411
|
-
message += `
|
|
3412
|
-
(${refRange}): ${getDiagnosticMessage(ref.code)}`;
|
|
3413
|
-
}
|
|
3414
|
-
return ` ${codeName}(${range}): ${message}`;
|
|
3415
|
-
}
|
|
3416
|
-
|
|
3417
3408
|
// src/vm/env.ts
|
|
3418
3409
|
var keys3 = [];
|
|
3419
3410
|
var values3 = [];
|
|
@@ -3567,10 +3558,15 @@ function emitScript(source, [code, diagnostics], options) {
|
|
|
3567
3558
|
if (!code) {
|
|
3568
3559
|
reportDiagnostic(source, diagnostics);
|
|
3569
3560
|
}
|
|
3570
|
-
const
|
|
3561
|
+
const sourcemaps = options.sourceMap ? parseDiagnostics(source, diagnostics, (c) => c === DiagnosticCode.SourceMap).sourcemaps : [];
|
|
3562
|
+
const target = emit(source, code, sourcemaps, options);
|
|
3571
3563
|
return createScript(source, target);
|
|
3572
3564
|
}
|
|
3573
3565
|
async function compile(source, options = {}) {
|
|
3566
|
+
if (options.sourceMap) {
|
|
3567
|
+
options.diagnostic_sourcemap = true;
|
|
3568
|
+
options.diagnostic_position_encoding ??= "Utf16";
|
|
3569
|
+
}
|
|
3574
3570
|
if (typeof source == "string") {
|
|
3575
3571
|
const result = compileFast(source, options);
|
|
3576
3572
|
if (result) return result;
|
|
@@ -3596,6 +3592,7 @@ function compileSync(source, options = {}) {
|
|
|
3596
3592
|
|
|
3597
3593
|
export {
|
|
3598
3594
|
VmError,
|
|
3595
|
+
isVmWrapper,
|
|
3599
3596
|
operations_exports,
|
|
3600
3597
|
VmSharedContext,
|
|
3601
3598
|
defineVmContextValue,
|
|
@@ -3611,7 +3608,9 @@ export {
|
|
|
3611
3608
|
wrapToVmValue,
|
|
3612
3609
|
unwrapFromVmValue,
|
|
3613
3610
|
VmExtern,
|
|
3611
|
+
isVmExtern,
|
|
3614
3612
|
VmModule,
|
|
3613
|
+
isVmModule,
|
|
3615
3614
|
isVmScript,
|
|
3616
3615
|
isVmConst,
|
|
3617
3616
|
isVmImmutable,
|
|
@@ -3620,15 +3619,9 @@ export {
|
|
|
3620
3619
|
isVmArray,
|
|
3621
3620
|
isVmRecord,
|
|
3622
3621
|
isVmPrimitive,
|
|
3623
|
-
isVmExtern,
|
|
3624
3622
|
isVmCallable,
|
|
3625
|
-
isVmModule,
|
|
3626
3623
|
VM_ARRAY_MAX_LENGTH,
|
|
3627
3624
|
constants_exports,
|
|
3628
|
-
DiagnosticCode,
|
|
3629
|
-
getDiagnosticMessage,
|
|
3630
|
-
parseDiagnostics,
|
|
3631
|
-
formatDiagnostic,
|
|
3632
3625
|
emitScript,
|
|
3633
3626
|
compile,
|
|
3634
3627
|
compileSync,
|
|
@@ -3636,6 +3629,11 @@ export {
|
|
|
3636
3629
|
lib,
|
|
3637
3630
|
serializeString,
|
|
3638
3631
|
serializePropName,
|
|
3632
|
+
serializeNil,
|
|
3633
|
+
serializeBoolean,
|
|
3634
|
+
serializeNumber,
|
|
3635
|
+
serializeArray,
|
|
3636
|
+
serializeRecord,
|
|
3639
3637
|
serialize
|
|
3640
3638
|
};
|
|
3641
|
-
//# sourceMappingURL=chunk-
|
|
3639
|
+
//# sourceMappingURL=chunk-RYSPVMVZ.js.map
|