eliscript 0.1.3 → 0.1.4

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 (526) hide show
  1. package/COPYING.RUNTIME +93 -0
  2. package/README.md +15 -3
  3. package/bin/eliscript-test +29 -0
  4. package/bootstrap/backends/README.md +5 -4
  5. package/bootstrap/backends/binary.eli +89 -22
  6. package/bootstrap/backends/capabilities.eli +9 -4
  7. package/bootstrap/backends/managed-layout.eli +93 -81
  8. package/bootstrap/backends/managed.eli +651 -125
  9. package/bootstrap/backends/native.eli +1791 -324
  10. package/bootstrap/backends/numeric.eli +71 -7
  11. package/bootstrap/backends/sha256.eli +165 -68
  12. package/bootstrap/backends/wasm.eli +461 -52
  13. package/bootstrap/compiler/analyzer.eli +692 -2
  14. package/bootstrap/compiler/compiler.eli +16 -3
  15. package/bootstrap/compiler/emitter.eli +80 -35
  16. package/bootstrap/compiler/project.eli +175 -1
  17. package/bootstrap/compiler/transient-analysis.eli +2 -2
  18. package/bootstrap/host/build.eli +1 -0
  19. package/bootstrap/host/build.mjs +1 -1
  20. package/bootstrap/host/build.mjs.map +1 -1
  21. package/bootstrap/host/bun.mjs +7 -9
  22. package/bootstrap/host/bun.mjs.map +1 -1
  23. package/bootstrap/host/check-cli-ground.eli +47 -5
  24. package/bootstrap/host/check-cli-ground.mjs +60 -19
  25. package/bootstrap/host/check-cli-ground.mjs.map +1 -1
  26. package/bootstrap/host/check-cli.mjs +41 -1
  27. package/bootstrap/host/check-cli.mjs.map +1 -1
  28. package/bootstrap/host/compiler-session.eli +136 -22
  29. package/bootstrap/host/eliscript-cli.mjs +1 -1
  30. package/bootstrap/host/eliscript-cli.mjs.map +1 -1
  31. package/bootstrap/host/evaluation-cli.eli +33 -1
  32. package/bootstrap/host/evaluation-cli.mjs +65 -28
  33. package/bootstrap/host/evaluation-cli.mjs.map +1 -1
  34. package/bootstrap/host/evaluation.eli +651 -42
  35. package/bootstrap/host/evaluation.mjs +884 -72
  36. package/bootstrap/host/evaluation.mjs.map +1 -1
  37. package/bootstrap/host/project-cli-ground.eli +6 -1
  38. package/bootstrap/host/project-cli-ground.mjs +33 -32
  39. package/bootstrap/host/project-cli-ground.mjs.map +1 -1
  40. package/bootstrap/host/project-cli.mjs +1 -1
  41. package/bootstrap/host/project-cli.mjs.map +1 -1
  42. package/bootstrap/host/project-ground.eli +266 -45
  43. package/bootstrap/host/project-ground.mjs +429 -159
  44. package/bootstrap/host/project-ground.mjs.map +1 -1
  45. package/bootstrap/host/project.mjs +30 -40
  46. package/bootstrap/host/project.mjs.map +1 -1
  47. package/bootstrap/host/test-cli.eli +379 -0
  48. package/bootstrap/host/test-cli.mjs +494 -0
  49. package/bootstrap/host/test-cli.mjs.map +1 -0
  50. package/browser/README.md +7 -0
  51. package/browser/host.mjs +21 -29
  52. package/browser/host.mjs.map +1 -1
  53. package/browser/worker.mjs +7 -9
  54. package/browser/worker.mjs.map +1 -1
  55. package/compiler/eliscript-analyzer.el +694 -0
  56. package/compiler/eliscript-cli.el +66 -22
  57. package/compiler/eliscript-emitter.el +67 -43
  58. package/compiler/eliscript-ir-emitter.el +71 -36
  59. package/compiler/eliscript-project.el +360 -80
  60. package/compiler/eliscript-transient-analysis.el +5 -5
  61. package/compiler/eliscript.el +6 -0
  62. package/dist/backends/binary.mjs +148 -26
  63. package/dist/backends/binary.mjs.map +1 -1
  64. package/dist/backends/capabilities.mjs +11 -4
  65. package/dist/backends/capabilities.mjs.map +1 -1
  66. package/dist/backends/elf.mjs +4 -4
  67. package/dist/backends/elf.mjs.map +1 -1
  68. package/dist/backends/managed-layout.mjs +53 -56
  69. package/dist/backends/managed-layout.mjs.map +1 -1
  70. package/dist/backends/managed.mjs +1116 -375
  71. package/dist/backends/managed.mjs.map +1 -1
  72. package/dist/backends/memory.mjs +24 -26
  73. package/dist/backends/memory.mjs.map +1 -1
  74. package/dist/backends/native.mjs +2529 -434
  75. package/dist/backends/native.mjs.map +1 -1
  76. package/dist/backends/numeric.mjs +140 -33
  77. package/dist/backends/numeric.mjs.map +1 -1
  78. package/dist/backends/optimize.mjs +2 -2
  79. package/dist/backends/optimize.mjs.map +1 -1
  80. package/dist/backends/regexp.mjs +33 -35
  81. package/dist/backends/regexp.mjs.map +1 -1
  82. package/dist/backends/sha256.mjs +159 -59
  83. package/dist/backends/sha256.mjs.map +1 -1
  84. package/dist/backends/wasm.mjs +609 -73
  85. package/dist/backends/wasm.mjs.map +1 -1
  86. package/dist/bootstrap/analyzer.mjs +1018 -2
  87. package/dist/bootstrap/analyzer.mjs.map +1 -1
  88. package/dist/bootstrap/compiler.mjs +30 -23
  89. package/dist/bootstrap/compiler.mjs.map +1 -1
  90. package/dist/bootstrap/emitter.mjs +206 -161
  91. package/dist/bootstrap/emitter.mjs.macro-origins.json +16 -16
  92. package/dist/bootstrap/emitter.mjs.map +1 -1
  93. package/dist/bootstrap/expander.mjs +27 -31
  94. package/dist/bootstrap/expander.mjs.map +1 -1
  95. package/dist/bootstrap/ir.mjs +22 -24
  96. package/dist/bootstrap/ir.mjs.map +1 -1
  97. package/dist/bootstrap/project.mjs +246 -1
  98. package/dist/bootstrap/project.mjs.map +1 -1
  99. package/dist/bootstrap/reader.mjs +2 -2
  100. package/dist/bootstrap/reader.mjs.map +1 -1
  101. package/dist/bootstrap/source-map.mjs +34 -48
  102. package/dist/bootstrap/source-map.mjs.map +1 -1
  103. package/dist/bootstrap/transient-analysis.mjs +2 -2
  104. package/dist/bootstrap/transient-analysis.mjs.map +1 -1
  105. package/dist/browser/compiler.js +106 -106
  106. package/dist/browser/host.mjs +21 -29
  107. package/dist/browser/loader.js +1 -1
  108. package/dist/browser/worker.mjs +95 -95
  109. package/dist/compiler-artifact.json +1 -1
  110. package/dist/host/compiler-session.mjs +405 -228
  111. package/dist/host/compiler-session.mjs.map +1 -1
  112. package/dist/host/compiler-tools.mjs +44 -46
  113. package/dist/host/compiler-tools.mjs.map +1 -1
  114. package/dist/literal-sources/runtime/core/array-map.eli +45 -0
  115. package/dist/literal-sources/runtime/core/collection-internals.eli +22 -2
  116. package/dist/literal-sources/runtime/core/collection.eli +282 -23
  117. package/dist/literal-sources/runtime/core/data-text.eli +196 -13
  118. package/dist/literal-sources/runtime/core/data.eli +1 -1
  119. package/dist/literal-sources/runtime/core/identifier.eli +1 -1
  120. package/dist/literal-sources/runtime/core/lazy-sequence.eli +822 -44
  121. package/dist/literal-sources/runtime/core/list.eli +1 -1
  122. package/dist/literal-sources/runtime/core/map.eli +1 -1
  123. package/dist/literal-sources/runtime/core/metadata-internals.eli +2 -2
  124. package/dist/literal-sources/runtime/core/metadata.eli +2 -2
  125. package/dist/literal-sources/{stdlib/core/object.eli → runtime/core/object-impl.eli} +6 -6
  126. package/dist/literal-sources/runtime/core/object.eli +1 -1
  127. package/dist/literal-sources/runtime/core/order.eli +3 -3
  128. package/dist/literal-sources/runtime/core/persistent-kind.eli +1 -1
  129. package/dist/literal-sources/{stdlib/core/protocol.eli → runtime/core/protocol-impl.eli} +2 -2
  130. package/dist/literal-sources/runtime/core/protocol.eli +5 -3
  131. package/dist/literal-sources/runtime/core/queue.eli +1 -1
  132. package/dist/literal-sources/runtime/core/record.eli +3 -3
  133. package/dist/literal-sources/runtime/core/regex.eli +2 -2
  134. package/dist/literal-sources/runtime/core/sequence.eli +1 -1
  135. package/dist/literal-sources/runtime/core/set-algebra.eli +1 -1
  136. package/dist/literal-sources/runtime/core/set.eli +1 -1
  137. package/dist/literal-sources/runtime/core/sorted.eli +4 -4
  138. package/dist/literal-sources/{stdlib/core/text.eli → runtime/core/text-impl.eli} +2 -2
  139. package/dist/literal-sources/runtime/core/text.eli +1 -1
  140. package/dist/literal-sources/runtime/core/transducer.eli +24 -2
  141. package/dist/literal-sources/runtime/core/transient.eli +7 -5
  142. package/dist/literal-sources/runtime/core/type.eli +1 -1
  143. package/dist/literal-sources/runtime/core/value-internals.eli +3 -3
  144. package/dist/literal-sources/runtime/core/value.eli +2 -2
  145. package/dist/literal-sources/runtime/core/vector.eli +5 -2
  146. package/dist/literal-sources/{stdlib → runtime/managed}/managed-literal-protocols.eli +100 -34
  147. package/dist/literal-sources/{stdlib → runtime/managed}/managed-literals.eli +406 -81
  148. package/{stdlib → dist/literal-sources/runtime/managed}/managed-queue-state.eli +1 -1
  149. package/{stdlib → dist/literal-sources/runtime/managed}/managed-sorted-state.eli +1 -1
  150. package/dist/literal-sources/runtime/managed/managed-transient-state.eli +1206 -0
  151. package/{stdlib → dist/literal-sources/runtime/managed}/managed-value-state.eli +30 -6
  152. package/dist/literal-sources/{stdlib → runtime/managed}/managed-vector-view-state.eli +1 -1
  153. package/dist/literal-sources/runtime/wire/http-rpc.eli +1 -1
  154. package/dist/literal-sources/runtime/wire/markdown.eli +1 -1
  155. package/dist/literal-sources/runtime/wire/schema.eli +1 -1
  156. package/dist/literal-sources/stdlib/bit.eli +89 -1
  157. package/dist/literal-sources/stdlib/data.eli +522 -0
  158. package/dist/literal-sources/stdlib/interop/object.eli +39 -0
  159. package/dist/literal-sources/stdlib/persistent-list.eli +60 -21
  160. package/dist/literal-sources/stdlib/persistent-map.eli +335 -324
  161. package/dist/literal-sources/stdlib/persistent-set.eli +8 -6
  162. package/dist/literal-sources/stdlib/persistent-vector.eli +18 -18
  163. package/dist/literal-sources/stdlib/protocol.eli +63 -0
  164. package/{stdlib/core → dist/literal-sources/stdlib}/set.eli +8 -8
  165. package/dist/literal-sources/stdlib/string.eli +362 -0
  166. package/dist/runtime/lisp/async-runtime.mjs +55 -59
  167. package/dist/runtime/lisp/async-runtime.mjs.map +1 -1
  168. package/dist/runtime/lisp/builtins.mjs +232 -280
  169. package/dist/runtime/lisp/builtins.mjs.map +1 -1
  170. package/dist/runtime/lisp/cli.mjs +159 -167
  171. package/dist/runtime/lisp/cli.mjs.map +1 -1
  172. package/dist/runtime/lisp/compiler.mjs +359 -419
  173. package/dist/runtime/lisp/compiler.mjs.map +1 -1
  174. package/dist/runtime/lisp/core.mjs +24 -24
  175. package/dist/runtime/lisp/core.mjs.map +1 -1
  176. package/dist/runtime/lisp/evaluator.mjs +315 -385
  177. package/dist/runtime/lisp/evaluator.mjs.map +1 -1
  178. package/dist/runtime/lisp/extensions.mjs +85 -103
  179. package/dist/runtime/lisp/extensions.mjs.map +1 -1
  180. package/dist/runtime/lisp/host-io.mjs +106 -122
  181. package/dist/runtime/lisp/host-io.mjs.map +1 -1
  182. package/dist/runtime/lisp/io-worker.mjs +117 -135
  183. package/dist/runtime/lisp/io-worker.mjs.map +1 -1
  184. package/dist/runtime/lisp/keymap.mjs +5 -5
  185. package/dist/runtime/lisp/keymap.mjs.map +1 -1
  186. package/dist/runtime/lisp/macros-forms.mjs +49 -51
  187. package/dist/runtime/lisp/macros-forms.mjs.map +1 -1
  188. package/dist/runtime/lisp/reader-format.mjs +31 -31
  189. package/dist/runtime/lisp/reader-format.mjs.map +1 -1
  190. package/dist/runtime/lisp/regexp-buffer.mjs +9 -9
  191. package/dist/runtime/lisp/regexp-buffer.mjs.map +1 -1
  192. package/dist/runtime/math.mjs +32 -38
  193. package/dist/runtime/math.mjs.map +1 -1
  194. package/dist/runtime/number-radix.mjs +5 -7
  195. package/dist/runtime/number-radix.mjs.map +1 -1
  196. package/dist/runtime/primitives.mjs +81 -46
  197. package/dist/runtime/primitives.mjs.macro-origins.json +294 -44
  198. package/dist/runtime/primitives.mjs.map +1 -1
  199. package/dist/runtime/unicode-case.mjs +6 -6
  200. package/dist/runtime/unicode-case.mjs.map +1 -1
  201. package/dist/runtime.eli +3068 -1882
  202. package/dist/stage3-release.json +1 -1
  203. package/dist/stdlib/async.mjs +1838 -0
  204. package/dist/stdlib/bit.mjs +116 -0
  205. package/dist/stdlib/collection.mjs +193 -0
  206. package/dist/stdlib/core.mjs +28 -0
  207. package/dist/stdlib/data-text.mjs +54 -0
  208. package/dist/stdlib/data.mjs +601 -0
  209. package/dist/stdlib/devtools.mjs +565 -0
  210. package/dist/stdlib/diff.mjs +180 -0
  211. package/dist/stdlib/fn.mjs +164 -0
  212. package/dist/stdlib/hierarchy.mjs +189 -0
  213. package/dist/stdlib/identifier.mjs +33 -0
  214. package/dist/stdlib/interop/js.mjs +706 -0
  215. package/dist/stdlib/interop/object.mjs +40 -0
  216. package/dist/stdlib/json.mjs +843 -0
  217. package/dist/stdlib/lazy-sequence.mjs +117 -0
  218. package/dist/stdlib/math.mjs +386 -0
  219. package/dist/stdlib/meta.mjs +21 -0
  220. package/dist/stdlib/multimethod.mjs +345 -0
  221. package/dist/stdlib/numeric.mjs +327 -0
  222. package/dist/stdlib/order.mjs +194 -0
  223. package/dist/stdlib/persistent-list.mjs +171 -0
  224. package/dist/stdlib/persistent-map.mjs +781 -0
  225. package/dist/stdlib/persistent-queue.mjs +44 -0
  226. package/dist/stdlib/persistent-set.mjs +225 -0
  227. package/dist/stdlib/persistent-vector.mjs +316 -0
  228. package/dist/stdlib/portable/data-text.mjs +1094 -0
  229. package/dist/stdlib/portable/data.mjs +62 -0
  230. package/dist/stdlib/portable/identifier.mjs +179 -0
  231. package/dist/stdlib/portable/metadata.mjs +63 -0
  232. package/dist/stdlib/portable/object.mjs +140 -0
  233. package/dist/stdlib/portable/sequence.mjs +142 -0
  234. package/dist/stdlib/portable/text.mjs +111 -0
  235. package/dist/stdlib/pprint.mjs +807 -0
  236. package/dist/stdlib/protocol.mjs +61 -0
  237. package/dist/stdlib/record.mjs +25 -0
  238. package/dist/stdlib/regex.mjs +115 -0
  239. package/dist/stdlib/result.mjs +198 -0
  240. package/dist/stdlib/schema.mjs +2828 -0
  241. package/dist/stdlib/seq.mjs +913 -0
  242. package/dist/stdlib/set.mjs +317 -0
  243. package/dist/stdlib/sorted.mjs +56 -0
  244. package/dist/stdlib/state.mjs +451 -0
  245. package/dist/stdlib/string.mjs +494 -0
  246. package/dist/stdlib/tap.mjs +187 -0
  247. package/dist/stdlib/test.mjs +669 -0
  248. package/dist/stdlib/time.mjs +522 -0
  249. package/dist/stdlib/transducer.mjs +85 -0
  250. package/dist/stdlib/transient.mjs +32 -0
  251. package/dist/stdlib/type.mjs +28 -0
  252. package/dist/stdlib/uuid.mjs +377 -0
  253. package/dist/stdlib/value.mjs +334 -0
  254. package/dist/stdlib/walk.mjs +243 -0
  255. package/dist/stdlib/wire/gepo.mjs +28 -0
  256. package/dist/stdlib/wire/mdp.mjs +13 -0
  257. package/dist/stdlib/wire/mds.mjs +10 -0
  258. package/dist/stdlib/zipper.mjs +1025 -0
  259. package/editor/README.md +15 -0
  260. package/editor/eliscript-data.el +221 -8
  261. package/editor/eliscript-mode.el +207 -48
  262. package/editor/eliscript-runtime.el +6 -3
  263. package/package.json +49 -15
  264. package/platform/README.md +6 -0
  265. package/platform/browser.mjs +10 -12
  266. package/platform/browser.mjs.map +1 -1
  267. package/runtime/README.md +12 -5
  268. package/runtime/core/array-map.eli +538 -0
  269. package/runtime/core/array-map.mjs +651 -0
  270. package/runtime/core/array-map.mjs.map +1 -0
  271. package/runtime/core/collection-internals.eli +85 -33
  272. package/runtime/core/collection-internals.mjs +245 -193
  273. package/runtime/core/collection-internals.mjs.map +1 -1
  274. package/runtime/core/collection.eli +105 -3
  275. package/runtime/core/collection.mjs +190 -53
  276. package/runtime/core/collection.mjs.map +1 -1
  277. package/runtime/core/data-text.eli +224 -16
  278. package/runtime/core/data-text.mjs +345 -83
  279. package/runtime/core/data-text.mjs.map +1 -1
  280. package/runtime/core/data.eli +50 -33
  281. package/runtime/core/data.mjs +72 -36
  282. package/runtime/core/data.mjs.map +1 -1
  283. package/runtime/core/identifier.mjs +15 -19
  284. package/runtime/core/identifier.mjs.map +1 -1
  285. package/runtime/core/lazy-sequence.eli +885 -15
  286. package/runtime/core/lazy-sequence.mjs +1265 -38
  287. package/runtime/core/lazy-sequence.mjs.map +1 -1
  288. package/runtime/core/map-internals.eli +209 -1
  289. package/runtime/core/map-internals.mjs +359 -71
  290. package/runtime/core/map-internals.mjs.map +1 -1
  291. package/runtime/core/map.eli +75 -7
  292. package/runtime/core/map.mjs +122 -47
  293. package/runtime/core/map.mjs.map +1 -1
  294. package/{stdlib/core/object.eli → runtime/core/object-impl.eli} +6 -6
  295. package/runtime/core/object-impl.mjs +5 -5
  296. package/runtime/core/object-impl.mjs.map +1 -1
  297. package/runtime/core/order.eli +15 -3
  298. package/runtime/core/order.mjs +23 -8
  299. package/runtime/core/order.mjs.map +1 -1
  300. package/runtime/core/persistent-kind.mjs +9 -13
  301. package/runtime/core/persistent-kind.mjs.map +1 -1
  302. package/runtime/core/protocol-error.mjs +9 -11
  303. package/runtime/core/protocol-error.mjs.map +1 -1
  304. package/{stdlib/core/protocol.eli → runtime/core/protocol-impl.eli} +2 -2
  305. package/runtime/core/protocol-impl.mjs +10 -10
  306. package/runtime/core/protocol-impl.mjs.map +1 -1
  307. package/runtime/core/queue.mjs +14 -16
  308. package/runtime/core/queue.mjs.map +1 -1
  309. package/runtime/core/record.eli +2 -2
  310. package/runtime/core/record.mjs +13 -17
  311. package/runtime/core/record.mjs.map +1 -1
  312. package/runtime/core/regex.mjs +18 -22
  313. package/runtime/core/regex.mjs.map +1 -1
  314. package/runtime/core/sequence.eli +33 -31
  315. package/runtime/core/sequence.mjs +60 -93
  316. package/runtime/core/sequence.mjs.map +1 -1
  317. package/runtime/core/set.eli +53 -27
  318. package/runtime/core/set.mjs +113 -82
  319. package/runtime/core/set.mjs.map +1 -1
  320. package/runtime/core/sorted.mjs +91 -108
  321. package/runtime/core/sorted.mjs.map +1 -1
  322. package/{stdlib/core/text.eli → runtime/core/text-impl.eli} +2 -2
  323. package/runtime/core/text-impl.mjs +1 -1
  324. package/runtime/core/text-impl.mjs.map +1 -1
  325. package/runtime/core/transducer.eli +24 -0
  326. package/runtime/core/transducer.mjs +27 -1
  327. package/runtime/core/transducer.mjs.map +1 -1
  328. package/runtime/core/transient-internals.eli +12 -4
  329. package/runtime/core/transient-internals.mjs +19 -6
  330. package/runtime/core/transient-internals.mjs.map +1 -1
  331. package/runtime/core/transient.eli +31 -0
  332. package/runtime/core/transient.mjs +33 -2
  333. package/runtime/core/transient.mjs.map +1 -1
  334. package/runtime/core/value-internals.mjs +29 -35
  335. package/runtime/core/value-internals.mjs.map +1 -1
  336. package/runtime/core/vector.eli +73 -20
  337. package/runtime/core/vector.mjs +159 -156
  338. package/runtime/core/vector.mjs.map +1 -1
  339. package/runtime/literals.eli +16 -9
  340. package/runtime/literals.mjs +25 -9
  341. package/runtime/literals.mjs.map +1 -1
  342. package/{stdlib → runtime/managed}/managed-literal-protocols.eli +100 -34
  343. package/{stdlib → runtime/managed}/managed-literals.eli +406 -81
  344. package/{dist/literal-sources/stdlib → runtime/managed}/managed-queue-state.eli +1 -1
  345. package/runtime/managed/managed-runtime-array-map.eli +45 -0
  346. package/{stdlib → runtime/managed}/managed-runtime-collection-internals.eli +22 -2
  347. package/{stdlib → runtime/managed}/managed-runtime-collection.eli +282 -23
  348. package/{stdlib → runtime/managed}/managed-runtime-data-text.eli +196 -13
  349. package/{stdlib → runtime/managed}/managed-runtime-data.eli +1 -1
  350. package/{stdlib → runtime/managed}/managed-runtime-identifier.eli +1 -1
  351. package/runtime/managed/managed-runtime-lazy-sequence.eli +935 -0
  352. package/{stdlib → runtime/managed}/managed-runtime-list.eli +1 -1
  353. package/{stdlib → runtime/managed}/managed-runtime-map.eli +1 -1
  354. package/{stdlib → runtime/managed}/managed-runtime-metadata-internals.eli +2 -2
  355. package/{stdlib → runtime/managed}/managed-runtime-metadata.eli +2 -2
  356. package/{stdlib → runtime/managed}/managed-runtime-object.eli +1 -1
  357. package/{stdlib → runtime/managed}/managed-runtime-order.eli +3 -3
  358. package/{stdlib → runtime/managed}/managed-runtime-persistent-kind.eli +1 -1
  359. package/{stdlib → runtime/managed}/managed-runtime-protocol.eli +5 -3
  360. package/{stdlib → runtime/managed}/managed-runtime-queue.eli +1 -1
  361. package/{stdlib → runtime/managed}/managed-runtime-record.eli +3 -3
  362. package/{stdlib → runtime/managed}/managed-runtime-regex.eli +2 -2
  363. package/{stdlib → runtime/managed}/managed-runtime-sequence.eli +1 -1
  364. package/{stdlib → runtime/managed}/managed-runtime-set-algebra.eli +1 -1
  365. package/{stdlib → runtime/managed}/managed-runtime-set.eli +1 -1
  366. package/{stdlib → runtime/managed}/managed-runtime-sorted.eli +4 -4
  367. package/{stdlib → runtime/managed}/managed-runtime-text.eli +1 -1
  368. package/{stdlib → runtime/managed}/managed-runtime-transducer.eli +24 -2
  369. package/{stdlib → runtime/managed}/managed-runtime-transient.eli +7 -5
  370. package/{stdlib → runtime/managed}/managed-runtime-type.eli +1 -1
  371. package/{stdlib → runtime/managed}/managed-runtime-value-internals.eli +3 -3
  372. package/{stdlib → runtime/managed}/managed-runtime-value.eli +2 -2
  373. package/{stdlib → runtime/managed}/managed-runtime-vector.eli +5 -2
  374. package/{dist/literal-sources/stdlib → runtime/managed}/managed-sorted-state.eli +1 -1
  375. package/runtime/managed/managed-transient-state.eli +1206 -0
  376. package/{dist/literal-sources/stdlib → runtime/managed}/managed-value-state.eli +30 -6
  377. package/{stdlib → runtime/managed}/managed-vector-view-state.eli +1 -1
  378. package/{stdlib → runtime/managed}/managed-wire-http-rpc.eli +1 -1
  379. package/{stdlib → runtime/managed}/managed-wire-markdown.eli +1 -1
  380. package/{stdlib → runtime/managed}/managed-wire-schema.eli +1 -1
  381. package/runtime/math.mjs +32 -38
  382. package/runtime/math.mjs.map +1 -1
  383. package/runtime/number-radix.mjs +5 -7
  384. package/runtime/number-radix.mjs.map +1 -1
  385. package/runtime/primitives.eli +19 -6
  386. package/runtime/primitives.mjs +81 -46
  387. package/runtime/primitives.mjs.map +1 -1
  388. package/runtime/source-mapping.mjs +17 -23
  389. package/runtime/source-mapping.mjs.map +1 -1
  390. package/runtime/testing/map.eli +70 -41
  391. package/runtime/testing/map.mjs +57 -34
  392. package/runtime/testing/map.mjs.map +1 -1
  393. package/runtime/unicode-case.mjs +6 -6
  394. package/runtime/unicode-case.mjs.map +1 -1
  395. package/runtime/wire/http-rpc.mjs +12 -18
  396. package/runtime/wire/http-rpc.mjs.map +1 -1
  397. package/runtime/wire/markdown.mjs +42 -42
  398. package/runtime/wire/markdown.mjs.map +1 -1
  399. package/runtime/wire/schema.mjs +13 -13
  400. package/runtime/wire/schema.mjs.map +1 -1
  401. package/runtime/worker-value-codec.mjs +5 -7
  402. package/runtime/worker-value-codec.mjs.map +1 -1
  403. package/runtime/worker-value-stream.mjs +128 -135
  404. package/runtime/worker-value-stream.mjs.map +1 -1
  405. package/runtime/worker.mjs +75 -89
  406. package/runtime/worker.mjs.map +1 -1
  407. package/stdlib/README.md +25 -18
  408. package/stdlib/async.eli +1245 -0
  409. package/stdlib/bit.eli +89 -1
  410. package/stdlib/bit.mjs +89 -2
  411. package/stdlib/bit.mjs.map +1 -1
  412. package/stdlib/{core/collection.eli → collection.eli} +39 -4
  413. package/stdlib/core.eli +956 -0
  414. package/stdlib/data-text.eli +62 -1091
  415. package/stdlib/data.eli +517 -37
  416. package/stdlib/devtools.eli +399 -0
  417. package/stdlib/diff.eli +134 -0
  418. package/stdlib/{function.eli → fn.eli} +1 -1
  419. package/stdlib/identifier.eli +21 -136
  420. package/stdlib/interop/object.eli +39 -0
  421. package/stdlib/{core/lazy-sequence.eli → lazy-sequence.eli} +28 -2
  422. package/stdlib/math.eli +267 -0
  423. package/stdlib/{core/metadata.eli → meta.eli} +2 -2
  424. package/stdlib/{core/order.eli → order.eli} +6 -6
  425. package/stdlib/persistent-list.eli +60 -21
  426. package/stdlib/persistent-map.eli +335 -324
  427. package/stdlib/persistent-set.eli +8 -6
  428. package/stdlib/persistent-vector.eli +18 -18
  429. package/stdlib/portable/data-text.eli +1092 -0
  430. package/stdlib/portable/data.eli +42 -0
  431. package/stdlib/portable/identifier.eli +147 -0
  432. package/stdlib/{metadata.eli → portable/metadata.eli} +5 -5
  433. package/stdlib/{object.eli → portable/object.eli} +1 -1
  434. package/stdlib/{sequence.eli → portable/sequence.eli} +1 -1
  435. package/stdlib/{text.eli → portable/text.eli} +1 -1
  436. package/stdlib/pprint.eli +588 -0
  437. package/stdlib/protocol.eli +63 -0
  438. package/stdlib/{core/record.eli → record.eli} +2 -2
  439. package/stdlib/regex.eli +70 -0
  440. package/stdlib/result.eli +53 -44
  441. package/stdlib/schema.eli +1886 -0
  442. package/stdlib/{core/seq.eli → seq.eli} +97 -90
  443. package/{dist/literal-sources/stdlib/core → stdlib}/set.eli +8 -8
  444. package/stdlib/{core/sorted.eli → sorted.eli} +2 -2
  445. package/stdlib/{state/atom.eli → state.eli} +137 -7
  446. package/stdlib/string.eli +362 -0
  447. package/stdlib/tap.eli +135 -0
  448. package/stdlib/test.eli +566 -0
  449. package/stdlib/time.eli +419 -0
  450. package/stdlib/{core/transducer.eli → transducer.eli} +4 -2
  451. package/stdlib/{core/transient.eli → transient.eli} +11 -5
  452. package/stdlib/{core/type.eli → type.eli} +2 -2
  453. package/stdlib/uuid.eli +288 -0
  454. package/stdlib/{core/walk.eli → walk.eli} +6 -6
  455. package/stdlib/{gepo.eli → wire/gepo.eli} +2 -2
  456. package/stdlib/{mdp.eli → wire/mdp.eli} +2 -2
  457. package/stdlib/{mds.eli → wire/mds.eli} +2 -2
  458. package/stdlib/{core/zipper.eli → zipper.eli} +179 -138
  459. package/tests/helpers/wasm-managed-math-node.mjs +495 -582
  460. package/tools/acceptance/check-ground.mjs +106 -132
  461. package/tools/acceptance/check.mjs +16 -16
  462. package/tools/acceptance/retained-performance-snapshot.mjs +265 -149
  463. package/tools/acceptance/retained-soak.mjs +5 -7
  464. package/tools/acceptance/retained-transient.mjs +5 -7
  465. package/tools/backends/build.mjs +373 -95
  466. package/tools/backends/compiler-bootstrap.mjs +271 -317
  467. package/tools/backends/compiler-browser.mjs +7 -9
  468. package/tools/backends/compiler-build.mjs +77 -97
  469. package/tools/backends/compiler-cli-ground.mjs +47 -47
  470. package/tools/backends/compiler-data-transport.mjs +27 -31
  471. package/tools/backends/compiler-host-iteration.mjs +13 -21
  472. package/tools/backends/compiler-host-record.mjs +28 -34
  473. package/tools/backends/compiler-metadata.mjs +145 -53
  474. package/tools/backends/compiler-package-ground.mjs +39 -47
  475. package/tools/backends/compiler-package-loader.mjs +164 -206
  476. package/tools/backends/compiler-session.mjs +432 -324
  477. package/tools/backends/compiler-worker.mjs +79 -89
  478. package/tools/backends/dist/bootstrap-js-stages.mjs +17 -19
  479. package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -1
  480. package/tools/backends/dist/managed-ir-inventory.mjs +1 -1
  481. package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -1
  482. package/tools/backends/dist/release-cli.mjs +151 -22
  483. package/tools/backends/dist/release-cli.mjs.map +1 -1
  484. package/tools/backends/dist/run-artifact.mjs +54 -76
  485. package/tools/backends/dist/run-artifact.mjs.map +1 -1
  486. package/tools/backends/managed-foreign-binding.mjs +370 -114
  487. package/tools/backends/managed-host-ground.mjs +14 -17
  488. package/tools/backends/managed-host-lifecycle.mjs +42 -53
  489. package/tools/backends/managed-host-object-realm.mjs +121 -111
  490. package/tools/backends/managed-host-proxy.mjs +5 -7
  491. package/tools/backends/managed-host-runtime.mjs +6295 -4350
  492. package/tools/backends/managed-host.mjs +234 -188
  493. package/tools/backends/managed-layout.mjs +53 -56
  494. package/tools/backends/managed-module-graph-ground.mjs +488 -568
  495. package/tools/backends/managed-module-graph.mjs +62 -76
  496. package/tools/backends/managed-runtime-host-ground.mjs +352 -400
  497. package/tools/backends/managed-runtime.mjs +227 -266
  498. package/tools/backends/managed-source-view-ground.mjs +165 -161
  499. package/tools/backends/managed-source-view.mjs +415 -154
  500. package/tools/backends/native-managed-runtime.mjs +96 -138
  501. package/tools/backends/native-memory.mjs +1122 -742
  502. package/tools/backends/native-node-ffi.mjs +2439 -0
  503. package/tools/backends/native-node-memory.mjs +793 -383
  504. package/tools/backends/native-node-runner.mjs +1458 -579
  505. package/tools/backends/native-node-watchdog.mjs +12 -14
  506. package/tools/backends/native-node-worker.mjs +46 -50
  507. package/tools/backends/stage3-targets.mjs +2 -2
  508. package/tools/bootstrap-runtime.el +4 -4
  509. package/tools/collections/transient-builder-benchmark.mjs +17 -17
  510. package/tools/project/check-cli.eli +27 -3
  511. package/tools/project/project-cli.eli +1 -1
  512. package/tools/testing/maintained-suite-source.mjs +5 -7
  513. package/tools/testing/maintained-suite-source.mjs.map +1 -1
  514. package/dist/literal-sources/stdlib/core/data.eli +0 -306
  515. package/dist/literal-sources/stdlib/managed-transient-state.eli +0 -353
  516. package/stdlib/core/data-text.eli +0 -16
  517. package/stdlib/core/data.eli +0 -306
  518. package/stdlib/core/identifier.eli +0 -32
  519. package/stdlib/core/regex.eli +0 -17
  520. package/stdlib/deferred.eli +0 -70
  521. package/stdlib/managed-runtime-lazy-sequence.eli +0 -157
  522. package/stdlib/managed-transient-state.eli +0 -353
  523. /package/{stdlib → runtime/managed}/managed-protocol-error.eli +0 -0
  524. /package/{stdlib → runtime/managed}/managed-runtime-literals.eli +0 -0
  525. /package/{stdlib → runtime/managed}/managed-runtime-truth.eli +0 -0
  526. /package/{stdlib → runtime/managed}/managed-testing-value.eli +0 -0
