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,5 +1,5 @@
1
1
  (module eliscript.backend.managed
2
- (import "./numeric.mjs" backend-fail find-function)
2
+ (import "./numeric.mjs" backend-fail find-function runtime-body-cache-set mark-trusted-runtime-program)
3
3
  (import "./async.mjs" lower-async-program)
4
4
  (import "./capabilities.mjs" prepare-host-capabilities)
5
5
  (import "../bootstrap/ir.mjs" validate-serializable-program)
@@ -30,6 +30,310 @@
30
30
  ;; Static images contain only immutable primitives and function facts.
31
31
  ;; Mutable function instances remain private to their owning Realm.
32
32
  (defconst managed-static-images (new globalThis.WeakMap))
33
+ (defconst lowered-memory-runtime-cache (new globalThis.WeakMap))
34
+ (defconst unfrozen-memory-runtime-cache (new globalThis.WeakMap))
35
+ (defvar next-runtime-id 1)
36
+ (defconst runtime-memory-access-ops (new globalThis.Set (js-array
37
+ "load-u8" "load-u16" "load-u32" "load-f64" "load-v64" "load-bits64"
38
+ "store-u8" "store-u16" "store-u32" "store-f64" "store-v64" "store-bits64")))
39
+ (defun locals-type-sig (locals)
40
+ (let ((parts (js-array)) (len (js-length locals)) (i 0))
41
+ (while (< i len)
42
+ (js-call parts :push (get (js-nth i locals) :type))
43
+ (setq i (1+ i)))
44
+ (js-call parts :join ",")))
45
+ (defun deep-freeze-runtime-body (body)
46
+ (let ((seen (new globalThis.Set)) (stack (js-array body)))
47
+ (while (> (js-length stack) 0)
48
+ (let ((node (js-call stack :pop)))
49
+ (when (and (not (nil? node)) (= (value-type node) "object") (not (js-call seen :has node)))
50
+ (js-call seen :add node)
51
+ (let ((children (get node :children nil))
52
+ (param-types (get node :parameterTypes nil))
53
+ (props (get node :properties nil))
54
+ (kind (get node :kind nil))
55
+ (val (get node :value nil)))
56
+ (when (Array/isArray children)
57
+ (let ((ci 0) (clen (js-length children)))
58
+ (while (< ci clen)
59
+ (js-call stack :push (js-nth ci children))
60
+ (setq ci (1+ ci))))
61
+ (Object/freeze children))
62
+ (when (Array/isArray param-types)
63
+ (Object/freeze param-types))
64
+ (when (and (not (nil? props)) (= (value-type props) "object"))
65
+ (Object/freeze props))
66
+ (when (and (= kind "literal") (not (nil? val)) (= (value-type val) "object"))
67
+ (Object/freeze val))
68
+ (Object/freeze node)))))
69
+ body))
70
+ (defconst runtime-hot-leaf-names (new globalThis.Set (js-array
71
+ "heap-block" "rt-root-scope-set-abs" "rt-root-scope-get-abs"
72
+ "heap-ro-block" "heap-value-valid" "value-number-bits"
73
+ "heap-number-from-word")))
74
+ (defun inspect-runtime-body (body fn-index fn-count arity locals runtime-id &optional fn-name)
75
+ (let ((has-indirect false) (has-host-call false)
76
+ (has-data-text false) (has-memory-access false)
77
+ (call-count 0) (has-self-call false) (has-loop false) (max-call-target -1) (node-count 0)
78
+ (hot-leaf (and (= (value-type fn-name) "string") (js-call runtime-hot-leaf-names :has fn-name)))
79
+ (stack (js-array body)))
80
+ (while (> (js-length stack) 0)
81
+ (let ((node (js-call stack :pop)))
82
+ (when (and (not (nil? node)) (= (value-type node) "object"))
83
+ (setq node-count (1+ node-count))
84
+ (let ((kind (get node :kind nil))
85
+ (children (get node :children nil)))
86
+ (cond
87
+ ((= kind "call")
88
+ (setq call-count (1+ call-count))
89
+ (let ((target (get node :value nil)))
90
+ (when (= (value-type target) "number")
91
+ (when (= target fn-index) (setq has-self-call t))
92
+ (setq max-call-target (Math/max max-call-target target)))))
93
+ ((= kind "call-indirect") (setq has-indirect t))
94
+ ((= kind "host-call") (setq has-host-call t))
95
+ ((or (= kind "data-text") (= kind "memory-data-copy")) (setq has-data-text t))
96
+ ((or (= kind "while") (= kind "remainder-while") (= kind "guarded-while")) (setq has-loop t))
97
+ ((and (= kind "memory-op")
98
+ (js-call runtime-memory-access-ops :has (get node :value nil)))
99
+ (setq has-memory-access t)))
100
+ (when (Array/isArray children)
101
+ (let ((ci 0) (clen (js-length children)))
102
+ (while (< ci clen)
103
+ (js-call stack :push (js-nth ci children))
104
+ (setq ci (1+ ci)))))))))
105
+ (let ((can-freeze (and (not has-indirect) (not has-host-call))))
106
+ (when can-freeze (deep-freeze-runtime-body body))
107
+ (js-object
108
+ :runtimeId runtime-id :runtimeFnCount fn-count :fnIndex fn-index
109
+ :arity arity :localsSig (locals-type-sig locals)
110
+ :hasIndirect has-indirect :hasHostCall has-host-call
111
+ :hasDataText has-data-text :hasMemoryAccess has-memory-access
112
+ :maxCallTarget max-call-target
113
+ :leafCandidate (if (and (<= (js-length locals) 12)
114
+ (<= node-count (if hot-leaf 120 52))
115
+ (<= call-count (if hot-leaf 4 3))
116
+ (not has-self-call) (< max-call-target fn-count)
117
+ (not has-indirect) (not has-host-call) (not has-loop) (not has-data-text))
118
+ node-count -1)
119
+ :frozen can-freeze
120
+ :wasmValidated false :nativeValidated false
121
+ :wasmBodies (new globalThis.Map) :nativeBodies (new globalThis.Map)))))
122
+ (defun register-lowered-runtime-bodies (lowered)
123
+ (let* ((functions (get lowered :functions (js-array)))
124
+ (len (js-length functions))
125
+ (runtime-id next-runtime-id)
126
+ (i 0))
127
+ (setq next-runtime-id (1+ next-runtime-id))
128
+ (while (< i len)
129
+ (let ((fn (js-nth i functions)))
130
+ (when fn
131
+ (runtime-body-cache-set (get fn :body nil)
132
+ (inspect-runtime-body (get fn :body nil) i len (get fn :arity) (get fn :locals) runtime-id (get fn :name nil)))))
133
+ (setq i (1+ i)))))
134
+ (defconst ir-fingerprint-strings (new globalThis.Map))
135
+ (defun ir-string-id (s)
136
+ (let ((existing (js-call ir-fingerprint-strings :get s)))
137
+ (if (not (undefined? existing)) existing
138
+ (let* ((slen (js-length s)) (h (uint32 (+ slen 2166136261))) (si 0))
139
+ (while (< si slen)
140
+ (setq h (unsigned-bit-shift-right (imul32 (bit-xor h (string-code-unit-at s si)) 16777619) 0))
141
+ (setq si (1+ si)))
142
+ (when (< (get ir-fingerprint-strings :size) 32768)
143
+ (js-call ir-fingerprint-strings :set s h))
144
+ h))))
145
+ (defun fingerprint-ir-program (program)
146
+ (try
147
+ (let ((h1 2166136261) (h2 33554467) (steps 0) (aborted false)
148
+ (stack (js-array program)))
149
+ (when (= (value-type (get program :filename nil)) "string")
150
+ (let ((fid (ir-string-id (get program :filename))))
151
+ (setq h1 (imul32 (bit-xor h1 fid) 16777619)
152
+ h2 (imul32 (bit-xor h2 fid) 2246822507))))
153
+ (while (and (not aborted) (> (js-length stack) 0))
154
+ (setq steps (1+ steps))
155
+ (if (> steps 2000000)
156
+ (setq aborted t)
157
+ (let ((cur (js-call stack :pop)))
158
+ (cond
159
+ ((eq cur nil)
160
+ (setq h1 (imul32 (bit-xor h1 1) 16777619)
161
+ h2 (imul32 (bit-xor h2 1) 2246822507)))
162
+ ((undefined? cur)
163
+ (setq h1 (imul32 (bit-xor h1 2) 16777619)
164
+ h2 (imul32 (bit-xor h2 2) 2246822507)))
165
+ (t
166
+ (let ((vt (value-type cur)))
167
+ (cond
168
+ ((= vt "string")
169
+ (let ((sid (ir-string-id cur)))
170
+ (setq h1 (imul32 (bit-xor h1 sid) 16777619)
171
+ h2 (imul32 (bit-xor h2 (+ sid 3)) 2246822507))))
172
+ ((= vt "number")
173
+ (if (and (Number/isInteger cur) (>= cur -2147483648) (<= cur 2147483647))
174
+ (let ((nv (if (Object/is cur (- 0)) 4294967299 (+ cur 2147483649))))
175
+ (setq h1 (imul32 (bit-xor h1 nv) 16777619)
176
+ h2 (imul32 (bit-xor h2 (+ nv 4)) 2246822507)))
177
+ (if (Number/isNaN cur)
178
+ (setq h1 (imul32 (bit-xor h1 999) 16777619)
179
+ h2 (imul32 (bit-xor h2 999) 2246822507))
180
+ (let ((words (number-float64-words cur)))
181
+ (setq h1 (imul32 (bit-xor h1 (js-nth 0 words)) 16777619)
182
+ h2 (imul32 (bit-xor h2 (js-nth 1 words)) 2246822507))))))
183
+ ((= vt "boolean")
184
+ (let ((bv (if cur 5 6)))
185
+ (setq h1 (imul32 (bit-xor h1 bv) 16777619)
186
+ h2 (imul32 (bit-xor h2 bv) 2246822507))))
187
+ ((= vt "bigint")
188
+ (let ((bid (ir-string-id (funcall globalThis.String cur))))
189
+ (setq h1 (imul32 (bit-xor h1 (+ bid 10)) 16777619)
190
+ h2 (imul32 (bit-xor h2 (+ bid 10)) 2246822507))))
191
+ ((Array/isArray cur)
192
+ (let* ((alen (js-length cur)) (ai (1- alen)))
193
+ (setq h1 (imul32 (bit-xor h1 (+ alen 7)) 16777619)
194
+ h2 (imul32 (bit-xor h2 (+ alen 7)) 2246822507))
195
+ (while (>= ai 0)
196
+ (let ((elem (js-nth ai cur)))
197
+ (cond
198
+ ((= (value-type elem) "string")
199
+ (let ((sid (ir-string-id elem)))
200
+ (setq h1 (imul32 (bit-xor h1 sid) 16777619)
201
+ h2 (imul32 (bit-xor h2 (+ sid 3)) 2246822507))))
202
+ ((= (value-type elem) "number")
203
+ (if (and (Number/isInteger elem) (>= elem -2147483648) (<= elem 2147483647))
204
+ (let ((nv (if (Object/is elem (- 0)) 4294967299 (+ elem 2147483649))))
205
+ (setq h1 (imul32 (bit-xor h1 nv) 16777619)
206
+ h2 (imul32 (bit-xor h2 (+ nv 4)) 2246822507)))
207
+ (js-call stack :push elem)))
208
+ (t (js-call stack :push elem))))
209
+ (setq ai (1- ai)))))
210
+ ((= vt "object")
211
+ (setq h1 (imul32 (bit-xor h1 8) 16777619)
212
+ h2 (imul32 (bit-xor h2 8) 2246822507))
213
+ (let ((k (get cur :kind undefined)))
214
+ (when (not (undefined? k))
215
+ (if (= (value-type k) "string")
216
+ (let ((sid (ir-string-id k)))
217
+ (setq h1 (imul32 (bit-xor h1 sid) 16777619)
218
+ h2 (imul32 (bit-xor h2 (+ sid 3)) 2246822507)))
219
+ (js-call stack :push k))))
220
+ (let ((v (get cur :value undefined)))
221
+ (cond
222
+ ((undefined? v)
223
+ (when (Object/hasOwn cur "value")
224
+ (setq h1 (imul32 (bit-xor h1 2) 16777619)
225
+ h2 (imul32 (bit-xor h2 2) 2246822507))))
226
+ ((eq v nil)
227
+ (setq h1 (imul32 (bit-xor h1 1) 16777619)
228
+ h2 (imul32 (bit-xor h2 1) 2246822507)))
229
+ ((= (value-type v) "string")
230
+ (let ((sid (ir-string-id v)))
231
+ (setq h1 (imul32 (bit-xor h1 sid) 16777619)
232
+ h2 (imul32 (bit-xor h2 (+ sid 3)) 2246822507))))
233
+ ((= (value-type v) "number")
234
+ (if (and (Number/isInteger v) (>= v -2147483648) (<= v 2147483647))
235
+ (let ((nv (if (Object/is v (- 0)) 4294967299 (+ v 2147483649))))
236
+ (setq h1 (imul32 (bit-xor h1 nv) 16777619)
237
+ h2 (imul32 (bit-xor h2 (+ nv 4)) 2246822507)))
238
+ (js-call stack :push v)))
239
+ ((= (value-type v) "boolean")
240
+ (let ((bv (if v 5 6)))
241
+ (setq h1 (imul32 (bit-xor h1 bv) 16777619)
242
+ h2 (imul32 (bit-xor h2 bv) 2246822507))))
243
+ (t (js-call stack :push v))))
244
+ (let ((tp (get cur :type undefined)))
245
+ (when (not (undefined? tp))
246
+ (if (= (value-type tp) "string")
247
+ (let ((sid (ir-string-id tp)))
248
+ (setq h1 (imul32 (bit-xor h1 sid) 16777619)
249
+ h2 (imul32 (bit-xor h2 (+ sid 3)) 2246822507)))
250
+ (js-call stack :push tp))))
251
+ (let ((fn (get cur :filename undefined)))
252
+ (when (not (undefined? fn))
253
+ (if (= (value-type fn) "string")
254
+ (let ((sid (ir-string-id fn)))
255
+ (setq h1 (imul32 (bit-xor h1 sid) 16777619)
256
+ h2 (imul32 (bit-xor h2 (+ sid 3)) 2246822507)))
257
+ (js-call stack :push fn))))
258
+ (let ((props (get cur :properties nil)))
259
+ (when (and props (= (value-type props) "object"))
260
+ (let ((pkeys (Object/keys props)) (pi 0))
261
+ (setq h1 (imul32 (bit-xor h1 (+ (js-length pkeys) 9)) 16777619)
262
+ h2 (imul32 (bit-xor h2 (+ (js-length pkeys) 9)) 2246822507))
263
+ (while (< pi (js-length pkeys))
264
+ (let* ((pk (js-nth pi pkeys))
265
+ (kid (ir-string-id pk)))
266
+ (setq h1 (imul32 (bit-xor h1 kid) 16777619)
267
+ h2 (imul32 (bit-xor h2 kid) 2246822507))
268
+ (js-call stack :push (get props pk)))
269
+ (setq pi (1+ pi))))))
270
+ (let ((span (get cur :span nil)))
271
+ (when (and span (= (value-type span) "object"))
272
+ (let ((sl (or (get span :line 0) 0))
273
+ (sc (or (get span :column 0) 0)))
274
+ (setq h1 (imul32 (bit-xor h1 (+ sl sc)) 16777619)
275
+ h2 (imul32 (bit-xor h2 (+ sl sc)) 2246822507)))))
276
+ (let ((ch (get cur :children undefined)))
277
+ (when (not (undefined? ch))
278
+ (if (Array/isArray ch)
279
+ (let* ((clen (js-length ch)) (ci (1- clen)))
280
+ (setq h1 (imul32 (bit-xor h1 (+ clen 7)) 16777619)
281
+ h2 (imul32 (bit-xor h2 (+ clen 7)) 2246822507))
282
+ (while (>= ci 0)
283
+ (js-call stack :push (js-nth ci ch))
284
+ (setq ci (1- ci))))
285
+ (js-call stack :push ch))))
286
+ (let ((bd (get cur :body undefined)))
287
+ (when (not (undefined? bd))
288
+ (js-call stack :push bd))))
289
+ (t (setq aborted t)))))))))
290
+ (if aborted nil (str (unsigned-bit-shift-right h1 0) ":" (unsigned-bit-shift-right h2 0))))
291
+ (catch error nil)))
292
+ (defun clone-lowered-memory-runtime (lowered)
293
+ (let ((copy (js-object :abi (get lowered :abi)
294
+ :filename (get lowered :filename)
295
+ :functions (js-call (get lowered :functions) :map (lambda (fn)
296
+ (Object/assign (js-object) fn
297
+ (js-object :locals (js-call (get fn :locals) :slice)
298
+ :parameterTypes (js-call (get fn :parameterTypes) :slice)))))
299
+ :exports (js-call (get lowered :exports) :slice))))
300
+ (when (get lowered :table nil)
301
+ (put copy :table (js-call (get lowered :table) :slice)))
302
+ (when (get lowered :indirectSignatures nil)
303
+ (put copy :indirectSignatures
304
+ (js-call (get lowered :indirectSignatures) :map (lambda (sig)
305
+ (Object/assign (js-object) sig
306
+ (js-object :parameterTypes (js-call (get sig :parameterTypes) :slice)))))))
307
+ copy))
308
+ (defun cached-lower-memory-program (runtime-program)
309
+ (if (or (nil? runtime-program) (not (= (value-type runtime-program) "object")))
310
+ (lower-memory-program runtime-program)
311
+ (if (Object/isFrozen runtime-program)
312
+ (let ((cached (js-call lowered-memory-runtime-cache :get runtime-program)))
313
+ (unless cached
314
+ (setq cached (lower-memory-program runtime-program))
315
+ (register-lowered-runtime-bodies cached)
316
+ (js-call lowered-memory-runtime-cache :set runtime-program cached))
317
+ (clone-lowered-memory-runtime cached))
318
+ (let ((entry (js-call unfrozen-memory-runtime-cache :get runtime-program)))
319
+ (if entry
320
+ (let ((hash (fingerprint-ir-program runtime-program)))
321
+ (if (and (not (nil? hash)) (= (get entry :hash) hash))
322
+ (clone-lowered-memory-runtime (get entry :lowered))
323
+ (let ((lowered (lower-memory-program runtime-program))
324
+ (next-hash (fingerprint-ir-program runtime-program)))
325
+ (register-lowered-runtime-bodies lowered)
326
+ (when (not (nil? next-hash))
327
+ (js-call unfrozen-memory-runtime-cache :set runtime-program
328
+ (js-object :hash next-hash :lowered lowered)))
329
+ (clone-lowered-memory-runtime lowered))))
330
+ (let ((lowered (lower-memory-program runtime-program))
331
+ (hash (fingerprint-ir-program runtime-program)))
332
+ (register-lowered-runtime-bodies lowered)
333
+ (when (not (nil? hash))
334
+ (js-call unfrozen-memory-runtime-cache :set runtime-program
335
+ (js-object :hash hash :lowered lowered)))
336
+ (clone-lowered-memory-runtime lowered)))))))
33
337
  (defun managed-static-image (state)
34
338
  (let ((image (js-call managed-static-images :get (get state :runtime))))
35
339
  (unless image (managed-fail nil "managed static image is not initialized")) image))
@@ -196,7 +500,8 @@
196
500
  (let ((arguments (js-array (word-local (get state :heap)))))
197
501
  (append-managed arguments values)))
