xbintsc 0.3.87 → 0.5.6

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 (85) hide show
  1. package/AGENTS.md +8 -4
  2. package/README.md +4 -3
  3. package/README.zh-CN.md +2 -2
  4. package/dist/src/codegen/generator/calls/access.js +6 -2
  5. package/dist/src/codegen/generator/calls/access.js.map +1 -1
  6. package/dist/src/codegen/generator/calls/closures.js +4 -0
  7. package/dist/src/codegen/generator/calls/closures.js.map +1 -1
  8. package/dist/src/codegen/generator/calls/invocation.js +4 -3
  9. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  10. package/dist/src/codegen/generator/expressions/primary.js +6 -1
  11. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  12. package/dist/src/codegen/generator/module.d.ts +0 -1
  13. package/dist/src/codegen/generator/module.js +10 -10
  14. package/dist/src/codegen/generator/module.js.map +1 -1
  15. package/dist/src/codegen/generator/state.js +4 -0
  16. package/dist/src/codegen/generator/state.js.map +1 -1
  17. package/dist/src/codegen/generator/statements/control-flow.js +1 -3
  18. package/dist/src/codegen/generator/statements/control-flow.js.map +1 -1
  19. package/dist/src/codegen/generator/tables.d.ts +9 -0
  20. package/dist/src/codegen/generator/tables.js +74 -2
  21. package/dist/src/codegen/generator/tables.js.map +1 -1
  22. package/dist/src/driver/compiler.d.ts +2 -2
  23. package/dist/src/driver/compiler.js +4 -1
  24. package/dist/src/driver/compiler.js.map +1 -1
  25. package/dist/tests/codegen/closures.test.js +8 -0
  26. package/dist/tests/codegen/closures.test.js.map +1 -1
  27. package/dist/tests/e2e/async-await.test.d.ts +10 -0
  28. package/dist/tests/e2e/async-await.test.js +247 -0
  29. package/dist/tests/e2e/async-await.test.js.map +1 -0
  30. package/dist/tests/e2e/runtime-coverage-globals.test.js +46 -0
  31. package/dist/tests/e2e/runtime-coverage-globals.test.js.map +1 -1
  32. package/dist/tests/e2e/string-utf16.test.d.ts +6 -0
  33. package/dist/tests/e2e/string-utf16.test.js +133 -0
  34. package/dist/tests/e2e/string-utf16.test.js.map +1 -0
  35. package/doc/ai/contributing.md +9 -7
  36. package/doc/ai/extensions.md +3 -2
  37. package/doc/ai/language-support.md +11 -8
  38. package/doc/ai/troubleshooting.md +4 -3
  39. package/doc/ai/zh-CN/contributing.md +5 -5
  40. package/doc/ai/zh-CN/extensions.md +2 -1
  41. package/doc/ai/zh-CN/language-support.md +11 -8
  42. package/doc/ai/zh-CN/troubleshooting.md +3 -2
  43. package/doc/implemented.md +15 -12
  44. package/doc/unimplemented.md +11 -10
  45. package/doc/zh-CN/implemented.md +14 -11
  46. package/doc/zh-CN/unimplemented.md +11 -10
  47. package/package.json +1 -1
  48. package/runtime/rt.h +32 -0
  49. package/runtime/rt_internal.h +99 -10
  50. package/runtime/xt_alloc.c +6 -0
  51. package/runtime/xt_async.c +197 -0
  52. package/runtime/xt_builtins.c +40 -36
  53. package/runtime/xt_constructors.c +389 -0
  54. package/runtime/xt_containers/access.inc +47 -11
  55. package/runtime/xt_containers/arrays.inc +26 -2
  56. package/runtime/xt_containers/objects.inc +202 -5
  57. package/runtime/xt_coroutine.c +212 -0
  58. package/runtime/xt_generator.c +31 -162
  59. package/runtime/xt_io/inspect.inc +35 -2
  60. package/runtime/xt_promise.c +62 -17
  61. package/runtime/xt_stdlib/dispatch.inc +18 -2
  62. package/runtime/xt_stdlib/strings.inc +73 -16
  63. package/runtime/xt_stdlib2/array-statics.inc +3 -3
  64. package/runtime/xt_stdlib2/error.inc +11 -0
  65. package/runtime/xt_stdlib2/json.inc +44 -15
  66. package/runtime/xt_stdlib2/number-string-statics.inc +24 -15
  67. package/runtime/xt_stdlib2/objects.inc +1 -1
  68. package/runtime/xt_stdlib2/regexp-match.inc +2 -2
  69. package/runtime/xt_stdlib2/set.inc +6 -0
  70. package/runtime/xt_stdlib2/strings.inc +70 -40
  71. package/runtime/xt_typed_array/construction.inc +43 -2
  72. package/runtime/xt_typed_array.c +4 -0
  73. package/runtime/xt_values/constructors.inc +8 -0
  74. package/runtime/xt_values/strings.inc +19 -3
  75. package/runtime/xt_values/utf16.inc +340 -0
  76. package/runtime/xt_values.c +1 -0
  77. package/src/codegen/generator/calls/access.ts +7 -2
  78. package/src/codegen/generator/calls/closures.ts +3 -0
  79. package/src/codegen/generator/calls/invocation.ts +4 -3
  80. package/src/codegen/generator/expressions/primary.ts +6 -1
  81. package/src/codegen/generator/module.ts +10 -12
  82. package/src/codegen/generator/state.ts +4 -0
  83. package/src/codegen/generator/statements/control-flow.ts +1 -2
  84. package/src/codegen/generator/tables.ts +84 -2
  85. package/src/driver/compiler.ts +4 -1
