@holoscript/core 7.0.0 → 8.0.1

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 (350) hide show
  1. package/README.md +4 -4
  2. package/bin/holoscript.cjs +3 -0
  3. package/dist/GLTFPipeline-N6B6PJ6G.cjs +38 -0
  4. package/dist/GLTFPipeline-P3WMNYCN.js +17 -0
  5. package/dist/HoloScriptPlusParser-7FBIFUFC.js +693 -0
  6. package/dist/HoloScriptPlusParser-A2W7OCN2.cjs +698 -0
  7. package/dist/HoloScriptPlusParser-F2Z56FJR.js +10 -0
  8. package/dist/HoloScriptPlusParser-WKHRIH6T.cjs +27 -0
  9. package/dist/HoloScriptRuntime-CBYJX3LZ.js +10 -0
  10. package/dist/HoloScriptRuntime-VJ374RER.cjs +19 -0
  11. package/dist/USDZExporter-3FWJ25JI.cjs +1037 -0
  12. package/dist/USDZExporter-D2HQLQYK.js +1035 -0
  13. package/dist/agents/index.cjs +19 -0
  14. package/dist/agents/index.d.ts +100 -0
  15. package/dist/agents/index.js +17 -0
  16. package/dist/chunk-2BSMSUCE.js +1941 -0
  17. package/dist/chunk-2IWC4FP7.cjs +1189 -0
  18. package/dist/chunk-2M2DPHKB.js +762 -0
  19. package/dist/chunk-2X7NGX3M.js +2426 -0
  20. package/dist/chunk-2YSNA2F2.cjs +1274 -0
  21. package/dist/chunk-3FOKASKO.cjs +348 -0
  22. package/dist/chunk-3WZEJHUQ.cjs +116 -0
  23. package/dist/chunk-4C57PR42.js +468 -0
  24. package/dist/chunk-4GU5GCIY.js +1384 -0
  25. package/dist/chunk-4N4SXXWF.js +769 -0
  26. package/dist/chunk-4PDEPEQW.cjs +41 -0
  27. package/dist/chunk-4R6SBXDB.js +45 -0
  28. package/dist/chunk-4SDKXQ4C.js +811 -0
  29. package/dist/chunk-4V2E7U7Q.cjs +2015 -0
  30. package/dist/chunk-5FSKKMR7.cjs +2092 -0
  31. package/dist/chunk-5GLCTO44.js +161 -0
  32. package/dist/chunk-5H2G27PK.cjs +627 -0
  33. package/dist/chunk-5JEU52DW.js +382 -0
  34. package/dist/chunk-5NWINHR5.cjs +689 -0
  35. package/dist/chunk-5S7RKFGR.cjs +446 -0
  36. package/dist/chunk-5WUNN6ZN.cjs +428 -0
  37. package/dist/chunk-6CTRH7HT.cjs +1985 -0
  38. package/dist/chunk-6EX3I5P4.cjs +130 -0
  39. package/dist/chunk-6Q7RC2MK.cjs +1418 -0
  40. package/dist/chunk-7H33U5SM.cjs +413 -0
  41. package/dist/chunk-7M3PNU2M.cjs +672 -0
  42. package/dist/chunk-7T25IEZ2.js +449 -0
  43. package/dist/chunk-7V4JI5TB.cjs +6947 -0
  44. package/dist/chunk-A6KINLZJ.js +236 -0
  45. package/dist/chunk-ADADVMXY.js +404 -0
  46. package/dist/chunk-AIA52I7T.cjs +543 -0
  47. package/dist/chunk-ALC6K7GL.cjs +4402 -0
  48. package/dist/chunk-ANXZFVY2.js +113 -0
  49. package/dist/chunk-AOVGZ25K.cjs +56583 -0
  50. package/dist/chunk-AVJHHUC5.cjs +718 -0
  51. package/dist/chunk-BGY3SDG3.js +4396 -0
  52. package/dist/chunk-BOVPWH4H.js +3857 -0
  53. package/dist/chunk-BRQJKJGT.cjs +20 -0
  54. package/dist/chunk-C37BHB7N.cjs +636 -0
  55. package/dist/chunk-CBJY23VL.js +126 -0
  56. package/dist/chunk-CCATWPXM.js +778 -0
  57. package/dist/chunk-CIWWXYHZ.cjs +50 -0
  58. package/dist/chunk-CMT5NMMS.js +669 -0
  59. package/dist/chunk-CR4FMIWL.cjs +1049 -0
  60. package/dist/chunk-CR7XRXRN.cjs +639 -0
  61. package/dist/chunk-CSD27UNQ.js +2176 -0
  62. package/dist/chunk-D3STJ56J.js +714 -0
  63. package/dist/chunk-DAJXW4KX.js +725 -0
  64. package/dist/chunk-DHO2YRIM.js +756 -0
  65. package/dist/chunk-DTGBOSEM.cjs +319 -0
  66. package/dist/chunk-E6XXE66V.js +2252 -0
  67. package/dist/chunk-E7JP3BS3.cjs +61 -0
  68. package/dist/chunk-EKBKLK7P.js +1169 -0
  69. package/dist/chunk-EKYL4PE3.cjs +404 -0
  70. package/dist/chunk-EXKSFGSX.cjs +274 -0
  71. package/dist/chunk-EXUP2BUM.cjs +1173 -0
  72. package/dist/chunk-FDSGHPAK.js +130 -0
  73. package/dist/chunk-FEWUHQNM.cjs +144 -0
  74. package/dist/chunk-FFAOS5HQ.js +70 -0
  75. package/dist/chunk-FGGJQRLZ.js +270 -0
  76. package/dist/chunk-FHP6LXJS.js +415 -0
  77. package/dist/chunk-FJPADH77.cjs +666 -0
  78. package/dist/chunk-FL33V6U7.js +421 -0
  79. package/dist/chunk-FYSPZT4V.cjs +169 -0
  80. package/dist/chunk-GIOYPNTH.js +5575 -0
  81. package/dist/chunk-GJNCFRJU.cjs +125 -0
  82. package/dist/chunk-GMP623FG.cjs +1508 -0
  83. package/dist/chunk-GQHQOPXZ.cjs +5580 -0
  84. package/dist/chunk-GTU2Z2WW.cjs +262 -0
  85. package/dist/chunk-GYZE55MO.js +2007 -0
  86. package/dist/chunk-GZG4KA4E.js +529 -0
  87. package/dist/chunk-H652NHX5.js +600 -0
  88. package/dist/chunk-HCCQLAA4.cjs +74 -0
  89. package/dist/chunk-HKEXJUWS.cjs +4007 -0
  90. package/dist/chunk-HNDK4IQU.cjs +5737 -0
  91. package/dist/chunk-HR2OSYVQ.js +56165 -0
  92. package/dist/chunk-HYNTS5CP.js +422 -0
  93. package/dist/chunk-I6XZ5DZF.cjs +488 -0
  94. package/dist/chunk-ILRBGFVD.cjs +72 -0
  95. package/dist/chunk-IUDGEUDO.cjs +1409 -0
  96. package/dist/chunk-IUTY5WQ2.cjs +424 -0
  97. package/dist/chunk-IVY74O6C.js +247 -0
  98. package/dist/chunk-IWC5DM2M.cjs +611 -0
  99. package/dist/chunk-J32ZJZJH.js +554 -0
  100. package/dist/chunk-J52VSAQ7.js +6884 -0
  101. package/dist/chunk-J6M4FPK5.js +421 -0
  102. package/dist/chunk-J7XZV333.js +844 -0
  103. package/dist/chunk-JBNDTXXV.cjs +2433 -0
  104. package/dist/chunk-JC5YBPSF.cjs +984 -0
  105. package/dist/chunk-JD7CIZ33.js +1949 -0
  106. package/dist/chunk-JIBL5LRK.js +4287 -0
  107. package/dist/chunk-JIYN45TV.cjs +2525 -0
  108. package/dist/chunk-K574J76X.cjs +457 -0
  109. package/dist/chunk-KHDZJE5D.cjs +2196 -0
  110. package/dist/chunk-KKFZ3B6J.cjs +557 -0
  111. package/dist/chunk-KKP7JKN4.cjs +6002 -0
  112. package/dist/chunk-KPJL34Y7.cjs +186 -0
  113. package/dist/chunk-KQCN6AKJ.cjs +3042 -0
  114. package/dist/chunk-L5LKKENW.cjs +424 -0
  115. package/dist/chunk-LHAXPADA.js +882 -0
  116. package/dist/chunk-LM2VU56C.cjs +37 -0
  117. package/dist/chunk-M56JSP4A.js +400 -0
  118. package/dist/chunk-MBOOR7X4.js +18 -0
  119. package/dist/chunk-MQWAT42R.cjs +4310 -0
  120. package/dist/chunk-MXFUTKCO.js +56 -0
  121. package/dist/chunk-MYY4PMWX.cjs +264 -0
  122. package/dist/chunk-N75IH2HY.js +258 -0
  123. package/dist/chunk-NCWCUZNS.cjs +72 -0
  124. package/dist/chunk-NG77ATEW.cjs +778 -0
  125. package/dist/chunk-NW5G5FBQ.js +215 -0
  126. package/dist/chunk-OBIYPYYS.cjs +1993 -0
  127. package/dist/chunk-OH2FAIVU.js +608 -0
  128. package/dist/chunk-OIQYIIO3.cjs +473 -0
  129. package/dist/chunk-OL46QLBJ.js +61 -0
  130. package/dist/chunk-OMXII44L.js +5386 -0
  131. package/dist/chunk-OSYNRVOV.cjs +243 -0
  132. package/dist/chunk-PGANYCAG.cjs +220 -0
  133. package/dist/chunk-PHENW4MQ.js +65 -0
  134. package/dist/chunk-PY37LNDP.js +686 -0
  135. package/dist/chunk-Q56TT7IL.js +483 -0
  136. package/dist/chunk-QD32ADK6.js +1046 -0
  137. package/dist/chunk-QPOQ7VPI.js +1491 -0
  138. package/dist/chunk-QPSKHBJP.js +5963 -0
  139. package/dist/chunk-QXH7QDSZ.js +1989 -0
  140. package/dist/chunk-R24NNAEG.js +1399 -0
  141. package/dist/chunk-R75BSDH7.cjs +50 -0
  142. package/dist/chunk-RARB3MBR.js +207 -0
  143. package/dist/chunk-ROHLEP2W.cjs +847 -0
  144. package/dist/chunk-S3MDHNKB.cjs +490 -0
  145. package/dist/chunk-S6YWHCKV.cjs +410 -0
  146. package/dist/chunk-SIEXCILW.js +229 -0
  147. package/dist/chunk-SLU6UPJI.cjs +410 -0
  148. package/dist/chunk-SMIWS6DE.cjs +212 -0
  149. package/dist/chunk-T5J7ZKP3.cjs +4885 -0
  150. package/dist/chunk-TDCNJHWO.js +341 -0
  151. package/dist/chunk-TG7O4WBC.js +406 -0
  152. package/dist/chunk-THCK6ECW.js +2085 -0
  153. package/dist/chunk-TJHVSBP2.js +439 -0
  154. package/dist/chunk-TVHSPJ4N.cjs +606 -0
  155. package/dist/chunk-TWUXUCEW.cjs +781 -0
  156. package/dist/chunk-U44IKGG7.cjs +5390 -0
  157. package/dist/chunk-UFZZ7TSN.cjs +886 -0
  158. package/dist/chunk-UJXISJBN.js +487 -0
  159. package/dist/chunk-UOIGFQXC.cjs +9750 -0
  160. package/dist/chunk-URG2SJLK.js +2521 -0
  161. package/dist/chunk-UWJHCOH2.js +623 -0
  162. package/dist/chunk-V6MKC2FZ.js +979 -0
  163. package/dist/chunk-VJ3L7CHT.cjs +169 -0
  164. package/dist/chunk-VMLKSV26.js +1216 -0
  165. package/dist/chunk-VVKVQZI6.js +55 -0
  166. package/dist/chunk-W6RW64BB.cjs +1219 -0
  167. package/dist/chunk-WKX5AMOY.js +309 -0
  168. package/dist/chunk-WNNE3PO3.js +34 -0
  169. package/dist/chunk-WRKUDAZJ.js +3038 -0
  170. package/dist/chunk-WRLUBRKS.cjs +1943 -0
  171. package/dist/chunk-WRNEH5MO.js +3169 -0
  172. package/dist/chunk-WRWEX5ZF.js +658 -0
  173. package/dist/chunk-X3GJPRVK.cjs +3246 -0
  174. package/dist/chunk-X3UVCWNL.cjs +2257 -0
  175. package/dist/chunk-XB274MW5.cjs +814 -0
  176. package/dist/chunk-XHIV6326.cjs +793 -0
  177. package/dist/chunk-XIVIE43A.cjs +729 -0
  178. package/dist/chunk-XJAN7CZG.cjs +432 -0
  179. package/dist/chunk-XKTPFXGA.js +164 -0
  180. package/dist/chunk-XL6INWKT.js +121 -0
  181. package/dist/chunk-XSFNHP2E.js +632 -0
  182. package/dist/chunk-XT6JY5W5.js +9684 -0
  183. package/dist/chunk-XUILI4KB.cjs +430 -0
  184. package/dist/chunk-YF2I3MV3.js +46 -0
  185. package/dist/chunk-YIMN575O.js +4847 -0
  186. package/dist/chunk-YIVFJNYV.js +176 -0
  187. package/dist/chunk-YKGPCZEE.cjs +237 -0
  188. package/dist/chunk-YN2YWTXW.js +5731 -0
  189. package/dist/chunk-YN6V7R3L.cjs +327 -0
  190. package/dist/chunk-YQELFNJV.js +39 -0
  191. package/dist/chunk-YVD3CSO3.js +1183 -0
  192. package/dist/chunk-YVOAF4ML.js +623 -0
  193. package/dist/chunk-YWOBW2PV.cjs +759 -0
  194. package/dist/chunk-YYXH45E2.js +426 -0
  195. package/dist/chunk-ZDSYWBIE.cjs +69 -0
  196. package/dist/chunk-ZU7NIRT6.js +325 -0
  197. package/dist/chunk-ZZ7RO2UQ.js +1243 -0
  198. package/dist/cli/holoscript-runner.cjs +2255 -0
  199. package/dist/cli/holoscript-runner.js +2230 -0
  200. package/dist/codebase/index.cjs +336 -0
  201. package/dist/codebase/index.js +331 -0
  202. package/dist/compiler/agent-inference.cjs +31 -0
  203. package/dist/compiler/agent-inference.js +8 -0
  204. package/dist/compiler/android-xr.cjs +24 -0
  205. package/dist/compiler/android-xr.js +14 -0
  206. package/dist/compiler/android.cjs +24 -0
  207. package/dist/compiler/android.js +14 -0
  208. package/dist/compiler/ar.cjs +23 -0
  209. package/dist/compiler/ar.js +11 -0
  210. package/dist/compiler/babylon.cjs +21 -0
  211. package/dist/compiler/babylon.js +15 -0
  212. package/dist/compiler/business-quest.cjs +43 -0
  213. package/dist/compiler/business-quest.js +4 -0
  214. package/dist/compiler/coco.cjs +27 -0
  215. package/dist/compiler/coco.js +4 -0
  216. package/dist/compiler/context.cjs +25 -0
  217. package/dist/compiler/context.d.ts +28 -0
  218. package/dist/compiler/context.js +8 -0
  219. package/dist/compiler/domain-block-utils.cjs +609 -0
  220. package/dist/compiler/domain-block-utils.js +11 -0
  221. package/dist/compiler/dtdl.cjs +27 -0
  222. package/dist/compiler/dtdl.js +11 -0
  223. package/dist/compiler/gltf-pipeline.cjs +39 -0
  224. package/dist/compiler/gltf-pipeline.js +4 -0
  225. package/dist/compiler/godot.cjs +18 -0
  226. package/dist/compiler/godot.js +12 -0
  227. package/dist/compiler/incremental.cjs +34 -0
  228. package/dist/compiler/incremental.js +9 -0
  229. package/dist/compiler/index.cjs +5408 -0
  230. package/dist/compiler/index.d.ts +334 -21
  231. package/dist/compiler/index.js +5069 -0
  232. package/dist/compiler/ios.cjs +23 -0
  233. package/dist/compiler/ios.js +13 -0
  234. package/dist/compiler/llm-provider-capabilities.cjs +25 -0
  235. package/dist/compiler/llm-provider-capabilities.d.ts +43 -0
  236. package/dist/compiler/llm-provider-capabilities.js +8 -0
  237. package/dist/compiler/multi-layer.cjs +24 -0
  238. package/dist/compiler/multi-layer.js +15 -0
  239. package/dist/compiler/nodetoy.cjs +23 -0
  240. package/dist/compiler/nodetoy.d.ts +69 -0
  241. package/dist/compiler/nodetoy.js +4 -0
  242. package/dist/compiler/openxr.cjs +19 -0
  243. package/dist/compiler/openxr.js +13 -0
  244. package/dist/compiler/playcanvas.cjs +19 -0
  245. package/dist/compiler/playcanvas.js +13 -0
  246. package/dist/compiler/r3f.cjs +39 -0
  247. package/dist/compiler/r3f.d.ts +22 -0
  248. package/dist/compiler/r3f.js +17 -0
  249. package/dist/compiler/remotion.cjs +23 -0
  250. package/dist/compiler/remotion.js +4 -0
  251. package/dist/compiler/reproducibility.cjs +39 -0
  252. package/dist/compiler/reproducibility.js +4 -0
  253. package/dist/compiler/sdf.cjs +24 -0
  254. package/dist/compiler/sdf.js +12 -0
  255. package/dist/compiler/semantic-scene.cjs +31 -0
  256. package/dist/compiler/semantic-scene.js +4 -0
  257. package/dist/compiler/state.cjs +21 -0
  258. package/dist/compiler/state.js +11 -0
  259. package/dist/compiler/trait-composition.cjs +30 -0
  260. package/dist/compiler/trait-composition.js +9 -0
  261. package/dist/compiler/unity.cjs +19 -0
  262. package/dist/compiler/unity.js +13 -0
  263. package/dist/compiler/unreal.cjs +23 -0
  264. package/dist/compiler/unreal.js +13 -0
  265. package/dist/compiler/urdf.cjs +52 -0
  266. package/dist/compiler/urdf.js +12 -0
  267. package/dist/compiler/usd-physics.cjs +26 -0
  268. package/dist/compiler/usd-physics.js +9 -0
  269. package/dist/compiler/visionos.cjs +19 -0
  270. package/dist/compiler/visionos.js +13 -0
  271. package/dist/compiler/vrchat.cjs +22 -0
  272. package/dist/compiler/vrchat.js +12 -0
  273. package/dist/compiler/vrr.cjs +24 -0
  274. package/dist/compiler/vrr.js +12 -0
  275. package/dist/compiler/wasm.cjs +36 -0
  276. package/dist/compiler/wasm.js +12 -0
  277. package/dist/compiler/webgpu.cjs +18 -0
  278. package/dist/compiler/webgpu.js +12 -0
  279. package/dist/coordinators/index.cjs +1266 -0
  280. package/dist/coordinators/index.d.ts +72 -1
  281. package/dist/coordinators/index.js +1259 -0
  282. package/dist/debugger.cjs +24 -0
  283. package/dist/debugger.js +11 -0
  284. package/dist/dist-ACXG6IH5.cjs +3113 -0
  285. package/dist/dist-VD4L6V7Q.js +3076 -0
  286. package/dist/entries/interop.cjs +64 -0
  287. package/dist/entries/interop.js +7 -0
  288. package/dist/entries/scripting.cjs +55 -0
  289. package/dist/entries/scripting.js +10 -0
  290. package/dist/hololand/index.cjs +146 -0
  291. package/dist/hololand/index.d.ts +70 -0
  292. package/dist/hololand/index.js +5 -0
  293. package/dist/index.cjs +44660 -0
  294. package/dist/index.d.ts +978 -21
  295. package/dist/index.js +41422 -0
  296. package/dist/math/tropical-spmv.cjs +45 -0
  297. package/dist/math/tropical-spmv.js +4 -0
  298. package/dist/math/vec3.cjs +57 -0
  299. package/dist/math/vec3.js +4 -0
  300. package/dist/ml-dsa-FSKBTE3W.cjs +1265 -0
  301. package/dist/ml-dsa-Z7JDKW4L.js +1265 -0
  302. package/dist/paper-0c-spike/index.cjs +150 -0
  303. package/dist/paper-0c-spike/index.js +141 -0
  304. package/dist/parser.cjs +61 -0
  305. package/dist/parser.d.ts +11 -0
  306. package/dist/parser.js +12 -0
  307. package/dist/playwright-3AT3AKTV.cjs +98673 -0
  308. package/dist/playwright-VZPDVUEQ.js +98660 -0
  309. package/dist/reconstruction/index.cjs +153 -0
  310. package/dist/reconstruction/index.d.ts +29 -2
  311. package/dist/reconstruction/index.js +8 -0
  312. package/dist/runtime.cjs +316 -0
  313. package/dist/runtime.d.ts +61 -0
  314. package/dist/runtime.js +31 -0
  315. package/dist/self-improvement/index.cjs +563 -0
  316. package/dist/self-improvement/index.js +545 -0
  317. package/dist/src-4ROC227P.cjs +2094 -0
  318. package/dist/src-HCCCSYP7.js +2073 -0
  319. package/dist/storage/index.cjs +38 -0
  320. package/dist/storage/index.js +5 -0
  321. package/dist/testing.cjs +25 -0
  322. package/dist/testing.d.ts +70 -0
  323. package/dist/testing.js +4 -0
  324. package/dist/traitDocs/traitDocs.cjs +33 -0
  325. package/dist/traitDocs/traitDocs.js +7 -0
  326. package/dist/traits/botanical-lotus.cjs +177 -0
  327. package/dist/traits/botanical-lotus.d.ts +502 -0
  328. package/dist/traits/botanical-lotus.js +7 -0
  329. package/dist/traits/engines/index.cjs +520 -0
  330. package/dist/traits/engines/index.js +380 -0
  331. package/dist/traits/index.cjs +24548 -0
  332. package/dist/traits/index.d.ts +171 -35
  333. package/dist/traits/index.js +21638 -0
  334. package/dist/traits/simulation-solver-factory.cjs +13 -0
  335. package/dist/traits/simulation-solver-factory.d.ts +23 -0
  336. package/dist/traits/simulation-solver-factory.js +4 -0
  337. package/dist/traits/webcam-gaze.cjs +35 -0
  338. package/dist/traits/webcam-gaze.d.ts +17 -0
  339. package/dist/traits/webcam-gaze.js +4 -0
  340. package/dist/type-checker.cjs +19 -0
  341. package/dist/type-checker.js +6 -0
  342. package/dist/world/index.cjs +947 -0
  343. package/dist/world/index.d.ts +147 -0
  344. package/dist/world/index.js +939 -0
  345. package/dist/world-model/index.cjs +1446 -0
  346. package/dist/world-model/index.d.ts +119 -0
  347. package/dist/world-model/index.js +1414 -0
  348. package/dist/wot/index.cjs +29 -0
  349. package/dist/wot/index.js +4 -0
  350. package/package.json +93 -49
