peachsim 0.1.2778 → 0.1.2779

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 (137) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +294 -480
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-RWBIRNWO.mjs → acorn-SCZ56W4Q.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-GSTHJQMW.mjs → chunk-6BNEOOBT.mjs} +114 -18
  28. package/dist-lib/esm-chunks/{chunk-KX7LV722.mjs → chunk-7VWBLM73.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-IQSFMB4R.mjs → chunk-DX5V3733.mjs} +4 -4
  30. package/dist-lib/esm-chunks/{chunk-KBYVKTVK.mjs → chunk-E56EZ3QT.mjs} +3 -3
  31. package/dist-lib/esm-chunks/{chunk-EXU474NE.mjs → chunk-FNQXQNQK.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-3WQANOYY.mjs → chunk-H2V3ZZTO.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-5WASPTSS.mjs → chunk-H6JAFCAZ.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-VZ3NXXUC.mjs → chunk-HMFIO57I.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-6YHF4VYF.mjs → chunk-HWK2V6R4.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-LQVLXDRN.mjs → chunk-KAMO4C4X.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-5TIUTQ55.mjs → chunk-KFDP4372.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-F3OPIKJC.mjs → chunk-KOULWLTF.mjs} +2 -2
  39. package/dist-lib/esm-chunks/{chunk-DLBUPWTI.mjs → chunk-LVEDBGWX.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-X25PQNNH.mjs → chunk-MJXJYVF5.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-QKTKE4OX.mjs → chunk-MK4VAM4G.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-ZWOS2EDN.mjs → chunk-Q6XMYYNV.mjs} +118 -361
  43. package/dist-lib/esm-chunks/{chunk-K3ULPN2R.mjs → chunk-SFTGQN5D.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-KLA74B7J.mjs → chunk-SM5MJSQP.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-G7UJ4BAC.mjs → chunk-SNMGOZXQ.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-MRIDS3GE.mjs → chunk-SZI5IZ76.mjs} +5 -5
  47. package/dist-lib/esm-chunks/{chunk-N2PEXZGL.mjs → chunk-T7DTXCV5.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-ZDWMPXYI.mjs → chunk-UBM772FD.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-QUVLFF6I.mjs → chunk-VJSHIZ7J.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-3RPELUA2.mjs → chunk-Z42YJEC4.mjs} +6 -6
  51. package/dist-lib/esm-chunks/{metro-layout-parser-RRIZOLBE.mjs → metro-layout-parser-7S5M3EG6.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-EIZ7MCKR.mjs → swift-package-prebuilt-MJSFHIOP.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-S2LQ4OXD.mjs → swift-sdk-app-module-ZIN3LFLS.mjs} +47 -69
  54. package/dist-lib/esm-chunks/{swift-sdk-image-77FFUGXI.mjs → swift-sdk-image-MIWPBZEN.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-XFSFUXQJ.mjs → swift-sdk-image-producer-OTH543HF.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +294 -480
  57. package/dist-lib/expo-swift-metadata.cjs +1 -1
  58. package/dist-lib/expo-swift-metadata.mjs +7 -7
  59. package/dist-lib/home-paths.cjs +1 -1
  60. package/dist-lib/host/bridge-host.cjs +300 -486
  61. package/dist-lib/host/fetch-proxy-handler.cjs +22 -11
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +1 -1
  67. package/dist-lib/kotlin-host.cjs +1 -1
  68. package/dist-lib/menu.cjs +1 -1
  69. package/dist-lib/menu.mjs +3 -3
  70. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  71. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  72. package/dist-lib/metro-production-bundle.cjs +1 -1
  73. package/dist-lib/metro-production-bundle.mjs +4 -4
  74. package/dist-lib/native-app-identity-project.cjs +1 -1
  75. package/dist-lib/native-app-identity-project.mjs +15 -15
  76. package/dist-lib/native-app-identity.cjs +1 -1
  77. package/dist-lib/native-app-identity.mjs +6 -6
  78. package/dist-lib/native-firebase-metadata.cjs +1 -1
  79. package/dist-lib/native-firebase-metadata.mjs +3 -3
  80. package/dist-lib/pdfium-raster.cjs +1 -1
  81. package/dist-lib/pdfium-raster.mjs +2 -2
  82. package/dist-lib/plist.cjs +1 -1
  83. package/dist-lib/plist.mjs +3 -3
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/public-origins-lib-esm.json +86 -86
  87. package/dist-lib/public-origins-lib.json +70 -70
  88. package/dist-lib/react-native-host-modules.cjs +1 -1
  89. package/dist-lib/react-native-host-modules.mjs +2 -2
  90. package/dist-lib/reap-browser.cjs +1 -1
  91. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  92. package/dist-lib/sdk.cjs +1 -1
  93. package/dist-lib/sdk.mjs +8 -8
  94. package/dist-lib/skills.cjs +300 -486
  95. package/dist-lib/swift-compile.cjs +287 -465
  96. package/dist-lib/swift-compile.mjs +12 -12
  97. package/dist-lib/swift-package.cjs +1 -1
  98. package/dist-lib/swift-package.mjs +3 -3
  99. package/dist-lib/swift-submit.cjs +1 -1
  100. package/dist-lib/swift-submit.mjs +6 -6
  101. package/dist-lib/swift-svg-raster.cjs +1 -1
  102. package/dist-lib/swift-svg-raster.mjs +2 -2
  103. package/dist-lib/swift-toolchain.cjs +1 -1
  104. package/dist-lib/swift.cjs +1 -1
  105. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  106. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  108. package/dist-lib/vendor/acorn.cjs +1 -1
  109. package/dist-lib/vendor/magic-string.cjs +1 -1
  110. package/dist-lib/vendor/stream-json.cjs +1 -1
  111. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase.cjs +1 -1
  116. package/dist-lib/vendor/terser.cjs +1 -1
  117. package/dist-lib/vendor/valibot.cjs +1 -1
  118. package/dist-lib/vendor/ws.cjs +1 -1
  119. package/dist-lib/vendor/zod.cjs +1 -1
  120. package/dist-lib/worklet-executable.cjs +1 -1
  121. package/dist-lib/worklet-executable.mjs +3 -3
  122. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +15 -2
  123. package/dist-types/packages/peach-engine/src/render-worker/worklet-wire.d.ts +10 -1
  124. package/package.json +1 -1
  125. package/src/swift-compiler-digest.ts +1 -0
  126. package/src/swift-guest-dyld-functions.ts +1 -11
  127. package/src/swift-guest-dyld-table.ts +2 -9
  128. package/src/swift-guest-image-ledger.ts +9 -35
  129. package/src/swift-guest-source-inputs.ts +5 -22
  130. package/src/swift-icu.ts +15 -28
  131. package/src/swift-link-roots.ts +4 -8
  132. package/src/swift-sdk-app-module.ts +5 -27
  133. package/src/swift-sdk-image-wasm.ts +12 -41
  134. package/src/swift-shared-sdk.ts +1 -13
  135. package/src/swift-wasm-archive.ts +6 -11
  136. package/src/swift-wasm-prune.ts +22 -100
  137. package/src/wasm-binary-sections.ts +61 -7
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2778 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2779 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -2707,6 +2707,7 @@ var init_swift_compiler_digest = __esm({
2707
2707
  "swift-objc-prebuilt-catalog.ts",
2708
2708
  "swift-toolchain.ts",
2709
2709
  "swift-shared-sdk.ts",
2710
+ "wasm-binary-sections.ts",
2710
2711
  "swift-distribution-mirror.ts",
2711
2712
  "swift-design-time.ts",
2712
2713
  "binaryen.lock.json",
@@ -4407,6 +4408,111 @@ var init_swift_objc_standin = __esm({
4407
4408
  }
4408
4409
  });
4409
4410
 
4411
+ // src/wasm-binary-sections.ts
4412
+ function encodeWasmNumber(value) {
4413
+ const bytes = [];
4414
+ for (let rest = value; ; ) {
4415
+ const byte = rest % 128;
4416
+ rest = Math.floor(rest / 128);
4417
+ if (rest === 0) return [...bytes, byte];
4418
+ bytes.push(byte | 128);
4419
+ }
4420
+ }
4421
+ function encodeWasmSigned(value) {
4422
+ const out = [];
4423
+ for (; ; ) {
4424
+ const byte = Number(value & 127n);
4425
+ value >>= 7n;
4426
+ if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
4427
+ out.push(byte);
4428
+ return out;
4429
+ }
4430
+ out.push(byte | 128);
4431
+ }
4432
+ }
4433
+ function encodeWasmName(name3) {
4434
+ const bytes = new TextEncoder().encode(name3);
4435
+ return [...encodeWasmNumber(bytes.length), ...bytes];
4436
+ }
4437
+ function readULEB(bytes, offset, end = bytes.length) {
4438
+ if (offset < end) {
4439
+ const first = bytes[offset];
4440
+ if (first < 128) return [first, offset + 1];
4441
+ }
4442
+ let value = 0;
4443
+ for (let shift = 0; ; shift += 7) {
4444
+ if (offset >= end || shift > 63) throw new Error("invalid wasm integer");
4445
+ const byte = bytes[offset++];
4446
+ value += (byte & 127) * 2 ** shift;
4447
+ if (!(byte & 128)) return [value, offset];
4448
+ }
4449
+ }
4450
+ function readSLEB(bytes, offset, end = bytes.length) {
4451
+ let value = 0n;
4452
+ let shift = 0n;
4453
+ let byte = 0;
4454
+ do {
4455
+ if (offset >= end || shift > 70n) throw new Error("invalid wasm integer");
4456
+ byte = bytes[offset++];
4457
+ value |= BigInt(byte & 127) << shift;
4458
+ shift += 7n;
4459
+ } while (byte & 128);
4460
+ if (byte & 64) value -= 1n << shift;
4461
+ return [value, offset];
4462
+ }
4463
+ function skipLEB(bytes, offset) {
4464
+ while ((bytes[offset++] & 128) !== 0) {
4465
+ }
4466
+ return offset;
4467
+ }
4468
+ function readWasmSection(bytes, start, end) {
4469
+ let at = start;
4470
+ const number3 = () => {
4471
+ const [value, next] = readULEB(bytes, at, end);
4472
+ at = next;
4473
+ return value;
4474
+ };
4475
+ return {
4476
+ number: number3,
4477
+ byte: () => {
4478
+ if (at >= end) throw new Error("truncated wasm section");
4479
+ return bytes[at++];
4480
+ },
4481
+ name: () => {
4482
+ const length = number3();
4483
+ at += length;
4484
+ if (at > end) throw new Error("truncated wasm name");
4485
+ return Buffer.from(bytes.buffer, bytes.byteOffset + at - length, length).toString();
4486
+ },
4487
+ skip: (length) => {
4488
+ at += length;
4489
+ if (at > end) throw new Error("truncated wasm section");
4490
+ },
4491
+ position: () => at,
4492
+ done: () => at === end
4493
+ };
4494
+ }
4495
+ function wasmSections(bytes) {
4496
+ if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
4497
+ throw new Error("not a wasm module");
4498
+ const found = [];
4499
+ for (let at = 8; at < bytes.length; ) {
4500
+ const header = readWasmSection(bytes, at, bytes.length);
4501
+ const id = header.byte();
4502
+ const size = header.number();
4503
+ const start = header.position();
4504
+ if (start + size > bytes.length) throw new Error("truncated wasm section");
4505
+ found.push({ id, offset: at, start, end: start + size });
4506
+ at = start + size;
4507
+ }
4508
+ return found;
4509
+ }
4510
+ var init_wasm_binary_sections = __esm({
4511
+ "src/wasm-binary-sections.ts"() {
4512
+ "use strict";
4513
+ }
4514
+ });
4515
+
4410
4516
  // src/swift-shared-sdk.ts
4411
4517
  function swiftSharedSdkSourceRoot(moduleRoot, distribution) {
4412
4518
  return import_node_path11.default.resolve(moduleRoot, distribution ? "sdk/ios" : "../peachsim/sdk/ios");
@@ -4457,18 +4563,6 @@ function swiftSharedSdkFlags(moduleRoot, distribution) {
4457
4563
  import_node_path11.default.join(root, "usr/include")
4458
4564
  ];
4459
4565
  }
4460
- function readULEB(b, o) {
4461
- let res = 0;
4462
- let shift = 0;
4463
- let p = o;
4464
- while (true) {
4465
- const byte = b[p++];
4466
- res |= (byte & 127) << shift;
4467
- if ((byte & 128) === 0) break;
4468
- shift += 7;
4469
- }
4470
- return [res, p];
4471
- }
4472
4566
  function weakenFoundationSymbolsInWasmObj(buf) {
4473
4567
  let pos = 8;
4474
4568
  while (pos < buf.length) {
@@ -4833,6 +4927,7 @@ var init_swift_shared_sdk = __esm({
4833
4927
  import_node_path11 = __toESM(require("node:path"), 1);
4834
4928
  init_swift_toolchain();
4835
4929
  init_swiftTargetContract();
4930
+ init_wasm_binary_sections();
4836
4931
  SWIFT_DISTRIBUTION_MIRROR_RECORD = ".peach-mirror.json";
4837
4932
  distributionHeaderRoots = /* @__PURE__ */ new Map();
4838
4933
  WEAKEN_FOUNDATION_SYMS = /* @__PURE__ */ new Set([
@@ -6424,16 +6519,12 @@ var init_swift_link_roots = __esm({
6424
6519
  "use strict";
6425
6520
  import_node_fs14 = __toESM(require("node:fs"), 1);
6426
6521
  import_node_path15 = __toESM(require("node:path"), 1);
6522
+ init_wasm_binary_sections();
6427
6523
  OBJC_RUNTIME_LOOKUP_SECTION = "peach_objc_runtime_lookup";
6428
6524
  leb = (bytes, at) => {
6429
- let value = 0;
6430
- let scale = 1;
6431
- for (; ; ) {
6432
- const byte = bytes[at.offset++];
6433
- value += (byte & 127) * scale;
6434
- if (!(byte & 128)) return value;
6435
- scale *= 128;
6436
- }
6525
+ const [value, next] = readULEB(bytes, at.offset);
6526
+ at.offset = next;
6527
+ return value;
6437
6528
  };
6438
6529
  rootsByDistribution = /* @__PURE__ */ new Map();
6439
6530
  }
@@ -7262,68 +7353,6 @@ var init_swift_guest_linked_spans = __esm({
7262
7353
  }
7263
7354
  });
7264
7355
 
7265
- // src/wasm-binary-sections.ts
7266
- function encodeWasmNumber(value) {
7267
- const bytes = [];
7268
- for (let rest = value; ; ) {
7269
- const byte = rest % 128;
7270
- rest = Math.floor(rest / 128);
7271
- if (rest === 0) return [...bytes, byte];
7272
- bytes.push(byte | 128);
7273
- }
7274
- }
7275
- function encodeWasmName(name3) {
7276
- const bytes = new TextEncoder().encode(name3);
7277
- return [...encodeWasmNumber(bytes.length), ...bytes];
7278
- }
7279
- function readWasmSection(bytes, start, end) {
7280
- let at = start;
7281
- const number3 = () => {
7282
- let value = 0;
7283
- for (let shift = 0; ; shift += 7) {
7284
- if (at >= end || shift > 63) throw new Error("invalid wasm integer");
7285
- const byte = bytes[at++];
7286
- value += (byte & 127) * 2 ** shift;
7287
- if (!(byte & 128)) return value;
7288
- }
7289
- };
7290
- return {
7291
- number: number3,
7292
- byte: () => {
7293
- if (at >= end) throw new Error("truncated wasm section");
7294
- return bytes[at++];
7295
- },
7296
- name: () => {
7297
- const length = number3();
7298
- at += length;
7299
- if (at > end) throw new Error("truncated wasm name");
7300
- return Buffer.from(bytes.buffer, bytes.byteOffset + at - length, length).toString();
7301
- },
7302
- position: () => at,
7303
- done: () => at === end
7304
- };
7305
- }
7306
- function wasmSections(bytes) {
7307
- if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
7308
- throw new Error("not a wasm module");
7309
- const found = [];
7310
- for (let at = 8; at < bytes.length; ) {
7311
- const header = readWasmSection(bytes, at, bytes.length);
7312
- const id = header.byte();
7313
- const size = header.number();
7314
- const start = header.position();
7315
- if (start + size > bytes.length) throw new Error("truncated wasm section");
7316
- found.push({ id, offset: at, start, end: start + size });
7317
- at = start + size;
7318
- }
7319
- return found;
7320
- }
7321
- var init_wasm_binary_sections = __esm({
7322
- "src/wasm-binary-sections.ts"() {
7323
- "use strict";
7324
- }
7325
- });
7326
-
7327
7356
  // src/wasm-imports.ts
7328
7357
  function readWasmImports(bytes, section2, visit) {
7329
7358
  const input = readWasmSection(bytes, section2.start, section2.end);
@@ -7607,23 +7636,13 @@ function wasmReader(bytes, start) {
7607
7636
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
7608
7637
  let at = start;
7609
7638
  const u = () => {
7610
- let value = 0;
7611
- for (let shift = 0; ; shift += 7) {
7612
- const byte = bytes[at++];
7613
- value += (byte & 127) * 2 ** shift;
7614
- if (!(byte & 128)) return value;
7615
- }
7639
+ const [value, next] = readULEB(bytes, at);
7640
+ at = next;
7641
+ return value;
7616
7642
  };
7617
7643
  const s = () => {
7618
- let value = 0n;
7619
- let shift = 0n;
7620
- let byte = 0;
7621
- do {
7622
- byte = bytes[at++];
7623
- value |= BigInt(byte & 127) << shift;
7624
- shift += 7n;
7625
- } while (byte & 128);
7626
- if (byte & 64) value -= 1n << shift;
7644
+ const [value, next] = readSLEB(bytes, at);
7645
+ at = next;
7627
7646
  return value;
7628
7647
  };
7629
7648
  return {
@@ -7928,7 +7947,7 @@ function finishSdkImage(bytes, hostExports, libraries, guestMap) {
7928
7947
  else data[entry.name] = value;
7929
7948
  }
7930
7949
  if (entry.kind !== 0 && entry.kind !== 3 || host2.has(entry.name))
7931
- kept.push([...encodedName(entry.name), entry.kind, ...uleb(entry.index)]);
7950
+ kept.push([...encodeWasmName(entry.name), entry.kind, ...encodeWasmNumber(entry.index)]);
7932
7951
  }
7933
7952
  if (guestMap) {
7934
7953
  if (guestMap.code.length !== m.bodies.length)
@@ -7943,19 +7962,19 @@ function finishSdkImage(bytes, hostExports, libraries, guestMap) {
7943
7962
  const er = wasmReader(bytes, elements.start);
7944
7963
  const segments = er.u();
7945
7964
  const replaced = /* @__PURE__ */ new Map([
7946
- [4, [1, 112, 4, ...uleb(tableEnd + added.length)]],
7947
- [7, [...uleb(kept.length), ...kept.flat()]],
7965
+ [4, [1, 112, 4, ...encodeWasmNumber(tableEnd + added.length)]],
7966
+ [7, [...encodeWasmNumber(kept.length), ...kept.flat()]],
7948
7967
  [
7949
7968
  9,
7950
7969
  [
7951
- ...uleb(segments + 1),
7970
+ ...encodeWasmNumber(segments + 1),
7952
7971
  ...bytes.subarray(er.at, elements.end),
7953
7972
  0,
7954
7973
  66,
7955
- ...sleb(BigInt(tableEnd)),
7974
+ ...encodeWasmSigned(BigInt(tableEnd)),
7956
7975
  11,
7957
- ...uleb(added.length),
7958
- ...added.flatMap(uleb)
7976
+ ...encodeWasmNumber(added.length),
7977
+ ...added.flatMap(encodeWasmNumber)
7959
7978
  ]
7960
7979
  ]
7961
7980
  ]);
@@ -8061,33 +8080,33 @@ function codeOnlySdkImage(bytes, constructorMask) {
8061
8080
  if (drop) r.skip(1);
8062
8081
  gated.push(
8063
8082
  66,
8064
- ...sleb(BigInt(constructorMask + index++)),
8083
+ ...encodeWasmSigned(BigInt(constructorMask + index++)),
8065
8084
  45,
8066
8085
  0,
8067
8086
  0,
8068
8087
  4,
8069
8088
  64,
8070
8089
  16,
8071
- ...uleb(callee),
8090
+ ...encodeWasmNumber(callee),
8072
8091
  ...drop ? [26] : [],
8073
8092
  11
8074
8093
  );
8075
8094
  }
8076
8095
  if (index > SWIFT_SDK_CONSTRUCTOR_LIMIT)
8077
8096
  throw new Error(`${index} sdk constructors exceed the mask`);
8078
- gated.push(16, ...uleb(functionIndex("__peach_sdk_register")), 11);
8097
+ gated.push(16, ...encodeWasmNumber(functionIndex("__peach_sdk_register")), 11);
8079
8098
  bodies[constructors] = Uint8Array.from(gated);
8080
8099
  }
8081
- const codeParts = [Uint8Array.from(uleb(bodies.length))];
8082
- for (const body of bodies) codeParts.push(Uint8Array.from(uleb(body.length)), body);
8100
+ const codeParts = [Uint8Array.from(encodeWasmNumber(bodies.length))];
8101
+ for (const body of bodies) codeParts.push(Uint8Array.from(encodeWasmNumber(body.length)), body);
8083
8102
  const codeSize = codeParts.reduce((sum, part) => sum + part.length, 0);
8084
8103
  const tls = passiveSegments(bytes)[0];
8085
8104
  const out = [bytes.subarray(0, 8)];
8086
8105
  for (const s of m.sections) {
8087
8106
  if (s.id === 10) {
8088
- out.push(Uint8Array.from([10, ...uleb(codeSize)]));
8107
+ out.push(Uint8Array.from([10, ...encodeWasmNumber(codeSize)]));
8089
8108
  for (const part of codeParts) out.push(part);
8090
- } else if (s.id === 11) out.push(section(11, [1, 1, ...uleb(tls.length), ...tls]));
8109
+ } else if (s.id === 11) out.push(section(11, [1, 1, ...encodeWasmNumber(tls.length), ...tls]));
8091
8110
  else if (s.id === 12) out.push(section(12, [1]));
8092
8111
  else out.push(bytes.subarray(s.offset, s.end));
8093
8112
  }
@@ -8404,39 +8423,14 @@ function unslottedFunctions(bytes) {
8404
8423
  }
8405
8424
  return definedFuncs - slotted.size;
8406
8425
  }
8407
- var uleb, sleb, encodedName, section, PROCESS_EXPORTS, SWIFT_SDK_CONSTRUCTOR_LIMIT, FUNCTION_RELOCATIONS, MEMORY_RELOCATIONS, ADDEND_RELOCATIONS, FUNCTION_RELOC_MASK, MEMORY_RELOC_MASK, ADDEND_RELOC_MASK;
8426
+ var section, PROCESS_EXPORTS, SWIFT_SDK_CONSTRUCTOR_LIMIT, FUNCTION_RELOCATIONS, MEMORY_RELOCATIONS, ADDEND_RELOCATIONS, FUNCTION_RELOC_MASK, MEMORY_RELOC_MASK, ADDEND_RELOC_MASK;
8408
8427
  var init_swift_sdk_image_wasm = __esm({
8409
8428
  "src/swift-sdk-image-wasm.ts"() {
8410
8429
  "use strict";
8411
8430
  init_swift_sdk_image_map();
8412
8431
  init_swiftSdkLinkContract();
8413
- uleb = (value) => {
8414
- const out = [];
8415
- do {
8416
- let byte = value % 128;
8417
- value = Math.floor(value / 128);
8418
- if (value) byte |= 128;
8419
- out.push(byte);
8420
- } while (value);
8421
- return out;
8422
- };
8423
- sleb = (value) => {
8424
- const out = [];
8425
- for (; ; ) {
8426
- const byte = Number(value & 127n);
8427
- value >>= 7n;
8428
- if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
8429
- out.push(byte);
8430
- return out;
8431
- }
8432
- out.push(byte | 128);
8433
- }
8434
- };
8435
- encodedName = (name3) => {
8436
- const bytes = [...Buffer.from(name3)];
8437
- return [...uleb(bytes.length), ...bytes];
8438
- };
8439
- section = (id, payload) => Uint8Array.from([id, ...uleb(payload.length), ...payload]);
8432
+ init_wasm_binary_sections();
8433
+ section = (id, payload) => Uint8Array.from([id, ...encodeWasmNumber(payload.length), ...payload]);
8440
8434
  PROCESS_EXPORTS = [
8441
8435
  "_initialize",
8442
8436
  "__wasm_call_ctors",
@@ -8539,45 +8533,11 @@ function readArMembers(buf, includeBitcode = false) {
8539
8533
  var init_swift_wasm_archive = __esm({
8540
8534
  "src/swift-wasm-archive.ts"() {
8541
8535
  "use strict";
8536
+ init_wasm_binary_sections();
8542
8537
  }
8543
8538
  });
8544
8539
 
8545
8540
  // src/swift-wasm-prune.ts
8546
- function readULEB2(b, o) {
8547
- let res = 0;
8548
- let shift = 0;
8549
- let p = o;
8550
- while (true) {
8551
- const byte = b[p++];
8552
- res |= (byte & 127) << shift;
8553
- if ((byte & 128) === 0) break;
8554
- shift += 7;
8555
- }
8556
- return [res, p];
8557
- }
8558
- function readSLEB(b, o) {
8559
- let res = 0;
8560
- let shift = 0;
8561
- let p = o;
8562
- let byte = 0;
8563
- do {
8564
- byte = b[p++];
8565
- res |= (byte & 127) << shift;
8566
- shift += 7;
8567
- } while (byte & 128);
8568
- if (shift < 32 && byte & 64) res |= ~0 << shift;
8569
- return [res, p];
8570
- }
8571
- function encodeULEB(val) {
8572
- const out = [];
8573
- do {
8574
- let byte = val & 127;
8575
- val >>>= 7;
8576
- if (val !== 0) byte |= 128;
8577
- out.push(byte);
8578
- } while (val !== 0);
8579
- return out;
8580
- }
8581
8541
  function isRootSegName(name3) {
8582
8542
  for (const pref of ROOT_SEG_PREFIXES) {
8583
8543
  if (name3 === pref || name3.startsWith(`${pref}.`)) return true;
@@ -8603,39 +8563,14 @@ function decodeRelocations(buf, sections) {
8603
8563
  for (let k = 0; k < sectionCount; k++, i++) {
8604
8564
  start[i] = length + cur - baseAt;
8605
8565
  const rType = buf[cur++];
8606
- let offset = buf[cur++];
8607
- if (offset >= 128) {
8608
- offset &= 127;
8609
- let shift = 7;
8610
- while (true) {
8611
- const byte = buf[cur++];
8612
- offset |= (byte & 127) << shift;
8613
- if (byte < 128) break;
8614
- shift += 7;
8615
- }
8616
- }
8617
- let symbol = buf[cur++];
8618
- if (symbol >= 128) {
8619
- symbol &= 127;
8620
- let shift = 7;
8621
- while (true) {
8622
- const byte = buf[cur++];
8623
- symbol |= (byte & 127) << shift;
8624
- if (byte < 128) break;
8625
- shift += 7;
8626
- }
8627
- }
8566
+ let offset;
8567
+ [offset, cur] = readULEB(buf, cur);
8568
+ let symbol;
8569
+ [symbol, cur] = readULEB(buf, cur);
8628
8570
  if (rType < 32 && (ADDEND_RELOC_MASK2 & 1 << rType) !== 0) {
8629
- let byte = buf[cur++];
8630
- let value = byte & 127;
8631
- let shift = 7;
8632
- while (byte >= 128) {
8633
- byte = buf[cur++];
8634
- value |= (byte & 127) << shift;
8635
- shift += 7;
8636
- }
8637
- if (shift < 32 && (byte & 64) !== 0) value |= ~0 << shift;
8638
- addend[i] = value;
8571
+ let value;
8572
+ [value, cur] = readSLEB(buf, cur);
8573
+ addend[i] = Number(BigInt.asIntN(32, value));
8639
8574
  }
8640
8575
  ro[i] = offset;
8641
8576
  rs[i] = symbol;
@@ -8670,36 +8605,36 @@ function patchSwiftrtObject(src) {
8670
8605
  let pos = 8;
8671
8606
  while (pos < buf.length) {
8672
8607
  const id = buf[pos++];
8673
- const [sz, p] = readULEB2(buf, pos);
8608
+ const [sz, p] = readULEB(buf, pos);
8674
8609
  const end = p + sz;
8675
8610
  if (id === 0) {
8676
- const [nLen, np] = readULEB2(buf, p);
8611
+ const [nLen, np] = readULEB(buf, p);
8677
8612
  const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
8678
8613
  const cp = np + nLen;
8679
8614
  if (name3 === "linking") {
8680
- let [, lp] = readULEB2(buf, cp);
8615
+ let [, lp] = readULEB(buf, cp);
8681
8616
  while (lp < end) {
8682
8617
  const subId = buf[lp++];
8683
- const [subLen, sp] = readULEB2(buf, lp);
8618
+ const [subLen, sp] = readULEB(buf, lp);
8684
8619
  const subEnd = sp + subLen;
8685
8620
  if (subId === 8) {
8686
- let [cnt, cur] = readULEB2(buf, sp);
8621
+ let [cnt, cur] = readULEB(buf, sp);
8687
8622
  for (let i = 0; i < cnt; i++) {
8688
8623
  const kind = buf[cur++];
8689
8624
  const flPos = cur;
8690
- const [fl, c2] = readULEB2(buf, cur);
8625
+ const [fl, c2] = readULEB(buf, cur);
8691
8626
  cur = c2;
8692
8627
  const isUndef = (fl & 16) !== 0;
8693
8628
  const isExplicitName = (fl & 64) !== 0;
8694
8629
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
8695
- const [, c3] = readULEB2(buf, cur);
8630
+ const [, c3] = readULEB(buf, cur);
8696
8631
  cur = c3;
8697
8632
  if (!isUndef || isExplicitName) {
8698
- const [sLen, c4] = readULEB2(buf, cur);
8633
+ const [sLen, c4] = readULEB(buf, cur);
8699
8634
  cur = c4 + sLen;
8700
8635
  }
8701
8636
  } else if (kind === 1) {
8702
- const [sLen, c3] = readULEB2(buf, cur);
8637
+ const [sLen, c3] = readULEB(buf, cur);
8703
8638
  const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString("utf8");
8704
8639
  if (sName === "_ZN12_GLOBAL__N_18sectionsE") fallbackSymIdx = i;
8705
8640
  for (const prefix of ["__start_", "__stop_"]) {
@@ -8711,13 +8646,13 @@ function patchSwiftrtObject(src) {
8711
8646
  }
8712
8647
  cur = c3 + sLen;
8713
8648
  if (!isUndef) {
8714
- const [, c4] = readULEB2(buf, cur);
8715
- const [, c5] = readULEB2(buf, c4);
8716
- const [, c6] = readULEB2(buf, c5);
8649
+ const [, c4] = readULEB(buf, cur);
8650
+ const [, c5] = readULEB(buf, c4);
8651
+ const [, c6] = readULEB(buf, c5);
8717
8652
  cur = c6;
8718
8653
  }
8719
8654
  } else if (kind === 3) {
8720
- const [, c3] = readULEB2(buf, cur);
8655
+ const [, c3] = readULEB(buf, cur);
8721
8656
  cur = c3;
8722
8657
  }
8723
8658
  }
@@ -8731,26 +8666,25 @@ function patchSwiftrtObject(src) {
8731
8666
  pos = 8;
8732
8667
  while (pos < buf.length) {
8733
8668
  const id = buf[pos++];
8734
- const [sz, p] = readULEB2(buf, pos);
8669
+ const [sz, p] = readULEB(buf, pos);
8735
8670
  const end = p + sz;
8736
8671
  if (id === 0) {
8737
- const [nLen, np] = readULEB2(buf, p);
8672
+ const [nLen, np] = readULEB(buf, p);
8738
8673
  const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
8739
8674
  const cp = np + nLen;
8740
8675
  if (name3 === "reloc.CODE") {
8741
- const [, r1] = readULEB2(buf, cp);
8742
- let [cnt, cur] = readULEB2(buf, r1);
8676
+ const [, r1] = readULEB(buf, cp);
8677
+ let [cnt, cur] = readULEB(buf, r1);
8743
8678
  for (let i = 0; i < cnt; i++) {
8744
8679
  const rType = buf[cur++];
8745
- const [, c2] = readULEB2(buf, cur);
8746
- const [rs, c3] = readULEB2(buf, c2);
8680
+ const [, c2] = readULEB(buf, cur);
8681
+ const [rs, c3] = readULEB(buf, c2);
8747
8682
  if (neutralizedSyms.has(rs) && c3 - c2 === 1) {
8748
8683
  buf[c2] = fallbackSymIdx;
8749
8684
  }
8750
8685
  cur = c3;
8751
8686
  if (ADDEND_RELOCATIONS.has(rType)) {
8752
- const [, c4] = readSLEB(buf, cur);
8753
- cur = c4;
8687
+ cur = skipLEB(buf, cur);
8754
8688
  }
8755
8689
  }
8756
8690
  }
@@ -8764,25 +8698,14 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
8764
8698
  let pos = 8;
8765
8699
  let cur = 8;
8766
8700
  const readU = () => {
8767
- const b0 = buf[cur++];
8768
- if (b0 < 128) return b0;
8769
- let res = b0 & 127;
8770
- let shift = 7;
8771
- while (true) {
8772
- const byte = buf[cur++];
8773
- res |= (byte & 127) << shift;
8774
- if (byte < 128) return res;
8775
- shift += 7;
8776
- }
8701
+ const [res, next] = readULEB(buf, cur);
8702
+ cur = next;
8703
+ return res;
8777
8704
  };
8778
8705
  const skipU = () => {
8779
- while (buf[cur++] >= 128) {
8780
- }
8781
- };
8782
- const skipS = () => {
8783
- while (buf[cur++] >= 128) {
8784
- }
8706
+ cur = skipLEB(buf, cur);
8785
8707
  };
8708
+ const skipS = skipU;
8786
8709
  let numImportFuncs = 0;
8787
8710
  let importsDlsym = false;
8788
8711
  const importFuncNames = [];
@@ -9380,16 +9303,9 @@ function guestWasmSymbols(bytes) {
9380
9303
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
9381
9304
  let cur = 8;
9382
9305
  const readU = () => {
9383
- const b0 = bytes[cur++];
9384
- if (b0 < 128) return b0;
9385
- let res = b0 & 127;
9386
- let shift = 7;
9387
- while (true) {
9388
- const byte = bytes[cur++];
9389
- res |= (byte & 127) << shift;
9390
- if ((byte & 128) === 0) return res;
9391
- shift += 7;
9392
- }
9306
+ const [res, next] = readULEB(bytes, cur);
9307
+ cur = next;
9308
+ return res;
9393
9309
  };
9394
9310
  let importsDlsym = false;
9395
9311
  const importFuncNames = [];
@@ -10530,7 +10446,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
10530
10446
  if (!deadSpecialSegs.has(sIdx)) continue;
10531
10447
  if (!isSpecialSegRelocLive(obj, obj.segNames[sIdx], data.rs[i])) continue;
10532
10448
  const first = relocationBytes(data, i);
10533
- const [, afterRoOff] = readULEB2(first, 1);
10449
+ const [, afterRoOff] = readULEB(first, 1);
10534
10450
  firstLiveInSpecialSeg.set(sIdx, {
10535
10451
  rType: first[0],
10536
10452
  afterRo: first.subarray(afterRoOff)
@@ -10560,7 +10476,7 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
10560
10476
  zeroDataReloc(i);
10561
10477
  } else {
10562
10478
  const repl = firstLiveInSpecialSeg.get(segIdx);
10563
- const roBytes = encodeULEB(data.ro[i]);
10479
+ const roBytes = encodeWasmNumber(data.ro[i]);
10564
10480
  const out = new Uint8Array(1 + roBytes.length + repl.afterRo.length);
10565
10481
  out[0] = repl.rType;
10566
10482
  out.set(roBytes, 1);
@@ -10599,34 +10515,34 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
10599
10515
  while (pos < buf.length) {
10600
10516
  const secStart = pos;
10601
10517
  const id = buf[pos++];
10602
- const [sz, p] = readULEB2(buf, pos);
10518
+ const [sz, p] = readULEB(buf, pos);
10603
10519
  const end = p + sz;
10604
10520
  if (id === 0) {
10605
- const [nLen, np] = readULEB2(buf, p);
10521
+ const [nLen, np] = readULEB(buf, p);
10606
10522
  const name3 = rawBuf.toString("utf8", np, np + nLen);
10607
10523
  const cp = np + nLen;
10608
10524
  if (name3 === "linking") {
10609
- const [, lpStart] = readULEB2(buf, cp);
10525
+ const [, lpStart] = readULEB(buf, cp);
10610
10526
  const subChunks = [buf.subarray(p, lpStart)];
10611
10527
  let lp = lpStart;
10612
10528
  while (lp < end) {
10613
10529
  const subStart = lp;
10614
10530
  const subId = buf[lp++];
10615
- const [subLen, sp] = readULEB2(buf, lp);
10531
+ const [subLen, sp] = readULEB(buf, lp);
10616
10532
  const subEnd = sp + subLen;
10617
10533
  if (subId === 5) {
10618
10534
  const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
10619
- let [cnt, cur] = readULEB2(buf, sp);
10535
+ let [cnt, cur] = readULEB(buf, sp);
10620
10536
  for (let i = 0; i < cnt; i++) {
10621
- const [sLen, s2] = readULEB2(buf, cur);
10537
+ const [sLen, s2] = readULEB(buf, cur);
10622
10538
  const segName = obj.segNames[i];
10623
10539
  const repl = RECORD_SEGS.get(segName);
10624
10540
  const isSpecial = repl !== void 0;
10625
10541
  if (deadSpecialSegs.has(i) && repl !== void 0)
10626
10542
  subCopy.set(Buffer.from(repl, "utf8"), s2 - subStart);
10627
10543
  cur = s2 + sLen;
10628
- const [, s3] = readULEB2(buf, cur);
10629
- const [segFl, s4] = readULEB2(buf, s3);
10544
+ const [, s3] = readULEB(buf, cur);
10545
+ const [segFl, s4] = readULEB(buf, s3);
10630
10546
  const sFlLen = s4 - s3;
10631
10547
  const keepRetain = isSpecial ? !deadSpecialSegs.has(i) : isRootSegName(segName) && !segName.startsWith(".init_array") && sLive[i] === 1;
10632
10548
  const newSegFl = keepRetain ? segFl | 4 : segFl & ~4;
@@ -10640,12 +10556,12 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
10640
10556
  }
10641
10557
  subChunks.push(subCopy);
10642
10558
  } else if (subId === 6) {
10643
- let [cnt, cur] = readULEB2(buf, sp);
10559
+ let [cnt, cur] = readULEB(buf, sp);
10644
10560
  const entrySlices = [];
10645
10561
  for (let i = 0; i < cnt; i++) {
10646
10562
  const eStart = cur;
10647
- const [, s2] = readULEB2(buf, cur);
10648
- const [symIdx, s3] = readULEB2(buf, s2);
10563
+ const [, s2] = readULEB(buf, cur);
10564
+ const [symIdx, s3] = readULEB(buf, s2);
10649
10565
  cur = s3;
10650
10566
  if (obj.symKind[symIdx] === 0 && obj.symElemIdx[symIdx] >= obj.numImportFuncs) {
10651
10567
  if (fLive[obj.symElemIdx[symIdx] - obj.numImportFuncs] === 1) {
@@ -10656,19 +10572,19 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
10656
10572
  }
10657
10573
  }
10658
10574
  if (entrySlices.length > 0) {
10659
- const cntBytes = Uint8Array.from(encodeULEB(entrySlices.length));
10575
+ const cntBytes = Uint8Array.from(encodeWasmNumber(entrySlices.length));
10660
10576
  const bodyLen = cntBytes.length + entrySlices.reduce((a, b) => a + b.length, 0);
10661
- const lenBytes = Uint8Array.from(encodeULEB(bodyLen));
10577
+ const lenBytes = Uint8Array.from(encodeWasmNumber(bodyLen));
10662
10578
  subChunks.push(Uint8Array.of(6), lenBytes, cntBytes);
10663
10579
  for (const entry of entrySlices) subChunks.push(entry);
10664
10580
  }
10665
10581
  } else if (subId === 8) {
10666
10582
  const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
10667
- let [cnt, cur] = readULEB2(buf, sp);
10583
+ let [cnt, cur] = readULEB(buf, sp);
10668
10584
  for (let i = 0; i < cnt; i++) {
10669
10585
  const kind = buf[cur++];
10670
10586
  const flOffset = cur - subStart;
10671
- const [fl, c2] = readULEB2(buf, cur);
10587
+ const [fl, c2] = readULEB(buf, cur);
10672
10588
  cur = c2;
10673
10589
  const isUndef = (fl & 16) !== 0;
10674
10590
  const isExplicitName = (fl & 64) !== 0;
@@ -10688,23 +10604,23 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
10688
10604
  subCopy[flOffset + 1] = 0;
10689
10605
  }
10690
10606
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
10691
- const [, c3] = readULEB2(buf, cur);
10607
+ const [, c3] = readULEB(buf, cur);
10692
10608
  cur = c3;
10693
10609
  if (!isUndef || isExplicitName) {
10694
- const [sLen, c4] = readULEB2(buf, cur);
10610
+ const [sLen, c4] = readULEB(buf, cur);
10695
10611
  cur = c4 + sLen;
10696
10612
  }
10697
10613
  } else if (kind === 1) {
10698
- const [sLen, c3] = readULEB2(buf, cur);
10614
+ const [sLen, c3] = readULEB(buf, cur);
10699
10615
  cur = c3 + sLen;
10700
10616
  if (!isUndef) {
10701
- const [, c4] = readULEB2(buf, cur);
10702
- const [, c5] = readULEB2(buf, c4);
10703
- const [, c6] = readULEB2(buf, c5);
10617
+ const [, c4] = readULEB(buf, cur);
10618
+ const [, c5] = readULEB(buf, c4);
10619
+ const [, c6] = readULEB(buf, c5);
10704
10620
  cur = c6;
10705
10621
  }
10706
10622
  } else if (kind === 3) {
10707
- const [, c3] = readULEB2(buf, cur);
10623
+ const [, c3] = readULEB(buf, cur);
10708
10624
  cur = c3;
10709
10625
  }
10710
10626
  }
@@ -10715,29 +10631,29 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
10715
10631
  lp = subEnd;
10716
10632
  }
10717
10633
  const totalSubLen = subChunks.reduce((a, b) => a + b.length, 0);
10718
- outChunks.push(Uint8Array.of(0), Uint8Array.from(encodeULEB(totalSubLen)));
10634
+ outChunks.push(Uint8Array.of(0), Uint8Array.from(encodeWasmNumber(totalSubLen)));
10719
10635
  for (const chunk of subChunks) outChunks.push(chunk);
10720
10636
  } else if (name3 === "reloc.CODE") {
10721
- const [, r1] = readULEB2(buf, cp);
10637
+ const [, r1] = readULEB(buf, cp);
10722
10638
  const headerSlice = buf.subarray(p, r1);
10723
- const cntBytes = Uint8Array.from(encodeULEB(keptCodeRelocs.length));
10639
+ const cntBytes = Uint8Array.from(encodeWasmNumber(keptCodeRelocs.length));
10724
10640
  const relSlices = keptCodeRelocs.map((i) => relocationBytes(code, i));
10725
10641
  const totalLen = headerSlice.length + cntBytes.length + relSlices.reduce((a, b) => a + b.length, 0);
10726
10642
  outChunks.push(
10727
10643
  Uint8Array.of(0),
10728
- Uint8Array.from(encodeULEB(totalLen)),
10644
+ Uint8Array.from(encodeWasmNumber(totalLen)),
10729
10645
  headerSlice,
10730
10646
  cntBytes
10731
10647
  );
10732
10648
  for (const relocation of relSlices) outChunks.push(relocation);
10733
10649
  } else if (name3 === "reloc.DATA") {
10734
- const [, r1] = readULEB2(buf, cp);
10650
+ const [, r1] = readULEB(buf, cp);
10735
10651
  const headerSlice = buf.subarray(p, r1);
10736
- const cntBytes = Uint8Array.from(encodeULEB(keptDataRelocBytes.length));
10652
+ const cntBytes = Uint8Array.from(encodeWasmNumber(keptDataRelocBytes.length));
10737
10653
  const totalLen = headerSlice.length + cntBytes.length + keptDataRelocBytes.reduce((a, b) => a + b.length, 0);
10738
10654
  outChunks.push(
10739
10655
  Uint8Array.of(0),
10740
- Uint8Array.from(encodeULEB(totalLen)),
10656
+ Uint8Array.from(encodeWasmNumber(totalLen)),
10741
10657
  headerSlice,
10742
10658
  cntBytes
10743
10659
  );
@@ -10747,15 +10663,15 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
10747
10663
  const nameBytes = buf.subarray(p, cp);
10748
10664
  outChunks.push(
10749
10665
  Uint8Array.of(0),
10750
- Uint8Array.from(encodeULEB(nameBytes.length)),
10666
+ Uint8Array.from(encodeWasmNumber(nameBytes.length)),
10751
10667
  nameBytes
10752
10668
  );
10753
10669
  } else if (name3.startsWith("reloc..debug_")) {
10754
- const [, r1] = readULEB2(buf, cp);
10670
+ const [, r1] = readULEB(buf, cp);
10755
10671
  const headerSlice = buf.subarray(p, r1);
10756
10672
  outChunks.push(
10757
10673
  Uint8Array.of(0),
10758
- Uint8Array.from(encodeULEB(headerSlice.length + 1)),
10674
+ Uint8Array.from(encodeWasmNumber(headerSlice.length + 1)),
10759
10675
  headerSlice,
10760
10676
  Uint8Array.of(0)
10761
10677
  );
@@ -10885,6 +10801,7 @@ var init_swift_wasm_prune = __esm({
10885
10801
  init_swift_toolchain();
10886
10802
  init_swift_wasm_archive();
10887
10803
  init_swiftRuntimeProductContract();
10804
+ init_wasm_binary_sections();
10888
10805
  WIDE_DATA_RELOCS = /* @__PURE__ */ new Set([16, 19, 22, 27]);
10889
10806
  ROOT_SEG_PREFIXES = [
10890
10807
  ".init_array",
@@ -11107,34 +11024,11 @@ var init_nativeWasmContract = __esm({
11107
11024
  });
11108
11025
 
11109
11026
  // src/swift-guest-image-ledger.ts
11110
- function readNumber(bytes, position) {
11111
- if (position < bytes.length) {
11112
- const first = bytes[position];
11113
- if (first < 128) return [first, position + 1];
11114
- }
11115
- let value = 0;
11116
- let shift = 0;
11117
- for (; ; ) {
11118
- if (position >= bytes.length || shift > 63) throw new Error("invalid wasm integer");
11119
- const byte = bytes[position++];
11120
- value += (byte & 127) * 2 ** shift;
11121
- if (!(byte & 128)) return [value, position];
11122
- shift += 7;
11123
- }
11124
- }
11125
11027
  function encodeNumber(value) {
11126
- if (value < 128) return Buffer.from([value]);
11127
- const bytes = [];
11128
- do {
11129
- let byte = value % 128;
11130
- value = Math.floor(value / 128);
11131
- if (value) byte |= 128;
11132
- bytes.push(byte);
11133
- } while (value);
11134
- return Buffer.from(bytes);
11028
+ return Buffer.from(encodeWasmNumber(value));
11135
11029
  }
11136
11030
  function readString(bytes, position) {
11137
- const [length, start] = readNumber(bytes, position);
11031
+ const [length, start] = readULEB(bytes, position);
11138
11032
  if (start + length > bytes.length) throw new Error("invalid wasm string");
11139
11033
  return [
11140
11034
  Buffer.from(bytes.buffer, bytes.byteOffset + start, length).toString("utf8"),
@@ -11460,13 +11354,13 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
11460
11354
  for (const subsection of subsections) {
11461
11355
  if (subsection.kind === 6 && objcLoader !== void 0) {
11462
11356
  const content = subsection.parts[0];
11463
- const [count, entriesStart] = readNumber(content, 0);
11357
+ const [count, entriesStart] = readULEB(content, 0);
11464
11358
  const initWriter = new ByteWriter(content.length + 16);
11465
11359
  initWriter.bytes(content, 0, entriesStart);
11466
11360
  let entryStart = entriesStart;
11467
11361
  for (let i = 0; i < count; i++) {
11468
- const [, symbolStart] = readNumber(content, entryStart);
11469
- const [symbol, entryEnd] = readNumber(content, symbolStart);
11362
+ const [, symbolStart] = readULEB(content, entryStart);
11363
+ const [symbol, entryEnd] = readULEB(content, symbolStart);
11470
11364
  if (symbol === objcLoader) {
11471
11365
  initWriter.uleb(1);
11472
11366
  initWriter.bytes(content, symbolStart, entryEnd);
@@ -11536,7 +11430,7 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
11536
11430
  if (position < bytes.length && bytes[position] < 128) {
11537
11431
  size = bytes[position++];
11538
11432
  } else {
11539
- const [val, next] = readNumber(bytes, position);
11433
+ const [val, next] = readULEB(bytes, position);
11540
11434
  size = val;
11541
11435
  position = next;
11542
11436
  }
@@ -12292,7 +12186,7 @@ function nameGuestImageAliases(wasm, symbols) {
12292
12186
  const parts = [wasm.subarray(0, 8)];
12293
12187
  let position = 8;
12294
12188
  while (position < wasm.length) {
12295
- const [size, start] = readNumber(wasm, position + 1);
12189
+ const [size, start] = readULEB(wasm, position + 1);
12296
12190
  const end = start + size;
12297
12191
  const custom = wasm[position] === 0 ? readString(wasm, start) : void 0;
12298
12192
  if (custom?.[0] !== "name") {
@@ -12303,17 +12197,17 @@ function nameGuestImageAliases(wasm, symbols) {
12303
12197
  const subsections = [encodedString("name")];
12304
12198
  let at = custom[1];
12305
12199
  while (at < end) {
12306
- const [subSize, subStart] = readNumber(wasm, at + 1);
12200
+ const [subSize, subStart] = readULEB(wasm, at + 1);
12307
12201
  const subEnd = subStart + subSize;
12308
12202
  if (wasm[at] !== 1) {
12309
12203
  subsections.push(wasm.subarray(at, subEnd));
12310
12204
  at = subEnd;
12311
12205
  continue;
12312
12206
  }
12313
- let [count, cursor] = readNumber(wasm, subStart);
12207
+ let [count, cursor] = readULEB(wasm, subStart);
12314
12208
  const entries2 = [encodeNumber(count)];
12315
12209
  for (; count > 0; count--) {
12316
- const [index, next] = readNumber(wasm, cursor);
12210
+ const [index, next] = readULEB(wasm, cursor);
12317
12211
  const [name3, after] = readString(wasm, next);
12318
12212
  cursor = after;
12319
12213
  const symbol = symbols[Number(alias.exec(name3)?.[1] ?? -1)];
@@ -12337,6 +12231,7 @@ var init_swift_guest_image_ledger = __esm({
12337
12231
  init_nativeWasmContract();
12338
12232
  init_swift_sdk_image_wasm();
12339
12233
  init_swiftSdkLinkContract();
12234
+ init_wasm_binary_sections();
12340
12235
  ByteWriter = class {
12341
12236
  buf;
12342
12237
  pos = 0;
@@ -12357,16 +12252,13 @@ var init_swift_guest_image_ledger = __esm({
12357
12252
  this.buf[this.pos++] = value;
12358
12253
  }
12359
12254
  uleb(value) {
12360
- this.ensure(10);
12361
- let pos = this.pos;
12362
- const buf = this.buf;
12363
- do {
12364
- let byte = value % 128;
12365
- value = Math.floor(value / 128);
12366
- if (value) byte |= 128;
12367
- buf[pos++] = byte;
12368
- } while (value);
12369
- this.pos = pos;
12255
+ if (value < 128) {
12256
+ this.byte(value);
12257
+ return;
12258
+ }
12259
+ const encoded = encodeWasmNumber(value);
12260
+ this.ensure(encoded.length);
12261
+ for (let i = 0; i < encoded.length; i++) this.buf[this.pos++] = encoded[i];
12370
12262
  }
12371
12263
  bytes(source, start = 0, end = source.length) {
12372
12264
  const len = end - start;
@@ -12702,13 +12594,6 @@ function sha256Buffer(bytes) {
12702
12594
  return Buffer.from(new Bun.CryptoHasher("sha256").update(bytes).digest());
12703
12595
  return (0, import_node_crypto12.createHash)("sha256").update(bytes).digest();
12704
12596
  }
12705
- function uleb2(value) {
12706
- const bytes = [];
12707
- for (let rest = value; ; rest = Math.floor(rest / 128)) {
12708
- if (rest < 128) return [...bytes, rest];
12709
- bytes.push(rest % 128 | 128);
12710
- }
12711
- }
12712
12597
  function encodeGuestDyldTable(rows) {
12713
12598
  const encoded = rows.map((row) => ({ ...row, bytes: Buffer.from(row.name) })).sort((a, b) => Buffer.compare(a.bytes, b.bytes));
12714
12599
  const packs = [];
@@ -12721,7 +12606,7 @@ function encodeGuestDyldTable(rows) {
12721
12606
  value.writeBigUInt64LE(row.value);
12722
12607
  const bytes = Buffer.concat([
12723
12608
  row.bytes,
12724
- Buffer.from([0, ...uleb2(row.image), row.kind]),
12609
+ Buffer.from([0, ...encodeWasmNumber(row.image), row.kind]),
12725
12610
  value
12726
12611
  ]);
12727
12612
  if (!current.length) firsts.push(row.bytes);
@@ -12798,6 +12683,7 @@ var init_swift_guest_dyld_table = __esm({
12798
12683
  init_sha256();
12799
12684
  init_swift_guest_image_ledger();
12800
12685
  init_swift_guest_linked_spans();
12686
+ init_wasm_binary_sections();
12801
12687
  init_wasm_narrow_boundary();
12802
12688
  PACK_BYTES = 64 * 1024;
12803
12689
  }
@@ -12873,8 +12759,8 @@ function readImports2(bytes, sections) {
12873
12759
  return { functions, table64 };
12874
12760
  }
12875
12761
  function vectorSection(id, count, parts) {
12876
- const body = Buffer.concat([Buffer.from(uleb3(count)), ...parts]);
12877
- return Buffer.concat([Buffer.from([id, ...uleb3(body.length)]), body]);
12762
+ const body = Buffer.concat([Buffer.from(encodeWasmNumber(count)), ...parts]);
12763
+ return Buffer.concat([Buffer.from([id, ...encodeWasmNumber(body.length)]), body]);
12878
12764
  }
12879
12765
  function rewriteSections(bytes, sections, changes) {
12880
12766
  const out = [bytes.subarray(0, 8)];
@@ -12930,9 +12816,9 @@ function appendLazyPlacement(bytes, functions, table) {
12930
12816
  vectorSection(2, count + 1, [
12931
12817
  found && header ? bytes.subarray(header.at, found.end) : new Uint8Array(),
12932
12818
  Buffer.from([
12933
- ...uleb3(module2.length),
12819
+ ...encodeWasmNumber(module2.length),
12934
12820
  ...module2,
12935
- ...uleb3(name4.length),
12821
+ ...encodeWasmNumber(name4.length),
12936
12822
  ...name4,
12937
12823
  1,
12938
12824
  112,
@@ -12954,7 +12840,7 @@ function appendLazyPlacement(bytes, functions, table) {
12954
12840
  elements.splice(
12955
12841
  placementIndex,
12956
12842
  0,
12957
- Buffer.from([1, 0, ...uleb3(functions.length), ...functions.flatMap(uleb3)])
12843
+ Buffer.from([1, 0, ...encodeWasmNumber(functions.length), ...functions.flatMap(encodeWasmNumber)])
12958
12844
  );
12959
12845
  const place2 = imports.functions + declared.length;
12960
12846
  const instructions = [
@@ -12968,7 +12854,7 @@ function appendLazyPlacement(bytes, functions, table) {
12968
12854
  1,
12969
12855
  252,
12970
12856
  12,
12971
- ...uleb3(placementIndex),
12857
+ ...encodeWasmNumber(placementIndex),
12972
12858
  0,
12973
12859
  11
12974
12860
  ];
@@ -12989,14 +12875,14 @@ function appendLazyPlacement(bytes, functions, table) {
12989
12875
  3,
12990
12876
  vectorSection(3, declared.length + 1, [
12991
12877
  ...declared,
12992
- Buffer.from(uleb3(types.length))
12878
+ Buffer.from(encodeWasmNumber(types.length))
12993
12879
  ])
12994
12880
  ],
12995
12881
  [
12996
12882
  7,
12997
12883
  vectorSection(7, exports2.length + 1, [
12998
12884
  ...exports2,
12999
- Buffer.from([...uleb3(name3.length), ...name3, 0, ...uleb3(place2)])
12885
+ Buffer.from([...encodeWasmNumber(name3.length), ...name3, 0, ...encodeWasmNumber(place2)])
13000
12886
  ])
13001
12887
  ],
13002
12888
  [9, vectorSection(9, elements.length, elements)],
@@ -13004,7 +12890,7 @@ function appendLazyPlacement(bytes, functions, table) {
13004
12890
  10,
13005
12891
  vectorSection(10, bodies.length + 1, [
13006
12892
  ...bodies,
13007
- Buffer.from([...uleb3(instructions.length), ...instructions])
12893
+ Buffer.from([...encodeWasmNumber(instructions.length), ...instructions])
13008
12894
  ])
13009
12895
  ]
13010
12896
  ])
@@ -13057,22 +12943,13 @@ function placeGuestLazyFunctions(bytes, lazy) {
13057
12943
  function guestLazyExports(lazy) {
13058
12944
  return lazy.map((name3) => JSON.stringify(`--export=${name3}`)).join("\n");
13059
12945
  }
13060
- var uleb3, SECTION_ORDER, readExport, lastTableElement;
12946
+ var SECTION_ORDER, readExport, lastTableElement;
13061
12947
  var init_swift_guest_dyld_functions = __esm({
13062
12948
  "src/swift-guest-dyld-functions.ts"() {
13063
12949
  "use strict";
13064
12950
  init_nativeWasmContract();
13065
12951
  init_swift_sdk_image_wasm();
13066
- uleb3 = (value) => {
13067
- const out = [];
13068
- do {
13069
- let byte = value % 128;
13070
- value = Math.floor(value / 128);
13071
- if (value) byte |= 128;
13072
- out.push(byte);
13073
- } while (value);
13074
- return out;
13075
- };
12952
+ init_wasm_binary_sections();
13076
12953
  SECTION_ORDER = [1, 2, 3, 4, 5, 13, 6, 7, 8, 9, 12, 10, 11];
13077
12954
  readExport = (r) => {
13078
12955
  r.name();
@@ -16739,30 +16616,12 @@ function wasmAutolinkEntries(bytes, out) {
16739
16616
  const len = bytes.length;
16740
16617
  while (pos < len) {
16741
16618
  const id = bytes[pos++];
16742
- let sz = bytes[pos++];
16743
- if (sz >= 128) {
16744
- sz &= 127;
16745
- let shift = 7;
16746
- while (true) {
16747
- const b = bytes[pos++];
16748
- sz |= (b & 127) << shift;
16749
- if (b < 128) break;
16750
- shift += 7;
16751
- }
16752
- }
16619
+ let sz;
16620
+ [sz, pos] = readULEB(bytes, pos, len);
16753
16621
  const end = pos + sz;
16754
16622
  if (id === 0) {
16755
- let nLen = bytes[pos++];
16756
- if (nLen >= 128) {
16757
- nLen &= 127;
16758
- let shift = 7;
16759
- while (true) {
16760
- const b = bytes[pos++];
16761
- nLen |= (b & 127) << shift;
16762
- if (b < 128) break;
16763
- shift += 7;
16764
- }
16765
- }
16623
+ let nLen;
16624
+ [nLen, pos] = readULEB(bytes, pos, end);
16766
16625
  if (nLen === 24 && raw2.toString("ascii", pos, pos + 24) === ".swift1_autolink_entries") {
16767
16626
  const payload = raw2.toString("utf8", pos + 24, end);
16768
16627
  for (const entry of payload.split("\0")) {
@@ -16999,6 +16858,7 @@ var init_swift_guest_source_inputs = __esm({
16999
16858
  init_swift_guest_source_plan();
17000
16859
  init_swift_runtime_products();
17001
16860
  init_swift_wasm_prune();
16861
+ init_wasm_binary_sections();
17002
16862
  CLANG_TARGET_MODULE_WRAPPER = ".peach-clang";
17003
16863
  PARALLEL_REPLAY = `
17004
16864
  const { spawn } = require('node:child_process')
@@ -20710,8 +20570,8 @@ function finishSwiftAppModuleFile(file) {
20710
20570
  return;
20711
20571
  }
20712
20572
  const thunks = sdkImportThunks(prefix);
20713
- const nameBytes = Buffer.from(encodedName2(NATIVE_SDK_THUNK_SECTION));
20714
- const header = Buffer.from([0, ...uleb4(nameBytes.length + thunks.length)]);
20573
+ const nameBytes = Buffer.from(encodeWasmName(NATIVE_SDK_THUNK_SECTION));
20574
+ const header = Buffer.from([0, ...encodeWasmNumber(nameBytes.length + thunks.length)]);
20715
20575
  (0, import_node_fs38.appendFileSync)(file, Buffer.concat([header, nameBytes, thunks]));
20716
20576
  }
20717
20577
  function swiftAppModuleInputs(tokens, buildRoot, sdkLibraries) {
@@ -21063,17 +20923,17 @@ function sdkImportThunks(bytes) {
21063
20923
  for (const { type } of imports)
21064
20924
  if (!typeIndex.has(type)) typeIndex.set(type, typeIndex.size + 1);
21065
20925
  const loaderType = [96, 1, 127, 0];
21066
- const vector = (items) => [...uleb4(items.length), ...items.flat()];
21067
- const sectionBytes = (id, body) => [id, ...uleb4(body.length), ...body];
20926
+ const vector = (items) => [...encodeWasmNumber(items.length), ...items.flat()];
20927
+ const sectionBytes = (id, body) => [id, ...encodeWasmNumber(body.length), ...body];
21068
20928
  const slotGlobals = imports.map(({ slot }) => [
21069
- ...encodedName2(NATIVE_SDK_IMPORT_MODULE),
21070
- ...encodedName2(String(slot)),
20929
+ ...encodeWasmName(NATIVE_SDK_IMPORT_MODULE),
20930
+ ...encodeWasmName(String(slot)),
21071
20931
  3,
21072
20932
  127,
21073
20933
  0
21074
20934
  ]);
21075
20935
  const bodies = imports.map(({ type }, index) => {
21076
- const slotValue = [35, ...uleb4(index)];
20936
+ const slotValue = [35, ...encodeWasmNumber(index)];
21077
20937
  const code = [
21078
20938
  0,
21079
20939
  ...slotValue,
@@ -21086,14 +20946,14 @@ function sdkImportThunks(bytes) {
21086
20946
  16,
21087
20947
  0,
21088
20948
  11,
21089
- ...Array.from({ length: params[type] }, (_, i) => [32, ...uleb4(i)]).flat(),
20949
+ ...Array.from({ length: params[type] }, (_, i) => [32, ...encodeWasmNumber(i)]).flat(),
21090
20950
  ...slotValue,
21091
20951
  17,
21092
- ...uleb4(typeIndex.get(type)),
20952
+ ...encodeWasmNumber(typeIndex.get(type)),
21093
20953
  0,
21094
20954
  11
21095
20955
  ];
21096
- return [...uleb4(code.length), ...code];
20956
+ return [...encodeWasmNumber(code.length), ...code];
21097
20957
  });
21098
20958
  return Uint8Array.from([
21099
20959
  0,
@@ -21111,21 +20971,21 @@ function sdkImportThunks(bytes) {
21111
20971
  ...sectionBytes(
21112
20972
  2,
21113
20973
  vector([
21114
- [...encodedName2("env"), ...encodedName2("__indirect_function_table"), 1, ...table],
20974
+ [...encodeWasmName("env"), ...encodeWasmName("__indirect_function_table"), 1, ...table],
21115
20975
  [
21116
- ...encodedName2(NATIVE_LAZY_IMPORT_MODULE),
21117
- ...encodedName2(NATIVE_LAZY_SLOT_IMPORT),
20976
+ ...encodeWasmName(NATIVE_LAZY_IMPORT_MODULE),
20977
+ ...encodeWasmName(NATIVE_LAZY_SLOT_IMPORT),
21118
20978
  0,
21119
20979
  0
21120
20980
  ],
21121
20981
  ...slotGlobals
21122
20982
  ])
21123
20983
  ),
21124
- ...sectionBytes(3, vector(imports.map(({ type }) => uleb4(typeIndex.get(type))))),
20984
+ ...sectionBytes(3, vector(imports.map(({ type }) => encodeWasmNumber(typeIndex.get(type))))),
21125
20985
  ...sectionBytes(
21126
20986
  7,
21127
20987
  vector(
21128
- imports.map(({ slot }, i) => [...encodedName2(String(slot)), 0, ...uleb4(i + 1)])
20988
+ imports.map(({ slot }, i) => [...encodeWasmName(String(slot)), 0, ...encodeWasmNumber(i + 1)])
21129
20989
  )
21130
20990
  ),
21131
20991
  ...sectionBytes(10, vector(bodies))
@@ -21245,7 +21105,7 @@ function resolveSdkReferences(source, sdk, forwarders) {
21245
21105
  syntheticGlobals.push(type);
21246
21106
  got.set(index, value);
21247
21107
  }
21248
- return [35, ...uleb4(index)];
21108
+ return [35, ...encodeWasmNumber(index)];
21249
21109
  };
21250
21110
  const tlsHelpers = new Map(
21251
21111
  symbols.filter((symbol) => symbol.kind === 0 && symbol.name.startsWith(SDK_TLS_HELPER)).map((symbol) => [symbol.name.slice(SDK_TLS_HELPER.length), symbol.index])
@@ -21297,7 +21157,7 @@ function resolveSdkReferences(source, sdk, forwarders) {
21297
21157
  const code = [16];
21298
21158
  for (let i = 0, rest = helper; i < 5; i++, rest >>>= 7)
21299
21159
  code.push(i < 4 ? rest & 127 | 128 : rest & 127);
21300
- if (addend) code.push(66, ...sleb2(addend), 124);
21160
+ if (addend) code.push(66, ...encodeWasmSigned(addend), 124);
21301
21161
  patchCode(at2, 11, code);
21302
21162
  continue;
21303
21163
  }
@@ -21371,7 +21231,7 @@ function resolveSdkReferences(source, sdk, forwarders) {
21371
21231
  syntheticGlobals.push(valueType);
21372
21232
  scratchGlobals.set(valueType, scratch2);
21373
21233
  }
21374
- const index = uleb4(scratch2);
21234
+ const index = encodeWasmNumber(scratch2);
21375
21235
  patchCode(at - 2, 12, [
21376
21236
  36,
21377
21237
  ...index,
@@ -21387,7 +21247,7 @@ function resolveSdkReferences(source, sdk, forwarders) {
21387
21247
  }
21388
21248
  const encodedNameBuf = (name3) => {
21389
21249
  const raw2 = Buffer.from(name3, "utf8");
21390
- const len = uleb4(raw2.length);
21250
+ const len = encodeWasmNumber(raw2.length);
21391
21251
  const out = Buffer.allocUnsafe(len.length + raw2.length);
21392
21252
  for (let i = 0; i < len.length; i++) out[i] = len[i];
21393
21253
  raw2.copy(out, len.length);
@@ -21432,7 +21292,7 @@ function resolveSdkReferences(source, sdk, forwarders) {
21432
21292
  }
21433
21293
  }
21434
21294
  const globalParts = [
21435
- Buffer.from(uleb4(globalCount - 1 + syntheticGlobals.length))
21295
+ Buffer.from(encodeWasmNumber(globalCount - 1 + syntheticGlobals.length))
21436
21296
  ];
21437
21297
  for (let index = 0; index < globalCount; index++) {
21438
21298
  const start = gr.at;
@@ -21477,18 +21337,18 @@ function resolveSdkReferences(source, sdk, forwarders) {
21477
21337
  }
21478
21338
  }
21479
21339
  const exportParts = [
21480
- Buffer.from(uleb4(exportCount + 1 + got.size)),
21340
+ Buffer.from(encodeWasmNumber(exportCount + 1 + got.size)),
21481
21341
  bytes.subarray(originalExportsStart, exportSection.end)
21482
21342
  ];
21483
21343
  for (const [index, value] of got) {
21484
21344
  exportParts.push(
21485
21345
  encodedNameBuf(`${NATIVE_SDK_GLOBAL_PREFIX}${value}.${index}`),
21486
- Buffer.from([3, ...uleb4(index)])
21346
+ Buffer.from([3, ...encodeWasmNumber(index)])
21487
21347
  );
21488
21348
  }
21489
21349
  exportParts.push(encodedNameBuf("__indirect_function_table"), Buffer.from([1, 0]));
21490
21350
  const replaced = /* @__PURE__ */ new Map([
21491
- [2, Buffer.concat([Buffer.from(uleb4(importEntryCount)), ...importParts])],
21351
+ [2, Buffer.concat([Buffer.from(encodeWasmNumber(importEntryCount)), ...importParts])],
21492
21352
  [6, Buffer.concat(globalParts)],
21493
21353
  [7, Buffer.concat(exportParts)]
21494
21354
  ]);
@@ -21505,7 +21365,7 @@ function resolveSdkReferences(source, sdk, forwarders) {
21505
21365
  if (s.id === 10 && rebuiltCode) {
21506
21366
  parts.push(rebuiltCode);
21507
21367
  } else if (payload) {
21508
- parts.push(Buffer.from([s.id, ...uleb4(payload.length)]), payload);
21368
+ parts.push(Buffer.from([s.id, ...encodeWasmNumber(payload.length)]), payload);
21509
21369
  } else {
21510
21370
  parts.push(bytes.subarray(s.offset, s.end));
21511
21371
  }
@@ -21521,7 +21381,7 @@ function expandSdkRelocations(bytes, section2, patches) {
21521
21381
  patches.sort((a, b) => a.at - b.at);
21522
21382
  const r = wasmReader(bytes, section2.start);
21523
21383
  const count = r.u();
21524
- const payload = [Uint8Array.from(uleb4(count))];
21384
+ const payload = [Uint8Array.from(encodeWasmNumber(count))];
21525
21385
  let next = 0;
21526
21386
  for (let i = 0; i < count; i++) {
21527
21387
  const start = r.at;
@@ -21541,7 +21401,7 @@ function expandSdkRelocations(bytes, section2, patches) {
21541
21401
  }
21542
21402
  parts.push(bytes.subarray(at, end));
21543
21403
  payload.push(
21544
- Uint8Array.from(uleb4(parts.reduce((size2, part) => size2 + part.length, 0))),
21404
+ Uint8Array.from(encodeWasmNumber(parts.reduce((size2, part) => size2 + part.length, 0))),
21545
21405
  ...parts
21546
21406
  );
21547
21407
  }
@@ -21550,7 +21410,7 @@ function expandSdkRelocations(bytes, section2, patches) {
21550
21410
  if (next !== patches.length || r.at !== section2.end)
21551
21411
  throw new Error("Swift SDK code relocations exceed the code section");
21552
21412
  return Buffer.concat([
21553
- Uint8Array.from([10, ...uleb4(payload.reduce((size, part) => size + part.length, 0))]),
21413
+ Uint8Array.from([10, ...encodeWasmNumber(payload.reduce((size, part) => size + part.length, 0))]),
21554
21414
  ...payload
21555
21415
  ]);
21556
21416
  }
@@ -22242,7 +22102,7 @@ function partitionParent(section2) {
22242
22102
  "__objc_class_refs"
22243
22103
  ].find((name3) => section2 === name3 || section2.startsWith(`${name3}.`));
22244
22104
  }
22245
- var import_node_child_process25, import_node_crypto27, import_node_fs38, import_node_path38, import_node_util8, import_node_zlib4, run3, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, uleb4, sleb2, encodedName2, SCANNED, RUN_GAP;
22105
+ var import_node_child_process25, import_node_crypto27, import_node_fs38, import_node_path38, import_node_util8, import_node_zlib4, run3, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, SCANNED, RUN_GAP;
22246
22106
  var init_swift_sdk_app_module = __esm({
22247
22107
  "src/swift-sdk-app-module.ts"() {
22248
22108
  "use strict";
@@ -22265,6 +22125,7 @@ var init_swift_sdk_app_module = __esm({
22265
22125
  init_swift_wasm_prune();
22266
22126
  init_swiftSdkLinkContract();
22267
22127
  init_swiftTargetContract();
22128
+ init_wasm_binary_sections();
22268
22129
  init_wasm_narrow_boundary();
22269
22130
  init_wasm_optimize();
22270
22131
  run3 = (0, import_node_util8.promisify)(import_node_child_process25.execFile);
@@ -22285,32 +22146,6 @@ var init_swift_sdk_app_module = __esm({
22285
22146
  SDK_TLS_HELPER = "__peach_sdk_tls.";
22286
22147
  SDK_TLS_DELTA = "__peach_sdk_tls_delta.";
22287
22148
  OBJC_SECTION_BOUNDARY = /^__(?:start|stop)_(__objc_(?:selectors|classes|class_refs|cats|protocols|protocol_refs|class_aliases|constant_string))$/;
22288
- uleb4 = (value) => {
22289
- const out = [];
22290
- do {
22291
- let byte = value % 128;
22292
- value = Math.floor(value / 128);
22293
- if (value) byte |= 128;
22294
- out.push(byte);
22295
- } while (value);
22296
- return out;
22297
- };
22298
- sleb2 = (value) => {
22299
- const out = [];
22300
- for (; ; ) {
22301
- const byte = Number(value & 127n);
22302
- value >>= 7n;
22303
- if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
22304
- out.push(byte);
22305
- return out;
22306
- }
22307
- out.push(byte | 128);
22308
- }
22309
- };
22310
- encodedName2 = (name3) => {
22311
- const bytes = [...Buffer.from(name3)];
22312
- return [...uleb4(bytes.length), ...bytes];
22313
- };
22314
22149
  SCANNED = /* @__PURE__ */ new Set([
22315
22150
  "swift5_protocols",
22316
22151
  "swift5_protocol_conformances",
@@ -23438,36 +23273,22 @@ function archiveMember(archive, name3) {
23438
23273
  throw new Error(`swift-icu: ${name3} is not in the sdk's icu archive`);
23439
23274
  }
23440
23275
  function icuSegment(object4) {
23441
- let at = 8;
23442
- const leb2 = () => {
23443
- let result = 0;
23444
- let shift = 0;
23445
- let byte;
23446
- do {
23447
- byte = object4[at++];
23448
- result += (byte & 127) * 2 ** shift;
23449
- shift += 7;
23450
- } while (byte & 128);
23451
- return result;
23452
- };
23453
23276
  const found = [];
23454
- while (at < object4.length) {
23455
- const id = object4[at++];
23456
- const size = leb2();
23457
- const end = at + size;
23458
- if (id === 11) {
23459
- for (let count = leb2(); count > 0; count--) {
23460
- if (leb2() !== 0) throw new Error("swift-icu: unexpected data segment kind");
23461
- at++;
23462
- leb2();
23463
- at++;
23464
- const length = leb2();
23465
- const bytes = object4.subarray(at, at + length);
23466
- if (bytes[2] === 218 && bytes[3] === 39) found.push(bytes);
23467
- at += length;
23468
- }
23469
- }
23470
- at = end;
23277
+ for (const section2 of wasmSections(object4)) {
23278
+ if (section2.id !== 11) continue;
23279
+ const reader = readWasmSection(object4, section2.start, section2.end);
23280
+ for (let count = reader.number(); count > 0; count--) {
23281
+ if (reader.number() !== 0)
23282
+ throw new Error("swift-icu: unexpected data segment kind");
23283
+ reader.byte();
23284
+ reader.number();
23285
+ reader.byte();
23286
+ const length = reader.number();
23287
+ const start = reader.position();
23288
+ const bytes = object4.subarray(start, start + length);
23289
+ if (bytes[2] === 218 && bytes[3] === 39) found.push(bytes);
23290
+ reader.skip(length);
23291
+ }
23471
23292
  }
23472
23293
  if (found.length !== 1)
23473
23294
  throw new Error(`swift-icu: expected one icu data segment, found ${found.length}`);
@@ -23521,6 +23342,7 @@ var init_swift_icu = __esm({
23521
23342
  init_icuData();
23522
23343
  init_swift_toolchain();
23523
23344
  init_swiftTargetContract();
23345
+ init_wasm_binary_sections();
23524
23346
  run4 = (0, import_node_util9.promisify)(import_node_child_process27.execFile);
23525
23347
  deflate = (0, import_node_util9.promisify)(import_node_zlib5.gzip);
23526
23348
  compressBrotli = (0, import_node_util9.promisify)(import_node_zlib5.brotliCompress);
@@ -30374,7 +30196,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
30374
30196
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
30375
30197
  MULTI_MANIFEST_VERSION = 76;
30376
30198
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
30377
- compilerSourceDigest = true ? "3bdbb1d31ba7d202e612a91b60a3b588f9bc94a11990fb114585b3e2521857f5" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
30199
+ compilerSourceDigest = true ? "816651f27c8e6bad4746f2f90d840446903e3c4a2384095dcdf1c9ceb69ceba8" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
30378
30200
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
30379
30201
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
30380
30202
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));