198
502
  (defun capture-error (state)
199
- (managed-guard state (word-set (get state :error) (runtime-call state "last-error" (js-array)))))
503
+ (managed-guard state (word-set (get state :error)
504
+ (word-node "memory-op" (js-array (word-constant 8)) "load-u32"))))
200
505
  (defun managed-guard (state expression)
201
506
  (let* ((error (get state :error)) (index (get error :index)) (cached (get state :guardPredicate nil)))
202
507
  ;; Only pure IR is shared inside this function's private lowering state.
@@ -216,13 +521,17 @@
216
521
  (js-object :steps (checked-control state name arguments)
217
522
  :result (managed-v64-constant (js-object :low 3 :high 0))))
218
523
  (defun managed-private-roots-p (state) (eq (get state :privateRoots nil) t))
524
+ (defun managed-root-set-at (state base-local offset value)
525
+ (checked-control state "rt-root-scope-set-abs" (runtime-arguments state
526
+ (js-array (if (= offset 0) (word-local base-local)
527
+ (managed-raw-binary (word-local base-local) (word-constant offset) "+"))
528
+ value))))
219
529
  (defun managed-root-set (state index value)
220
530
  ;; index is a compiler integer inside the function scope. Nested argument
221
531
  ;; scopes move the current top, so private roots use the cached absolute
222
532
  ;; functionBase. root-scope-base is an index, never a success flag.
223
533
  (if (managed-private-roots-p state)
224
- (checked-control state "root-scope-set-abs" (runtime-arguments state
225
- (js-array (managed-raw-binary (word-local (get state :functionBase)) (word-constant index) "+") value)))
534
+ (managed-root-set-at state (get state :functionBase) index value)
226
535
  (checked-control state "frame-set" (runtime-arguments state
227
536
  (js-array (word-local (get state :frame)) (word-constant index) value)))))
228
537
  (defun managed-root-clear-except (state first end keep)
@@ -531,6 +840,21 @@
531
840
  (put node :resultType "v64") (fixed id "v64"))
532
841
  ((= kind "host-call")
533
842
  (fixed (js-nth 0 child-vars) "u32") (fixed (js-nth 1 child-vars) "v64") (fixed id "v64"))
843
+ ((= kind "memory-op")
844
+ (let ((op (get node :value)))
845
+ (cond
846
+ ((= op "store-v64")
847
+ (fixed (js-nth 0 child-vars) "u32")
848
+ (fixed (js-nth 1 child-vars) "v64")
849
+ (fixed id "u32"))
850
+ ((= op "store-bits64")
851
+ (fixed (js-nth 0 child-vars) "u32")
852
+ (fixed (js-nth 1 child-vars) "bits64")
853
+ (fixed id "u32"))
854
+ ((or (= op "load-u32") (= op "load-u8") (= op "load-u16"))
855
+ (fixed (js-nth 0 child-vars) "u32")
856
+ (fixed id "u32"))
857
+ (t (fixed id (get node :type))))))
534
858
  (t
535
859
  (fixed id (get node :type))
536
860
  (when (= kind "word-arithmetic")
@@ -1170,7 +1494,7 @@
1170
1494
  (runtime-arguments state (js-array (word-constant 7) (word-constant 0)))) t)))
