@mirascript/mirascript 0.1.78 → 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.
Files changed (152) hide show
  1. package/dist/{chunk-VNQQF2W7.js → chunk-BPFOJ4Q6.js} +381 -432
  2. package/dist/chunk-BPFOJ4Q6.js.map +6 -0
  3. package/dist/{chunk-BITOQYYQ.js → chunk-LSPCAN32.js} +204 -149
  4. package/dist/chunk-LSPCAN32.js.map +6 -0
  5. package/dist/compiler/emit/constants.d.ts +1 -1
  6. package/dist/compiler/emit/constants.d.ts.map +1 -1
  7. package/dist/compiler/emit/consts.d.ts.map +1 -1
  8. package/dist/compiler/worker.js +1 -1
  9. package/dist/helpers/convert/{to-boolean.d.ts → boolean.d.ts} +1 -1
  10. package/dist/helpers/convert/boolean.d.ts.map +1 -0
  11. package/dist/helpers/convert/{to-format.d.ts → format.d.ts} +1 -1
  12. package/dist/helpers/convert/format.d.ts.map +1 -0
  13. package/dist/helpers/convert/index.d.ts +4 -4
  14. package/dist/helpers/convert/index.d.ts.map +1 -1
  15. package/dist/helpers/convert/{to-number.d.ts → number.d.ts} +1 -1
  16. package/dist/helpers/convert/number.d.ts.map +1 -0
  17. package/dist/helpers/convert/{to-string.d.ts → string.d.ts} +1 -1
  18. package/dist/helpers/convert/string.d.ts.map +1 -0
  19. package/dist/helpers/serialize.d.ts.map +1 -1
  20. package/dist/helpers/types/array-like.d.ts +8 -0
  21. package/dist/helpers/types/array-like.d.ts.map +1 -0
  22. package/dist/helpers/types/basic.d.ts +26 -0
  23. package/dist/helpers/types/basic.d.ts.map +1 -0
  24. package/dist/helpers/types/composed.d.ts +12 -0
  25. package/dist/helpers/types/composed.d.ts.map +1 -0
  26. package/dist/helpers/types/const.d.ts +6 -0
  27. package/dist/helpers/types/const.d.ts.map +1 -0
  28. package/dist/helpers/types/get-type.d.ts +6 -0
  29. package/dist/helpers/types/get-type.d.ts.map +1 -0
  30. package/dist/helpers/types/index.d.ts +6 -0
  31. package/dist/helpers/types/index.d.ts.map +1 -0
  32. package/dist/helpers/types/proto.d.ts +5 -0
  33. package/dist/helpers/types/proto.d.ts.map +1 -0
  34. package/dist/helpers/utils.d.ts.map +1 -1
  35. package/dist/index.js +2 -2
  36. package/dist/subtle.js +3 -3
  37. package/dist/vm/lib/global/json.d.ts +1 -1
  38. package/dist/vm/lib/global/json.d.ts.map +1 -1
  39. package/dist/vm/lib/helpers.d.ts.map +1 -1
  40. package/dist/vm/lib/mod/index.d.ts +1 -1
  41. package/dist/vm/lib/mod/index.d.ts.map +1 -1
  42. package/dist/vm/lib/mod/matrix/bin-ops.d.ts +8 -0
  43. package/dist/vm/lib/mod/matrix/bin-ops.d.ts.map +1 -0
  44. package/dist/vm/lib/mod/matrix/fill.d.ts +6 -0
  45. package/dist/vm/lib/mod/matrix/fill.d.ts.map +1 -0
  46. package/dist/vm/lib/mod/matrix/helpers.d.ts +6 -0
  47. package/dist/vm/lib/mod/matrix/helpers.d.ts.map +1 -0
  48. package/dist/vm/lib/mod/matrix/index.d.ts +6 -0
  49. package/dist/vm/lib/mod/matrix/index.d.ts.map +1 -0
  50. package/dist/vm/lib/mod/matrix/invert.d.ts +3 -0
  51. package/dist/vm/lib/mod/matrix/invert.d.ts.map +1 -0
  52. package/dist/vm/lib/mod/matrix/size.d.ts +2 -0
  53. package/dist/vm/lib/mod/matrix/size.d.ts.map +1 -0
  54. package/dist/vm/lib/mod/matrix/transpose.d.ts +2 -0
  55. package/dist/vm/lib/mod/matrix/transpose.d.ts.map +1 -0
  56. package/dist/vm/operations/array-range.d.ts +3 -3
  57. package/dist/vm/operations/array-range.d.ts.map +1 -1
  58. package/dist/vm/operations/call.d.ts +1 -1
  59. package/dist/vm/operations/call.d.ts.map +1 -1
  60. package/dist/vm/operations/compound.d.ts +1 -13
  61. package/dist/vm/operations/compound.d.ts.map +1 -1
  62. package/dist/vm/operations/index.d.ts +3 -0
  63. package/dist/vm/operations/index.d.ts.map +1 -1
  64. package/dist/vm/operations/iterable.d.ts +6 -0
  65. package/dist/vm/operations/iterable.d.ts.map +1 -0
  66. package/dist/vm/operations/record.d.ts +6 -0
  67. package/dist/vm/operations/record.d.ts.map +1 -0
  68. package/dist/vm/operations/slice.d.ts.map +1 -1
  69. package/dist/vm/operations/spread.d.ts +6 -0
  70. package/dist/vm/operations/spread.d.ts.map +1 -0
  71. package/dist/vm/operations/utils.d.ts.map +1 -1
  72. package/dist/vm/types/extern/access.d.ts +5 -0
  73. package/dist/vm/types/extern/access.d.ts.map +1 -0
  74. package/dist/vm/types/{extern.d.ts → extern/index.d.ts} +3 -3
  75. package/dist/vm/types/extern/index.d.ts.map +1 -0
  76. package/dist/vm/types/extern/tag.d.ts +3 -0
  77. package/dist/vm/types/extern/tag.d.ts.map +1 -0
  78. package/dist/vm/types/extern/utils.d.ts +13 -0
  79. package/dist/vm/types/extern/utils.d.ts.map +1 -0
  80. package/dist/vm/types/index.d.ts +3 -3
  81. package/dist/vm/types/index.d.ts.map +1 -1
  82. package/package.json +4 -4
  83. package/src/compiler/diagnostic.ts +2 -2
  84. package/src/compiler/emit/constants.ts +1 -1
  85. package/src/compiler/emit/consts.ts +0 -1
  86. package/src/compiler/emit/index.ts +1 -1
  87. package/src/compiler/emit/sourcemap.ts +1 -1
  88. package/src/compiler/load-module.ts +5 -1
  89. package/src/helpers/convert/{to-boolean.ts → boolean.ts} +1 -1
  90. package/src/helpers/convert/{to-format.ts → format.ts} +1 -1
  91. package/src/helpers/convert/index.ts +4 -4
  92. package/src/helpers/convert/{to-number.ts → number.ts} +15 -26
  93. package/src/helpers/convert/{to-string.ts → string.ts} +2 -2
  94. package/src/helpers/serialize.ts +42 -36
  95. package/src/helpers/types/array-like.ts +32 -0
  96. package/src/helpers/types/basic.ts +82 -0
  97. package/src/helpers/types/composed.ts +27 -0
  98. package/src/helpers/types/const.ts +44 -0
  99. package/src/helpers/types/get-type.ts +16 -0
  100. package/src/helpers/types/index.ts +5 -0
  101. package/src/helpers/types/proto.ts +21 -0
  102. package/src/helpers/utils.ts +7 -1
  103. package/src/vm/lib/global/sequence/all-any.ts +1 -1
  104. package/src/vm/lib/global/sequence/find.ts +1 -1
  105. package/src/vm/lib/global/sequence/group.ts +1 -1
  106. package/src/vm/lib/global/sequence/map-filter.ts +1 -1
  107. package/src/vm/lib/global/sequence/new.ts +1 -1
  108. package/src/vm/lib/global/sequence/sort.ts +1 -1
  109. package/src/vm/lib/global/sequence/unique.ts +1 -1
  110. package/src/vm/lib/global/sequence/with.ts +1 -1
  111. package/src/vm/lib/global/time.ts +1 -1
  112. package/src/vm/lib/helpers.ts +8 -1
  113. package/src/vm/lib/mod/index.ts +1 -1
  114. package/src/vm/lib/mod/matrix/bin-ops.ts +291 -0
  115. package/src/vm/lib/mod/matrix/fill.ts +109 -0
  116. package/src/vm/lib/mod/matrix/helpers.ts +26 -0
  117. package/src/vm/lib/mod/matrix/index.ts +5 -0
  118. package/src/vm/lib/mod/matrix/invert.ts +122 -0
  119. package/src/vm/lib/mod/matrix/size.ts +15 -0
  120. package/src/vm/lib/mod/matrix/transpose.ts +32 -0
  121. package/src/vm/operations/array-range.ts +15 -27
  122. package/src/vm/operations/call.ts +2 -2
  123. package/src/vm/operations/compound.ts +4 -131
  124. package/src/vm/operations/helpers.ts +1 -1
  125. package/src/vm/operations/index.ts +3 -0
  126. package/src/vm/operations/iterable.ts +40 -0
  127. package/src/vm/operations/record.ts +33 -0
  128. package/src/vm/operations/slice.ts +23 -22
  129. package/src/vm/operations/spread.ts +57 -0
  130. package/src/vm/operations/type-check.ts +1 -1
  131. package/src/vm/operations/utils.ts +45 -37
  132. package/src/vm/types/boundary.ts +2 -2
  133. package/src/vm/types/extern/access.ts +24 -0
  134. package/src/vm/types/extern/index.ts +124 -0
  135. package/src/vm/types/extern/tag.ts +58 -0
  136. package/src/vm/types/extern/utils.ts +55 -0
  137. package/src/vm/types/function.ts +1 -1
  138. package/src/vm/types/index.ts +3 -3
  139. package/dist/chunk-BITOQYYQ.js.map +0 -6
  140. package/dist/chunk-VNQQF2W7.js.map +0 -6
  141. package/dist/helpers/convert/to-boolean.d.ts.map +0 -1
  142. package/dist/helpers/convert/to-format.d.ts.map +0 -1
  143. package/dist/helpers/convert/to-number.d.ts.map +0 -1
  144. package/dist/helpers/convert/to-string.d.ts.map +0 -1
  145. package/dist/helpers/types.d.ts +0 -58
  146. package/dist/helpers/types.d.ts.map +0 -1
  147. package/dist/vm/lib/mod/matrix.d.ts +0 -15
  148. package/dist/vm/lib/mod/matrix.d.ts.map +0 -1
  149. package/dist/vm/types/extern.d.ts.map +0 -1
  150. package/src/helpers/types.ts +0 -283
  151. package/src/vm/lib/mod/matrix.ts +0 -590
  152. package/src/vm/types/extern.ts +0 -197
@@ -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 });