@mirascript/mirascript 0.1.15 → 0.1.16

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 (216) hide show
  1. package/dist/{chunk-NT235HY3.js → chunk-LU4ZKFF6.js} +1411 -608
  2. package/dist/chunk-LU4ZKFF6.js.map +6 -0
  3. package/dist/chunk-RIT53WVY.js +1 -0
  4. package/dist/chunk-RLWIIOH5.js +12 -0
  5. package/dist/chunk-RLWIIOH5.js.map +6 -0
  6. package/dist/{chunk-JVFUK7AN.js → chunk-YZGL3D7L.js} +739 -1366
  7. package/dist/chunk-YZGL3D7L.js.map +6 -0
  8. package/dist/cli/index.js +11 -67
  9. package/dist/cli/index.js.map +2 -2
  10. package/dist/compiler/compile-fast.d.ts +1 -1
  11. package/dist/compiler/compile-fast.d.ts.map +1 -1
  12. package/dist/compiler/create-script.d.ts +10 -1
  13. package/dist/compiler/create-script.d.ts.map +1 -1
  14. package/dist/compiler/diagnostic.d.ts +1 -1
  15. package/dist/compiler/diagnostic.d.ts.map +1 -1
  16. package/dist/compiler/emit/constants.d.ts +3 -0
  17. package/dist/compiler/emit/constants.d.ts.map +1 -0
  18. package/dist/compiler/emit/consts.d.ts +6 -0
  19. package/dist/compiler/emit/consts.d.ts.map +1 -0
  20. package/dist/compiler/emit/globals.d.ts +17 -0
  21. package/dist/compiler/emit/globals.d.ts.map +1 -0
  22. package/dist/compiler/emit/index.d.ts +58 -0
  23. package/dist/compiler/emit/index.d.ts.map +1 -0
  24. package/dist/compiler/emit/sourcemap.d.ts +6 -0
  25. package/dist/compiler/emit/sourcemap.d.ts.map +1 -0
  26. package/dist/compiler/index.d.ts +3 -2
  27. package/dist/compiler/index.d.ts.map +1 -1
  28. package/dist/compiler/worker.js +1 -1
  29. package/dist/helpers/constants.d.ts +10 -0
  30. package/dist/helpers/constants.d.ts.map +1 -1
  31. package/dist/helpers/convert.d.ts +12 -0
  32. package/dist/helpers/convert.d.ts.map +1 -0
  33. package/dist/{vm → helpers}/error.d.ts +1 -1
  34. package/dist/helpers/error.d.ts.map +1 -0
  35. package/dist/helpers/serialize.d.ts +13 -4
  36. package/dist/helpers/serialize.d.ts.map +1 -1
  37. package/dist/helpers/types.d.ts +54 -0
  38. package/dist/helpers/types.d.ts.map +1 -0
  39. package/dist/index.js +11 -17
  40. package/dist/subtle.d.ts +3 -2
  41. package/dist/subtle.d.ts.map +1 -1
  42. package/dist/subtle.js +21 -15
  43. package/dist/vm/checkpoint.d.ts +9 -0
  44. package/dist/vm/checkpoint.d.ts.map +1 -0
  45. package/dist/vm/helpers.d.ts +4 -10
  46. package/dist/vm/helpers.d.ts.map +1 -1
  47. package/dist/vm/index.d.ts +3 -3
  48. package/dist/vm/index.d.ts.map +1 -1
  49. package/dist/vm/lib/global/bit.d.ts +7 -7
  50. package/dist/vm/lib/global/bit.d.ts.map +1 -1
  51. package/dist/vm/lib/global/debug.d.ts +2 -2
  52. package/dist/vm/lib/global/debug.d.ts.map +1 -1
  53. package/dist/vm/lib/global/index.d.ts +0 -1
  54. package/dist/vm/lib/global/index.d.ts.map +1 -1
  55. package/dist/vm/lib/global/json.d.ts +2 -2
  56. package/dist/vm/lib/global/json.d.ts.map +1 -1
  57. package/dist/vm/lib/global/math-additional.d.ts +1 -1
  58. package/dist/vm/lib/global/math-additional.d.ts.map +1 -1
  59. package/dist/vm/lib/global/math-arr.d.ts +5 -5
  60. package/dist/vm/lib/global/math-arr.d.ts.map +1 -1
  61. package/dist/vm/lib/global/math-unary.d.ts +26 -26
  62. package/dist/vm/lib/global/math-unary.d.ts.map +1 -1
  63. package/dist/vm/lib/global/math.d.ts +3 -3
  64. package/dist/vm/lib/global/math.d.ts.map +1 -1
  65. package/dist/vm/lib/global/sequence/all-any.d.ts +2 -2
  66. package/dist/vm/lib/global/sequence/all-any.d.ts.map +1 -1
  67. package/dist/vm/lib/global/sequence/entries.d.ts +5 -5
  68. package/dist/vm/lib/global/sequence/entries.d.ts.map +1 -1
  69. package/dist/vm/lib/global/sequence/find.d.ts +3 -3
  70. package/dist/vm/lib/global/sequence/find.d.ts.map +1 -1
  71. package/dist/vm/lib/global/sequence/flatten.d.ts +1 -1
  72. package/dist/vm/lib/global/sequence/flatten.d.ts.map +1 -1
  73. package/dist/vm/lib/global/sequence/len.d.ts +1 -1
  74. package/dist/vm/lib/global/sequence/len.d.ts.map +1 -1
  75. package/dist/vm/lib/global/sequence/map-filter.d.ts +3 -3
  76. package/dist/vm/lib/global/sequence/map-filter.d.ts.map +1 -1
  77. package/dist/vm/lib/global/sequence/repeat.d.ts +1 -1
  78. package/dist/vm/lib/global/sequence/repeat.d.ts.map +1 -1
  79. package/dist/vm/lib/global/sequence/reverse.d.ts +1 -1
  80. package/dist/vm/lib/global/sequence/reverse.d.ts.map +1 -1
  81. package/dist/vm/lib/global/sequence/sort.d.ts +2 -2
  82. package/dist/vm/lib/global/sequence/sort.d.ts.map +1 -1
  83. package/dist/vm/lib/global/sequence/with.d.ts +2 -2
  84. package/dist/vm/lib/global/sequence/with.d.ts.map +1 -1
  85. package/dist/vm/lib/global/sequence/zip.d.ts +1 -1
  86. package/dist/vm/lib/global/sequence/zip.d.ts.map +1 -1
  87. package/dist/vm/lib/global/string.d.ts +10 -10
  88. package/dist/vm/lib/global/string.d.ts.map +1 -1
  89. package/dist/vm/lib/global/time.d.ts +3 -13
  90. package/dist/vm/lib/global/time.d.ts.map +1 -1
  91. package/dist/vm/lib/global/to-primitive.d.ts +4 -4
  92. package/dist/vm/lib/global/to-primitive.d.ts.map +1 -1
  93. package/dist/vm/lib/helpers.d.ts +53 -0
  94. package/dist/vm/lib/helpers.d.ts.map +1 -0
  95. package/dist/vm/lib/index.d.ts +4 -0
  96. package/dist/vm/lib/index.d.ts.map +1 -0
  97. package/dist/vm/lib/{_loader.d.ts → loader.d.ts} +5 -5
  98. package/dist/vm/lib/loader.d.ts.map +1 -0
  99. package/dist/vm/lib/mod/index.d.ts +2 -0
  100. package/dist/vm/lib/mod/index.d.ts.map +1 -0
  101. package/dist/vm/lib/mod/matrix.d.ts +15 -0
  102. package/dist/vm/lib/mod/matrix.d.ts.map +1 -0
  103. package/dist/vm/operations.d.ts +2 -4
  104. package/dist/vm/operations.d.ts.map +1 -1
  105. package/dist/vm/types/boundary.d.ts +1 -1
  106. package/dist/vm/types/boundary.d.ts.map +1 -1
  107. package/dist/vm/types/context.d.ts +10 -9
  108. package/dist/vm/types/context.d.ts.map +1 -1
  109. package/dist/vm/types/extern.d.ts +1 -3
  110. package/dist/vm/types/extern.d.ts.map +1 -1
  111. package/dist/vm/types/function.d.ts +1 -6
  112. package/dist/vm/types/function.d.ts.map +1 -1
  113. package/dist/vm/types/index.d.ts +31 -17
  114. package/dist/vm/types/index.d.ts.map +1 -1
  115. package/dist/vm/types/module.d.ts +2 -4
  116. package/dist/vm/types/module.d.ts.map +1 -1
  117. package/dist/vm/types/wrapper.d.ts +0 -2
  118. package/dist/vm/types/wrapper.d.ts.map +1 -1
  119. package/package.json +7 -3
  120. package/src/cli/index.ts +1 -1
  121. package/src/compiler/compile-fast.ts +1 -2
  122. package/src/compiler/create-script.ts +12 -2
  123. package/src/compiler/diagnostic.ts +17 -8
  124. package/src/compiler/emit/constants.ts +2 -0
  125. package/src/compiler/emit/consts.ts +47 -0
  126. package/src/compiler/emit/globals.ts +39 -0
  127. package/src/compiler/{emit.ts → emit/index.ts} +16 -200
  128. package/src/compiler/emit/sourcemap.ts +163 -0
  129. package/src/compiler/index.ts +9 -9
  130. package/src/compiler/worker.ts +1 -1
  131. package/src/helpers/constants.ts +12 -0
  132. package/src/helpers/convert.ts +128 -0
  133. package/src/{vm → helpers}/error.ts +1 -1
  134. package/src/helpers/serialize.ts +71 -24
  135. package/src/helpers/types.ts +267 -0
  136. package/src/subtle.ts +3 -1
  137. package/src/vm/checkpoint.ts +42 -0
  138. package/src/vm/helpers.ts +9 -53
  139. package/src/vm/index.ts +3 -3
  140. package/src/vm/lib/global/bit.ts +8 -9
  141. package/src/vm/lib/global/debug.ts +5 -4
  142. package/src/vm/lib/global/index.ts +0 -1
  143. package/src/vm/lib/global/json.ts +2 -2
  144. package/src/vm/lib/global/math-additional.ts +2 -4
  145. package/src/vm/lib/global/math-arr.ts +1 -1
  146. package/src/vm/lib/global/math-unary.ts +2 -4
  147. package/src/vm/lib/global/math.ts +3 -4
  148. package/src/vm/lib/global/sequence/all-any.ts +11 -6
  149. package/src/vm/lib/global/sequence/entries.ts +1 -1
  150. package/src/vm/lib/global/sequence/find.ts +4 -3
  151. package/src/vm/lib/global/sequence/flatten.ts +2 -3
  152. package/src/vm/lib/global/sequence/len.ts +1 -1
  153. package/src/vm/lib/global/sequence/map-filter.ts +4 -3
  154. package/src/vm/lib/global/sequence/repeat.ts +2 -4
  155. package/src/vm/lib/global/sequence/reverse.ts +1 -1
  156. package/src/vm/lib/global/sequence/sort.ts +6 -5
  157. package/src/vm/lib/global/sequence/with.ts +21 -20
  158. package/src/vm/lib/global/sequence/zip.ts +3 -3
  159. package/src/vm/lib/global/string.ts +16 -27
  160. package/src/vm/lib/global/time.ts +59 -30
  161. package/src/vm/lib/global/to-primitive.ts +27 -18
  162. package/src/vm/lib/{_helpers.ts → helpers.ts} +129 -41
  163. package/src/vm/lib/index.ts +16 -0
  164. package/src/vm/lib/{_loader.ts → loader.ts} +3 -11
  165. package/src/vm/lib/mod/index.ts +1 -0
  166. package/src/vm/lib/{global/mod → mod}/matrix.ts +9 -7
  167. package/src/vm/operations.ts +31 -126
  168. package/src/vm/types/boundary.ts +10 -13
  169. package/src/vm/types/context.ts +17 -24
  170. package/src/vm/types/extern.ts +8 -15
  171. package/src/vm/types/function.ts +4 -19
  172. package/src/vm/types/index.ts +47 -25
  173. package/src/vm/types/module.ts +3 -7
  174. package/src/vm/types/wrapper.ts +1 -5
  175. package/dist/chunk-35JGBXRE.js +0 -1
  176. package/dist/chunk-JVFUK7AN.js.map +0 -6
  177. package/dist/chunk-NT235HY3.js.map +0 -6
  178. package/dist/compiler/emit.d.ts +0 -5
  179. package/dist/compiler/emit.d.ts.map +0 -1
  180. package/dist/vm/error.d.ts.map +0 -1
  181. package/dist/vm/lib/_helpers.d.ts +0 -35
  182. package/dist/vm/lib/_helpers.d.ts.map +0 -1
  183. package/dist/vm/lib/_loader.d.ts.map +0 -1
  184. package/dist/vm/lib/global/mod/index.d.ts +0 -3
  185. package/dist/vm/lib/global/mod/index.d.ts.map +0 -1
  186. package/dist/vm/lib/global/mod/matrix.d.ts +0 -15
  187. package/dist/vm/lib/global/mod/matrix.d.ts.map +0 -1
  188. package/dist/vm/types/any.d.ts +0 -10
  189. package/dist/vm/types/any.d.ts.map +0 -1
  190. package/dist/vm/types/array.d.ts +0 -12
  191. package/dist/vm/types/array.d.ts.map +0 -1
  192. package/dist/vm/types/callable.d.ts +0 -5
  193. package/dist/vm/types/callable.d.ts.map +0 -1
  194. package/dist/vm/types/const.d.ts +0 -15
  195. package/dist/vm/types/const.d.ts.map +0 -1
  196. package/dist/vm/types/immutable.d.ts +0 -15
  197. package/dist/vm/types/immutable.d.ts.map +0 -1
  198. package/dist/vm/types/primitive.d.ts +0 -7
  199. package/dist/vm/types/primitive.d.ts.map +0 -1
  200. package/dist/vm/types/record.d.ts +0 -20
  201. package/dist/vm/types/record.d.ts.map +0 -1
  202. package/dist/vm/types/script.d.ts +0 -14
  203. package/dist/vm/types/script.d.ts.map +0 -1
  204. package/dist/vm/types/value.d.ts +0 -14
  205. package/dist/vm/types/value.d.ts.map +0 -1
  206. package/src/vm/lib/global/mod/index.ts +0 -4
  207. package/src/vm/types/any.ts +0 -33
  208. package/src/vm/types/array.ts +0 -19
  209. package/src/vm/types/callable.ts +0 -10
  210. package/src/vm/types/const.ts +0 -109
  211. package/src/vm/types/immutable.ts +0 -22
  212. package/src/vm/types/primitive.ts +0 -14
  213. package/src/vm/types/record.ts +0 -53
  214. package/src/vm/types/script.ts +0 -18
  215. package/src/vm/types/value.ts +0 -22
  216. /package/dist/{chunk-35JGBXRE.js.map → chunk-RIT53WVY.js.map} +0 -0