1171
1495
  ;; The original initialized test still owns the observation boundary.
1172
1496
  ;; Only its actual first observation allocates the private ABI vector.
1173
- (word-if (word-compare (runtime-call state (if (= builtin 0)
1497
+ (managed-guard state (word-if (word-compare (runtime-call state (if (= builtin 0)
1174
1498
  "value-function-number-prototype-ready" "value-function-initialized")
1175
1499
  (runtime-arguments state (js-array value))) (word-constant 0) "=")
1176
1500
  (word-sequence (js-array (get arguments :steps)
@@ -1178,7 +1502,7 @@
1178
1502
  (runtime-arguments state (js-array value (get arguments :result) (word-constant 0)))
1179
1503
  (get initializer :index)))
1180
1504
  (capture-error state)))
1181
- (word-constant 0))))
1505
+ (word-constant 0)))))
1182
1506
  (defun lower-managed-object-constructor-publication (value key state)
1183
1507
  (let ((steps (js-array))
1184
1508
  (operations (js-array 16 17 18 21 22 23 27 37 38 39 170 171 172 173 174 175 176 177 178 179 194 195))
@@ -1379,9 +1703,9 @@
1379
1703
  ;; Nested member/iterator assembly borrows the caller's guard. Restore
1380
1704
  ;; it instead of clearing an enclosing Array publication's guard.
1381
1705
  (put state :describingNative describing))
1382
- (word-if (word-compare (runtime-call state (if defer-number-statics
1706
+ (managed-guard state (word-if (word-compare (runtime-call state (if defer-number-statics
1383
1707
  "value-function-number-prototype-ready" "value-function-initialized") (runtime-arguments state (js-array value)))
1384
- (word-constant 0) "=") (word-sequence steps) (word-constant 0)))))))
1708
+ (word-constant 0) "=") (word-sequence steps) (word-constant 0))))))))
1385
1709
  (defun lower-managed-realm-initialization (state)
1386
1710
  ;; Only this existing private callback owns the common native assembly IR.
1387
1711
  ;; Nested Object/member descriptions retain the original recursion guards.
@@ -1523,7 +1847,7 @@
1523
1847
  (let ((described (lower-managed-function-description (get value :result) function state)))
1524
1848
  (js-call steps :push (get described :steps))
1525
1849
  (unless (nil? (get function :builtin nil))
1526
- (js-call steps :push (lower-managed-native-initialization (get described :result) function state)))
1850
+ (js-call steps :push (managed-guard state (lower-managed-native-initialization (get described :result) function state))))
1527
1851
  ;; Native registration retains its actual members through the realm
1528
1852
  ;; object graph. Names, argument vectors and nested initialization
1529
1853
  ;; intermediates cease to be caller roots once this expression ends.
@@ -2255,7 +2579,7 @@
2255
2579
  (word-sequence (js-array
2256
2580
  (checked-control state "value-set" (runtime-arguments state
2257
2581
  (js-array (word-local argv) (word-local cursor)
2258
- (runtime-call state "root-scope-get-abs" (runtime-arguments state
2582
+ (runtime-call state "rt-root-scope-get-abs" (runtime-arguments state
2259
2583
  (js-array (managed-raw-binary (word-local arg-base) (word-local cursor) "+")))))))
2260
2584
  (managed-guard state (word-set cursor (managed-raw-binary (word-local cursor) (word-constant 1) "+")))))))
2261
2585
  (managed-guard state (word-set result (runtime-call state "value-source-invoke-rooted-with-this" (runtime-arguments state
@@ -2317,15 +2641,13 @@
2317
2641
  (steps (js-array)))
2318
2642
  (js-call steps :push
2319
2643
  (managed-guard state (word-set arg-scope (word-constant 0)))
2320
- (managed-guard state (word-set arg-scope (runtime-call state "root-scope-enter" (runtime-arguments state
2644
+ (managed-guard state (word-set arg-base (runtime-call state "rt-scope-enter" (runtime-arguments state
2321
2645
  (js-array (word-constant count))))))
2322
2646
  (capture-error state)
2323
- (managed-guard state (word-set arg-base (runtime-call state "root-scope-base" (runtime-arguments state (js-array)))))
2324
- (capture-error state))
2647
+ (managed-guard state (word-set arg-scope (word-local arg-base))))
2325
2648
  (let ((slot 0))
2326
2649
  (while (< slot count)
2327
- (js-call steps :push (checked-control state "root-scope-set-abs" (runtime-arguments state
2328
- (js-array (managed-raw-binary (word-local arg-base) (word-constant slot) "+") (js-nth slot values)))))
2650
+ (js-call steps :push (managed-root-set-at state arg-base slot (js-nth slot values)))
2329
2651
  (setq slot (1+ slot))))
2330
2652
  (js-call steps :push (get previous :steps)
2331
2653
  (checked-control state "value-call-restore" (runtime-arguments state
@@ -2339,7 +2661,7 @@
2339
2661
  (runtime-call state "fail" (js-array (word-local (get state :error)))) (word-constant 0))))
2340
2662
  (word-constant 0))
2341
2663
  (word-if (word-compare (word-local arg-scope) (word-constant 0) "/=")
2342
- (runtime-call state "root-scope-exit" (runtime-arguments state (js-array))) (word-constant 0)))
2664
+ (runtime-call state "rt-scope-exit" (runtime-arguments state (js-array))) (word-constant 0)))
2343
2665
  (let ((local (js-nth (get (get previous :result) :value) (get state :locals))))
2344
2666
  (js-call steps :push (managed-root-set state (get local :rootIndex) (word-constant 0))))
2345
2667
  (put call :steps (word-sequence steps)) call))
@@ -2444,15 +2766,13 @@
2444
2766
  (when use-slots
2445
2767
  (js-call steps :push (managed-guard state (word-set arg-scope (word-constant 0))))
2446
2768
  (js-call steps :push
2447
- (managed-guard state (word-set arg-scope (runtime-call state "root-scope-enter" (runtime-arguments state
2769
+ (managed-guard state (word-set arg-base (runtime-call state "rt-scope-enter" (runtime-arguments state
2448
2770
  (js-array (word-constant (js-length values)))))))
2449
2771
  (capture-error state)
2450
- (managed-guard state (word-set arg-base (runtime-call state "root-scope-base" (runtime-arguments state (js-array)))))
2451
- (capture-error state))
2772
+ (managed-guard state (word-set arg-scope (word-local arg-base))))
2452
2773
  (let ((slot 0))
2453
2774
  (while (< slot (js-length values))
2454
- (js-call steps :push (checked-control state "root-scope-set-abs" (runtime-arguments state
2455
- (js-array (managed-raw-binary (word-local arg-base) (word-constant slot) "+") (js-nth slot values)))))
2775
+ (js-call steps :push (managed-root-set-at state arg-base slot (js-nth slot values)))
2456
2776
  (setq slot (1+ slot)))))
2457
2777
  (js-call steps :push (get previous :steps)
2458
2778
  (checked-control state "value-call-restore" (runtime-arguments state (js-array (word-constant 3))))
@@ -2465,7 +2785,7 @@
2465
2785
  (word-constant 0)))
2466
2786
  (when use-slots
2467
2787
  (js-call steps :push (word-if (word-compare (word-local arg-scope) (word-constant 0) "/=")
2468
- (runtime-call state "root-scope-exit" (runtime-arguments state (js-array))) (word-constant 0))))
2788
+ (runtime-call state "rt-scope-exit" (runtime-arguments state (js-array))) (word-constant 0))))
2469
2789
  (when list
2470
2790
  (let ((local (js-nth (get (get list :result) :value) (get state :locals))))
2471
2791
  (js-call steps :push (managed-root-set state (get local :rootIndex) (word-constant 0)))))
