@mirascript/mirascript 0.1.76 → 0.1.79
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-ZRLBJK6A.js → chunk-BPFOJ4Q6.js} +499 -470
- package/dist/chunk-BPFOJ4Q6.js.map +6 -0
- package/dist/{chunk-VI74OKFU.js → chunk-LSPCAN32.js} +291 -226
- package/dist/chunk-LSPCAN32.js.map +6 -0
- package/dist/compiler/emit/constants.d.ts +1 -1
- package/dist/compiler/emit/constants.d.ts.map +1 -1
- package/dist/compiler/emit/consts.d.ts.map +1 -1
- package/dist/compiler/emit/index.d.ts.map +1 -1
- package/dist/compiler/emit-script.d.ts.map +1 -1
- package/dist/compiler/worker.js +1 -1
- package/dist/helpers/convert/{to-boolean.d.ts → boolean.d.ts} +1 -1
- package/dist/helpers/convert/boolean.d.ts.map +1 -0
- package/dist/helpers/convert/{to-format.d.ts → format.d.ts} +1 -1
- package/dist/helpers/convert/format.d.ts.map +1 -0
- package/dist/helpers/convert/index.d.ts +4 -4
- package/dist/helpers/convert/index.d.ts.map +1 -1
- package/dist/helpers/convert/{to-number.d.ts → number.d.ts} +1 -1
- package/dist/helpers/convert/number.d.ts.map +1 -0
- package/dist/helpers/convert/{to-string.d.ts → string.d.ts} +3 -1
- package/dist/helpers/convert/string.d.ts.map +1 -0
- package/dist/helpers/error.d.ts +1 -0
- package/dist/helpers/error.d.ts.map +1 -1
- package/dist/helpers/serialize.d.ts.map +1 -1
- package/dist/helpers/types/array-like.d.ts +8 -0
- package/dist/helpers/types/array-like.d.ts.map +1 -0
- package/dist/helpers/types/basic.d.ts +26 -0
- package/dist/helpers/types/basic.d.ts.map +1 -0
- package/dist/helpers/types/composed.d.ts +12 -0
- package/dist/helpers/types/composed.d.ts.map +1 -0
- package/dist/helpers/types/const.d.ts +6 -0
- package/dist/helpers/types/const.d.ts.map +1 -0
- package/dist/helpers/types/get-type.d.ts +6 -0
- package/dist/helpers/types/get-type.d.ts.map +1 -0
- package/dist/helpers/types/index.d.ts +6 -0
- package/dist/helpers/types/index.d.ts.map +1 -0
- package/dist/helpers/types/proto.d.ts +5 -0
- package/dist/helpers/types/proto.d.ts.map +1 -0
- package/dist/helpers/utils.d.ts +9 -0
- package/dist/helpers/utils.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/subtle.js +3 -3
- package/dist/vm/lib/global/debug.d.ts.map +1 -1
- package/dist/vm/lib/global/json.d.ts +3 -2
- package/dist/vm/lib/global/json.d.ts.map +1 -1
- package/dist/vm/lib/global/math/tgamma.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/entries.d.ts +1 -1
- package/dist/vm/lib/global/sequence/entries.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/fold.d.ts +3 -0
- package/dist/vm/lib/global/sequence/fold.d.ts.map +1 -0
- package/dist/vm/lib/global/sequence/group.d.ts +3 -0
- package/dist/vm/lib/global/sequence/group.d.ts.map +1 -0
- package/dist/vm/lib/global/sequence/index.d.ts +2 -0
- package/dist/vm/lib/global/sequence/index.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/new.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/zip.d.ts +2 -2
- package/dist/vm/lib/global/sequence/zip.d.ts.map +1 -1
- package/dist/vm/lib/helpers.d.ts +2 -2
- package/dist/vm/lib/helpers.d.ts.map +1 -1
- package/dist/vm/lib/mod/index.d.ts +1 -1
- package/dist/vm/lib/mod/index.d.ts.map +1 -1
- package/dist/vm/lib/mod/matrix/bin-ops.d.ts +8 -0
- package/dist/vm/lib/mod/matrix/bin-ops.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/fill.d.ts +6 -0
- package/dist/vm/lib/mod/matrix/fill.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/helpers.d.ts +6 -0
- package/dist/vm/lib/mod/matrix/helpers.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/index.d.ts +6 -0
- package/dist/vm/lib/mod/matrix/index.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/invert.d.ts +3 -0
- package/dist/vm/lib/mod/matrix/invert.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/size.d.ts +2 -0
- package/dist/vm/lib/mod/matrix/size.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/transpose.d.ts +2 -0
- package/dist/vm/lib/mod/matrix/transpose.d.ts.map +1 -0
- package/dist/vm/operations/array-range.d.ts +3 -3
- package/dist/vm/operations/array-range.d.ts.map +1 -1
- package/dist/vm/operations/call.d.ts +1 -1
- package/dist/vm/operations/call.d.ts.map +1 -1
- package/dist/vm/operations/compound.d.ts +1 -13
- package/dist/vm/operations/compound.d.ts.map +1 -1
- package/dist/vm/operations/index.d.ts +3 -0
- package/dist/vm/operations/index.d.ts.map +1 -1
- package/dist/vm/operations/iterable.d.ts +6 -0
- package/dist/vm/operations/iterable.d.ts.map +1 -0
- package/dist/vm/operations/record.d.ts +6 -0
- package/dist/vm/operations/record.d.ts.map +1 -0
- package/dist/vm/operations/slice.d.ts.map +1 -1
- package/dist/vm/operations/spread.d.ts +6 -0
- package/dist/vm/operations/spread.d.ts.map +1 -0
- package/dist/vm/operations/utils.d.ts.map +1 -1
- package/dist/vm/types/extern/access.d.ts +5 -0
- package/dist/vm/types/extern/access.d.ts.map +1 -0
- package/dist/vm/types/{extern.d.ts → extern/index.d.ts} +3 -3
- package/dist/vm/types/extern/index.d.ts.map +1 -0
- package/dist/vm/types/extern/tag.d.ts +3 -0
- package/dist/vm/types/extern/tag.d.ts.map +1 -0
- package/dist/vm/types/extern/utils.d.ts +13 -0
- package/dist/vm/types/extern/utils.d.ts.map +1 -0
- package/dist/vm/types/index.d.ts +3 -3
- package/dist/vm/types/index.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/compiler/compile-fast.ts +1 -1
- package/src/compiler/diagnostic.ts +2 -2
- package/src/compiler/emit/constants.ts +1 -1
- package/src/compiler/emit/consts.ts +0 -1
- package/src/compiler/emit/index.ts +1 -7
- package/src/compiler/emit/sourcemap.ts +1 -1
- package/src/compiler/emit-script.ts +1 -0
- package/src/compiler/load-module.ts +5 -1
- package/src/helpers/convert/{to-boolean.ts → boolean.ts} +1 -1
- package/src/helpers/convert/{to-format.ts → format.ts} +1 -1
- package/src/helpers/convert/index.ts +4 -4
- package/src/helpers/convert/{to-number.ts → number.ts} +16 -32
- package/src/helpers/convert/{to-string.ts → string.ts} +5 -4
- package/src/helpers/error.ts +3 -1
- package/src/helpers/serialize.ts +45 -44
- package/src/helpers/types/array-like.ts +32 -0
- package/src/helpers/types/basic.ts +82 -0
- package/src/helpers/types/composed.ts +27 -0
- package/src/helpers/types/const.ts +44 -0
- package/src/helpers/types/get-type.ts +16 -0
- package/src/helpers/types/index.ts +5 -0
- package/src/helpers/types/proto.ts +21 -0
- package/src/helpers/utils.ts +33 -0
- package/src/vm/lib/global/debug.ts +4 -8
- package/src/vm/lib/global/json.ts +21 -9
- package/src/vm/lib/global/math/tgamma.ts +8 -14
- package/src/vm/lib/global/sequence/all-any.ts +1 -1
- package/src/vm/lib/global/sequence/entries.ts +6 -1
- package/src/vm/lib/global/sequence/find.ts +1 -1
- package/src/vm/lib/global/sequence/fold.ts +30 -0
- package/src/vm/lib/global/sequence/group.ts +37 -0
- package/src/vm/lib/global/sequence/index.ts +2 -0
- package/src/vm/lib/global/sequence/map-filter.ts +3 -3
- package/src/vm/lib/global/sequence/new.ts +9 -3
- package/src/vm/lib/global/sequence/sort.ts +1 -1
- package/src/vm/lib/global/sequence/unique.ts +1 -1
- package/src/vm/lib/global/sequence/with.ts +5 -5
- package/src/vm/lib/global/sequence/zip.ts +21 -10
- package/src/vm/lib/global/time.ts +1 -1
- package/src/vm/lib/helpers.ts +12 -5
- package/src/vm/lib/mod/index.ts +1 -1
- package/src/vm/lib/mod/matrix/bin-ops.ts +291 -0
- package/src/vm/lib/mod/matrix/fill.ts +109 -0
- package/src/vm/lib/mod/matrix/helpers.ts +26 -0
- package/src/vm/lib/mod/matrix/index.ts +5 -0
- package/src/vm/lib/mod/matrix/invert.ts +122 -0
- package/src/vm/lib/mod/matrix/size.ts +15 -0
- package/src/vm/lib/mod/matrix/transpose.ts +32 -0
- package/src/vm/operations/array-range.ts +15 -27
- package/src/vm/operations/call.ts +2 -2
- package/src/vm/operations/compound.ts +5 -125
- package/src/vm/operations/helpers.ts +1 -1
- package/src/vm/operations/index.ts +3 -0
- package/src/vm/operations/iterable.ts +40 -0
- package/src/vm/operations/record.ts +33 -0
- package/src/vm/operations/slice.ts +23 -22
- package/src/vm/operations/spread.ts +57 -0
- package/src/vm/operations/type-check.ts +1 -1
- package/src/vm/operations/utils.ts +45 -37
- package/src/vm/types/boundary.ts +2 -2
- package/src/vm/types/extern/access.ts +24 -0
- package/src/vm/types/extern/index.ts +124 -0
- package/src/vm/types/extern/tag.ts +58 -0
- package/src/vm/types/extern/utils.ts +55 -0
- package/src/vm/types/function.ts +1 -1
- package/src/vm/types/index.ts +3 -3
- package/dist/chunk-VI74OKFU.js.map +0 -6
- package/dist/chunk-ZRLBJK6A.js.map +0 -6
- package/dist/helpers/convert/to-boolean.d.ts.map +0 -1
- package/dist/helpers/convert/to-format.d.ts.map +0 -1
- package/dist/helpers/convert/to-number.d.ts.map +0 -1
- package/dist/helpers/convert/to-string.d.ts.map +0 -1
- package/dist/helpers/types.d.ts +0 -58
- package/dist/helpers/types.d.ts.map +0 -1
- package/dist/vm/lib/mod/matrix.d.ts +0 -15
- package/dist/vm/lib/mod/matrix.d.ts.map +0 -1
- package/dist/vm/types/extern.d.ts.map +0 -1
- package/src/helpers/types.ts +0 -283
- package/src/vm/lib/mod/matrix.ts +0 -590
- package/src/vm/types/extern.ts +0 -197
package/src/vm/types/extern.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { VmError } from '../../helpers/error.js';
|
|
2
|
-
import { getPrototypeOf, getOwnPropertyNames, hasOwn, apply, isArray } from '../../helpers/utils.js';
|
|
3
|
-
import { innerToString } from '../../helpers/convert/to-string.js';
|
|
4
|
-
import { isVmExtern } from '../../helpers/types.js';
|
|
5
|
-
import { kVmExtern } from '../../helpers/constants.js';
|
|
6
|
-
import type { VmTypeName, VmAny, VmConst, VmPrimitive, VmValue } from './index.js';
|
|
7
|
-
import { VmWrapper } from './wrapper.js';
|
|
8
|
-
import { unwrapFromVmValue, wrapToVmValue } from './boundary.js';
|
|
9
|
-
|
|
10
|
-
const ObjectPrototype = Object.prototype;
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
12
|
-
const ObjectToString = ObjectPrototype.toString;
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
14
|
-
const FunctionToString = Function.prototype.toString;
|
|
15
|
-
const ArrayToString = Array.prototype.toString;
|
|
16
|
-
const ArrayMap = Array.prototype.map;
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
18
|
-
const TypedArrayToString = Uint8Array.prototype.toString;
|
|
19
|
-
|
|
20
|
-
/** 获取类的名称,如果无法确定则返回 null */
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
22
|
-
function classNameOf(kls: Function): string | null {
|
|
23
|
-
const { displayName } = kls as typeof kls & { displayName?: string };
|
|
24
|
-
if (typeof displayName === 'string' && displayName.trim()) {
|
|
25
|
-
return displayName.trim();
|
|
26
|
-
}
|
|
27
|
-
const { name } = kls;
|
|
28
|
-
if (typeof name == 'string' && name.length > 2) {
|
|
29
|
-
// Looks like a non-minified name
|
|
30
|
-
return name;
|
|
31
|
-
}
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** 包装 Mirascript `extern` 类型的对象 */
|
|
36
|
-
export class VmExtern<const T extends object = object> extends VmWrapper<T> {
|
|
37
|
-
constructor(
|
|
38
|
-
/** 包装值 */
|
|
39
|
-
value: T,
|
|
40
|
-
/** 当 {@link value} 是函数时,绑定的 this 参数 */
|
|
41
|
-
readonly thisArg: ThisParameterType<T> | null = null,
|
|
42
|
-
) {
|
|
43
|
-
super(value);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Check if the object has a property
|
|
48
|
-
* This method will be used in {@link get}, {@link set}, {@link has}, and {@link keys} methods
|
|
49
|
-
*/
|
|
50
|
-
protected access(key: string, read: boolean): boolean {
|
|
51
|
-
// __proto__ and other “private” properties are not accessible
|
|
52
|
-
if (key.startsWith('_')) return false;
|
|
53
|
-
// Function-specific properties are not accessible
|
|
54
|
-
if (typeof this.value == 'function' && (key === 'prototype' || key === 'arguments' || key === 'caller'))
|
|
55
|
-
return false;
|
|
56
|
-
if (hasOwn(this.value, key)) return true;
|
|
57
|
-
if (!read) return true;
|
|
58
|
-
if (!(key in this.value)) return false;
|
|
59
|
-
if (key === 'constructor') return false; // constructor is not accessible
|
|
60
|
-
const prop = (this.value as Record<string, unknown>)[key];
|
|
61
|
-
if (key in Function.prototype && prop === Function.prototype[key as keyof (() => void)]) return false;
|
|
62
|
-
if (key in Array.prototype && prop === Array.prototype[key as keyof unknown[]]) return false;
|
|
63
|
-
if (key in Object.prototype && prop === Object.prototype[key as keyof object]) return false;
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** 决定是否对属性进行包装 */
|
|
68
|
-
assumeVmValue(value: object, key: keyof T | undefined): value is Exclude<VmConst, VmPrimitive> {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** @inheritdoc */
|
|
73
|
-
override has(key: string): boolean {
|
|
74
|
-
return this.access(key, true);
|
|
75
|
-
}
|
|
76
|
-
/** @inheritdoc */
|
|
77
|
-
override get(key: string): VmAny {
|
|
78
|
-
if (!(key in this.value)) return undefined;
|
|
79
|
-
if (!this.access(key, true)) return undefined;
|
|
80
|
-
const prop = (this.value as Record<string, unknown>)[key];
|
|
81
|
-
return wrapToVmValue(prop, this.value, (v) => this.assumeVmValue(v, key as keyof T));
|
|
82
|
-
}
|
|
83
|
-
/** Set a property on the object */
|
|
84
|
-
set(key: string, value: VmValue): boolean {
|
|
85
|
-
if (!this.access(key, false)) return false;
|
|
86
|
-
const prop = unwrapFromVmValue(value, true);
|
|
87
|
-
(this.value as Record<string, unknown>)[key] = prop;
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
/** Call extern value */
|
|
91
|
-
call(args: readonly VmValue[]): VmAny {
|
|
92
|
-
const { value } = this;
|
|
93
|
-
if (typeof value != 'function') {
|
|
94
|
-
throw VmError.from(`Not a callable extern`, null, null);
|
|
95
|
-
}
|
|
96
|
-
const caller = this.thisArg;
|
|
97
|
-
const unwrappedArgs = args.map((arg) => unwrapFromVmValue(arg, true));
|
|
98
|
-
let ret: unknown;
|
|
99
|
-
try {
|
|
100
|
-
ret = apply(value, caller, unwrappedArgs);
|
|
101
|
-
} catch (ex) {
|
|
102
|
-
throw VmError.from(`Callable extern`, ex, null);
|
|
103
|
-
}
|
|
104
|
-
return wrapToVmValue(ret, null, (obj) => this.assumeVmValue(obj, undefined));
|
|
105
|
-
}
|
|
106
|
-
/** @inheritdoc */
|
|
107
|
-
override keys(includeNonEnumerable = false): string[] {
|
|
108
|
-
if (!includeNonEnumerable) {
|
|
109
|
-
const keys: string[] = [];
|
|
110
|
-
for (const key in this.value) {
|
|
111
|
-
if (this.access(key, true)) keys.push(key);
|
|
112
|
-
}
|
|
113
|
-
return keys;
|
|
114
|
-
} else {
|
|
115
|
-
const keys = new Set<string>();
|
|
116
|
-
let e: unknown = this.value;
|
|
117
|
-
while (e != null && (typeof e == 'object' || typeof e == 'function')) {
|
|
118
|
-
for (const key of getOwnPropertyNames(e)) {
|
|
119
|
-
keys.add(key);
|
|
120
|
-
}
|
|
121
|
-
e = getPrototypeOf(e);
|
|
122
|
-
}
|
|
123
|
-
return Array.from(keys).filter((key) => this.access(key, true));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/** @inheritdoc */
|
|
127
|
-
override same(other: VmAny): boolean {
|
|
128
|
-
if (!isVmExtern(other)) return false;
|
|
129
|
-
return this.value === other.value && this.thisArg === other.thisArg;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Should this extern be treated as array-like?
|
|
133
|
-
*
|
|
134
|
-
* By default, this method returns true if the wrapped value is an Array or a TypedArray.
|
|
135
|
-
*/
|
|
136
|
-
isArrayLike(): this is VmExtern<ArrayLike<unknown>> {
|
|
137
|
-
return isArray(this.value) || (ArrayBuffer.isView(this.value) && 'length' in this.value);
|
|
138
|
-
}
|
|
139
|
-
/** @inheritdoc */
|
|
140
|
-
override toString(useBraces: boolean): string {
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
142
|
-
const { toString } = this.value;
|
|
143
|
-
if (typeof toString != 'function' || toString === ObjectToString || toString === FunctionToString) {
|
|
144
|
-
// When the toString method is not overridden or invalid, provide a better default representation
|
|
145
|
-
return super.toString(useBraces);
|
|
146
|
-
}
|
|
147
|
-
if ((toString === ArrayToString || toString === TypedArrayToString) && this.isArrayLike()) {
|
|
148
|
-
// Handle array-like externs specially when using default toString
|
|
149
|
-
const mapped = ArrayMap.call(this.value, (item: unknown) => {
|
|
150
|
-
if (item === undefined) return '';
|
|
151
|
-
return innerToString(wrapToVmValue(item ?? null, null, null), true);
|
|
152
|
-
});
|
|
153
|
-
const str = mapped.join(', ');
|
|
154
|
-
if (useBraces) return `[${str}]`;
|
|
155
|
-
return str;
|
|
156
|
-
}
|
|
157
|
-
// Use the wrapped object's toString method
|
|
158
|
-
return String(this.value);
|
|
159
|
-
}
|
|
160
|
-
/** @inheritdoc */
|
|
161
|
-
override get type(): VmTypeName {
|
|
162
|
-
return 'extern';
|
|
163
|
-
}
|
|
164
|
-
/** @inheritdoc */
|
|
165
|
-
override get tag(): string {
|
|
166
|
-
const tag = ObjectToString.call(this.value).slice(8, -1);
|
|
167
|
-
if (this.isArrayLike()) {
|
|
168
|
-
return `${tag}(${this.value.length})`;
|
|
169
|
-
} else if (tag === 'Object') {
|
|
170
|
-
const proto = getPrototypeOf(this.value);
|
|
171
|
-
if (proto === ObjectPrototype) {
|
|
172
|
-
return 'Object';
|
|
173
|
-
}
|
|
174
|
-
if (proto == null) {
|
|
175
|
-
return 'Object: null prototype';
|
|
176
|
-
}
|
|
177
|
-
if (typeof proto.constructor === 'function') {
|
|
178
|
-
return classNameOf(proto.constructor) ?? 'Object';
|
|
179
|
-
}
|
|
180
|
-
} else if (tag === 'Function' && 'prototype' in this.value && typeof this.value.prototype == 'object') {
|
|
181
|
-
const className = classNameOf(this.value as unknown as new () => unknown);
|
|
182
|
-
if (!className) return `class`;
|
|
183
|
-
return `class ${className}`;
|
|
184
|
-
} else if (tag === 'Function') {
|
|
185
|
-
return `function`;
|
|
186
|
-
} else if (tag === 'AsyncFunction') {
|
|
187
|
-
return `async function`;
|
|
188
|
-
} else if (tag === 'GeneratorFunction') {
|
|
189
|
-
return `function*`;
|
|
190
|
-
} else if (tag === 'AsyncGeneratorFunction') {
|
|
191
|
-
return `async function*`;
|
|
192
|
-
}
|
|
193
|
-
return tag;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
Object.defineProperty(VmExtern.prototype, kVmExtern, { value: true });
|