@@ -1,109 +0,0 @@
1
- import type { VmArray } from './array.js';
2
- import type { VmPrimitive } from './primitive.js';
3
- import type { VmRecord } from './record.js';
4
- import type { VmAny } from './any.js';
5
- import { getPrototypeOf, isArray, values } from '../../helpers/utils.js';
6
- import { isVmWrapper } from './wrapper.js';
7
-
8
- /** Mirascript 虚拟机内的值语义值 */
9
- export type VmConst = VmPrimitive | VmRecord | VmArray;
10
-
11
- const MAX_DEPTH = 32;
12
- /**
13
- * 检查是否为 Mirascript 数组
14
- */
15
- function isVmArrayDeep(value: readonly unknown[], depth: number): value is VmArray {
16
- // VmArray 应为普通数组
17
- // Array.prototype
18
- const proto1: unknown = getPrototypeOf(value);
19
- if (!isArray(proto1)) return false;
20
- if (!depth) return true;
21
- return value.every((item) => isVmConstInner(item, depth));
22
- }
23
- /**
24
- * 检查是否为 Mirascript 记录
25
- */
26
- function isVmRecordDeep(value: object, depth: number): value is VmRecord {
27
- // VmRecord 应为普通对象或空原型对象
28
- let isRecord;
29
- // Object.prototype
30
- const proto1: unknown = getPrototypeOf(value);
31
- if (proto1 == null) {
32
- isRecord = true;
33
- } else {
34
- // null
35
- const proto2: unknown = getPrototypeOf(proto1);
36
- if (proto2 != null) {
37
- isRecord = false;
38
- } else {
39
- isRecord = 'hasOwnProperty' in value;
40
- }
41
- }
42
- if (!isRecord) return false;
43
- if (!depth) return true;
44
- return values(value).every((value) => isVmConstInner(value, depth));
45
- }
46
- /**
47
- * 检查是否为 Mirascript 值语义值
48
- */
49
- function isVmConstInner(value: unknown, depth: number): value is VmConst {
50
- if (depth++ >= MAX_DEPTH) return false;
51
- switch (typeof value) {
52
- case 'string':
53
- case 'number':
54
- case 'boolean':
55
- case 'undefined': // undefined 在复合类型内部被视为 nil
56
- return true;
57
- case 'object':
58
- if (value == null) return true;
59
- if (isVmWrapper(value)) return false;
60
- if (isArray(value)) {
61
- return isVmArrayDeep(value, depth);
62
- } else {
63
- return isVmRecordDeep(value, depth);
64
- }
65
- case 'function':
66
- case 'bigint':
67
- case 'symbol':
68
- default:
69
- return false; // Other types are not valid
70
- }
71
- }
72
-
73
- /**
74
- * 检查是否为 Mirascript 值语义值
75
- */
76
- export function isVmConst(value: VmAny): value is VmConst;
77
- /**
78
- * 检查是否为 Mirascript 值语义值
79
- */
80
- export function isVmConst(value: unknown, checkDeep: boolean): value is VmConst;
81
- /**
82
- * 检查是否为 Mirascript 值语义值
83
- */
84
- export function isVmConst(value: unknown, checkDeep = false): value is VmConst {
85
- switch (typeof value) {
86
- case 'string':
87
- case 'number':
88
- case 'boolean':
89
- return true;
90
- case 'object':
91
- if (value == null) return true;
92
- if (isVmWrapper(value)) return false;
93
- if (!checkDeep) {
94
- if (isArray(value)) {
95
- return isVmArrayDeep(value, 0);
96
- } else {
97
- return isVmRecordDeep(value, 0);
98
- }
99
- } else {
100
- return isVmConstInner(value, 1);
101
- }
102
- case 'undefined':
103
- case 'function':
104
- case 'bigint':
105
- case 'symbol':
106
- default:
107
- return false; // Other types are not valid
108
- }
109
- }
@@ -1,22 +0,0 @@
1
- import type { VmAny } from './any.js';
2
- import { isVmConst, type VmConst } from './const.js';
3
- import { isVmFunction, type VmFunction } from './function.js';
4
- import { isVmModule, type VmModule } from './module.js';
5
-
6
- /** Mirascript 虚拟机内的不可变值 */
7
- export type VmImmutable = VmConst | VmFunction | VmModule;
8
-
9
- /**
10
- * 检查是否为 Mirascript 不可变值
11
- */
12
- export function isVmImmutable(value: VmAny): value is VmImmutable;
13
- /**
14
- * 检查是否为 Mirascript 不可变值
15
- */
16
- export function isVmImmutable(value: unknown, checkDeep: boolean): value is VmImmutable;
17
- /**
18
- * 检查是否为 Mirascript 不可变值
19
- */
20
- export function isVmImmutable(value: unknown, checkDeep = false): value is VmImmutable {
21
- return isVmModule(value) || isVmFunction(value) || isVmConst(value, checkDeep);
22
- }
@@ -1,14 +0,0 @@
1
- /** Mirascript 原始值 */
2
- export type VmPrimitive = null | number | string | boolean;
3
-
4
- /**
5
- * 检查值是否为 Mirascript 原始值
6
- */
7
- export function isVmPrimitive(value: unknown): value is VmPrimitive {
8
- if (value === null || typeof value == 'number' || typeof value == 'string' || typeof value == 'boolean') {
9
- value as VmPrimitive satisfies typeof value;
10
- value satisfies VmPrimitive;
11
- return true;
12
- }
13
- return false;
14
- }
@@ -1,53 +0,0 @@
1
- import { keys } from '../../helpers/utils.js';
2
- import { isVmArray, VM_ARRAY_MAX_LENGTH } from './array.js';
3
- import { isVmWrapper, type VmAny, type VmConst } from './index.js';
4
-
5
- /**
6
- * Mirascript 记录
7
- * 仅拥有且可枚举的字符串键视作存在
8
- * 字段值 `undefined` 和 `null` 均视作 `nil`
9
- */
10
- // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
11
- export type VmRecord = {
12
- readonly [key: string]: VmConst | undefined;
13
- };
14
-
15
- /**
16
- * 检查值是否为 Mirascript 记录
17
- */
18
- export function isVmRecord(value: VmAny): value is VmRecord {
19
- if (value == null || typeof value !== 'object') return false;
20
- if (isVmWrapper(value)) return false;
21
- if (isVmArray(value)) return false;
22
- value satisfies VmRecord;
23
- return true;
24
- }
25
-
26
- /** 检查是否为仅包含从 0 开始的连续数字键的 MiraScript 记录 */
27
- export function isVmArrayLikeRecordByEntires(entries: ReadonlyArray<readonly [string, unknown]>): boolean {
28
- const { length } = entries;
29
- if (length === 0) return true;
30
- if (length > VM_ARRAY_MAX_LENGTH) return false;
31
- const firstKey = entries[0]![0];
32
- if (firstKey !== '0') return false;
33
- const lastKey = entries[length - 1]![0];
34
- if (lastKey !== String(length - 1)) return false;
35
- return true;
36
- }
37
-
38
- /** 检查是否为仅包含从 0 开始的连续数字键的 MiraScript 记录 */
39
- export function isVmArrayLikeRecordByKeys(keys: readonly string[]): boolean {
40
- const { length } = keys;
41
- if (length === 0) return true;
42
- if (length > VM_ARRAY_MAX_LENGTH) return false;
43
- const firstKey = keys[0]!;
44
- if (firstKey !== '0') return false;
45
- const lastKey = keys[length - 1]!;
46
- if (lastKey !== String(length - 1)) return false;
47
- return true;
48
- }
49
-
50
- /** 检查是否为仅包含从 0 开始的连续数字键的 MiraScript 记录 */
51
- export function isVmArrayLikeRecord(value: VmRecord): boolean {
52
- return isVmArrayLikeRecordByKeys(keys(value));
53
- }
@@ -1,18 +0,0 @@
1
- import type { VmContext, VmValue } from './index.js';
2
-
3
- const kVmScript = Symbol.for('mirascript.vm.script');
4
-
5
- /** Mirascript 脚本 */
6
- export type VmScriptLike = (global?: VmContext) => VmValue;
7
-
8
- /** Mirascript 脚本 */
9
- export type VmScript = VmScriptLike & {
10
- readonly [kVmScript]: true;
11
- /** 原始代码 */
12
- readonly source: string;
13
- };
14
-
15
- /** 检查是否为 Mirascript 脚本 */
16
- export function isVmScript(value: unknown): value is VmScript {
17
- return typeof value === 'function' && (value as VmScript)[kVmScript] === true;
18
- }
@@ -1,22 +0,0 @@
1
- import { isVmAny, type VmAny } from './any.js';
2
- import type { VmExtern } from './extern.js';
3
- import type { VmImmutable } from './immutable.js';
4
-
5
- /** Mirascript 虚拟机内的合法值 */
6
- export type VmValue = VmImmutable | VmExtern;
7
-
8
- /**
9
- * 检查是否为 Mirascript 合法值
10
- */
11
- export function isVmValue(value: VmAny): value is VmValue;
12
- /**
13
- * 检查是否为 Mirascript 合法值
14
- */
15
- export function isVmValue(value: unknown, checkDeep: boolean): value is VmValue;
16
- /**
17
- * 检查是否为 Mirascript 合法值
18
- */
19
- export function isVmValue(value: unknown, checkDeep = false): value is VmValue {
20
- if (value === undefined) return false;
21
- return isVmAny(value, checkDeep);
22
- }