solve-engine 1.2.0 → 2.0.0

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 (384) hide show
  1. package/README.md +12 -17
  2. package/dist/{BytecodeBuilder-Bp9xeTmX.d.cts → BytecodeBuilder-DGGeByAP.d.cts} +18 -0
  3. package/dist/{BytecodeBuilder-Bp9xeTmX.d.ts → BytecodeBuilder-DGGeByAP.d.ts} +18 -0
  4. package/dist/{Configuration-C9W8tJv_.d.cts → Configuration-B6W0-T67.d.cts} +17 -4
  5. package/dist/{Configuration-C9W8tJv_.d.ts → Configuration-B6W0-T67.d.ts} +17 -4
  6. package/dist/{EngineError-CNA_rHY-.d.cts → EngineError-Ce1lPkjZ.d.cts} +2 -0
  7. package/dist/{EngineError-CNA_rHY-.d.ts → EngineError-Ce1lPkjZ.d.ts} +2 -0
  8. package/dist/{PackageCompatibility-B6NX9IaN.d.cts → PackageCompatibility-Bn5jnBtA.d.cts} +2 -2
  9. package/dist/{PackageCompatibility-Ceg5XdAp.d.ts → PackageCompatibility-CIvq2MP5.d.ts} +2 -2
  10. package/dist/{PackageRegistry-DrCPQNyy.d.ts → PackageRegistry-DzeiWcv4.d.ts} +93 -172
  11. package/dist/{PackageRegistry-DnJYVw9G.d.cts → PackageRegistry-dpdurBVO.d.cts} +93 -172
  12. package/dist/{Parselet-Bhf7d0_W.d.ts → Parselet-B-zoPrTa.d.ts} +8 -5
  13. package/dist/{Parselet-Cv7S7KRt.d.cts → Parselet-C4Wu055_.d.cts} +8 -5
  14. package/dist/{ScopeManager-Bzq87GfA.d.ts → ScopeManager-C2LDOrDx.d.ts} +7 -16
  15. package/dist/{ScopeManager-DRDBVfan.d.cts → ScopeManager-D7uMXbhS.d.cts} +7 -16
  16. package/dist/{VMCheckpoints-C6c17Hbo.d.ts → VMCheckpoints-CGyFhivM.d.ts} +3 -3
  17. package/dist/{VMCheckpoints-dZxSMGHG.d.cts → VMCheckpoints-I9jg3jWR.d.cts} +3 -3
  18. package/dist/{Value-DZNQ_PU7.d.cts → Value-CCi_Eecs.d.cts} +40 -0
  19. package/dist/{Value-DZNQ_PU7.d.ts → Value-CCi_Eecs.d.ts} +40 -0
  20. package/dist/{WorkerError-Djd7GGGa.d.cts → WorkerError-B4p6PNfx.d.cts} +1 -1
  21. package/dist/{WorkerError-B7t7R2-m.d.ts → WorkerError-Dhj9BQ_A.d.ts} +1 -1
  22. package/dist/chunk-2JMFUQZH.js +2 -0
  23. package/dist/chunk-2JMFUQZH.js.map +1 -0
  24. package/dist/chunk-2RWAXT6O.js +0 -1
  25. package/dist/chunk-4BZIYU7S.cjs +3 -0
  26. package/dist/chunk-4BZIYU7S.cjs.map +1 -0
  27. package/dist/chunk-4J7XZSZJ.cjs +5 -0
  28. package/dist/chunk-4J7XZSZJ.cjs.map +1 -0
  29. package/dist/chunk-4QVBSG6B.cjs +2 -0
  30. package/dist/chunk-4QVBSG6B.cjs.map +1 -0
  31. package/dist/chunk-5IJD5L3O.cjs +2 -0
  32. package/dist/chunk-5IJD5L3O.cjs.map +1 -0
  33. package/dist/chunk-62LMTO4F.js +2 -0
  34. package/dist/chunk-62LMTO4F.js.map +1 -0
  35. package/dist/chunk-6CY44ZPG.js +2 -0
  36. package/dist/chunk-6CY44ZPG.js.map +1 -0
  37. package/dist/chunk-6G3PMEPA.js +2 -0
  38. package/dist/chunk-6G3PMEPA.js.map +1 -0
  39. package/dist/chunk-6INX773F.cjs +2 -0
  40. package/dist/chunk-6INX773F.cjs.map +1 -0
  41. package/dist/chunk-6KFVG6UY.cjs +2 -0
  42. package/dist/{chunk-YJHY7CMN.cjs.map → chunk-6KFVG6UY.cjs.map} +1 -1
  43. package/dist/chunk-76F3LCIL.js +4 -0
  44. package/dist/chunk-76F3LCIL.js.map +1 -0
  45. package/dist/chunk-7GK3XEZF.js +2 -0
  46. package/dist/chunk-7GK3XEZF.js.map +1 -0
  47. package/dist/chunk-APN442VD.cjs +2 -0
  48. package/dist/chunk-APN442VD.cjs.map +1 -0
  49. package/dist/chunk-AXMQG5TS.cjs +2 -0
  50. package/dist/chunk-AXMQG5TS.cjs.map +1 -0
  51. package/dist/chunk-CIQOK7Q4.cjs +2 -0
  52. package/dist/chunk-CIQOK7Q4.cjs.map +1 -0
  53. package/dist/chunk-E6Z4NQAS.js +2 -0
  54. package/dist/chunk-E6Z4NQAS.js.map +1 -0
  55. package/dist/chunk-EFJCC6FJ.cjs +2 -0
  56. package/dist/chunk-EFJCC6FJ.cjs.map +1 -0
  57. package/dist/chunk-ESUN2THE.cjs +2 -0
  58. package/dist/chunk-ESUN2THE.cjs.map +1 -0
  59. package/dist/chunk-EVAOPEO4.js +2 -0
  60. package/dist/chunk-EVAOPEO4.js.map +1 -0
  61. package/dist/chunk-EYRBENHC.js +3 -0
  62. package/dist/chunk-EYRBENHC.js.map +1 -0
  63. package/dist/chunk-FDE5HWDI.cjs +2 -0
  64. package/dist/chunk-FDE5HWDI.cjs.map +1 -0
  65. package/dist/chunk-FWW3M36J.cjs +2 -0
  66. package/dist/chunk-FWW3M36J.cjs.map +1 -0
  67. package/dist/chunk-GOIQYUWV.js +2 -0
  68. package/dist/chunk-GOIQYUWV.js.map +1 -0
  69. package/dist/chunk-HFKDWQUL.js +2 -0
  70. package/dist/chunk-HFKDWQUL.js.map +1 -0
  71. package/dist/chunk-HLBYHXQD.cjs +3 -0
  72. package/dist/chunk-HLBYHXQD.cjs.map +1 -0
  73. package/dist/chunk-IANAMBJQ.cjs +2 -0
  74. package/dist/chunk-IANAMBJQ.cjs.map +1 -0
  75. package/dist/chunk-IJMNVBIS.js +2 -0
  76. package/dist/chunk-IJMNVBIS.js.map +1 -0
  77. package/dist/chunk-J4LZD4ZY.js +3 -0
  78. package/dist/chunk-J4LZD4ZY.js.map +1 -0
  79. package/dist/chunk-JAK3RAFA.cjs +2 -0
  80. package/dist/chunk-JAK3RAFA.cjs.map +1 -0
  81. package/dist/chunk-JFAJN3C2.cjs +2 -0
  82. package/dist/chunk-JFAJN3C2.cjs.map +1 -0
  83. package/dist/chunk-JPFCXLJV.js +2 -0
  84. package/dist/chunk-JPFCXLJV.js.map +1 -0
  85. package/dist/chunk-JSPKKNPQ.js +3 -0
  86. package/dist/chunk-JSPKKNPQ.js.map +1 -0
  87. package/dist/chunk-L3FPQSGN.js +2 -0
  88. package/dist/chunk-L3FPQSGN.js.map +1 -0
  89. package/dist/chunk-LR4E4A4W.cjs +2 -0
  90. package/dist/chunk-LR4E4A4W.cjs.map +1 -0
  91. package/dist/chunk-MIQBJGGR.js +2 -0
  92. package/dist/chunk-MIQBJGGR.js.map +1 -0
  93. package/dist/chunk-MPB7KUN5.js +3 -0
  94. package/dist/chunk-MPB7KUN5.js.map +1 -0
  95. package/dist/chunk-MSYX32PF.cjs +2 -0
  96. package/dist/chunk-MSYX32PF.cjs.map +1 -0
  97. package/dist/chunk-MVZUTETT.js +2 -0
  98. package/dist/chunk-MVZUTETT.js.map +1 -0
  99. package/dist/chunk-N7N7MPMK.cjs +2 -0
  100. package/dist/chunk-N7N7MPMK.cjs.map +1 -0
  101. package/dist/chunk-NGBBNL4K.cjs +1 -3
  102. package/dist/chunk-P6WPEUAJ.cjs +2 -0
  103. package/dist/chunk-P6WPEUAJ.cjs.map +1 -0
  104. package/dist/chunk-PS272DZJ.cjs +2 -0
  105. package/dist/chunk-PS272DZJ.cjs.map +1 -0
  106. package/dist/chunk-QXQE7X4S.js +2 -0
  107. package/dist/chunk-QXQE7X4S.js.map +1 -0
  108. package/dist/chunk-R2ENWQ76.js +2 -0
  109. package/dist/chunk-R2ENWQ76.js.map +1 -0
  110. package/dist/chunk-R2SZFJTT.cjs +2 -0
  111. package/dist/chunk-R2SZFJTT.cjs.map +1 -0
  112. package/dist/chunk-RAF57WYO.js +2 -0
  113. package/dist/chunk-RAF57WYO.js.map +1 -0
  114. package/dist/chunk-RSF25YSJ.js +2 -0
  115. package/dist/chunk-RSF25YSJ.js.map +1 -0
  116. package/dist/chunk-SOMGSIO4.cjs +3 -0
  117. package/dist/chunk-SOMGSIO4.cjs.map +1 -0
  118. package/dist/chunk-SUXRZWH2.cjs +3 -0
  119. package/dist/chunk-SUXRZWH2.cjs.map +1 -0
  120. package/dist/chunk-SYYE3QAX.cjs +2 -0
  121. package/dist/chunk-SYYE3QAX.cjs.map +1 -0
  122. package/dist/chunk-SZGK6RIP.cjs +2 -0
  123. package/dist/chunk-SZGK6RIP.cjs.map +1 -0
  124. package/dist/chunk-TCZSPH4A.js +2 -0
  125. package/dist/chunk-TCZSPH4A.js.map +1 -0
  126. package/dist/chunk-TLG7VZRX.cjs +2 -0
  127. package/dist/chunk-TLG7VZRX.cjs.map +1 -0
  128. package/dist/chunk-TRBXW6HW.js +2 -0
  129. package/dist/{chunk-AQNHHJMJ.cjs.map → chunk-TRBXW6HW.js.map} +1 -1
  130. package/dist/chunk-TTFO4YDP.cjs +2 -0
  131. package/dist/chunk-TTFO4YDP.cjs.map +1 -0
  132. package/dist/chunk-TWC7K3ZX.js +2 -0
  133. package/dist/chunk-TWC7K3ZX.js.map +1 -0
  134. package/dist/chunk-UDQ57ZRX.cjs +2 -0
  135. package/dist/chunk-UDQ57ZRX.cjs.map +1 -0
  136. package/dist/chunk-UI6IFGBT.js +2 -0
  137. package/dist/chunk-UI6IFGBT.js.map +1 -0
  138. package/dist/chunk-UURM7P3P.cjs +4 -0
  139. package/dist/chunk-UURM7P3P.cjs.map +1 -0
  140. package/dist/chunk-W2JAR233.js +2 -0
  141. package/dist/chunk-W2JAR233.js.map +1 -0
  142. package/dist/chunk-WGZ3FNHI.js +2 -0
  143. package/dist/chunk-WGZ3FNHI.js.map +1 -0
  144. package/dist/chunk-WN5CMP4T.cjs +3 -0
  145. package/dist/chunk-WN5CMP4T.cjs.map +1 -0
  146. package/dist/chunk-XEIDV5JP.js +2 -0
  147. package/dist/chunk-XEIDV5JP.js.map +1 -0
  148. package/dist/chunk-XNIWQHXY.js +2 -0
  149. package/dist/chunk-XNIWQHXY.js.map +1 -0
  150. package/dist/chunk-XR7HEC7B.js +5 -0
  151. package/dist/chunk-XR7HEC7B.js.map +1 -0
  152. package/dist/chunk-Y7O4D3BJ.cjs +2 -0
  153. package/dist/chunk-Y7O4D3BJ.cjs.map +1 -0
  154. package/dist/chunk-YAYBVVG2.js +3 -0
  155. package/dist/chunk-YAYBVVG2.js.map +1 -0
  156. package/dist/chunk-YJ2OPULK.js +2 -0
  157. package/dist/chunk-YJ2OPULK.js.map +1 -0
  158. package/dist/chunk-YVKHEAFT.js +2 -0
  159. package/dist/chunk-YVKHEAFT.js.map +1 -0
  160. package/dist/chunk-ZCNBT44X.cjs +2 -0
  161. package/dist/chunk-ZCNBT44X.cjs.map +1 -0
  162. package/dist/chunk-ZLRJ7TDP.cjs +2 -0
  163. package/dist/chunk-ZLRJ7TDP.cjs.map +1 -0
  164. package/dist/constants.cjs +1 -21
  165. package/dist/constants.d.cts +1 -1
  166. package/dist/constants.d.ts +1 -1
  167. package/dist/constants.js +1 -4
  168. package/dist/engine.cjs +1 -94
  169. package/dist/engine.d.cts +10 -11
  170. package/dist/engine.d.ts +10 -11
  171. package/dist/engine.js +1 -37
  172. package/dist/errors.cjs +1 -105
  173. package/dist/errors.d.cts +3 -3
  174. package/dist/errors.d.ts +3 -3
  175. package/dist/errors.js +1 -4
  176. package/dist/format.cjs +1 -26
  177. package/dist/format.d.cts +2 -2
  178. package/dist/format.d.ts +2 -2
  179. package/dist/format.js +1 -9
  180. package/dist/index.cjs +1 -314
  181. package/dist/index.cjs.map +1 -1
  182. package/dist/index.d.cts +52 -20
  183. package/dist/index.d.ts +52 -20
  184. package/dist/index.js +1 -278
  185. package/dist/index.js.map +1 -1
  186. package/dist/language.cjs +1 -369
  187. package/dist/language.cjs.map +1 -1
  188. package/dist/language.d.cts +9 -10
  189. package/dist/language.d.ts +9 -10
  190. package/dist/language.js +1 -348
  191. package/dist/language.js.map +1 -1
  192. package/dist/lexer.cjs +1 -63
  193. package/dist/lexer.js +1 -10
  194. package/dist/normalizer.cjs +1 -39
  195. package/dist/normalizer.js +1 -10
  196. package/dist/packages.cjs +1 -132
  197. package/dist/packages.d.cts +8 -9
  198. package/dist/packages.d.ts +8 -9
  199. package/dist/packages.js +1 -23
  200. package/dist/parser.cjs +1 -54
  201. package/dist/parser.d.cts +8 -8
  202. package/dist/parser.d.ts +8 -8
  203. package/dist/parser.js +1 -9
  204. package/dist/{pipeline-D-PS9gVw.d.ts → pipeline-72QmQlGx.d.ts} +1 -1
  205. package/dist/{pipeline-DtSBJ8TS.d.cts → pipeline-DCQicwWX.d.cts} +1 -1
  206. package/dist/resolvers.cjs +1 -12
  207. package/dist/resolvers.d.cts +2 -2
  208. package/dist/resolvers.d.ts +2 -2
  209. package/dist/resolvers.js +1 -3
  210. package/dist/services.cjs +1 -20
  211. package/dist/services.js +1 -3
  212. package/dist/testing.cjs +3 -477
  213. package/dist/testing.cjs.map +1 -1
  214. package/dist/testing.d.cts +9 -10
  215. package/dist/testing.d.ts +9 -10
  216. package/dist/testing.js +3 -469
  217. package/dist/testing.js.map +1 -1
  218. package/dist/uom.cjs +1 -55
  219. package/dist/uom.d.cts +2 -2
  220. package/dist/uom.d.ts +2 -2
  221. package/dist/uom.js +1 -10
  222. package/dist/utilities.cjs +1 -36
  223. package/dist/utilities.js +1 -7
  224. package/dist/vm.cjs +1 -295
  225. package/dist/vm.cjs.map +1 -1
  226. package/dist/vm.d.cts +22 -10
  227. package/dist/vm.d.ts +22 -10
  228. package/dist/vm.js +1 -193
  229. package/dist/vm.js.map +1 -1
  230. package/dist/worker.cjs +2 -492
  231. package/dist/worker.cjs.map +1 -1
  232. package/dist/worker.d.cts +16 -17
  233. package/dist/worker.d.ts +16 -17
  234. package/dist/worker.js +2 -483
  235. package/dist/worker.js.map +1 -1
  236. package/package.json +1 -13
  237. package/dist/chunk-3BOK2LDK.js +0 -17
  238. package/dist/chunk-3BOK2LDK.js.map +0 -1
  239. package/dist/chunk-3VGDNEE3.js +0 -84
  240. package/dist/chunk-3VGDNEE3.js.map +0 -1
  241. package/dist/chunk-4K5W7EH2.cjs +0 -112
  242. package/dist/chunk-4K5W7EH2.cjs.map +0 -1
  243. package/dist/chunk-5EFKSKMA.js +0 -413
  244. package/dist/chunk-5EFKSKMA.js.map +0 -1
  245. package/dist/chunk-5HRB36DK.js +0 -405
  246. package/dist/chunk-5HRB36DK.js.map +0 -1
  247. package/dist/chunk-5ON7PUAZ.js +0 -12
  248. package/dist/chunk-5ON7PUAZ.js.map +0 -1
  249. package/dist/chunk-7AXJNQMF.cjs +0 -297
  250. package/dist/chunk-7AXJNQMF.cjs.map +0 -1
  251. package/dist/chunk-7JM3F4KL.js +0 -1795
  252. package/dist/chunk-7JM3F4KL.js.map +0 -1
  253. package/dist/chunk-7USV76HV.cjs +0 -341
  254. package/dist/chunk-7USV76HV.cjs.map +0 -1
  255. package/dist/chunk-A2DZ5BEJ.cjs +0 -1930
  256. package/dist/chunk-A2DZ5BEJ.cjs.map +0 -1
  257. package/dist/chunk-ADBA3XBE.cjs +0 -20
  258. package/dist/chunk-ADBA3XBE.cjs.map +0 -1
  259. package/dist/chunk-AKNGX4TZ.cjs +0 -236
  260. package/dist/chunk-AKNGX4TZ.cjs.map +0 -1
  261. package/dist/chunk-ALYRJ72W.cjs +0 -434
  262. package/dist/chunk-ALYRJ72W.cjs.map +0 -1
  263. package/dist/chunk-AMOJYLG2.cjs +0 -1692
  264. package/dist/chunk-AMOJYLG2.cjs.map +0 -1
  265. package/dist/chunk-AOH6UR2L.js +0 -825
  266. package/dist/chunk-AOH6UR2L.js.map +0 -1
  267. package/dist/chunk-AQNHHJMJ.cjs +0 -261
  268. package/dist/chunk-B7LXJ6LC.cjs +0 -36
  269. package/dist/chunk-B7LXJ6LC.cjs.map +0 -1
  270. package/dist/chunk-BESTLPRK.cjs +0 -6919
  271. package/dist/chunk-BESTLPRK.cjs.map +0 -1
  272. package/dist/chunk-BLI4NIQY.js +0 -98
  273. package/dist/chunk-BLI4NIQY.js.map +0 -1
  274. package/dist/chunk-BSPXMGIS.js +0 -455
  275. package/dist/chunk-BSPXMGIS.js.map +0 -1
  276. package/dist/chunk-C2OMO3WN.cjs +0 -2806
  277. package/dist/chunk-C2OMO3WN.cjs.map +0 -1
  278. package/dist/chunk-CSDQMDU2.js +0 -204
  279. package/dist/chunk-CSDQMDU2.js.map +0 -1
  280. package/dist/chunk-EJ3ILXX6.cjs +0 -223
  281. package/dist/chunk-EJ3ILXX6.cjs.map +0 -1
  282. package/dist/chunk-ENRIK36Q.cjs +0 -94
  283. package/dist/chunk-ENRIK36Q.cjs.map +0 -1
  284. package/dist/chunk-F4UB4XIL.js +0 -109
  285. package/dist/chunk-F4UB4XIL.js.map +0 -1
  286. package/dist/chunk-FD5ZZHEU.js +0 -92
  287. package/dist/chunk-FD5ZZHEU.js.map +0 -1
  288. package/dist/chunk-FE4RC37D.js +0 -2801
  289. package/dist/chunk-FE4RC37D.js.map +0 -1
  290. package/dist/chunk-FEAIOR7N.cjs +0 -91
  291. package/dist/chunk-FEAIOR7N.cjs.map +0 -1
  292. package/dist/chunk-FR7RNOPT.cjs +0 -3303
  293. package/dist/chunk-FR7RNOPT.cjs.map +0 -1
  294. package/dist/chunk-G2YPPLGX.cjs +0 -484
  295. package/dist/chunk-G2YPPLGX.cjs.map +0 -1
  296. package/dist/chunk-GCM5JHMX.js +0 -88
  297. package/dist/chunk-GCM5JHMX.js.map +0 -1
  298. package/dist/chunk-GDEU72RG.cjs +0 -829
  299. package/dist/chunk-GDEU72RG.cjs.map +0 -1
  300. package/dist/chunk-HKTQCQ4Z.cjs +0 -8383
  301. package/dist/chunk-HKTQCQ4Z.cjs.map +0 -1
  302. package/dist/chunk-HWHU642X.cjs +0 -316
  303. package/dist/chunk-HWHU642X.cjs.map +0 -1
  304. package/dist/chunk-ICEKS6YC.cjs +0 -507
  305. package/dist/chunk-ICEKS6YC.cjs.map +0 -1
  306. package/dist/chunk-IJGOFP2J.js +0 -6904
  307. package/dist/chunk-IJGOFP2J.js.map +0 -1
  308. package/dist/chunk-IQJGDZOP.js +0 -333
  309. package/dist/chunk-IQJGDZOP.js.map +0 -1
  310. package/dist/chunk-IT74O4BE.cjs +0 -456
  311. package/dist/chunk-IT74O4BE.cjs.map +0 -1
  312. package/dist/chunk-KXDQKVNX.cjs +0 -459
  313. package/dist/chunk-KXDQKVNX.cjs.map +0 -1
  314. package/dist/chunk-L2TE7PMO.cjs +0 -14
  315. package/dist/chunk-L2TE7PMO.cjs.map +0 -1
  316. package/dist/chunk-L5YHV6BQ.js +0 -499
  317. package/dist/chunk-L5YHV6BQ.js.map +0 -1
  318. package/dist/chunk-LO7HU5WB.cjs +0 -209
  319. package/dist/chunk-LO7HU5WB.cjs.map +0 -1
  320. package/dist/chunk-LSALB3IN.js +0 -292
  321. package/dist/chunk-LSALB3IN.js.map +0 -1
  322. package/dist/chunk-MI7OTUHL.cjs +0 -339
  323. package/dist/chunk-MI7OTUHL.cjs.map +0 -1
  324. package/dist/chunk-MIGXCBXT.cjs +0 -381
  325. package/dist/chunk-MIGXCBXT.cjs.map +0 -1
  326. package/dist/chunk-MVTOCRV2.js +0 -213
  327. package/dist/chunk-MVTOCRV2.js.map +0 -1
  328. package/dist/chunk-N7FNVFXW.cjs +0 -32
  329. package/dist/chunk-N7FNVFXW.cjs.map +0 -1
  330. package/dist/chunk-N7OA4WPJ.js +0 -362
  331. package/dist/chunk-N7OA4WPJ.js.map +0 -1
  332. package/dist/chunk-NAWZATKT.js +0 -478
  333. package/dist/chunk-NAWZATKT.js.map +0 -1
  334. package/dist/chunk-NLNDMWZC.js +0 -31
  335. package/dist/chunk-NLNDMWZC.js.map +0 -1
  336. package/dist/chunk-ORM7CHYZ.js +0 -1531
  337. package/dist/chunk-ORM7CHYZ.js.map +0 -1
  338. package/dist/chunk-OUHT5Z36.cjs +0 -393
  339. package/dist/chunk-OUHT5Z36.cjs.map +0 -1
  340. package/dist/chunk-PCZVMMWU.cjs +0 -74
  341. package/dist/chunk-PCZVMMWU.cjs.map +0 -1
  342. package/dist/chunk-RNKDIXDV.js +0 -336
  343. package/dist/chunk-RNKDIXDV.js.map +0 -1
  344. package/dist/chunk-SBUFNJVE.js +0 -258
  345. package/dist/chunk-SBUFNJVE.js.map +0 -1
  346. package/dist/chunk-TC6BTUSU.cjs +0 -1799
  347. package/dist/chunk-TC6BTUSU.cjs.map +0 -1
  348. package/dist/chunk-TPOK3UNI.js +0 -8355
  349. package/dist/chunk-TPOK3UNI.js.map +0 -1
  350. package/dist/chunk-UF6JG5SG.js +0 -312
  351. package/dist/chunk-UF6JG5SG.js.map +0 -1
  352. package/dist/chunk-UKQHXPGW.js +0 -30
  353. package/dist/chunk-UKQHXPGW.js.map +0 -1
  354. package/dist/chunk-V4XG5QF6.js +0 -1685
  355. package/dist/chunk-V4XG5QF6.js.map +0 -1
  356. package/dist/chunk-VEKIWQ3F.cjs +0 -39
  357. package/dist/chunk-VEKIWQ3F.cjs.map +0 -1
  358. package/dist/chunk-WMQRJTAO.js +0 -3266
  359. package/dist/chunk-WMQRJTAO.js.map +0 -1
  360. package/dist/chunk-X6K3HUOY.cjs +0 -86
  361. package/dist/chunk-X6K3HUOY.cjs.map +0 -1
  362. package/dist/chunk-XBTEO4OB.js +0 -391
  363. package/dist/chunk-XBTEO4OB.js.map +0 -1
  364. package/dist/chunk-XIYYHA65.cjs +0 -101
  365. package/dist/chunk-XIYYHA65.cjs.map +0 -1
  366. package/dist/chunk-YJHY7CMN.cjs +0 -1534
  367. package/dist/chunk-YLJ4XMA6.js +0 -33
  368. package/dist/chunk-YLJ4XMA6.js.map +0 -1
  369. package/dist/chunk-YNIWOYW6.js +0 -232
  370. package/dist/chunk-YNIWOYW6.js.map +0 -1
  371. package/dist/chunk-Z2XP767T.cjs +0 -35
  372. package/dist/chunk-Z2XP767T.cjs.map +0 -1
  373. package/dist/chunk-Z4X2RWOF.js +0 -37
  374. package/dist/chunk-Z4X2RWOF.js.map +0 -1
  375. package/dist/chunk-ZN6YYPIW.js +0 -67
  376. package/dist/chunk-ZN6YYPIW.js.map +0 -1
  377. package/dist/chunk-ZNFFTYWH.js +0 -1854
  378. package/dist/chunk-ZNFFTYWH.js.map +0 -1
  379. package/dist/variables.cjs +0 -17
  380. package/dist/variables.cjs.map +0 -1
  381. package/dist/variables.d.cts +0 -87
  382. package/dist/variables.d.ts +0 -87
  383. package/dist/variables.js +0 -4
  384. package/dist/variables.js.map +0 -1
