@mirascript/mirascript 0.1.16 → 0.1.18

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.
Files changed (115) hide show
  1. package/dist/{chunk-LU4ZKFF6.js → chunk-3BAOZ2P2.js} +203 -62
  2. package/dist/chunk-3BAOZ2P2.js.map +6 -0
  3. package/dist/{chunk-YZGL3D7L.js → chunk-5AEWM4W6.js} +41 -95
  4. package/dist/chunk-5AEWM4W6.js.map +6 -0
  5. package/dist/cli/execute.d.ts.map +1 -1
  6. package/dist/cli/index.js +11 -12
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/compiler/diagnostic.d.ts.map +1 -1
  9. package/dist/compiler/emit/sourcemap.d.ts.map +1 -1
  10. package/dist/compiler/worker.js +1 -1
  11. package/dist/helpers/convert/index.d.ts +5 -0
  12. package/dist/helpers/convert/index.d.ts.map +1 -0
  13. package/dist/helpers/convert/to-boolean.d.ts +4 -0
  14. package/dist/helpers/convert/to-boolean.d.ts.map +1 -0
  15. package/dist/helpers/convert/to-format.d.ts +4 -0
  16. package/dist/helpers/convert/to-format.d.ts.map +1 -0
  17. package/dist/helpers/convert/to-number.d.ts +4 -0
  18. package/dist/helpers/convert/to-number.d.ts.map +1 -0
  19. package/dist/helpers/convert/to-string.d.ts +6 -0
  20. package/dist/helpers/convert/to-string.d.ts.map +1 -0
  21. package/dist/helpers/serialize.d.ts.map +1 -1
  22. package/dist/index.js +2 -2
  23. package/dist/subtle.d.ts +2 -2
  24. package/dist/subtle.d.ts.map +1 -1
  25. package/dist/subtle.js +3 -5
  26. package/dist/vm/checkpoint.d.ts.map +1 -1
  27. package/dist/vm/helpers.d.ts.map +1 -1
  28. package/dist/vm/lib/global/bit.d.ts +7 -7
  29. package/dist/vm/lib/global/bit.d.ts.map +1 -1
  30. package/dist/vm/lib/global/debug.d.ts +17 -1
  31. package/dist/vm/lib/global/debug.d.ts.map +1 -1
  32. package/dist/vm/lib/global/json.d.ts +2 -2
  33. package/dist/vm/lib/global/json.d.ts.map +1 -1
  34. package/dist/vm/lib/global/math-additional.d.ts +1 -1
  35. package/dist/vm/lib/global/math-additional.d.ts.map +1 -1
  36. package/dist/vm/lib/global/math-arr.d.ts +5 -5
  37. package/dist/vm/lib/global/math-arr.d.ts.map +1 -1
  38. package/dist/vm/lib/global/math-unary.d.ts +26 -26
  39. package/dist/vm/lib/global/math-unary.d.ts.map +1 -1
  40. package/dist/vm/lib/global/math.d.ts +3 -3
  41. package/dist/vm/lib/global/math.d.ts.map +1 -1
  42. package/dist/vm/lib/global/sequence/all-any.d.ts +2 -2
  43. package/dist/vm/lib/global/sequence/all-any.d.ts.map +1 -1
  44. package/dist/vm/lib/global/sequence/entries.d.ts +3 -3
  45. package/dist/vm/lib/global/sequence/entries.d.ts.map +1 -1
  46. package/dist/vm/lib/global/sequence/find.d.ts +1 -1
  47. package/dist/vm/lib/global/sequence/find.d.ts.map +1 -1
  48. package/dist/vm/lib/global/sequence/flatten.d.ts +1 -1
  49. package/dist/vm/lib/global/sequence/flatten.d.ts.map +1 -1
  50. package/dist/vm/lib/global/sequence/len.d.ts +1 -1
  51. package/dist/vm/lib/global/sequence/len.d.ts.map +1 -1
  52. package/dist/vm/lib/global/sequence/map-filter.d.ts +3 -3
  53. package/dist/vm/lib/global/sequence/map-filter.d.ts.map +1 -1
  54. package/dist/vm/lib/global/sequence/repeat.d.ts +1 -1
  55. package/dist/vm/lib/global/sequence/repeat.d.ts.map +1 -1
  56. package/dist/vm/lib/global/sequence/reverse.d.ts +1 -1
  57. package/dist/vm/lib/global/sequence/reverse.d.ts.map +1 -1
  58. package/dist/vm/lib/global/sequence/sort.d.ts +2 -2
  59. package/dist/vm/lib/global/sequence/sort.d.ts.map +1 -1
  60. package/dist/vm/lib/global/sequence/with.d.ts +1 -1
  61. package/dist/vm/lib/global/sequence/with.d.ts.map +1 -1
  62. package/dist/vm/lib/global/sequence/zip.d.ts +1 -1
  63. package/dist/vm/lib/global/sequence/zip.d.ts.map +1 -1
  64. package/dist/vm/lib/global/string.d.ts +10 -10
  65. package/dist/vm/lib/global/string.d.ts.map +1 -1
  66. package/dist/vm/lib/global/time.d.ts +3 -3
  67. package/dist/vm/lib/global/time.d.ts.map +1 -1
  68. package/dist/vm/lib/global/to-primitive.d.ts +4 -4
  69. package/dist/vm/lib/global/to-primitive.d.ts.map +1 -1
  70. package/dist/vm/lib/helpers.d.ts +4 -2
  71. package/dist/vm/lib/helpers.d.ts.map +1 -1
  72. package/dist/vm/lib/index.d.ts +1 -1
  73. package/dist/vm/lib/index.d.ts.map +1 -1
  74. package/dist/vm/lib/mod/matrix.d.ts +13 -13
  75. package/dist/vm/lib/mod/matrix.d.ts.map +1 -1
  76. package/dist/vm/operations.d.ts.map +1 -1
  77. package/dist/vm/types/context.d.ts +3 -17
  78. package/dist/vm/types/context.d.ts.map +1 -1
  79. package/dist/vm/types/index.d.ts +1 -1
  80. package/dist/vm/types/index.d.ts.map +1 -1
  81. package/package.json +2 -2
  82. package/src/cli/execute.ts +10 -10
  83. package/src/compiler/diagnostic.ts +29 -11
  84. package/src/compiler/emit/globals.ts +1 -1
  85. package/src/compiler/emit/sourcemap.ts +8 -3
  86. package/src/helpers/convert/index.ts +4 -0
  87. package/src/helpers/convert/to-boolean.ts +12 -0
  88. package/src/helpers/convert/to-format.ts +37 -0
  89. package/src/helpers/convert/to-number.ts +35 -0
  90. package/src/helpers/convert/to-string.ts +55 -0
  91. package/src/helpers/serialize.ts +1 -0
  92. package/src/subtle.ts +2 -2
  93. package/src/vm/checkpoint.ts +19 -10
  94. package/src/vm/helpers.ts +1 -1
  95. package/src/vm/lib/global/debug.ts +84 -7
  96. package/src/vm/lib/global/json.ts +3 -4
  97. package/src/vm/lib/global/sequence/all-any.ts +1 -1
  98. package/src/vm/lib/global/sequence/find.ts +1 -1
  99. package/src/vm/lib/global/sequence/map-filter.ts +1 -1
  100. package/src/vm/lib/global/sequence/sort.ts +1 -1
  101. package/src/vm/lib/global/sequence/with.ts +1 -1
  102. package/src/vm/lib/global/time.ts +1 -1
  103. package/src/vm/lib/global/to-primitive.ts +1 -1
  104. package/src/vm/lib/helpers.ts +5 -4
  105. package/src/vm/lib/index.ts +4 -4
  106. package/src/vm/lib/mod/matrix.ts +1 -1
  107. package/src/vm/operations.ts +11 -12
  108. package/src/vm/types/context.ts +26 -38
  109. package/src/vm/types/extern.ts +1 -1
  110. package/src/vm/types/index.ts +1 -1
  111. package/dist/chunk-LU4ZKFF6.js.map +0 -6
  112. package/dist/chunk-YZGL3D7L.js.map +0 -6
  113. package/dist/helpers/convert.d.ts +0 -12
  114. package/dist/helpers/convert.d.ts.map +0 -1
  115. package/src/helpers/convert.ts +0 -128