@@ -1,19 +1,20 @@
1
1
  // Generated by Eliscript. Do not edit.
2
2
  import { tdz as __eliscript_tdz_error, immutable as __eliscript_const_error } from "eliscript/runtime/errors.mjs";
3
3
  var __eliscript_tdz_ready_0;
4
+ var __eliscript_tdz_ready_1;
4
5
  import "eliscript/runtime/unicode-case.mjs";
5
6
  import "eliscript/runtime/math.mjs";
6
- import { __eliscript_at, __eliscript_at_direct, __eliscript_to_number, __eliscript_numeric_decrement, __eliscript_numeric_relation, __eliscript_numeric_sub, __eliscript_numeric_mul, __eliscript_numeric_div, __eliscript_numeric_rem, __eliscript_numeric_and, __eliscript_numeric_or, __eliscript_numeric_xor, __eliscript_numeric_shl, __eliscript_numeric_shr, __eliscript_numeric_ushr, __eliscript_numeric_neg, __eliscript_numeric_int32, __eliscript_numeric_uint32, __eliscript_numeric_not } from "eliscript/runtime/prelude.mjs";
7
+ import { __eliscript_at, __eliscript_at_direct, __eliscript_to_number, __eliscript_numeric_decrement, __eliscript_numeric_relation, __eliscript_numeric_sub, __eliscript_numeric_mul, __eliscript_numeric_div, __eliscript_numeric_rem, __eliscript_numeric_and, __eliscript_numeric_or, __eliscript_numeric_xor, __eliscript_numeric_shl, __eliscript_numeric_shr, __eliscript_numeric_ushr, __eliscript_numeric_neg, __eliscript_numeric_int32, __eliscript_numeric_uint32, __eliscript_numeric_not, __eliscript_numeric_imul } from "eliscript/runtime/prelude.mjs";
7
8
  import { stringToBigint as __eliscript_string_to_bigint, float64Words as __eliscript_number_float64_words, buildArray as __eliscript_array_build, arrayCopyAssoc as __eliscript_array_copy_assoc, unsupportedArity as __eliscript_arity_error } from "eliscript/runtime/primitives.mjs";