@@ -0,0 +1,1183 @@
1
+ import { init_DomainBlockCompilerMixin, compileDomainBlocks, compileMaterialBlock } from './chunk-BOVPWH4H.js';
2
+ import { createTestCompilerToken, init_CompilerBase, CompilerBase } from './chunk-QPSKHBJP.js';
3
+ import { __export, __esm } from './chunk-OL46QLBJ.js';
4
+ import { ANSCapabilityPath } from '@holoscript/core-types/ans';
5
+
6
+ // src/compiler/WASMCompiler.ts
7
+ var WASMCompiler_exports = {};
8
+ __export(WASMCompiler_exports, {
9
+ WASMCompiler: () => WASMCompiler,
10
+ compileASTToWASM: () => compileASTToWASM,
11
+ compileToWASM: () => compileToWASM,
12
+ createWASMCompiler: () => createWASMCompiler,
13
+ default: () => WASMCompiler_default
14
+ });
15
+ function createWASMCompiler(options) {
16
+ return new WASMCompiler(options);
17
+ }
18
+ function compileToWASM(composition, options) {
19
+ const compiler = new WASMCompiler(options);
20
+ return compiler.compile(composition, createTestCompilerToken());
21
+ }
22
+ function compileASTToWASM(ast, options) {
23
+ const compiler = new WASMCompiler(options);
24
+ return compiler.compileAST(ast);
25
+ }
26
+ var WASM_WAT_LIMITATIONS, WASM_BINARY_LIMITATIONS, WASMCompiler, WASMCompiler_default;
27
+ var init_WASMCompiler = __esm({
28
+ "src/compiler/WASMCompiler.ts"() {
29
+ init_CompilerBase();
30
+ init_DomainBlockCompilerMixin();
31
+ WASM_WAT_LIMITATIONS = [
32
+ "Emits WebAssembly Text Format scaffolding only.",
33
+ 'Does not return instantiable bytes unless format is set to "wasm".',
34
+ "Lowers trait/lifecycle/event hooks to deterministic host event calls, not arbitrary user code."
35
+ ];
36
+ WASM_BINARY_LIMITATIONS = [
37
+ "Returns an instantiable WebAssembly binary for the compiler-supported runtime subset.",
38
+ "Lowers trait/lifecycle/event hooks to deterministic host event calls, not arbitrary user code.",
39
+ "Does not run a general-purpose WAT parser for unsupported custom WAT extensions."
40
+ ];
41
+ WASMCompiler = class extends CompilerBase {
42
+ constructor(options = {}) {
43
+ super();
44
+ this.compilerName = "WASMCompiler";
45
+ this.lines = [];
46
+ this.indentLevel = 0;
47
+ this.stateVars = [];
48
+ this.objects = [];
49
+ this.functions = /* @__PURE__ */ new Map();
50
+ this.stringPool = /* @__PURE__ */ new Map();
51
+ this.nextStringOffset = 0;
52
+ this.imports = [];
53
+ this.exports = [];
54
+ // Memory layout
55
+ this.memoryLayout = {
56
+ stateOffset: 0,
57
+ stateSize: 0,
58
+ objectsOffset: 0,
59
+ objectsSize: 0,
60
+ eventsOffset: 0,
61
+ eventsSize: 1024,
62
+ // Fixed event queue size
63
+ stringsOffset: 0,
64
+ stringsSize: 0,
65
+ totalSize: 0
66
+ };
67
+ const { generateDocs, docsOptions, provenanceHash, ...wasmRest } = options;
68
+ this.docGenerationOptions = { generateDocs, docsOptions, provenanceHash };
69
+ const w = wasmRest;
70
+ this.options = {
71
+ format: w.format || "wat",
72
+ debug: w.debug ?? false,
73
+ memoryPages: w.memoryPages || 16,
74
+ // 1MB default
75
+ simd: w.simd ?? false,
76
+ threads: w.threads ?? false,
77
+ generateBindings: w.generateBindings ?? true,
78
+ moduleName: w.moduleName || "holoscript"
79
+ };
80
+ }
81
+ getRequiredCapability() {
82
+ return ANSCapabilityPath.WASM;
83
+ }
84
+ // ===========================================================================
85
+ // MAIN COMPILATION
86
+ // ===========================================================================
87
+ /**
88
+ * Compile HoloComposition AST to WASM
89
+ */
90
+ compile(composition, agentToken, outputPath) {
91
+ this.validateCompilerAccess(agentToken, outputPath);
92
+ this.reset();
93
+ this.analyzeState(composition.state);
94
+ this.analyzeObjects(composition.objects || []);
95
+ this.calculateMemoryLayout();
96
+ this.emitModule(composition);
97
+ const domainBlocks = composition.domainBlocks ?? [];
98
+ if (domainBlocks.length > 0) {
99
+ this.emit("");
100
+ this.emit(" ;; === v4.2 Domain Blocks ===");
101
+ compileDomainBlocks(
102
+ domainBlocks,
103
+ {
104
+ material: (block) => {
105
+ const mat = compileMaterialBlock(block);
106
+ this.emit(
107
+ ` ;; Material: "${this.escapeStringValue(mat.name, "TypeScript")}" type=${mat.type}`
108
+ );
109
+ this.emit(
110
+ ` ;; baseColor=${mat.baseColor || "none"} roughness=${mat.roughness ?? 0.5} metallic=${mat.metallic ?? 0}`
111
+ );
112
+ return "";
113
+ }
114
+ },
115
+ (block) => {
116
+ this.emit(
117
+ ` ;; Domain block: ${block.domain}/${block.keyword} "${this.escapeStringValue(block.name, "TypeScript")}"`
118
+ );
119
+ return "";
120
+ }
121
+ );
122
+ }
123
+ const bindings = this.options.generateBindings ? this.generateBindings(composition) : "";
124
+ const wasm = this.options.format === "wasm" ? this.emitWASMBytes(this.lowerCompositionObjectUpdates(composition.objects || [])) : void 0;
125
+ const result = {
126
+ artifactKind: wasm ? "wasm-binary" : "wat-scaffold",
127
+ format: this.options.format,
128
+ wat: this.lines.join("\n"),
129
+ ...wasm ? { wasm } : {},
130
+ bindings,
131
+ memoryLayout: this.memoryLayout,
132
+ exports: this.exports,
133
+ imports: this.imports,
134
+ limitations: wasm ? [...WASM_BINARY_LIMITATIONS] : [...WASM_WAT_LIMITATIONS]
135
+ };
136
+ return this.withTripleOutputIfRequested(composition, result, this.docGenerationOptions);
137
+ }
138
+ /**
139
+ * Compile HSPlusAST to WASM
140
+ */
141
+ compileAST(ast) {
142
+ this.reset();
143
+ this.analyzeHSPlusState(ast);
144
+ this.analyzeHSPlusObjects(ast.root);
145
+ this.calculateMemoryLayout();
146
+ this.emitModuleFromAST(ast);
147
+ const bindings = this.options.generateBindings ? this.generateBindingsFromAST(ast) : "";
148
+ const wasm = this.options.format === "wasm" ? this.emitWASMBytes(this.lowerASTObjectUpdates(ast.root.children || [])) : void 0;
149
+ return {
150
+ artifactKind: wasm ? "wasm-binary" : "wat-scaffold",
151
+ format: this.options.format,
152
+ wat: this.lines.join("\n"),
153
+ ...wasm ? { wasm } : {},
154
+ bindings,
155
+ memoryLayout: this.memoryLayout,
156
+ exports: this.exports,
157
+ imports: this.imports,
158
+ limitations: wasm ? [...WASM_BINARY_LIMITATIONS] : [...WASM_WAT_LIMITATIONS]
159
+ };
160
+ }
161
+ reset() {
162
+ this.lines = [];
163
+ this.indentLevel = 0;
164
+ this.stateVars = [];
165
+ this.objects = [];
166
+ this.functions.clear();
167
+ this.stringPool.clear();
168
+ this.nextStringOffset = 0;
169
+ this.imports = [];
170
+ this.exports = [];
171
+ }
172
+ // ===========================================================================
173
+ // ANALYSIS
174
+ // ===========================================================================
175
+ analyzeState(state) {
176
+ if (!state) return;
177
+ let offset = 0;
178
+ const stateAny = state;
179
+ if (stateAny.properties) {
180
+ for (const prop of stateAny.properties) {
181
+ const type = this.inferWASMType(prop.value);
182
+ const size = this.getTypeSize(type);
183
+ this.stateVars.push({
184
+ name: prop.key,
185
+ type,
186
+ offset,
187
+ size,
188
+ initialValue: this.valueToWASM(prop.value, type)
189
+ });
190
+ offset += size;
191
+ }
192
+ } else if (stateAny.declarations) {
193
+ for (const [name, value] of Object.entries(stateAny.declarations)) {
194
+ const type = this.inferWASMType(value);
195
+ const size = this.getTypeSize(type);
196
+ this.stateVars.push({
197
+ name,
198
+ type,
199
+ offset,
200
+ size,
201
+ initialValue: this.valueToWASM(value, type)
202
+ });
203
+ offset += size;
204
+ }
205
+ }
206
+ this.memoryLayout.stateSize = offset;
207
+ }
208
+ analyzeHSPlusState(ast) {
209
+ const stateDirective = ast.root.directives?.find((d) => d.type === "state");
210
+ if (!stateDirective || stateDirective.type !== "state") return;
211
+ let offset = 0;
212
+ const body = stateDirective.body;
213
+ for (const [name, value] of Object.entries(body)) {
214
+ const type = this.inferWASMType(value);
215
+ const size = this.getTypeSize(type);
216
+ this.stateVars.push({
217
+ name,
218
+ type,
219
+ offset,
220
+ size,
221
+ initialValue: this.valueToWASM(value, type)
222
+ });
223
+ offset += size;
224
+ }
225
+ this.memoryLayout.stateSize = offset;
226
+ }
227
+ analyzeObjects(objects) {
228
+ let offset = 0;
229
+ for (let i = 0; i < objects.length; i++) {
230
+ const obj = objects[i];
231
+ const instance = {
232
+ id: obj.name,
233
+ typeIndex: i,
234
+ offset,
235
+ properties: /* @__PURE__ */ new Map()
236
+ };
237
+ let propOffset = 12;
238
+ for (const prop of obj.properties || []) {
239
+ const type = this.inferWASMType(prop.value);
240
+ const size = this.getTypeSize(type);
241
+ instance.properties.set(prop.key, { offset: propOffset, type });
242
+ propOffset += size;
243
+ }
244
+ propOffset = Math.ceil(propOffset / 8) * 8;
245
+ this.objects.push(instance);
246
+ offset += propOffset;
247
+ }
248
+ this.memoryLayout.objectsSize = offset;
249
+ }
250
+ analyzeHSPlusObjects(root) {
251
+ const children = root.children || [];
252
+ let offset = 0;
253
+ for (let i = 0; i < children.length; i++) {
254
+ const node = children[i];
255
+ const instance = {
256
+ id: node.id || `obj_${i}`,
257
+ typeIndex: i,
258
+ offset,
259
+ properties: /* @__PURE__ */ new Map()
260
+ };
261
+ let propOffset = 12;
262
+ if (node.properties) {
263
+ for (const [key, value] of Object.entries(node.properties)) {
264
+ const type = this.inferWASMType(value);
265
+ const size = this.getTypeSize(type);
266
+ instance.properties.set(key, { offset: propOffset, type });
267
+ propOffset += size;
268
+ }
269
+ }
270
+ propOffset = Math.ceil(propOffset / 8) * 8;
271
+ this.objects.push(instance);
272
+ offset += propOffset;
273
+ }
274
+ this.memoryLayout.objectsSize = offset;
275
+ }
276
+ calculateMemoryLayout() {
277
+ this.memoryLayout.stateOffset = 0;
278
+ this.memoryLayout.objectsOffset = this.memoryLayout.stateSize;
279
+ this.memoryLayout.eventsOffset = this.memoryLayout.objectsOffset + this.memoryLayout.objectsSize;
280
+ this.memoryLayout.stringsOffset = this.memoryLayout.eventsOffset + this.memoryLayout.eventsSize;
281
+ this.memoryLayout.totalSize = this.memoryLayout.stringsOffset + this.memoryLayout.stringsSize;
282
+ }
283
+ // ===========================================================================
284
+ // WAT GENERATION
285
+ // ===========================================================================
286
+ emitModule(composition) {
287
+ this.emit("(module");
288
+ this.indent();
289
+ if (this.options.debug) {
290
+ this.emit(`(; Module: ${this.options.moduleName} ;)`);
291
+ }
292
+ this.emitImports();
293
+ this.emitMemory();
294
+ this.emitGlobals();
295
+ this.emitFunctionTypes();
296
+ this.emitInitFunction();
297
+ this.emitStateAccessors();
298
+ this.emitObjectFunctions();
299
+ this.emitEventFunctions();
300
+ this.emitUpdateFunction(composition);
301
+ this.emitDataSections();
302
+ this.emitExports();
303
+ this.dedent();
304
+ this.emit(")");
305
+ }
306
+ emitModuleFromAST(ast) {
307
+ this.emit("(module");
308
+ this.indent();
309
+ if (this.options.debug) {
310
+ this.emit(`(; Module: ${this.options.moduleName} (from AST) ;)`);
311
+ }
312
+ this.emitImports();
313
+ this.emitMemory();
314
+ this.emitGlobals();
315
+ this.emitFunctionTypes();
316
+ this.emitInitFunction();
317
+ this.emitStateAccessors();
318
+ this.emitObjectFunctions();
319
+ this.emitEventFunctions();
320
+ this.emitUpdateFunctionFromAST(ast);
321
+ this.emitDataSections();
322
+ this.emitExports();
323
+ this.dedent();
324
+ this.emit(")");
325
+ }
326
+ emitImports() {
327
+ this.emit(";; Imports from host");
328
+ this.emit('(import "env" "log_i32" (func $log_i32 (param i32)))');
329
+ this.emit('(import "env" "log_f32" (func $log_f32 (param f32)))');
330
+ this.emit('(import "env" "log_str" (func $log_str (param i32 i32)))');
331
+ this.imports.push(
332
+ { module: "env", name: "log_i32", kind: "function", signature: "(i32) -> void" },
333
+ { module: "env", name: "log_f32", kind: "function", signature: "(f32) -> void" },
334
+ { module: "env", name: "log_str", kind: "function", signature: "(i32, i32) -> void" }
335
+ );
336
+ this.emit('(import "env" "emit_event" (func $emit_event (param i32 i32)))');
337
+ this.imports.push({
338
+ module: "env",
339
+ name: "emit_event",
340
+ kind: "function",
341
+ signature: "(event_id: i32, payload_ptr: i32) -> void"
342
+ });
343
+ this.emit('(import "env" "get_time" (func $get_time (result f64)))');
344
+ this.imports.push({
345
+ module: "env",
346
+ name: "get_time",
347
+ kind: "function",
348
+ signature: "() -> f64"
349
+ });
350
+ this.emit("");
351
+ }
352
+ emitMemory() {
353
+ const pages = this.options.memoryPages;
354
+ this.emit(`;; Memory: ${pages} pages (${pages * 64}KB)`);
355
+ if (this.options.threads) {
356
+ this.emit(`(memory (export "memory") ${pages} ${pages * 2} shared)`);
357
+ } else {
358
+ this.emit(`(memory (export "memory") ${pages})`);
359
+ }
360
+ this.exports.push({ name: "memory", kind: "memory" });
361
+ this.emit("");
362
+ }
363
+ emitGlobals() {
364
+ this.emit(";; Globals");
365
+ this.emit("(global $frame_count (mut i32) (i32.const 0))");
366
+ this.emit("(global $delta_time (mut f32) (f32.const 0.0))");
367
+ this.emit("(global $last_time (mut f64) (f64.const 0.0))");
368
+ this.emit(`(global $object_count i32 (i32.const ${this.objects.length}))`);
369
+ this.emit("");
370
+ }
371
+ emitFunctionTypes() {
372
+ this.emit(";; Function types");
373
+ this.emit("(type $void_void (func))");
374
+ this.emit("(type $i32_void (func (param i32)))");
375
+ this.emit("(type $f32_void (func (param f32)))");
376
+ this.emit("(type $void_i32 (func (result i32)))");
377
+ this.emit("(type $void_f32 (func (result f32)))");
378
+ this.emit("(type $i32_i32 (func (param i32) (result i32)))");
379
+ this.emit("(type $i32_f32 (func (param i32) (result f32)))");
380
+ this.emit("(type $i32_i32_void (func (param i32 i32)))");
381
+ this.emit("(type $update_fn (func (param f32)))");
382
+ this.emit("");
383
+ }
384
+ emitInitFunction() {
385
+ this.emit(";; Initialize module");
386
+ this.emit('(func $init (export "init")');
387
+ this.indent();
388
+ for (const v of this.stateVars) {
389
+ const offset = this.memoryLayout.stateOffset + v.offset;
390
+ this.emit(` ;; ${this.escapeStringValue(v.name, "TypeScript")}`);
391
+ switch (v.type) {
392
+ case "i32":
393
+ this.emit(` (i32.store (i32.const ${offset}) (i32.const ${v.initialValue}))`);
394
+ break;
395
+ case "i64":
396
+ this.emit(` (i64.store (i32.const ${offset}) (i64.const ${v.initialValue}))`);
397
+ break;
398
+ case "f32":
399
+ this.emit(` (f32.store (i32.const ${offset}) (f32.const ${v.initialValue}))`);
400
+ break;
401
+ case "f64":
402
+ this.emit(` (f64.store (i32.const ${offset}) (f64.const ${v.initialValue}))`);
403
+ break;
404
+ }
405
+ }
406
+ for (const obj of this.objects) {
407
+ const baseOffset = this.memoryLayout.objectsOffset + obj.offset;
408
+ const safeName = this.sanitizeName(obj.id);
409
+ this.emit(` ;; Object: ${safeName}`);
410
+ this.emit(` (i32.store (i32.const ${baseOffset}) (i32.const ${obj.typeIndex})) ;; type`);
411
+ this.emit(` (i32.store (i32.const ${baseOffset + 4}) (i32.const 1)) ;; active`);
412
+ this.emit(` (i32.store (i32.const ${baseOffset + 8}) (i32.const -1)) ;; parent`);
413
+ }
414
+ this.dedent();
415
+ this.emit(")");
416
+ this.emit("");
417
+ this.exports.push({ name: "init", kind: "function", signature: "() -> void" });
418
+ }
419
+ emitStateAccessors() {
420
+ this.emit(";; State accessors");
421
+ for (const v of this.stateVars) {
422
+ const offset = this.memoryLayout.stateOffset + v.offset;
423
+ const safeName = this.sanitizeName(v.name);
424
+ this.emit(`(func $get_${safeName} (export "get_${safeName}") (result ${v.type})`);
425
+ this.emit(` (${v.type}.load (i32.const ${offset}))`);
426
+ this.emit(")");
427
+ this.emit(`(func $set_${safeName} (export "set_${safeName}") (param $value ${v.type})`);
428
+ this.emit(` (${v.type}.store (i32.const ${offset}) (local.get $value))`);
429
+ this.emit(")");
430
+ this.exports.push({
431
+ name: `get_${safeName}`,
432
+ kind: "function",
433
+ signature: `() -> ${v.type}`
434
+ });
435
+ this.exports.push({
436
+ name: `set_${safeName}`,
437
+ kind: "function",
438
+ signature: `(${v.type}) -> void`
439
+ });
440
+ }
441
+ this.emit('(func $get_frame_count (export "get_frame_count") (result i32)');
442
+ this.emit(" (global.get $frame_count)");
443
+ this.emit(")");
444
+ this.exports.push({
445
+ name: "get_frame_count",
446
+ kind: "function",
447
+ signature: "() -> i32"
448
+ });
449
+ this.emit("");
450
+ }
451
+ emitObjectFunctions() {
452
+ this.emit(";; Object functions");
453
+ this.emit('(func $get_object_count (export "get_object_count") (result i32)');
454
+ this.emit(" (global.get $object_count)");
455
+ this.emit(")");
456
+ this.emit('(func $is_object_active (export "is_object_active") (param $idx i32) (result i32)');
457
+ this.indent();
458
+ this.emit("(i32.load");
459
+ this.emit(" (i32.add");
460
+ this.emit(` (i32.const ${this.memoryLayout.objectsOffset})`);
461
+ this.emit(" (i32.add");
462
+ this.emit(" (i32.mul (local.get $idx) (i32.const 64)) ;; obj size");
463
+ this.emit(" (i32.const 4) ;; active offset");
464
+ this.emit(" )");
465
+ this.emit(" )");
466
+ this.emit(")");
467
+ this.dedent();
468
+ this.emit(")");
469
+ this.emit(
470
+ '(func $set_object_active (export "set_object_active") (param $idx i32) (param $active i32)'
471
+ );
472
+ this.indent();
473
+ this.emit("(i32.store");
474
+ this.emit(" (i32.add");
475
+ this.emit(` (i32.const ${this.memoryLayout.objectsOffset})`);
476
+ this.emit(" (i32.add");
477
+ this.emit(" (i32.mul (local.get $idx) (i32.const 64))");
478
+ this.emit(" (i32.const 4)");
479
+ this.emit(" )");
480
+ this.emit(" )");
481
+ this.emit(" (local.get $active)");
482
+ this.emit(")");
483
+ this.dedent();
484
+ this.emit(")");
485
+ this.exports.push(
486
+ { name: "get_object_count", kind: "function", signature: "() -> i32" },
487
+ { name: "is_object_active", kind: "function", signature: "(i32) -> i32" },
488
+ { name: "set_object_active", kind: "function", signature: "(i32, i32) -> void" }
489
+ );
490
+ this.emit("");
491
+ }
492
+ emitEventFunctions() {
493
+ this.emit(";; Event functions");
494
+ this.emit("(func $dispatch_event (param $event_id i32) (param $payload i32)");
495
+ this.emit(" (call $emit_event (local.get $event_id) (local.get $payload))");
496
+ this.emit(")");
497
+ this.emit("");
498
+ }
499
+ emitUpdateFunction(composition) {
500
+ const objectUpdates = this.lowerCompositionObjectUpdates(composition.objects || []);
501
+ this.emit(";; Main update function");
502
+ this.emit('(func $update (export "update") (param $dt f32)');
503
+ this.indent();
504
+ this.emit("(global.set $delta_time (local.get $dt))");
505
+ this.emit("(global.set $frame_count");
506
+ this.emit(" (i32.add (global.get $frame_count) (i32.const 1))");
507
+ this.emit(")");
508
+ for (let i = 0; i < this.objects.length; i++) {
509
+ const obj = this.objects[i];
510
+ const safeObjName = this.sanitizeName(obj.id);
511
+ this.emit(` ;; Update ${safeObjName}`);
512
+ this.emit(` (if (call $is_object_active (i32.const ${i}))`);
513
+ this.emit(" (then");
514
+ this.emit(` (call $update_object_${i} (local.get $dt))`);
515
+ this.emit(" )");
516
+ this.emit(" )");
517
+ }
518
+ this.dedent();
519
+ this.emit(")");
520
+ this.emit("");
521
+ for (let i = 0; i < this.objects.length; i++) {
522
+ const obj = this.objects[i];
523
+ const safeName = this.sanitizeName(obj.id);
524
+ this.emit(`(func $update_object_${i} (param $dt f32)`);
525
+ this.emit(` ;; Update logic for ${safeName}`);
526
+ this.emitLoweredObjectUpdateBody(objectUpdates[i] || [], i);
527
+ this.emit(")");
528
+ }
529
+ this.exports.push({ name: "update", kind: "function", signature: "(f32) -> void" });
530
+ this.emit("");
531
+ }
532
+ emitUpdateFunctionFromAST(ast) {
533
+ const objectUpdates = this.lowerASTObjectUpdates(ast.root.children || []);
534
+ this.emit(";; Main update function");
535
+ this.emit('(func $update (export "update") (param $dt f32)');
536
+ this.indent();
537
+ this.emit("(global.set $delta_time (local.get $dt))");
538
+ this.emit("(global.set $frame_count");
539
+ this.emit(" (i32.add (global.get $frame_count) (i32.const 1))");
540
+ this.emit(")");
541
+ for (let i = 0; i < this.objects.length; i++) {
542
+ const obj = this.objects[i];
543
+ const safeObjName = this.sanitizeName(obj.id);
544
+ this.emit(` ;; Update ${safeObjName}`);
545
+ this.emit(` (if (call $is_object_active (i32.const ${i}))`);
546
+ this.emit(" (then");
547
+ this.emit(` (call $update_object_${i} (local.get $dt))`);
548
+ this.emit(" )");
549
+ this.emit(" )");
550
+ }
551
+ this.dedent();
552
+ this.emit(")");
553
+ this.emit("");
554
+ for (let i = 0; i < this.objects.length; i++) {
555
+ const obj = this.objects[i];
556
+ const safeName = this.sanitizeName(obj.id);
557
+ this.emit(`(func $update_object_${i} (param $dt f32)`);
558
+ this.emit(` ;; Update logic for ${safeName}`);
559
+ this.emitLoweredObjectUpdateBody(objectUpdates[i] || [], i);
560
+ this.emit(")");
561
+ }
562
+ this.exports.push({ name: "update", kind: "function", signature: "(f32) -> void" });
563
+ this.emit("");
564
+ }
565
+ emitLoweredObjectUpdateBody(updates, objectIndex) {
566
+ if (updates.length === 0) {
567
+ this.emit(" ;; No WASM-lowerable trait/lifecycle/event hooks for this object");
568
+ return;
569
+ }
570
+ for (const update of updates) {
571
+ this.emit(` ;; ${this.escapeStringValue(update.label, "TypeScript")}`);
572
+ this.emit(` (call $emit_event (i32.const ${update.eventId}) (i32.const ${objectIndex}))`);
573
+ }
574
+ }
575
+ lowerCompositionObjectUpdates(objects) {
576
+ return objects.map((obj) => {
577
+ const events = [];
578
+ for (const trait of obj.traits || []) {
579
+ events.push(this.createLoweredUpdate(`trait:${trait.name}`));
580
+ }
581
+ for (const eventHandler of this.getUnknownArray(obj, "eventHandlers")) {
582
+ const event = this.getUnknownString(eventHandler, "event");
583
+ if (event) events.push(this.createLoweredUpdate(`event:${event}`));
584
+ }
585
+ for (const directive of this.getUnknownArray(obj, "directives")) {
586
+ const directiveType = this.getUnknownString(directive, "type");
587
+ const hook = this.getUnknownString(directive, "hook") || this.getUnknownString(directive, "name");
588
+ if (directiveType === "lifecycle" && hook) {
589
+ events.push(this.createLoweredUpdate(`lifecycle:${hook}`));
590
+ }
591
+ }
592
+ return events;
593
+ });
594
+ }
595
+ lowerASTObjectUpdates(nodes) {
596
+ return nodes.map((node) => {
597
+ const events = [];
598
+ for (const directive of node.directives || []) {
599
+ const directiveType = this.getUnknownString(directive, "type");
600
+ const name = this.getUnknownString(directive, "name") || this.getUnknownString(directive, "hook");
601
+ if (directiveType === "trait" && name) {
602
+ events.push(this.createLoweredUpdate(`trait:${name}`));
603
+ } else if (directiveType === "lifecycle" && name) {
604
+ events.push(this.createLoweredUpdate(`lifecycle:${name}`));
605
+ }
606
+ }
607
+ for (const [key] of Object.entries(node.properties || {})) {
608
+ if (key.startsWith("on_")) events.push(this.createLoweredUpdate(`event:${key}`));
609
+ }
610
+ return events;
611
+ });
612
+ }
613
+ createLoweredUpdate(label) {
614
+ return {
615
+ label,
616
+ eventId: this.stableEventId(label)
617
+ };
618
+ }
619
+ stableEventId(label) {
620
+ let hash = 2166136261;
621
+ for (let i = 0; i < label.length; i++) {
622
+ hash ^= label.charCodeAt(i);
623
+ hash = Math.imul(hash, 16777619);
624
+ }
625
+ return hash >>> 1;
626
+ }
627
+ getUnknownArray(source, key) {
628
+ if (!source || typeof source !== "object") return [];
629
+ const value = source[key];
630
+ return Array.isArray(value) ? value : [];
631
+ }
632
+ getUnknownString(source, key) {
633
+ if (!source || typeof source !== "object") return void 0;
634
+ const value = source[key];
635
+ return typeof value === "string" ? value : void 0;
636
+ }
637
+ emitDataSections() {
638
+ if (this.stringPool.size === 0) return;
639
+ this.emit(";; Data sections");
640
+ for (const [str, offset] of this.stringPool) {
641
+ const escaped = this.escapeWATString(str);
642
+ this.emit(`(data (i32.const ${this.memoryLayout.stringsOffset + offset}) "${escaped}")`);
643
+ }
644
+ this.emit("");
645
+ }
646
+ emitExports() {
647
+ }
648
+ // ===========================================================================
649
+ // JS BINDINGS GENERATION
650
+ // ===========================================================================
651
+ generateBindings(_composition) {
652
+ const lines = [];
653
+ lines.push("/**");
654
+ lines.push(` * JavaScript bindings for ${this.options.moduleName}`);
655
+ lines.push(" * Auto-generated by HoloScript WASMCompiler");
656
+ lines.push(" */");
657
+ lines.push("");
658
+ lines.push("export class HoloScriptWASM {");
659
+ lines.push(" private instance: WebAssembly.Instance | null = null;");
660
+ lines.push(" private memory: WebAssembly.Memory | null = null;");
661
+ lines.push(
662
+ " private eventHandlers: Map<string, Set<(payload: unknown) => void>> = new Map();"
663
+ );
664
+ lines.push("");
665
+ lines.push(" private static EVENT_IDS: Record<string, number> = {");
666
+ lines.push(" 'update': 0,");
667
+ lines.push(" 'state_change': 1,");
668
+ lines.push(" 'object_activated': 2,");
669
+ lines.push(" 'object_deactivated': 3,");
670
+ lines.push(" };");
671
+ lines.push("");
672
+ lines.push(" async load(wasmSource: ArrayBuffer | Response): Promise<void> {");
673
+ lines.push(" const importObject = {");
674
+ lines.push(" env: {");
675
+ lines.push(' log_i32: (v: number) => console.log("[WASM i32]", v),');
676
+ lines.push(' log_f32: (v: number) => console.log("[WASM f32]", v),');
677
+ lines.push(" log_str: (ptr: number, len: number) => {");
678
+ lines.push(" const bytes = new Uint8Array(this.memory!.buffer, ptr, len);");
679
+ lines.push(' console.log("[WASM str]", new TextDecoder().decode(bytes));');
680
+ lines.push(" },");
681
+ lines.push(" emit_event: (eventId: number, payloadPtr: number) => {");
682
+ lines.push(" this.handleEvent(eventId, payloadPtr);");
683
+ lines.push(" },");
684
+ lines.push(" get_time: () => performance.now(),");
685
+ lines.push(" },");
686
+ lines.push(" };");
687
+ lines.push("");
688
+ lines.push(" const result = await WebAssembly.instantiate(wasmSource, importObject);");
689
+ lines.push(" this.instance = result.instance;");
690
+ lines.push(" this.memory = this.instance.exports.memory as WebAssembly.Memory;");
691
+ lines.push(" (this.instance.exports.init as Function)();");
692
+ lines.push(" }");
693
+ lines.push("");
694
+ lines.push(" // State accessors");
695
+ for (const v of this.stateVars) {
696
+ const safeName = this.sanitizeName(v.name);
697
+ const jsType = this.wasmTypeToJS(v.type);
698
+ lines.push(` get ${safeName}(): ${jsType} {`);
699
+ lines.push(` return (this.instance!.exports.get_${safeName} as Function)();`);
700
+ lines.push(" }");
701
+ lines.push(` set ${safeName}(value: ${jsType}) {`);
702
+ lines.push(` (this.instance!.exports.set_${safeName} as Function)(value);`);
703
+ lines.push(" }");
704
+ }
705
+ lines.push("");
706
+ lines.push(" update(dt: number): void {");
707
+ lines.push(" (this.instance!.exports.update as Function)(dt);");
708
+ lines.push(" }");
709
+ lines.push("");
710
+ lines.push(" on(event: string, handler: (payload: unknown) => void): () => void {");
711
+ lines.push(" if (!this.eventHandlers.has(event)) {");
712
+ lines.push(" this.eventHandlers.set(event, new Set());");
713
+ lines.push(" }");
714
+ lines.push(" this.eventHandlers.get(event)!.add(handler);");
715
+ lines.push(" return () => this.eventHandlers.get(event)?.delete(handler);");
716
+ lines.push(" }");
717
+ lines.push("");
718
+ lines.push(" private handleEvent(eventId: number, payloadPtr: number): void {");
719
+ lines.push(" const eventName = Object.entries(HoloScriptWASM.EVENT_IDS)");
720
+ lines.push(" .find(([_, id]) => id === eventId)?.[0];");
721
+ lines.push(" if (!eventName) return;");
722
+ lines.push(" const handlers = this.eventHandlers.get(eventName);");
723
+ lines.push(" if (handlers) {");
724
+ lines.push(" const payload = this.decodePayload(payloadPtr);");
725
+ lines.push(" handlers.forEach(h => h(payload));");
726
+ lines.push(" }");
727
+ lines.push(" }");
728
+ lines.push("");
729
+ lines.push(" private decodePayload(ptr: number): unknown {");
730
+ lines.push(" if (!this.instance || ptr === 0) return {};");
731
+ lines.push(" const memory = this.instance.exports.memory as WebAssembly.Memory;");
732
+ lines.push(" const view = new DataView(memory.buffer);");
733
+ lines.push(" // Read payload header: [type:u8][length:u32]");
734
+ lines.push(" const payloadType = view.getUint8(ptr);");
735
+ lines.push(" const length = view.getUint32(ptr + 1, true);");
736
+ lines.push(" const dataPtr = ptr + 5;");
737
+ lines.push(" switch (payloadType) {");
738
+ lines.push(" case 0: return null; // Null");
739
+ lines.push(" case 1: return view.getFloat64(dataPtr, true); // Number");
740
+ lines.push(" case 2: return view.getUint8(dataPtr) !== 0; // Boolean");
741
+ lines.push(" case 3: { // String");
742
+ lines.push(" const bytes = new Uint8Array(memory.buffer, dataPtr, length);");
743
+ lines.push(" return new TextDecoder().decode(bytes);");
744
+ lines.push(" }");
745
+ lines.push(" case 4: { // Object (JSON)");
746
+ lines.push(" const bytes = new Uint8Array(memory.buffer, dataPtr, length);");
747
+ lines.push(" return JSON.parse(new TextDecoder().decode(bytes));");
748
+ lines.push(" }");
749
+ lines.push(" case 5: { // Float32Array");
750
+ lines.push(" return new Float32Array(memory.buffer, dataPtr, length / 4);");
751
+ lines.push(" }");
752
+ lines.push(" default: return { ptr, type: payloadType, length };");
753
+ lines.push(" }");
754
+ lines.push(" }");
755
+ lines.push("");
756
+ lines.push(" getObjectCount(): number {");
757
+ lines.push(" return (this.instance!.exports.get_object_count as Function)();");
758
+ lines.push(" }");
759
+ lines.push("");
760
+ lines.push(" isObjectActive(index: number): boolean {");
761
+ lines.push(" return (this.instance!.exports.is_object_active as Function)(index) !== 0;");
762
+ lines.push(" }");
763
+ lines.push("");
764
+ lines.push(" setObjectActive(index: number, active: boolean): void {");
765
+ lines.push(
766
+ " (this.instance!.exports.set_object_active as Function)(index, active ? 1 : 0);"
767
+ );
768
+ lines.push(" }");
769
+ lines.push("");
770
+ lines.push(" getMemoryLayout(): object {");
771
+ lines.push(` return ${JSON.stringify(this.memoryLayout)};`);
772
+ lines.push(" }");
773
+ lines.push("}");
774
+ return lines.join("\n");
775
+ }
776
+ generateBindingsFromAST(ast) {
777
+ const minimalComposition = {
778
+ type: "Composition",
779
+ name: ast.root.id || "scene",
780
+ objects: [],
781
+ templates: [],
782
+ spatialGroups: [],
783
+ lights: [],
784
+ imports: [],
785
+ timelines: [],
786
+ audio: [],
787
+ zones: [],
788
+ transitions: [],
789
+ conditionals: [],
790
+ iterators: [],
791
+ npcs: [],
792
+ quests: [],
793
+ abilities: [],
794
+ dialogues: [],
795
+ stateMachines: [],
796
+ achievements: [],
797
+ talentTrees: [],
798
+ shapes: []
799
+ };
800
+ return this.generateBindings(minimalComposition);
801
+ }
802
+ // ===========================================================================
803
+ // WASM BINARY GENERATION
804
+ // ===========================================================================
805
+ emitWASMBytes(objectUpdates) {
806
+ const types = [];
807
+ const typeIndexes = /* @__PURE__ */ new Map();
808
+ const typeIndex = (params, results = []) => {
809
+ const key = `${params.join(",")}->${results.join(",")}`;
810
+ const existing = typeIndexes.get(key);
811
+ if (existing !== void 0) return existing;
812
+ const next = types.length;
813
+ types.push({ params, results });
814
+ typeIndexes.set(key, next);
815
+ return next;
816
+ };
817
+ const imports = [
818
+ { module: "env", name: "log_i32", typeIndex: typeIndex(["i32"]) },
819
+ { module: "env", name: "log_f32", typeIndex: typeIndex(["f32"]) },
820
+ { module: "env", name: "log_str", typeIndex: typeIndex(["i32", "i32"]) },
821
+ { module: "env", name: "emit_event", typeIndex: typeIndex(["i32", "i32"]) },
822
+ { module: "env", name: "get_time", typeIndex: typeIndex([], ["f64"]) }
823
+ ];
824
+ const functions = [];
825
+ const functionIndexes = /* @__PURE__ */ new Map();
826
+ const addFunction = (name, params, results, body) => {
827
+ functionIndexes.set(name, imports.length + functions.length);
828
+ functions.push({ name, typeIndex: typeIndex(params, results), body });
829
+ };
830
+ addFunction("init", [], [], () => this.binaryInitBody());
831
+ for (const stateVar of this.stateVars) {
832
+ const safeName = this.sanitizeName(stateVar.name);
833
+ addFunction(
834
+ `get_${safeName}`,
835
+ [],
836
+ [stateVar.type],
837
+ () => this.binaryStateGetterBody(stateVar)
838
+ );
839
+ addFunction(
840
+ `set_${safeName}`,
841
+ [stateVar.type],
842
+ [],
843
+ () => this.binaryStateSetterBody(stateVar)
844
+ );
845
+ }
846
+ addFunction("get_frame_count", [], ["i32"], () => [0, 35, ...this.encodeULEB(0), 11]);
847
+ addFunction("get_object_count", [], ["i32"], () => [0, 35, ...this.encodeULEB(3), 11]);
848
+ addFunction("is_object_active", ["i32"], ["i32"], () => this.binaryIsObjectActiveBody());
849
+ addFunction("set_object_active", ["i32", "i32"], [], () => this.binarySetObjectActiveBody());
850
+ addFunction(
851
+ "update",
852
+ ["f32"],
853
+ [],
854
+ () => this.binaryUpdateBody(functionIndexes, objectUpdates.length)
855
+ );
856
+ for (let i = 0; i < this.objects.length; i++) {
857
+ addFunction(
858
+ `update_object_${i}`,
859
+ ["f32"],
860
+ [],
861
+ () => this.binaryUpdateObjectBody(objectUpdates[i] || [], i)
862
+ );
863
+ }
864
+ const bytes = [
865
+ 0,
866
+ 97,
867
+ 115,
868
+ 109,
869
+ 1,
870
+ 0,
871
+ 0,
872
+ 0,
873
+ ...this.binarySection(1, this.binaryTypeSection(types)),
874
+ ...this.binarySection(2, this.binaryImportSection(imports)),
875
+ ...this.binarySection(3, this.binaryFunctionSection(functions)),
876
+ ...this.binarySection(5, this.binaryMemorySection()),
877
+ ...this.binarySection(6, this.binaryGlobalSection()),
878
+ ...this.binarySection(7, this.binaryExportSection(functions, imports.length)),
879
+ ...this.binarySection(10, this.binaryCodeSection(functions))
880
+ ];
881
+ return new Uint8Array(bytes);
882
+ }
883
+ binaryTypeSection(types) {
884
+ return this.binaryVector(
885
+ types.map((type) => [
886
+ 96,
887
+ ...this.binaryVector(type.params.map((param) => [this.wasmBinaryValueType(param)])),
888
+ ...this.binaryVector(type.results.map((result) => [this.wasmBinaryValueType(result)]))
889
+ ])
890
+ );
891
+ }
892
+ binaryImportSection(imports) {
893
+ return this.binaryVector(
894
+ imports.map((entry) => [
895
+ ...this.encodeString(entry.module),
896
+ ...this.encodeString(entry.name),
897
+ 0,
898
+ ...this.encodeULEB(entry.typeIndex)
899
+ ])
900
+ );
901
+ }
902
+ binaryFunctionSection(functions) {
903
+ return this.binaryVector(functions.map((fn) => this.encodeULEB(fn.typeIndex)));
904
+ }
905
+ binaryMemorySection() {
906
+ if (this.options.threads) {
907
+ return this.binaryVector([
908
+ [
909
+ 3,
910
+ ...this.encodeULEB(this.options.memoryPages),
911
+ ...this.encodeULEB(this.options.memoryPages * 2)
912
+ ]
913
+ ]);
914
+ }
915
+ return this.binaryVector([[0, ...this.encodeULEB(this.options.memoryPages)]]);
916
+ }
917
+ binaryGlobalSection() {
918
+ return this.binaryVector([
919
+ [127, 1, 65, ...this.encodeSLEB(0), 11],
920
+ [125, 1, 67, ...this.f32Bytes(0), 11],
921
+ [124, 1, 68, ...this.f64Bytes(0), 11],
922
+ [127, 0, 65, ...this.encodeSLEB(this.objects.length), 11]
923
+ ]);
924
+ }
925
+ binaryExportSection(functions, importedFunctionCount) {
926
+ const exports$1 = [
927
+ [...this.encodeString("memory"), 2, ...this.encodeULEB(0)],
928
+ ...functions.filter((fn) => !fn.name.startsWith("update_object_")).map((fn, index) => [
929
+ ...this.encodeString(fn.name),
930
+ 0,
931
+ ...this.encodeULEB(importedFunctionCount + index)
932
+ ])
933
+ ];
934
+ return this.binaryVector(exports$1);
935
+ }
936
+ binaryCodeSection(functions) {
937
+ return this.binaryVector(
938
+ functions.map((fn) => {
939
+ const body = fn.body();
940
+ return [...this.encodeULEB(body.length), ...body];
941
+ })
942
+ );
943
+ }
944
+ binaryInitBody() {
945
+ const body = [0];
946
+ for (const stateVar of this.stateVars) {
947
+ const offset = this.memoryLayout.stateOffset + stateVar.offset;
948
+ body.push(65, ...this.encodeSLEB(offset));
949
+ this.pushWASMConst(body, stateVar.type, stateVar.initialValue);
950
+ this.pushWASMStore(body, stateVar.type);
951
+ }
952
+ for (const obj of this.objects) {
953
+ const baseOffset = this.memoryLayout.objectsOffset + obj.offset;
954
+ this.pushI32StoreConst(body, baseOffset, obj.typeIndex);
955
+ this.pushI32StoreConst(body, baseOffset + 4, 1);
956
+ this.pushI32StoreConst(body, baseOffset + 8, -1);
957
+ }
958
+ body.push(11);
959
+ return body;
960
+ }
961
+ binaryStateGetterBody(stateVar) {
962
+ const offset = this.memoryLayout.stateOffset + stateVar.offset;
963
+ const body = [0, 65, ...this.encodeSLEB(offset)];
964
+ this.pushWASMLoad(body, stateVar.type);
965
+ body.push(11);
966
+ return body;
967
+ }
968
+ binaryStateSetterBody(stateVar) {
969
+ const offset = this.memoryLayout.stateOffset + stateVar.offset;
970
+ const body = [0, 65, ...this.encodeSLEB(offset), 32, 0];
971
+ this.pushWASMStore(body, stateVar.type);
972
+ body.push(11);
973
+ return body;
974
+ }
975
+ binaryIsObjectActiveBody() {
976
+ const body = [0];
977
+ this.pushObjectActiveAddress(body, 0);
978
+ body.push(40, 2, 0, 11);
979
+ return body;
980
+ }
981
+ binarySetObjectActiveBody() {
982
+ const body = [0];
983
+ this.pushObjectActiveAddress(body, 0);
984
+ body.push(32, 1, 54, 2, 0, 11);
985
+ return body;
986
+ }
987
+ binaryUpdateBody(functionIndexes, loweredObjectCount) {
988
+ const body = [0];
989
+ body.push(32, 0, 36, ...this.encodeULEB(1));
990
+ body.push(35, ...this.encodeULEB(0), 65, ...this.encodeSLEB(1), 106);
991
+ body.push(36, ...this.encodeULEB(0));
992
+ const isActiveIndex = functionIndexes.get("is_object_active");
993
+ if (isActiveIndex === void 0) throw new Error("missing is_object_active function index");
994
+ for (let i = 0; i < loweredObjectCount; i++) {
995
+ const updateObjectIndex = functionIndexes.get(`update_object_${i}`);
996
+ if (updateObjectIndex === void 0) continue;
997
+ body.push(65, ...this.encodeSLEB(i), 16, ...this.encodeULEB(isActiveIndex));
998
+ body.push(4, 64);
999
+ body.push(32, 0, 16, ...this.encodeULEB(updateObjectIndex));
1000
+ body.push(11);
1001
+ }
1002
+ body.push(11);
1003
+ return body;
1004
+ }
1005
+ binaryUpdateObjectBody(updates, objectIndex) {
1006
+ const body = [0];
1007
+ for (const update of updates) {
1008
+ body.push(
1009
+ 65,
1010
+ ...this.encodeSLEB(update.eventId),
1011
+ 65,
1012
+ ...this.encodeSLEB(objectIndex),
1013
+ 16,
1014
+ ...this.encodeULEB(3)
1015
+ );
1016
+ }
1017
+ body.push(11);
1018
+ return body;
1019
+ }
1020
+ pushObjectActiveAddress(body, localIndex) {
1021
+ body.push(65, ...this.encodeSLEB(this.memoryLayout.objectsOffset));
1022
+ body.push(32, ...this.encodeULEB(localIndex));
1023
+ body.push(65, ...this.encodeSLEB(64), 108);
1024
+ body.push(65, ...this.encodeSLEB(4), 106);
1025
+ body.push(106);
1026
+ }
1027
+ pushI32StoreConst(body, offset, value) {
1028
+ body.push(65, ...this.encodeSLEB(offset), 65, ...this.encodeSLEB(value), 54, 2, 0);
1029
+ }
1030
+ pushWASMConst(body, type, value) {
1031
+ switch (type) {
1032
+ case "i32":
1033
+ body.push(65, ...this.encodeSLEB(Number(value)));
1034
+ break;
1035
+ case "i64":
1036
+ body.push(66, ...this.encodeSLEB(value));
1037
+ break;
1038
+ case "f32":
1039
+ body.push(67, ...this.f32Bytes(Number(value)));
1040
+ break;
1041
+ case "f64":
1042
+ body.push(68, ...this.f64Bytes(Number(value)));
1043
+ break;
1044
+ }
1045
+ }
1046
+ pushWASMLoad(body, type) {
1047
+ const opcode = { i32: 40, i64: 41, f32: 42, f64: 43 }[type];
1048
+ const align = type === "i64" || type === "f64" ? 3 : 2;
1049
+ body.push(opcode, align, 0);
1050
+ }
1051
+ pushWASMStore(body, type) {
1052
+ const opcode = { i32: 54, i64: 55, f32: 56, f64: 57 }[type];
1053
+ const align = type === "i64" || type === "f64" ? 3 : 2;
1054
+ body.push(opcode, align, 0);
1055
+ }
1056
+ binarySection(id, payload) {
1057
+ return [id, ...this.encodeULEB(payload.length), ...payload];
1058
+ }
1059
+ binaryVector(items) {
1060
+ return [...this.encodeULEB(items.length), ...items.flat()];
1061
+ }
1062
+ encodeString(value) {
1063
+ const bytes = Array.from(new TextEncoder().encode(value));
1064
+ return [...this.encodeULEB(bytes.length), ...bytes];
1065
+ }
1066
+ encodeULEB(value) {
1067
+ const bytes = [];
1068
+ let next = value >>> 0;
1069
+ do {
1070
+ let byte = next & 127;
1071
+ next >>>= 7;
1072
+ if (next !== 0) byte |= 128;
1073
+ bytes.push(byte);
1074
+ } while (next !== 0);
1075
+ return bytes;
1076
+ }
1077
+ encodeSLEB(value) {
1078
+ const bytes = [];
1079
+ let next = BigInt(value);
1080
+ let more = true;
1081
+ while (more) {
1082
+ let byte = Number(next & 0x7fn);
1083
+ next >>= 7n;
1084
+ const signBitSet = (byte & 64) !== 0;
1085
+ more = !(next === 0n && !signBitSet || next === -1n && signBitSet);
1086
+ if (more) byte |= 128;
1087
+ bytes.push(byte);
1088
+ }
1089
+ return bytes;
1090
+ }
1091
+ f32Bytes(value) {
1092
+ const bytes = new Uint8Array(4);
1093
+ new DataView(bytes.buffer).setFloat32(0, value, true);
1094
+ return Array.from(bytes);
1095
+ }
1096
+ f64Bytes(value) {
1097
+ const bytes = new Uint8Array(8);
1098
+ new DataView(bytes.buffer).setFloat64(0, value, true);
1099
+ return Array.from(bytes);
1100
+ }
1101
+ wasmBinaryValueType(type) {
1102
+ switch (type) {
1103
+ case "i32":
1104
+ return 127;
1105
+ case "i64":
1106
+ return 126;
1107
+ case "f32":
1108
+ return 125;
1109
+ case "f64":
1110
+ return 124;
1111
+ }
1112
+ }
1113
+ // ===========================================================================
1114
+ // HELPERS
1115
+ // ===========================================================================
1116
+ emit(line) {
1117
+ const indent = " ".repeat(this.indentLevel);
1118
+ this.lines.push(indent + line);
1119
+ }
1120
+ indent() {
1121
+ this.indentLevel++;
1122
+ }
1123
+ dedent() {
1124
+ this.indentLevel = Math.max(0, this.indentLevel - 1);
1125
+ }
1126
+ inferWASMType(value) {
1127
+ if (typeof value === "boolean") return "i32";
1128
+ if (typeof value === "number") {
1129
+ return Number.isInteger(value) ? "i32" : "f32";
1130
+ }
1131
+ if (typeof value === "bigint") return "i64";
1132
+ if (typeof value === "string") return "i32";
1133
+ if (Array.isArray(value)) return "i32";
1134
+ return "i32";
1135
+ }
1136
+ getTypeSize(type) {
1137
+ switch (type) {
1138
+ case "i32":
1139
+ case "f32":
1140
+ return 4;
1141
+ case "i64":
1142
+ case "f64":
1143
+ return 8;
1144
+ }
1145
+ }
1146
+ valueToWASM(value, _type) {
1147
+ if (typeof value === "boolean") return value ? 1 : 0;
1148
+ if (typeof value === "number") return value;
1149
+ if (typeof value === "bigint") return value;
1150
+ if (typeof value === "string") {
1151
+ if (!this.stringPool.has(value)) {
1152
+ this.stringPool.set(value, this.nextStringOffset);
1153
+ this.nextStringOffset += value.length + 1;
1154
+ }
1155
+ return this.stringPool.get(value);
1156
+ }
1157
+ return 0;
1158
+ }
1159
+ wasmTypeToJS(type) {
1160
+ switch (type) {
1161
+ case "i32":
1162
+ case "f32":
1163
+ return "number";
1164
+ case "i64":
1165
+ return "bigint";
1166
+ case "f64":
1167
+ return "number";
1168
+ }
1169
+ }
1170
+ sanitizeName(name) {
1171
+ return name.replace(/[^a-zA-Z0-9_]/g, "_");
1172
+ }
1173
+ escapeWATString(str) {
1174
+ return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
1175
+ }
1176
+ };
1177
+ WASMCompiler_default = WASMCompiler;
1178
+ }
1179
+ });
1180
+
1181
+ export { WASMCompiler, WASMCompiler_default, WASMCompiler_exports, compileASTToWASM, compileToWASM, createWASMCompiler, init_WASMCompiler };
1182
+ //# sourceMappingURL=chunk-YVD3CSO3.js.map
1183
+ //# sourceMappingURL=chunk-YVD3CSO3.js.map