@@ -2824,7 +3144,7 @@
2824
3144
  (word-if (word-compare (word-local active) (word-constant 0) "/=")
2825
3145
  (word-sequence (js-array
2826
3146
  (runtime-call state "value-source-iterator-close" (runtime-arguments state (js-array (get iterator :result) (word-local (get state :error)))))
2827
- (word-set (get state :error) (runtime-call state "last-error" (js-array))))) (word-constant 0)))))
3147
+ (word-set (get state :error) (word-node "memory-op" (js-array (word-constant 8)) "load-u32")))) (word-constant 0)))))
2828
3148
  ((= kind "map-binding-pattern")
2829
3149
  (let ((count (get (get node :properties) :entryCount)) (index 0))
2830
3150
  (when (get (get node :properties) :as nil)
@@ -2975,7 +3295,7 @@
2975
3295
  (runtime-arguments state (js-array (word-local (get state :error))))) (word-constant 0) "/=")
2976
3296
  (word-sequence (js-array
2977
3297
  (word-set caught (runtime-call state "value-exception-catch" (runtime-arguments state (js-array (word-local (get state :error))))))
2978
- (word-set (get state :error) (runtime-call state "last-error" (js-array))) (root-local state caught)
3298
+ (word-set (get state :error) (word-node "memory-op" (js-array (word-constant 8)) "load-u32")) (root-local state caught)
2979
3299
  setup binding-steps (get body :steps)
2980
3300
  (managed-guard state (word-set output (get body :result))) (root-local state output)))
2981
3301
  (word-constant 0))))))
@@ -3150,26 +3470,12 @@
3150
3470
  (js-array (get captured :result)))) t)))
3151
3471
  (put result :steps (word-sequence (js-array (get captured :steps) (get result :steps)))) result))))
3152
3472
  (defun lower-managed-access-key (node receiver scope state functions)
3153
- (let ((text (managed-static-method node)))
3154
- (if (and text (<= (js-length text) 20))
3155
- (let* ((arguments (js-array receiver (word-constant (js-length text)))) (index 0)
3156
- (local (new-managed-temporary-local state "literal-property-key"))
3157
- (fallback (lower-managed-key node scope state functions)))
3158
- (while (< index 20)
3159
- (let ((low (if (< index (js-length text)) (string-code-unit-at text index) 0))
3160
- (high (if (< (1+ index) (js-length text)) (string-code-unit-at text (1+ index)) 0)))
3161
- (js-call arguments :push (word-constant (+ low (* high 65536)))))
3162
- (setq index (+ index 2)))
3163
- (js-object :steps (word-sequence (js-array
3164
- (managed-guard state (word-set local (runtime-call state "value-property-literal-key" (runtime-arguments state arguments))))
3165
- (capture-error state)
3166
- (managed-guard state (word-if (word-compare (word-local local) (word-constant 0) "=")
3167
- (word-sequence (js-array (get fallback :steps) (managed-guard state (word-set local (get fallback :result)))))
3168
- (word-constant 0))) (root-local state local))) :result (word-local local)))
3169
- (let* ((operand (snapshot-managed (lower-managed-raw-key node scope state functions) state))
3170
- (result (managed-result state (runtime-call state "value-source-access-key"
3171
- (runtime-arguments state (js-array receiver (get operand :result)))) t)))
3172
- (put result :steps (word-sequence (js-array (get operand :steps) (get result :steps)))) result))))
3473
+ (if (managed-static-method node)
3474
+ (lower-managed-key node scope state functions)
3475
+ (let* ((operand (snapshot-managed (lower-managed-raw-key node scope state functions) state))
3476
+ (result (managed-result state (runtime-call state "value-source-access-key"
3477
+ (runtime-arguments state (js-array receiver (get operand :result)))) t)))
3478
+ (put result :steps (word-sequence (js-array (get operand :steps) (get result :steps)))) result)))
3173
3479
  (defun lower-managed-array (node scope state functions)
3174
3480
  (let ((children (get node :children)) (steps (js-array)) (values (js-array)) (i 0))
3175
3481
  (while (< i (js-length children))
@@ -3184,35 +3490,99 @@
3184
3490
  (put result :steps (word-sequence steps)) result)))
3185
3491
  (defun lower-managed-static-key (property state)
3186
3492
  (lower-managed-literal (js-object :kind "literal" :value (get property :value) :children (js-array)) state))
3493
+ (defun managed-object-capacity (count)
3494
+ (let ((cap 4) (target (if (> count 1024) 1024 count)))
3495
+ (while (< cap target) (setq cap (* cap 2)))
3496
+ cap))
3187
3497
  (defun lower-managed-object (node scope state functions)
3188
3498
  (let* ((properties (get node :children))
3189
- (clone-source (when (= (js-length properties) 0) (get state :managedCloneSource nil)))
3499
+ (prop-count (js-length properties))
3500
+ (clone-source (when (= prop-count 0) (get state :managedCloneSource nil)))
3190
3501
  (result (managed-result state (if clone-source
3191
3502
  (runtime-call state "value-collection-clone-new" (runtime-arguments state (js-array (word-local clone-source))))
3192
- (runtime-call state "value-object-new" (runtime-arguments state (js-array (word-constant 3))))) t))
3193
- (steps (js-array (get result :steps))) (i 0) (prototype-seen nil))
3503
+ (if (or (> prop-count 4) (= prop-count 1) (= prop-count 2))
3504
+ (runtime-call state "value-object-new-capacity"
3505
+ (runtime-arguments state (js-array (word-constant 3)
3506
+ (word-constant (if (<= prop-count 2) 2 (managed-object-capacity prop-count))))))
3507
+ (runtime-call state "value-object-new" (runtime-arguments state (js-array (word-constant 3)))))) t))
3508
+ (steps (js-array (get result :steps))) (i 0) (prototype-seen nil)
3509
+ (all-static-distinct (and (>= prop-count 1) (<= prop-count 1024)))
3510
+ (seen-static (new globalThis.Set)))
3194
3511
  ;; Validate property shapes before lowering any child or reading its IR.
3195
3512
  (while (< i (js-length properties))
3196
- (let ((property (js-nth i properties)))
3513
+ (let* ((property (js-nth i properties))
3514
+ (props (get property :properties))
3515
+ (computed (get props :computed))
3516
+ (key-name (get property :value)))
3197
3517
  (unless (and (= (get property :kind) "object-property") (get property :children)
3198
- (= (js-length (get property :children)) (if (get (get property :properties) :computed) 2 1)))
3199
- (managed-fail property "invalid managed object property"))) (setq i (1+ i)))
3518
+ (= (js-length (get property :children)) (if computed 2 1)))
3519
+ (managed-fail property "invalid managed object property"))
3520
+ (when all-static-distinct
3521
+ (if (or computed (not (= (value-type key-name) "string")) (= key-name "__proto__") (js-call seen-static :has key-name))
3522
+ (setq all-static-distinct false)
3523
+ (js-call seen-static :add key-name))))
3524
+ (setq i (1+ i)))
3200
3525
  (setq i 0)