8
9
  import { valueType as __eliscript_value_type } from "eliscript/runtime/primitives.mjs";
9
10
  const __eliscript_truthy = (value) => value !== false && value != null;
10
11
 
11
12
  import {optimize_program} from "./optimize.mjs";
12
- import {lower_numeric_program, optimize_numeric_program, numeric_pure, tree_size, backend_fail, find_function} from "./numeric.mjs";
13
+ import {lower_numeric_program, optimize_numeric_program, numeric_pure, tree_size, backend_fail, find_function, runtime_body_cache_get, mark_trusted_runtime_program, trusted_runtime_program_p} from "./numeric.mjs";
13
14
  import {lower_memory_program} from "./memory.mjs";
14
15
  import {prepare_host_capabilities, host_capability_index} from "./capabilities.mjs";
15
16
  import {lower_managed_program, lower_managed_project} from "./managed.mjs";
16
- import {binary_output, binary_byte, binary_push, binary_child, binary_length, binary_resume, binary_append, binary_append_owned, binary_finish} from "./binary.mjs";
17
+ import {binary_output, binary_byte, binary_push, binary_child, binary_length, binary_resume, binary_append, binary_append_owned, binary_to_u8, binary_append_u8, binary_finish} from "./binary.mjs";
17
18
  function append_bytes(output, bytes) {
18
19
  return binary_append(output, bytes);
19
20
  }