@@ -43,12 +43,88 @@ import {
43
43
  kVmWrapper,
44
44
  keys,
45
45
  parseDiagnostics,
46
- toBoolean,
47
- toFormat,
48
- toNumber,
49
46
  toString,
50
47
  values
51
- } from "./chunk-YZGL3D7L.js";
48
+ } from "./chunk-5AEWM4W6.js";
49
+
50
+ // src/helpers/convert/index.ts
51
+ var convert_exports = {};
52
+ __export(convert_exports, {
53
+ toBoolean: () => toBoolean,
54
+ toFormat: () => toFormat,
55
+ toNumber: () => toNumber,
56
+ toString: () => toString
57
+ });
58
+
59
+ // src/helpers/convert/to-number.ts
60
+ var { POSITIVE_INFINITY, NEGATIVE_INFINITY } = Number;
61
+ function toNumber(value, fallback) {
62
+ if (typeof value === "number") {
63
+ return value;
64
+ }
65
+ if (typeof value == "boolean") {
66
+ return value ? 1 : 0;
67
+ }
68
+ if (typeof value == "string") {
69
+ value = value.trim();
70
+ if (value !== "") {
71
+ if (value === "inf" || value === "+inf" || value === "Infinity" || value === "+Infinity") {
72
+ return POSITIVE_INFINITY;
73
+ }
74
+ if (value === "-inf" || value === "-Infinity") {
75
+ return NEGATIVE_INFINITY;
76
+ }
77
+ if (value === "nan" || value === "NaN") {
78
+ return Number.NaN;
79
+ }
80
+ const num2 = Number(value);
81
+ if (!isNaN(num2)) return num2;
82
+ }
83
+ }
84
+ if (fallback === void 0) {
85
+ throw new VmError(`Failed to convert value to number: ${display(value)}`, Number.NaN);
86
+ }
87
+ return fallback;
88
+ }
89
+
90
+ // src/helpers/convert/to-format.ts
91
+ function formatNumber(value) {
92
+ if (!isFinite(value)) return toString(value, void 0);
93
+ if (value === 0) return "0";
94
+ const s = value.toString();
95
+ let ps;
96
+ const abs3 = Math.abs(value);
97
+ if (abs3 >= 1e3 || abs3 < 1e-3) {
98
+ const ps1 = value.toExponential();
99
+ const ps2 = value.toExponential(5);
100
+ ps = ps1.length < ps2.length ? ps1 : ps2;
101
+ } else {
102
+ ps = value.toPrecision(6);
103
+ }
104
+ return ps.length < s.length ? ps : s;
105
+ }
106
+ function toFormat(value, format2) {
107
+ const f = format2 == null ? "" : format2.trim();
108
+ if (typeof value == "number") {
109
+ if (/^\.\d+$/.test(f)) {
110
+ let digits = Math.trunc(Number(f.slice(1)));
111
+ if (!(digits <= 100)) digits = 100;
112
+ return value.toFixed(digits);
113
+ } else {
114
+ return formatNumber(value);
115
+ }
116
+ }
117
+ return toString(value, void 0);
118
+ }
119
+
120
+ // src/helpers/convert/to-boolean.ts
121
+ function toBoolean(value, fallback) {
122
+ if (typeof value === "boolean") return value;
123
+ if (fallback === void 0) {
124
+ throw new VmError(`Failed to convert value to boolean: ${display(value)}`, false);
125
+ }
126
+ return fallback;
127
+ }
52
128
 