3201
- (while (< i (js-length properties))
3202
- (let* ((property (js-nth i properties)) (children (get property :children))
3203
- (computed (get (get property :properties) :computed))
3204
- (prototype (and (not computed) (= (get property :value) "__proto__")))
3205
- (key (snapshot-managed (if computed
3206
- (lower-managed-key (js-nth 0 children) scope state functions)
3207
- (lower-managed-static-key property state)) state))
3208
- (value (snapshot-managed (lower-managed-expression (js-nth (if computed 1 0) children) scope state functions) state)))
3209
- (when prototype
3210
- (when prototype-seen (managed-fail property "duplicate object prototype setter")) (setq prototype-seen t))
3211
- (js-call steps :push (get key :steps)
3212
- (checked-control state "value-property-key-check" (runtime-arguments state (js-array (get result :result) (get key :result))))
3213
- (get value :steps) (checked-control state "value-object-put" (runtime-arguments state
3214
- (js-array (get result :result) (get key :result) (get value :result) (word-constant (if prototype 1 2)))))))
3215
- (setq i (1+ i))) (put result :steps (word-sequence steps)) result))
3526
+ (if all-static-distinct
3527
+ (let ((static-keys (js-array)) (static-vals (js-array)))
3528
+ (while (< i prop-count)
3529
+ (let* ((property (js-nth i properties))
3530
+ (children (get property :children))
3531
+ (key (snapshot-managed (lower-managed-static-key property state) state))
3532
+ (value (snapshot-managed (lower-managed-expression (js-nth 0 children) scope state functions) state)))
3533
+ (js-call steps :push (get key :steps) (get value :steps))
3534
+ (js-call static-keys :push (get key :result))
3535
+ (js-call static-vals :push (get value :result)))
3536
+ (setq i (1+ i)))
3537
+ (setq i 0)
3538
+ (while (< i prop-count)
3539
+ (let ((rem (- prop-count i)))
3540
+ (cond
3541
+ ((>= rem 4)
3542
+ (js-call steps :push (checked-control state "value-object-init-4" (runtime-arguments state
3543
+ (js-array (get result :result)
3544
+ (js-nth i static-keys) (js-nth i static-vals)
3545
+ (js-nth (+ i 1) static-keys) (js-nth (+ i 1) static-vals)
3546
+ (js-nth (+ i 2) static-keys) (js-nth (+ i 2) static-vals)
3547
+ (js-nth (+ i 3) static-keys) (js-nth (+ i 3) static-vals)))))
3548
+ (setq i (+ i 4)))
3549
+ ((= rem 3)
3550
+ (js-call steps :push (checked-control state "value-object-init-3" (runtime-arguments state
3551
+ (js-array (get result :result)
3552
+ (js-nth i static-keys) (js-nth i static-vals)
3553
+ (js-nth (+ i 1) static-keys) (js-nth (+ i 1) static-vals)
3554
+ (js-nth (+ i 2) static-keys) (js-nth (+ i 2) static-vals)))))
3555
+ (setq i (+ i 3)))
3556
+ ((= rem 2)
3557
+ (js-call steps :push (checked-control state "value-object-init-2" (runtime-arguments state
3558
+ (js-array (get result :result)
3559
+ (js-nth i static-keys) (js-nth i static-vals)
3560
+ (js-nth (+ i 1) static-keys) (js-nth (+ i 1) static-vals)))))
3561
+ (setq i (+ i 2)))
3562
+ (t
3563
+ (js-call steps :push (checked-control state "value-object-init-static" (runtime-arguments state
3564
+ (js-array (get result :result)
3565
+ (js-nth i static-keys) (js-nth i static-vals)))))
3566
+ (setq i (+ i 1)))))))
3567
+ (while (< i (js-length properties))
3568
+ (let* ((property (js-nth i properties)) (children (get property :children))
3569
+ (computed (get (get property :properties) :computed))
3570
+ (prototype (and (not computed) (= (get property :value) "__proto__")))
3571
+ (key (snapshot-managed (if computed
3572
+ (lower-managed-key (js-nth 0 children) scope state functions)
3573
+ (lower-managed-static-key property state)) state))
3574
+ (value (snapshot-managed (lower-managed-expression (js-nth (if computed 1 0) children) scope state functions) state)))
3575
+ (when prototype
3576
+ (when prototype-seen (managed-fail property "duplicate object prototype setter")) (setq prototype-seen t))
3577
+ (js-call steps :push (get key :steps))
3578
+ (when (or computed prototype)
3579
+ (js-call steps :push
3580
+ (checked-control state "value-property-key-check" (runtime-arguments state (js-array (get result :result) (get key :result))))))
3581
+ (js-call steps :push (get value :steps)
3582
+ (checked-control state "value-object-put" (runtime-arguments state
3583
+ (js-array (get result :result) (get key :result) (get value :result) (word-constant (if prototype 1 2)))))))
3584
+ (setq i (1+ i))))
3585
+ (put result :steps (word-sequence steps)) result))
3216
3586
  (defun lower-managed-object-operation (node scope state functions)
3217
3587
  (let* ((children (get node :children)) (operation (get node :value)) (count (js-length children))
3218
3588
  (assoc (= operation "object-assoc")) (keys (= operation "object-keys")))
@@ -4177,7 +4547,98 @@
4177
4547
  (while (and (not found) (< index (js-length children)))
4178
4548
  (setq found (managed-host-capability-node (js-nth index children))) (setq index (1+ index))) found)))
4179
4549
  (defun managed-host-capabilities (functions)
4180
- (prepare-host-capabilities (js-object :abi "memory-u32" :functions functions)))
4550
+ (prepare-host-capabilities (mark-trusted-runtime-program (js-object :abi "memory-u32" :functions functions))))
4551
+ (defun has-managed-local-p (scope state name)
4552
+ (or (find-local scope name)
4553
+ (find-local (get state :captures) name)
4554
+ (and (get state :outerState nil)
4555
+ (has-managed-local-p (get state :outerScope) (get state :outerState) name))))
4556
+ (defun managed-outer-local-ref-p (node idx scope state)
4557
+ (and node (= (get node :kind) "reference")
4558
+ (= (js-length (get node :children)) 0)
4559
+ (= (value-type (get node :value)) "string")
4560
+ (not (= (managed-binding-key (get node :value)) (managed-binding-key idx)))
4561
+ (has-managed-local-p scope state (get node :value))))
4562
+ (defun managed-param-ref-p (node idx)
4563
+ (and node (= (get node :kind) "reference")
4564
+ (= (js-length (get node :children)) 0)
4565
+ (= (value-type (get node :value)) "string")
4566
+ (= (managed-binding-key (get node :value)) (managed-binding-key idx))))
4567
+ (defun managed-same-ref-p (left right)
4568
+ (and left right (= (get left :kind) "reference") (= (get right :kind) "reference")
4569
+ (= (managed-binding-key (get left :value)) (managed-binding-key (get right :value)))))
4570
+ (defun match-managed-array-build-copy (builder scope state)
4571
+ (let ((props (when builder (get builder :properties))))
4572
+ (when (and builder (= (get builder :kind) "function-expression")
4573
+ props (not (get props :async nil)) (= (get props :parameterCount nil) 1)
4574
+ (= (js-length (get builder :children)) 2))
4575
+ (let* ((param (js-nth 0 (get builder :children)))
4576
+ (pprops (when param (get param :properties)))
4577
+ (body (js-nth 1 (get builder :children))))
4578
+ (when (and param (= (get param :kind) "parameter-binding")
4579
+ pprops (= (get pprops :parameterKind nil) "required")
4580
+ (= (value-type (get param :value)) "string")
4581
+ body)
4582
+ (let ((idx (get param :value))
4583
+ (bkind (get body :kind))
4584
+ (bval (get body :value))
4585
+ (bch (get body :children)))
4586
+ (cond
4587
+ ;; Prefix copy: (get source index)
4588
+ ((and (= bkind "property-read") (= bval "get") (= (js-length bch) 2)
4589
+ (managed-outer-local-ref-p (js-nth 0 bch) idx scope state)
4590
+ (managed-param-ref-p (js-nth 1 bch) idx))
4591
+ (js-object :op "value-array-copy-prefix" :source (js-nth 0 bch)))
4592
+ ;; Remove element at W: (get source (if (>= index W) (1+ index) index))
4593
+ ;; or (get source (if (< index W) index (1+ index)))
4594
+ ((and (= bkind "property-read") (= bval "get") (= (js-length bch) 2)
4595
+ (managed-outer-local-ref-p (js-nth 0 bch) idx scope state)
4596
+ (let ((sel (js-nth 1 bch)))
4597
+ (and sel (= (get sel :kind) "conditional") (= (get sel :value) "if")
4598
+ (= (js-length (get sel :children)) 3))))
4599
+ (let* ((sel (js-nth 1 bch)) (sch (get sel :children))
4600
+ (cnd (js-nth 0 sch)) (thn (js-nth 1 sch)) (els (js-nth 2 sch)))
4601
+ (when (and cnd (= (get cnd :kind) "intrinsic") (= (js-length (get cnd :children)) 2)
4602
+ (managed-param-ref-p (js-nth 0 (get cnd :children)) idx)
4603
+ (managed-outer-local-ref-p (js-nth 1 (get cnd :children)) idx scope state))
4604
+ (cond
4605
+ ((and (= (get cnd :value) ">=")
4606
+ thn (= (get thn :kind) "intrinsic") (= (get thn :value) "1+")
4607
+ (= (js-length (get thn :children)) 1) (managed-param-ref-p (js-nth 0 (get thn :children)) idx)
4608
+ (managed-param-ref-p els idx))
4609
+ (js-object :op "value-array-copy-remove" :source (js-nth 0 bch) :index (js-nth 1 (get cnd :children))))
4610
+ ((and (= (get cnd :value) "<")
4611
+ (managed-param-ref-p thn idx)
4612
+ els (= (get els :kind) "intrinsic") (= (get els :value) "1+")
4613
+ (= (js-length (get els :children)) 1) (managed-param-ref-p (js-nth 0 (get els :children)) idx))
4614
+ (js-object :op "value-array-copy-remove" :source (js-nth 0 bch) :index (js-nth 1 (get cnd :children))))))))
4615
+ ;; Insert V at W: (if (= index W) V (get S (if (< index W) index (1- index))))
4616
+ ((and (= bkind "conditional") (= bval "if") (= (js-length bch) 3))
4617
+ (let ((cnd (js-nth 0 bch)) (thn (js-nth 1 bch)) (els (js-nth 2 bch)))
4618
+ (when (and cnd (= (get cnd :kind) "intrinsic") (= (get cnd :value) "=")
4619
+ (= (js-length (get cnd :children)) 2)
4620
+ (managed-param-ref-p (js-nth 0 (get cnd :children)) idx)
4621
+ (managed-outer-local-ref-p (js-nth 1 (get cnd :children)) idx scope state)
4622
+ (managed-outer-local-ref-p thn idx scope state)
4623
+ els (= (get els :kind) "property-read") (= (get els :value) "get")
4624
+ (= (js-length (get els :children)) 2)
4625
+ (managed-outer-local-ref-p (js-nth 0 (get els :children)) idx scope state))
4626
+ (let* ((wref (js-nth 1 (get cnd :children)))
4627
+ (sel (js-nth 1 (get els :children)))
4628
+ (sch (when sel (get sel :children))))
4629
+ (when (and sel (= (get sel :kind) "conditional") (= (get sel :value) "if")
4630
+ (= (js-length sch) 3)
4631
+ (let ((c2 (js-nth 0 sch)) (t2 (js-nth 1 sch)) (e2 (js-nth 2 sch)))
4632
+ (and c2 (= (get c2 :kind) "intrinsic") (= (get c2 :value) "<")
4633
+ (= (js-length (get c2 :children)) 2)
4634
+ (managed-param-ref-p (js-nth 0 (get c2 :children)) idx)
4635
+ (managed-same-ref-p (js-nth 1 (get c2 :children)) wref)
4636
+ (managed-param-ref-p t2 idx)
4637
+ e2 (= (get e2 :kind) "intrinsic") (= (get e2 :value) "1-")
4638
+ (= (js-length (get e2 :children)) 1)
4639
+ (managed-param-ref-p (js-nth 0 (get e2 :children)) idx))))
4640
+ (js-object :op "value-array-copy-insert" :source (js-nth 0 (get els :children))
4641
+ :index wref :replacement thn)))))))))))))
4181
4642
  (defun lower-managed-expression (node scope state functions)
4182
4643
  (let* ((lowered (lower-managed-expression-dispatch node scope state functions)) (span (get node :span nil)))
4183
4644
  (if (nil? span) lowered
@@ -4272,11 +4733,29 @@
4272
4733
  (put result :steps (word-sequence (js-array (get owner :steps) (get argument :steps) (get result :steps)))) result)))