@@ -206,10 +207,11 @@ function emit_trapping_bytes(output, expression, bytes, terminal = null) {
206
207
  if (__eliscript_truthy(state)) {
207
208
  {
208
209
  let sites = (state)["trapSites"];
210
+ let site_id = (((state)["trapSiteBase"] ?? 0) + (((sites) ?? []).length + 1));
209
211
  binary_push(output, 65);
210
- positive_signed_leb(output, (((sites) ?? []).length + 1));
212
+ positive_signed_leb(output, site_id);
211
213
  binary_push(output, 36, 0);
212
- ((range = ({"kind": "trap-site", "function": (state)["function"], "functionIndex": (state)["functionIndex"], "depth": (state)["depth"], "start": ((output) ?? []).length, "end": 0, "span": ((expression)["span"] ?? null), "site": (((sites) ?? []).length + 1)})));
214
+ ((range = ({"kind": "trap-site", "function": (state)["function"], "functionIndex": (state)["functionIndex"], "depth": (state)["depth"], "start": ((output) ?? []).length, "end": 0, "span": ((expression)["span"] ?? null), "site": site_id})));
213
215
  (sites)["push"](range);
214
216
  ((state)["ranges"])["push"](range);
215
217
  }
@@ -904,6 +906,7 @@ function copy_typed_wasm_program(program) {
904
906
  let functions = (program)["functions"];
905
907
  let copies = [];
906
908
  let memory = ((program)["abi"] === "memory-u32");
909
+ let workspace = null;
907
910
  let copy = Object.assign(({}), program);
908
911
  let index = 0;
909
912
  if ((!__eliscript_truthy(Array.isArray(functions)))) {
@@ -916,9 +919,22 @@ function copy_typed_wasm_program(program) {
916
919
  backend_fail(program, "typed WASM function requires a locals array");
917
920
  }
918
921
  {
922
+ let fn_body = (function$)["body"];
923
+ let cached = (__eliscript_truthy(memory) ? runtime_body_cache_get(fn_body) : null);
919
924
  let function_copy = Object.assign(({}), function$);
920
925
  ((function_copy)["locals"] = ((function$)["locals"])["slice"]());
921
- ((function_copy)["body"] = copy_wasm_expression((function$)["body"], function$, memory));
926
+ if ((__eliscript_truthy(cached) && __eliscript_truthy((cached)["frozen"]))) {
927
+ if ((!__eliscript_truthy((cached)["wasmValidated"]))) {
928
+ if ((!__eliscript_truthy(workspace))) {
929
+ ((workspace = make_wasm_validation_workspace()));
930
+ }
931
+ validate_fresh_wasm_expression(fn_body, function$, memory, workspace);
932
+ ((cached)["wasmValidated"] = true);
933
+ }
934
+ ((function_copy)["body"] = fn_body);
935
+ } else {
936
+ ((function_copy)["body"] = copy_wasm_expression(fn_body, function$, memory));
937
+ }
922
938
  (copies)["push"](function_copy);
923
939
  }
924
940
  }
@@ -1163,6 +1179,13 @@ function emit_memory_data_copy(output, expression) {
1163
1179
  (texts)["push"](text);
1164
1180
  (indices)["set"](text, index);
1165
1181
  }
1182
+ {
1183
+ let refs = ((output)["wasmDataRefs"] ?? null);
1184
+ if (__eliscript_truthy(refs)) {
1185
+ (refs)["push"](text);
1186
+ ((output)["wasmDataRefIndices"])["push"](index);
1187
+ }
1188
+ }
1166
1189
  emit_expression(output, ((((children) ?? [])[0]) ?? null));
1167
1190
  binary_push(output, 65, 0, 65);
1168
1191
  signed_word_leb(output, __eliscript_numeric_mul(2, ((text) ?? []).length));
@@ -1691,11 +1714,268 @@ function prepare_indirect_calls(expression, signature_map, allowed_domain_sigs,
1691
1714
  }
1692
1715
  return expression;
1693
1716
  }
1717
+ function replay_wasm_debug_body(debug, function$, host_count, index, count, body_start, body_end, ranges, local_entries_start, instructions_start, size_start) {
1718
+ {
1719
+ let source = ((function$)["source"] ?? null);
1720
+ let dst_ranges = (debug)["ranges"];
1721
+ let dst_sites = (debug)["trapSites"];
1722
+ let ri = 0;
1723
+ let rlen = ((ranges) ?? []).length;
1724
+ while (__eliscript_numeric_relation("<", ri, rlen)) {
1725
+ {
1726
+ let r = ((((ranges) ?? [])[ri]) ?? null);
1727
+ let cloned = Object.assign(({}), r, ({"start": (body_start + (r)["start"]), "end": (body_start + (r)["end"])}));
1728
+ (dst_ranges)["push"](cloned);
1729
+ if (((cloned)["kind"] === "trap-site")) {
1730
+ (dst_sites)["push"](cloned);
1731
+ }
1732
+ }
1733
+ ((ri = (ri + 1)));
1734
+ }
1735
+ return ((debug)["functions"])["push"](({"name": (function$)["name"], "index": (host_count + index), "span": ((function$)["span"] ?? (__eliscript_truthy(source) ? ((source)["span"] ?? null) : null)), "sizeField": ({"start": size_start, "end": body_start}), "body": ({"start": body_start, "end": body_end}), "locals": ({"start": body_start, "entriesStart": (body_start + local_entries_start), "end": (body_start + instructions_start), "count": count}), "instructions": ({"start": (body_start + instructions_start), "end": body_end})}));
1736
+ }
1737
+ }
1738
+ const wasm_hot_inline_names = new (globalThis.Set)(["last-error", "fail", "begin-operation", "heap-check", "heap-block", "heap-ro-block", "heap-value-valid", "heap-reference-check", "val64-dynamic-p", "val64-inline-number-p", "val64-ro-p", "val64-readable-block-p", "heap-slot-index", "heap-generation", "heap-handle", "value-number-bits", "heap-number-word", "heap-number-from-word", "rt-root-scope-get-abs", "rt-root-scope-set-abs"]);
1739
+ __eliscript_tdz_ready_1 = true;
1740
+ function wasm_inline_candidate(function$, self_index) {
1741
+ if (__eliscript_truthy(((__eliscript_tdz_ready_1 === true ? wasm_hot_inline_names : __eliscript_tdz_error("wasm_hot_inline_names")))["has"](((function$)["name"] ?? null)))) {
1742
+ {
1743
+ let body = (function$)["body"];
1744
+ let locals = (function$)["locals"];
1745
+ let pending = [body];
1746
+ let count = 0;
1747
+ let valid = __eliscript_numeric_relation("<=", ((locals) ?? []).length, 16);
1748
+ while ((__eliscript_truthy(valid) && __eliscript_numeric_relation(">", ((pending) ?? []).length, 0))) {
1749
+ {
1750
+ let node = (pending)["pop"]();
1751
+ let kind = (node)["kind"];
1752
+ let children = (node)["children"];
1753
+ let i = 0;
1754
+ ((count = (count + 1)));
1755
+ if (((kind === "call") && ((node)["value"] === self_index))) {
1756
+ ((valid = null));
1757
+ }
1758
+ if ((__eliscript_numeric_relation(">", count, 180) || !(__eliscript_truthy(valid)) || (kind === "call-indirect") || (kind === "host-call") || (kind === "while") || (kind === "remainder-while") || (kind === "guarded-while") || (kind === "guarded-counter-while") || (kind === "data-text") || (kind === "memory-data-copy"))) {
1759
+ ((valid = null));
1760
+ } else {
1761
+ if (__eliscript_truthy(Array.isArray(children))) {
1762
+ while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
1763
+ (pending)["push"](((((children) ?? [])[i]) ?? null));
1764
+ ((i = (i + 1)));
1765
+ }
1766
+ }
1767
+ }
1768
+ }
1769
+ }
1770
+ if (__eliscript_truthy(valid)) {
1771
+ return ({"function": function$, "body": body, "locals": (locals)["slice"](), "arity": (function$)["arity"], "size": count});
1772
+ } else {
1773
+ return null;
1774
+ }
1775
+ }
1776
+ } else {
1777
+ return null;
1778
+ }
1779
+ }
1780
+ function wasm_has_inline_site(node, candidates, self_index) {
1781
+ {
1782
+ let pending = [node];
1783
+ let found = null;
1784
+ while ((!(__eliscript_truthy(found)) && __eliscript_numeric_relation(">", ((pending) ?? []).length, 0))) {
1785
+ {
1786
+ let item = (pending)["pop"]();
1787
+ let kind = (item)["kind"];
1788
+ let children = (item)["children"];
1789
+ let i = 0;
1790
+ if (((kind === "call") && ((item)["value"] !== self_index) && !((((((candidates) ?? [])[(item)["value"]]) ?? null) === null)))) {
1791
+ ((found = true));
1792
+ } else {
1793
+ if (__eliscript_truthy(Array.isArray(children))) {
1794
+ while (__eliscript_numeric_relation("<", i, ((children) ?? []).length)) {
1795
+ (pending)["push"](((((children) ?? [])[i]) ?? null));
1796
+ ((i = (i + 1)));
1797
+ }
1798
+ }
1799
+ }
1800
+ }
1801
+ }
1802
+ return found;
1803
+ }
1804
+ }
1805
+ function wasm_shift_clone(node, base) {
1806
+ {
1807
+ let kind = (node)["kind"];
1808
+ let children = (node)["children"];
1809
+ let has_children = Array.isArray(children);
1810
+ let clen = (__eliscript_truthy(has_children) ? ((children) ?? []).length : 0);
1811
+ let is_local = ((kind === "local") || (kind === "set") || (kind === "initialize"));
1812
+ if (((clen === 0) && !(__eliscript_truthy(is_local)))) {
1813
+ return node;
1814
+ } else {
1815
+ {
1816
+ let new_children = null;
1817
+ let changed = false;
1818
+ let i = 0;
1819
+ while (__eliscript_numeric_relation("<", i, clen)) {
1820
+ {
1821
+ let orig = ((((children) ?? [])[i]) ?? null);
1822
+ let cloned = wasm_shift_clone(orig, base);
1823
+ if (!((cloned === orig))) {
1824
+ if ((!__eliscript_truthy(new_children))) {
1825
+ ((new_children = (children)["slice"]()));
1826
+ }
1827
+ ((new_children)[i] = cloned);
1828
+ ((changed = true));
1829
+ }
1830
+ }
1831
+ ((i = (i + 1)));
1832
+ }
1833
+ if ((!(__eliscript_truthy(changed)) && !(__eliscript_truthy(is_local)))) {
1834
+ return node;
1835
+ } else {
1836
+ {
1837
+ let copy = Object.assign(({}), node);
1838
+ ((copy)["children"] = ((__eliscript_value_3) => (__eliscript_truthy(__eliscript_value_3) ? __eliscript_value_3 : (__eliscript_truthy(has_children) ? children : [])))(new_children));
1839
+ if (__eliscript_truthy(is_local)) {
1840
+ ((copy)["value"] = ((node)["value"] + base));
1841
+ }
1842
+ return copy;
1843
+ }
1844
+ }
1845
+ }
1846
+ }
1847
+ }
1848
+ }
1849
+ function wasm_rewrite_inline(node, candidates, self_index, locals, budget) {
1850
+ {
1851
+ let kind = (node)["kind"];
1852
+ let children = (node)["children"];
1853
+ let has_children = Array.isArray(children);
1854
+ let clen = (__eliscript_truthy(has_children) ? ((children) ?? []).length : 0);
1855
+ let new_children = null;
1856
+ let changed = false;
1857
+ let i = 0;
1858
+ while (__eliscript_numeric_relation("<", i, clen)) {
1859
+ {
1860
+ let orig = ((((children) ?? [])[i]) ?? null);
1861
+ let rewritten = wasm_rewrite_inline(orig, candidates, self_index, locals, budget);
1862
+ if (!((rewritten === orig))) {
1863
+ if ((!__eliscript_truthy(new_children))) {
1864
+ ((new_children = (children)["slice"]()));
1865
+ }
1866
+ ((new_children)[i] = rewritten);
1867
+ ((changed = true));
1868
+ }
1869
+ }
1870
+ ((i = (i + 1)));
1871
+ }
1872
+ {
1873
+ let target_index = ((kind === "call") ? (node)["value"] : -1);
1874
+ let cand = (((kind === "call") && (target_index !== self_index) && __eliscript_numeric_relation(">=", target_index, 0) && __eliscript_numeric_relation("<", target_index, ((candidates) ?? []).length)) ? ((((candidates) ?? [])[target_index]) ?? null) : null);
1875
+ let callee_locals = (__eliscript_truthy(cand) ? (cand)["locals"] : null);
1876
+ let callee_body = (__eliscript_truthy(cand) ? (cand)["body"] : null);
1877
+ if ((__eliscript_truthy(cand) && __eliscript_truthy(callee_body) && __eliscript_numeric_relation("<=", (((locals) ?? []).length + ((callee_locals) ?? []).length), (budget)["maxLocals"]) && __eliscript_numeric_relation("<=", ((budget)["added"] + (cand)["size"]), (budget)["maxAdded"]))) {
1878
+ {
1879
+ let base = ((locals) ?? []).length;
1880
+ let callee_arity = (cand)["arity"];
1881
+ let args = ((__eliscript_value_4) => (__eliscript_truthy(__eliscript_value_4) ? __eliscript_value_4 : children))(new_children);
1882
+ let seq_children = [];
1883
+ let k = 0;
1884
+ while (__eliscript_numeric_relation("<", k, ((callee_locals) ?? []).length)) {
1885
+ {
1886
+ let ltype = (((((callee_locals) ?? [])[k]) ?? null))["type"];
1887
+ (locals)["push"](({"name": (String("inline-") + String((base + k))), "type": ltype, "index": (base + k)}));
1888
+ if (__eliscript_numeric_relation("<", k, callee_arity)) {
1889
+ (seq_children)["push"](({"kind": "set", "type": ltype, "value": (base + k), "children": [((((args) ?? [])[k]) ?? null)]}));
1890
+ } else {
1891
+ {
1892
+ let zero_node = ({"kind": "literal", "type": ltype, "value": ((ltype === "f64") ? 0 : (((ltype === "v64") || (ltype === "bits64")) ? ({"low": 0, "high": 0}) : 0)), "children": []});
1893
+ (seq_children)["push"](({"kind": "set", "type": ltype, "value": (base + k), "children": [zero_node]}));
1894
+ }
1895
+ }
1896
+ }
1897
+ ((k = (k + 1)));
1898
+ }
1899
+ (seq_children)["push"](wasm_shift_clone(callee_body, base));
1900
+ ((budget)["added"] = ((budget)["added"] + (cand)["size"]));
1901
+ return ({"kind": "sequence", "type": (node)["type"], "children": seq_children});
1902
+ }
1903
+ } else {
1904
+ if (__eliscript_truthy(changed)) {
1905
+ {
1906
+ let copy = Object.assign(({}), node);
1907
+ ((copy)["children"] = new_children);
1908
+ return copy;
1909
+ }
1910
+ } else {
1911
+ return node;
1912
+ }
1913
+ }
1914
+ }
1915
+ }
1916
+ }
1917
+ function wasm_build_inline_candidates(functions) {
1918
+ {
1919
+ let count = ((functions) ?? []).length;
1920
+ let candidates = new (globalThis.Array)(count);
1921
+ let any_cand = null;
1922
+ let k = 0;
1923
+ while (__eliscript_numeric_relation("<", k, count)) {
1924
+ {
1925
+ let cand = wasm_inline_candidate(((((functions) ?? [])[k]) ?? null), k);
1926
+ ((candidates)[k] = cand);
1927
+ if (__eliscript_truthy(cand)) {
1928
+ ((any_cand = true));
1929
+ }
1930
+ }
1931
+ ((k = (k + 1)));
1932
+ }
1933
+ if (__eliscript_truthy(any_cand)) {
1934
+ return candidates;
1935
+ } else {
1936
+ return null;
1937
+ }
1938
+ }
1939
+ }
1940
+ function wasm_runtime_prefix_ok(functions, inline_candidates) {
1941
+ {
1942
+ let count = ((functions) ?? []).length;
1943
+ let first_cached = (__eliscript_numeric_relation(">", count, 0) ? runtime_body_cache_get(((((((functions) ?? [])[0]) ?? null))["body"] ?? null)) : null);
1944
+ let rt_id = (__eliscript_truthy(first_cached) ? ((first_cached)["runtimeId"] ?? 0) : 0);
1945
+ let rt_count = (__eliscript_truthy(first_cached) ? ((first_cached)["runtimeFnCount"] ?? 0) : 0);
1946
+ let ok = (__eliscript_numeric_relation(">", rt_id, 0) && __eliscript_numeric_relation(">", rt_count, 0) && __eliscript_numeric_relation("<=", rt_count, count));
1947
+ let ri = 0;
1948
+ while ((__eliscript_truthy(ok) && __eliscript_numeric_relation("<", ri, rt_count))) {
1949
+ {
1950
+ let rfn = ((((functions) ?? [])[ri]) ?? null);
1951
+ let rc = runtime_body_cache_get(((rfn)["body"] ?? null));
1952
+ let cand = ((((inline_candidates) ?? [])[ri]) ?? null);
1953
+ if ((!__eliscript_truthy((__eliscript_truthy(rc) ? (((rc)["runtimeId"] === rt_id) && ((rc)["runtimeFnCount"] === rt_count) && ((rc)["fnIndex"] === ri) && ((rc)["arity"] === (rfn)["arity"])) : (cand === null))))) {
1954
+ ((ok = false));
1955
+ }
1956
+ }
1957
+ ((ri = (ri + 1)));
1958
+ }
1959
+ if (__eliscript_truthy(ok)) {
1960
+ return rt_count;
1961
+ } else {
1962
+ return 0;
1963
+ }
1964
+ }
1965
+ }
1966
+ function wasm_append_memory_scratch(locals) {
1967
+ {
1968
+ let base = ((locals) ?? []).length;
1969
+ (locals)["push"](({"name": "memory-address", "index": base, "type": "u32"}), ({"name": "memory-word", "index": (base + 1), "type": "u32"}), ({"name": "memory-float", "index": (base + 2), "type": "f64"}), ({"name": "memory-wide", "index": (base + 3), "type": "v64"}));
1970
+ return ({"word": ({"addressLocal": base, "valueLocal": (base + 1)}), "floating": ({"addressLocal": base, "valueLocal": (base + 2)}), "wide": ({"addressLocal": base, "valueLocal": (base + 3)})});
1971
+ }
1972
+ }
1694
1973
  function emit_typed_scalar_wasm(program, options, debug = null, consume_owned_bodies = null) {
1695
1974
  {
1696
1975
  let memory = ((program)["abi"] === "memory-u32");
1976
+ let trusted = ((__eliscript_value_5) => (__eliscript_truthy(__eliscript_value_5) ? trusted_runtime_program_p(program) : __eliscript_value_5))(memory);
1697
1977
  let scalar_byte = (__eliscript_truthy(memory) ? 127 : 124);
1698
- let ro_data = ((__eliscript_value_3) => (__eliscript_truthy(__eliscript_value_3) ? __eliscript_value_3 : ((options)["roData"] ?? null)))(((program)["roData"] ?? null));
1978
+ let ro_data = ((__eliscript_value_6) => (__eliscript_truthy(__eliscript_value_6) ? __eliscript_value_6 : ((options)["roData"] ?? null)))(((program)["roData"] ?? null));
1699
1979
  let active_ro_segments = (__eliscript_truthy(memory) ? build_active_ro_segments(ro_data) : []);
1700
1980
  let required_pages = ((__eliscript_truthy(ro_data) && __eliscript_truthy(((ro_data)["header"] ?? null))) ? (globalThis.Math)["max"](1, (globalThis.Math)["ceil"](__eliscript_numeric_div((((ro_data)["header"])["imageDataEnd"] ?? 256), 65536))) : 1);
1701
1981
  let raw_initial = ((options)["initialPages"] ?? 1);
@@ -1716,6 +1996,15 @@ function emit_typed_scalar_wasm(program, options, debug = null, consume_owned_bo
1716
1996
  let exports = null;
1717
1997
  let bodies = null;
1718
1998
  let memory_scratch = [];
1999
+ let inline_candidates = ((__eliscript_truthy(memory) && !(__eliscript_truthy(debug))) ? wasm_build_inline_candidates(functions) : null);
2000
+ let rt_prefix_count = (__eliscript_truthy(inline_candidates) ? wasm_runtime_prefix_ok(functions, inline_candidates) : 0);
2001
+ let rt_inline_candidates = ((__eliscript_truthy(inline_candidates) && __eliscript_numeric_relation(">", rt_prefix_count, 0)) ? ((arr, k) => {
2002
+ while (__eliscript_numeric_relation("<", k, rt_prefix_count)) {
2003
+ ((arr)[k] = ((((inline_candidates) ?? [])[k]) ?? null));
2004
+ ((k = (k + 1)));
2005
+ }
2006
+ return arr;
2007
+ })(new (globalThis.Array)(rt_prefix_count), 0) : null);
1719
2008
  let data_texts = [];
1720
2009
  let data_indices = new (globalThis.Map)();
1721
2010
  let output = null;
@@ -1733,7 +2022,24 @@ function emit_typed_scalar_wasm(program, options, debug = null, consume_owned_bo
1733
2022
  {
1734
2023
  let position = 0;
1735
2024
  while (__eliscript_numeric_relation("<", position, ((functions) ?? []).length)) {
1736
- (memory_scratch)["push"](prepare_memory_scratch(((((functions) ?? [])[position]) ?? null)));
2025
+ {
2026
+ let fn = ((((functions) ?? [])[position]) ?? null);
2027
+ let cached = runtime_body_cache_get((fn)["body"]);
2028
+ if ((__eliscript_truthy(cached) && (__eliscript_truthy(trusted) || __eliscript_truthy((cached)["frozen"])))) {
2029
+ if (__eliscript_truthy((cached)["hasMemoryAccess"])) {
2030
+ {
2031
+ let locals = (fn)["locals"];
2032
+ let base = ((locals) ?? []).length;
2033
+ (locals)["push"](({"name": "memory-address", "index": base, "type": "u32"}), ({"name": "memory-word", "index": (base + 1), "type": "u32"}), ({"name": "memory-float", "index": (base + 2), "type": "f64"}), ({"name": "memory-wide", "index": (base + 3), "type": "v64"}));
2034
+ (memory_scratch)["push"](({"word": ({"addressLocal": base, "valueLocal": (base + 1)}), "floating": ({"addressLocal": base, "valueLocal": (base + 2)}), "wide": ({"addressLocal": base, "valueLocal": (base + 3)})}));
2035
+ }
2036
+ } else {
2037
+ (memory_scratch)["push"](undefined);
2038
+ }
2039
+ } else {
2040
+ (memory_scratch)["push"](prepare_memory_scratch(fn));
2041
+ }
2042
+ }
1737
2043
  ((position = (position + 1)));
1738
2044
  }
1739
2045
  }
@@ -1785,8 +2091,8 @@ function emit_typed_scalar_wasm(program, options, debug = null, consume_owned_bo
1785
2091
  while (__eliscript_numeric_relation("<", position, ((declared_sigs) ?? []).length)) {
1786
2092
  {
1787
2093
  let entry = ((((declared_sigs) ?? [])[position]) ?? null);
1788
- let param_types = ((__eliscript_value_4) => (__eliscript_truthy(__eliscript_value_4) ? ((__eliscript_value_5) => (__eliscript_truthy(__eliscript_value_5) ? ((entry)["parameterTypes"] ?? null) : __eliscript_value_5))((__eliscript_value_type(entry) === "object")) : __eliscript_value_4))(entry);
1789
- let ret_type = ((__eliscript_value_6) => (__eliscript_truthy(__eliscript_value_6) ? ((__eliscript_value_7) => (__eliscript_truthy(__eliscript_value_7) ? ((entry)["resultType"] ?? null) : __eliscript_value_7))((__eliscript_value_type(entry) === "object")) : __eliscript_value_6))(entry);
2094
+ let param_types = ((__eliscript_value_7) => (__eliscript_truthy(__eliscript_value_7) ? ((__eliscript_value_8) => (__eliscript_truthy(__eliscript_value_8) ? ((entry)["parameterTypes"] ?? null) : __eliscript_value_8))((__eliscript_value_type(entry) === "object")) : __eliscript_value_7))(entry);
2095
+ let ret_type = ((__eliscript_value_9) => (__eliscript_truthy(__eliscript_value_9) ? ((__eliscript_value_10) => (__eliscript_truthy(__eliscript_value_10) ? ((entry)["resultType"] ?? null) : __eliscript_value_10))((__eliscript_value_type(entry) === "object")) : __eliscript_value_9))(entry);
1790
2096
  let params = [];
1791
2097
  let i = 0;
1792
2098
  if ((!(__eliscript_truthy(entry) && (__eliscript_value_type(entry) === "object") && __eliscript_truthy(Array.isArray(param_types)) && __eliscript_numeric_relation("<=", ((param_types) ?? []).length, 65535) && __eliscript_truthy(ret_type)))) {
@@ -1803,7 +2109,7 @@ function emit_typed_scalar_wasm(program, options, debug = null, consume_owned_bo
1803
2109
  }
1804
2110
  }
1805
2111
  ((output = binary_output(options)));
1806
- ((types = binary_child(output)), (declarations = binary_child(output)), (imports = binary_child(output)), (exports = binary_child(output)), (bodies = binary_child(output)));
2112
+ ((types = binary_child(output)), (declarations = binary_child(output)), (imports = binary_child(output)), (exports = binary_child(output)), (bodies = binary_output(({"binaryEncoding": "u16le-chunks"}))));
1807
2113
  append_bytes(output, [0, 97, 115, 109, 1, 0, 0, 0]);
1808
2114
  if (__eliscript_numeric_relation(">", host_count, 0)) {
1809
2115
  unsigned_leb(imports, host_count);
@@ -1812,7 +2118,7 @@ function emit_typed_scalar_wasm(program, options, debug = null, consume_owned_bo
1812
2118
  while (__eliscript_numeric_relation("<", position, host_count)) {
1813
2119
  {
1814
2120
  let capability = ((((capabilities) ?? [])[position]) ?? null);
1815
- let cap_params = ((__eliscript_value_8) => (__eliscript_truthy(__eliscript_value_8) ? __eliscript_value_8 : ["u32", "v64"]))(((capability)["parameterTypes"] ?? null));
2121
+ let cap_params = ((__eliscript_value_11) => (__eliscript_truthy(__eliscript_value_11) ? __eliscript_value_11 : ["u32", "v64"]))(((capability)["parameterTypes"] ?? null));
1816
2122
  let cap_result = ((capability)["resultType"] ?? "v64");
1817
2123
  let param_bytes = [];
1818
2124
  let i = 0;
@@ -1834,7 +2140,13 @@ function emit_typed_scalar_wasm(program, options, debug = null, consume_owned_bo
1834
2140
  }
1835
2141
  ((index = 0));
1836
2142
  while (__eliscript_numeric_relation("<", index, ((functions) ?? []).length)) {
1837
- prepare_indirect_calls((((((functions) ?? [])[index]) ?? null))["body"], signature_map, allowed_domain_sigs, ((__eliscript_value_9) => (__eliscript_truthy(__eliscript_value_9) ? table : __eliscript_value_9))(memory));
2143
+ {
2144
+ let body = (((((functions) ?? [])[index]) ?? null))["body"];
2145
+ let cached = (__eliscript_truthy(memory) ? runtime_body_cache_get(body) : null);
2146
+ if ((!(__eliscript_truthy(cached) && (__eliscript_truthy(trusted) || __eliscript_truthy((cached)["frozen"])) && !(__eliscript_truthy((cached)["hasIndirect"]))))) {
2147
+ prepare_indirect_calls(body, signature_map, allowed_domain_sigs, ((__eliscript_value_12) => (__eliscript_truthy(__eliscript_value_12) ? table : __eliscript_value_12))(memory));
2148
+ }
2149
+ }
1838
2150
  ((index = (index + 1)));
1839
2151
  }
1840
2152
  unsigned_leb(types, ((signatures) ?? []).length);
@@ -1898,55 +2210,246 @@ function emit_typed_scalar_wasm(program, options, debug = null, consume_owned_bo
1898
2210
  while (__eliscript_numeric_relation("<", index, ((functions) ?? []).length)) {
1899
2211
  {
1900
2212
  let function$ = ((((functions) ?? [])[index]) ?? null);
1901
- let body = binary_child(output);
2213
+ let fn_body = (function$)["body"];
1902
2214
  let locals = (function$)["locals"];
1903
- let count = __eliscript_numeric_sub(((locals) ?? []).length, (function$)["arity"]);
1904
- let position = (function$)["arity"];
1905
- let range_start = (__eliscript_truthy(debug) ? (((debug)["ranges"]) ?? []).length : 0);
1906
- let local_entries_start = 0;
1907
- let instructions_start = 0;
1908
- ((body)["wasmFunctionBase"] = host_count);
1909
- ((body)["wasmHostCapabilities"] = capabilities);
1910
- ((body)["wasmMemory"] = memory);
1911
- ((body)["wasmDataTexts"] = data_texts);
1912
- if (__eliscript_truthy(memory)) {
1913
- ((body)["wasmMemoryScratch"] = ((((memory_scratch) ?? [])[index]) ?? null));
1914
- }
1915
- ((body)["wasmDataIndices"] = data_indices);
1916
- if (__eliscript_truthy(debug)) {
1917
- ((body)["wasmDebug"] = ({"ranges": (debug)["ranges"], "depth": 0, "trapSites": (debug)["trapSites"], "function": (function$)["name"], "functionIndex": (host_count + index)}));
1918
- }
1919
- unsigned_leb(body, count);
1920
- ((local_entries_start = ((body) ?? []).length));
1921
- while (__eliscript_numeric_relation("<", position, ((locals) ?? []).length)) {
1922
- binary_push(body, 1, result_byte((((((locals) ?? [])[position]) ?? null))["type"]));
1923
- ((position = (position + 1)));
1924
- }
1925
- ((instructions_start = ((body) ?? []).length));
1926
- emit_expression(body, (function$)["body"]);
1927
- binary_push(body, 11);
1928
- {
1929
- let size_start = ((bodies) ?? []).length;
1930
- unsigned_leb(bodies, ((body) ?? []).length);
1931
- if (__eliscript_truthy(debug)) {
2215
+ let cache_entry = (__eliscript_truthy(memory) ? runtime_body_cache_get(fn_body) : null);
2216
+ let can_cache_body = ((__eliscript_value_13) => (__eliscript_truthy(__eliscript_value_13) ? ((__eliscript_value_14) => (__eliscript_truthy(__eliscript_value_14) ? ((!__eliscript_truthy((cache_entry)["hasIndirect"])) && (!__eliscript_truthy((cache_entry)["hasHostCall"]))) : __eliscript_value_14))(((__eliscript_value_15) => (__eliscript_truthy(__eliscript_value_15) ? __eliscript_value_15 : (cache_entry)["frozen"]))(trusted)) : __eliscript_value_13))(cache_entry);
2217
+ if (__eliscript_truthy(can_cache_body)) {
2218
+ {
2219
+ let arity = (function$)["arity"];
2220
+ let nlocals = ((locals) ?? []).length;
2221
+ let loc_sig = 2166136261;
2222
+ let li = arity;
2223
+ while (__eliscript_numeric_relation("<", li, nlocals)) {
2224
+ ((loc_sig = __eliscript_numeric_ushr(__eliscript_numeric_imul(__eliscript_numeric_xor(loc_sig, result_byte((((((locals) ?? [])[li]) ?? null))["type"])), 16777619), 0)));
2225
+ ((li = (li + 1)));
2226
+ }
1932
2227
  {
1933
- let body_start = ((bodies) ?? []).length;
1934
- let body_end = (body_start + ((body) ?? []).length);
1935
- let source = ((function$)["source"] ?? null);
1936
- let ranges = (debug)["ranges"];
1937
- let i = range_start;
1938
- while (__eliscript_numeric_relation("<", i, ((ranges) ?? []).length)) {
2228
+ let inline_rt = ((__eliscript_value_16) => (__eliscript_truthy(__eliscript_value_16) ? ((__eliscript_value_17) => (__eliscript_truthy(__eliscript_value_17) ? __eliscript_numeric_relation("<", index, rt_prefix_count) : __eliscript_value_17))(rt_inline_candidates) : __eliscript_value_16))((!__eliscript_truthy(debug)));
2229
+ let trap_site_base = (__eliscript_truthy(debug) ? (((debug)["trapSites"]) ?? []).length : 0);
2230
+ let cache_key = (__eliscript_truthy(debug) ? (String(host_count) + String(":") + String(index) + String(":") + String(arity) + String(":") + String(nlocals) + String(":") + String(loc_sig) + String(":") + String(trap_site_base) + String(":") + String((function$)["name"])) : (String(host_count) + String(":") + String(arity) + String(":") + String(nlocals) + String(":") + String(loc_sig) + String((__eliscript_truthy(inline_rt) ? ":I" : ""))));
2231
+ let wasm_bodies = (__eliscript_truthy(debug) ? ((m) => {
2232
+ if ((!__eliscript_truthy(m))) {
2233
+ ((m = new (globalThis.Map)()));
2234
+ ((cache_entry)["wasmDebugBodies"] = m);
2235
+ }
2236
+ return m;
2237
+ })(((cache_entry)["wasmDebugBodies"] ?? null)) : (cache_entry)["wasmBodies"]);
2238
+ let has_data_text = (cache_entry)["hasDataText"];
2239
+ let cached_entry = (wasm_bodies)["get"](cache_key);
2240
+ let hit_entry = null;
2241
+ let hit_bytes = null;
2242
+ if (__eliscript_truthy(cached_entry)) {
2243
+ if (!(__eliscript_truthy(has_data_text))) {
2244
+ ((hit_entry = cached_entry));
2245
+ ((hit_bytes = (__eliscript_truthy(debug) ? (cached_entry)["bytes"] : cached_entry)));
2246
+ } else {
2247
+ {
2248
+ let refs = (cached_entry)["refs"];
2249
+ let ref_indices = (cached_entry)["refIndices"];
2250
+ let rcount = ((refs) ?? []).length;
2251
+ let next_idx = ((data_texts) ?? []).length;
2252
+ let pending = new (globalThis.Map)();
2253
+ let ok = true;
2254
+ let ri = 0;
2255
+ while ((__eliscript_truthy(ok) && __eliscript_numeric_relation("<", ri, rcount))) {
2256
+ {
2257
+ let txt = ((((refs) ?? [])[ri]) ?? null);
2258
+ let existing = (data_indices)["get"](txt);
2259
+ let actual = (!((existing === undefined)) ? existing : ((pend) => {
2260
+ if (!((pend === undefined))) {
2261
+ return pend;
2262
+ } else {
2263
+ {
2264
+ let assigned = next_idx;
2265
+ ((next_idx = (next_idx + 1)));
2266
+ (pending)["set"](txt, assigned);
2267
+ return assigned;
2268
+ }
2269
+ }
2270
+ })((pending)["get"](txt)));
2271
+ if ((!(actual === ((((ref_indices) ?? [])[ri]) ?? null)))) {
2272
+ ((ok = false));
2273
+ }
2274
+ }
2275
+ ((ri = (ri + 1)));
2276
+ }
2277
+ if (__eliscript_truthy(ok)) {
2278
+ (pending)["forEach"](((idx, txt) => {
2279
+ (data_indices)["set"](txt, idx);
2280
+ return (data_texts)["push"](txt);
2281
+ }));
2282
+ ((hit_entry = cached_entry));
2283
+ ((hit_bytes = (cached_entry)["bytes"]));
2284
+ }
2285
+ }
2286
+ }
2287
+ }
2288
+ if (__eliscript_truthy(hit_bytes)) {
1939
2289
  {
1940
- let range = ((((ranges) ?? [])[i]) ?? null);
1941
- ((range)["start"] = (body_start + (range)["start"]));
1942
- ((range)["end"] = (body_start + (range)["end"]));
2290
+ let size_start = ((bodies) ?? []).length;
2291
+ unsigned_leb(bodies, ((hit_bytes) ?? []).length);
2292
+ if (__eliscript_truthy(debug)) {
2293
+ {
2294
+ let body_start = ((bodies) ?? []).length;
2295
+ let body_end = (body_start + ((hit_bytes) ?? []).length);
2296
+ replay_wasm_debug_body(debug, function$, host_count, index, __eliscript_numeric_sub(nlocals, arity), body_start, body_end, (hit_entry)["ranges"], (hit_entry)["localEntriesStart"], (hit_entry)["instructionsStart"], size_start);
2297
+ }
2298
+ }
2299
+ binary_append_u8(bodies, hit_bytes);
2300
+ }
2301
+ } else {
2302
+ {
2303
+ let emit_body = fn_body;
2304
+ let emit_locals = locals;
2305
+ let emit_scratch = (__eliscript_truthy(memory) ? ((((memory_scratch) ?? [])[index]) ?? null) : null);
2306
+ if ((__eliscript_truthy(inline_rt) && __eliscript_truthy(wasm_has_inline_site(fn_body, rt_inline_candidates, index)))) {
2307
+ {
2308
+ let tmp_locals = (locals)["slice"]();
2309
+ let budget = ({"added": 0, "maxAdded": 140, "maxLocals": 80});
2310
+ let new_body = wasm_rewrite_inline(fn_body, rt_inline_candidates, index, tmp_locals, budget);
2311
+ if (__eliscript_numeric_relation(">", (budget)["added"], 0)) {
2312
+ ((emit_locals = tmp_locals), (emit_body = new_body));
2313
+ if ((__eliscript_truthy(memory) && (emit_scratch === null) && __eliscript_truthy(has_memory_access_p(emit_body)))) {
2314
+ ((emit_scratch = wasm_append_memory_scratch(emit_locals)));
2315
+ }
2316
+ }
2317
+ }
2318
+ }
2319
+ {
2320
+ let emit_nlocals = ((emit_locals) ?? []).length;
2321
+ let body = binary_child(bodies);
2322
+ let count = __eliscript_numeric_sub(emit_nlocals, arity);
2323
+ let position = arity;
2324
+ let local_ranges = (__eliscript_truthy(debug) ? [] : null);
2325
+ let local_sites = (__eliscript_truthy(debug) ? [] : null);
2326
+ let local_entries_start = 0;
2327
+ let instructions_start = 0;
2328
+ let refs = ((__eliscript_truthy(has_data_text) && !(__eliscript_truthy(cached_entry))) ? [] : null);
2329
+ let ref_indices = ((__eliscript_truthy(has_data_text) && !(__eliscript_truthy(cached_entry))) ? [] : null);
2330
+ ((body)["wasmFunctionBase"] = host_count);
2331
+ ((body)["wasmHostCapabilities"] = capabilities);
2332
+ ((body)["wasmMemory"] = memory);
2333
+ ((body)["wasmDataTexts"] = data_texts);
2334
+ if (__eliscript_truthy(emit_scratch)) {
2335
+ ((body)["wasmMemoryScratch"] = emit_scratch);
2336
+ }
2337
+ ((body)["wasmDataIndices"] = data_indices);
2338
+ if (__eliscript_truthy(debug)) {
2339
+ ((body)["wasmDebug"] = ({"ranges": local_ranges, "depth": 0, "trapSites": local_sites, "trapSiteBase": trap_site_base, "function": (function$)["name"], "functionIndex": (host_count + index)}));
2340
+ }
2341
+ if (__eliscript_truthy(refs)) {
2342
+ ((body)["wasmDataRefs"] = refs);
2343
+ ((body)["wasmDataRefIndices"] = ref_indices);
2344
+ }
2345
+ unsigned_leb(body, count);
2346
+ ((local_entries_start = ((body) ?? []).length));
2347
+ while (__eliscript_numeric_relation("<", position, emit_nlocals)) {
2348
+ binary_push(body, 1, result_byte((((((emit_locals) ?? [])[position]) ?? null))["type"]));
2349
+ ((position = (position + 1)));
2350
+ }
2351
+ ((instructions_start = ((body) ?? []).length));
2352
+ emit_expression(body, emit_body);
2353
+ binary_push(body, 11);
2354
+ {
2355
+ let u8 = ((!(__eliscript_truthy(cached_entry) && !(__eliscript_truthy(debug)))) ? binary_to_u8(body) : null);
2356
+ let size_start = ((bodies) ?? []).length;
2357
+ if ((!__eliscript_truthy(cached_entry))) {
2358
+ if (__eliscript_truthy(debug)) {
2359
+ (wasm_bodies)["set"](cache_key, ({"bytes": u8, "ranges": local_ranges, "localEntriesStart": local_entries_start, "instructionsStart": instructions_start, "refs": refs, "refIndices": ref_indices}));
2360
+ } else {
2361
+ if (__eliscript_truthy(has_data_text)) {
2362
+ (wasm_bodies)["set"](cache_key, ({"bytes": u8, "refs": refs, "refIndices": ref_indices}));
2363
+ } else {
2364
+ (wasm_bodies)["set"](cache_key, u8);
2365
+ }
2366
+ }
2367
+ }
2368
+ unsigned_leb(bodies, ((body) ?? []).length);
2369
+ if (__eliscript_truthy(debug)) {
2370
+ {
2371
+ let body_start = ((bodies) ?? []).length;
2372
+ let body_end = (body_start + ((body) ?? []).length);
2373
+ replay_wasm_debug_body(debug, function$, host_count, index, count, body_start, body_end, local_ranges, local_entries_start, instructions_start, size_start);
2374
+ }
2375
+ }
2376
+ binary_append_owned(bodies, body);
2377
+ }
2378
+ }
1943
2379
  }
1944
- ((i = (i + 1)));
1945
2380
  }
1946
- ((debug)["functions"])["push"](({"name": (function$)["name"], "index": (host_count + index), "span": ((function$)["span"] ?? (__eliscript_truthy(source) ? ((source)["span"] ?? null) : null)), "sizeField": ({"start": size_start, "end": body_start}), "body": ({"start": body_start, "end": body_end}), "locals": ({"start": body_start, "entriesStart": (body_start + local_entries_start), "end": (body_start + instructions_start), "count": count}), "instructions": ({"start": (body_start + instructions_start), "end": body_end})}));
1947
2381
  }
1948
2382
  }
1949
- binary_append_owned(bodies, body);
2383
+ } else {
2384
+ {
2385
+ let emit_body = fn_body;
2386
+ let emit_locals = locals;
2387
+ let emit_scratch = (__eliscript_truthy(memory) ? ((((memory_scratch) ?? [])[index]) ?? null) : null);
2388
+ if ((__eliscript_truthy(memory) && !(__eliscript_truthy(debug)) && __eliscript_truthy(inline_candidates) && __eliscript_truthy(wasm_has_inline_site(fn_body, inline_candidates, index)))) {
2389
+ {
2390
+ let tmp_locals = (locals)["slice"]();
2391
+ let budget = ({"added": 0, "maxAdded": 140, "maxLocals": 80});
2392
+ let new_body = wasm_rewrite_inline(fn_body, inline_candidates, index, tmp_locals, budget);
2393
+ if (__eliscript_numeric_relation(">", (budget)["added"], 0)) {
2394
+ ((emit_locals = tmp_locals), (emit_body = new_body));
2395
+ if (((emit_scratch === null) && __eliscript_truthy(has_memory_access_p(emit_body)))) {
2396
+ ((emit_scratch = wasm_append_memory_scratch(emit_locals)));
2397
+ }
2398
+ }
2399
+ }
2400
+ }
2401
+ {
2402
+ let body = binary_child(bodies);
2403
+ let count = __eliscript_numeric_sub(((emit_locals) ?? []).length, (function$)["arity"]);
2404
+ let position = (function$)["arity"];
2405
+ let range_start = (__eliscript_truthy(debug) ? (((debug)["ranges"]) ?? []).length : 0);
2406
+ let local_entries_start = 0;
2407
+ let instructions_start = 0;
2408
+ ((body)["wasmFunctionBase"] = host_count);
2409
+ ((body)["wasmHostCapabilities"] = capabilities);
2410
+ ((body)["wasmMemory"] = memory);
2411
+ ((body)["wasmDataTexts"] = data_texts);
2412
+ if (__eliscript_truthy(emit_scratch)) {
2413
+ ((body)["wasmMemoryScratch"] = emit_scratch);
2414
+ }
2415
+ ((body)["wasmDataIndices"] = data_indices);
2416
+ if (__eliscript_truthy(debug)) {
2417
+ ((body)["wasmDebug"] = ({"ranges": (debug)["ranges"], "depth": 0, "trapSites": (debug)["trapSites"], "function": (function$)["name"], "functionIndex": (host_count + index)}));
2418
+ }
2419
+ unsigned_leb(body, count);
2420
+ ((local_entries_start = ((body) ?? []).length));
2421
+ while (__eliscript_numeric_relation("<", position, ((emit_locals) ?? []).length)) {
2422
+ binary_push(body, 1, result_byte((((((emit_locals) ?? [])[position]) ?? null))["type"]));
2423
+ ((position = (position + 1)));
2424
+ }
2425
+ ((instructions_start = ((body) ?? []).length));
2426
+ emit_expression(body, emit_body);
2427
+ binary_push(body, 11);
2428
+ {
2429
+ let size_start = ((bodies) ?? []).length;
2430
+ unsigned_leb(bodies, ((body) ?? []).length);
2431
+ if (__eliscript_truthy(debug)) {
2432
+ {
2433
+ let body_start = ((bodies) ?? []).length;
2434
+ let body_end = (body_start + ((body) ?? []).length);
2435
+ let source = ((function$)["source"] ?? null);
2436
+ let ranges = (debug)["ranges"];
2437
+ let i = range_start;
2438
+ while (__eliscript_numeric_relation("<", i, ((ranges) ?? []).length)) {
2439
+ {
2440
+ let range = ((((ranges) ?? [])[i]) ?? null);
2441
+ ((range)["start"] = (body_start + (range)["start"]));
2442
+ ((range)["end"] = (body_start + (range)["end"]));
2443
+ }
2444
+ ((i = (i + 1)));
2445
+ }
2446
+ ((debug)["functions"])["push"](({"name": (function$)["name"], "index": (host_count + index), "span": ((function$)["span"] ?? (__eliscript_truthy(source) ? ((source)["span"] ?? null) : null)), "sizeField": ({"start": size_start, "end": body_start}), "body": ({"start": body_start, "end": body_end}), "locals": ({"start": body_start, "entriesStart": (body_start + local_entries_start), "end": (body_start + instructions_start), "count": count}), "instructions": ({"start": (body_start + instructions_start), "end": body_end})}));
2447
+ }
2448
+ }
2449
+ binary_append_owned(bodies, body);
2450
+ }
2451
+ }
2452
+ }
1950
2453
  }
1951
2454
  if (__eliscript_truthy(consume_owned_bodies)) {
1952
2455
  ((function$)["body"] = null);
@@ -2073,7 +2576,7 @@ function make_wasm_validation_workspace() {
2073
2576
  function validate_fresh_wasm_expression(expression, parent, memory, workspace = null) {
2074
2577
  require_wasm_expression_node(expression, parent, memory);
2075
2578
  {
2076
- let work = ((__eliscript_value_10) => (__eliscript_truthy(__eliscript_value_10) ? __eliscript_value_10 : make_wasm_validation_workspace()))(workspace);
2579
+ let work = ((__eliscript_value_18) => (__eliscript_truthy(__eliscript_value_18) ? __eliscript_value_18 : make_wasm_validation_workspace()))(workspace);
2077
2580
  let nodes = (work)["nodes"];
2078
2581
  let positions = (work)["positions"];
2079
2582
  let seen = (work)["seen"];
@@ -2166,14 +2669,49 @@ function validate_fresh_typed_wasm_program(program) {
2166
2669
  }
2167
2670
  return program;
2168
2671
  }
2672
+ function validate_trusted_typed_wasm_program(program) {
2673
+ if ((!(!((program === null)) && (__eliscript_value_type(program) === "object") && !(__eliscript_truthy(Array.isArray(program)))))) {
2674
+ backend_fail(null, "typed WASM emitter requires a program object");
2675
+ }
2676
+ {
2677
+ let functions = (program)["functions"];
2678
+ let memory = ((program)["abi"] === "memory-u32");
2679
+ let trusted = ((__eliscript_value_19) => (__eliscript_truthy(__eliscript_value_19) ? trusted_runtime_program_p(program) : __eliscript_value_19))(((program)["abi"] === "memory-u32"));
2680
+ let workspace = make_wasm_validation_workspace();
2681
+ let index = 0;
2682
+ if ((!__eliscript_truthy(Array.isArray(functions)))) {
2683
+ backend_fail(program, "typed WASM emitter requires declared functions");
2684
+ }
2685
+ while (__eliscript_numeric_relation("<", index, ((functions) ?? []).length)) {
2686
+ {
2687
+ let function$ = ((((functions) ?? [])[index]) ?? null);
2688
+ if ((!(!((function$ === null)) && (__eliscript_value_type(function$) === "object") && !(__eliscript_truthy(Array.isArray(function$))) && __eliscript_truthy(Array.isArray((function$)["locals"]))))) {
2689
+ backend_fail(program, "typed WASM function requires a locals array");
2690
+ }
2691
+ {
2692
+ let body = (function$)["body"];
2693
+ let cached = (__eliscript_truthy(memory) ? runtime_body_cache_get(body) : null);
2694
+ if ((!(__eliscript_truthy(cached) && (__eliscript_truthy(trusted) || __eliscript_truthy((cached)["frozen"])) && __eliscript_truthy((cached)["wasmValidated"])))) {
2695
+ validate_fresh_wasm_expression(body, function$, memory, workspace);
2696
+ if (__eliscript_truthy(cached)) {
2697
+ ((cached)["wasmValidated"] = true);
2698
+ }
2699
+ }
2700
+ }
2701
+ }
2702
+ ((index = (index + 1)));
2703
+ }
2704
+ }
2705
+ return program;
2706
+ }
2169
2707
  function emit_fresh_managed_wasm_product(lowered, configure) {
2170
2708
  if ((!(__eliscript_value_type(configure) === "function"))) {
2171
2709
  backend_fail(null, "managed WASM product requires an output configuration callback");
2172
2710
  }
2173
2711
  {
2174
2712
  let configuration = configure();
2175
- let typed = validate_fresh_typed_wasm_program((lowered)["typed"]);
2176
- let memory = ((__eliscript_value_11) => (__eliscript_truthy(__eliscript_value_11) ? __eliscript_value_11 : ({})))(((configuration)["memory"] ?? null));
2713
+ let typed = validate_trusted_typed_wasm_program(mark_trusted_runtime_program((lowered)["typed"]));
2714
+ let memory = ((__eliscript_value_20) => (__eliscript_truthy(__eliscript_value_20) ? __eliscript_value_20 : ({})))(((configuration)["memory"] ?? null));
2177
2715
  let debug = ((((configuration)["debug"] ?? false) === true) ? ({"format": "eliscript-wasm-source-map", "target": "wasm32", "abi": "memory-u32", "offsetUnit": "byte", "offsetBase": "module", "functions": [], "ranges": []}) : null);
2178
2716
  let descriptor = (lowered)["descriptor"];
2179
2717
  let output = append_metadata_section(emit_typed_scalar_wasm(typed, memory, debug, true), "eliscript-managed-control", JSON.stringify(descriptor));
@@ -2187,18 +2725,16 @@ function emit_fresh_managed_wasm_product(lowered, configure) {
2187
2725
  }
2188
2726
  }
2189
2727
  function managed_wasm_product_fail(node, message, phase = null) {
2190
- return (() => {
2191
- try {
2192
- return backend_fail(node, message);
2193
- } catch (error) {
2194
- (((error)["eliscriptDiagnostic"])["phase"] = ((__eliscript_value_12) => (__eliscript_truthy(__eliscript_value_12) ? __eliscript_value_12 : "managed-backend"))(phase));
2195
- return ((__eliscript_value_13) => { throw __eliscript_value_13; })(error);
2196
- }
2197
- })();
2728
+ try {
2729
+ return backend_fail(node, message);
2730
+ } catch (error) {
2731
+ (((error)["eliscriptDiagnostic"])["phase"] = ((__eliscript_value_21) => (__eliscript_truthy(__eliscript_value_21) ? __eliscript_value_21 : "managed-backend"))(phase));
2732
+ return ((__eliscript_value_22) => { throw __eliscript_value_22; })(error);
2733
+ }
2198
2734
  }
2199
2735
  function emit_managed_ir_wasm_product(program, runtime_program, lower_options, configure) {
2200
2736
  {
2201
- let options = ((__eliscript_value_14) => (__eliscript_truthy(__eliscript_value_14) ? __eliscript_value_14 : ({})))(lower_options);
2737
+ let options = ((__eliscript_value_23) => (__eliscript_truthy(__eliscript_value_23) ? __eliscript_value_23 : ({})))(lower_options);
2202
2738
  let requested = ((options)["abi"] ?? null);
2203
2739
  let lowered = lower_managed_program(program, runtime_program, (requested === "managed-module"), null, null, null, null, null, null, ((options)["literalModules"] ?? null));
2204
2740
  if ((!((requested === null)) && !(((requested === "managed-control") || (requested === "managed-module"))))) {
@@ -2212,7 +2748,7 @@ function emit_managed_ir_wasm_product(program, runtime_program, lower_options, c
2212
2748
  }
2213
2749
  function emit_managed_project_wasm_product(modules, entry, runtime_program, lower_options, configure) {
2214
2750
  {
2215
- let requested = ((((__eliscript_value_15) => (__eliscript_truthy(__eliscript_value_15) ? __eliscript_value_15 : ({})))(lower_options))["abi"] ?? null);
2751
+ let requested = ((((__eliscript_value_24) => (__eliscript_truthy(__eliscript_value_24) ? __eliscript_value_24 : ({})))(lower_options))["abi"] ?? null);
2216
2752
  let lowered = lower_managed_project(modules, entry, runtime_program, lower_options);
2217
2753
  if ((!((requested === null)) && !((requested === "managed-module")))) {
2218
2754
  managed_wasm_product_fail(null, "managed projects require managed-module", "managed-link");
@@ -2224,22 +2760,22 @@ function emit_typed_numeric_wasm(program, options = null) {
2224
2760
  if ((!((program)["abi"] === "numeric-f64"))) {
2225
2761
  backend_fail(program, "WASM emitter requires numeric-f64 typed input");
2226
2762
  }
2227
- return binary_finish(emit_typed_scalar_wasm(copy_typed_wasm_program(program), ((__eliscript_value_16) => (__eliscript_truthy(__eliscript_value_16) ? __eliscript_value_16 : ({})))(options)));
2763
+ return binary_finish(emit_typed_scalar_wasm(copy_typed_wasm_program(program), ((__eliscript_value_25) => (__eliscript_truthy(__eliscript_value_25) ? __eliscript_value_25 : ({})))(options)));
2228
2764
  }
2229
2765
  function emit_memory_wasm(program, options = null) {
2230
- return binary_finish(emit_typed_scalar_wasm(lower_memory_program(program), ((__eliscript_value_17) => (__eliscript_truthy(__eliscript_value_17) ? __eliscript_value_17 : ({})))(options)));
2766
+ return binary_finish(emit_typed_scalar_wasm(lower_memory_program(program), ((__eliscript_value_26) => (__eliscript_truthy(__eliscript_value_26) ? __eliscript_value_26 : ({})))(options)));
2231
2767
  }
2232
2768
  function emit_owned_memory_wasm(program, options = null) {
2233
2769
  if ((!((program)["abi"] === "memory-u32"))) {
2234
2770
  backend_fail(program, "owned memory emitter requires memory-u32");
2235
2771
  }
2236
- return binary_finish(emit_typed_scalar_wasm(validate_fresh_typed_wasm_program(program), ((__eliscript_value_18) => (__eliscript_truthy(__eliscript_value_18) ? __eliscript_value_18 : ({})))(options), null, true));
2772
+ return binary_finish(emit_typed_scalar_wasm(validate_trusted_typed_wasm_program(program), ((__eliscript_value_27) => (__eliscript_truthy(__eliscript_value_27) ? __eliscript_value_27 : ({})))(options), null, true));
2237
2773
  }
2238
2774
  function emit_typed_memory_wasm(program, options = null) {
2239
2775
  if ((!((program)["abi"] === "memory-u32"))) {
2240
2776
  backend_fail(program, "typed memory emitter requires memory-u32");
2241
2777
  }
2242
- return binary_finish(emit_typed_scalar_wasm(copy_typed_wasm_program(program), ((__eliscript_value_19) => (__eliscript_truthy(__eliscript_value_19) ? __eliscript_value_19 : ({})))(options)));
2778
+ return binary_finish(emit_typed_scalar_wasm(copy_typed_wasm_program(program), ((__eliscript_value_28) => (__eliscript_truthy(__eliscript_value_28) ? __eliscript_value_28 : ({})))(options)));
2243
2779
  }
2244
2780
  function emit_typed_memory_wasm_artifact(program, options = null) {
2245
2781
  if ((!((program)["abi"] === "memory-u32"))) {
@@ -2247,7 +2783,7 @@ function emit_typed_memory_wasm_artifact(program, options = null) {
2247
2783
  }
2248
2784
  {
2249
2785
  let debug = ({"format": "eliscript-wasm-source-map", "target": "wasm32", "abi": "memory-u32", "offsetUnit": "byte", "offsetBase": "module", "functions": [], "ranges": []});
2250
- let bytes = emit_typed_scalar_wasm(copy_typed_wasm_program(program), ((__eliscript_value_20) => (__eliscript_truthy(__eliscript_value_20) ? __eliscript_value_20 : ({})))(options), debug);
2786
+ let bytes = emit_typed_scalar_wasm(copy_typed_wasm_program(program), ((__eliscript_value_29) => (__eliscript_truthy(__eliscript_value_29) ? __eliscript_value_29 : ({})))(options), debug);
2251
2787
  ((debug)["moduleByteLength"] = ((bytes) ?? []).length);
2252
2788
  return ({"bytes": binary_finish(bytes), "debug": debug});
2253
2789
  }