53
129
  // src/vm/operations.ts
54
130
  var operations_exports = {};
@@ -274,10 +350,8 @@ var $Length = (value) => {
274
350
  $AssertInit(value);
275
351
  if (isVmArray(value)) return value.length;
276
352
  if (isVmRecord(value)) return keys(value).length;
277
- if (isVmWrapper(value)) {
278
- return value.keys().length;
279
- }
280
- return Number.NaN;
353
+ if (isVmWrapper(value)) return value.keys().length;
354
+ throw new VmError(`Value has no length: ${display(value)}`, 0);
281
355
  };
282
356
  var $Omit = (value, omitted) => {
283
357
  $AssertInit(value);
@@ -320,14 +394,14 @@ var sliceCore = (value, start, end, exclusive) => {
320
394
  };
321
395
  var $Slice = (value, start, end) => {
322
396
  $AssertInit(value);
323
- if (!isVmArray(value)) throw new VmError(`Expected array, got ${$Type(value)}`, []);
397
+ if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
324
398
  const s = start != null ? $ToNumber(start) : 0;
325
399
  const e = end != null ? $ToNumber(end) : value.length - 1;
326
400
  return sliceCore(value, s, e, false);
327
401
  };
328
402
  var $SliceExclusive = (value, start, end) => {
329
403
  $AssertInit(value);
330
- if (!isVmArray(value)) throw new VmError(`Expected array, got ${$Type(value)}`, []);
404
+ if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
331
405
  const s = start != null ? $ToNumber(start) : 0;
332
406
  const e = end != null ? $ToNumber(end) : value.length;
333
407
  return sliceCore(value, s, e, true);
@@ -392,7 +466,7 @@ var $IsArray = (value) => {
392
466
  var $AssertNonNil = (value) => {
393
467
  $AssertInit(value);
394
468
  if (value !== null) return;
395
- throw new VmError("Expected non-nil value", null);
469
+ throw new VmError(`Expected non-nil value`, null);
396
470
  };
397
471
  var $Has = (obj, key) => {
398
472
  $AssertInit(obj);
@@ -419,7 +493,7 @@ var $Set = (obj, key, value) => {
419
493
  $AssertInit(value);
420
494
  const pk = $ToString(key);
421
495
  if (obj == null) return;
422
- if (!isVmExtern(obj)) throw new VmError(`Expected extern, got ${$Type(obj)}`, void 0);
496
+ if (!isVmExtern(obj)) throw new VmError(`Expected extern, got ${display(obj)}`, void 0);
423
497
  obj.set(pk, value);
424
498
  };
425
499
  var $Iterable = (value) => {
@@ -427,7 +501,7 @@ var $Iterable = (value) => {
427
501
  if (isVmWrapper(value)) return value.keys();
428
502
  if (isVmArray(value)) return value;
429
503
  if (value != null && typeof value == "object") return keys(value);
430
- throw new VmError(`Value is not iterable`, isVmFunction(value) ? [] : [value]);
504
+ throw new VmError(`Value is not iterable: ${display(value)}`, isVmFunction(value) ? [] : [value]);
431
505
  };
432
506
  var $RecordSpread = (record) => {
433
507
  $AssertInit(record);
@@ -451,7 +525,7 @@ var $RecordSpread = (record) => {
451
525
  }
452
526
  return result;
453
527
  }
454
- throw new VmError(`Expected record, array, extern or nil, got ${$Type(record)}`, null);
528
+ throw new VmError(`Expected record, array, extern or nil, got ${display(record)}`, null);
455
529
  };
456
530
  var $ArraySpread = (array) => {
457
531
  $AssertInit(array);
@@ -468,7 +542,7 @@ var $ArraySpread = (array) => {
468
542
  }
469
543
  return result;
470
544
  }
471
- throw new VmError(`Expected array, iterable extern or nil, got ${$Type(array)}`, []);
545
+ throw new VmError(`Expected array, iterable extern or nil, got ${display(array)}`, []);
472
546
  };
473
547
  var $Format = (value, format2) => {
474
548
  $AssertInit(value);
@@ -699,21 +773,26 @@ var VmExtern = class extends VmWrapper {
699
773
  Object.defineProperty(VmExtern.prototype, kVmExtern, { value: true });
700
774
 
701
775
  // src/vm/checkpoint.ts
776
+ var { now } = Date;
777
+ var TIME_ORIGIN = now() - 1e3 * 3600 * 24;
778
+ var timestamp = () => now() - TIME_ORIGIN;
702
779
  var MAX_DEPTH = 128;
780
+ var CP_UNSET = -1;
781
+ var CP_DEFAULT_TIMEOUT = 100;
703
782
  var cpDepth = 0;
704
- var cp = Number.NaN;
705
- var cpTimeout = 100;
783
+ var cp = CP_UNSET;
784
+ var cpTimeout = CP_DEFAULT_TIMEOUT;
706
785
  function Cp() {
707
- if (!cp) {
708
- cp = Date.now();
709
- } else if (Date.now() - cp > cpTimeout) {
786
+ if (cp === CP_UNSET) {
787
+ cp = timestamp();
788
+ } else if (timestamp() - cp > cpTimeout) {
710
789
  throw new RangeError("Execution timeout");
711
790
  }
712
791
  }
713
792
  function CpEnter() {
714
793
  cpDepth++;
715
794
  if (cpDepth <= 1) {
716
- cp = Date.now();
795
+ cp = timestamp();
717
796
  cpDepth = 1;
718
797
  } else if (cpDepth > MAX_DEPTH) {
719
798
  throw new RangeError("Maximum call depth exceeded");
@@ -724,17 +803,17 @@ function CpEnter() {
724
803
  function CpExit() {
725
804
  cpDepth--;
726
805
  if (cpDepth < 1) {
727
- cp = Number.NaN;
806
+ cp = CP_UNSET;
728
807
  cpDepth = 0;
729
808
  } else {
730
809
  Cp();
731
810
  }
732
811
  }
733
- function configCheckpoint(timeout = 100) {
734
- if (typeof timeout !== "number" || timeout <= 0 || Number.isNaN(timeout)) {
812
+ function configCheckpoint(timeout = CP_DEFAULT_TIMEOUT) {
813
+ if (typeof timeout !== "number" || timeout <= 0 || isNaN(timeout)) {
735
814
  throw new RangeError("Invalid timeout value");
736
815
  }
737
- cpTimeout = timeout;
816
+ cpTimeout = Math.ceil(timeout);
738
817
  }
739
818
 
740
819
  // src/vm/types/function.ts
@@ -775,13 +854,14 @@ function VmFunction(fn, option = {}) {
775
854
  }
776
855
 
777
856
  // src/vm/types/context.ts
778
- var VmSharedContext = create(null);
779
- var VmSharedContextKeys = null;
857
+ var { freeze } = Object;
858
+ var VM_SHARED_CONTEXT = create(null);
859
+ var VM_SHARED_CONTEXT_KEYS = null;
780
860
  function globalVarNotFound(name) {
781
861
  throw new VmError(`Global variable '${name}' is not defined.`, null);
782
862
  }
783
863
  function defineVmContextValue(name, value, override = false) {
784
- if (!override && name in VmSharedContext) throw new Error(`Global variable '${name}' is already defined.`);
864
+ if (!override && name in VM_SHARED_CONTEXT) throw new Error(`Global variable '${name}' is already defined.`);
785
865
  let v;
786
866
  if (typeof value == "function") {
787
867
  v = VmFunction(value, {
@@ -791,25 +871,25 @@ function defineVmContextValue(name, value, override = false) {
791
871
  } else {
792
872
  v = value;
793
873
  }
794
- VmSharedContext[name] = v ?? null;
795
- VmSharedContextKeys = null;
874
+ VM_SHARED_CONTEXT[name] = v ?? null;
875
+ VM_SHARED_CONTEXT_KEYS = null;
796
876
  }
797
- var DefaultVmContext = Object.freeze({
877
+ var DefaultVmContext = freeze({
798
878
  [kVmContext]: true,
799
879
  /** @inheritdoc */
800
880
  keys() {
801
- VmSharedContextKeys ??= Object.freeze(keys(VmSharedContext));
802
- return VmSharedContextKeys;
881
+ VM_SHARED_CONTEXT_KEYS ??= freeze(keys(VM_SHARED_CONTEXT));
882
+ return VM_SHARED_CONTEXT_KEYS;
803
883
  },
804
884
  /** @inheritdoc */
805
885
  get(key) {
806
- const val = VmSharedContext[key];
886
+ const val = VM_SHARED_CONTEXT[key];
807
887
  if (val === void 0) globalVarNotFound(key);
808
888
  return val;
809
889
  },
810
890
  /** @inheritdoc */
811
891
  has(key) {
812
- return key in VmSharedContext;
892
+ return key in VM_SHARED_CONTEXT;
813
893
  }
814
894
  });
815
895
  var _a;
@@ -823,8 +903,12 @@ var ValueVmContext = class {
823
903
  }
824
904
  /** @inheritdoc */
825
905
  keys() {
826
- this.cachedKeys ??= keys(this.env);
827
- return [...this.cachedKeys, ...DefaultVmContext.keys()];
906
+ const defaultKeys = DefaultVmContext.keys();
907
+ if (this.cachedKeys?.[0] !== defaultKeys) {
908
+ const allKeys = freeze([...keys(this.env), ...defaultKeys]);
909
+ this.cachedKeys = freeze([defaultKeys, allKeys]);
910
+ }
911
+ return this.cachedKeys[1];
828
912
  }
829
913
  /** @inheritdoc */
830
914
  get(key) {
@@ -849,7 +933,7 @@ var FactoryVmContext = class {
849
933
  /** @inheritdoc */
850
934
  keys() {
851
935
  if (!this.enumerator) return DefaultVmContext.keys();
852
- return [...this.enumerator(), ...DefaultVmContext.keys()];
936
+ return freeze([...this.enumerator(), ...DefaultVmContext.keys()]);
853
937
  }
854
938
  /** @inheritdoc */
855
939
  get(key) {
@@ -871,7 +955,7 @@ function createVmContext(...args) {
871
955
  return new FactoryVmContext(getter, enumerator ?? void 0, describer2 ?? void 0);
872
956
  }
873
957
  const [vmValues, externValues, describer] = args;
874
- const env = create(VmSharedContext);
958
+ const env = create(VM_SHARED_CONTEXT);
875
959
  if (vmValues) {
876
960
  for (const [key, value] of entries(vmValues)) {
877
961
  if (!isVmAny(value, false)) continue;
@@ -2390,9 +2474,63 @@ var repeat = VmLib(
2390
2474
 
2391
2475
  // src/vm/lib/global/debug.ts
2392
2476
  import supportsColor from "supports-color";
2477
+ function defaultSerializer(arg, format2) {
2478
+ return null;
2479
+ }
2480
+ function serializeValue(arg, format2, serializer) {
2481
+ if (serializer == null || serializer === defaultSerializer) {
2482
+ return defaultSerializer(arg, format2);
2483
+ }
2484
+ try {
2485
+ return serializer(arg, format2);
2486
+ } catch {
2487
+ return defaultSerializer(arg, format2);
2488
+ }
2489
+ }
2393
2490
  var debug_print = VmLib(
2394
2491
  (...args) => {
2395
- console.log(...debug_print.prefix, ...args);
2492
+ const { serializer } = debug_print;
2493
+ if (args.length <= 1 || typeof args[0] != "string" || !args[0].includes("%")) {
2494
+ console.log(...debug_print.prefix, ...args.map((v) => serializeValue(v, "", serializer) ?? v));
2495
+ return;
2496
+ }
2497
+ const [prefix, ...additional] = debug_print.prefix;
2498
+ const [arg0, ...argsRest] = args;
2499
+ const format2 = `${prefix || ""} ${arg0}`;
2500
+ const values4 = [...additional, ...argsRest];
2501
+ const parts = format2.split(/(%[%\w])/g);
2502
+ const messageToConsole = [];
2503
+ const valuesToConsole = [];
2504
+ let valIndex = 0;
2505
+ for (let i = 0; i < parts.length; i++) {
2506
+ if (i % 2 === 0) {
2507
+ messageToConsole.push(parts[i]);
2508
+ continue;
2509
+ }
2510
+ const specifier = parts[i];
2511
+ if (specifier === "%%") {
2512
+ messageToConsole.push("%");
2513
+ } else {
2514
+ if (valIndex >= values4.length) {
2515
+ messageToConsole.push(specifier);
2516
+ continue;
2517
+ }
2518
+ const arg = values4[valIndex++];
2519
+ const f = serializeValue(arg, specifier, serializer);
2520
+ if (f != null) {
2521
+ messageToConsole.push("%s");
2522
+ valuesToConsole.push(f);
2523
+ } else {
2524
+ messageToConsole.push(specifier);
2525
+ valuesToConsole.push(arg);
2526
+ }
2527
+ }
2528
+ }
2529
+ if (valIndex < values4.length) {
2530
+ const remaining = values4.slice(valIndex);
2531
+ valuesToConsole.push(...remaining.map((v) => serializeValue(v, "", serializer) ?? v));
2532
+ }
2533
+ console.log(messageToConsole.join(""), ...valuesToConsole);
2396
2534
  },
2397
2535
  {
2398
2536
  summary: "打印调试信息到控制台",
@@ -2402,13 +2540,14 @@ var debug_print = VmLib(
2402
2540
  examples: ['debug_print("value:", 42);']
2403
2541
  },
2404
2542
  {
2405
- prefix: ["MiraScript"]
2543
+ prefix: ["MiraScript"],
2544
+ serializer: defaultSerializer
2406
2545
  }
2407
2546
  );
2408
2547
  var panic = VmLib(
2409
2548
  (message) => {
2410
2549
  if (message === void 0) console.error(...panic.prefix);
2411
- else console.error(...panic.prefix, message);
2550
+ else console.error(...panic.prefix, serializeValue(message, "", panic.serializer));
2412
2551
  const mgsStr = toString(message, null);
2413
2552
  const error = !mgsStr ? "panic" : "panic: " + mgsStr;
2414
2553
  throw new VmError(error, void 0);
@@ -2421,14 +2560,16 @@ var panic = VmLib(
2421
2560
  examples: ['panic("boom");']
2422
2561
  },
2423
2562
  {
2424
- prefix: ["MiraScript"]
2563
+ prefix: ["MiraScript"],
2564
+ serializer: defaultSerializer
2425
2565
  }
2426
2566
  );
2427
2567
  if (typeof location != "undefined") {
2428
- const badge = "%cMiraScript";
2568
+ const badge = "%cMiraScript%c";
2429
2569
  const common = "display: inline-block; padding: 1px 4px; border-radius: 3px;";
2430
- debug_print.prefix = [badge, `${common} background: #007acc; color: #fff;`];
2431
- panic.prefix = [badge, `${common} background: #d23d3d; color: #fff;`];
2570
+ const reset = "";
2571
+ debug_print.prefix = [badge, `${common} background: #007acc; color: #fff;`, reset];
2572
+ panic.prefix = [badge, `${common} background: #d23d3d; color: #fff;`, reset];
2432
2573
  } else {
2433
2574
  if (supportsColor.stdout) {
2434
2575
  debug_print.prefix = ["\x1B[44;37m MiraScript \x1B[0m"];
@@ -2463,10 +2604,9 @@ var to_json = VmLib(
2463
2604
  );
2464
2605
  var from_json = VmLib(
2465
2606
  (json, fallback) => {
2466
- required("json", json, null);
2467
- if (typeof json != "string") return json;
2607
+ const j = expectString("json", json);
2468
2608
  try {
2469
- return parse(json);
2609
+ return parse(j);
2470
2610
  } catch (ex) {
2471
2611
  if (fallback !== void 0) return fallback;
2472
2612
  rethrowError("Invalid JSON", ex, null);
@@ -2703,9 +2843,9 @@ var getTimestamp = (datetime, fallback) => {
2703
2843
  };
2704
2844
  var to_timestamp = VmLib(
2705
2845
  (datetime, fallback) => {
2706
- const timestamp = getTimestamp(datetime, fallback !== void 0);
2707
- if (timestamp == null) return fallback;
2708
- return timestamp;
2846
+ const timestamp2 = getTimestamp(datetime, fallback !== void 0);
2847
+ if (timestamp2 == null) return fallback;
2848
+ return timestamp2;
2709
2849
  },
2710
2850
  {
2711
2851
  summary: "将数据转换为 Unix 毫秒时间戳",
@@ -2720,10 +2860,10 @@ var to_timestamp = VmLib(
2720
2860
  );
2721
2861
  var to_datetime = VmLib(
2722
2862
  (datetime, offset, fallback) => {
2723
- const timestamp = getTimestamp(datetime, fallback !== void 0);
2724
- if (timestamp == null) return fallback;
2863
+ const timestamp2 = getTimestamp(datetime, fallback !== void 0);
2864
+ if (timestamp2 == null) return fallback;
2725
2865
  const o = expectNumberRange("offset", offset ?? 0, -24, 24);
2726
- const dateOffset = new Date(timestamp + o * 1e3 * 60 * 60);
2866
+ const dateOffset = new Date(timestamp2 + o * 1e3 * 60 * 60);
2727
2867
  return {
2728
2868
  year: dateOffset.getUTCFullYear(),
2729
2869
  month: dateOffset.getUTCMonth() + 1,
@@ -2759,9 +2899,9 @@ to_datetime(0)
2759
2899
  );
2760
2900
  var to_iso8601 = VmLib(
2761
2901
  (datetime, fallback) => {
2762
- const timestamp = getTimestamp(datetime, fallback !== void 0);
2763
- if (timestamp == null) return fallback;
2764
- return new Date(timestamp).toISOString();
2902
+ const timestamp2 = getTimestamp(datetime, fallback !== void 0);
2903
+ if (timestamp2 == null) return fallback;
2904
+ return new Date(timestamp2).toISOString();
2765
2905
  },
2766
2906
  {
2767
2907
  summary: "将数据转换为 ISO 8601 格式的字符串",
@@ -3308,22 +3448,22 @@ function createModule(name, lib2) {
3308
3448
 
3309
3449
  // src/vm/lib/index.ts
3310
3450
  for (const [name, value] of entries(global_exports)) {
3311
- VmSharedContext[name] = wrapEntry(name, value, "global");
3451
+ VM_SHARED_CONTEXT[name] = wrapEntry(name, value, "global");
3312
3452
  }
3313
3453
  for (const [name, value] of entries(mod_exports)) {
3314
3454
  const mod = createModule(name, value);
3315
- VmSharedContext[name] = wrapEntry(name, mod, "global");
3455
+ VM_SHARED_CONTEXT[name] = wrapEntry(name, mod, "global");
3316
3456
  }
3317
3457
  var lib = Object.freeze(Object.assign(create(null), global_exports, mod_exports));
3318
3458
 
3319
3459
  export {
3460
+ convert_exports,
3320
3461
  operations_exports,
3321
3462
  VmExtern,
3322
3463
  wrapToVmValue,
3323
3464
  unwrapFromVmValue,
3324
3465
  configCheckpoint,
3325
3466
  VmFunction,
3326
- VmSharedContext,
3327
3467
  defineVmContextValue,
3328
3468
  DefaultVmContext,
3329
3469
  createVmContext,
@@ -3332,6 +3472,7 @@ export {
3332
3472
  compileSync,
3333
3473
  VmModule,
3334
3474
  debug_print,
3475
+ panic,
3335
3476
  lib
3336
3477
  };
3337
- //# sourceMappingURL=chunk-LU4ZKFF6.js.map
3478
+ //# sourceMappingURL=chunk-3BAOZ2P2.js.map