4273
4734
  ((and (= kind "intrinsic") (= value "__eliscript_array_build"))
4274
4735
  (unless (= (js-length children) 2) (managed-fail node "invalid private array builder arity"))
4275
- (let* ((count (snapshot-managed (lower-managed-expression (js-nth 0 children) scope state functions) state))
4276
- (builder (snapshot-managed (lower-managed-expression (js-nth 1 children) scope state functions) state))
4277
- (result (managed-result state (runtime-call state "value-array-build"
4278
- (runtime-arguments state (js-array (get count :result) (get builder :result)))) t)))
4279
- (put result :steps (word-sequence (js-array (get count :steps) (get builder :steps) (get result :steps)))) result))
4736
+ (let ((fast (match-managed-array-build-copy (js-nth 1 children) scope state)))
4737
+ (if fast
4738
+ (let* ((count (snapshot-managed (lower-managed-expression (js-nth 0 children) scope state functions) state))
4739
+ (source (snapshot-managed (lower-managed-expression (get fast :source) scope state functions) state))
4740
+ (steps (js-array (get count :steps) (get source :steps)))
4741
+ (args (js-array (get count :result) (get source :result))))
4742
+ (when (get fast :index nil)
4743
+ (let ((idx (snapshot-managed (lower-managed-expression (get fast :index) scope state functions) state)))
4744
+ (js-call steps :push (get idx :steps))
4745
+ (js-call args :push (get idx :result))))
4746
+ (when (get fast :replacement nil)
4747
+ (let ((rep (snapshot-managed (lower-managed-expression (get fast :replacement) scope state functions) state)))
4748
+ (js-call steps :push (get rep :steps))
4749
+ (js-call args :push (get rep :result))))
4750
+ (let ((result (managed-result state (runtime-call state (get fast :op) (runtime-arguments state args)) t)))
4751
+ (js-call steps :push (get result :steps))
4752
+ (put result :steps (word-sequence steps))
4753
+ result))
4754
+ (let* ((count (snapshot-managed (lower-managed-expression (js-nth 0 children) scope state functions) state))
4755
+ (builder (snapshot-managed (lower-managed-expression (js-nth 1 children) scope state functions) state))
4756
+ (result (managed-result state (runtime-call state "value-array-build"
4757
+ (runtime-arguments state (js-array (get count :result) (get builder :result)))) t)))
4758
+ (put result :steps (word-sequence (js-array (get count :steps) (get builder :steps) (get result :steps)))) result))))
4280
4759
  ((and (= kind "intrinsic") (= value "__eliscript_array_copy_assoc"))
4281
4760
  (unless (= (js-length children) 4) (managed-fail node "invalid private array copy arity"))
4282
4761
  (let* ((count (snapshot-managed (lower-managed-expression (js-nth 0 children) scope state functions) state))
@@ -4348,7 +4827,7 @@
4348
4827
  (runtime-arguments state (js-array (word-local (get state :error))))) (word-constant 1) "=")
4349
4828
  (word-sequence (js-array
4350
4829
  (runtime-call state "value-exception-clear" (runtime-arguments state (js-array)))
4351
- (word-set (get state :error) (runtime-call state "last-error" (js-array)))
4830
+ (word-set (get state :error) (word-node "memory-op" (js-array (word-constant 8)) "load-u32"))
4352
4831
  (word-set local (word-constant 0)) (root-local state local)))
4353
4832
  (word-constant 0)) (word-constant 0)) (word-constant 0))))) result))
4354
4833
  ((and (= kind "intrinsic") (= value "__eliscript_arity_error"))
@@ -5171,29 +5650,44 @@
5171
5650
  ;; dynamic Object.getPrototypeOf Get and all abrupt effects.
5172
5651
  (put normalized :steps (word-sequence (js-array (get original :steps) (get normalized :steps)))) normalized)
5173
5652
  raw-body)))
5174
- (captures (get state :captures)) (result (new-managed-local state "result" nil)) (steps (js-array)))
5175
- (js-call steps :push (runtime-call state "begin-operation" (js-array))
5176
- (runtime-call state "heap-check" (runtime-arguments state (js-array))) (capture-error state))
5177
- ;; Retain only the existing initializer/prototype table codes in the
5178
- ;; heap header. No callable, prototype or native member is allocated
5179
- ;; until an actual missing native Array property is observed.
5180
- (js-call steps :push (lower-managed-array-initializer-registration state))
5181
- (when (get state :module nil)
5182
- (js-call steps :push (checked-control state "value-module-check" (runtime-arguments state (js-array)))))
5653
+ (captures (get state :captures)) (result (new-managed-local state "result" nil)) (steps (js-array))
5654
+ (internal-fast
5655
+ (and (not (get function :isExported nil))
5656
+ (not (get function :initializer nil))
5657
+ (not (get function :realmInitializer nil))
5658
+ (not (get function :descriptionInitializer nil))
5659
+ (nil? (get function :nativeInitializer nil))
5660
+ (nil? (get function :builtin nil))
5661
+ (not (get function :boundMethod nil))
5662
+ (not (get function :literalBrandProbe nil))
5663
+ (or (not uniform)
5664
+ (= (get function :parameterSource nil) "slots")
5665
+ (get function :slotDispatch nil)
5666
+ (get function :lambda nil)))))
5667
+ (unless internal-fast
5668
+ (js-call steps :push (runtime-call state "begin-operation" (js-array))
5669
+ (runtime-call state "heap-check" (runtime-arguments state (js-array))) (capture-error state))
5670
+ ;; Retain only the existing initializer/prototype table codes in the
5671
+ ;; heap header. No callable, prototype or native member is allocated
5672
+ ;; until an actual missing native Array property is observed.
5673
+ (js-call steps :push (lower-managed-array-initializer-registration state))
5674
+ (when (get state :module nil)
5675
+ (js-call steps :push (checked-control state "value-module-check" (runtime-arguments state (js-array))))))
5183
5676
  (when uniform
5184
- (js-call steps :push (checked-control state "heap-reference-check" (runtime-arguments state (js-array (word-local (get state :function))))))
5185
- (unless (= (get state :parameterSource nil) "slots")
5186
- (js-call steps :push
5187
- (checked-control state "heap-reference-check" (runtime-arguments state (js-array (word-local (get state :arguments)))))
5188
- (checked-control state "value-call-arguments-check" (runtime-arguments state
5189
- (js-array (word-local (get state :arguments)) (word-local (get state :count)))))))
5677
+ (unless internal-fast
5678
+ (js-call steps :push (checked-control state "heap-reference-check" (runtime-arguments state (js-array (word-local (get state :function))))))
5679
+ (unless (= (get state :parameterSource nil) "slots")
5680
+ (js-call steps :push
5681
+ (checked-control state "heap-reference-check" (runtime-arguments state (js-array (word-local (get state :arguments)))))
5682
+ (checked-control state "value-call-arguments-check" (runtime-arguments state
5683
+ (js-array (word-local (get state :arguments)) (word-local (get state :count))))))))
5190
5684
  (setq index 0)
5191
5685
  (while (< index arity)
5192
5686
  (unless (= (js-nth index kinds) "rest")
5193
5687
  (js-call steps :push (managed-guard state (word-set (js-nth index scope)
5194
5688
  (word-if (word-compare (word-local (get state :count)) (word-constant index) ">")
5195
5689
  (if (= (get state :parameterSource nil) "slots")
5196
- (runtime-call state "root-scope-get-abs" (runtime-arguments state
5690
+ (runtime-call state "rt-root-scope-get-abs" (runtime-arguments state
5197
5691
  (js-array (managed-raw-binary (word-local (get state :arguments)) (word-constant index) "+"))))
5198
5692
  (runtime-call state "value-get" (runtime-arguments state (js-array (word-local (get state :arguments)) (word-constant index)))))
5199
5693
  (word-constant 3)))) (capture-error state))
@@ -5202,28 +5696,27 @@
5202
5696
  (word-compare (word-local (js-nth index scope)) (word-constant 3) "=")
5203
5697
  (word-set (js-nth index scope) (word-constant 0)) (word-constant 0))))))
5204
5698
  (setq index (1+ index))))
