@mirascript/mirascript 0.1.33 → 0.1.35
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-UM7PQV4L.js → chunk-C6YXWSTI.js} +205 -156
- package/dist/chunk-C6YXWSTI.js.map +6 -0
- package/dist/{chunk-BMSHG7ON.js → chunk-HGARNCSR.js} +2 -2
- package/dist/{chunk-NRUNNMNC.js → chunk-PYMZMMRB.js} +18 -20
- package/dist/chunk-PYMZMMRB.js.map +6 -0
- package/dist/{chunk-VZGKLLRC.js → chunk-SEZII6RI.js} +19 -7
- package/dist/chunk-SEZII6RI.js.map +6 -0
- package/dist/cli/index.js +4 -4
- package/dist/compiler/compile-fast.d.ts.map +1 -1
- package/dist/compiler/create-script.d.ts +1 -1
- package/dist/compiler/create-script.d.ts.map +1 -1
- package/dist/compiler/emit/constants.d.ts +1 -1
- package/dist/compiler/emit/constants.d.ts.map +1 -1
- package/dist/compiler/worker.js +1 -1
- package/dist/helpers/serialize.d.ts +5 -4
- package/dist/helpers/serialize.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/subtle.js +3 -3
- package/dist/vm/lib/global/debug.d.ts +1 -1
- package/dist/vm/lib/global/debug.d.ts.map +1 -1
- package/dist/vm/lib/global/math-const.d.ts +6 -0
- package/dist/vm/lib/global/math-const.d.ts.map +1 -1
- package/dist/vm/lib/global/time.d.ts.map +1 -1
- package/dist/vm/lib/helpers.d.ts +1 -1
- package/dist/vm/lib/helpers.d.ts.map +1 -1
- package/dist/vm/operations/call.d.ts +7 -3
- package/dist/vm/operations/call.d.ts.map +1 -1
- package/dist/vm/operations/common.d.ts +2 -1
- package/dist/vm/operations/common.d.ts.map +1 -1
- package/dist/vm/operations/compound.d.ts +20 -10
- package/dist/vm/operations/compound.d.ts.map +1 -1
- package/dist/vm/operations/convert.d.ts +8 -4
- package/dist/vm/operations/convert.d.ts.map +1 -1
- package/dist/vm/operations/helpers.d.ts +8 -6
- package/dist/vm/operations/helpers.d.ts.map +1 -1
- package/dist/vm/operations/operator.d.ts +44 -22
- package/dist/vm/operations/operator.d.ts.map +1 -1
- package/dist/vm/operations/slice.d.ts +4 -2
- package/dist/vm/operations/slice.d.ts.map +1 -1
- package/dist/vm/operations/type-check.d.ts +14 -7
- package/dist/vm/operations/type-check.d.ts.map +1 -1
- package/dist/vm/types/boundary.d.ts +2 -0
- package/dist/vm/types/boundary.d.ts.map +1 -1
- package/dist/vm/types/extern.d.ts +7 -2
- package/dist/vm/types/extern.d.ts.map +1 -1
- package/dist/vm/types/function.d.ts +6 -0
- package/dist/vm/types/function.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/compiler/compile-fast.ts +17 -20
- package/src/compiler/create-script.ts +1 -1
- package/src/compiler/emit/constants.ts +1 -1
- package/src/helpers/serialize.ts +22 -8
- package/src/vm/lib/global/debug.ts +1 -1
- package/src/vm/lib/global/math-const.ts +17 -0
- package/src/vm/lib/global/time.ts +6 -5
- package/src/vm/lib/helpers.ts +2 -1
- package/src/vm/operations/call.ts +30 -7
- package/src/vm/operations/common.ts +3 -2
- package/src/vm/operations/compound.ts +59 -32
- package/src/vm/operations/convert.ts +12 -8
- package/src/vm/operations/helpers.ts +14 -12
- package/src/vm/operations/operator.ts +66 -44
- package/src/vm/operations/slice.ts +6 -4
- package/src/vm/operations/type-check.ts +21 -14
- package/src/vm/types/boundary.ts +27 -11
- package/src/vm/types/extern.ts +3 -1
- package/src/vm/types/function.ts +4 -0
- package/dist/chunk-NRUNNMNC.js.map +0 -6
- package/dist/chunk-UM7PQV4L.js.map +0 -6
- package/dist/chunk-VZGKLLRC.js.map +0 -6
- /package/dist/{chunk-BMSHG7ON.js.map → chunk-HGARNCSR.js.map} +0 -0
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
parseDiagnostics,
|
|
46
46
|
toString,
|
|
47
47
|
values
|
|
48
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-SEZII6RI.js";
|
|
49
49
|
|
|
50
50
|
// src/compiler/load-module.ts
|
|
51
51
|
import { loadModule } from "@mirascript/bindings";
|
|
@@ -154,12 +154,12 @@ var VmWrapper = class {
|
|
|
154
154
|
Object.defineProperty(VmWrapper.prototype, kVmWrapper, { value: true });
|
|
155
155
|
|
|
156
156
|
// src/vm/operations/common.ts
|
|
157
|
-
|
|
157
|
+
function $AssertInit(value) {
|
|
158
158
|
if (value === void 0) throw new VmError(`Uninitialized value`, null);
|
|
159
|
-
}
|
|
159
|
+
}
|
|
160
160
|
|
|
161
161
|
// src/vm/operations/call.ts
|
|
162
|
-
|
|
162
|
+
function $Call(func, args) {
|
|
163
163
|
for (const a of args) {
|
|
164
164
|
$AssertInit(a);
|
|
165
165
|
}
|
|
@@ -170,8 +170,8 @@ var $Call = (func, args) => {
|
|
|
170
170
|
return func(...args) ?? null;
|
|
171
171
|
}
|
|
172
172
|
throw new VmError(`Value is not callable: ${display(func)}`, null);
|
|
173
|
-
}
|
|
174
|
-
|
|
173
|
+
}
|
|
174
|
+
function $VArgs(varags) {
|
|
175
175
|
for (let i = 0, l = varags.length; i < l; i++) {
|
|
176
176
|
const el = varags[i];
|
|
177
177
|
if (!isVmConst(el)) {
|
|
@@ -179,7 +179,7 @@ var $VArgs = (varags) => {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
return varags;
|
|
182
|
-
}
|
|
182
|
+
}
|
|
183
183
|
|
|
184
184
|
// src/vm/types/boundary.ts
|
|
185
185
|
function toVmFunctionProxy(fn) {
|
|
@@ -207,19 +207,16 @@ function fromVmFunctionProxy(fn) {
|
|
|
207
207
|
if (original && isVmFunction(original)) return original;
|
|
208
208
|
return null;
|
|
209
209
|
}
|
|
210
|
-
function
|
|
210
|
+
function wrapToVmConst(value, assumeVmValue = null) {
|
|
211
211
|
if (value == null) return null;
|
|
212
212
|
switch (typeof value) {
|
|
213
|
-
case "function":
|
|
214
|
-
|
|
215
|
-
if (unwrapped != null) return unwrapped;
|
|
216
|
-
return new VmExtern(value, thisArg);
|
|
217
|
-
}
|
|
213
|
+
case "function":
|
|
214
|
+
return null;
|
|
218
215
|
case "object": {
|
|
219
|
-
if (isVmWrapper(value)) return
|
|
216
|
+
if (isVmWrapper(value)) return null;
|
|
220
217
|
if (value instanceof Date) return value.valueOf();
|
|
221
218
|
if (assumeVmValue?.(value)) return value;
|
|
222
|
-
return
|
|
219
|
+
return null;
|
|
223
220
|
}
|
|
224
221
|
case "string":
|
|
225
222
|
case "number":
|
|
@@ -233,6 +230,21 @@ function wrapToVmValue(value, thisArg = null, assumeVmValue = null) {
|
|
|
233
230
|
return null;
|
|
234
231
|
}
|
|
235
232
|
}
|
|
233
|
+
function wrapToVmValue(value, thisArg = null, assumeVmValue = null) {
|
|
234
|
+
if (value == null) return null;
|
|
235
|
+
if (typeof value == "function") {
|
|
236
|
+
const unwrapped = fromVmFunctionProxy(value);
|
|
237
|
+
if (unwrapped != null) return unwrapped;
|
|
238
|
+
return new VmExtern(value, thisArg);
|
|
239
|
+
}
|
|
240
|
+
const constValue = wrapToVmConst(value, assumeVmValue);
|
|
241
|
+
if (constValue != null) return constValue;
|
|
242
|
+
if (typeof value == "object") {
|
|
243
|
+
if (isVmWrapper(value)) return value;
|
|
244
|
+
return new VmExtern(value);
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
236
248
|
function bindThis(fn, thisArg) {
|
|
237
249
|
if (thisArg == null) return fn;
|
|
238
250
|
return new Proxy(fn, {
|
|
@@ -336,14 +348,14 @@ var VmExtern = class extends VmWrapper {
|
|
|
336
348
|
return keys4;
|
|
337
349
|
} else {
|
|
338
350
|
const keys4 = /* @__PURE__ */ new Set();
|
|
339
|
-
let
|
|
340
|
-
while (
|
|
341
|
-
for (const key of Object.getOwnPropertyNames(
|
|
351
|
+
let e2 = this.value;
|
|
352
|
+
while (e2 && (typeof e2 == "object" || typeof e2 == "function")) {
|
|
353
|
+
for (const key of Object.getOwnPropertyNames(e2)) {
|
|
342
354
|
if (this.access(key, true)) {
|
|
343
355
|
keys4.add(key);
|
|
344
356
|
}
|
|
345
357
|
}
|
|
346
|
-
|
|
358
|
+
e2 = Object.getPrototypeOf(e2);
|
|
347
359
|
}
|
|
348
360
|
return Array.from(keys4);
|
|
349
361
|
}
|
|
@@ -489,7 +501,8 @@ function VmFunction(fn, option = {}) {
|
|
|
489
501
|
paramsType: option.paramsType,
|
|
490
502
|
returns: option.returns || void 0,
|
|
491
503
|
returnsType: option.returnsType || void 0,
|
|
492
|
-
examples: option.examples?.length ? option.examples : void 0
|
|
504
|
+
examples: option.examples?.length ? option.examples : void 0,
|
|
505
|
+
deprecated: option.deprecated ?? void 0
|
|
493
506
|
};
|
|
494
507
|
if (option.injectCp) {
|
|
495
508
|
const original = fn;
|
|
@@ -742,59 +755,59 @@ __export(operations_exports, {
|
|
|
742
755
|
});
|
|
743
756
|
|
|
744
757
|
// src/vm/operations/convert.ts
|
|
745
|
-
|
|
758
|
+
function $ToBoolean(value) {
|
|
746
759
|
if (typeof value == "boolean") return value;
|
|
747
760
|
$AssertInit(value);
|
|
748
761
|
return toBoolean(value, void 0);
|
|
749
|
-
}
|
|
750
|
-
|
|
762
|
+
}
|
|
763
|
+
function $ToString(value) {
|
|
751
764
|
if (typeof value == "string") return value;
|
|
752
765
|
$AssertInit(value);
|
|
753
766
|
return toString(value, void 0);
|
|
754
|
-
}
|
|
755
|
-
|
|
767
|
+
}
|
|
768
|
+
function $ToNumber(value) {
|
|
756
769
|
if (typeof value == "number") return value;
|
|
757
770
|
$AssertInit(value);
|
|
758
771
|
return toNumber(value, void 0);
|
|
759
|
-
}
|
|
760
|
-
|
|
772
|
+
}
|
|
773
|
+
function $Format(value, format2) {
|
|
761
774
|
$AssertInit(value);
|
|
762
775
|
return toFormat(value, format2);
|
|
763
|
-
}
|
|
776
|
+
}
|
|
764
777
|
|
|
765
778
|
// src/vm/operations/type-check.ts
|
|
766
|
-
|
|
779
|
+
function $Type(value) {
|
|
767
780
|
if (value == null) return "nil";
|
|
768
781
|
if (isVmWrapper(value)) return value.type;
|
|
769
782
|
if (isVmArray(value)) return "array";
|
|
770
783
|
if (typeof value == "object") return "record";
|
|
771
784
|
return typeof value;
|
|
772
|
-
}
|
|
773
|
-
|
|
785
|
+
}
|
|
786
|
+
function $IsBoolean(value) {
|
|
774
787
|
$AssertInit(value);
|
|
775
788
|
return typeof value == "boolean";
|
|
776
|
-
}
|
|
777
|
-
|
|
789
|
+
}
|
|
790
|
+
function $IsNumber(value) {
|
|
778
791
|
$AssertInit(value);
|
|
779
792
|
return typeof value == "number";
|
|
780
|
-
}
|
|
781
|
-
|
|
793
|
+
}
|
|
794
|
+
function $IsString(value) {
|
|
782
795
|
$AssertInit(value);
|
|
783
796
|
return typeof value == "string";
|
|
784
|
-
}
|
|
785
|
-
|
|
797
|
+
}
|
|
798
|
+
function $IsRecord(value) {
|
|
786
799
|
$AssertInit(value);
|
|
787
800
|
return isVmRecord(value);
|
|
788
|
-
}
|
|
789
|
-
|
|
801
|
+
}
|
|
802
|
+
function $IsArray(value) {
|
|
790
803
|
$AssertInit(value);
|
|
791
804
|
return isVmArray(value);
|
|
792
|
-
}
|
|
793
|
-
|
|
805
|
+
}
|
|
806
|
+
function $AssertNonNil(value) {
|
|
794
807
|
$AssertInit(value);
|
|
795
808
|
if (value !== null) return;
|
|
796
809
|
throw new VmError(`Expected non-nil value`, null);
|
|
797
|
-
}
|
|
810
|
+
}
|
|
798
811
|
|
|
799
812
|
// src/vm/operations/utils.ts
|
|
800
813
|
function overloadNumberString(a, b) {
|
|
@@ -844,81 +857,81 @@ function isSame(a, b) {
|
|
|
844
857
|
}
|
|
845
858
|
|
|
846
859
|
// src/vm/operations/operator.ts
|
|
847
|
-
|
|
860
|
+
function $Concat(...args) {
|
|
848
861
|
return args.map((a) => toFormat(a, null)).join("");
|
|
849
|
-
}
|
|
850
|
-
|
|
862
|
+
}
|
|
863
|
+
function $Pos(a) {
|
|
851
864
|
return $ToNumber(a);
|
|
852
|
-
}
|
|
853
|
-
|
|
865
|
+
}
|
|
866
|
+
function $Neg(a) {
|
|
854
867
|
return -$ToNumber(a);
|
|
855
|
-
}
|
|
856
|
-
|
|
868
|
+
}
|
|
869
|
+
function $Not(a) {
|
|
857
870
|
return !$ToBoolean(a);
|
|
858
|
-
}
|
|
859
|
-
|
|
871
|
+
}
|
|
872
|
+
function $Add(a, b) {
|
|
860
873
|
return $ToNumber(a) + $ToNumber(b);
|
|
861
|
-
}
|
|
862
|
-
|
|
874
|
+
}
|
|
875
|
+
function $Sub(a, b) {
|
|
863
876
|
return $ToNumber(a) - $ToNumber(b);
|
|
864
|
-
}
|
|
865
|
-
|
|
877
|
+
}
|
|
878
|
+
function $Mul(a, b) {
|
|
866
879
|
return $ToNumber(a) * $ToNumber(b);
|
|
867
|
-
}
|
|
868
|
-
|
|
880
|
+
}
|
|
881
|
+
function $Div(a, b) {
|
|
869
882
|
return $ToNumber(a) / $ToNumber(b);
|
|
870
|
-
}
|
|
871
|
-
|
|
883
|
+
}
|
|
884
|
+
function $Mod(a, b) {
|
|
872
885
|
return $ToNumber(a) % $ToNumber(b);
|
|
873
|
-
}
|
|
874
|
-
|
|
886
|
+
}
|
|
887
|
+
function $Pow(a, b) {
|
|
875
888
|
return $ToNumber(a) ** $ToNumber(b);
|
|
876
|
-
}
|
|
877
|
-
|
|
889
|
+
}
|
|
890
|
+
function $And(a, b) {
|
|
878
891
|
return $ToBoolean(a) && $ToBoolean(b);
|
|
879
|
-
}
|
|
880
|
-
|
|
892
|
+
}
|
|
893
|
+
function $Or(a, b) {
|
|
881
894
|
return $ToBoolean(a) || $ToBoolean(b);
|
|
882
|
-
}
|
|
883
|
-
|
|
895
|
+
}
|
|
896
|
+
function $Gt(a, b) {
|
|
884
897
|
if (overloadNumberString(a, b)) {
|
|
885
898
|
return $ToNumber(a) > $ToNumber(b);
|
|
886
899
|
} else {
|
|
887
900
|
return $ToString(a) > $ToString(b);
|
|
888
901
|
}
|
|
889
|
-
}
|
|
890
|
-
|
|
902
|
+
}
|
|
903
|
+
function $Gte(a, b) {
|
|
891
904
|
if (overloadNumberString(a, b)) {
|
|
892
905
|
return $ToNumber(a) >= $ToNumber(b);
|
|
893
906
|
} else {
|
|
894
907
|
return $ToString(a) >= $ToString(b);
|
|
895
908
|
}
|
|
896
|
-
}
|
|
897
|
-
|
|
909
|
+
}
|
|
910
|
+
function $Lt(a, b) {
|
|
898
911
|
if (overloadNumberString(a, b)) {
|
|
899
912
|
return $ToNumber(a) < $ToNumber(b);
|
|
900
913
|
} else {
|
|
901
914
|
return $ToString(a) < $ToString(b);
|
|
902
915
|
}
|
|
903
|
-
}
|
|
904
|
-
|
|
916
|
+
}
|
|
917
|
+
function $Lte(a, b) {
|
|
905
918
|
if (overloadNumberString(a, b)) {
|
|
906
919
|
return $ToNumber(a) <= $ToNumber(b);
|
|
907
920
|
} else {
|
|
908
921
|
return $ToString(a) <= $ToString(b);
|
|
909
922
|
}
|
|
910
|
-
}
|
|
911
|
-
|
|
923
|
+
}
|
|
924
|
+
function $Eq(a, b) {
|
|
912
925
|
$AssertInit(a);
|
|
913
926
|
$AssertInit(b);
|
|
914
927
|
if (typeof a == "number" && typeof b == "number") return a === b;
|
|
915
928
|
return isSame(a, b);
|
|
916
|
-
}
|
|
917
|
-
|
|
929
|
+
}
|
|
930
|
+
function $Neq(a, b) {
|
|
918
931
|
return !$Eq(a, b);
|
|
919
|
-
}
|
|
932
|
+
}
|
|
920
933
|
var { abs, min } = Math;
|
|
921
|
-
|
|
934
|
+
function $Aeq(a, b) {
|
|
922
935
|
if (overloadNumberString(a, b)) {
|
|
923
936
|
const an = $ToNumber(a);
|
|
924
937
|
const bn = $ToNumber(b);
|
|
@@ -940,18 +953,18 @@ var $Aeq = (a, b) => {
|
|
|
940
953
|
const bn = bi.normalize("NFC");
|
|
941
954
|
return an === bn;
|
|
942
955
|
}
|
|
943
|
-
}
|
|
944
|
-
|
|
956
|
+
}
|
|
957
|
+
function $Naeq(a, b) {
|
|
945
958
|
return !$Aeq(a, b);
|
|
946
|
-
}
|
|
947
|
-
|
|
959
|
+
}
|
|
960
|
+
function $Same(a, b) {
|
|
948
961
|
$AssertInit(a);
|
|
949
962
|
$AssertInit(b);
|
|
950
963
|
return isSame(a, b);
|
|
951
|
-
}
|
|
952
|
-
|
|
964
|
+
}
|
|
965
|
+
function $Nsame(a, b) {
|
|
953
966
|
return !$Same(a, b);
|
|
954
|
-
}
|
|
967
|
+
}
|
|
955
968
|
|
|
956
969
|
// src/vm/operations/slice.ts
|
|
957
970
|
var { ceil } = Math;
|
|
@@ -970,41 +983,41 @@ var sliceCore = (value, start, end, exclusive) => {
|
|
|
970
983
|
}
|
|
971
984
|
return slice.call(value, start, end);
|
|
972
985
|
};
|
|
973
|
-
|
|
986
|
+
function $Slice(value, start, end) {
|
|
974
987
|
$AssertInit(value);
|
|
975
988
|
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
976
989
|
const s = start != null ? $ToNumber(start) : 0;
|
|
977
|
-
const
|
|
978
|
-
return sliceCore(value, s,
|
|
979
|
-
}
|
|
980
|
-
|
|
990
|
+
const e2 = end != null ? $ToNumber(end) : value.length - 1;
|
|
991
|
+
return sliceCore(value, s, e2, false);
|
|
992
|
+
}
|
|
993
|
+
function $SliceExclusive(value, start, end) {
|
|
981
994
|
$AssertInit(value);
|
|
982
995
|
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
983
996
|
const s = start != null ? $ToNumber(start) : 0;
|
|
984
|
-
const
|
|
985
|
-
return sliceCore(value, s,
|
|
986
|
-
}
|
|
997
|
+
const e2 = end != null ? $ToNumber(end) : value.length;
|
|
998
|
+
return sliceCore(value, s, e2, true);
|
|
999
|
+
}
|
|
987
1000
|
|
|
988
1001
|
// src/vm/operations/helpers.ts
|
|
989
|
-
|
|
1002
|
+
function $El(value) {
|
|
990
1003
|
$AssertInit(value);
|
|
991
1004
|
if (!isVmConst(value)) return null;
|
|
992
1005
|
return value;
|
|
993
|
-
}
|
|
1006
|
+
}
|
|
994
1007
|
var EMPTY = create(null);
|
|
995
|
-
|
|
1008
|
+
function $ElOpt(key, value) {
|
|
996
1009
|
$AssertInit(value);
|
|
997
1010
|
if (value == null || !isVmConst(value)) return EMPTY;
|
|
998
1011
|
return { __proto__: null, [key]: value };
|
|
999
|
-
}
|
|
1000
|
-
|
|
1012
|
+
}
|
|
1013
|
+
function $Fn(name, fn) {
|
|
1001
1014
|
defineProperty(fn, "name", { value: name || VM_FUNCTION_ANONYMOUS_NAME });
|
|
1002
1015
|
return VmFunction(fn, { isLib: false, injectCp: false });
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1016
|
+
}
|
|
1017
|
+
function $Upvalue(value) {
|
|
1005
1018
|
$AssertInit(value);
|
|
1006
1019
|
return value;
|
|
1007
|
-
}
|
|
1020
|
+
}
|
|
1008
1021
|
var assertArrayLength = (start, end) => {
|
|
1009
1022
|
if (end - start > VM_ARRAY_MAX_LENGTH) {
|
|
1010
1023
|
throw new RangeError(`Array length exceeds maximum limit of ${VM_ARRAY_MAX_LENGTH}`);
|
|
@@ -1013,28 +1026,28 @@ var assertArrayLength = (start, end) => {
|
|
|
1013
1026
|
var isEmptyRange = (start, end) => {
|
|
1014
1027
|
return !isFinite(start) || !isFinite(end) || start > end;
|
|
1015
1028
|
};
|
|
1016
|
-
|
|
1029
|
+
function $ArrayRange(start, end) {
|
|
1017
1030
|
const s = $ToNumber(start);
|
|
1018
|
-
const
|
|
1019
|
-
if (isEmptyRange(s,
|
|
1020
|
-
assertArrayLength(s,
|
|
1031
|
+
const e2 = $ToNumber(end);
|
|
1032
|
+
if (isEmptyRange(s, e2)) return [];
|
|
1033
|
+
assertArrayLength(s, e2);
|
|
1021
1034
|
const arr = [];
|
|
1022
|
-
for (let i = s; i <=
|
|
1035
|
+
for (let i = s; i <= e2; i++) {
|
|
1023
1036
|
arr.push(i);
|
|
1024
1037
|
}
|
|
1025
1038
|
return arr;
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1039
|
+
}
|
|
1040
|
+
function $ArrayRangeExclusive(start, end) {
|
|
1028
1041
|
const s = $ToNumber(start);
|
|
1029
|
-
const
|
|
1030
|
-
if (isEmptyRange(s,
|
|
1031
|
-
assertArrayLength(s,
|
|
1042
|
+
const e2 = $ToNumber(end);
|
|
1043
|
+
if (isEmptyRange(s, e2)) return [];
|
|
1044
|
+
assertArrayLength(s, e2);
|
|
1032
1045
|
const arr = [];
|
|
1033
|
-
for (let i = s; i <
|
|
1046
|
+
for (let i = s; i < e2; i++) {
|
|
1034
1047
|
arr.push(i);
|
|
1035
1048
|
}
|
|
1036
1049
|
return arr;
|
|
1037
|
-
}
|
|
1050
|
+
}
|
|
1038
1051
|
function $GlobalFallback() {
|
|
1039
1052
|
return DefaultVmContext;
|
|
1040
1053
|
}
|
|
@@ -1042,7 +1055,7 @@ function $GlobalFallback() {
|
|
|
1042
1055
|
// src/vm/operations/compound.ts
|
|
1043
1056
|
var { trunc } = Math;
|
|
1044
1057
|
var { at } = Array.prototype;
|
|
1045
|
-
|
|
1058
|
+
function $In(value, iterable) {
|
|
1046
1059
|
$AssertInit(value);
|
|
1047
1060
|
$AssertInit(iterable);
|
|
1048
1061
|
if (iterable == null) return false;
|
|
@@ -1058,15 +1071,15 @@ var $In = (value, iterable) => {
|
|
|
1058
1071
|
const key = toString(value, void 0);
|
|
1059
1072
|
if (isVmWrapper(iterable)) return iterable.has(key);
|
|
1060
1073
|
return hasOwnEnumerable(iterable, key);
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1074
|
+
}
|
|
1075
|
+
function $Length(value) {
|
|
1063
1076
|
$AssertInit(value);
|
|
1064
1077
|
if (isVmArray(value)) return value.length;
|
|
1065
1078
|
if (isVmRecord(value)) return keys(value).length;
|
|
1066
1079
|
if (isVmWrapper(value)) return value.keys().length;
|
|
1067
1080
|
throw new VmError(`Value has no length: ${display(value)}`, 0);
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1081
|
+
}
|
|
1082
|
+
function $Omit(value, omitted) {
|
|
1070
1083
|
$AssertInit(value);
|
|
1071
1084
|
if (value == null || !isVmRecord(value)) return {};
|
|
1072
1085
|
const result = {};
|
|
@@ -1078,8 +1091,8 @@ var $Omit = (value, omitted) => {
|
|
|
1078
1091
|
}
|
|
1079
1092
|
}
|
|
1080
1093
|
return result;
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1094
|
+
}
|
|
1095
|
+
function $Pick(value, picked) {
|
|
1083
1096
|
$AssertInit(value);
|
|
1084
1097
|
if (value == null || !isVmRecord(value)) return {};
|
|
1085
1098
|
const result = {};
|
|
@@ -1090,15 +1103,15 @@ var $Pick = (value, picked) => {
|
|
|
1090
1103
|
}
|
|
1091
1104
|
}
|
|
1092
1105
|
return result;
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1106
|
+
}
|
|
1107
|
+
function $Has(obj, key) {
|
|
1095
1108
|
$AssertInit(obj);
|
|
1096
1109
|
const pk = $ToString(key);
|
|
1097
1110
|
if (obj == null || typeof obj != "object") return false;
|
|
1098
1111
|
if (isVmWrapper(obj)) return obj.has(pk);
|
|
1099
1112
|
return hasOwnEnumerable(obj, pk);
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1113
|
+
}
|
|
1114
|
+
function $Get(obj, key) {
|
|
1102
1115
|
$AssertInit(obj);
|
|
1103
1116
|
if (isVmArray(obj)) {
|
|
1104
1117
|
$AssertInit(key);
|
|
@@ -1108,26 +1121,36 @@ var $Get = (obj, key) => {
|
|
|
1108
1121
|
}
|
|
1109
1122
|
const pk = $ToString(key);
|
|
1110
1123
|
if (obj == null || typeof obj != "object") return null;
|
|
1111
|
-
if (isVmWrapper(obj))
|
|
1124
|
+
if (isVmWrapper(obj)) {
|
|
1125
|
+
if (isFinite(key) && isVmExtern(obj) && obj.isArrayLike()) {
|
|
1126
|
+
let index = trunc(key);
|
|
1127
|
+
const { length } = obj.value;
|
|
1128
|
+
if (index < 0) index += length;
|
|
1129
|
+
if (index >= 0 && index < length) {
|
|
1130
|
+
return obj.get(String(index)) ?? null;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return obj.get(pk) ?? null;
|
|
1134
|
+
}
|
|
1112
1135
|
if (!hasOwnEnumerable(obj, pk)) return null;
|
|
1113
1136
|
return obj[pk] ?? null;
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1137
|
+
}
|
|
1138
|
+
function $Set(obj, key, value) {
|
|
1116
1139
|
$AssertInit(obj);
|
|
1117
1140
|
$AssertInit(value);
|
|
1118
1141
|
const pk = $ToString(key);
|
|
1119
1142
|
if (obj == null) return;
|
|
1120
1143
|
if (!isVmExtern(obj)) throw new VmError(`Expected extern, got ${display(obj)}`, void 0);
|
|
1121
1144
|
obj.set(pk, value);
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1145
|
+
}
|
|
1146
|
+
function $Iterable(value) {
|
|
1124
1147
|
$AssertInit(value);
|
|
1125
1148
|
if (isVmWrapper(value)) return value.keys();
|
|
1126
1149
|
if (isVmArray(value)) return value;
|
|
1127
1150
|
if (value != null && typeof value == "object") return keys(value);
|
|
1128
1151
|
throw new VmError(`Value is not iterable: ${display(value)}`, isVmFunction(value) ? [] : [value]);
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1152
|
+
}
|
|
1153
|
+
function $RecordSpread(record) {
|
|
1131
1154
|
$AssertInit(record);
|
|
1132
1155
|
if (record == null || isVmRecord(record)) return record;
|
|
1133
1156
|
if (isVmArray(record)) {
|
|
@@ -1150,24 +1173,29 @@ var $RecordSpread = (record) => {
|
|
|
1150
1173
|
return result;
|
|
1151
1174
|
}
|
|
1152
1175
|
throw new VmError(`Expected record, array, extern or nil, got ${display(record)}`, null);
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1176
|
+
}
|
|
1177
|
+
function $ArraySpread(array) {
|
|
1155
1178
|
$AssertInit(array);
|
|
1156
1179
|
if (array == null) return [];
|
|
1157
1180
|
if (isVmArray(array)) return array;
|
|
1158
|
-
if (isVmExtern(array)
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1181
|
+
if (isVmExtern(array)) {
|
|
1182
|
+
if (array.isArrayLike()) {
|
|
1183
|
+
const result = [];
|
|
1184
|
+
for (let i = 0, len2 = array.value.length; i < len2; i++) {
|
|
1185
|
+
const item = array.value[i];
|
|
1186
|
+
result.push(wrapToVmConst(item, (v) => array.assumeVmValue(v, i)));
|
|
1187
|
+
}
|
|
1188
|
+
return result;
|
|
1189
|
+
} else if (typeof array.value[Symbol.iterator] == "function") {
|
|
1190
|
+
const result = [];
|
|
1191
|
+
for (const item of array.value) {
|
|
1192
|
+
result.push(wrapToVmConst(item, (v) => array.assumeVmValue(v, Symbol.iterator)));
|
|
1165
1193
|
}
|
|
1194
|
+
return result;
|
|
1166
1195
|
}
|
|
1167
|
-
return result;
|
|
1168
1196
|
}
|
|
1169
1197
|
throw new VmError(`Expected array, iterable extern or nil, got ${display(array)}`, []);
|
|
1170
|
-
}
|
|
1198
|
+
}
|
|
1171
1199
|
|
|
1172
1200
|
// src/compiler/create-script.ts
|
|
1173
1201
|
function wrapScript(source, mode, script) {
|
|
@@ -1285,6 +1313,7 @@ __export(global_exports, {
|
|
|
1285
1313
|
cos: () => cos,
|
|
1286
1314
|
cosh: () => cosh,
|
|
1287
1315
|
debug_print: () => debug_print,
|
|
1316
|
+
e: () => e,
|
|
1288
1317
|
ends_with: () => ends_with,
|
|
1289
1318
|
entries: () => entries2,
|
|
1290
1319
|
exp: () => exp,
|
|
@@ -1309,6 +1338,7 @@ __export(global_exports, {
|
|
|
1309
1338
|
max: () => max,
|
|
1310
1339
|
min: () => min2,
|
|
1311
1340
|
panic: () => panic,
|
|
1341
|
+
pi: () => pi,
|
|
1312
1342
|
pow: () => pow2,
|
|
1313
1343
|
product: () => product,
|
|
1314
1344
|
random: () => random,
|
|
@@ -1484,14 +1514,14 @@ function map(data, mapper) {
|
|
|
1484
1514
|
}
|
|
1485
1515
|
return result;
|
|
1486
1516
|
} else {
|
|
1487
|
-
const
|
|
1517
|
+
const e2 = [];
|
|
1488
1518
|
for (const [key, value] of entries(data)) {
|
|
1489
1519
|
Cp();
|
|
1490
1520
|
const ret = mapper(value ?? null, key, data);
|
|
1491
1521
|
if (ret === void 0) continue;
|
|
1492
|
-
|
|
1522
|
+
e2.push([key, ret]);
|
|
1493
1523
|
}
|
|
1494
|
-
return fromEntries(
|
|
1524
|
+
return fromEntries(e2);
|
|
1495
1525
|
}
|
|
1496
1526
|
}
|
|
1497
1527
|
function VmLib(value, option, properties) {
|
|
@@ -1505,6 +1535,7 @@ function VmLib(value, option, properties) {
|
|
|
1505
1535
|
ret.summary = option.summary;
|
|
1506
1536
|
ret.examples = option.examples;
|
|
1507
1537
|
ret.injectCp = option.injectCp ?? false;
|
|
1538
|
+
ret.deprecated = option.deprecated ?? void 0;
|
|
1508
1539
|
return ret;
|
|
1509
1540
|
}
|
|
1510
1541
|
|
|
@@ -1564,6 +1595,7 @@ var product = VmLib(
|
|
|
1564
1595
|
);
|
|
1565
1596
|
|
|
1566
1597
|
// src/vm/lib/global/math-const.ts
|
|
1598
|
+
import { DiagnosticCode as DiagnosticCode2 } from "@mirascript/constants";
|
|
1567
1599
|
var PI = VmLib(Math.PI, {
|
|
1568
1600
|
summary: "圆周率",
|
|
1569
1601
|
returnsType: "number"
|
|
@@ -1572,6 +1604,22 @@ var E = VmLib(Math.E, {
|
|
|
1572
1604
|
summary: "自然对数的底数",
|
|
1573
1605
|
returnsType: "number"
|
|
1574
1606
|
});
|
|
1607
|
+
var pi = VmLib(Math.PI, {
|
|
1608
|
+
summary: "圆周率",
|
|
1609
|
+
returnsType: "number",
|
|
1610
|
+
deprecated: {
|
|
1611
|
+
use: "PI",
|
|
1612
|
+
message: DiagnosticCode2.PreferUppercaseConstant
|
|
1613
|
+
}
|
|
1614
|
+
});
|
|
1615
|
+
var e = VmLib(Math.E, {
|
|
1616
|
+
summary: "自然对数的底数",
|
|
1617
|
+
returnsType: "number",
|
|
1618
|
+
deprecated: {
|
|
1619
|
+
use: "E",
|
|
1620
|
+
message: DiagnosticCode2.PreferUppercaseConstant
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1575
1623
|
var SQRT1_2 = VmLib(Math.SQRT1_2, {
|
|
1576
1624
|
summary: "1 的平方根除以 2",
|
|
1577
1625
|
returnsType: "number"
|
|
@@ -2456,7 +2504,7 @@ var sort_by = VmLib(
|
|
|
2456
2504
|
});
|
|
2457
2505
|
}
|
|
2458
2506
|
arr.sort((a, b) => compare(a.k, b.k));
|
|
2459
|
-
return arr.map((
|
|
2507
|
+
return arr.map((e2) => e2.o);
|
|
2460
2508
|
},
|
|
2461
2509
|
{
|
|
2462
2510
|
summary: "根据键函数对数组中的元素进行排序,并返回排序后的结果",
|
|
@@ -2907,21 +2955,22 @@ var to_datetime = VmLib(
|
|
|
2907
2955
|
};
|
|
2908
2956
|
},
|
|
2909
2957
|
{
|
|
2910
|
-
summary: "将数据转换为
|
|
2958
|
+
summary: "将数据转换为 DateTime 记录",
|
|
2911
2959
|
params: {
|
|
2912
2960
|
datetime: "要转换的数据,默认为当前时间",
|
|
2913
2961
|
offset: "时区偏移量(单位:小时),默认为 0",
|
|
2914
2962
|
fallback: "转换失败时的返回值"
|
|
2915
2963
|
},
|
|
2916
2964
|
paramsType: { datetime: "number | string", offset: "number", fallback: "any" },
|
|
2917
|
-
returnsType: "
|
|
2965
|
+
returnsType: "DateTime | type(fallback)",
|
|
2918
2966
|
examples: [
|
|
2919
2967
|
`
|
|
2920
2968
|
to_datetime(0)
|
|
2921
2969
|
// (
|
|
2922
|
-
//
|
|
2923
|
-
//
|
|
2924
|
-
//
|
|
2970
|
+
// year: 1970, month: 1, day: 1,
|
|
2971
|
+
// hour: 0, minute: 0, second: 0,
|
|
2972
|
+
// millisecond: 0,
|
|
2973
|
+
// dayOfWeek: 4, offset: 0
|
|
2925
2974
|
// )
|
|
2926
2975
|
`.trim()
|
|
2927
2976
|
]
|
|
@@ -3270,8 +3319,8 @@ var invert = VmLib(
|
|
|
3270
3319
|
if (rows !== cols) throwError(`Matrix must be square`, a);
|
|
3271
3320
|
const m = a;
|
|
3272
3321
|
if (rows === 1) {
|
|
3273
|
-
const
|
|
3274
|
-
return [[1 /
|
|
3322
|
+
const e2 = num(m[0]?.[0]);
|
|
3323
|
+
return [[1 / e2]];
|
|
3275
3324
|
}
|
|
3276
3325
|
if (rows === 2) {
|
|
3277
3326
|
const a2 = num(m[0]?.[0]);
|
|
@@ -3409,7 +3458,7 @@ var diagonal = VmLib(
|
|
|
3409
3458
|
(x, k = 0) => {
|
|
3410
3459
|
expectArray("x", x, []);
|
|
3411
3460
|
const fk = expectInteger("k", k);
|
|
3412
|
-
if (x.every((
|
|
3461
|
+
if (x.every((e2) => isArray(e2))) {
|
|
3413
3462
|
const diag = [];
|
|
3414
3463
|
for (let i = 0; i < x.length; i++) {
|
|
3415
3464
|
const row = x[i];
|
|
@@ -3532,4 +3581,4 @@ export {
|
|
|
3532
3581
|
panic,
|
|
3533
3582
|
lib
|
|
3534
3583
|
};
|
|
3535
|
-
//# sourceMappingURL=chunk-
|
|
3584
|
+
//# sourceMappingURL=chunk-C6YXWSTI.js.map
|