@@ -253,6 +253,23 @@ export const NAMESPACE_STATICS: Record<string, string> = {
253
253
  ...TYPED_ARRAY_STATICS,
254
254
  };
255
255
 
256
+ /** The well-known symbols exposed as properties of the `Symbol` namespace. */
257
+ export const SYMBOL_WELL_KNOWN = new Set<string>([
258
+ "asyncIterator",
259
+ "hasInstance",
260
+ "isConcatSpreadable",
261
+ "iterator",
262
+ "match",
263
+ "matchAll",
264
+ "replace",
265
+ "search",
266
+ "species",
267
+ "split",
268
+ "toPrimitive",
269
+ "toStringTag",
270
+ "unscopables",
271
+ ]);
272
+
256
273
  /** Namespace identifiers whose property access maps to a runtime getter. */
257
274
  export const NAMESPACE_PROPERTIES: Record<string, string> = {
258
275
  process: "xt_process_get",
@@ -262,7 +279,7 @@ export const NAMESPACE_PROPERTIES: Record<string, string> = {
262
279
 
263
280
  /** Global constructors called as `new X(...)` (all have signature `(i32, i64*)`). */
264
281
  export const CTOR_FUNCTIONS: Record<string, string> = {
265
- Array: "xt_array_new",
282
+ Array: "xt_array_ctor",
266
283
  Map: "xt_map_ctor",
267
284
  Set: "xt_set_ctor",
268
285
  Date: "xt_date_ctor",
@@ -281,6 +298,30 @@ export const CTOR_FUNCTIONS: Record<string, string> = {
281
298
  ...TYPED_ARRAY_CTORS,
282
299
  };
283
300
 
301
+ /**
302
+ * Built-in constructors that are also ordinary first-class values. The codegen
303
+ * lowers a bare reference (`const A = Array`) to `xt_builtin_constructor`, which
304
+ * returns a cached function with `name`/`length`, a `prototype` and the
305
+ * constructor's statics (`A.isArray`, `A.from`, ...).
306
+ */
307
+ export const FIRST_CLASS_CONSTRUCTORS = new Set<string>([
308
+ "Array",
309
+ "Object",
310
+ "Function",
311
+ "Map",
312
+ "Set",
313
+ "Date",
314
+ "RegExp",
315
+ "Promise",
316
+ ...Object.keys(TYPED_ARRAYS),
317
+ ...Object.keys(ERROR_CONSTRUCTORS),
318
+ "Number",
319
+ "String",
320
+ "Boolean",
321
+ "BigInt",
322
+ "Symbol",
323
+ ]);
324
+
284
325
  export const BUILTIN_METHODS = new Set<string>([
285
326
  "push", "pop", "shift", "unshift", "join", "slice", "indexOf", "includes", "map", "forEach", "filter",
286
327
  "reduce", "concat", "reverse", "charAt", "charCodeAt", "substring", "substr", "split", "toUpperCase",
@@ -394,7 +435,7 @@ export function utf8Bytes(text: string): number[] {
394
435
  if (!hasMultiByteUnit(text)) {
395
436
  const bytes: number[] = [];
396
437
  for (let index = 0; index < text.length; index++) bytes.push(text.charCodeAt(index) & 0xff);
397
- return bytes;
438
+ return combineSurrogateBytes(bytes);
398
439
  }
399
440
  const bytes: number[] = [];
400
441
  const length = text.length;
@@ -420,6 +461,47 @@ function hasMultiByteUnit(text: string): boolean {
420
461
  return false;
421
462
  }
422
463
 
464
+ /**
465
+ * Join adjacent WTF-8 surrogate halves into one four-byte sequence.
466
+ *
467
+ * A literal such as `"\uD83D\uDE00"` scans to two separate three-byte
468
+ * escapes. JavaScript's string value is one code point, so the emitted bytes
469
+ * must be the four-byte UTF-8 form (and a lone escape must stay three bytes,
470
+ * which is why this runs after scanning rather than per escape).
471
+ */
472
+ function combineSurrogateBytes(bytes: number[]): number[] {
473
+ const out: number[] = [];
474
+ for (let index = 0; index < bytes.length; index++) {
475
+ if (
476
+ index + 5 < bytes.length &&
477
+ bytes[index] === 0xed &&
478
+ bytes[index + 1]! >= 0xa0 &&
479
+ bytes[index + 1]! <= 0xaf &&
480
+ bytes[index + 2]! >= 0x80 &&
481
+ bytes[index + 2]! <= 0xbf &&
482
+ bytes[index + 3] === 0xed &&
483
+ bytes[index + 4]! >= 0xb0 &&
484
+ bytes[index + 4]! <= 0xbf &&
485
+ bytes[index + 5]! >= 0x80 &&
486
+ bytes[index + 5]! <= 0xbf
487
+ ) {
488
+ const high = ((bytes[index]! & 0x0f) << 12) | ((bytes[index + 1]! & 0x3f) << 6) | (bytes[index + 2]! & 0x3f);
489
+ const low = ((bytes[index + 3]! & 0x0f) << 12) | ((bytes[index + 4]! & 0x3f) << 6) | (bytes[index + 5]! & 0x3f);
490
+ const code = 0x10000 + ((high - 0xd800) << 10) + (low - 0xdc00);
491
+ out.push(
492
+ 0xf0 | (code >> 18),
493
+ 0x80 | ((code >> 12) & 0x3f),
494
+ 0x80 | ((code >> 6) & 0x3f),
495
+ 0x80 | (code & 0x3f),
496
+ );
497
+ index += 5;
498
+ continue;
499
+ }
500
+ out.push(bytes[index]!);
501
+ }
502
+ return out;
503
+ }
504
+
423
505
  export function escapeBytes(bytes: readonly number[]): string {
424
506
  return bytes
425
507
  .map((byte) => {
@@ -42,7 +42,7 @@ import {
42
42
  * `package.json`); a stale version would let an upgraded compiler reuse binaries
43
43
  * produced by the previous one.
44
44
  */
45
- export const COMPILER_VERSION = "0.3.87";
45
+ export const COMPILER_VERSION = "0.5.6";
46
46
 
47
47
  export type EmitKind = "exe" | "obj" | "ir";
48
48
 
@@ -444,11 +444,14 @@ export const RUNTIME_SOURCES = [
444
444
  "xt_stdlib.c",
445
445
  "xt_stdlib2.c",
446
446
  "xt_promise.c",
447
+ "xt_async.c",
447
448
  "xt_loop.c",
448
449
  "xt_generator.c",
450
+ "xt_coroutine.c",
449
451
  "xt_fetch.c",
450
452
  "xt_symbol.c",
451
453
  "xt_builtins.c",
454
+ "xt_constructors.c",
452
455
  "xt_io.c",
453
456
  ] as const;
454
457