5205
- (setq index 0)
5206
- (while (< index arity)
5207
- (js-call steps :push (checked-control state "heap-reference-check" (runtime-arguments state (js-array (word-local (js-nth index scope))))))
5208
- (setq index (1+ index)))
5209
- (js-call steps :push (checked-control state "value-exception-class-set" (runtime-arguments state (js-array (word-constant 0)))))
5699
+ (unless internal-fast
5700
+ (setq index 0)
5701
+ (while (< index arity)
5702
+ (js-call steps :push (checked-control state "heap-reference-check" (runtime-arguments state (js-array (word-local (js-nth index scope))))))
5703
+ (setq index (1+ index)))
5704
+ (js-call steps :push (checked-control state "value-exception-class-set" (runtime-arguments state (js-array (word-constant 0))))))
5210
5705
  (let ((reader (and (not patterns) (not function-recur) (not uniform) (managed-direct-reader children arity scope state)))
5211
5706
  (query (and (not patterns) (not function-recur) (not uniform) (managed-direct-collection-query children arity scope state))))
5212
5707
  (if reader
5213
5708
  (js-call steps :push (managed-guard state (word-set result reader)) (capture-error state))
5214
5709
  (let ((frame-steps (js-array)))
5215
- (when (managed-private-roots-p state)
5216
- (js-call frame-steps :push (word-set (get state :functionBase) (word-constant 0))))
5217
- (js-call frame-steps :push
5218
- (managed-guard state (word-set (get state :frame)
5219
- (if (managed-private-roots-p state)
5220
- (runtime-call state "root-scope-enter" (runtime-arguments state (js-array (word-constant (get state :roots)))))
5221
- (runtime-call state "frame-new" (runtime-arguments state (js-array (word-constant (get state :roots))))))))
5222
- (capture-error state))
5223
- (when (managed-private-roots-p state)
5710
+ (if (managed-private-roots-p state)
5224
5711
  (js-call frame-steps :push
5712
+ (word-set (get state :functionBase) (word-constant 0))
5225
5713
  (managed-guard state (word-set (get state :functionBase)
5226
- (runtime-call state "root-scope-base" (runtime-arguments state (js-array)))))
5714
+ (runtime-call state "rt-scope-enter" (runtime-arguments state (js-array (word-constant (get state :roots)))))))
5715
+ (capture-error state)
5716
+ (managed-guard state (word-set (get state :frame) (word-local (get state :functionBase)))))
5717
+ (js-call frame-steps :push
5718
+ (managed-guard state (word-set (get state :frame)
5719
+ (runtime-call state "frame-new" (runtime-arguments state (js-array (word-constant (get state :roots)))))))
5227
5720
  (capture-error state)))
5228
5721
  (when uniform
5229
5722
  (js-call frame-steps :push (root-local state (get state :function)))
@@ -5295,7 +5788,7 @@
5295
5788
  (js-call frame-steps :push
5296
5789
  (word-if (word-compare (word-local (get state :frame)) (word-constant 0) "/=")
5297
5790
  (if (managed-private-roots-p state)
5298
- (runtime-call state "root-scope-exit" (runtime-arguments state (js-array)))
5791
+ (runtime-call state "rt-scope-exit" (runtime-arguments state (js-array)))
5299
5792
  (runtime-call state "frame-pop" (runtime-arguments state (js-array (word-local (get state :frame))))))
5300
5793
  (word-constant 0)))
5301
5794
  (js-call steps :push
@@ -5605,6 +6098,28 @@
5605
6098
  (runtime-call state "fail-v64" (js-array (word-local error))))) nil))))
5606
6099
  (put result :parameterTypes (js-array "u32" "u32" "v64" "v64" "u32"))
5607
6100
  (put result :resultType "v64") result)))
6101
+ (defun managed-module-code-batch-invoker (index runtime function-count functions)
6102
+ (let* ((function (managed-module-wrapper "__eliscript_module_invoke_batch" index runtime 7))
6103
+ (state (get function :state)) (arguments (get function :arguments))
6104
+ (error (new-managed-local state "error" nil))
6105
+ (code (word-local (js-nth 0 arguments))))
6106
+ (put state :error error) (put state :functions functions)
6107
+ (put (js-nth 1 arguments) :type "v64") (put (js-nth 2 arguments) :type "v64")
6108
+ (put (js-nth 3 arguments) :type "v64") (put (js-nth 4 arguments) :type "v64")
6109
+ (put (js-nth 5 arguments) :type "v64")
6110
+ (let ((result (managed-finish-wrapper function (word-node "sequence" (js-array
6111
+ (runtime-call state "begin-operation" (js-array))
6112
+ (checked-control state "value-module-check" (runtime-arguments state (js-array)))
6113
+ (lower-managed-array-initializer-registration state)
6114
+ (word-if (word-compare (word-local error) (word-constant 0) "=")
6115
+ (word-if (word-compare code (word-constant function-count) "<")
6116
+ (runtime-call state "heap-host-call-code-invoke" (runtime-arguments state
6117
+ (js-array code (word-local (js-nth 1 arguments)) (word-local (js-nth 2 arguments))
6118
+ (word-local (js-nth 3 arguments)) (word-local (js-nth 4 arguments)) (word-local (js-nth 5 arguments)))))
6119
+ (runtime-call state "fail-v64" (js-array (word-constant 3))))
6120
+ (runtime-call state "fail-v64" (js-array (word-local error))))) nil))))
6121
+ (put result :parameterTypes (js-array "u32" "u32" "v64" "v64" "v64" "v64" "v64"))
6122
+ (put result :resultType "v64") result)))
5608
6123
  (defun managed-module-binding-wrapper (index runtime)
5609
6124
  (let* ((function (managed-module-wrapper (str "__eliscript_binding_" index) index runtime 4))
5610
6125
  (state (get function :state)) (arguments (get function :arguments))
@@ -5868,11 +6383,11 @@
5868
6383
  (and b (Object/hasOwn a "value") (Object/hasOwn b "value")
5869
6384
  (managed-protocol-ir-equal (get a :value) (get b :value)))))))))))