@@ -1,1799 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkBESTLPRK_cjs = require('./chunk-BESTLPRK.cjs');
4
- var chunkL2TE7PMO_cjs = require('./chunk-L2TE7PMO.cjs');
5
- var chunkADBA3XBE_cjs = require('./chunk-ADBA3XBE.cjs');
6
- var chunkFR7RNOPT_cjs = require('./chunk-FR7RNOPT.cjs');
7
- var chunkIT74O4BE_cjs = require('./chunk-IT74O4BE.cjs');
8
- var chunkLO7HU5WB_cjs = require('./chunk-LO7HU5WB.cjs');
9
- var chunk7USV76HV_cjs = require('./chunk-7USV76HV.cjs');
10
- var chunkMIGXCBXT_cjs = require('./chunk-MIGXCBXT.cjs');
11
-
12
- // src/engine/SegmentTree.ts
13
- var SegmentTree = class {
14
- constructor() {
15
- this.root = null;
16
- }
17
- // ── Public API ───────────────────────────────────────────────────────
18
- /** Total number of elements in the tree. */
19
- get length() {
20
- return this.root ? this.root.size : 0;
21
- }
22
- /** Whether the tree is empty. */
23
- get isEmpty() {
24
- return this.root === null;
25
- }
26
- /**
27
- * Get the lineId at the given 0-based index.
28
- * Returns undefined if index is out of bounds.
29
- * O(log N) expected.
30
- */
31
- getAt(index) {
32
- if (index < 0 || index >= (this.root?.size ?? 0)) return void 0;
33
- return this.nodeAt(this.root, index).lineId;
34
- }
35
- /**
36
- * Insert a single lineId at the given 0-based index.
37
- * O(log N) expected.
38
- */
39
- insertAt(index, lineId) {
40
- const [left, right] = split(this.root, index);
41
- this.root = merge(merge(left, createNode(lineId)), right);
42
- }
43
- /**
44
- * Delete a single element at the given 0-based index.
45
- * Returns the removed lineId, or undefined if out of bounds.
46
- * O(log N) expected.
47
- */
48
- deleteAt(index) {
49
- if (index < 0 || index >= (this.root?.size ?? 0)) return void 0;
50
- const [left, midRight] = split(this.root, index);
51
- const [mid, right] = split(midRight, 1);
52
- const removed = mid ? mid.lineId : void 0;
53
- this.root = merge(left, right);
54
- return removed;
55
- }
56
- /**
57
- * Bulk splice: delete `deleteCount` elements at `startIndex` (0-based),
58
- * then insert `newIds` in their place.
59
- *
60
- * Returns the removed lineId array.
61
- * O(log N + deleteCount + insertCount) expected.
62
- */
63
- spliceAt(startIndex, deleteCount, newIds) {
64
- const clampedStart = Math.max(0, startIndex);
65
- const clampedCount = Math.min(
66
- Math.max(0, deleteCount),
67
- (this.root?.size ?? 0) - clampedStart
68
- );
69
- const [left, midRight] = split(this.root, clampedStart);
70
- const [mid, right] = split(midRight, clampedCount);
71
- const removed = collectInOrder(mid);
72
- const newTree = buildTreap(newIds, 0, newIds.length);
73
- this.root = merge(merge(left, newTree), right);
74
- return removed;
75
- }
76
- /**
77
- * Replace the entire tree with a new set of lineIds.
78
- * O(N), builds a balanced treap from a flat array.
79
- */
80
- replaceAll(lineIds) {
81
- this.root = buildTreap(lineIds, 0, lineIds.length);
82
- }
83
- /**
84
- * Get a contiguous range of lineIds by index.
85
- * O(rangeSize + log N), single in-order walk instead of N × O(log N).
86
- *
87
- * This is the hot path for viewport rendering in DocumentModel.getVisibleLines().
88
- */
89
- getRange(startIndex, endIndex) {
90
- const clampedStart = Math.max(0, startIndex);
91
- const clampedEnd = Math.min((this.root?.size ?? 0) - 1, endIndex);
92
- if (clampedStart > clampedEnd) return [];
93
- const result = [];
94
- this.collectRange(this.root, clampedStart, clampedEnd, 0, result);
95
- return result;
96
- }
97
- /**
98
- * Clear the tree.
99
- */
100
- clear() {
101
- this.root = null;
102
- }
103
- // ── Iteration ─────────────────────────────────────────────────────────
104
- /**
105
- * In-order iterator yielding all lineIds.
106
- */
107
- *[Symbol.iterator]() {
108
- yield* this.inOrder(this.root);
109
- }
110
- *inOrder(node) {
111
- if (!node) return;
112
- yield* this.inOrder(node.left);
113
- yield node.lineId;
114
- yield* this.inOrder(node.right);
115
- }
116
- // ── Private helpers ───────────────────────────────────────────────────
117
- nodeAt(node, index) {
118
- const leftSize = node.left ? node.left.size : 0;
119
- if (index < leftSize) {
120
- return this.nodeAt(node.left, index);
121
- } else if (index === leftSize) {
122
- return node;
123
- } else {
124
- return this.nodeAt(node.right, index - leftSize - 1);
125
- }
126
- }
127
- /**
128
- * Collect all node values in the range [targetStart, targetEnd] into result.
129
- * `offset` is the 0-based start of the current subtree within the full tree.
130
- * O(rangeSize + log N), skips entire subtrees outside the target range.
131
- */
132
- collectRange(node, targetStart, targetEnd, offset, result) {
133
- if (!node) return;
134
- const leftSize = node.left ? node.left.size : 0;
135
- const nodeIndex = offset + leftSize;
136
- if (nodeIndex > targetStart && node.left) {
137
- this.collectRange(node.left, targetStart, targetEnd, offset, result);
138
- }
139
- if (nodeIndex >= targetStart && nodeIndex <= targetEnd) {
140
- result.push(node.lineId);
141
- }
142
- if (nodeIndex < targetEnd && node.right) {
143
- this.collectRange(node.right, targetStart, targetEnd, nodeIndex + 1, result);
144
- }
145
- }
146
- };
147
- function createNode(lineId) {
148
- return {
149
- lineId,
150
- size: 1,
151
- priority: Math.random(),
152
- left: null,
153
- right: null
154
- };
155
- }
156
- function updateSize(node) {
157
- node.size = 1 + (node.left ? node.left.size : 0) + (node.right ? node.right.size : 0);
158
- }
159
- function merge(left, right) {
160
- if (!left) return right;
161
- if (!right) return left;
162
- if (left.priority > right.priority) {
163
- left.right = merge(left.right, right);
164
- updateSize(left);
165
- return left;
166
- } else {
167
- right.left = merge(left, right.left);
168
- updateSize(right);
169
- return right;
170
- }
171
- }
172
- function split(node, index) {
173
- if (!node) return [null, null];
174
- const leftSize = node.left ? node.left.size : 0;
175
- if (index <= leftSize) {
176
- const [left, right] = split(node.left, index);
177
- node.left = right;
178
- updateSize(node);
179
- return [left, node];
180
- } else {
181
- const [left, right] = split(node.right, index - leftSize - 1);
182
- node.right = left;
183
- updateSize(node);
184
- return [node, right];
185
- }
186
- }
187
- function collectInOrder(node) {
188
- const result = [];
189
- collect(node, result);
190
- return result;
191
- }
192
- function collect(node, result) {
193
- if (!node) return;
194
- collect(node.left, result);
195
- result.push(node.lineId);
196
- collect(node.right, result);
197
- }
198
- function buildTreap(lineIds, start, end) {
199
- if (start >= end) return null;
200
- const mid = Math.floor((start + end) / 2);
201
- const priority = pseudoRandom(mid);
202
- const node = {
203
- lineId: lineIds[mid],
204
- size: end - start,
205
- priority,
206
- left: buildTreap(lineIds, start, mid),
207
- right: buildTreap(lineIds, mid + 1, end)
208
- };
209
- return node;
210
- }
211
- function pseudoRandom(seed) {
212
- let x = seed;
213
- x = (x >> 16 ^ x) * 73244475;
214
- x = (x >> 16 ^ x) * 73244475;
215
- x = x >> 16 ^ x;
216
- return x / 4294967295;
217
- }
218
-
219
- // src/engine/DocumentModel.ts
220
- var DocumentModel = class {
221
- /**
222
- * @param maxLines - Ceiling on the line count, defaulting to the engine's
223
- * configured one. Every line costs a LineState with six arrays in it
224
- * whatever the line says, so the cost of a document is its line count and
225
- * nothing else bounds it: two hundred thousand lines of `1 + 1` exhausted
226
- * the heap here, before a single expression had been looked at.
227
- */
228
- constructor(maxLines = chunkLO7HU5WB_cjs.DEFAULT_CONFIG.performance.maxDocumentLines) {
229
- /** Persistent line ID → LineState. */
230
- this.lines = /* @__PURE__ */ new Map();
231
- /** Order-statistic treap representing the current document line order. */
232
- this.orderTree = new SegmentTree();
233
- /** Monotonically increasing counter for new line IDs. */
234
- this.nextLineId = 1;
235
- /**
236
- * Lazy position cache: lineId → 1-based position.
237
- * Built on first `getLinePosition()` call, invalidated on structural edits.
238
- */
239
- this._positionCache = null;
240
- /**
241
- * Line IDs currently marked dirty, maintained alongside every
242
- * `state.dirty` mutation (in this class and in every other module that
243
- * holds a direct `LineState` reference: ThreeTierEvaluator, PageManager).
244
- * Lets {@link hasAnyDirtyLineBefore} answer "is anything before position
245
- * X dirty" in O(d log N), d = current dirty count, typically tiny once
246
- * a document has settled after its initial evaluation, instead of
247
- * O(N log N), which used to mean every scroll event re-walked the WHOLE
248
- * document via `getLineAt()` regardless of how little of it was actually
249
- * dirty. Benchmarked: ~10.6ms per setViewport() call scrolled near the
250
- * bottom of a 20k-line document before this fix.
251
- */
252
- this.dirtyLineIds = /* @__PURE__ */ new Set();
253
- this.maxLines = maxLines;
254
- }
255
- // ── Initialization ──────────────────────────────────────────────────
256
- /**
257
- * Initialize or replace the entire document from a text blob.
258
- * Clears all existing state and assigns new persistent line IDs.
259
- *
260
- * @throws `DOCUMENT_TOO_LARGE` for a document past {@link maxLines}, before
261
- * any of it is stored. Recoverable: nothing has been replaced yet, so the
262
- * model still holds whatever it held.
263
- */
264
- setDocument(text) {
265
- const lineCount = chunkADBA3XBE_cjs.countLines(text, this.maxLines);
266
- if (lineCount > this.maxLines) {
267
- throw chunkMIGXCBXT_cjs.ErrorFactory.execution(
268
- "DOCUMENT_TOO_LARGE",
269
- `This document has more than ${this.maxLines.toLocaleString("en-US")} lines, which is the most the engine will hold at once`,
270
- { maxLines: this.maxLines }
271
- );
272
- }
273
- this.lines.clear();
274
- this.orderTree.clear();
275
- this._positionCache = null;
276
- this.dirtyLineIds.clear();
277
- this.nextLineId = 1;
278
- const rawLines = text.split("\n");
279
- const lineIds = new Array(rawLines.length);
280
- for (let i = 0; i < rawLines.length; i++) {
281
- const lineId = this.nextLineId++;
282
- lineIds[i] = lineId;
283
- this.lines.set(lineId, {
284
- lineId,
285
- textHash: chunkL2TE7PMO_cjs.djb2Hash(rawLines[i]),
286
- text: rawLines[i],
287
- expressions: [],
288
- bytecodes: [],
289
- reads: [],
290
- writes: [],
291
- results: [],
292
- result: null,
293
- dirty: true,
294
- isVariableDef: false,
295
- isEmpty: rawLines[i].trim().length === 0,
296
- inlineSolveCount: 0
297
- });
298
- }
299
- this.orderTree.replaceAll(lineIds);
300
- for (const id of lineIds) this.dirtyLineIds.add(id);
301
- }
302
- // ── Structural edits ────────────────────────────────────────────────
303
- /**
304
- * Apply one or more line-level changes to the document.
305
- *
306
- * **Precondition:** Changes must be **non-overlapping** in their line ranges.
307
- * If two changes target the same or adjacent lines, the reverse-order
308
- * processing may produce incorrect results because the first-applied
309
- * change shifts the line numbers that the second change references.
310
- *
311
- * Changes are applied in **reverse order** (highest startLine first) so
312
- * that earlier changes in the document don't shift the indices of later
313
- * changes during processing.
314
- *
315
- * Returns both the newly inserted line IDs and the removed line IDs.
316
- * Callers should use `removed` to clean up the dependency graph and
317
- * other data structures keyed by lineId.
318
- */
319
- applyChanges(changes) {
320
- const inserted = [];
321
- const removed = [];
322
- const sorted = [...changes].sort((a, b) => b.startLine - a.startLine);
323
- for (const change of sorted) {
324
- const startIdx = change.startLine - 1;
325
- const newIds = [];
326
- for (const text of change.insertLines) {
327
- const lineId = this.nextLineId++;
328
- newIds.push(lineId);
329
- inserted.push(lineId);
330
- this.lines.set(lineId, {
331
- lineId,
332
- textHash: chunkL2TE7PMO_cjs.djb2Hash(text),
333
- text,
334
- expressions: [],
335
- bytecodes: [],
336
- reads: [],
337
- writes: [],
338
- results: [],
339
- result: null,
340
- dirty: true,
341
- isVariableDef: false,
342
- isEmpty: text.trim().length === 0,
343
- inlineSolveCount: 0
344
- });
345
- }
346
- for (const id of newIds) this.dirtyLineIds.add(id);
347
- const removedIds = this.orderTree.spliceAt(
348
- startIdx,
349
- change.deleteCount,
350
- newIds
351
- );
352
- for (const id of removedIds) {
353
- removed.push(id);
354
- this.lines.delete(id);
355
- this.dirtyLineIds.delete(id);
356
- }
357
- }
358
- this._positionCache = null;
359
- return { inserted, removed };
360
- }
361
- /**
362
- * Insert new lines at the given 1-based position.
363
- * Convenience wrapper around applyChanges.
364
- */
365
- insertLines(atLine, texts) {
366
- const change = {
367
- startLine: atLine,
368
- deleteCount: 0,
369
- insertLines: texts
370
- };
371
- const result = this.applyChanges([change]);
372
- return result.inserted;
373
- }
374
- /**
375
- * Delete lines in the given 1-based range [startLine, endLine] inclusive.
376
- * Convenience wrapper around applyChanges.
377
- */
378
- deleteLines(startLine, endLine) {
379
- const change = {
380
- startLine,
381
- deleteCount: endLine - startLine + 1,
382
- insertLines: []
383
- };
384
- const result = this.applyChanges([change]);
385
- return result.removed;
386
- }
387
- /**
388
- * Update the text of a single line in place.
389
- * If the text hash differs, marks the line dirty and clears its
390
- * bytecode/result so it gets re-evaluated.
391
- *
392
- * Returns true if the text actually changed (hash mismatch).
393
- */
394
- editLine(lineNumber, newText) {
395
- const state = this.getLineAt(lineNumber);
396
- if (!state) return false;
397
- const newHash = chunkL2TE7PMO_cjs.djb2Hash(newText);
398
- if (newHash === state.textHash) return false;
399
- state.text = newText;
400
- state.textHash = newHash;
401
- state.expressions = [];
402
- state.bytecodes = [];
403
- state.results = [];
404
- state.result = null;
405
- state.inlineSolveCount = 0;
406
- state.dirty = true;
407
- this.dirtyLineIds.add(state.lineId);
408
- state.isEmpty = newText.trim().length === 0;
409
- return true;
410
- }
411
- // ── Queries ─────────────────────────────────────────────────────────
412
- /**
413
- * Get the LineState at the given 1-based line position. O(1).
414
- */
415
- getLineAt(position) {
416
- const idx = position - 1;
417
- const lineId = this.orderTree.getAt(idx);
418
- if (lineId === void 0) return void 0;
419
- return this.lines.get(lineId);
420
- }
421
- /**
422
- * Get the 1-based position of a line by its persistent ID.
423
- * Returns -1 if the line ID is not in the document.
424
- *
425
- * Uses a lazy position cache: O(N) on first call after structural edit,
426
- * O(1) on subsequent calls. The cache is invalidated by any structural edit.
427
- */
428
- getLinePosition(lineId) {
429
- if (this._positionCache) {
430
- return this._positionCache.get(lineId) ?? -1;
431
- }
432
- this._positionCache = /* @__PURE__ */ new Map();
433
- let pos = 1;
434
- for (const id of this.orderTree) {
435
- this._positionCache.set(id, pos++);
436
- }
437
- return this._positionCache.get(lineId) ?? -1;
438
- }
439
- /**
440
- * Get all LineState entries within the given viewport range (1-based, inclusive).
441
- * Uses SegmentTree.getRange() for O(viewport + log N) collection instead of
442
- * O(viewport × log N) per-line lookups.
443
- */
444
- getVisibleLines(startLine, endLine) {
445
- const lineIds = this.orderTree.getRange(startLine - 1, endLine - 1);
446
- const result = [];
447
- for (const lineId of lineIds) {
448
- const state = this.lines.get(lineId);
449
- if (state) result.push(state);
450
- }
451
- return result;
452
- }
453
- /**
454
- * Get all LineState entries in order. Useful for batch processing.
455
- */
456
- getAllLines() {
457
- return this.getVisibleLines(1, this.lineCount);
458
- }
459
- /**
460
- * Get a LineState by its persistent line ID. O(1).
461
- */
462
- getLineById(lineId) {
463
- return this.lines.get(lineId);
464
- }
465
- /**
466
- * Get all lines that are marked dirty.
467
- */
468
- getDirtyLines() {
469
- const result = [];
470
- for (const state of this.lines.values()) {
471
- if (state.dirty) result.push(state);
472
- }
473
- return result;
474
- }
475
- /**
476
- * Whether any line before `position` (1-based, exclusive) is dirty.
477
- *
478
- * Used by ThreeTierEvaluator.setViewport() to decide whether cached
479
- * checkpoint state might be stale and a full evaluate() (from line 1) is
480
- * needed instead of the cheap viewport-only path.
481
- *
482
- * O(d log N) where d = current dirty line count via {@link dirtyLineIds},
483
- * not O(N log N), a document that's mostly clean (the steady state after
484
- * initial load) answers this in the cost of resolving a handful of
485
- * lineIds to positions, not walking every line up to `position`.
486
- */
487
- hasAnyDirtyLineBefore(position) {
488
- for (const lineId of this.dirtyLineIds) {
489
- const pos = this.getLinePosition(lineId);
490
- if (pos >= 1 && pos < position) return true;
491
- }
492
- return false;
493
- }
494
- /**
495
- * Whether any **variable-definition** line before `position` (1-based,
496
- * exclusive) is dirty.
497
- *
498
- * Narrower than {@link hasAnyDirtyLineBefore}: `VMCheckpointer.snapshot()`
499
- * only ever records state for lines with `writes.length > 0` (see
500
- * VMCheckpoints.ts), so a dirty plain-expression line before the viewport
501
- * cannot have invalidated any checkpoint, there's no checkpoint entry
502
- * for it to invalidate. Only a dirty variable-def line can mean the VM
503
- * state a checkpoint would restore is stale.
504
- *
505
- * This distinction matters because `PageManager.evictPageBytecode()`
506
- * marks evicted non-variable-def lines dirty (so they get Tier 1 if
507
- * scrolled back into view), and Tier 3's compile-only path never clears
508
- * `dirty` for non-variable-def lines by design. Using the broader
509
- * `hasAnyDirtyLineBefore` here meant scrolling far into a large,
510
- * variable-def-free document would trip `setViewport()`'s fallback to
511
- * `evaluate()` on every single call, evaluate() reprocesses the evicted
512
- * lines via Tier 3, which recompiles their bytecode without clearing
513
- * dirty, so the very next `maintainAfterEval()` re-evicts and re-dirties
514
- * the same lines, forever re-triggering the fallback on an otherwise
515
- * unchanged viewport.
516
- */
517
- hasAnyDirtyVariableDefLineBefore(position) {
518
- for (const lineId of this.dirtyLineIds) {
519
- const state = this.lines.get(lineId);
520
- if (!state || !state.isVariableDef) continue;
521
- const pos = this.getLinePosition(lineId);
522
- if (pos >= 1 && pos < position) return true;
523
- }
524
- return false;
525
- }
526
- /** Number of lines currently marked dirty. For diagnostics/tests. */
527
- get dirtyCount() {
528
- return this.dirtyLineIds.size;
529
- }
530
- // ── Thread-safety validation ────────────────────────────────────────
531
- /**
532
- * Verify that bytecode compiled by a worker is still valid for this line.
533
- *
534
- * When Phase 5.2h sends compilation to a worker, the worker posts back
535
- * `{lineId, bytecode, reads, writes, compiledAgainstHash}`. Between dispatch
536
- * and response, the user may have edited the line. This method lets the
537
- * main thread check whether the bytecode is still applicable.
538
- *
539
- * @returns true if the line still exists and its text hash matches.
540
- */
541
- isBytecodeValid(lineId, compiledAgainstHash) {
542
- const state = this.lines.get(lineId);
543
- return state !== void 0 && state.textHash === compiledAgainstHash;
544
- }
545
- // ── State mutations ─────────────────────────────────────────────────
546
- /**
547
- * Mark a line as clean (re-evaluated successfully).
548
- */
549
- markClean(lineId) {
550
- const state = this.lines.get(lineId);
551
- if (state) {
552
- state.dirty = false;
553
- this.dirtyLineIds.delete(lineId);
554
- }
555
- }
556
- /**
557
- * Mark a line as dirty (needs re-evaluation) by its 1-based position.
558
- * Convenience for callers that have line numbers instead of line IDs.
559
- */
560
- markDirtyByLineNumber(lineNumber) {
561
- const state = this.getLineAt(lineNumber);
562
- if (state) {
563
- state.dirty = true;
564
- this.dirtyLineIds.add(state.lineId);
565
- }
566
- }
567
- /**
568
- * Mark a line as dirty (needs re-evaluation).
569
- */
570
- markDirty(lineId) {
571
- const state = this.lines.get(lineId);
572
- if (state) {
573
- state.dirty = true;
574
- this.dirtyLineIds.add(lineId);
575
- }
576
- }
577
- /**
578
- * Mark all lines as dirty (e.g., after plugin register/unregister).
579
- */
580
- invalidateAll() {
581
- for (const state of this.lines.values()) {
582
- state.dirty = true;
583
- }
584
- this.dirtyLineIds = new Set(this.lines.keys());
585
- }
586
- /**
587
- * Update a line's evaluation state after successful execution (Tier 1 / Tier 2).
588
- *
589
- * Sets results, bytecodes, reads, writes, and marks the line clean.
590
- * Supports multi-expression lines (inline solves) via parallel arrays.
591
- *
592
- * @param lineId - Persistent line identifier.
593
- * @param results - Evaluation result groups for each expression (in order). Each element is a Value[].
594
- * @param bytecodes - Compiled bytecode for each expression (in order).
595
- * @param expressions - Extracted expression strings (in order).
596
- * @param reads - Aggregated read variables across all expressions.
597
- * @param writes - Aggregated write variables across all expressions.
598
- * @param isVariableDef - True if any expression defines a variable.
599
- * @param inlineSolveCount - Number of inline solves (0 for full-line).
600
- */
601
- updateLineResult(lineId, results, bytecodes, expressions, reads, writes, isVariableDef, inlineSolveCount = 0) {
602
- const state = this.lines.get(lineId);
603
- if (!state) return;
604
- state.results = results;
605
- state.result = results[0]?.[0] ?? null;
606
- state.bytecodes = bytecodes;
607
- state.expressions = expressions;
608
- state.reads = reads;
609
- state.writes = writes;
610
- state.isVariableDef = isVariableDef;
611
- state.inlineSolveCount = inlineSolveCount;
612
- state.dirty = false;
613
- this.dirtyLineIds.delete(lineId);
614
- }
615
- /**
616
- * Update a line's compile-only state (Tier 3: background compilation).
617
- *
618
- * Stores expressions, bytecodes, reads, and writes. Does NOT set results
619
- * and does NOT mark the line clean, it still needs execution (Tier 1 or
620
- * Tier 2) to produce results. This distinction allows the three-tier
621
- * evaluation strategy: compile invisible lines in the background without
622
- * executing them, then execute from cached bytecode when scrolled into view.
623
- *
624
- * @param lineId - Persistent line identifier.
625
- * @param expressions - Extracted expression strings (in order).
626
- * @param bytecodes - Compiled bytecode for each expression (in order).
627
- * @param reads - Aggregated read variables across all expressions.
628
- * @param writes - Aggregated write variables across all expressions.
629
- * @param isVariableDef - True if any expression defines a variable.
630
- * @param inlineSolveCount - Number of inline solves (0 for full-line).
631
- */
632
- updateLineCompiled(lineId, expressions, bytecodes, reads, writes, isVariableDef, inlineSolveCount = 0) {
633
- const state = this.lines.get(lineId);
634
- if (!state) return;
635
- state.expressions = expressions;
636
- state.bytecodes = bytecodes;
637
- state.reads = reads;
638
- state.writes = writes;
639
- state.isVariableDef = isVariableDef;
640
- state.inlineSolveCount = inlineSolveCount;
641
- }
642
- // ── Properties ──────────────────────────────────────────────────────
643
- get lineCount() {
644
- return this.orderTree.length;
645
- }
646
- get isEmpty() {
647
- return this.orderTree.isEmpty;
648
- }
649
- /**
650
- * Iterator over LineState in document order.
651
- */
652
- *[Symbol.iterator]() {
653
- for (const lineId of this.orderTree) {
654
- const state = this.lines.get(lineId);
655
- if (state) yield state;
656
- }
657
- }
658
- // ── Lifecycle ───────────────────────────────────────────────────────
659
- clear() {
660
- this.lines.clear();
661
- this.orderTree.clear();
662
- this._positionCache = null;
663
- this.nextLineId = 1;
664
- }
665
- /**
666
- * Serialize the document model to a plain object for debugging.
667
- */
668
- toJSON() {
669
- return {
670
- lineCount: this.lineCount,
671
- lines: this.getAllLines().map((s) => ({
672
- lineId: s.lineId,
673
- text: s.text.substring(0, 80),
674
- // truncate for readability
675
- textHash: s.textHash,
676
- dirty: s.dirty,
677
- isVariableDef: s.isVariableDef,
678
- isEmpty: s.isEmpty,
679
- hasBytecode: s.bytecodes.length > 0,
680
- hasResult: s.results.length > 0,
681
- inlineSolveCount: s.inlineSolveCount,
682
- reads: s.reads,
683
- writes: s.writes
684
- }))
685
- };
686
- }
687
- };
688
-
689
- // src/engine/CompilationWorkerManager.ts
690
- var CompilationWorkerManager = class {
691
- constructor() {
692
- this.worker = null;
693
- this.nextId = 1;
694
- this.pending = /* @__PURE__ */ new Map();
695
- }
696
- /**
697
- * Ensure the worker is started (lazy initialization).
698
- * Uses esbuild-plugin-inline-worker to inline the worker as a blob URL.
699
- */
700
- ensureWorker() {
701
- if (this.worker) return this.worker;
702
- this.worker = chunkBESTLPRK_cjs.engine_worker_default();
703
- this.worker.onmessage = (event) => {
704
- const data = event.data;
705
- if (!data || data.type !== "COMPILE_RESULT") return;
706
- const pending = this.pending.get(data.id);
707
- if (!pending) return;
708
- this.pending.delete(data.id);
709
- const results = [];
710
- for (const raw of data.results) {
711
- results.push(this.reconstructResult(raw));
712
- }
713
- pending.resolve(results);
714
- };
715
- this.worker.onerror = (err) => {
716
- for (const [id, pending] of this.pending) {
717
- pending.reject(
718
- new Error(`Compilation worker error: ${err.message}`)
719
- );
720
- this.pending.delete(id);
721
- }
722
- };
723
- return this.worker;
724
- }
725
- /**
726
- * Batch-compile expressions in the worker.
727
- *
728
- * Sends a batch of { lineId, expression, textHash } to the worker,
729
- * which compiles each and transfers bytecode ArrayBuffers back.
730
- * Bytecode is reconstructed into BytecodeProgram objects.
731
- *
732
- * Results are returned in the same order as the input items.
733
- *
734
- * @param items Expressions to compile.
735
- * @returns Compiled bytecode for each item (or error).
736
- */
737
- async compileBatch(items) {
738
- if (items.length === 0) return [];
739
- const worker = this.ensureWorker();
740
- const id = this.nextId++;
741
- return new Promise((resolve, reject) => {
742
- this.pending.set(id, { resolve, reject });
743
- worker.postMessage({
744
- type: "COMPILE_BATCH",
745
- id,
746
- items
747
- });
748
- });
749
- }
750
- /**
751
- * Store worker-compiled bytecode into the DocumentModel, with safety
752
- * validation. Only stores bytecode for lines whose text has not changed
753
- * since the compilation request was dispatched.
754
- *
755
- * Results for the same lineId are batched, all bytecodes from
756
- * successful compilations are passed to updateLineCompiled in a single
757
- * call. This supports multi-expression lines (inline solves).
758
- *
759
- * @param results Compiled results from the worker.
760
- * @param doc The target document model.
761
- * @returns Number of results successfully stored (passed safety check).
762
- */
763
- storeResults(results, doc) {
764
- const byLineId = /* @__PURE__ */ new Map();
765
- for (const result of results) {
766
- if (result.error) continue;
767
- const state = doc.getLineById(result.lineId);
768
- if (!state) continue;
769
- if (state.textHash !== result.compiledAgainstHash) continue;
770
- let batch = byLineId.get(result.lineId);
771
- if (!batch) {
772
- batch = {
773
- bytecodes: [],
774
- reads: /* @__PURE__ */ new Set(),
775
- writes: /* @__PURE__ */ new Set(),
776
- isVariableDef: false,
777
- expressions: state.expressions.length > 0 ? [...state.expressions] : [],
778
- textHash: result.compiledAgainstHash
779
- };
780
- byLineId.set(result.lineId, batch);
781
- }
782
- batch.bytecodes.push(result.program);
783
- for (const r of result.reads) batch.reads.add(r);
784
- for (const w of result.writes) batch.writes.add(w);
785
- if (result.isVariableDef) batch.isVariableDef = true;
786
- }
787
- let stored = 0;
788
- for (const [lineId, batch] of byLineId) {
789
- if (batch.bytecodes.length === 0) continue;
790
- const state = doc.getLineById(lineId);
791
- const inlineSolveCount = state?.inlineSolveCount ?? 0;
792
- doc.updateLineCompiled(
793
- lineId,
794
- batch.expressions,
795
- batch.bytecodes,
796
- [...batch.reads],
797
- [...batch.writes],
798
- batch.isVariableDef,
799
- inlineSolveCount
800
- );
801
- stored += batch.bytecodes.length;
802
- }
803
- return stored;
804
- }
805
- /**
806
- * Terminate the worker and clean up.
807
- */
808
- terminate() {
809
- if (this.worker) {
810
- this.worker.terminate();
811
- this.worker = null;
812
- this.pending.clear();
813
- }
814
- }
815
- /**
816
- * Whether the worker is currently active.
817
- */
818
- get isActive() {
819
- return this.worker !== null;
820
- }
821
- // ── Private helpers ────────────────────────────────────────────────
822
- /**
823
- * Reconstruct a BytecodeProgram from transferred ArrayBuffers.
824
- *
825
- * The transferred ArrayBuffers are zero-copy, we create TypedArray
826
- * views directly over them. No data is copied or serialized.
827
- */
828
- reconstructResult(raw) {
829
- if (raw.error) {
830
- return {
831
- lineId: raw.lineId,
832
- compiledAgainstHash: raw.compiledAgainstHash,
833
- program: { opcodes: new Uint8Array(0), numbers: new Float64Array(0), strings: [], hasAsync: false },
834
- reads: [],
835
- writes: [],
836
- isVariableDef: false,
837
- error: raw.error
838
- };
839
- }
840
- const opcodes = raw.opcodesLength > 0 ? new Uint8Array(raw.opcodesBuffer, 0, raw.opcodesLength) : new Uint8Array(0);
841
- const numbers = raw.numbersLength > 0 ? new Float64Array(raw.numbersBuffer, 0, raw.numbersLength) : new Float64Array(0);
842
- const program = {
843
- opcodes,
844
- numbers,
845
- strings: raw.strings,
846
- hasAsync: false
847
- };
848
- return {
849
- lineId: raw.lineId,
850
- compiledAgainstHash: raw.compiledAgainstHash,
851
- program,
852
- reads: raw.reads,
853
- writes: raw.writes,
854
- isVariableDef: raw.isVariableDef,
855
- error: null
856
- };
857
- }
858
- };
859
-
860
- // src/engine/PageManager.ts
861
- var PAGE_SIZE = 128;
862
- var HOT_PAGE_RADIUS = 3;
863
- var WARM_PAGE_RADIUS = 6;
864
- var PRELOAD_PAGE_COUNT = 2;
865
- var COLD_EVICT_BUFFER = HOT_PAGE_RADIUS;
866
- var PageManager = class _PageManager {
867
- constructor() {
868
- /** Previous viewport for scroll direction detection. null = no previous viewport. */
869
- this.lastViewportStart = null;
870
- /** Saved scroll direction from the most recent maintainAfterEval call. */
871
- this.savedDirection = null;
872
- /** Per-page access counter for LRU tracking. */
873
- this.pageAccess = /* @__PURE__ */ new Map();
874
- /** Monotonically increasing access sequence number. */
875
- this.accessSeq = 0;
876
- }
877
- // ── Static helpers ─────────────────────────────────────────────────
878
- /** Get the page number for a 1-based line number (0-based page index). */
879
- static pageForLine(lineNumber) {
880
- return Math.floor((lineNumber - 1) / PAGE_SIZE);
881
- }
882
- /** Get the 1-based inclusive line range for a page. */
883
- static pageRange(pageNum, docLineCount) {
884
- return {
885
- startLine: pageNum * PAGE_SIZE + 1,
886
- endLine: Math.min((pageNum + 1) * PAGE_SIZE, docLineCount)
887
- };
888
- }
889
- // ── Public API ─────────────────────────────────────────────────────
890
- /**
891
- * Detect scroll direction from viewport movement.
892
- * Returns null on first call (no previous viewport) or no movement.
893
- */
894
- detectDirection(newViewport) {
895
- if (this.lastViewportStart === null) return null;
896
- if (newViewport.startLine > this.lastViewportStart) return "down";
897
- if (newViewport.startLine < this.lastViewportStart) return "up";
898
- return null;
899
- }
900
- /**
901
- * Maintain page tiers after evaluation.
902
- *
903
- * 1. Records the new viewport position
904
- * 2. Touches hot pages (viewport ± HOT_PAGE_RADIUS) for LRU
905
- * 3. Evicts cold/warm pages based on distance from viewport
906
- *
907
- * Call this after every `evaluate()`, `setViewport()`, or `evaluateAll()`.
908
- */
909
- maintainAfterEval(viewport, doc) {
910
- this.savedDirection = this.detectDirection(viewport);
911
- this.lastViewportStart = viewport.startLine;
912
- const docLineCount = doc.lineCount;
913
- const viewportStartPage = _PageManager.pageForLine(viewport.startLine);
914
- const viewportEndPage = _PageManager.pageForLine(viewport.endLine);
915
- const lastPage = _PageManager.pageForLine(docLineCount);
916
- const hotStart = Math.max(0, viewportStartPage - HOT_PAGE_RADIUS);
917
- const hotEnd = Math.min(lastPage, viewportEndPage + HOT_PAGE_RADIUS);
918
- const warmStart = Math.max(0, viewportStartPage - WARM_PAGE_RADIUS);
919
- const warmEnd = Math.min(lastPage, viewportEndPage + WARM_PAGE_RADIUS);
920
- for (let p = hotStart; p <= hotEnd; p++) {
921
- this.touchPage(p);
922
- }
923
- for (let p = warmStart; p <= warmEnd; p++) {
924
- if (p >= hotStart && p <= hotEnd) continue;
925
- this.evictPageResults(p, doc, docLineCount);
926
- }
927
- const coldLeftEnd = warmStart - 1;
928
- const coldLeftStart = Math.max(0, coldLeftEnd - COLD_EVICT_BUFFER + 1);
929
- for (let p = coldLeftStart; p <= coldLeftEnd; p++) {
930
- this.evictPageBytecode(p, doc, docLineCount);
931
- }
932
- const coldRightStart = warmEnd + 1;
933
- const coldRightEnd = Math.min(lastPage, coldRightStart + COLD_EVICT_BUFFER - 1);
934
- for (let p = coldRightStart; p <= coldRightEnd; p++) {
935
- this.evictPageBytecode(p, doc, docLineCount);
936
- }
937
- }
938
- /**
939
- * Get lines ahead of the viewport that should be pre-compiled.
940
- *
941
- * Looks PRELOAD_PAGE_COUNT pages ahead of the current scroll direction.
942
- * Only returns lines that are dirty, don't already have bytecode,
943
- * and are not empty/markdown-only.
944
- *
945
- * @param viewport The current viewport.
946
- * @param doc The document model.
947
- * @returns Items ready to send to the compilation worker.
948
- */
949
- getPreloadTargets(viewport, doc) {
950
- const direction = this.savedDirection;
951
- if (!direction) return [];
952
- const items = [];
953
- const viewportEndPage = _PageManager.pageForLine(viewport.endLine);
954
- const viewportStartPage = _PageManager.pageForLine(viewport.startLine);
955
- const lastPage = _PageManager.pageForLine(doc.lineCount);
956
- const pages = [];
957
- if (direction === "down") {
958
- const startPage = viewportEndPage + HOT_PAGE_RADIUS + 1;
959
- const endPage = Math.min(startPage + PRELOAD_PAGE_COUNT - 1, lastPage);
960
- for (let p = startPage; p <= endPage && p <= lastPage; p++) {
961
- pages.push(p);
962
- }
963
- } else {
964
- const firstPreloadPage = viewportStartPage - HOT_PAGE_RADIUS - 1;
965
- for (let p = firstPreloadPage; p > firstPreloadPage - PRELOAD_PAGE_COUNT && p >= 0; p--) {
966
- pages.push(p);
967
- }
968
- }
969
- for (const pageNum of pages) {
970
- const range = _PageManager.pageRange(pageNum, doc.lineCount);
971
- for (let pos = range.startLine; pos <= range.endLine; pos++) {
972
- const state = doc.getLineAt(pos);
973
- if (!state) continue;
974
- if (!state.dirty) continue;
975
- if (state.bytecodes.length > 0 && !state.isVariableDef) continue;
976
- if (state.isEmpty) continue;
977
- if (state.expressions.length > 0) {
978
- for (const expression of state.expressions) {
979
- if (!expression.trim()) continue;
980
- items.push({
981
- lineId: state.lineId,
982
- expression,
983
- textHash: state.textHash
984
- });
985
- }
986
- } else {
987
- const inlineSpans = chunk7USV76HV_cjs.sharedLexer.findInlineSolves(state.text);
988
- if (inlineSpans.length > 0) {
989
- for (const span of inlineSpans) {
990
- if (!span.expression.trim()) continue;
991
- items.push({
992
- lineId: state.lineId,
993
- expression: span.expression,
994
- textHash: state.textHash
995
- });
996
- }
997
- } else {
998
- const expression = state.text.trim();
999
- if (expression) {
1000
- items.push({
1001
- lineId: state.lineId,
1002
- expression,
1003
- textHash: state.textHash
1004
- });
1005
- }
1006
- }
1007
- }
1008
- }
1009
- }
1010
- return items;
1011
- }
1012
- /**
1013
- * Reset internal state (e.g., after document switch).
1014
- */
1015
- clear() {
1016
- this.pageAccess.clear();
1017
- this.accessSeq = 0;
1018
- this.lastViewportStart = null;
1019
- this.savedDirection = null;
1020
- }
1021
- // ── Private helpers ─────────────────────────────────────────────────
1022
- /** Record a page access with a monotonic sequence number. */
1023
- touchPage(pageNum) {
1024
- this.pageAccess.set(pageNum, ++this.accessSeq);
1025
- }
1026
- /**
1027
- * Evict results from all non-variable-def lines in a page.
1028
- * Bytecode is preserved so Tier 2 execution works on scroll-back.
1029
- */
1030
- evictPageResults(pageNum, doc, docLineCount) {
1031
- const range = _PageManager.pageRange(pageNum, docLineCount);
1032
- for (let pos = range.startLine; pos <= range.endLine; pos++) {
1033
- const state = doc.getLineAt(pos);
1034
- if (state && !state.isVariableDef && state.results.length > 0) {
1035
- state.results = [];
1036
- state.result = null;
1037
- }
1038
- }
1039
- }
1040
- /**
1041
- * Evict bytecode + results from all non-variable-def lines in a page.
1042
- * Variable definition bytecode is **never** evicted, it forms the
1043
- * backbone of the DAG and VM checkpoints.
1044
- *
1045
- * Evicted lines are marked dirty so they get Tier 1 re-evaluation
1046
- * when scrolled back into view.
1047
- */
1048
- evictPageBytecode(pageNum, doc, docLineCount) {
1049
- const range = _PageManager.pageRange(pageNum, docLineCount);
1050
- for (let pos = range.startLine; pos <= range.endLine; pos++) {
1051
- const state = doc.getLineAt(pos);
1052
- if (!state || state.isVariableDef) continue;
1053
- if (state.bytecodes.length > 0 || state.results.length > 0) {
1054
- state.bytecodes = [];
1055
- state.results = [];
1056
- state.result = null;
1057
- doc.markDirty(state.lineId);
1058
- }
1059
- }
1060
- }
1061
- };
1062
-
1063
- // src/engine/ThreeTierEvaluator.ts
1064
- var EvalTier = /* @__PURE__ */ ((EvalTier2) => {
1065
- EvalTier2[EvalTier2["Tier1"] = 1] = "Tier1";
1066
- EvalTier2[EvalTier2["Tier2"] = 2] = "Tier2";
1067
- EvalTier2[EvalTier2["Tier3"] = 3] = "Tier3";
1068
- EvalTier2[EvalTier2["Skipped"] = 0] = "Skipped";
1069
- return EvalTier2;
1070
- })(EvalTier || {});
1071
- var ThreeTierEvaluator = class {
1072
- /**
1073
- * @param doc The persistent document model.
1074
- * @param engine The expression engine (shared VM is accessed via engine.getVM()).
1075
- * @param checkpointer Optional VM state checkpointer. If provided, the evaluator
1076
- * will create checkpoints after variable-definition lines and support fast VM
1077
- * restoration via `restoreTo()`. If omitted, checkpointing is disabled.
1078
- */
1079
- constructor(doc, engine, checkpointer) {
1080
- this.compilationWorker = null;
1081
- /**
1082
- * Unsubscribe from sharedGlobalVariableStore, set in the constructor
1083
- * called from terminateWorker(). See the subscription itself below for
1084
- * why this only marks lines dirty and never re-evaluates synchronously.
1085
- */
1086
- this.globalUnsubscribe = null;
1087
- this.doc = doc;
1088
- this.engine = engine;
1089
- this.dag = engine.getDag();
1090
- this.checkpointer = checkpointer ?? null;
1091
- this.pageManager = new PageManager();
1092
- this.engine.setDocumentModel(this.doc);
1093
- this.globalUnsubscribe = chunkFR7RNOPT_cjs.sharedGlobalVariableStore.subscribe((name) => {
1094
- for (const lineNumber of this.dag.getAffectedLines(chunkFR7RNOPT_cjs.globalDagKey(name))) {
1095
- this.doc.markDirtyByLineNumber(lineNumber);
1096
- }
1097
- });
1098
- }
1099
- /**
1100
- * Evaluate all lines needed to render the given viewport.
1101
- *
1102
- * Processes lines from 1 to `viewport.endLine` in document order.
1103
- * Dirty lines in the viewport get Tier-1 full pipeline; clean cached
1104
- * lines get Tier-2 bytecode execution. Lines after the viewport
1105
- * get Tier-3 compile-only (with variable-def execution).
1106
- *
1107
- * @returns Results for all processed lines, including tier metadata.
1108
- */
1109
- evaluate(viewport, signal) {
1110
- this.engine.setKeystrokeSignal(signal ?? null);
1111
- chunkIT74O4BE_cjs.enableValueArena();
1112
- try {
1113
- this.reseedAccumulators();
1114
- const lines = [];
1115
- const resultMap = /* @__PURE__ */ new Map();
1116
- const tierCounts = { tier1: 0, tier2: 0, tier3: 0, skipped: 0 };
1117
- const docEnd = this.doc.lineCount;
1118
- const evalEnd = Math.min(viewport.endLine, docEnd);
1119
- for (let pos = 1; pos <= evalEnd; pos++) {
1120
- const state = this.doc.getLineAt(pos);
1121
- if (!state) {
1122
- tierCounts.skipped++;
1123
- continue;
1124
- }
1125
- const inViewport = pos >= viewport.startLine && pos <= viewport.endLine;
1126
- const lineResult = this.evaluateSingleLine(state, pos, inViewport);
1127
- lines.push(lineResult);
1128
- if (lineResult.tier === 1 /* Tier1 */) tierCounts.tier1++;
1129
- else if (lineResult.tier === 2 /* Tier2 */) tierCounts.tier2++;
1130
- else if (lineResult.tier === 3 /* Tier3 */) tierCounts.tier3++;
1131
- else tierCounts.skipped++;
1132
- if (lineResult.results && inViewport) {
1133
- resultMap.set(pos, lineResult.results.flat());
1134
- }
1135
- }
1136
- this.pageManager.maintainAfterEval(viewport, this.doc);
1137
- return { lines, resultMap, tierCounts };
1138
- } finally {
1139
- this.engine.setKeystrokeSignal(null);
1140
- chunkIT74O4BE_cjs.disableValueArena();
1141
- }
1142
- }
1143
- /**
1144
- * Background-compile invisible dirty lines beyond the viewport (Tier 3 only).
1145
- *
1146
- * Compiles expressions to discover reads/writes for the dependency graph
1147
- * without executing display-only expressions. Variable definitions are
1148
- * executed to maintain VM state for future Tier-2 executions.
1149
- *
1150
- * This is intended to be called after evaluate() so visible lines are
1151
- * rendered first, then background work fills in the dependency graph.
1152
- *
1153
- * **Phase 5.2h:** This synchronous method is retained for environments
1154
- * without Worker support. Prefer `dispatchBackgroundCompiles()` which
1155
- * offloads compilation to a Web Worker with Transferable bytecode.
1156
- */
1157
- backgroundCompile(viewport) {
1158
- const results = [];
1159
- const docEnd = this.doc.lineCount;
1160
- const startPos = viewport.endLine + 1;
1161
- for (let pos = startPos; pos <= docEnd; pos++) {
1162
- const state = this.doc.getLineAt(pos);
1163
- if (!state) continue;
1164
- if (!state.dirty) continue;
1165
- if (state.bytecodes.length > 0 && !state.isVariableDef) continue;
1166
- const lineResult = this.evaluateSingleLine(state, pos, false);
1167
- results.push(lineResult);
1168
- }
1169
- return results;
1170
- }
1171
- /**
1172
- * Dispatch background compilation to a Web Worker (Phase 5.2h).
1173
- *
1174
- * Collects invisible dirty lines beyond the viewport that need compilation,
1175
- * sends them to the compilation worker, and asynchronously stores the
1176
- * transferred bytecode in the DocumentModel when the worker responds.
1177
- *
1178
- * This is the non-blocking alternative to `backgroundCompile()`. The worker
1179
- * compiles expressions with Transferable ArrayBuffers (zero-copy postMessage),
1180
- * so bytecode appears on the main thread without serialization overhead.
1181
- *
1182
- * Lines that already have cached bytecode (from a previous worker pass or
1183
- * synchronous compile) are skipped, only truly uncompiled dirty lines are
1184
- * sent to the worker.
1185
- *
1186
- * **Usage:** Call after `evaluate()` so visible lines render first, then
1187
- * this fills the bytecode cache for future Tier-2 scrolls.
1188
- *
1189
- * @param viewport The current visible range. Lines beyond viewport.endLine
1190
- * that are dirty and don't have bytecode are dispatched.
1191
- */
1192
- dispatchBackgroundCompiles(viewport) {
1193
- const items = this.collectInvisibleCompileTargets(viewport);
1194
- if (items.length === 0) return;
1195
- if (!this.compilationWorker) {
1196
- this.compilationWorker = new CompilationWorkerManager();
1197
- }
1198
- this.compilationWorker.compileBatch(items).then((results) => {
1199
- this.compilationWorker.storeResults(results, this.doc);
1200
- }).catch((_err) => {
1201
- });
1202
- }
1203
- /**
1204
- * Terminate the compilation worker if active, and unsubscribe from
1205
- * sharedGlobalVariableStore. Call this when the evaluator is no longer
1206
- * needed to clean up resources, every call site that retires a
1207
- * ThreeTierEvaluator (document switch, pane destroy()) already calls
1208
- * this unconditionally, so folding the global-store unsubscribe in here
1209
- * needs no new call sites anywhere.
1210
- */
1211
- terminateWorker() {
1212
- if (this.compilationWorker) {
1213
- this.compilationWorker.terminate();
1214
- this.compilationWorker = null;
1215
- }
1216
- if (this.globalUnsubscribe) {
1217
- this.globalUnsubscribe();
1218
- this.globalUnsubscribe = null;
1219
- }
1220
- }
1221
- /**
1222
- * Get the DocumentModel (read-only access for decoration building).
1223
- */
1224
- getDoc() {
1225
- return this.doc;
1226
- }
1227
- /**
1228
- * Evaluate all dirty lines in the document, regardless of viewport.
1229
- * Used for full re-evaluation after plugin register/unregister.
1230
- */
1231
- evaluateAll(signal) {
1232
- const viewport = { startLine: 1, endLine: this.doc.lineCount };
1233
- const result = this.evaluate(viewport, signal);
1234
- return result;
1235
- }
1236
- /**
1237
- * Zero-allocation viewport evaluation, the Phase 5.2e "holy grail."
1238
- *
1239
- * **Key insight:** When the user scrolls (viewport-only change, no edits),
1240
- * we don't need to re-evaluate from line 1. Instead:
1241
- *
1242
- * 1. Restore the VM to just before the viewport via the nearest checkpoint.
1243
- * 2. Evaluate ONLY the visible lines (Tier 2 for clean cached, Tier 1 for dirty).
1244
- * 3. Lines before the viewport are completely skipped, their state lives in
1245
- * the VM checkpointer's prototypal chain.
1246
- *
1247
- * **Correctness guard:** If any variable-definition line before the viewport
1248
- * is dirty (e.g., the user edited a variable def that hasn't been
1249
- * re-evaluated yet), we clear stale checkpoints and fall back to `evaluate()`
1250
- * which processes from line 1 and rebuilds fresh checkpoints. This
1251
- * guarantees that stale checkpoints are never used as restoration targets.
1252
- * Only variable-def lines matter here, `VMCheckpointer.snapshot()` only
1253
- * records state for lines that write a variable, so a dirty plain-expression
1254
- * line before the viewport has no checkpoint to invalidate (see
1255
- * `DocumentModel.hasAnyDirtyVariableDefLineBefore()`).
1256
- *
1257
- * **Performance:** O(visible lines) instead of O(document length). Target:
1258
- * < 1ms for a typical ~30-line viewport, independent of document size.
1259
- *
1260
- * @param viewport The visible line range.
1261
- * @returns Results for visible lines only. Lines before the viewport are
1262
- * not included in `lines[]` or `resultMap`.
1263
- */
1264
- setViewport(viewport, signal) {
1265
- this.engine.setKeystrokeSignal(signal ?? null);
1266
- if (viewport.startLine > 1 && this.hasDirtyLinesBefore(viewport.startLine)) {
1267
- this.checkpointer?.clear();
1268
- return this.evaluate(viewport, signal);
1269
- }
1270
- this.pageManager.maintainAfterEval(viewport, this.doc);
1271
- this.preloadNextPages(viewport);
1272
- this.restoreTo(viewport.startLine - 1);
1273
- chunkIT74O4BE_cjs.enableValueArena();
1274
- try {
1275
- const result = this.collectEvalResults(viewport.startLine, viewport.endLine);
1276
- return result;
1277
- } finally {
1278
- this.engine.setKeystrokeSignal(null);
1279
- chunkIT74O4BE_cjs.disableValueArena();
1280
- }
1281
- }
1282
- /**
1283
- * Apply incremental line-level changes to the document model.
1284
- *
1285
- * **Phase 5.2f:** Replaces the O(N) `setDocument()` + full re-evaluation
1286
- * with O(changed) incremental updates. Key benefits:
1287
- *
1288
- * 1. Unchanged lines retain their persistent lineIds → bytecode survives
1289
- * 2. Only changed + DAG-downstream lines are marked dirty → Tier 1 re-evaluation
1290
- * 3. Clean lines in viewport use Tier 2 (cached bytecode execution)
1291
- * 4. Clean lines outside viewport are skipped entirely
1292
- *
1293
- * The DAG is fully cleared after propagation: shifted lines would have
1294
- * stale entries keyed by old line numbers, so the DAG is rebuilt from
1295
- * scratch during the subsequent `evaluate()` call.
1296
- *
1297
- * **Caller should follow up with `evaluate(viewport)`** to re-evaluate
1298
- * dirty lines from line 1 and rebuild the DAG + checkpoints.
1299
- *
1300
- * @param changes Line-level changes to apply. Must be non-overlapping.
1301
- * @returns Metadata about the applied changes.
1302
- */
1303
- applyTransaction(changes) {
1304
- const allWrites = /* @__PURE__ */ new Set();
1305
- for (const change of changes) {
1306
- for (let i = 0; i < change.deleteCount; i++) {
1307
- const lineNum = change.startLine + i;
1308
- const writes = this.dag.getWrites(lineNum);
1309
- for (const w of writes) {
1310
- allWrites.add(w);
1311
- }
1312
- this.dag.removeLine(lineNum);
1313
- this.engine.getLineCache().removeAllForLine(lineNum);
1314
- }
1315
- }
1316
- const downstreamLineIds = /* @__PURE__ */ new Set();
1317
- for (const writeVar of allWrites) {
1318
- const affected = this.dag.getAffectedLines(writeVar);
1319
- for (const lineNum of affected) {
1320
- const state = this.doc.getLineAt(lineNum);
1321
- if (state) {
1322
- downstreamLineIds.add(state.lineId);
1323
- }
1324
- }
1325
- }
1326
- const result = this.doc.applyChanges(changes);
1327
- this.checkpointer?.clear();
1328
- for (const lineId of downstreamLineIds) {
1329
- this.doc.markDirty(lineId);
1330
- }
1331
- this.dag.clear();
1332
- return {
1333
- inserted: result.inserted,
1334
- removed: result.removed
1335
- };
1336
- }
1337
- // ── Private helpers ─────────────────────────────────────────────────
1338
- /**
1339
- * Reset running-total accumulators and mark the lines that touch them
1340
- * dirty, so the from-line-1 pass in {@link evaluate} recomputes each total
1341
- * from its seed instead of reading its own previous evaluation's value.
1342
- *
1343
- * A `total += 5` line compiles to no bytecode (it rides the symbolic
1344
- * channel), so a clean one would be skipped by the tier dispatch rather
1345
- * than re-run. It must re-run to re-apply its delta over the freshly-reset
1346
- * base, so every line that WRITES an accumulator name is forced dirty (the
1347
- * DAG drops a self-writing line from its own variable's consumers, so
1348
- * getAffectedLines can't surface them). Pure readers of the total keep
1349
- * their real bytecode and re-run via Tier 2 once the total is correct, so
1350
- * they need no special handling. Cheap: a no-op unless the document
1351
- * actually uses `+=`/`-=`, and accumulators are rare.
1352
- */
1353
- reseedAccumulators() {
1354
- const names = this.engine.resetAccumulators();
1355
- if (names.size === 0) return;
1356
- const docEnd = this.doc.lineCount;
1357
- for (let pos = 1; pos <= docEnd; pos++) {
1358
- const writes = this.dag.getWrites(pos);
1359
- if (writes.size === 0) continue;
1360
- for (const w of writes) {
1361
- if (names.has(w)) {
1362
- this.doc.markDirtyByLineNumber(pos);
1363
- break;
1364
- }
1365
- }
1366
- }
1367
- }
1368
- /**
1369
- * Collect evaluation results for a contiguous range of lines.
1370
- *
1371
- * Used by both `evaluate()` (startLine=1) and `setViewport()` (any start).
1372
- * All lines in the range are treated as in-viewport (visible), callers that
1373
- * need the invisible/dirty → Tier 3 handling should use `evaluate()` instead.
1374
- *
1375
- * @param startLine First line to evaluate (1-based, inclusive).
1376
- * @param endLine Last line to evaluate (1-based, inclusive). Clamped to docEnd.
1377
- */
1378
- collectEvalResults(startLine, endLine) {
1379
- const lines = [];
1380
- const resultMap = /* @__PURE__ */ new Map();
1381
- const tierCounts = { tier1: 0, tier2: 0, tier3: 0, skipped: 0 };
1382
- const docEnd = this.doc.lineCount;
1383
- const evalEnd = Math.min(endLine, docEnd);
1384
- for (let pos = startLine; pos <= evalEnd; pos++) {
1385
- const state = this.doc.getLineAt(pos);
1386
- if (!state) continue;
1387
- const lineResult = this.evaluateSingleLine(state, pos, true);
1388
- lines.push(lineResult);
1389
- if (lineResult.tier === 1 /* Tier1 */) tierCounts.tier1++;
1390
- else if (lineResult.tier === 2 /* Tier2 */) tierCounts.tier2++;
1391
- else if (lineResult.tier === 3 /* Tier3 */) tierCounts.tier3++;
1392
- else tierCounts.skipped++;
1393
- if (lineResult.results) {
1394
- resultMap.set(pos, lineResult.results.flat());
1395
- }
1396
- }
1397
- return { lines, resultMap, tierCounts };
1398
- }
1399
- /**
1400
- * Check whether any **variable-definition** line before `position`
1401
- * (1-based, exclusive) is dirty.
1402
- *
1403
- * Used by `setViewport()` to decide whether to fall back to `evaluate()`:
1404
- * if a variable-def before the viewport is dirty, the checkpoint state
1405
- * `restoreTo()` would use may be stale and we need to reprocess from
1406
- * line 1 to rebuild checkpoints correctly.
1407
- *
1408
- * Deliberately narrower than `DocumentModel.hasAnyDirtyLineBefore()`:
1409
- * checkpoints only snapshot variable-def lines (see VMCheckpointer), so a
1410
- * dirty plain-expression line before the viewport can't have invalidated
1411
- * one, there's nothing checkpointed for it to invalidate. Using the
1412
- * broader check here previously caused a real perf bug: `PageManager`'s
1413
- * cold-page eviction marks evicted non-variable-def lines dirty, so
1414
- * scrolling far into a large, variable-def-free document would trip this
1415
- * guard, fall back to `evaluate()`, which recompiles those lines via
1416
- * Tier 3 (never clearing their dirty flag by design), causing the very
1417
- * next `maintainAfterEval()` to re-evict and re-dirty them, a
1418
- * self-sustaining loop that pinned every subsequent `setViewport()` call
1419
- * to the cost of a full re-evaluation instead of O(visible lines).
1420
- *
1421
- * Delegates to DocumentModel.hasAnyDirtyVariableDefLineBefore(), which
1422
- * tracks dirty lineIds incrementally instead of scanning every line up to
1423
- * `position` on every call. This used to be a real per-scroll cost
1424
- * (benchmarked at ~10ms scrolled near the bottom of a 20k-line document)
1425
- * since it fired on every viewport change, not just edits.
1426
- */
1427
- hasDirtyLinesBefore(position) {
1428
- return this.doc.hasAnyDirtyVariableDefLineBefore(position);
1429
- }
1430
- /**
1431
- * Evaluate a single line using the appropriate tier.
1432
- *
1433
- * Tier assignment logic:
1434
- * - Empty/markdown-only lines → skipped
1435
- * - Dirty + in-viewport → Tier 1 (full pipeline)
1436
- * - Dirty + not in viewport → Tier 3 (compile-only, execute variable defs)
1437
- * - Clean + has bytecode + in viewport → Tier 2 (execute from cache)
1438
- * - Clean + no bytecode → skipped (non-evaluable)
1439
- */
1440
- evaluateSingleLine(state, lineNumber, inViewport) {
1441
- const baseResult = {
1442
- lineId: state.lineId,
1443
- lineNumber
1444
- };
1445
- if (state.isEmpty || chunkBESTLPRK_cjs.isEmptyLine(state.text)) {
1446
- state.isEmpty = true;
1447
- this.doc.markClean(state.lineId);
1448
- return { ...baseResult, tier: 0 /* Skipped */, result: null, error: null };
1449
- }
1450
- const { expressions, inlineSolveCount } = this.extractExpressions(state);
1451
- if (expressions.length === 0) {
1452
- state.isEmpty = true;
1453
- this.doc.markClean(state.lineId);
1454
- return { ...baseResult, tier: 0 /* Skipped */, result: null, error: null };
1455
- }
1456
- if (state.dirty) {
1457
- if (inViewport) {
1458
- return this.evaluateTier1(state, lineNumber, expressions, inlineSolveCount, baseResult);
1459
- } else {
1460
- if (state.bytecodes.length > 0 && state.bytecodes.length === expressions.length && !state.isVariableDef) {
1461
- return { ...baseResult, tier: 0 /* Skipped */, result: null, error: null };
1462
- }
1463
- return this.evaluateTier3(state, lineNumber, expressions, inlineSolveCount, baseResult);
1464
- }
1465
- }
1466
- if (inViewport && state.bytecodes.length > 0) {
1467
- return this.evaluateTier2(state, lineNumber, baseResult);
1468
- }
1469
- return { ...baseResult, tier: 0 /* Skipped */, result: null, error: null };
1470
- }
1471
- /**
1472
- * Tier 1: Full pipeline, lex, parse, compile, execute.
1473
- * Uses the engine's existing evaluateLine() which handles all pipeline
1474
- * stages including DAG updates and LineCache population.
1475
- *
1476
- * Supports multiple expressions per line (inline solves). Evaluates each
1477
- * expression left-to-right through the engine so variable definitions in
1478
- * earlier solves update the VM state before later solves are evaluated.
1479
- * Reads/writes are aggregated across all expressions for the DAG.
1480
- */
1481
- evaluateTier1(state, lineNumber, expressions, inlineSolveCount, baseResult) {
1482
- const allResults = [];
1483
- const allBytecodes = [];
1484
- const allReads = /* @__PURE__ */ new Set();
1485
- const allWrites = /* @__PURE__ */ new Set();
1486
- let hasVariableDef = false;
1487
- let lastValue = null;
1488
- let firstError = null;
1489
- let anyFailed = false;
1490
- let anyPending = false;
1491
- for (const expression of expressions) {
1492
- if (!expression.trim()) continue;
1493
- let value = null;
1494
- let entry;
1495
- try {
1496
- const evaluation = this.engine.evaluateLineDetailed(lineNumber, expression);
1497
- value = evaluation.values;
1498
- lastValue = value[0];
1499
- entry = this.engine.getLineCache().get(lineNumber, expression);
1500
- } catch (e) {
1501
- const errorMessage = e instanceof Error ? e.message : String(e);
1502
- if (!firstError) firstError = errorMessage;
1503
- anyFailed = true;
1504
- value = null;
1505
- }
1506
- if (value && value.some((v) => v.type === 12 /* Pending */)) {
1507
- anyPending = true;
1508
- }
1509
- if (value) {
1510
- allResults.push(value);
1511
- } else {
1512
- allResults.push([chunkIT74O4BE_cjs.errorValue("eval_failed", firstError ?? "unknown error")]);
1513
- }
1514
- if (entry) {
1515
- allBytecodes.push(entry.bytecode);
1516
- for (const r of entry.readVariables) allReads.add(r);
1517
- if (entry.writeVariable) {
1518
- allWrites.add(entry.writeVariable);
1519
- hasVariableDef = true;
1520
- }
1521
- } else {
1522
- try {
1523
- const { program, reads: reads2, writes: writes2 } = this.engine.compileExpression(expression);
1524
- allBytecodes.push(program);
1525
- for (const r of reads2) allReads.add(r);
1526
- for (const w of writes2) allWrites.add(w);
1527
- if (writes2.length > 0) hasVariableDef = true;
1528
- } catch (compileErr) {
1529
- allBytecodes.push({ opcodes: new Uint8Array(0), numbers: new Float64Array(0), strings: [], hasAsync: false });
1530
- if (compileErr instanceof chunkMIGXCBXT_cjs.EngineError && compileErr.context) {
1531
- const errReads = compileErr.context.reads;
1532
- const errWrites = compileErr.context.writes;
1533
- if (Array.isArray(errReads)) for (const r of errReads) allReads.add(r);
1534
- if (Array.isArray(errWrites)) for (const w of errWrites) allWrites.add(w);
1535
- }
1536
- }
1537
- }
1538
- }
1539
- const reads = [...allReads];
1540
- const writes = [...allWrites];
1541
- if (anyFailed || anyPending) {
1542
- this.doc.updateLineCompiled(
1543
- state.lineId,
1544
- expressions,
1545
- allBytecodes,
1546
- reads,
1547
- writes,
1548
- hasVariableDef,
1549
- inlineSolveCount
1550
- );
1551
- state.results = allResults;
1552
- state.result = allResults[0]?.[0] ?? null;
1553
- state.inlineSolveCount = inlineSolveCount;
1554
- state.expressions = expressions;
1555
- } else {
1556
- this.doc.updateLineResult(
1557
- state.lineId,
1558
- allResults,
1559
- allBytecodes,
1560
- expressions,
1561
- reads,
1562
- writes,
1563
- hasVariableDef,
1564
- inlineSolveCount
1565
- );
1566
- }
1567
- this.dag.registerLine(lineNumber, reads, writes);
1568
- if (this.checkpointer && writes.length > 0 && !anyFailed && !anyPending) {
1569
- this.checkpointer.snapshot(lineNumber, state.lineId, writes);
1570
- }
1571
- return {
1572
- ...baseResult,
1573
- tier: 1 /* Tier1 */,
1574
- result: lastValue,
1575
- results: allResults,
1576
- error: firstError
1577
- };
1578
- }
1579
- /**
1580
- * Tier 2: Execute from cached bytecode only.
1581
- * Skips lexing, parsing, and compiling, runs the pre-compiled bytecode
1582
- * against the engine's shared VM. Supports multiple bytecodes per line
1583
- * (inline solves), each is executed left-to-right so variable definitions
1584
- * in earlier bytecodes update the VM before later ones run.
1585
- * Assumes the VM already has correct variable state from preceding
1586
- * Tier-1 evaluations.
1587
- */
1588
- evaluateTier2(state, lineNumber, baseResult) {
1589
- if (state.bytecodes.length === 0) {
1590
- return { ...baseResult, tier: 0 /* Skipped */, result: null, error: null };
1591
- }
1592
- const results = [];
1593
- let lastValue = null;
1594
- let firstError = null;
1595
- let anyFailed = false;
1596
- for (const bytecode of state.bytecodes) {
1597
- if (bytecode.opcodes.length === 0) continue;
1598
- try {
1599
- const value = this.engine.executeCached(bytecode, lineNumber);
1600
- lastValue = value;
1601
- results.push([value]);
1602
- } catch (e) {
1603
- const errorMessage = e instanceof Error ? e.message : String(e);
1604
- if (!firstError) firstError = errorMessage;
1605
- anyFailed = true;
1606
- results.push([chunkIT74O4BE_cjs.errorValue("exec_failed", errorMessage)]);
1607
- }
1608
- }
1609
- this.dag.registerLine(lineNumber, state.reads, state.writes);
1610
- state.results = results;
1611
- state.result = results[0]?.[0] ?? null;
1612
- if (anyFailed) {
1613
- this.doc.markDirty(state.lineId);
1614
- }
1615
- return { ...baseResult, tier: 2 /* Tier2 */, result: lastValue, results, error: firstError };
1616
- }
1617
- /**
1618
- * Tier 3: Compile-only for invisible lines.
1619
- * Lex → Parse → Compile to discover reads/writes for the dependency graph.
1620
- * Executes the bytecode ONLY if the line defines a variable (isVariableDef
1621
- * or writes.length > 0), because variable assignments affect VM state
1622
- * that other lines depend on. Pure expression lines are compiled but NOT
1623
- * executed, saving CPU for large documents.
1624
- *
1625
- * Supports multiple expressions per line (inline solves). Each is compiled
1626
- * separately; variable-def expressions are also executed.
1627
- */
1628
- evaluateTier3(state, lineNumber, expressions, inlineSolveCount, baseResult) {
1629
- const allBytecodes = [];
1630
- const allReads = /* @__PURE__ */ new Set();
1631
- const allWrites = /* @__PURE__ */ new Set();
1632
- let hasVariableDef = false;
1633
- let lastResult = null;
1634
- let firstError = null;
1635
- let anyFailed = false;
1636
- let anyPending = false;
1637
- for (const expression of expressions) {
1638
- if (!expression.trim()) continue;
1639
- try {
1640
- const { program, reads: reads2, writes: writes2 } = this.engine.compileExpression(expression);
1641
- allBytecodes.push(program);
1642
- for (const r of reads2) allReads.add(r);
1643
- for (const w of writes2) allWrites.add(w);
1644
- if (writes2.length > 0) hasVariableDef = true;
1645
- if (writes2.length > 0 && program.opcodes.length > 0) {
1646
- lastResult = this.engine.executeCached(program, lineNumber);
1647
- if (lastResult && lastResult.type === 12 /* Pending */) {
1648
- anyPending = true;
1649
- }
1650
- }
1651
- } catch (e) {
1652
- const errorMessage = e instanceof Error ? e.message : String(e);
1653
- if (!firstError) firstError = errorMessage;
1654
- anyFailed = true;
1655
- allBytecodes.push({ opcodes: new Uint8Array(0), numbers: new Float64Array(0), strings: [], hasAsync: false });
1656
- }
1657
- }
1658
- const reads = [...allReads];
1659
- const writes = [...allWrites];
1660
- this.doc.updateLineCompiled(
1661
- state.lineId,
1662
- expressions,
1663
- allBytecodes,
1664
- reads,
1665
- writes,
1666
- hasVariableDef,
1667
- inlineSolveCount
1668
- );
1669
- this.dag.registerLine(lineNumber, reads, writes);
1670
- if (hasVariableDef && lastResult && !anyFailed && !anyPending) {
1671
- state.results = [[lastResult]];
1672
- state.result = lastResult;
1673
- this.doc.markClean(state.lineId);
1674
- if (this.checkpointer) {
1675
- this.checkpointer.snapshot(lineNumber, state.lineId, writes);
1676
- }
1677
- }
1678
- return { ...baseResult, tier: 3 /* Tier3 */, result: lastResult, results: hasVariableDef && lastResult && !anyFailed && !anyPending ? [[lastResult]] : void 0, error: firstError };
1679
- }
1680
- // ── Public checkpoint API (used by Phase 5.2e setViewport) ──────
1681
- /**
1682
- * Restore the VM to the state at or just after the given line number.
1683
- *
1684
- * Finds the nearest checkpoint at or before `lineNumber` and replays
1685
- * all variable definitions from the checkpoint chain into the VM.
1686
- * After calling this, the VM is ready to evaluate lines starting at
1687
- * `lineNumber + 1` without re-evaluating all preceding lines.
1688
- *
1689
- * **Usage:** Phase 5.2e's `setViewport()` calls `restoreTo(viewport.startLine - 1)`
1690
- * before evaluating only the newly visible lines. This is the key to
1691
- * O(visible lines) scrolling.
1692
- *
1693
- * @param lineNumber The line number to restore to. Variables defined
1694
- * at lines ≤ this number will be available in the VM.
1695
- */
1696
- restoreTo(lineNumber) {
1697
- if (this.checkpointer) {
1698
- this.checkpointer.restoreTo(lineNumber);
1699
- }
1700
- }
1701
- /**
1702
- * Get the VM checkpointer, or null if checkpointing is disabled.
1703
- */
1704
- getCheckpointer() {
1705
- return this.checkpointer;
1706
- }
1707
- /**
1708
- * Get the PageManager (Phase 5.2g).
1709
- * Exposed for testing.
1710
- */
1711
- getPageManager() {
1712
- return this.pageManager;
1713
- }
1714
- // ── Phase 5.2g: Directional preloading ──────────────────────────
1715
- /**
1716
- * Preload the next 1–2 pages in the current scroll direction.
1717
- *
1718
- * Called during `setViewport()` (scroll-only path). Collects dirty
1719
- * uncompiled lines in pages just beyond the viewport and dispatches
1720
- * them to the background compilation worker so bytecode is ready
1721
- * before the user scrolls those lines into view.
1722
- */
1723
- preloadNextPages(viewport) {
1724
- const targets = this.pageManager.getPreloadTargets(viewport, this.doc);
1725
- if (targets.length === 0) return;
1726
- if (!this.compilationWorker) {
1727
- this.compilationWorker = new CompilationWorkerManager();
1728
- }
1729
- this.compilationWorker.compileBatch(targets).then((results) => {
1730
- this.compilationWorker.storeResults(results, this.doc);
1731
- }).catch((_err) => {
1732
- });
1733
- }
1734
- /**
1735
- * Collect invisible dirty lines that need background compilation.
1736
- *
1737
- * Iterates lines beyond `viewport.endLine`, filtering for:
1738
- * - Dirty lines (need re-compilation)
1739
- * - Non-empty, non-markdown lines
1740
- * - No existing bytecode (skip already-compiled Tier 3 lines)
1741
- *
1742
- * Returns CompileRequestItem[] suitable for CompilationWorkerManager.
1743
- */
1744
- collectInvisibleCompileTargets(viewport) {
1745
- const items = [];
1746
- const docEnd = this.doc.lineCount;
1747
- const startPos = viewport.endLine + 1;
1748
- for (let pos = startPos; pos <= docEnd; pos++) {
1749
- const state = this.doc.getLineAt(pos);
1750
- if (!state) continue;
1751
- if (!state.dirty) continue;
1752
- if (state.bytecodes.length > 0 && !state.isVariableDef) continue;
1753
- if (state.isEmpty || chunkBESTLPRK_cjs.isEmptyLine(state.text)) continue;
1754
- const { expressions } = this.extractExpressions(state);
1755
- if (expressions.length === 0) continue;
1756
- for (const expression of expressions) {
1757
- if (!expression.trim()) continue;
1758
- items.push({
1759
- lineId: state.lineId,
1760
- expression,
1761
- textHash: state.textHash
1762
- });
1763
- }
1764
- }
1765
- return items;
1766
- }
1767
- /**
1768
- * Extract all evaluable expressions from a LineState.
1769
- *
1770
- * For full-line expressions: returns `{ expressions: [trimmedText], inlineSolveCount: 0 }`.
1771
- * For inline solve lines: returns `{ expressions: [...allSolves], inlineSolveCount: N }`.
1772
- * For pre-extracted (cached) expressions: returns the cached array.
1773
- *
1774
- * Inline solves are extracted left-to-right via the sharedLexer, so variable
1775
- * definitions in earlier solves (e.g., `s\`x = 5\` more text s\`x + 1\``)
1776
- * correctly update the VM state before later solves are evaluated.
1777
- */
1778
- extractExpressions(state) {
1779
- if (state.expressions.length > 0) {
1780
- return { expressions: state.expressions, inlineSolveCount: state.inlineSolveCount };
1781
- }
1782
- const trimmed = state.text.trim();
1783
- if (trimmed.length === 0) return { expressions: [], inlineSolveCount: 0 };
1784
- const inlineSpans = chunk7USV76HV_cjs.sharedLexer.findInlineSolves(state.text);
1785
- if (inlineSpans.length > 0) {
1786
- return {
1787
- expressions: inlineSpans.map((s) => s.expression),
1788
- inlineSolveCount: inlineSpans.length
1789
- };
1790
- }
1791
- return { expressions: [trimmed], inlineSolveCount: 0 };
1792
- }
1793
- };
1794
-
1795
- exports.DocumentModel = DocumentModel;
1796
- exports.EvalTier = EvalTier;
1797
- exports.ThreeTierEvaluator = ThreeTierEvaluator;
1798
- //# sourceMappingURL=chunk-TC6BTUSU.cjs.map
1799
- //# sourceMappingURL=chunk-TC6BTUSU.cjs.map