peachsim 0.1.2778 → 0.1.2780

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 (139) 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 +295 -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-SPK2673W.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-ZWOS2EDN.mjs → chunk-3BAOVPYB.mjs} +118 -361
  28. package/dist-lib/esm-chunks/{chunk-MRIDS3GE.mjs → chunk-664T7XWT.mjs} +5 -5
  29. package/dist-lib/esm-chunks/{chunk-QKTKE4OX.mjs → chunk-7B4ZRXZW.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-G7UJ4BAC.mjs → chunk-7UJZBQ6G.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-EXU474NE.mjs → chunk-B4DO5WJD.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-IQSFMB4R.mjs → chunk-DO3C6MOG.mjs} +4 -4
  33. package/dist-lib/esm-chunks/{chunk-K3ULPN2R.mjs → chunk-DZZZCBJY.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-5TIUTQ55.mjs → chunk-EEN3DGCH.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-ZDWMPXYI.mjs → chunk-JIGACUAS.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-X25PQNNH.mjs → chunk-JIKQAODQ.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-6YHF4VYF.mjs → chunk-MIESONPY.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-3RPELUA2.mjs → chunk-NDMVV5PE.mjs} +6 -6
  39. package/dist-lib/esm-chunks/{chunk-KX7LV722.mjs → chunk-NLIWJ2AO.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-5WASPTSS.mjs → chunk-P7DZLDBL.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-F3OPIKJC.mjs → chunk-RDFBVP4E.mjs} +2 -2
  42. package/dist-lib/esm-chunks/{chunk-DLBUPWTI.mjs → chunk-SWCGFJ5A.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-KLA74B7J.mjs → chunk-T6THDRRU.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-3WQANOYY.mjs → chunk-TBKPPEGS.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-QUVLFF6I.mjs → chunk-UHTFNN5A.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-GSTHJQMW.mjs → chunk-VV2TNQK4.mjs} +115 -18
  47. package/dist-lib/esm-chunks/{chunk-VZ3NXXUC.mjs → chunk-WKE7Z3LU.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-LQVLXDRN.mjs → chunk-WXCV7NSJ.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-KBYVKTVK.mjs → chunk-X2OBXRGN.mjs} +3 -3
  50. package/dist-lib/esm-chunks/{chunk-N2PEXZGL.mjs → chunk-ZDW2NOAO.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{metro-layout-parser-RRIZOLBE.mjs → metro-layout-parser-6N4ZZDLM.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-EIZ7MCKR.mjs → swift-package-prebuilt-GF27A4NU.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-S2LQ4OXD.mjs → swift-sdk-app-module-WWTSGAS7.mjs} +47 -69
  54. package/dist-lib/esm-chunks/{swift-sdk-image-77FFUGXI.mjs → swift-sdk-image-OQMMOQLZ.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-XFSFUXQJ.mjs → swift-sdk-image-producer-NOH5SG6O.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +295 -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 +301 -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 +301 -486
  95. package/dist-lib/swift-compile.cjs +288 -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/compositor-protocol.d.ts +2 -0
  123. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +15 -2
  124. package/dist-types/packages/peach-engine/src/render-worker/worklet-wire.d.ts +10 -1
  125. package/package.json +1 -1
  126. package/src/swift-compiler-digest.ts +1 -0
  127. package/src/swift-guest-dyld-functions.ts +1 -11
  128. package/src/swift-guest-dyld-table.ts +2 -9
  129. package/src/swift-guest-image-ledger.ts +9 -35
  130. package/src/swift-guest-source-inputs.ts +5 -22
  131. package/src/swift-icu.ts +15 -28
  132. package/src/swift-link-roots.ts +4 -8
  133. package/src/swift-sdk-app-module.ts +5 -27
  134. package/src/swift-sdk-image-wasm.ts +12 -41
  135. package/src/swift-sdk-surface.ts +1 -0
  136. package/src/swift-shared-sdk.ts +1 -13
  137. package/src/swift-wasm-archive.ts +6 -11
  138. package/src/swift-wasm-prune.ts +22 -100
  139. 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.2780 | (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;
@@ -10502,7 +10502,7 @@ var init_swift_objc_sdk_tree = __esm({
10502
10502
 
10503
10503
  // src/swift-compiler-digest.ts
10504
10504
  function swiftArchiveCompilerDigestValue() {
10505
- return true ? "faa13b0ae0340e03d058b765e659f5e07b69f8e94793bf99981b3da7ca3bf2bd" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname, "archive");
10505
+ return true ? "e8ee54259aef0a6a4e89faafc8a3413c810341697abe828044a70a8b46db3c15" : swiftCompilerSourceDigest2(__sootsim_import_meta_dirname, "archive");
10506
10506
  }
10507
10507
  var import_node_crypto10, import_node_fs20, import_node_path17, SWIFT_DIGEST_SOURCES, LINKED_IMAGE_SOURCES, SWIFT_ARCHIVE_DIGEST_SOURCES;
10508
10508
  var init_swift_compiler_digest = __esm({
@@ -10531,6 +10531,7 @@ var init_swift_compiler_digest = __esm({
10531
10531
  "swift-objc-prebuilt-catalog.ts",
10532
10532
  "swift-toolchain.ts",
10533
10533
  "swift-shared-sdk.ts",
10534
+ "wasm-binary-sections.ts",
10534
10535
  "swift-distribution-mirror.ts",
10535
10536
  "swift-design-time.ts",
10536
10537
  "binaryen.lock.json",
@@ -14424,6 +14425,111 @@ var init_swift_objc_standin = __esm({
14424
14425
  }
14425
14426
  });
14426
14427
 
14428
+ // src/wasm-binary-sections.ts
14429
+ function encodeWasmNumber(value) {
14430
+ const bytes = [];
14431
+ for (let rest = value; ; ) {
14432
+ const byte = rest % 128;
14433
+ rest = Math.floor(rest / 128);
14434
+ if (rest === 0) return [...bytes, byte];
14435
+ bytes.push(byte | 128);
14436
+ }
14437
+ }
14438
+ function encodeWasmSigned(value) {
14439
+ const out = [];
14440
+ for (; ; ) {
14441
+ const byte = Number(value & 127n);
14442
+ value >>= 7n;
14443
+ if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
14444
+ out.push(byte);
14445
+ return out;
14446
+ }
14447
+ out.push(byte | 128);
14448
+ }
14449
+ }
14450
+ function encodeWasmName(name3) {
14451
+ const bytes = new TextEncoder().encode(name3);
14452
+ return [...encodeWasmNumber(bytes.length), ...bytes];
14453
+ }
14454
+ function readULEB(bytes, offset, end = bytes.length) {
14455
+ if (offset < end) {
14456
+ const first = bytes[offset];
14457
+ if (first < 128) return [first, offset + 1];
14458
+ }
14459
+ let value = 0;
14460
+ for (let shift = 0; ; shift += 7) {
14461
+ if (offset >= end || shift > 63) throw new Error("invalid wasm integer");
14462
+ const byte = bytes[offset++];
14463
+ value += (byte & 127) * 2 ** shift;
14464
+ if (!(byte & 128)) return [value, offset];
14465
+ }
14466
+ }
14467
+ function readSLEB(bytes, offset, end = bytes.length) {
14468
+ let value = 0n;
14469
+ let shift = 0n;
14470
+ let byte = 0;
14471
+ do {
14472
+ if (offset >= end || shift > 70n) throw new Error("invalid wasm integer");
14473
+ byte = bytes[offset++];
14474
+ value |= BigInt(byte & 127) << shift;
14475
+ shift += 7n;
14476
+ } while (byte & 128);
14477
+ if (byte & 64) value -= 1n << shift;
14478
+ return [value, offset];
14479
+ }
14480
+ function skipLEB(bytes, offset) {
14481
+ while ((bytes[offset++] & 128) !== 0) {
14482
+ }
14483
+ return offset;
14484
+ }
14485
+ function readWasmSection(bytes, start, end) {
14486
+ let at = start;
14487
+ const number3 = () => {
14488
+ const [value, next] = readULEB(bytes, at, end);
14489
+ at = next;
14490
+ return value;
14491
+ };
14492
+ return {
14493
+ number: number3,
14494
+ byte: () => {
14495
+ if (at >= end) throw new Error("truncated wasm section");
14496
+ return bytes[at++];
14497
+ },
14498
+ name: () => {
14499
+ const length = number3();
14500
+ at += length;
14501
+ if (at > end) throw new Error("truncated wasm name");
14502
+ return Buffer.from(bytes.buffer, bytes.byteOffset + at - length, length).toString();
14503
+ },
14504
+ skip: (length) => {
14505
+ at += length;
14506
+ if (at > end) throw new Error("truncated wasm section");
14507
+ },
14508
+ position: () => at,
14509
+ done: () => at === end
14510
+ };
14511
+ }
14512
+ function wasmSections(bytes) {
14513
+ if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
14514
+ throw new Error("not a wasm module");
14515
+ const found = [];
14516
+ for (let at = 8; at < bytes.length; ) {
14517
+ const header = readWasmSection(bytes, at, bytes.length);
14518
+ const id = header.byte();
14519
+ const size2 = header.number();
14520
+ const start = header.position();
14521
+ if (start + size2 > bytes.length) throw new Error("truncated wasm section");
14522
+ found.push({ id, offset: at, start, end: start + size2 });
14523
+ at = start + size2;
14524
+ }
14525
+ return found;
14526
+ }
14527
+ var init_wasm_binary_sections = __esm({
14528
+ "src/wasm-binary-sections.ts"() {
14529
+ "use strict";
14530
+ }
14531
+ });
14532
+
14427
14533
  // src/swift-shared-sdk.ts
14428
14534
  function swiftSharedSdkSourceRoot(moduleRoot, distribution) {
14429
14535
  return import_node_path23.default.resolve(moduleRoot, distribution ? "sdk/ios" : "../peachsim/sdk/ios");
@@ -14474,18 +14580,6 @@ function swiftSharedSdkFlags(moduleRoot, distribution) {
14474
14580
  import_node_path23.default.join(root, "usr/include")
14475
14581
  ];
14476
14582
  }
14477
- function readULEB(b, o) {
14478
- let res = 0;
14479
- let shift = 0;
14480
- let p = o;
14481
- while (true) {
14482
- const byte = b[p++];
14483
- res |= (byte & 127) << shift;
14484
- if ((byte & 128) === 0) break;
14485
- shift += 7;
14486
- }
14487
- return [res, p];
14488
- }
14489
14583
  function weakenFoundationSymbolsInWasmObj(buf) {
14490
14584
  let pos = 8;
14491
14585
  while (pos < buf.length) {
@@ -14850,6 +14944,7 @@ var init_swift_shared_sdk = __esm({
14850
14944
  import_node_path23 = __toESM(require("node:path"), 1);
14851
14945
  init_swift_toolchain();
14852
14946
  init_swiftTargetContract();
14947
+ init_wasm_binary_sections();
14853
14948
  SWIFT_DISTRIBUTION_MIRROR_RECORD = ".peach-mirror.json";
14854
14949
  distributionHeaderRoots = /* @__PURE__ */ new Map();
14855
14950
  WEAKEN_FOUNDATION_SYMS = /* @__PURE__ */ new Set([
@@ -16354,16 +16449,12 @@ var init_swift_link_roots = __esm({
16354
16449
  "use strict";
16355
16450
  import_node_fs27 = __toESM(require("node:fs"), 1);
16356
16451
  import_node_path27 = __toESM(require("node:path"), 1);
16452
+ init_wasm_binary_sections();
16357
16453
  OBJC_RUNTIME_LOOKUP_SECTION = "peach_objc_runtime_lookup";
16358
16454
  leb = (bytes, at) => {
16359
- let value = 0;
16360
- let scale = 1;
16361
- for (; ; ) {
16362
- const byte = bytes[at.offset++];
16363
- value += (byte & 127) * scale;
16364
- if (!(byte & 128)) return value;
16365
- scale *= 128;
16366
- }
16455
+ const [value, next] = readULEB(bytes, at.offset);
16456
+ at.offset = next;
16457
+ return value;
16367
16458
  };
16368
16459
  rootsByDistribution = /* @__PURE__ */ new Map();
16369
16460
  }
@@ -17192,68 +17283,6 @@ var init_swift_guest_linked_spans = __esm({
17192
17283
  }
17193
17284
  });
17194
17285
 
17195
- // src/wasm-binary-sections.ts
17196
- function encodeWasmNumber(value) {
17197
- const bytes = [];
17198
- for (let rest = value; ; ) {
17199
- const byte = rest % 128;
17200
- rest = Math.floor(rest / 128);
17201
- if (rest === 0) return [...bytes, byte];
17202
- bytes.push(byte | 128);
17203
- }
17204
- }
17205
- function encodeWasmName(name3) {
17206
- const bytes = new TextEncoder().encode(name3);
17207
- return [...encodeWasmNumber(bytes.length), ...bytes];
17208
- }
17209
- function readWasmSection(bytes, start, end) {
17210
- let at = start;
17211
- const number3 = () => {
17212
- let value = 0;
17213
- for (let shift = 0; ; shift += 7) {
17214
- if (at >= end || shift > 63) throw new Error("invalid wasm integer");
17215
- const byte = bytes[at++];
17216
- value += (byte & 127) * 2 ** shift;
17217
- if (!(byte & 128)) return value;
17218
- }
17219
- };
17220
- return {
17221
- number: number3,
17222
- byte: () => {
17223
- if (at >= end) throw new Error("truncated wasm section");
17224
- return bytes[at++];
17225
- },
17226
- name: () => {
17227
- const length = number3();
17228
- at += length;
17229
- if (at > end) throw new Error("truncated wasm name");
17230
- return Buffer.from(bytes.buffer, bytes.byteOffset + at - length, length).toString();
17231
- },
17232
- position: () => at,
17233
- done: () => at === end
17234
- };
17235
- }
17236
- function wasmSections(bytes) {
17237
- if (Buffer.from(bytes.subarray(0, 8)).toString("hex") !== "0061736d01000000")
17238
- throw new Error("not a wasm module");
17239
- const found = [];
17240
- for (let at = 8; at < bytes.length; ) {
17241
- const header = readWasmSection(bytes, at, bytes.length);
17242
- const id = header.byte();
17243
- const size2 = header.number();
17244
- const start = header.position();
17245
- if (start + size2 > bytes.length) throw new Error("truncated wasm section");
17246
- found.push({ id, offset: at, start, end: start + size2 });
17247
- at = start + size2;
17248
- }
17249
- return found;
17250
- }
17251
- var init_wasm_binary_sections = __esm({
17252
- "src/wasm-binary-sections.ts"() {
17253
- "use strict";
17254
- }
17255
- });
17256
-
17257
17286
  // src/wasm-imports.ts
17258
17287
  function readWasmImports(bytes, section2, visit3) {
17259
17288
  const input = readWasmSection(bytes, section2.start, section2.end);
@@ -17537,23 +17566,13 @@ function wasmReader(bytes, start) {
17537
17566
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
17538
17567
  let at = start;
17539
17568
  const u = () => {
17540
- let value = 0;
17541
- for (let shift = 0; ; shift += 7) {
17542
- const byte = bytes[at++];
17543
- value += (byte & 127) * 2 ** shift;
17544
- if (!(byte & 128)) return value;
17545
- }
17569
+ const [value, next] = readULEB(bytes, at);
17570
+ at = next;
17571
+ return value;
17546
17572
  };
17547
17573
  const s = () => {
17548
- let value = 0n;
17549
- let shift = 0n;
17550
- let byte = 0;
17551
- do {
17552
- byte = bytes[at++];
17553
- value |= BigInt(byte & 127) << shift;
17554
- shift += 7n;
17555
- } while (byte & 128);
17556
- if (byte & 64) value -= 1n << shift;
17574
+ const [value, next] = readSLEB(bytes, at);
17575
+ at = next;
17557
17576
  return value;
17558
17577
  };
17559
17578
  return {
@@ -17858,7 +17877,7 @@ function finishSdkImage(bytes, hostExports, libraries, guestMap) {
17858
17877
  else data[entry.name] = value;
17859
17878
  }
17860
17879
  if (entry.kind !== 0 && entry.kind !== 3 || host2.has(entry.name))
17861
- kept.push([...encodedName(entry.name), entry.kind, ...uleb(entry.index)]);
17880
+ kept.push([...encodeWasmName(entry.name), entry.kind, ...encodeWasmNumber(entry.index)]);
17862
17881
  }
17863
17882
  if (guestMap) {
17864
17883
  if (guestMap.code.length !== m.bodies.length)
@@ -17873,19 +17892,19 @@ function finishSdkImage(bytes, hostExports, libraries, guestMap) {
17873
17892
  const er = wasmReader(bytes, elements.start);
17874
17893
  const segments = er.u();
17875
17894
  const replaced = /* @__PURE__ */ new Map([
17876
- [4, [1, 112, 4, ...uleb(tableEnd + added.length)]],
17877
- [7, [...uleb(kept.length), ...kept.flat()]],
17895
+ [4, [1, 112, 4, ...encodeWasmNumber(tableEnd + added.length)]],
17896
+ [7, [...encodeWasmNumber(kept.length), ...kept.flat()]],
17878
17897
  [
17879
17898
  9,
17880
17899
  [
17881
- ...uleb(segments + 1),
17900
+ ...encodeWasmNumber(segments + 1),
17882
17901
  ...bytes.subarray(er.at, elements.end),
17883
17902
  0,
17884
17903
  66,
17885
- ...sleb(BigInt(tableEnd)),
17904
+ ...encodeWasmSigned(BigInt(tableEnd)),
17886
17905
  11,
17887
- ...uleb(added.length),
17888
- ...added.flatMap(uleb)
17906
+ ...encodeWasmNumber(added.length),
17907
+ ...added.flatMap(encodeWasmNumber)
17889
17908
  ]
17890
17909
  ]
17891
17910
  ]);
@@ -17991,33 +18010,33 @@ function codeOnlySdkImage(bytes, constructorMask) {
17991
18010
  if (drop) r.skip(1);
17992
18011
  gated.push(
17993
18012
  66,
17994
- ...sleb(BigInt(constructorMask + index++)),
18013
+ ...encodeWasmSigned(BigInt(constructorMask + index++)),
17995
18014
  45,
17996
18015
  0,
17997
18016
  0,
17998
18017
  4,
17999
18018
  64,
18000
18019
  16,
18001
- ...uleb(callee),
18020
+ ...encodeWasmNumber(callee),
18002
18021
  ...drop ? [26] : [],
18003
18022
  11
18004
18023
  );
18005
18024
  }
18006
18025
  if (index > SWIFT_SDK_CONSTRUCTOR_LIMIT)
18007
18026
  throw new Error(`${index} sdk constructors exceed the mask`);
18008
- gated.push(16, ...uleb(functionIndex("__peach_sdk_register")), 11);
18027
+ gated.push(16, ...encodeWasmNumber(functionIndex("__peach_sdk_register")), 11);
18009
18028
  bodies[constructors] = Uint8Array.from(gated);
18010
18029
  }
18011
- const codeParts = [Uint8Array.from(uleb(bodies.length))];
18012
- for (const body of bodies) codeParts.push(Uint8Array.from(uleb(body.length)), body);
18030
+ const codeParts = [Uint8Array.from(encodeWasmNumber(bodies.length))];
18031
+ for (const body of bodies) codeParts.push(Uint8Array.from(encodeWasmNumber(body.length)), body);
18013
18032
  const codeSize = codeParts.reduce((sum, part) => sum + part.length, 0);
18014
18033
  const tls = passiveSegments(bytes)[0];
18015
18034
  const out = [bytes.subarray(0, 8)];
18016
18035
  for (const s of m.sections) {
18017
18036
  if (s.id === 10) {
18018
- out.push(Uint8Array.from([10, ...uleb(codeSize)]));
18037
+ out.push(Uint8Array.from([10, ...encodeWasmNumber(codeSize)]));
18019
18038
  for (const part of codeParts) out.push(part);
18020
- } else if (s.id === 11) out.push(section(11, [1, 1, ...uleb(tls.length), ...tls]));
18039
+ } else if (s.id === 11) out.push(section(11, [1, 1, ...encodeWasmNumber(tls.length), ...tls]));
18021
18040
  else if (s.id === 12) out.push(section(12, [1]));
18022
18041
  else out.push(bytes.subarray(s.offset, s.end));
18023
18042
  }
@@ -18334,39 +18353,14 @@ function unslottedFunctions(bytes) {
18334
18353
  }
18335
18354
  return definedFuncs - slotted.size;
18336
18355
  }
18337
- 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;
18356
+ var section, PROCESS_EXPORTS, SWIFT_SDK_CONSTRUCTOR_LIMIT, FUNCTION_RELOCATIONS, MEMORY_RELOCATIONS, ADDEND_RELOCATIONS, FUNCTION_RELOC_MASK, MEMORY_RELOC_MASK, ADDEND_RELOC_MASK;
18338
18357
  var init_swift_sdk_image_wasm = __esm({
18339
18358
  "src/swift-sdk-image-wasm.ts"() {
18340
18359
  "use strict";
18341
18360
  init_swift_sdk_image_map();
18342
18361
  init_swiftSdkLinkContract();
18343
- uleb = (value) => {
18344
- const out = [];
18345
- do {
18346
- let byte = value % 128;
18347
- value = Math.floor(value / 128);
18348
- if (value) byte |= 128;
18349
- out.push(byte);
18350
- } while (value);
18351
- return out;
18352
- };
18353
- sleb = (value) => {
18354
- const out = [];
18355
- for (; ; ) {
18356
- const byte = Number(value & 127n);
18357
- value >>= 7n;
18358
- if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
18359
- out.push(byte);
18360
- return out;
18361
- }
18362
- out.push(byte | 128);
18363
- }
18364
- };
18365
- encodedName = (name3) => {
18366
- const bytes = [...Buffer.from(name3)];
18367
- return [...uleb(bytes.length), ...bytes];
18368
- };
18369
- section = (id, payload) => Uint8Array.from([id, ...uleb(payload.length), ...payload]);
18362
+ init_wasm_binary_sections();
18363
+ section = (id, payload) => Uint8Array.from([id, ...encodeWasmNumber(payload.length), ...payload]);
18370
18364
  PROCESS_EXPORTS = [
18371
18365
  "_initialize",
18372
18366
  "__wasm_call_ctors",
@@ -18471,20 +18465,12 @@ function localizeDefinedWasmSymbols(bytes, names) {
18471
18465
  const output = new Uint8Array(bytes);
18472
18466
  let cur = 8;
18473
18467
  const readU = () => {
18474
- const b0 = bytes[cur++];
18475
- if (b0 < 128) return b0;
18476
- let res = b0 & 127;
18477
- let shift = 7;
18478
- while (true) {
18479
- const byte = bytes[cur++];
18480
- res |= (byte & 127) << shift;
18481
- if ((byte & 128) === 0) return res;
18482
- shift += 7;
18483
- }
18468
+ const [res, next] = readULEB(bytes, cur);
18469
+ cur = next;
18470
+ return res;
18484
18471
  };
18485
18472
  const skipU = () => {
18486
- while ((bytes[cur++] & 128) !== 0) {
18487
- }
18473
+ cur = skipLEB(bytes, cur);
18488
18474
  };
18489
18475
  const importFuncNames = [];
18490
18476
  const importGlobalNames = [];
@@ -18591,45 +18577,11 @@ function localizeDefinedWasmSymbols(bytes, names) {
18591
18577
  var init_swift_wasm_archive = __esm({
18592
18578
  "src/swift-wasm-archive.ts"() {
18593
18579
  "use strict";
18580
+ init_wasm_binary_sections();
18594
18581
  }
18595
18582
  });
18596
18583
 
18597
18584
  // src/swift-wasm-prune.ts
18598
- function readULEB2(b, o) {
18599
- let res = 0;
18600
- let shift = 0;
18601
- let p = o;
18602
- while (true) {
18603
- const byte = b[p++];
18604
- res |= (byte & 127) << shift;
18605
- if ((byte & 128) === 0) break;
18606
- shift += 7;
18607
- }
18608
- return [res, p];
18609
- }
18610
- function readSLEB(b, o) {
18611
- let res = 0;
18612
- let shift = 0;
18613
- let p = o;
18614
- let byte = 0;
18615
- do {
18616
- byte = b[p++];
18617
- res |= (byte & 127) << shift;
18618
- shift += 7;
18619
- } while (byte & 128);
18620
- if (shift < 32 && byte & 64) res |= ~0 << shift;
18621
- return [res, p];
18622
- }
18623
- function encodeULEB(val) {
18624
- const out = [];
18625
- do {
18626
- let byte = val & 127;
18627
- val >>>= 7;
18628
- if (val !== 0) byte |= 128;
18629
- out.push(byte);
18630
- } while (val !== 0);
18631
- return out;
18632
- }
18633
18585
  function isRootSegName(name3) {
18634
18586
  for (const pref of ROOT_SEG_PREFIXES) {
18635
18587
  if (name3 === pref || name3.startsWith(`${pref}.`)) return true;
@@ -18655,39 +18607,14 @@ function decodeRelocations(buf, sections) {
18655
18607
  for (let k = 0; k < sectionCount; k++, i++) {
18656
18608
  start[i] = length + cur - baseAt;
18657
18609
  const rType = buf[cur++];
18658
- let offset = buf[cur++];
18659
- if (offset >= 128) {
18660
- offset &= 127;
18661
- let shift = 7;
18662
- while (true) {
18663
- const byte = buf[cur++];
18664
- offset |= (byte & 127) << shift;
18665
- if (byte < 128) break;
18666
- shift += 7;
18667
- }
18668
- }
18669
- let symbol2 = buf[cur++];
18670
- if (symbol2 >= 128) {
18671
- symbol2 &= 127;
18672
- let shift = 7;
18673
- while (true) {
18674
- const byte = buf[cur++];
18675
- symbol2 |= (byte & 127) << shift;
18676
- if (byte < 128) break;
18677
- shift += 7;
18678
- }
18679
- }
18610
+ let offset;
18611
+ [offset, cur] = readULEB(buf, cur);
18612
+ let symbol2;
18613
+ [symbol2, cur] = readULEB(buf, cur);
18680
18614
  if (rType < 32 && (ADDEND_RELOC_MASK2 & 1 << rType) !== 0) {
18681
- let byte = buf[cur++];
18682
- let value = byte & 127;
18683
- let shift = 7;
18684
- while (byte >= 128) {
18685
- byte = buf[cur++];
18686
- value |= (byte & 127) << shift;
18687
- shift += 7;
18688
- }
18689
- if (shift < 32 && (byte & 64) !== 0) value |= ~0 << shift;
18690
- addend[i] = value;
18615
+ let value;
18616
+ [value, cur] = readSLEB(buf, cur);
18617
+ addend[i] = Number(BigInt.asIntN(32, value));
18691
18618
  }
18692
18619
  ro[i] = offset;
18693
18620
  rs[i] = symbol2;
@@ -18722,36 +18649,36 @@ function patchSwiftrtObject(src) {
18722
18649
  let pos = 8;
18723
18650
  while (pos < buf.length) {
18724
18651
  const id = buf[pos++];
18725
- const [sz, p] = readULEB2(buf, pos);
18652
+ const [sz, p] = readULEB(buf, pos);
18726
18653
  const end = p + sz;
18727
18654
  if (id === 0) {
18728
- const [nLen, np] = readULEB2(buf, p);
18655
+ const [nLen, np] = readULEB(buf, p);
18729
18656
  const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
18730
18657
  const cp = np + nLen;
18731
18658
  if (name3 === "linking") {
18732
- let [, lp] = readULEB2(buf, cp);
18659
+ let [, lp] = readULEB(buf, cp);
18733
18660
  while (lp < end) {
18734
18661
  const subId = buf[lp++];
18735
- const [subLen, sp] = readULEB2(buf, lp);
18662
+ const [subLen, sp] = readULEB(buf, lp);
18736
18663
  const subEnd = sp + subLen;
18737
18664
  if (subId === 8) {
18738
- let [cnt, cur] = readULEB2(buf, sp);
18665
+ let [cnt, cur] = readULEB(buf, sp);
18739
18666
  for (let i = 0; i < cnt; i++) {
18740
18667
  const kind = buf[cur++];
18741
18668
  const flPos = cur;
18742
- const [fl, c2] = readULEB2(buf, cur);
18669
+ const [fl, c2] = readULEB(buf, cur);
18743
18670
  cur = c2;
18744
18671
  const isUndef = (fl & 16) !== 0;
18745
18672
  const isExplicitName = (fl & 64) !== 0;
18746
18673
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
18747
- const [, c3] = readULEB2(buf, cur);
18674
+ const [, c3] = readULEB(buf, cur);
18748
18675
  cur = c3;
18749
18676
  if (!isUndef || isExplicitName) {
18750
- const [sLen, c4] = readULEB2(buf, cur);
18677
+ const [sLen, c4] = readULEB(buf, cur);
18751
18678
  cur = c4 + sLen;
18752
18679
  }
18753
18680
  } else if (kind === 1) {
18754
- const [sLen, c3] = readULEB2(buf, cur);
18681
+ const [sLen, c3] = readULEB(buf, cur);
18755
18682
  const sName = Buffer.from(buf.subarray(c3, c3 + sLen)).toString("utf8");
18756
18683
  if (sName === "_ZN12_GLOBAL__N_18sectionsE") fallbackSymIdx = i;
18757
18684
  for (const prefix of ["__start_", "__stop_"]) {
@@ -18763,13 +18690,13 @@ function patchSwiftrtObject(src) {
18763
18690
  }
18764
18691
  cur = c3 + sLen;
18765
18692
  if (!isUndef) {
18766
- const [, c4] = readULEB2(buf, cur);
18767
- const [, c5] = readULEB2(buf, c4);
18768
- const [, c6] = readULEB2(buf, c5);
18693
+ const [, c4] = readULEB(buf, cur);
18694
+ const [, c5] = readULEB(buf, c4);
18695
+ const [, c6] = readULEB(buf, c5);
18769
18696
  cur = c6;
18770
18697
  }
18771
18698
  } else if (kind === 3) {
18772
- const [, c3] = readULEB2(buf, cur);
18699
+ const [, c3] = readULEB(buf, cur);
18773
18700
  cur = c3;
18774
18701
  }
18775
18702
  }
@@ -18783,26 +18710,25 @@ function patchSwiftrtObject(src) {
18783
18710
  pos = 8;
18784
18711
  while (pos < buf.length) {
18785
18712
  const id = buf[pos++];
18786
- const [sz, p] = readULEB2(buf, pos);
18713
+ const [sz, p] = readULEB(buf, pos);
18787
18714
  const end = p + sz;
18788
18715
  if (id === 0) {
18789
- const [nLen, np] = readULEB2(buf, p);
18716
+ const [nLen, np] = readULEB(buf, p);
18790
18717
  const name3 = Buffer.from(buf.subarray(np, np + nLen)).toString("utf8");
18791
18718
  const cp = np + nLen;
18792
18719
  if (name3 === "reloc.CODE") {
18793
- const [, r1] = readULEB2(buf, cp);
18794
- let [cnt, cur] = readULEB2(buf, r1);
18720
+ const [, r1] = readULEB(buf, cp);
18721
+ let [cnt, cur] = readULEB(buf, r1);
18795
18722
  for (let i = 0; i < cnt; i++) {
18796
18723
  const rType = buf[cur++];
18797
- const [, c2] = readULEB2(buf, cur);
18798
- const [rs, c3] = readULEB2(buf, c2);
18724
+ const [, c2] = readULEB(buf, cur);
18725
+ const [rs, c3] = readULEB(buf, c2);
18799
18726
  if (neutralizedSyms.has(rs) && c3 - c2 === 1) {
18800
18727
  buf[c2] = fallbackSymIdx;
18801
18728
  }
18802
18729
  cur = c3;
18803
18730
  if (ADDEND_RELOCATIONS.has(rType)) {
18804
- const [, c4] = readSLEB(buf, cur);
18805
- cur = c4;
18731
+ cur = skipLEB(buf, cur);
18806
18732
  }
18807
18733
  }
18808
18734
  }
@@ -18816,25 +18742,14 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
18816
18742
  let pos = 8;
18817
18743
  let cur = 8;
18818
18744
  const readU = () => {
18819
- const b0 = buf[cur++];
18820
- if (b0 < 128) return b0;
18821
- let res = b0 & 127;
18822
- let shift = 7;
18823
- while (true) {
18824
- const byte = buf[cur++];
18825
- res |= (byte & 127) << shift;
18826
- if (byte < 128) return res;
18827
- shift += 7;
18828
- }
18745
+ const [res, next] = readULEB(buf, cur);
18746
+ cur = next;
18747
+ return res;
18829
18748
  };
18830
18749
  const skipU = () => {
18831
- while (buf[cur++] >= 128) {
18832
- }
18833
- };
18834
- const skipS = () => {
18835
- while (buf[cur++] >= 128) {
18836
- }
18750
+ cur = skipLEB(buf, cur);
18837
18751
  };
18752
+ const skipS = skipU;
18838
18753
  let numImportFuncs = 0;
18839
18754
  let importsDlsym = false;
18840
18755
  const importFuncNames = [];
@@ -19432,16 +19347,9 @@ function guestWasmSymbols(bytes) {
19432
19347
  const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
19433
19348
  let cur = 8;
19434
19349
  const readU = () => {
19435
- const b0 = bytes[cur++];
19436
- if (b0 < 128) return b0;
19437
- let res = b0 & 127;
19438
- let shift = 7;
19439
- while (true) {
19440
- const byte = bytes[cur++];
19441
- res |= (byte & 127) << shift;
19442
- if ((byte & 128) === 0) return res;
19443
- shift += 7;
19444
- }
19350
+ const [res, next] = readULEB(bytes, cur);
19351
+ cur = next;
19352
+ return res;
19445
19353
  };
19446
19354
  let importsDlsym = false;
19447
19355
  const importFuncNames = [];
@@ -20582,7 +20490,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
20582
20490
  if (!deadSpecialSegs.has(sIdx)) continue;
20583
20491
  if (!isSpecialSegRelocLive(obj, obj.segNames[sIdx], data.rs[i])) continue;
20584
20492
  const first = relocationBytes(data, i);
20585
- const [, afterRoOff] = readULEB2(first, 1);
20493
+ const [, afterRoOff] = readULEB(first, 1);
20586
20494
  firstLiveInSpecialSeg.set(sIdx, {
20587
20495
  rType: first[0],
20588
20496
  afterRo: first.subarray(afterRoOff)
@@ -20612,7 +20520,7 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
20612
20520
  zeroDataReloc(i);
20613
20521
  } else {
20614
20522
  const repl = firstLiveInSpecialSeg.get(segIdx);
20615
- const roBytes = encodeULEB(data.ro[i]);
20523
+ const roBytes = encodeWasmNumber(data.ro[i]);
20616
20524
  const out = new Uint8Array(1 + roBytes.length + repl.afterRo.length);
20617
20525
  out[0] = repl.rType;
20618
20526
  out.set(roBytes, 1);
@@ -20651,34 +20559,34 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
20651
20559
  while (pos < buf.length) {
20652
20560
  const secStart = pos;
20653
20561
  const id = buf[pos++];
20654
- const [sz, p] = readULEB2(buf, pos);
20562
+ const [sz, p] = readULEB(buf, pos);
20655
20563
  const end = p + sz;
20656
20564
  if (id === 0) {
20657
- const [nLen, np] = readULEB2(buf, p);
20565
+ const [nLen, np] = readULEB(buf, p);
20658
20566
  const name3 = rawBuf.toString("utf8", np, np + nLen);
20659
20567
  const cp = np + nLen;
20660
20568
  if (name3 === "linking") {
20661
- const [, lpStart] = readULEB2(buf, cp);
20569
+ const [, lpStart] = readULEB(buf, cp);
20662
20570
  const subChunks = [buf.subarray(p, lpStart)];
20663
20571
  let lp = lpStart;
20664
20572
  while (lp < end) {
20665
20573
  const subStart = lp;
20666
20574
  const subId = buf[lp++];
20667
- const [subLen, sp] = readULEB2(buf, lp);
20575
+ const [subLen, sp] = readULEB(buf, lp);
20668
20576
  const subEnd = sp + subLen;
20669
20577
  if (subId === 5) {
20670
20578
  const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
20671
- let [cnt, cur] = readULEB2(buf, sp);
20579
+ let [cnt, cur] = readULEB(buf, sp);
20672
20580
  for (let i = 0; i < cnt; i++) {
20673
- const [sLen, s2] = readULEB2(buf, cur);
20581
+ const [sLen, s2] = readULEB(buf, cur);
20674
20582
  const segName = obj.segNames[i];
20675
20583
  const repl = RECORD_SEGS.get(segName);
20676
20584
  const isSpecial = repl !== void 0;
20677
20585
  if (deadSpecialSegs.has(i) && repl !== void 0)
20678
20586
  subCopy.set(Buffer.from(repl, "utf8"), s2 - subStart);
20679
20587
  cur = s2 + sLen;
20680
- const [, s3] = readULEB2(buf, cur);
20681
- const [segFl, s4] = readULEB2(buf, s3);
20588
+ const [, s3] = readULEB(buf, cur);
20589
+ const [segFl, s4] = readULEB(buf, s3);
20682
20590
  const sFlLen = s4 - s3;
20683
20591
  const keepRetain = isSpecial ? !deadSpecialSegs.has(i) : isRootSegName(segName) && !segName.startsWith(".init_array") && sLive[i] === 1;
20684
20592
  const newSegFl = keepRetain ? segFl | 4 : segFl & ~4;
@@ -20692,12 +20600,12 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
20692
20600
  }
20693
20601
  subChunks.push(subCopy);
20694
20602
  } else if (subId === 6) {
20695
- let [cnt, cur] = readULEB2(buf, sp);
20603
+ let [cnt, cur] = readULEB(buf, sp);
20696
20604
  const entrySlices = [];
20697
20605
  for (let i = 0; i < cnt; i++) {
20698
20606
  const eStart = cur;
20699
- const [, s2] = readULEB2(buf, cur);
20700
- const [symIdx, s3] = readULEB2(buf, s2);
20607
+ const [, s2] = readULEB(buf, cur);
20608
+ const [symIdx, s3] = readULEB(buf, s2);
20701
20609
  cur = s3;
20702
20610
  if (obj.symKind[symIdx] === 0 && obj.symElemIdx[symIdx] >= obj.numImportFuncs) {
20703
20611
  if (fLive[obj.symElemIdx[symIdx] - obj.numImportFuncs] === 1) {
@@ -20708,19 +20616,19 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
20708
20616
  }
20709
20617
  }
20710
20618
  if (entrySlices.length > 0) {
20711
- const cntBytes = Uint8Array.from(encodeULEB(entrySlices.length));
20619
+ const cntBytes = Uint8Array.from(encodeWasmNumber(entrySlices.length));
20712
20620
  const bodyLen = cntBytes.length + entrySlices.reduce((a, b) => a + b.length, 0);
20713
- const lenBytes = Uint8Array.from(encodeULEB(bodyLen));
20621
+ const lenBytes = Uint8Array.from(encodeWasmNumber(bodyLen));
20714
20622
  subChunks.push(Uint8Array.of(6), lenBytes, cntBytes);
20715
20623
  for (const entry of entrySlices) subChunks.push(entry);
20716
20624
  }
20717
20625
  } else if (subId === 8) {
20718
20626
  const subCopy = new Uint8Array(buf.subarray(subStart, subEnd));
20719
- let [cnt, cur] = readULEB2(buf, sp);
20627
+ let [cnt, cur] = readULEB(buf, sp);
20720
20628
  for (let i = 0; i < cnt; i++) {
20721
20629
  const kind = buf[cur++];
20722
20630
  const flOffset = cur - subStart;
20723
- const [fl, c2] = readULEB2(buf, cur);
20631
+ const [fl, c2] = readULEB(buf, cur);
20724
20632
  cur = c2;
20725
20633
  const isUndef = (fl & 16) !== 0;
20726
20634
  const isExplicitName = (fl & 64) !== 0;
@@ -20740,23 +20648,23 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
20740
20648
  subCopy[flOffset + 1] = 0;
20741
20649
  }
20742
20650
  if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
20743
- const [, c3] = readULEB2(buf, cur);
20651
+ const [, c3] = readULEB(buf, cur);
20744
20652
  cur = c3;
20745
20653
  if (!isUndef || isExplicitName) {
20746
- const [sLen, c4] = readULEB2(buf, cur);
20654
+ const [sLen, c4] = readULEB(buf, cur);
20747
20655
  cur = c4 + sLen;
20748
20656
  }
20749
20657
  } else if (kind === 1) {
20750
- const [sLen, c3] = readULEB2(buf, cur);
20658
+ const [sLen, c3] = readULEB(buf, cur);
20751
20659
  cur = c3 + sLen;
20752
20660
  if (!isUndef) {
20753
- const [, c4] = readULEB2(buf, cur);
20754
- const [, c5] = readULEB2(buf, c4);
20755
- const [, c6] = readULEB2(buf, c5);
20661
+ const [, c4] = readULEB(buf, cur);
20662
+ const [, c5] = readULEB(buf, c4);
20663
+ const [, c6] = readULEB(buf, c5);
20756
20664
  cur = c6;
20757
20665
  }
20758
20666
  } else if (kind === 3) {
20759
- const [, c3] = readULEB2(buf, cur);
20667
+ const [, c3] = readULEB(buf, cur);
20760
20668
  cur = c3;
20761
20669
  }
20762
20670
  }
@@ -20767,29 +20675,29 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
20767
20675
  lp = subEnd;
20768
20676
  }
20769
20677
  const totalSubLen = subChunks.reduce((a, b) => a + b.length, 0);
20770
- outChunks.push(Uint8Array.of(0), Uint8Array.from(encodeULEB(totalSubLen)));
20678
+ outChunks.push(Uint8Array.of(0), Uint8Array.from(encodeWasmNumber(totalSubLen)));
20771
20679
  for (const chunk of subChunks) outChunks.push(chunk);
20772
20680
  } else if (name3 === "reloc.CODE") {
20773
- const [, r1] = readULEB2(buf, cp);
20681
+ const [, r1] = readULEB(buf, cp);
20774
20682
  const headerSlice = buf.subarray(p, r1);
20775
- const cntBytes = Uint8Array.from(encodeULEB(keptCodeRelocs.length));
20683
+ const cntBytes = Uint8Array.from(encodeWasmNumber(keptCodeRelocs.length));
20776
20684
  const relSlices = keptCodeRelocs.map((i) => relocationBytes(code, i));
20777
20685
  const totalLen = headerSlice.length + cntBytes.length + relSlices.reduce((a, b) => a + b.length, 0);
20778
20686
  outChunks.push(
20779
20687
  Uint8Array.of(0),
20780
- Uint8Array.from(encodeULEB(totalLen)),
20688
+ Uint8Array.from(encodeWasmNumber(totalLen)),
20781
20689
  headerSlice,
20782
20690
  cntBytes
20783
20691
  );
20784
20692
  for (const relocation of relSlices) outChunks.push(relocation);
20785
20693
  } else if (name3 === "reloc.DATA") {
20786
- const [, r1] = readULEB2(buf, cp);
20694
+ const [, r1] = readULEB(buf, cp);
20787
20695
  const headerSlice = buf.subarray(p, r1);
20788
- const cntBytes = Uint8Array.from(encodeULEB(keptDataRelocBytes.length));
20696
+ const cntBytes = Uint8Array.from(encodeWasmNumber(keptDataRelocBytes.length));
20789
20697
  const totalLen = headerSlice.length + cntBytes.length + keptDataRelocBytes.reduce((a, b) => a + b.length, 0);
20790
20698
  outChunks.push(
20791
20699
  Uint8Array.of(0),
20792
- Uint8Array.from(encodeULEB(totalLen)),
20700
+ Uint8Array.from(encodeWasmNumber(totalLen)),
20793
20701
  headerSlice,
20794
20702
  cntBytes
20795
20703
  );
@@ -20799,15 +20707,15 @@ function pruneSwiftWasmLink(directory2, toolchainBin, moduleRoot, staticClangTar
20799
20707
  const nameBytes = buf.subarray(p, cp);
20800
20708
  outChunks.push(
20801
20709
  Uint8Array.of(0),
20802
- Uint8Array.from(encodeULEB(nameBytes.length)),
20710
+ Uint8Array.from(encodeWasmNumber(nameBytes.length)),
20803
20711
  nameBytes
20804
20712
  );
20805
20713
  } else if (name3.startsWith("reloc..debug_")) {
20806
- const [, r1] = readULEB2(buf, cp);
20714
+ const [, r1] = readULEB(buf, cp);
20807
20715
  const headerSlice = buf.subarray(p, r1);
20808
20716
  outChunks.push(
20809
20717
  Uint8Array.of(0),
20810
- Uint8Array.from(encodeULEB(headerSlice.length + 1)),
20718
+ Uint8Array.from(encodeWasmNumber(headerSlice.length + 1)),
20811
20719
  headerSlice,
20812
20720
  Uint8Array.of(0)
20813
20721
  );
@@ -20937,6 +20845,7 @@ var init_swift_wasm_prune = __esm({
20937
20845
  init_swift_toolchain();
20938
20846
  init_swift_wasm_archive();
20939
20847
  init_swiftRuntimeProductContract();
20848
+ init_wasm_binary_sections();
20940
20849
  WIDE_DATA_RELOCS = /* @__PURE__ */ new Set([16, 19, 22, 27]);
20941
20850
  ROOT_SEG_PREFIXES = [
20942
20851
  ".init_array",
@@ -21200,34 +21109,11 @@ var init_nativeWasmContract = __esm({
21200
21109
  });
21201
21110
 
21202
21111
  // src/swift-guest-image-ledger.ts
21203
- function readNumber(bytes, position) {
21204
- if (position < bytes.length) {
21205
- const first = bytes[position];
21206
- if (first < 128) return [first, position + 1];
21207
- }
21208
- let value = 0;
21209
- let shift = 0;
21210
- for (; ; ) {
21211
- if (position >= bytes.length || shift > 63) throw new Error("invalid wasm integer");
21212
- const byte = bytes[position++];
21213
- value += (byte & 127) * 2 ** shift;
21214
- if (!(byte & 128)) return [value, position];
21215
- shift += 7;
21216
- }
21217
- }
21218
21112
  function encodeNumber(value) {
21219
- if (value < 128) return Buffer.from([value]);
21220
- const bytes = [];
21221
- do {
21222
- let byte = value % 128;
21223
- value = Math.floor(value / 128);
21224
- if (value) byte |= 128;
21225
- bytes.push(byte);
21226
- } while (value);
21227
- return Buffer.from(bytes);
21113
+ return Buffer.from(encodeWasmNumber(value));
21228
21114
  }
21229
21115
  function readString(bytes, position) {
21230
- const [length, start] = readNumber(bytes, position);
21116
+ const [length, start] = readULEB(bytes, position);
21231
21117
  if (start + length > bytes.length) throw new Error("invalid wasm string");
21232
21118
  return [
21233
21119
  Buffer.from(bytes.buffer, bytes.byteOffset + start, length).toString("utf8"),
@@ -21553,13 +21439,13 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
21553
21439
  for (const subsection of subsections) {
21554
21440
  if (subsection.kind === 6 && objcLoader !== void 0) {
21555
21441
  const content = subsection.parts[0];
21556
- const [count, entriesStart] = readNumber(content, 0);
21442
+ const [count, entriesStart] = readULEB(content, 0);
21557
21443
  const initWriter = new ByteWriter(content.length + 16);
21558
21444
  initWriter.bytes(content, 0, entriesStart);
21559
21445
  let entryStart = entriesStart;
21560
21446
  for (let i = 0; i < count; i++) {
21561
- const [, symbolStart] = readNumber(content, entryStart);
21562
- const [symbol2, entryEnd] = readNumber(content, symbolStart);
21447
+ const [, symbolStart] = readULEB(content, entryStart);
21448
+ const [symbol2, entryEnd] = readULEB(content, symbolStart);
21563
21449
  if (symbol2 === objcLoader) {
21564
21450
  initWriter.uleb(1);
21565
21451
  initWriter.bytes(content, symbolStart, entryEnd);
@@ -21629,7 +21515,7 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
21629
21515
  if (position < bytes.length && bytes[position] < 128) {
21630
21516
  size2 = bytes[position++];
21631
21517
  } else {
21632
- const [val, next] = readNumber(bytes, position);
21518
+ const [val, next] = readULEB(bytes, position);
21633
21519
  size2 = val;
21634
21520
  position = next;
21635
21521
  }
@@ -22385,7 +22271,7 @@ function nameGuestImageAliases(wasm, symbols) {
22385
22271
  const parts = [wasm.subarray(0, 8)];
22386
22272
  let position = 8;
22387
22273
  while (position < wasm.length) {
22388
- const [size2, start] = readNumber(wasm, position + 1);
22274
+ const [size2, start] = readULEB(wasm, position + 1);
22389
22275
  const end = start + size2;
22390
22276
  const custom = wasm[position] === 0 ? readString(wasm, start) : void 0;
22391
22277
  if (custom?.[0] !== "name") {
@@ -22396,17 +22282,17 @@ function nameGuestImageAliases(wasm, symbols) {
22396
22282
  const subsections = [encodedString("name")];
22397
22283
  let at = custom[1];
22398
22284
  while (at < end) {
22399
- const [subSize, subStart] = readNumber(wasm, at + 1);
22285
+ const [subSize, subStart] = readULEB(wasm, at + 1);
22400
22286
  const subEnd = subStart + subSize;
22401
22287
  if (wasm[at] !== 1) {
22402
22288
  subsections.push(wasm.subarray(at, subEnd));
22403
22289
  at = subEnd;
22404
22290
  continue;
22405
22291
  }
22406
- let [count, cursor] = readNumber(wasm, subStart);
22292
+ let [count, cursor] = readULEB(wasm, subStart);
22407
22293
  const entries2 = [encodeNumber(count)];
22408
22294
  for (; count > 0; count--) {
22409
- const [index, next] = readNumber(wasm, cursor);
22295
+ const [index, next] = readULEB(wasm, cursor);
22410
22296
  const [name3, after] = readString(wasm, next);
22411
22297
  cursor = after;
22412
22298
  const symbol2 = symbols[Number(alias.exec(name3)?.[1] ?? -1)];
@@ -22430,6 +22316,7 @@ var init_swift_guest_image_ledger = __esm({
22430
22316
  init_nativeWasmContract();
22431
22317
  init_swift_sdk_image_wasm();
22432
22318
  init_swiftSdkLinkContract();
22319
+ init_wasm_binary_sections();
22433
22320
  ByteWriter = class {
22434
22321
  buf;
22435
22322
  pos = 0;
@@ -22450,16 +22337,13 @@ var init_swift_guest_image_ledger = __esm({
22450
22337
  this.buf[this.pos++] = value;
22451
22338
  }
22452
22339
  uleb(value) {
22453
- this.ensure(10);
22454
- let pos = this.pos;
22455
- const buf = this.buf;
22456
- do {
22457
- let byte = value % 128;
22458
- value = Math.floor(value / 128);
22459
- if (value) byte |= 128;
22460
- buf[pos++] = byte;
22461
- } while (value);
22462
- this.pos = pos;
22340
+ if (value < 128) {
22341
+ this.byte(value);
22342
+ return;
22343
+ }
22344
+ const encoded = encodeWasmNumber(value);
22345
+ this.ensure(encoded.length);
22346
+ for (let i = 0; i < encoded.length; i++) this.buf[this.pos++] = encoded[i];
22463
22347
  }
22464
22348
  bytes(source, start = 0, end = source.length) {
22465
22349
  const len = end - start;
@@ -22811,13 +22695,6 @@ function sha256Buffer(bytes) {
22811
22695
  return Buffer.from(new Bun.CryptoHasher("sha256").update(bytes).digest());
22812
22696
  return (0, import_node_crypto19.createHash)("sha256").update(bytes).digest();
22813
22697
  }
22814
- function uleb2(value) {
22815
- const bytes = [];
22816
- for (let rest = value; ; rest = Math.floor(rest / 128)) {
22817
- if (rest < 128) return [...bytes, rest];
22818
- bytes.push(rest % 128 | 128);
22819
- }
22820
- }
22821
22698
  function encodeGuestDyldTable(rows) {
22822
22699
  const encoded = rows.map((row) => ({ ...row, bytes: Buffer.from(row.name) })).sort((a, b) => Buffer.compare(a.bytes, b.bytes));
22823
22700
  const packs = [];
@@ -22830,7 +22707,7 @@ function encodeGuestDyldTable(rows) {
22830
22707
  value.writeBigUInt64LE(row.value);
22831
22708
  const bytes = Buffer.concat([
22832
22709
  row.bytes,
22833
- Buffer.from([0, ...uleb2(row.image), row.kind]),
22710
+ Buffer.from([0, ...encodeWasmNumber(row.image), row.kind]),
22834
22711
  value
22835
22712
  ]);
22836
22713
  if (!current2.length) firsts.push(row.bytes);
@@ -22922,6 +22799,7 @@ var init_swift_guest_dyld_table = __esm({
22922
22799
  init_sha256();
22923
22800
  init_swift_guest_image_ledger();
22924
22801
  init_swift_guest_linked_spans();
22802
+ init_wasm_binary_sections();
22925
22803
  init_wasm_narrow_boundary();
22926
22804
  PACK_BYTES = 64 * 1024;
22927
22805
  }
@@ -22997,8 +22875,8 @@ function readImports2(bytes, sections) {
22997
22875
  return { functions, table64 };
22998
22876
  }
22999
22877
  function vectorSection(id, count, parts) {
23000
- const body = Buffer.concat([Buffer.from(uleb3(count)), ...parts]);
23001
- return Buffer.concat([Buffer.from([id, ...uleb3(body.length)]), body]);
22878
+ const body = Buffer.concat([Buffer.from(encodeWasmNumber(count)), ...parts]);
22879
+ return Buffer.concat([Buffer.from([id, ...encodeWasmNumber(body.length)]), body]);
23002
22880
  }
23003
22881
  function rewriteSections(bytes, sections, changes) {
23004
22882
  const out = [bytes.subarray(0, 8)];
@@ -23054,9 +22932,9 @@ function appendLazyPlacement(bytes, functions, table) {
23054
22932
  vectorSection(2, count + 1, [
23055
22933
  found && header ? bytes.subarray(header.at, found.end) : new Uint8Array(),
23056
22934
  Buffer.from([
23057
- ...uleb3(module2.length),
22935
+ ...encodeWasmNumber(module2.length),
23058
22936
  ...module2,
23059
- ...uleb3(name4.length),
22937
+ ...encodeWasmNumber(name4.length),
23060
22938
  ...name4,
23061
22939
  1,
23062
22940
  112,
@@ -23078,7 +22956,7 @@ function appendLazyPlacement(bytes, functions, table) {
23078
22956
  elements.splice(
23079
22957
  placementIndex,
23080
22958
  0,
23081
- Buffer.from([1, 0, ...uleb3(functions.length), ...functions.flatMap(uleb3)])
22959
+ Buffer.from([1, 0, ...encodeWasmNumber(functions.length), ...functions.flatMap(encodeWasmNumber)])
23082
22960
  );
23083
22961
  const place2 = imports2.functions + declared.length;
23084
22962
  const instructions = [
@@ -23092,7 +22970,7 @@ function appendLazyPlacement(bytes, functions, table) {
23092
22970
  1,
23093
22971
  252,
23094
22972
  12,
23095
- ...uleb3(placementIndex),
22973
+ ...encodeWasmNumber(placementIndex),
23096
22974
  0,
23097
22975
  11
23098
22976
  ];
@@ -23113,14 +22991,14 @@ function appendLazyPlacement(bytes, functions, table) {
23113
22991
  3,
23114
22992
  vectorSection(3, declared.length + 1, [
23115
22993
  ...declared,
23116
- Buffer.from(uleb3(types2.length))
22994
+ Buffer.from(encodeWasmNumber(types2.length))
23117
22995
  ])
23118
22996
  ],
23119
22997
  [
23120
22998
  7,
23121
22999
  vectorSection(7, exports2.length + 1, [
23122
23000
  ...exports2,
23123
- Buffer.from([...uleb3(name3.length), ...name3, 0, ...uleb3(place2)])
23001
+ Buffer.from([...encodeWasmNumber(name3.length), ...name3, 0, ...encodeWasmNumber(place2)])
23124
23002
  ])
23125
23003
  ],
23126
23004
  [9, vectorSection(9, elements.length, elements)],
@@ -23128,7 +23006,7 @@ function appendLazyPlacement(bytes, functions, table) {
23128
23006
  10,
23129
23007
  vectorSection(10, bodies.length + 1, [
23130
23008
  ...bodies,
23131
- Buffer.from([...uleb3(instructions.length), ...instructions])
23009
+ Buffer.from([...encodeWasmNumber(instructions.length), ...instructions])
23132
23010
  ])
23133
23011
  ]
23134
23012
  ])
@@ -23181,22 +23059,13 @@ function placeGuestLazyFunctions(bytes, lazy) {
23181
23059
  function guestLazyExports(lazy) {
23182
23060
  return lazy.map((name3) => JSON.stringify(`--export=${name3}`)).join("\n");
23183
23061
  }
23184
- var uleb3, SECTION_ORDER, readExport, lastTableElement;
23062
+ var SECTION_ORDER, readExport, lastTableElement;
23185
23063
  var init_swift_guest_dyld_functions = __esm({
23186
23064
  "src/swift-guest-dyld-functions.ts"() {
23187
23065
  "use strict";
23188
23066
  init_nativeWasmContract();
23189
23067
  init_swift_sdk_image_wasm();
23190
- uleb3 = (value) => {
23191
- const out = [];
23192
- do {
23193
- let byte = value % 128;
23194
- value = Math.floor(value / 128);
23195
- if (value) byte |= 128;
23196
- out.push(byte);
23197
- } while (value);
23198
- return out;
23199
- };
23068
+ init_wasm_binary_sections();
23200
23069
  SECTION_ORDER = [1, 2, 3, 4, 5, 13, 6, 7, 8, 9, 12, 10, 11];
23201
23070
  readExport = (r) => {
23202
23071
  r.name();
@@ -26530,30 +26399,12 @@ function wasmAutolinkEntries(bytes, out) {
26530
26399
  const len = bytes.length;
26531
26400
  while (pos < len) {
26532
26401
  const id = bytes[pos++];
26533
- let sz = bytes[pos++];
26534
- if (sz >= 128) {
26535
- sz &= 127;
26536
- let shift = 7;
26537
- while (true) {
26538
- const b = bytes[pos++];
26539
- sz |= (b & 127) << shift;
26540
- if (b < 128) break;
26541
- shift += 7;
26542
- }
26543
- }
26402
+ let sz;
26403
+ [sz, pos] = readULEB(bytes, pos, len);
26544
26404
  const end = pos + sz;
26545
26405
  if (id === 0) {
26546
- let nLen = bytes[pos++];
26547
- if (nLen >= 128) {
26548
- nLen &= 127;
26549
- let shift = 7;
26550
- while (true) {
26551
- const b = bytes[pos++];
26552
- nLen |= (b & 127) << shift;
26553
- if (b < 128) break;
26554
- shift += 7;
26555
- }
26556
- }
26406
+ let nLen;
26407
+ [nLen, pos] = readULEB(bytes, pos, end);
26557
26408
  if (nLen === 24 && raw2.toString("ascii", pos, pos + 24) === ".swift1_autolink_entries") {
26558
26409
  const payload = raw2.toString("utf8", pos + 24, end);
26559
26410
  for (const entry of payload.split("\0")) {
@@ -26790,6 +26641,7 @@ var init_swift_guest_source_inputs = __esm({
26790
26641
  init_swift_guest_source_plan();
26791
26642
  init_swift_runtime_products();
26792
26643
  init_swift_wasm_prune();
26644
+ init_wasm_binary_sections();
26793
26645
  CLANG_TARGET_MODULE_WRAPPER = ".peach-clang";
26794
26646
  PARALLEL_REPLAY = `
26795
26647
  const { spawn } = require('node:child_process')
@@ -29316,6 +29168,7 @@ function swiftModuleInputFiles(root) {
29316
29168
  ...swiftSharedSdkInputFiles(root),
29317
29169
  "../peachsim/src/admitted-mac-build.ts",
29318
29170
  "../peachsim/src/swift-shared-sdk.ts",
29171
+ "../peachsim/src/wasm-binary-sections.ts",
29319
29172
  "../peachsim/src/swift-runtime-products.ts",
29320
29173
  "../peachsim/src/swiftRuntimeProductContract.ts",
29321
29174
  "../peachsim/src/swiftTargetContract.ts",
@@ -33047,8 +32900,8 @@ function finishSwiftAppModuleFile(file) {
33047
32900
  return;
33048
32901
  }
33049
32902
  const thunks = sdkImportThunks(prefix);
33050
- const nameBytes = Buffer.from(encodedName2(NATIVE_SDK_THUNK_SECTION));
33051
- const header = Buffer.from([0, ...uleb4(nameBytes.length + thunks.length)]);
32903
+ const nameBytes = Buffer.from(encodeWasmName(NATIVE_SDK_THUNK_SECTION));
32904
+ const header = Buffer.from([0, ...encodeWasmNumber(nameBytes.length + thunks.length)]);
33052
32905
  (0, import_node_fs46.appendFileSync)(file, Buffer.concat([header, nameBytes, thunks]));
33053
32906
  }
33054
32907
  function swiftAppModuleInputs(tokens2, buildRoot, sdkLibraries) {
@@ -33400,17 +33253,17 @@ function sdkImportThunks(bytes) {
33400
33253
  for (const { type } of imports2)
33401
33254
  if (!typeIndex.has(type)) typeIndex.set(type, typeIndex.size + 1);
33402
33255
  const loaderType = [96, 1, 127, 0];
33403
- const vector = (items2) => [...uleb4(items2.length), ...items2.flat()];
33404
- const sectionBytes = (id, body) => [id, ...uleb4(body.length), ...body];
33256
+ const vector = (items2) => [...encodeWasmNumber(items2.length), ...items2.flat()];
33257
+ const sectionBytes = (id, body) => [id, ...encodeWasmNumber(body.length), ...body];
33405
33258
  const slotGlobals = imports2.map(({ slot }) => [
33406
- ...encodedName2(NATIVE_SDK_IMPORT_MODULE),
33407
- ...encodedName2(String(slot)),
33259
+ ...encodeWasmName(NATIVE_SDK_IMPORT_MODULE),
33260
+ ...encodeWasmName(String(slot)),
33408
33261
  3,
33409
33262
  127,
33410
33263
  0
33411
33264
  ]);
33412
33265
  const bodies = imports2.map(({ type }, index) => {
33413
- const slotValue = [35, ...uleb4(index)];
33266
+ const slotValue = [35, ...encodeWasmNumber(index)];
33414
33267
  const code = [
33415
33268
  0,
33416
33269
  ...slotValue,
@@ -33423,14 +33276,14 @@ function sdkImportThunks(bytes) {
33423
33276
  16,
33424
33277
  0,
33425
33278
  11,
33426
- ...Array.from({ length: params[type] }, (_, i) => [32, ...uleb4(i)]).flat(),
33279
+ ...Array.from({ length: params[type] }, (_, i) => [32, ...encodeWasmNumber(i)]).flat(),
33427
33280
  ...slotValue,
33428
33281
  17,
33429
- ...uleb4(typeIndex.get(type)),
33282
+ ...encodeWasmNumber(typeIndex.get(type)),
33430
33283
  0,
33431
33284
  11
33432
33285
  ];
33433
- return [...uleb4(code.length), ...code];
33286
+ return [...encodeWasmNumber(code.length), ...code];
33434
33287
  });
33435
33288
  return Uint8Array.from([
33436
33289
  0,
@@ -33448,21 +33301,21 @@ function sdkImportThunks(bytes) {
33448
33301
  ...sectionBytes(
33449
33302
  2,
33450
33303
  vector([
33451
- [...encodedName2("env"), ...encodedName2("__indirect_function_table"), 1, ...table],
33304
+ [...encodeWasmName("env"), ...encodeWasmName("__indirect_function_table"), 1, ...table],
33452
33305
  [
33453
- ...encodedName2(NATIVE_LAZY_IMPORT_MODULE),
33454
- ...encodedName2(NATIVE_LAZY_SLOT_IMPORT),
33306
+ ...encodeWasmName(NATIVE_LAZY_IMPORT_MODULE),
33307
+ ...encodeWasmName(NATIVE_LAZY_SLOT_IMPORT),
33455
33308
  0,
33456
33309
  0
33457
33310
  ],
33458
33311
  ...slotGlobals
33459
33312
  ])
33460
33313
  ),
33461
- ...sectionBytes(3, vector(imports2.map(({ type }) => uleb4(typeIndex.get(type))))),
33314
+ ...sectionBytes(3, vector(imports2.map(({ type }) => encodeWasmNumber(typeIndex.get(type))))),
33462
33315
  ...sectionBytes(
33463
33316
  7,
33464
33317
  vector(
33465
- imports2.map(({ slot }, i) => [...encodedName2(String(slot)), 0, ...uleb4(i + 1)])
33318
+ imports2.map(({ slot }, i) => [...encodeWasmName(String(slot)), 0, ...encodeWasmNumber(i + 1)])
33466
33319
  )
33467
33320
  ),
33468
33321
  ...sectionBytes(10, vector(bodies))
@@ -33582,7 +33435,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
33582
33435
  syntheticGlobals.push(type);
33583
33436
  got.set(index, value);
33584
33437
  }
33585
- return [35, ...uleb4(index)];
33438
+ return [35, ...encodeWasmNumber(index)];
33586
33439
  };
33587
33440
  const tlsHelpers = new Map(
33588
33441
  symbols.filter((symbol2) => symbol2.kind === 0 && symbol2.name.startsWith(SDK_TLS_HELPER)).map((symbol2) => [symbol2.name.slice(SDK_TLS_HELPER.length), symbol2.index])
@@ -33634,7 +33487,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
33634
33487
  const code = [16];
33635
33488
  for (let i = 0, rest = helper; i < 5; i++, rest >>>= 7)
33636
33489
  code.push(i < 4 ? rest & 127 | 128 : rest & 127);
33637
- if (addend) code.push(66, ...sleb2(addend), 124);
33490
+ if (addend) code.push(66, ...encodeWasmSigned(addend), 124);
33638
33491
  patchCode(at2, 11, code);
33639
33492
  continue;
33640
33493
  }
@@ -33708,7 +33561,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
33708
33561
  syntheticGlobals.push(valueType);
33709
33562
  scratchGlobals.set(valueType, scratch2);
33710
33563
  }
33711
- const index = uleb4(scratch2);
33564
+ const index = encodeWasmNumber(scratch2);
33712
33565
  patchCode(at - 2, 12, [
33713
33566
  36,
33714
33567
  ...index,
@@ -33724,7 +33577,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
33724
33577
  }
33725
33578
  const encodedNameBuf = (name3) => {
33726
33579
  const raw2 = Buffer.from(name3, "utf8");
33727
- const len = uleb4(raw2.length);
33580
+ const len = encodeWasmNumber(raw2.length);
33728
33581
  const out = Buffer.allocUnsafe(len.length + raw2.length);
33729
33582
  for (let i = 0; i < len.length; i++) out[i] = len[i];
33730
33583
  raw2.copy(out, len.length);
@@ -33769,7 +33622,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
33769
33622
  }
33770
33623
  }
33771
33624
  const globalParts = [
33772
- Buffer.from(uleb4(globalCount - 1 + syntheticGlobals.length))
33625
+ Buffer.from(encodeWasmNumber(globalCount - 1 + syntheticGlobals.length))
33773
33626
  ];
33774
33627
  for (let index = 0; index < globalCount; index++) {
33775
33628
  const start = gr.at;
@@ -33814,18 +33667,18 @@ function resolveSdkReferences(source, sdk2, forwarders) {
33814
33667
  }
33815
33668
  }
33816
33669
  const exportParts = [
33817
- Buffer.from(uleb4(exportCount + 1 + got.size)),
33670
+ Buffer.from(encodeWasmNumber(exportCount + 1 + got.size)),
33818
33671
  bytes.subarray(originalExportsStart, exportSection.end)
33819
33672
  ];
33820
33673
  for (const [index, value] of got) {
33821
33674
  exportParts.push(
33822
33675
  encodedNameBuf(`${NATIVE_SDK_GLOBAL_PREFIX}${value}.${index}`),
33823
- Buffer.from([3, ...uleb4(index)])
33676
+ Buffer.from([3, ...encodeWasmNumber(index)])
33824
33677
  );
33825
33678
  }
33826
33679
  exportParts.push(encodedNameBuf("__indirect_function_table"), Buffer.from([1, 0]));
33827
33680
  const replaced = /* @__PURE__ */ new Map([
33828
- [2, Buffer.concat([Buffer.from(uleb4(importEntryCount)), ...importParts])],
33681
+ [2, Buffer.concat([Buffer.from(encodeWasmNumber(importEntryCount)), ...importParts])],
33829
33682
  [6, Buffer.concat(globalParts)],
33830
33683
  [7, Buffer.concat(exportParts)]
33831
33684
  ]);
@@ -33842,7 +33695,7 @@ function resolveSdkReferences(source, sdk2, forwarders) {
33842
33695
  if (s.id === 10 && rebuiltCode) {
33843
33696
  parts.push(rebuiltCode);
33844
33697
  } else if (payload) {
33845
- parts.push(Buffer.from([s.id, ...uleb4(payload.length)]), payload);
33698
+ parts.push(Buffer.from([s.id, ...encodeWasmNumber(payload.length)]), payload);
33846
33699
  } else {
33847
33700
  parts.push(bytes.subarray(s.offset, s.end));
33848
33701
  }
@@ -33858,7 +33711,7 @@ function expandSdkRelocations(bytes, section2, patches) {
33858
33711
  patches.sort((a, b) => a.at - b.at);
33859
33712
  const r = wasmReader(bytes, section2.start);
33860
33713
  const count = r.u();
33861
- const payload = [Uint8Array.from(uleb4(count))];
33714
+ const payload = [Uint8Array.from(encodeWasmNumber(count))];
33862
33715
  let next = 0;
33863
33716
  for (let i = 0; i < count; i++) {
33864
33717
  const start = r.at;
@@ -33878,7 +33731,7 @@ function expandSdkRelocations(bytes, section2, patches) {
33878
33731
  }
33879
33732
  parts.push(bytes.subarray(at, end));
33880
33733
  payload.push(
33881
- Uint8Array.from(uleb4(parts.reduce((size3, part) => size3 + part.length, 0))),
33734
+ Uint8Array.from(encodeWasmNumber(parts.reduce((size3, part) => size3 + part.length, 0))),
33882
33735
  ...parts
33883
33736
  );
33884
33737
  }
@@ -33887,7 +33740,7 @@ function expandSdkRelocations(bytes, section2, patches) {
33887
33740
  if (next !== patches.length || r.at !== section2.end)
33888
33741
  throw new Error("Swift SDK code relocations exceed the code section");
33889
33742
  return Buffer.concat([
33890
- Uint8Array.from([10, ...uleb4(payload.reduce((size2, part) => size2 + part.length, 0))]),
33743
+ Uint8Array.from([10, ...encodeWasmNumber(payload.reduce((size2, part) => size2 + part.length, 0))]),
33891
33744
  ...payload
33892
33745
  ]);
33893
33746
  }
@@ -34579,7 +34432,7 @@ function partitionParent(section2) {
34579
34432
  "__objc_class_refs"
34580
34433
  ].find((name3) => section2 === name3 || section2.startsWith(`${name3}.`));
34581
34434
  }
34582
- var import_node_child_process29, import_node_crypto31, import_node_fs46, import_node_path45, import_node_util9, import_node_zlib5, run3, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, uleb4, sleb2, encodedName2, SCANNED, RUN_GAP;
34435
+ var import_node_child_process29, import_node_crypto31, import_node_fs46, import_node_path45, import_node_util9, import_node_zlib5, run3, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, SCANNED, RUN_GAP;
34583
34436
  var init_swift_sdk_app_module = __esm({
34584
34437
  "src/swift-sdk-app-module.ts"() {
34585
34438
  "use strict";
@@ -34602,6 +34455,7 @@ var init_swift_sdk_app_module = __esm({
34602
34455
  init_swift_wasm_prune();
34603
34456
  init_swiftSdkLinkContract();
34604
34457
  init_swiftTargetContract();
34458
+ init_wasm_binary_sections();
34605
34459
  init_wasm_narrow_boundary();
34606
34460
  init_wasm_optimize();
34607
34461
  run3 = (0, import_node_util9.promisify)(import_node_child_process29.execFile);
@@ -34622,32 +34476,6 @@ var init_swift_sdk_app_module = __esm({
34622
34476
  SDK_TLS_HELPER = "__peach_sdk_tls.";
34623
34477
  SDK_TLS_DELTA = "__peach_sdk_tls_delta.";
34624
34478
  OBJC_SECTION_BOUNDARY = /^__(?:start|stop)_(__objc_(?:selectors|classes|class_refs|cats|protocols|protocol_refs|class_aliases|constant_string))$/;
34625
- uleb4 = (value) => {
34626
- const out = [];
34627
- do {
34628
- let byte = value % 128;
34629
- value = Math.floor(value / 128);
34630
- if (value) byte |= 128;
34631
- out.push(byte);
34632
- } while (value);
34633
- return out;
34634
- };
34635
- sleb2 = (value) => {
34636
- const out = [];
34637
- for (; ; ) {
34638
- const byte = Number(value & 127n);
34639
- value >>= 7n;
34640
- if (value === 0n && !(byte & 64) || value === -1n && byte & 64) {
34641
- out.push(byte);
34642
- return out;
34643
- }
34644
- out.push(byte | 128);
34645
- }
34646
- };
34647
- encodedName2 = (name3) => {
34648
- const bytes = [...Buffer.from(name3)];
34649
- return [...uleb4(bytes.length), ...bytes];
34650
- };
34651
34479
  SCANNED = /* @__PURE__ */ new Set([
34652
34480
  "swift5_protocols",
34653
34481
  "swift5_protocol_conformances",
@@ -35738,36 +35566,22 @@ function archiveMember(archive, name3) {
35738
35566
  throw new Error(`swift-icu: ${name3} is not in the sdk's icu archive`);
35739
35567
  }
35740
35568
  function icuSegment(object8) {
35741
- let at = 8;
35742
- const leb2 = () => {
35743
- let result = 0;
35744
- let shift = 0;
35745
- let byte;
35746
- do {
35747
- byte = object8[at++];
35748
- result += (byte & 127) * 2 ** shift;
35749
- shift += 7;
35750
- } while (byte & 128);
35751
- return result;
35752
- };
35753
35569
  const found = [];
35754
- while (at < object8.length) {
35755
- const id = object8[at++];
35756
- const size2 = leb2();
35757
- const end = at + size2;
35758
- if (id === 11) {
35759
- for (let count = leb2(); count > 0; count--) {
35760
- if (leb2() !== 0) throw new Error("swift-icu: unexpected data segment kind");
35761
- at++;
35762
- leb2();
35763
- at++;
35764
- const length = leb2();
35765
- const bytes = object8.subarray(at, at + length);
35766
- if (bytes[2] === 218 && bytes[3] === 39) found.push(bytes);
35767
- at += length;
35768
- }
35570
+ for (const section2 of wasmSections(object8)) {
35571
+ if (section2.id !== 11) continue;
35572
+ const reader = readWasmSection(object8, section2.start, section2.end);
35573
+ for (let count = reader.number(); count > 0; count--) {
35574
+ if (reader.number() !== 0)
35575
+ throw new Error("swift-icu: unexpected data segment kind");
35576
+ reader.byte();
35577
+ reader.number();
35578
+ reader.byte();
35579
+ const length = reader.number();
35580
+ const start = reader.position();
35581
+ const bytes = object8.subarray(start, start + length);
35582
+ if (bytes[2] === 218 && bytes[3] === 39) found.push(bytes);
35583
+ reader.skip(length);
35769
35584
  }
35770
- at = end;
35771
35585
  }
35772
35586
  if (found.length !== 1)
35773
35587
  throw new Error(`swift-icu: expected one icu data segment, found ${found.length}`);
@@ -35821,6 +35635,7 @@ var init_swift_icu = __esm({
35821
35635
  init_icuData();
35822
35636
  init_swift_toolchain();
35823
35637
  init_swiftTargetContract();
35638
+ init_wasm_binary_sections();
35824
35639
  run4 = (0, import_node_util10.promisify)(import_node_child_process31.execFile);
35825
35640
  deflate = (0, import_node_util10.promisify)(import_node_zlib6.gzip);
35826
35641
  compressBrotli = (0, import_node_util10.promisify)(import_node_zlib6.brotliCompress);
@@ -42544,7 +42359,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
42544
42359
  REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
42545
42360
  MULTI_MANIFEST_VERSION = 76;
42546
42361
  SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
42547
- compilerSourceDigest = true ? "3bdbb1d31ba7d202e612a91b60a3b588f9bc94a11990fb114585b3e2521857f5" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
42362
+ compilerSourceDigest = true ? "05ea8272883560029dae1c9aef2497d3f4d9e0d3418ef288c47c562673f5ba19" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
42548
42363
  nativeCxxCompilerFlags = ["-fno-cxx-modules"];
42549
42364
  MODULE_MAP_RESPONSE_FILE_RUN = 16;
42550
42365
  cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));
@@ -88649,7 +88464,7 @@ var init_swift_standin_digest = __esm({
88649
88464
  ];
88650
88465
  RUNTIME_IMPORT = /(?:^|[;\n])[ \t]*(?:import|export)\s+(?!type(?:\s|\{))([\s\S]*?)\s+from\s*['"]([^'"]+)['"]|(?:^|[;\n])[ \t]*import\s+['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
88651
88466
  standinSourceDigest = (srcDir = __sootsim_import_meta_dirname) => sourceClosureDigest(srcDir, STANDIN_DIGEST_ENTRYPOINTS, STANDIN_DIGEST_EXCLUDED_FILES);
88652
- STANDIN_SOURCE_DIGEST = true ? "b6aa8eda1952d06a101c0a46227f227fb983255bb2a5f825515d7b9bc6f8650d" : standinSourceDigest();
88467
+ STANDIN_SOURCE_DIGEST = true ? "8b7dccbe4ecedba9dc6511eb4ab2e02ce2922969fcd9eebc93f3280c6529a48b" : standinSourceDigest();
88653
88468
  }
88654
88469
  });
88655
88470
 
@@ -107485,7 +107300,7 @@ var init_nitro_superset = __esm({
107485
107300
  init_nitroContract();
107486
107301
  init_swift_standin_digest();
107487
107302
  NITRO_SUPERSET_ENTRY_NAME = "superset";
107488
- NITRO_COMPILER_DIGEST = true ? "9e51ce132e701d77aa700249b4788f66b041f8f00fbd0bac84d9a3c8ed3a7569" : nitroCompilerSourceDigest(__sootsim_import_meta_dirname, STANDIN_SOURCE_DIGEST2);
107303
+ NITRO_COMPILER_DIGEST = true ? "4a3a6b72ce59c3936e7aa74be126ecd9fae095591d2808e5f7a2cad75c921084" : nitroCompilerSourceDigest(__sootsim_import_meta_dirname, STANDIN_SOURCE_DIGEST2);
107489
107304
  nitroSupersetLock = parseLock(nitro_superset_lock_default);
107490
107305
  nitroSupersetKey = (inputs2) => nativeEntryKey({ ...inputs2, compiler: NITRO_COMPILER_DIGEST });
107491
107306
  published = /* @__PURE__ */ new Map();
@@ -108189,7 +108004,7 @@ var init_expo_eager_seam_contract = __esm({
108189
108004
 
108190
108005
  // src/expo-native-compiler-digest.ts
108191
108006
  function expoNativeCompilerDigestValue() {
108192
- return true ? "d396bac9636107aeb95f7657c77fa10e270f50f4ac8935e007b088b2ef65dfc8" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
108007
+ return true ? "4dc23720ffaa03d981b544bb7024c9d2dc67271f54484b348e256cad727bd94f" : expoNativeCompilerDigest(__sootsim_import_meta_dirname);
108193
108008
  }
108194
108009
  var import_node_crypto80;
108195
108010
  var init_expo_native_compiler_digest = __esm({