5870
6385
  (defun managed-canonical-protocol-program-p (id program options)
5871
- (when (or (= id "stdlib/core/protocol.mjs") (= id "stdlib/core/protocol-impl.mjs"))
6386
+ (when (or (= id "runtime/core/protocol-impl.mjs") (= id "stdlib/protocol-impl.mjs"))
5872
6387
  (let ((provided (get (or options (js-object)) :literalModules nil)))
5873
6388
  (and (Array/isArray provided)
5874
6389
  (js-call provided :some (lambda (item)
5875
- (and (= (get item :id) "stdlib/core/protocol.mjs")
6390
+ (and (= (get item :id) "runtime/core/protocol-impl.mjs")
5876
6391
  (managed-protocol-ir-equal program (get item :program)))))))))
5877
6392
  (defun managed-string-hash-shape (value)
5878
6393
  ;; Only source locations are irrelevant. Keep every other IR field,
@@ -5918,7 +6433,7 @@
5918
6433
  (defun managed-canonical-string-hash-p (id program context)
5919
6434
  (let ((canonical-id (if (and context (js-call id :startsWith (get context :prefix)))
5920
6435
  (js-call id :slice (js-length (get context :prefix))) id)))
5921
- (when (= canonical-id "stdlib/managed-value-state.mjs")
6436
+ (when (= canonical-id "runtime/managed/managed-value-state.mjs")
5922
6437
  (let* ((expected (managed-string-hash-expected))
5923
6438
  (definitions (new globalThis.Map)) (valid t)
5924
6439
  (declarations (collect-managed-declarations (get program :body) (js-array))))
@@ -5987,7 +6502,7 @@
5987
6502
  ;; This exact helper belongs to the supplied canonical protocol source.
5988
6503
  ;; The bridge normalizes only its private registry key; ordinary source
5989
6504
  ;; reflection and the foreign object's identity remain untouched.
5990
- (when (= id "stdlib/core/protocol.mjs")
6505
+ (when (= id "runtime/core/protocol-impl.mjs")
5991
6506
  (let ((copy (managed-protocol-private-declaration
5992
6507
  (if output (Object/assign (js-object) node (js-object :children output)) node))))
5993
6508
  (unless (eq copy node) (setq node copy output (get copy :children)))))
@@ -6090,7 +6605,7 @@
6090
6605
  (defun managed-literal-context (modules options)
6091
6606
  (when (js-call modules :some (lambda (item) (managed-literal-program-required (get item :program) (get item :id))))
6092
6607
  (let* ((provided (get (or options (js-object)) :literalModules nil)) (ids (new globalThis.Set))
6093
- (by-id (new globalThis.Map)) (selected (new globalThis.Set)) (pending (js-array "stdlib/managed-literals.mjs"))
6608
+ (by-id (new globalThis.Map)) (selected (new globalThis.Set)) (pending (js-array "runtime/managed/managed-literals.mjs"))
6094
6609
  (aliases (new globalThis.Set))
6095
6610
  (_aliases (progn (managed-literal-json-aliases modules aliases)
6096
6611
  (managed-literal-json-aliases provided aliases)))
@@ -6101,7 +6616,7 @@
6101
6616
  (unless (and item (managed-link-id-p (get item :id)) (get item :program) (not (js-call ids :has (get item :id))))
6102
6617
  (managed-fail nil "invalid persistent literal module graph"))
6103
6618
  (js-call ids :add (get item :id)) (js-call by-id :set (get item :id) item)))
6104
- (unless (js-call ids :has "stdlib/managed-literals.mjs") (managed-fail nil "persistent literal adapter module is missing"))
6619
+ (unless (js-call ids :has "runtime/managed/managed-literals.mjs") (managed-fail nil "persistent literal adapter module is missing"))
6105
6620
  ;; Generated aliases pass the same binding-name contract as user IR.
6106
6621
  ;; Keep the reserved __eliscript_ namespace closed, and avoid lexical
6107
6622
  ;; names whose normalized JS spelling would shadow the private alias.
@@ -6125,7 +6640,7 @@
6125
6640
  (setq salt (1+ salt)) (setq alias (str "$eliscript_persistent_" salt)) (setq prefix (str alias "/")))
6126
6641
  (js-object :alias alias :prefix prefix :provided ids
6127
6642
  :modules (js-call provided :filter (lambda (item) (js-call selected :has (get item :id))))
6128
- :adapter (str prefix "stdlib/managed-literals.mjs")))))
6643
+ :adapter (str prefix "runtime/managed/managed-literals.mjs")))))
6129
6644
  (defun managed-literal-user-import (node id context)
6130
6645
  (if (= (get node :kind) "module-declaration")
6131
6646
  (let* ((children (get node :children)) (output nil) (index 0))
@@ -6238,7 +6753,7 @@
6238
6753
  (setq program (js-call globalThis.Object :assign (js-object) program
6239
6754
  (js-object :body (js-call (get program :body) :map (lambda (node)
6240
6755
  (managed-annotate-function-names node nil (get program :managedPortableDeclaration nil)))))))
6241
- (let* ((runtime (lower-memory-program runtime-program)) (runtime-functions (get runtime :functions))
6756
+ (let* ((runtime (cached-lower-memory-program runtime-program)) (runtime-functions (get runtime :functions))
6242
6757
  (declarations (collect-managed-declarations (get program :body) (js-array)))
6243
6758
  (functions (js-array)) (exports (js-array)) (globals (js-array)) (initializers (js-array))
6244
6759
  (names (new globalThis.Set)) (positions (new globalThis.Map)) (module (or module-mode nil))
@@ -6392,6 +6907,12 @@
6392
6907
  (js-call functions :push dispatch)
6393
6908
  (put functions :slotDispatch dispatch)))
6394
6909
  (setq index 0)
6910
+ (while (< index (js-length exports))
6911
+ (let* ((exp (js-nth index exports))
6912
+ (exp-fn (find-function functions (get exp :value))))
6913
+ (when exp-fn (put exp-fn :isExported t)))
6914
+ (setq index (1+ index)))
6915
+ (setq index 0)
6395
6916
  (while (< index (js-length functions))
6396
6917
  (let ((function (js-nth index functions)))
6397
6918
  (unless (or (get function :descriptionInitializer nil) (get function :slotDispatch nil)
@@ -6450,6 +6971,7 @@
6450
6971
  (js-call combined :push (managed-module-initializer (js-length combined) runtime-functions globals initializer))
6451
6972
  (js-call combined :push (managed-module-getter (js-length combined) runtime-functions function-count functions))
6452
6973
  (js-call combined :push (managed-module-code-invoker (js-length combined) runtime-functions function-count functions))
6974
+ (js-call combined :push (managed-module-code-batch-invoker (js-length combined) runtime-functions function-count functions))
6453
6975
  (js-call combined :push (managed-module-runtime-wrapper "__eliscript_module_status" (js-length combined) runtime-functions "value-module-status" 1))
6454
6976
  (js-call combined :push (managed-module-runtime-wrapper "__eliscript_module_close" (js-length combined) runtime-functions "value-module-close" 1))
6455
6977
  (js-call combined :push (managed-module-runtime-wrapper "__eliscript_module_abort" (js-length combined) runtime-functions "value-module-abort" 2))
@@ -6461,7 +6983,7 @@
6461
6983
  (let ((step (js-nth position steps)))
6462
6984
  (js-call combined :push (managed-project-step-wrapper (js-length combined) runtime-functions project step))
6463
6985
  (js-call bindings :push (get step :run))) (setq position (1+ position)))))
6464
- (append-managed bindings (js-array "__eliscript_module_init" "__eliscript_module_get" "__eliscript_module_invoke" "__eliscript_module_status"
6986
+ (append-managed bindings (js-array "__eliscript_module_init" "__eliscript_module_get" "__eliscript_module_invoke" "__eliscript_module_invoke_batch" "__eliscript_module_status"
6465
6987
  "__eliscript_module_close" "__eliscript_module_abort"))
6466
6988
  (setq index 0)
6467
6989
  (while (< index (js-length bindings))
@@ -6482,7 +7004,7 @@
6482
7004
  :parameterTypes (get description-initializer :parameterTypes) :resultType (get description-initializer :resultType)
6483
7005
  :locals (get description-initializer :locals)
6484
7006
  :body (get description-initializer :body))))
6485
- (let ((callable module) (table (get runtime :table nil)))
7007
+ (let ((callable module) (table (get runtime :table nil)) (cached-caps nil))
6486
7008
  (setq index 0)
6487
7009
  (while (< index (js-length functions))
6488
7010
  (when (get (js-nth index functions) :callable nil) (setq callable t)) (setq index (1+ index)))
@@ -6502,9 +7024,10 @@
6502
7024
  ;; Determine this before replacing either original no-op stub.
6503
7025
  ;; The control ABI accepts owned managed handles, not foreign JS
6504
7026
  ;; values. Only a module boundary exposes source-level host values.
6505
- (let ((external (or (and module await-host-capability)
6506
- (and host-modules (> (js-length host-modules) 0))
6507
- (> (js-length (managed-host-capabilities combined)) 0))))
7027
+ (let* ((base-external (or (and module await-host-capability)
7028
+ (and host-modules (> (js-length host-modules) 0))))
7029
+ (_caps (unless base-external (setq cached-caps (managed-host-capabilities combined))))
7030
+ (external (or base-external (> (js-length cached-caps) 0))))
6508
7031
  (when (or external (eq foreign-entry t))
6509
7032
  (let* ((stub (find-function combined "host-source-operation"))
6510
7033
  (locals (get stub :locals)))
@@ -6520,7 +7043,11 @@
6520
7043
  (let* ((stub (find-function combined "host-project-binding-changed")) (locals (get stub :locals)))
6521
7044
  (put stub :body (word-node "call" (js-array (word-local (js-nth 0 locals))
6522
7045
  (word-local (js-nth 1 locals)) (word-local (js-nth 2 locals)))
6523
- (get (find-function combined "value-project-binding-notify") :index))))))
7046
+ (get (find-function combined "value-project-binding-notify") :index)))))
7047
+ (when (or external (eq foreign-entry t))
7048
+ (setq cached-caps nil)))
7049
+ (unless cached-caps
7050
+ (setq cached-caps (managed-host-capabilities combined)))
6524
7051
  ;; All source bindings, captures and ABI wrappers are complete now.
6525
7052
  ;; Compact only freshly generated managed functions, retaining the
6526
7053
  ;; independent memory runtime prefix and its original local entries.
@@ -6590,8 +7117,8 @@
6590
7117
  :modules (js-call (get project :modules) :map (lambda (record)
6591
7118
  (js-object :id (get record :id) :dependencies (get record :dependencies) :exports (get record :exports) :portable (get record :portable) :portableBinding (get record :portableBinding nil)
6592
7119
  :steps (js-call (get record :steps) :map (lambda (step) (js-object :run (get step :run) :initializes (get step :initializes))))))))))
6593
- (let ((capabilities (managed-host-capabilities combined)))
6594
- (when (> (js-length capabilities) 0) (put descriptor :hostCapabilities capabilities)))
7120
+ (when (> (js-length cached-caps) 0)
7121
+ (put descriptor :hostCapabilities (js-call cached-caps :map (lambda (c) (Object/assign (js-object) c)))))
6595
7122
  (when module
6596
7123
  (put descriptor :module (js-object :initialize "__eliscript_module_init" :get "__eliscript_module_get"
6597
7124
  :invoke "__eliscript_module_invoke"
@@ -6599,9 +7126,8 @@
6599
7126
  :bindingCount (js-length globals) :functionCount function-count :exports module-exports)))
6600
7127
  (let ((typed (js-object :abi "memory-u32" :filename (get program :filename) :functions combined
6601
7128
  :exports (get runtime :exports) :aliases aliases :table table
6602
- :indirectSignatures (get runtime :indirectSignatures (js-array))))
6603
- (capabilities (managed-host-capabilities combined)))
6604
- (when (> (js-length capabilities) 0) (put typed :hostCapabilities capabilities))
7129
+ :indirectSignatures (get runtime :indirectSignatures (js-array)))))
7130
+ (when (> (js-length cached-caps) 0) (put typed :hostCapabilities cached-caps))
6605
7131
  (let ((signatures (js-object)))
6606
7132
  (js-call (get typed :exports) :forEach (lambda (name)
6607
7133
  (let ((function (find-function combined name)))
@@ -6628,7 +7154,7 @@
6628
7154
  (managed-fail program "unknown managed ABI"))
6629
7155
  (when (and (not (nil? requested)) (not (= requested (get (get lowered :descriptor) :abi))))
6630
7156
  (managed-fail program "top-level bindings require managed-module"))
6631
- (append-metadata-section (emit-owned-memory-wasm (get lowered :typed) (or options (js-object)))
7157
+ (append-metadata-section (emit-owned-memory-wasm (mark-trusted-runtime-program (get lowered :typed)) (or options (js-object)))
6632
7158
  "eliscript-managed-control" (JSON/stringify (get lowered :descriptor)))))
6633
7159
  (defun lower-managed-namespace (node state functions)
6634
7160
  (unless (and (get state :projectNamespaces nil) (js-call (get state :projectNamespaces) :includes node))
@@ -7229,7 +7755,7 @@
7229
7755
  (lowered (lower-managed-project modules entry runtime-program options)))
7230
7756
  (when (and (not (nil? requested)) (not (= requested "managed-module")))
7231
7757
  (managed-link-fail nil "managed projects require managed-module"))
7232
- (append-metadata-section (emit-owned-memory-wasm (get lowered :typed) (or options (js-object)))
7758
+ (append-metadata-section (emit-owned-memory-wasm (mark-trusted-runtime-program (get lowered :typed)) (or options (js-object)))
7233
7759
  "eliscript-managed-control" (JSON/stringify (get lowered :descriptor)))))
7234
7760
 
7235
7761
  (defun managed-well-known-symbol (name)