solve-engine 2.32.0 → 2.34.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 (226) hide show
  1. package/dist/{EngineError-CqGtaT_v.d.cts → EngineError-Bm4OYmw8.d.cts} +6 -0
  2. package/dist/{EngineError-CqGtaT_v.d.ts → EngineError-Bm4OYmw8.d.ts} +6 -0
  3. package/dist/{Lexer-CqFjYoRA.d.ts → Lexer-DPn5dfCH.d.ts} +1 -13
  4. package/dist/{Lexer-sCI05tqO.d.cts → Lexer-DaWkCu84.d.cts} +1 -13
  5. package/dist/{PackageCompatibility-phvSFP4f.d.ts → PackageCompatibility-CkzZfoJ3.d.ts} +1 -1
  6. package/dist/{PackageCompatibility-Bn-T_xKW.d.cts → PackageCompatibility-E_5GtcQW.d.cts} +1 -1
  7. package/dist/{PackageRegistry-C78jVkI9.d.ts → PackageRegistry-DSqic8kz.d.ts} +132 -23
  8. package/dist/{PackageRegistry-B-C1duZw.d.cts → PackageRegistry-js47hr28.d.cts} +132 -23
  9. package/dist/{Parselet-Dgymjxzd.d.ts → Parselet-CQjcHOKw.d.ts} +13 -6
  10. package/dist/{Parselet-DF3864la.d.cts → Parselet-s1sRRn8H.d.cts} +13 -6
  11. package/dist/{TokenNormalizer-Pe3_390t.d.cts → TokenNormalizer-D382VSYh.d.cts} +4 -1
  12. package/dist/{TokenNormalizer-IF7nPRMp.d.ts → TokenNormalizer-DAzPp-j1.d.ts} +4 -1
  13. package/dist/{VMBuiltins-BkKzhj6C.d.cts → VMBuiltins-JCavlQUj.d.cts} +53 -18
  14. package/dist/{VMBuiltins-Du9y8sEo.d.ts → VMBuiltins-qgzA6qGi.d.ts} +53 -18
  15. package/dist/{VMCheckpoints-WdUQrdc9.d.cts → VMCheckpoints-BxPzmdu0.d.cts} +2 -2
  16. package/dist/{VMCheckpoints-gvy_yxYh.d.ts → VMCheckpoints-DjjE92mf.d.ts} +2 -2
  17. package/dist/{Value-BYHw-x7q.d.cts → Value-2TIKi-YL.d.cts} +19 -0
  18. package/dist/{Value-BYHw-x7q.d.ts → Value-2TIKi-YL.d.ts} +19 -0
  19. package/dist/{WorkerError-DTrl3Jag.d.ts → WorkerError-BaN8_eok.d.ts} +1 -1
  20. package/dist/{WorkerError-CRoM8Ju1.d.cts → WorkerError-CexHHmbb.d.cts} +1 -1
  21. package/dist/{chunk-IJE4AEDX.js → chunk-24OW3AAU.js} +3 -3
  22. package/dist/{chunk-IJE4AEDX.js.map → chunk-24OW3AAU.js.map} +1 -1
  23. package/dist/{chunk-CAJTDZ5B.cjs → chunk-2XOLAHW6.cjs} +2 -2
  24. package/dist/{chunk-CAJTDZ5B.cjs.map → chunk-2XOLAHW6.cjs.map} +1 -1
  25. package/dist/{chunk-AGCNMEP2.cjs → chunk-3MG7VIPL.cjs} +2 -2
  26. package/dist/{chunk-AGCNMEP2.cjs.map → chunk-3MG7VIPL.cjs.map} +1 -1
  27. package/dist/chunk-4ASM522I.js +2 -0
  28. package/dist/chunk-4ASM522I.js.map +1 -0
  29. package/dist/{chunk-KH4QXKLT.js → chunk-4MD5L23F.js} +2 -2
  30. package/dist/{chunk-KH4QXKLT.js.map → chunk-4MD5L23F.js.map} +1 -1
  31. package/dist/{chunk-IQVSCL2R.js → chunk-4XWZXP6I.js} +3 -3
  32. package/dist/{chunk-IQVSCL2R.js.map → chunk-4XWZXP6I.js.map} +1 -1
  33. package/dist/{chunk-RELMEWY6.js → chunk-6G2NES2I.js} +2 -2
  34. package/dist/chunk-6G2NES2I.js.map +1 -0
  35. package/dist/{chunk-CDE2ZUGG.js → chunk-6NL7RBAG.js} +2 -2
  36. package/dist/{chunk-CDE2ZUGG.js.map → chunk-6NL7RBAG.js.map} +1 -1
  37. package/dist/{chunk-SUAGBRQ7.cjs → chunk-6SYU4MH7.cjs} +2 -2
  38. package/dist/chunk-6SYU4MH7.cjs.map +1 -0
  39. package/dist/chunk-72J5V7SN.cjs +2 -0
  40. package/dist/chunk-72J5V7SN.cjs.map +1 -0
  41. package/dist/{chunk-TSJ4RQLZ.js → chunk-AENL3Z66.js} +2 -2
  42. package/dist/{chunk-TSJ4RQLZ.js.map → chunk-AENL3Z66.js.map} +1 -1
  43. package/dist/chunk-APYRNAU2.js +2 -0
  44. package/dist/chunk-APYRNAU2.js.map +1 -0
  45. package/dist/{chunk-AXTYQFIV.cjs → chunk-D7URPV5Z.cjs} +3 -3
  46. package/dist/{chunk-AXTYQFIV.cjs.map → chunk-D7URPV5Z.cjs.map} +1 -1
  47. package/dist/chunk-DB5ISONG.js +2 -0
  48. package/dist/chunk-DB5ISONG.js.map +1 -0
  49. package/dist/chunk-DGDVY6XI.js +3 -0
  50. package/dist/chunk-DGDVY6XI.js.map +1 -0
  51. package/dist/chunk-EOKHRS2T.js +2 -0
  52. package/dist/chunk-EOKHRS2T.js.map +1 -0
  53. package/dist/{chunk-NQFCXLEF.js → chunk-EOO6M65F.js} +2 -2
  54. package/dist/{chunk-NQFCXLEF.js.map → chunk-EOO6M65F.js.map} +1 -1
  55. package/dist/{chunk-A764BY7L.cjs → chunk-EQNKDTMX.cjs} +2 -2
  56. package/dist/{chunk-A764BY7L.cjs.map → chunk-EQNKDTMX.cjs.map} +1 -1
  57. package/dist/chunk-FESR6PZI.cjs +2 -0
  58. package/dist/chunk-FESR6PZI.cjs.map +1 -0
  59. package/dist/chunk-G2LCDR52.cjs +3 -0
  60. package/dist/chunk-G2LCDR52.cjs.map +1 -0
  61. package/dist/chunk-G5TZ6TDA.js +2 -0
  62. package/dist/chunk-G5TZ6TDA.js.map +1 -0
  63. package/dist/chunk-GDLYXRMA.cjs +2 -0
  64. package/dist/chunk-GDLYXRMA.cjs.map +1 -0
  65. package/dist/{chunk-7DJYS5PO.cjs → chunk-HSTGWWU2.cjs} +2 -2
  66. package/dist/{chunk-7DJYS5PO.cjs.map → chunk-HSTGWWU2.cjs.map} +1 -1
  67. package/dist/{chunk-OE2DBN4K.js → chunk-INMJ7ZXL.js} +2 -2
  68. package/dist/chunk-INMJ7ZXL.js.map +1 -0
  69. package/dist/chunk-ITH2RLRG.js +5 -0
  70. package/dist/chunk-ITH2RLRG.js.map +1 -0
  71. package/dist/{chunk-5AKT36UK.cjs → chunk-K3PZ66XR.cjs} +2 -2
  72. package/dist/{chunk-5AKT36UK.cjs.map → chunk-K3PZ66XR.cjs.map} +1 -1
  73. package/dist/chunk-LI6LYJDA.cjs +2 -0
  74. package/dist/chunk-LI6LYJDA.cjs.map +1 -0
  75. package/dist/{chunk-WQGHJAW2.cjs → chunk-M4UC2PB6.cjs} +2 -2
  76. package/dist/{chunk-WQGHJAW2.cjs.map → chunk-M4UC2PB6.cjs.map} +1 -1
  77. package/dist/chunk-O7HF345B.js +2 -0
  78. package/dist/chunk-O7HF345B.js.map +1 -0
  79. package/dist/{chunk-CM2WM5CM.cjs → chunk-OBZJKZ2F.cjs} +2 -2
  80. package/dist/{chunk-CM2WM5CM.cjs.map → chunk-OBZJKZ2F.cjs.map} +1 -1
  81. package/dist/{chunk-Q7TBBV62.cjs → chunk-P5YWBIIU.cjs} +2 -2
  82. package/dist/chunk-P5YWBIIU.cjs.map +1 -0
  83. package/dist/chunk-PICFFFJV.js +3 -0
  84. package/dist/chunk-PICFFFJV.js.map +1 -0
  85. package/dist/{chunk-P43SV4NJ.cjs → chunk-QOOTRUY7.cjs} +3 -3
  86. package/dist/{chunk-P43SV4NJ.cjs.map → chunk-QOOTRUY7.cjs.map} +1 -1
  87. package/dist/chunk-R3W53ZMP.cjs +2 -0
  88. package/dist/chunk-R3W53ZMP.cjs.map +1 -0
  89. package/dist/chunk-RMDCGYZM.js +2 -0
  90. package/dist/chunk-RMDCGYZM.js.map +1 -0
  91. package/dist/{chunk-CB3EXUM2.js → chunk-RU3KGJRA.js} +2 -2
  92. package/dist/chunk-RU3KGJRA.js.map +1 -0
  93. package/dist/chunk-S3SPDK6N.cjs +2 -0
  94. package/dist/chunk-S3SPDK6N.cjs.map +1 -0
  95. package/dist/chunk-SF5QVUEI.cjs +3 -0
  96. package/dist/chunk-SF5QVUEI.cjs.map +1 -0
  97. package/dist/{chunk-FXB5GCBT.js → chunk-TJKN466F.js} +2 -2
  98. package/dist/{chunk-FXB5GCBT.js.map → chunk-TJKN466F.js.map} +1 -1
  99. package/dist/{chunk-VLX7ZVK4.js → chunk-U5MESNRT.js} +2 -2
  100. package/dist/{chunk-VLX7ZVK4.js.map → chunk-U5MESNRT.js.map} +1 -1
  101. package/dist/chunk-WCVPXBCW.cjs +5 -0
  102. package/dist/chunk-WCVPXBCW.cjs.map +1 -0
  103. package/dist/{chunk-YWF6C2IO.cjs → chunk-WFT3XUSH.cjs} +2 -2
  104. package/dist/{chunk-YWF6C2IO.cjs.map → chunk-WFT3XUSH.cjs.map} +1 -1
  105. package/dist/{chunk-3ZGFAE3Q.js → chunk-X2GQAKL2.js} +2 -2
  106. package/dist/{chunk-3ZGFAE3Q.js.map → chunk-X2GQAKL2.js.map} +1 -1
  107. package/dist/{chunk-G3POUURF.js → chunk-YID47OPR.js} +2 -2
  108. package/dist/{chunk-G3POUURF.js.map → chunk-YID47OPR.js.map} +1 -1
  109. package/dist/chunk-YV4GDW5A.cjs +2 -0
  110. package/dist/chunk-YV4GDW5A.cjs.map +1 -0
  111. package/dist/chunk-ZSXQP7PD.cjs +2 -0
  112. package/dist/chunk-ZSXQP7PD.cjs.map +1 -0
  113. package/dist/constants.cjs +1 -1
  114. package/dist/constants.js +1 -1
  115. package/dist/engine.cjs +1 -1
  116. package/dist/engine.d.cts +10 -10
  117. package/dist/engine.d.ts +10 -10
  118. package/dist/engine.js +1 -1
  119. package/dist/engine.worker.cjs +1 -1
  120. package/dist/engine.worker.cjs.map +1 -1
  121. package/dist/engine.worker.js +1 -1
  122. package/dist/engine.worker.js.map +1 -1
  123. package/dist/errors.cjs +1 -1
  124. package/dist/errors.d.cts +3 -3
  125. package/dist/errors.d.ts +3 -3
  126. package/dist/errors.js +1 -1
  127. package/dist/format.cjs +1 -1
  128. package/dist/format.d.cts +1 -1
  129. package/dist/format.d.ts +1 -1
  130. package/dist/format.js +1 -1
  131. package/dist/index.cjs +1 -1
  132. package/dist/index.cjs.map +1 -1
  133. package/dist/index.d.cts +10 -10
  134. package/dist/index.d.ts +10 -10
  135. package/dist/index.js +1 -1
  136. package/dist/index.js.map +1 -1
  137. package/dist/language.d.cts +9 -9
  138. package/dist/language.d.ts +9 -9
  139. package/dist/lexer.cjs +1 -1
  140. package/dist/lexer.d.cts +3 -3
  141. package/dist/lexer.d.ts +3 -3
  142. package/dist/lexer.js +1 -1
  143. package/dist/normalizer.cjs +1 -1
  144. package/dist/normalizer.d.cts +2 -2
  145. package/dist/normalizer.d.ts +2 -2
  146. package/dist/normalizer.js +1 -1
  147. package/dist/packages.cjs +1 -1
  148. package/dist/packages.d.cts +8 -8
  149. package/dist/packages.d.ts +8 -8
  150. package/dist/packages.js +1 -1
  151. package/dist/parser.cjs +1 -1
  152. package/dist/parser.d.cts +3 -3
  153. package/dist/parser.d.ts +3 -3
  154. package/dist/parser.js +1 -1
  155. package/dist/{pipeline-BYkKNpql.d.cts → pipeline-Bum6y1B9.d.cts} +1 -1
  156. package/dist/{pipeline-Cl7KW8CB.d.ts → pipeline-DOo3KHaq.d.ts} +1 -1
  157. package/dist/resolvers.cjs +1 -1
  158. package/dist/resolvers.d.cts +69 -3
  159. package/dist/resolvers.d.ts +69 -3
  160. package/dist/resolvers.js +1 -1
  161. package/dist/temporal.cjs +1 -1
  162. package/dist/temporal.js +1 -1
  163. package/dist/testing.cjs +2 -2
  164. package/dist/testing.cjs.map +1 -1
  165. package/dist/testing.d.cts +9 -9
  166. package/dist/testing.d.ts +9 -9
  167. package/dist/testing.js +1 -1
  168. package/dist/testing.js.map +1 -1
  169. package/dist/uom.cjs +1 -1
  170. package/dist/uom.d.cts +35 -2
  171. package/dist/uom.d.ts +35 -2
  172. package/dist/uom.js +1 -1
  173. package/dist/vm.cjs +1 -1
  174. package/dist/vm.d.cts +6 -6
  175. package/dist/vm.d.ts +6 -6
  176. package/dist/vm.js +1 -1
  177. package/dist/worker.cjs +2 -2
  178. package/dist/worker.cjs.map +1 -1
  179. package/dist/worker.d.cts +9 -9
  180. package/dist/worker.d.ts +9 -9
  181. package/dist/worker.js +1 -1
  182. package/dist/worker.js.map +1 -1
  183. package/package.json +1 -1
  184. package/dist/chunk-4DR5RBHQ.cjs +0 -2
  185. package/dist/chunk-4DR5RBHQ.cjs.map +0 -1
  186. package/dist/chunk-4IC5OARK.js +0 -3
  187. package/dist/chunk-4IC5OARK.js.map +0 -1
  188. package/dist/chunk-7ODHPWQC.js +0 -5
  189. package/dist/chunk-7ODHPWQC.js.map +0 -1
  190. package/dist/chunk-A755LVPT.cjs +0 -2
  191. package/dist/chunk-A755LVPT.cjs.map +0 -1
  192. package/dist/chunk-AF6NDOIE.js +0 -2
  193. package/dist/chunk-AF6NDOIE.js.map +0 -1
  194. package/dist/chunk-B2NL65FI.js +0 -2
  195. package/dist/chunk-B2NL65FI.js.map +0 -1
  196. package/dist/chunk-CB3EXUM2.js.map +0 -1
  197. package/dist/chunk-DUFEONVN.cjs +0 -3
  198. package/dist/chunk-DUFEONVN.cjs.map +0 -1
  199. package/dist/chunk-IJHL3LMH.js +0 -2
  200. package/dist/chunk-IJHL3LMH.js.map +0 -1
  201. package/dist/chunk-LCYQQFUH.cjs +0 -2
  202. package/dist/chunk-LCYQQFUH.cjs.map +0 -1
  203. package/dist/chunk-LP3JYC3A.js +0 -2
  204. package/dist/chunk-LP3JYC3A.js.map +0 -1
  205. package/dist/chunk-OE2DBN4K.js.map +0 -1
  206. package/dist/chunk-OKKGPINQ.cjs +0 -5
  207. package/dist/chunk-OKKGPINQ.cjs.map +0 -1
  208. package/dist/chunk-OM7NOHJF.cjs +0 -2
  209. package/dist/chunk-OM7NOHJF.cjs.map +0 -1
  210. package/dist/chunk-PTXUWGRR.js +0 -3
  211. package/dist/chunk-PTXUWGRR.js.map +0 -1
  212. package/dist/chunk-Q7TBBV62.cjs.map +0 -1
  213. package/dist/chunk-RELMEWY6.js.map +0 -1
  214. package/dist/chunk-SFM4XFGJ.js +0 -2
  215. package/dist/chunk-SFM4XFGJ.js.map +0 -1
  216. package/dist/chunk-SRAU3BLV.cjs +0 -3
  217. package/dist/chunk-SRAU3BLV.cjs.map +0 -1
  218. package/dist/chunk-SUAGBRQ7.cjs.map +0 -1
  219. package/dist/chunk-UNKZ5XRC.cjs +0 -2
  220. package/dist/chunk-UNKZ5XRC.cjs.map +0 -1
  221. package/dist/chunk-WU7SBKVU.cjs +0 -2
  222. package/dist/chunk-WU7SBKVU.cjs.map +0 -1
  223. package/dist/chunk-X5K72MBV.js +0 -2
  224. package/dist/chunk-X5K72MBV.js.map +0 -1
  225. package/dist/chunk-ZVPZQ66D.cjs +0 -2
  226. package/dist/chunk-ZVPZQ66D.cjs.map +0 -1
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkYBQOQTVL_cjs=require('./chunk-YBQOQTVL.cjs'),chunkS3DFU33X_cjs=require('./chunk-S3DFU33X.cjs'),chunkSUAGBRQ7_cjs=require('./chunk-SUAGBRQ7.cjs');var o={Lowest:0,Assignment:10,LogicalOr:12,LogicalAnd:14,Conjunction:16,BitwiseOr:18,BitwiseXor:20,BitwiseAnd:22,Conditional:24,Shift:27,Sum:30,Product:40,Uncertainty:45,Exponent:50,Prefix:60,Postfix:70,Call:80};var f={[chunkYBQOQTVL_cjs.a.PLUS]:o.Sum,[chunkYBQOQTVL_cjs.a.MINUS]:o.Sum,[chunkYBQOQTVL_cjs.a.STAR]:o.Product,[chunkYBQOQTVL_cjs.a.SLASH]:o.Product,[chunkYBQOQTVL_cjs.a.MOD]:o.Product,[chunkYBQOQTVL_cjs.a.CARET]:o.Exponent,[chunkYBQOQTVL_cjs.a.BIT_OR]:o.BitwiseOr,[chunkYBQOQTVL_cjs.a.BIT_XOR]:o.BitwiseXor,[chunkYBQOQTVL_cjs.a.BIT_AND]:o.BitwiseAnd,[chunkYBQOQTVL_cjs.a.LSHIFT]:o.Shift,[chunkYBQOQTVL_cjs.a.RSHIFT]:o.Shift,[chunkYBQOQTVL_cjs.a.URSHIFT]:o.Shift,[chunkYBQOQTVL_cjs.a.PERCENT]:o.Postfix,[chunkYBQOQTVL_cjs.a.OF]:o.Product},h=null;function F(){if(h)return h;let i=0;for(let n of Object.keys(f)){let t=chunkYBQOQTVL_cjs.c(n);t>i&&(i=t);}for(let n of Object.values(chunkYBQOQTVL_cjs.a)){let t=chunkYBQOQTVL_cjs.c(n);t>i&&(i=t);}let e=new Uint8Array(i+1);for(let[n,t]of Object.entries(f)){let u=chunkYBQOQTVL_cjs.c(n);e[u]=t;}return h=e,e}function P(){h=null;}var r=255,A="-0";function m(i,e){if(!Number.isInteger(i)||i<0||i>255)throw chunkSUAGBRQ7_cjs.c.parsing("BYTECODE_OPERAND_OUT_OF_RANGE",`A bytecode ${e} must be an integer from 0 to 255, but ${i} was emitted; the opcode stream stores one byte per operand.`,{value:i,what:e});return i}var O=Object.freeze([]),B=new Float64Array(0),b=class{constructor(e){this.pluginFunctionIndex=e;this.opcodes=[];this.numbers=[];this.strings=[];this.stringIndex=new Map;this.numberIndex=new Map;this._hasAsync=false;this.userFunctionBodies=[];this.anonymousBodies=[];}get pluginIndexMap(){return this.pluginFunctionIndex}emitPluginCall(e,n){let t=this.pluginFunctionIndex?.get(e);if(t===void 0)throw chunkSUAGBRQ7_cjs.c.execution("UNKNOWN_PLUGIN_FUNCTION",`No registered plugin function named "${e}". A package must declare it in its pluginFunctions record and be registered before an expression using it is parsed.`,{functionName:e});if(t>65535)throw chunkSUAGBRQ7_cjs.c.parsing("PLUGIN_FUNCTION_INDEX_TOO_LARGE",`Plugin-function index ${t} exceeds the two-byte bytecode limit (65535).`,{index:t});t<=255?(this.emitOpcode(50),this.emitIndex(t)):(this.emitOpcode(161),this.emitIndex(t&255),this.emitIndex(t>>8&255)),this.emitIndex(n);}emitOpcode(e){this.opcodes.push(e),(e===50||e===161)&&(this._hasAsync=true);}emitNumber(e){let n=Object.is(e,-0)?A:e,t=this.numberIndex.get(n);if(t===void 0){if(t=this.numbers.length,t>r)throw chunkSUAGBRQ7_cjs.c.parsing("TOO_MANY_NUMERIC_CONSTANTS",`Expression has more than ${r+1} distinct numeric literals, exceeding the bytecode constant pool's limit.`,{limit:r+1});this.numbers.push(e),this.numberIndex.set(n,t);}this.opcodes.push(t);}emitString(e){let n=this.stringIndex.get(e);if(n===void 0){if(n=this.strings.length,n>r)throw chunkSUAGBRQ7_cjs.c.parsing("TOO_MANY_STRING_CONSTANTS",`Expression has more than ${r+1} distinct string literals, exceeding the bytecode constant pool's limit.`,{limit:r+1});this.strings.push(e),this.stringIndex.set(e,n);}this.opcodes.push(n);}emitIndex(e){this.opcodes.push(m(e,"index"));}emitByte(e){this.opcodes.push(m(e,"byte"));}get currentLength(){return this.opcodes.length}emitUserFunctionBody(e,n,t){let u=this.userFunctionBodies.length;if(u>r)throw chunkSUAGBRQ7_cjs.c.parsing("TOO_MANY_FUNCTION_DEFINITIONS",`More than ${r+1} function definitions on one line, exceeding the bytecode constant pool's limit.`,{limit:r+1});return this.userFunctionBodies.push({name:e,params:n,program:t}),u}emitAnonymousBody(e,n){let t=this.anonymousBodies.length;if(t>r)throw chunkSUAGBRQ7_cjs.c.parsing("TOO_MANY_ANONYMOUS_BODIES",`More than ${r+1} map/reduce transform expressions on one line, exceeding the bytecode constant pool's limit.`,{limit:r+1});return this.anonymousBodies.push({params:e,program:n}),t}patchJump(e,n){if(e<0||e>=this.opcodes.length)throw chunkSUAGBRQ7_cjs.c.parsing("BYTECODE_OPERAND_OUT_OF_RANGE",`patchJump was asked to write at position ${e}, outside the ${this.opcodes.length} bytes emitted so far.`,{position:e,length:this.opcodes.length});this.opcodes[e]=m(n,"jump target");}build(){return {opcodes:new Uint8Array(this.opcodes),numbers:this.numbers.length>0?new Float64Array(this.numbers):B,strings:this.strings.length>0?[...this.strings]:O,hasAsync:this._hasAsync,userFunctionBodies:this.userFunctionBodies.length>0?[...this.userFunctionBodies]:void 0,anonymousBodies:this.anonymousBodies.length>0?[...this.anonymousBodies]:void 0}}buildInto(e){let n=this.opcodes.length,t=this.numbers.length,u=e&&e.opcodes.length>=n,I=e&&e.numbers.length>=t,g=u?new Uint8Array(e.opcodes.buffer,e.opcodes.byteOffset,n):new Uint8Array(n),p=I?new Float64Array(e.numbers.buffer,e.numbers.byteOffset,t):new Float64Array(t);for(let c=0;c<n;c++)g[c]=this.opcodes[c];for(let c=0;c<t;c++)p[c]=this.numbers[c];return {opcodes:g,numbers:p,strings:[...this.strings],hasAsync:this._hasAsync,userFunctionBodies:this.userFunctionBodies.length>0?[...this.userFunctionBodies]:void 0,anonymousBodies:this.anonymousBodies.length>0?[...this.anonymousBodies]:void 0}}reset(){this.opcodes.length=0,this.numbers.length>0&&(this.numbers.length=0,this.numberIndex.clear()),this.strings.length>0&&(this.strings.length=0,this.stringIndex.clear()),this._hasAsync=false,this.userFunctionBodies.length>0&&(this.userFunctionBodies.length=0),this.anonymousBodies.length>0&&(this.anonymousBodies.length=0);}};var _=/^\d{1,3}(\.\d{3}){2,}$/,y=/^\d+$/;function R(i,e){let n=i.endsWith("n")?i.slice(0,-1):i;if(y.test(n))return n;let t=_.test(n)?n.split(".").join(""):x(n,e);if(!y.test(t)){let u=n.includes(".")?".":n.includes(",")?",":n;throw chunkSUAGBRQ7_cjs.c.parsing("INVALID_NUMBER_LITERAL",`"${i}" is not a whole number: "${u}" separates decimals in the ${e} locale, and a whole number cannot have a fractional part.`,{raw:i,localeCode:e,separator:u})}return t}function x(i,e){let n=chunkS3DFU33X_cjs.a(e).display.thousandsSeparator;return n?i.split(n).join(""):i}exports.a=o;exports.b=F;exports.c=P;exports.d=b;exports.e=R;//# sourceMappingURL=chunk-5AKT36UK.cjs.map
2
- //# sourceMappingURL=chunk-5AKT36UK.cjs.map
1
+ 'use strict';var chunkYBQOQTVL_cjs=require('./chunk-YBQOQTVL.cjs'),chunkS3DFU33X_cjs=require('./chunk-S3DFU33X.cjs'),chunk6SYU4MH7_cjs=require('./chunk-6SYU4MH7.cjs');var o={Lowest:0,Assignment:10,LogicalOr:12,LogicalAnd:14,Conjunction:16,BitwiseOr:18,BitwiseXor:20,BitwiseAnd:22,Conditional:24,Shift:27,Sum:30,Product:40,Uncertainty:45,Exponent:50,Prefix:60,Postfix:70,Call:80};var f={[chunkYBQOQTVL_cjs.a.PLUS]:o.Sum,[chunkYBQOQTVL_cjs.a.MINUS]:o.Sum,[chunkYBQOQTVL_cjs.a.STAR]:o.Product,[chunkYBQOQTVL_cjs.a.SLASH]:o.Product,[chunkYBQOQTVL_cjs.a.MOD]:o.Product,[chunkYBQOQTVL_cjs.a.CARET]:o.Exponent,[chunkYBQOQTVL_cjs.a.BIT_OR]:o.BitwiseOr,[chunkYBQOQTVL_cjs.a.BIT_XOR]:o.BitwiseXor,[chunkYBQOQTVL_cjs.a.BIT_AND]:o.BitwiseAnd,[chunkYBQOQTVL_cjs.a.LSHIFT]:o.Shift,[chunkYBQOQTVL_cjs.a.RSHIFT]:o.Shift,[chunkYBQOQTVL_cjs.a.URSHIFT]:o.Shift,[chunkYBQOQTVL_cjs.a.PERCENT]:o.Postfix,[chunkYBQOQTVL_cjs.a.OF]:o.Product},h=null;function F(){if(h)return h;let i=0;for(let n of Object.keys(f)){let t=chunkYBQOQTVL_cjs.c(n);t>i&&(i=t);}for(let n of Object.values(chunkYBQOQTVL_cjs.a)){let t=chunkYBQOQTVL_cjs.c(n);t>i&&(i=t);}let e=new Uint8Array(i+1);for(let[n,t]of Object.entries(f)){let u=chunkYBQOQTVL_cjs.c(n);e[u]=t;}return h=e,e}function P(){h=null;}var r=255,A="-0";function m(i,e){if(!Number.isInteger(i)||i<0||i>255)throw chunk6SYU4MH7_cjs.c.parsing("BYTECODE_OPERAND_OUT_OF_RANGE",`A bytecode ${e} must be an integer from 0 to 255, but ${i} was emitted; the opcode stream stores one byte per operand.`,{value:i,what:e});return i}var O=Object.freeze([]),B=new Float64Array(0),b=class{constructor(e){this.pluginFunctionIndex=e;this.opcodes=[];this.numbers=[];this.strings=[];this.stringIndex=new Map;this.numberIndex=new Map;this._hasAsync=false;this.userFunctionBodies=[];this.anonymousBodies=[];}get pluginIndexMap(){return this.pluginFunctionIndex}emitPluginCall(e,n){let t=this.pluginFunctionIndex?.get(e);if(t===void 0)throw chunk6SYU4MH7_cjs.c.execution("UNKNOWN_PLUGIN_FUNCTION",`No registered plugin function named "${e}". A package must declare it in its pluginFunctions record and be registered before an expression using it is parsed.`,{functionName:e});if(t>65535)throw chunk6SYU4MH7_cjs.c.parsing("PLUGIN_FUNCTION_INDEX_TOO_LARGE",`Plugin-function index ${t} exceeds the two-byte bytecode limit (65535).`,{index:t});t<=255?(this.emitOpcode(50),this.emitIndex(t)):(this.emitOpcode(161),this.emitIndex(t&255),this.emitIndex(t>>8&255)),this.emitIndex(n);}emitOpcode(e){this.opcodes.push(e),(e===50||e===161)&&(this._hasAsync=true);}emitNumber(e){let n=Object.is(e,-0)?A:e,t=this.numberIndex.get(n);if(t===void 0){if(t=this.numbers.length,t>r)throw chunk6SYU4MH7_cjs.c.parsing("TOO_MANY_NUMERIC_CONSTANTS",`Expression has more than ${r+1} distinct numeric literals, exceeding the bytecode constant pool's limit.`,{limit:r+1});this.numbers.push(e),this.numberIndex.set(n,t);}this.opcodes.push(t);}emitString(e){let n=this.stringIndex.get(e);if(n===void 0){if(n=this.strings.length,n>r)throw chunk6SYU4MH7_cjs.c.parsing("TOO_MANY_STRING_CONSTANTS",`Expression has more than ${r+1} distinct string literals, exceeding the bytecode constant pool's limit.`,{limit:r+1});this.strings.push(e),this.stringIndex.set(e,n);}this.opcodes.push(n);}emitIndex(e){this.opcodes.push(m(e,"index"));}emitByte(e){this.opcodes.push(m(e,"byte"));}get currentLength(){return this.opcodes.length}emitUserFunctionBody(e,n,t){let u=this.userFunctionBodies.length;if(u>r)throw chunk6SYU4MH7_cjs.c.parsing("TOO_MANY_FUNCTION_DEFINITIONS",`More than ${r+1} function definitions on one line, exceeding the bytecode constant pool's limit.`,{limit:r+1});return this.userFunctionBodies.push({name:e,params:n,program:t}),u}emitAnonymousBody(e,n){let t=this.anonymousBodies.length;if(t>r)throw chunk6SYU4MH7_cjs.c.parsing("TOO_MANY_ANONYMOUS_BODIES",`More than ${r+1} map/reduce transform expressions on one line, exceeding the bytecode constant pool's limit.`,{limit:r+1});return this.anonymousBodies.push({params:e,program:n}),t}patchJump(e,n){if(e<0||e>=this.opcodes.length)throw chunk6SYU4MH7_cjs.c.parsing("BYTECODE_OPERAND_OUT_OF_RANGE",`patchJump was asked to write at position ${e}, outside the ${this.opcodes.length} bytes emitted so far.`,{position:e,length:this.opcodes.length});this.opcodes[e]=m(n,"jump target");}build(){return {opcodes:new Uint8Array(this.opcodes),numbers:this.numbers.length>0?new Float64Array(this.numbers):B,strings:this.strings.length>0?[...this.strings]:O,hasAsync:this._hasAsync,userFunctionBodies:this.userFunctionBodies.length>0?[...this.userFunctionBodies]:void 0,anonymousBodies:this.anonymousBodies.length>0?[...this.anonymousBodies]:void 0}}buildInto(e){let n=this.opcodes.length,t=this.numbers.length,u=e&&e.opcodes.length>=n,I=e&&e.numbers.length>=t,g=u?new Uint8Array(e.opcodes.buffer,e.opcodes.byteOffset,n):new Uint8Array(n),p=I?new Float64Array(e.numbers.buffer,e.numbers.byteOffset,t):new Float64Array(t);for(let c=0;c<n;c++)g[c]=this.opcodes[c];for(let c=0;c<t;c++)p[c]=this.numbers[c];return {opcodes:g,numbers:p,strings:[...this.strings],hasAsync:this._hasAsync,userFunctionBodies:this.userFunctionBodies.length>0?[...this.userFunctionBodies]:void 0,anonymousBodies:this.anonymousBodies.length>0?[...this.anonymousBodies]:void 0}}reset(){this.opcodes.length=0,this.numbers.length>0&&(this.numbers.length=0,this.numberIndex.clear()),this.strings.length>0&&(this.strings.length=0,this.stringIndex.clear()),this._hasAsync=false,this.userFunctionBodies.length>0&&(this.userFunctionBodies.length=0),this.anonymousBodies.length>0&&(this.anonymousBodies.length=0);}};var _=/^\d{1,3}(\.\d{3}){2,}$/,y=/^\d+$/;function R(i,e){let n=i.endsWith("n")?i.slice(0,-1):i;if(y.test(n))return n;let t=_.test(n)?n.split(".").join(""):x(n,e);if(!y.test(t)){let u=n.includes(".")?".":n.includes(",")?",":n;throw chunk6SYU4MH7_cjs.c.parsing("INVALID_NUMBER_LITERAL",`"${i}" is not a whole number: "${u}" separates decimals in the ${e} locale, and a whole number cannot have a fractional part.`,{raw:i,localeCode:e,separator:u})}return t}function x(i,e){let n=chunkS3DFU33X_cjs.a(e).display.thousandsSeparator;return n?i.split(n).join(""):i}exports.a=o;exports.b=F;exports.c=P;exports.d=b;exports.e=R;//# sourceMappingURL=chunk-K3PZ66XR.cjs.map
2
+ //# sourceMappingURL=chunk-K3PZ66XR.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parser/BindingPower.ts","../src/parser/BytecodeBuilder.ts","../src/parser/BigIntLiteral.ts"],"names":["BindingPower","BUILTIN_INFIX_BP","TokenTypes","_bpTable","buildBindingPowerTable","maxId","name","id","tokenTypeId","table","bp","invalidateBindingPowerTable","MAX_CONSTANT_POOL_INDEX","NEGATIVE_ZERO_KEY","checkedOperand","value","what","ErrorFactory","EMPTY_STRINGS","EMPTY_NUMBERS","BytecodeBuilder","pluginFunctionIndex","argCount","index","op","n","key","idx","s","b","params","program","position","target","buf","opLen","numLen","reuseOpcodes","reuseNumbers","opcodes","numbers","i","CHAINED_DOT_THOUSANDS_GROUPS","DIGITS_ONLY","bigIntLiteralDigits","raw","localeCode","withoutSuffix","digits","stripLocaleGrouping","separator","text","thousandsSeparator","getLocale"],"mappings":"uKAWO,IAAMA,CAAAA,CAAe,CAC1B,MAAA,CAAQ,CAAA,CACR,UAAA,CAAY,EAAA,CACZ,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CAaZ,WAAA,CAAa,EAAA,CAab,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CACZ,UAAA,CAAY,EAAA,CACZ,WAAA,CAAa,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AA,CAAY,IAAA,CAAKI,CAAa,CAAA,CAAG,OAAOA,CAAAA,CAE5C,IAAMC,CAAAA,CAASN,CAAAA,CAA6B,IAAA,CAAKK,CAAa,CAAA,CAC3DA,CAAAA,CAAc,KAAA,CAAM,GAAG,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA,CAChCE,CAAAA,CAAoBF,CAAAA,CAAeD,CAAU,CAAA,CAEhD,GAAI,CAACH,CAAAA,CAAY,IAAA,CAAKK,CAAM,CAAA,CAAG,CAC9B,IAAME,CAAAA,CAAYH,CAAAA,CAAc,QAAA,CAAS,GAAG,CAAA,CAAI,GAAA,CAAMA,CAAAA,CAAc,QAAA,CAAS,GAAG,CAAA,CAAI,GAAA,CAAMA,CAAAA,CAC1F,MAAM9B,mBAAAA,CAAa,OAAA,CAClB,wBAAA,CACA,CAAA,CAAA,EAAI4B,CAAG,CAAA,0BAAA,EAA6BK,CAAS,CAAA,4BAAA,EAA+BJ,CAAU,CAAA,0DAAA,CAAA,CACtF,CAAE,GAAA,CAAAD,CAAAA,CAAK,UAAA,CAAAC,CAAAA,CAAY,SAAA,CAAAI,CAAU,CAC9B,CACD,CACA,OAAOF,CACR,CASA,SAASC,CAAAA,CAAoBE,CAAAA,CAAcL,CAAAA,CAA4B,CACtE,IAAMM,CAAAA,CAAqBC,mBAAAA,CAAUP,CAAU,CAAA,CAAE,OAAA,CAAQ,kBAAA,CACzD,OAAOM,CAAAA,CAAqBD,CAAAA,CAAK,KAAA,CAAMC,CAAkB,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA,CAAID,CACvE","file":"chunk-5AKT36UK.cjs","sourcesContent":["/**\n * Named precedence levels for the Pratt parser, from loosest (`Lowest`) to\n * tightest (`Call`) binding. A custom infix parselet compares its own\n * binding power against the current expression's to decide whether to\n * consume the next operator (higher power binds tighter, e.g. `*` over `+`).\n *\n * Package authors reference these when declaring an infix parselet in a\n * package's `infixParselets`. See the built-in packages for examples of\n * picking an appropriate level (e.g. arithmetic `+`/`-` use `Sum`, `*`/`/`\n * use `Product`).\n */\nexport const BindingPower = {\n Lowest: 0,\n Assignment: 10,\n LogicalOr: 12, // `or`, `||` — loosest of the boolean-logic operators\n LogicalAnd: 14, // `&&` — binds tighter than `or` (\"a or b and c\" = \"a or (b and c)\")\n // The word \"and\" (`AND_CONJ`), which is both arithmetic addition (\"5 and 3\"\n // is 8) and boolean conjunction (\"true and false\"). A phrase parselet\n // collecting a list (\"average of X, Y and Z\") parses each argument at this\n // level, and an argument stops at any operator whose power is <= the level it\n // was parsed at, so putting \"and\" here is what makes it end an argument\n // rather than be consumed as the addition it also is. Everything an argument\n // should keep binds tighter, including a genuine \"+\" (`Sum`).\n //\n // It sits BELOW `Conditional` because the boolean reading needs comparisons\n // to be its operands: at 28, \"5 > 3 and 2 > 1\" parsed as \"5 > (3 and 2) > 1\"\n // and answered false. Above `LogicalAnd` so that \"and\" is still the tighter\n // of the two conjunctions, and two steps off each neighbour to leave room.\n Conjunction: 16,\n // The bitwise trio and the shifts, ordered exactly as C and JavaScript order\n // them, which is the order every language that borrowed these operators from\n // C uses: `|` looser than `xor`, `xor` looser than `&`, all three looser than\n // comparison, and the shifts tighter than comparison but looser than `+`.\n // They used to share one level (35) between `Sum` and `Product`, so\n // \"1 + 2 << 3\" answered 17 where JavaScript answers 24 and \"4 & 3 + 1\"\n // answered 1 where JavaScript answers 4. Each has its own level now because\n // a shared level makes \"4 | 6 & 3\" group left instead of letting `&` win.\n //\n // They stay TIGHTER than `Conjunction` so that a phrase argument parsed at\n // that level (\"average of 5 | 3, 2 and 4\") keeps its bitwise operators\n // instead of stopping at the first one.\n BitwiseOr: 18, // `|`\n BitwiseXor: 20, // the `xor` keyword (`BIT_XOR`), not the `^` exponent token\n BitwiseAnd: 22, // `&`\n Conditional: 24, // comparisons (`==`, `<`, `>=`, ...), tighter than the bitwise trio, looser than the shifts\n Shift: 27, // `<<`, `>>`, `>>>`\n Sum: 30,\n Product: 40,\n // `±` (the uncertainty operator), tighter than `+ - * /` and looser than `^`,\n // so the tolerance attaches to its adjacent values: `12.3 ± 0.5 * 4` reads as\n // `(12.3 ± 0.5) * 4` (the parenthesised headline case), and `2 + 3 ± 0.5` as\n // `2 + (3 ± 0.5)`. A Tier-2 parselet (packages/uncertainty/), so this level is\n // read off the parselet rather than the Tier-1 BUILTIN_INFIX_BP table below.\n Uncertainty: 45,\n // `^`, RIGHT-associative: \"2 ^ 3 ^ 2\" is 2^(3^2) = 512, as in mathematics,\n // Python, Ruby and JavaScript's `**`. See PrecedenceParser.parseExpression\n // and BinaryOpParselet for the two places that associativity is implemented.\n Exponent: 50,\n Prefix: 60,\n Postfix: 70,\n Call: 80,\n} as const;\n\n/**\n * Set the binding power of a named operator.\n *\n * Binding power is what decides precedence in the Pratt parser: a higher number\n * binds tighter, so `*` outranks `+`. Changing one changes how every existing\n * expression using that operator parses, which is why packages should allocate\n * a new name rather than adjust a built-in.\n *\n * @param name - Operator name.\n * @param power - Higher binds tighter.\n */\nexport function setBindingPower(name: string, power: number): void {\n (BindingPower as Record<string, number>)[name] = power;\n}\n\n/**\n * Read the binding power of a named operator.\n *\n * @param name - Operator name.\n * @returns Its binding power, or 0 when the name is unknown, which makes an\n * unregistered operator terminate an expression rather than swallow the rest\n * of it.\n */\nexport function getBindingPower(name: string): number {\n return (BindingPower as Record<string, number>)[name] ?? 0;\n}\n\n// ── Built-in Infix Operator Binding Power Table ──────────────────────────────\n// Pre-computed Uint8Array lookup indexed by token typeId.\n// value > 0 → built-in infix operator with that binding power\n// value = 0 → not a built-in infix, fall through to Tier 2 parselet registry\n//\n// Built at module load via buildBindingPowerTable(). The table is sparse\n// most entries are 0 since only ~15 of 80+ token types are infix operators.\n//\n// Performance: Uint8Array[typeId] is a single typed array load, no Map.get()\n// no string hashing, no property chain. V8 eliminates bounds checks when typeId\n// is known to be within array length.\n\nimport { TokenTypes } from \"@solve-js/lexer/Token\";\nimport { tokenTypeId } from \"@solve-js/lexer/Token\";\n\n/**\n * Mapping of token type names → binding powers for built-in infix operators.\n * Only operators listed here get the Tier 1 fast path in PrecedenceParser.\n * All other infix tokens use the Tier 2 parselet registry fallback.\n */\nexport const BUILTIN_INFIX_BP: Record<string, number> = {\n // Arithmetic (infix, left-associative)\n [TokenTypes.PLUS]: BindingPower.Sum,\n [TokenTypes.MINUS]: BindingPower.Sum,\n [TokenTypes.STAR]: BindingPower.Product,\n [TokenTypes.SLASH]: BindingPower.Product,\n [TokenTypes.MOD]: BindingPower.Product,\n\n // Arithmetic (infix, RIGHT-associative, PrecedenceParser handles this specially)\n [TokenTypes.CARET]: BindingPower.Exponent,\n\n // Bitwise and shift (infix, left-associative), one level each, ordered as C\n // and JavaScript order them. `>>>` used to be missing from this table\n // entirely, which left it running at its Tier 2 parselet level while `>>`\n // ran at the Tier 1 one, so \"16 >> 3 & 1\" and \"16 >>> 3 & 1\" grouped\n // differently and answered 0 and 8.\n [TokenTypes.BIT_OR]: BindingPower.BitwiseOr,\n [TokenTypes.BIT_XOR]: BindingPower.BitwiseXor,\n [TokenTypes.BIT_AND]: BindingPower.BitwiseAnd,\n [TokenTypes.LSHIFT]: BindingPower.Shift,\n [TokenTypes.RSHIFT]: BindingPower.Shift,\n [TokenTypes.URSHIFT]: BindingPower.Shift,\n\n // Postfix (no right operand, PrecedenceParser handles this specially)\n [TokenTypes.PERCENT]: BindingPower.Postfix,\n\n // Percentage keyword (infix, left-associative: \"50% of 200\" → MUL)\n [TokenTypes.OF]: BindingPower.Product,\n};\n\n// Note: These token types are intentionally NOT in the BP_TABLE, they stay in\n// the Tier 2 parselet registry because they require complex handling:\n// IN, TO → UoM conversion parselets (peek at target unit token, complex logic)\n// DOT → Property access (chained OBJ_GET, needs left-token tracking)\n// EQUALS → Assignment (VariableParselet handles :var = expr pattern)\n// EQUALITY, NEQ, GTE, LTE → Comparison ops (need dedicated VM opcodes, task 2.15a)\n// COMMA → Argument separator (function calls, array/object literals)\n\n/** Cached BP_TABLE, built once at module load, immutable thereafter. */\nlet _bpTable: Uint8Array | null = null;\n\n/**\n * Build the Uint8Array binding power table indexed by token typeId.\n * Idempotent, returns cached table on subsequent calls.\n *\n * Must be called after all token types are registered (via registerAllTokenTypes())\n * and after plugin providers have registered their token types.\n */\nexport function buildBindingPowerTable(): Uint8Array {\n if (_bpTable) return _bpTable;\n\n // Size to the largest registered typeId + 1\n let maxId = 0;\n for (const name of Object.keys(BUILTIN_INFIX_BP)) {\n const id = tokenTypeId(name);\n if (id > maxId) maxId = id;\n }\n // Also scan all TokenTypes to ensure table covers all registered IDs\n for (const name of Object.values(TokenTypes)) {\n const id = tokenTypeId(name);\n if (id > maxId) maxId = id;\n }\n\n const table = new Uint8Array(maxId + 1);\n for (const [name, bp] of Object.entries(BUILTIN_INFIX_BP)) {\n const id = tokenTypeId(name);\n table[id] = bp;\n }\n\n _bpTable = table;\n return table;\n}\n\n/**\n * Drop the cached table, so the next {@link buildBindingPowerTable} call builds\n * a fresh one sized to the token types registered by then.\n *\n * It does NOT add a plugin's operator to the Tier 1 fast path, which is what\n * this comment used to promise. The values in the table come from\n * `BUILTIN_INFIX_BP`, which is module-private and has no registration path, so\n * a rebuilt table holds the same binding powers and a plugin token still reads\n * 0. `PrecedenceParser.BP_TABLE` is a static initialized once at class\n * definition time and never re-read, so it would not see a rebuild anyway.\n *\n * A plugin's infix operator takes the Tier 2 parselet-registry route instead,\n * which is where an operator whose binding power the engine does not already\n * know is meant to live.\n */\nexport function invalidateBindingPowerTable(): void {\n _bpTable = null;\n}\n","import { OpCode } from \"@solve-js/parser/OpCode\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * `BytecodeProgram.opcodes` is a `Uint8Array`, every operand written into\n * it (including constant-pool indices from {@link BytecodeBuilder.emitNumber}/\n * {@link BytecodeBuilder.emitString}) is truncated to a single byte on\n * `build()`. Exceeding this silently wraps the index (e.g. entry 300 reads\n * back as entry 44), producing a wrong result with no error. See\n * {@link BytecodeBuilder.emitNumber} for the guard that turns this into a\n * thrown error instead.\n */\nconst MAX_CONSTANT_POOL_INDEX = 255;\n\n/** The `numberIndex` key for negative zero, which `Map` would otherwise fold into positive zero. */\nconst NEGATIVE_ZERO_KEY = \"-0\";\n\n/**\n * An operand that fits the byte the opcode stream stores it in, or a\n * structured refusal. `build()` copies the stream into a `Uint8Array`, which\n * keeps the low eight bits of whatever it is given: an operand of 300 used to\n * become 44 with no error, and the program then read a different constant,\n * plugin function or argument count from the one the parselet emitted. Every\n * raw operand goes through here, so a package author's mistake is reported at\n * compile time as a fault in the package rather than answered with a wrong\n * number.\n */\nfunction checkedOperand(value: number, what: string): number {\n\tif (!Number.isInteger(value) || value < 0 || value > 255) {\n\t\tthrow ErrorFactory.parsing(\n\t\t\t\"BYTECODE_OPERAND_OUT_OF_RANGE\",\n\t\t\t`A bytecode ${what} must be an integer from 0 to 255, but ${value} was emitted; the opcode stream stores one byte per operand.`,\n\t\t\t{ value, what }\n\t\t);\n\t}\n\treturn value;\n}\n\n/**\n * Compiled bytecode program produced by {@link BytecodeBuilder}.\n * Ready for consumption by {@link executeBytecode} without further processing.\n */\nexport interface BytecodeProgram {\n\topcodes: Uint8Array;\n\tnumbers: Float64Array;\n\tstrings: string[];\n\t/**\n\t * Numeric constants by opcode position, restored from a snapshot.\n\t *\n\t * Nothing in the compile path writes this: numbers are emitted inline into\n\t * {@link numbers} instead. `build()` used to attach an empty Map to every\n\t * program anyway, which was one allocation per compiled expression, around a\n\t * tenth of parse-and-compile time, for a collection that was never read.\n\t * It is left off now, and only {@link EngineSnapshot} sets it when restoring\n\t * a program that carried one; every reader already guards on its absence.\n\t */\n\tconstants?: Map<number, number>;\n\t/**\n\t * Whether the program contains any async opcodes (CALL_PLUGIN, etc.).\n\t * Set during compilation by the BytecodeBuilder. Allows the engine\n\t * to skip the O(n) resolver preflight check in O(1) for purely\n\t * synchronous expressions like `2 + 2`.\n\t */\n\thasAsync: boolean;\n\t/**\n\t * User-defined-function bodies compiled alongside this program (one\n\t * entry per `name(params) = body` definition on this line). See\n\t * {@link BytecodeBuilder.emitUserFunctionBody}. `OpCode.DEFINE_USER_FUNCTION`'s\n\t * operand is an index into this array, resolved at VM-execution time\n\t * (not parse time) so a diagnostic/lookahead parse that never actually\n\t * executes the definition line has no side effect on `vm.userFunctions`.\n\t */\n\tuserFunctionBodies?: UserFunctionDef[];\n\t/**\n\t * Anonymous function bodies compiled alongside this program, one entry\n\t * per `map`/`reduce` inline transform expression (e.g. the `10*x` in\n\t * `map(10*x, [0,1,500])`). See {@link BytecodeBuilder.emitAnonymousBody}.\n\t * Deliberately a SEPARATE side-table from `userFunctionBodies`, not\n\t * routed through `vm.userFunctions` at all: an inline body has no name\n\t * and must never leak into the persistent name-keyed registry the way\n\t * a real `f(x) = ...` definition does.\n\t */\n\tanonymousBodies?: AnonymousBodyDef[];\n}\n\n/**\n * An anonymous transform body for `map`/`reduce`'s inline-expression form\n * (e.g. `10*x` in `map(10*x, [0,1,500])`, or `acc+x` in `reduce(acc+x,\n * [1,2,3])`). Structurally identical to {@link UserFunctionDef} minus the\n * `name`. See `OpCode.MAP_INVOKE`/`REDUCE_INVOKE` and\n * `vm/VM.ts`'s handlers, which build a call frame from `params`/`args`\n * exactly like `CALL_USER_FUNCTION` does, just without ever registering\n * the body in `vm.userFunctions`.\n */\nexport interface AnonymousBodyDef {\n\tparams: string[];\n\tprogram: BytecodeProgram;\n}\n\n/**\n * A user-defined, parameterized, reusable function's compiled form\n * (`f(x) = 2*x + 1`). See `OpCode.DEFINE_USER_FUNCTION`/`CALL_USER_FUNCTION`\n * and `vm/VM.ts`'s `VM.defineUserFunction`/`getUserFunction`.\n *\n * `program` is the body compiled to its OWN independent `BytecodeProgram`,\n * not a fragment of the definition line's own bytecode. Parameter names\n * inside the body compile to ORDINARY `LOAD_VAR <name>` opcodes, no\n * parse-time rewriting, because parameter resolution happens dynamically\n * at the VM level: `CALL_USER_FUNCTION` pushes a name-keyed call frame\n * (`Map<string, Value>`) before re-executing `program`, and `VM.getVar()`\n * checks the innermost call frame before falling back to the flat\n * document-variable store. This is why a `UNIT`-collision parameter name\n * (e.g. `h` in `area(w, h) = w * h`, which lexes as the \"hour\" unit) needs\n * no special handling anywhere, it's just another `LOAD_VAR \"h\"`, resolved\n * the same way as any other name.\n */\nexport interface UserFunctionDef {\n\tname: string;\n\tparams: string[];\n\tprogram: BytecodeProgram;\n}\n\n/**\n * Shared empty collections for programs that emit none.\n *\n * `build()` runs once per compiled expression, so an empty array allocated\n * there is an allocation per line of every document. Most programs emit no\n * strings at all (only the unit and datetime parselets do), and one that emits\n * no numbers is common too, so both were routinely allocating an empty\n * container that nothing would ever read.\n *\n * Sharing them is safe because a built program is read-only downstream: the VM\n * and the snapshot writer only index and iterate these, and nothing in the\n * engine pushes to `program.strings` or `program.numbers`. They are frozen so\n * that a future writer fails loudly here rather than silently corrupting every\n * other program that shares the instance.\n */\nconst EMPTY_STRINGS: readonly string[] = Object.freeze([]);\nconst EMPTY_NUMBERS = new Float64Array(0);\n\n/**\n * Direct-to-bytecode compiler for the Pratt parser.\n *\n * Accumulates opcodes, numeric constants, and string references during parsing,\n * then produces a {@link BytecodeProgram} for VM execution. Supports:\n * - Standard build via {@link build}\n * - Zero-copy build into pre-allocated buffers via {@link buildInto}\n * - In-place reset for reuse without reallocation\n */\nexport class BytecodeBuilder {\n\tprivate opcodes: number[] = [];\n\tprivate numbers: number[] = [];\n\tprivate strings: string[] = [];\n\tprivate stringIndex = new Map<string, number>();\n\t/** Value (or {@link NEGATIVE_ZERO_KEY}) to its slot in `numbers`, so a repeated literal is emitted once. */\n\tprivate numberIndex = new Map<number | string, number>();\n\tprivate _hasAsync = false;\n\tprivate userFunctionBodies: UserFunctionDef[] = [];\n\tprivate anonymousBodies: AnonymousBodyDef[] = [];\n\n\t/**\n\t * The per-engine `plugin function name -> registry index` map, wired in by\n\t * the engine so {@link emitPluginCall} can resolve a name at emit time. The\n\t * same object reference is shared with every builder in an engine (the pool\n\t * and each ad-hoc nested-body builder), and the engine populates it as\n\t * packages register, so a parselet never sees the numeric index.\n\t */\n\tconstructor(private readonly pluginFunctionIndex?: ReadonlyMap<string, number>) {}\n\n\t/** The name->index map, so a nested-body builder inherits the same resolution. */\n\tget pluginIndexMap(): ReadonlyMap<string, number> | undefined {\n\t\treturn this.pluginFunctionIndex;\n\t}\n\n\t/**\n\t * Emit a plugin-function call by NAME. The engine assigns each registered\n\t * `pluginFunctions` entry an index at registration; this resolves the name to\n\t * that index and emits `CALL_PLUGIN` + index + argCount. Package authors emit\n\t * through this rather than a hand-allocated index.\n\t */\n\temitPluginCall(name: string, argCount: number): void {\n\t\tconst index = this.pluginFunctionIndex?.get(name);\n\t\tif (index === undefined) {\n\t\t\tthrow ErrorFactory.execution(\n\t\t\t\t\"UNKNOWN_PLUGIN_FUNCTION\",\n\t\t\t\t`No registered plugin function named \"${name}\". A package must declare it in its pluginFunctions record and be registered before an expression using it is parsed.`,\n\t\t\t\t{ functionName: name },\n\t\t\t);\n\t\t}\n\t\t// One byte covers the first 256 plugin functions; beyond that, the\n\t\t// wide opcode carries a two-byte little-endian index. Emitting the\n\t\t// narrow form whenever it fits keeps existing bytecode and snapshots\n\t\t// byte-for-byte unchanged. The index cannot exceed 65535 because the\n\t\t// allocator (allocatePluginFunctionIndex) caps it, but guard anyway so\n\t\t// a stray index is a clear error rather than a silently truncated byte.\n\t\tif (index > 0xffff) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"PLUGIN_FUNCTION_INDEX_TOO_LARGE\",\n\t\t\t\t`Plugin-function index ${index} exceeds the two-byte bytecode limit (65535).`,\n\t\t\t\t{ index },\n\t\t\t);\n\t\t}\n\t\tif (index <= 0xff) {\n\t\t\tthis.emitOpcode(OpCode.CALL_PLUGIN);\n\t\t\tthis.emitIndex(index);\n\t\t} else {\n\t\t\tthis.emitOpcode(OpCode.CALL_PLUGIN_WIDE);\n\t\t\tthis.emitIndex(index & 0xff); // low byte\n\t\t\tthis.emitIndex((index >> 8) & 0xff); // high byte\n\t\t}\n\t\tthis.emitIndex(argCount);\n\t}\n\n\t/** Emit an {@link OpCode} instruction. */\n\temitOpcode(op: OpCode): void {\n\t\tthis.opcodes.push(op);\n\t\tif (op === OpCode.CALL_PLUGIN || op === OpCode.CALL_PLUGIN_WIDE) {\n\t\t\tthis._hasAsync = true;\n\t\t}\n\t}\n\n\t/**\n\t * Emit a numeric literal: interns `n` into the program's constant pool\n\t * (deduplicated, like {@link emitString}) and writes its index into the\n\t * opcode stream (read back by the VM as e.g. `PUSH_NUMBER <idx>`).\n\t *\n\t * Deduplicated so that the 256-entry pool counts distinct values rather\n\t * than occurrences: a long line of repeated literals used to exhaust it\n\t * long before it held 256 different numbers. Negative zero keeps its own\n\t * slot, because `1 / -0` is not `1 / 0`; NaN shares one, since every NaN\n\t * reads the same.\n\t *\n\t * @throws If the pool would exceed 256 distinct entries.\n\t */\n\temitNumber(n: number): void {\n\t\tconst key = Object.is(n, -0) ? NEGATIVE_ZERO_KEY : n;\n\t\tlet idx = this.numberIndex.get(key);\n\t\tif (idx === undefined) {\n\t\t\tidx = this.numbers.length;\n\t\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\t\"TOO_MANY_NUMERIC_CONSTANTS\",\n\t\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} distinct numeric literals, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.numbers.push(n);\n\t\t\tthis.numberIndex.set(key, idx);\n\t\t}\n\t\tthis.opcodes.push(idx);\n\t}\n\n\t/**\n\t * Emit a string literal: interns `s` into the program's string pool\n\t * (deduplicated via `stringIndex`) and writes its index into the opcode\n\t * stream. Subject to the same constant-pool bound as {@link emitNumber},\n\t * but since strings ARE deduplicated, only distinct string values count\n\t * against the limit.\n\t *\n\t * @throws If the string pool would exceed 256 distinct entries.\n\t */\n\temitString(s: string): void {\n\t\tlet idx = this.stringIndex.get(s);\n\t\tif (idx === undefined) {\n\t\t\tidx = this.strings.length;\n\t\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\t\"TOO_MANY_STRING_CONSTANTS\",\n\t\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} distinct string literals, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.strings.push(s);\n\t\t\tthis.stringIndex.set(s, idx);\n\t\t}\n\t\tthis.opcodes.push(idx);\n\t}\n\n\t/**\n\t * Emit a raw numeric operand (0-255) following an opcode, e.g. a\n\t * plugin-function index for `CALL_PLUGIN`, or an argument count. Unlike\n\t * {@link emitOpcode}, this does not go through the `OpCode` enum, so\n\t * package authors use this (not an unsafe cast to `OpCode`) to push\n\t * operands their own opcode handler expects to read positionally.\n\t */\n\temitIndex(idx: number): void {\n\t\tthis.opcodes.push(checkedOperand(idx, \"index\"));\n\t}\n\n\t/** Emit a raw byte (0-255), used for fixed small operands like argument counts. */\n\temitByte(b: number): void {\n\t\tthis.opcodes.push(checkedOperand(b, \"byte\"));\n\t}\n\n\t/** Number of opcodes/operands emitted so far, used to compute jump targets before {@link patchJump}. */\n\tget currentLength(): number {\n\t\treturn this.opcodes.length;\n\t}\n\n\t/**\n\t * Register a compiled user-defined-function body, returning its index\n\t * into this program's `userFunctionBodies` side-table, the caller emits\n\t * that index as `DEFINE_USER_FUNCTION`'s operand via {@link emitIndex}.\n\t * Subject to the same {@link MAX_CONSTANT_POOL_INDEX} bound as\n\t * {@link emitNumber}/{@link emitString} (the index itself is a single\n\t * opcode-stream byte), in practice a single line defines at most a\n\t * handful of functions, so this limit is never realistically reached.\n\t *\n\t * @throws If more than 256 function bodies are registered on one program.\n\t */\n\temitUserFunctionBody(name: string, params: string[], program: BytecodeProgram): number {\n\t\tconst idx = this.userFunctionBodies.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_FUNCTION_DEFINITIONS\",\n\t\t\t\t`More than ${MAX_CONSTANT_POOL_INDEX + 1} function definitions on one line, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t);\n\t\t}\n\t\tthis.userFunctionBodies.push({ name, params, program });\n\t\treturn idx;\n\t}\n\n\t/**\n\t * Register a compiled `map`/`reduce` anonymous transform body, returning\n\t * its index into this program's `anonymousBodies` side-table, the\n\t * caller emits that index as `MAP_INVOKE`/`REDUCE_INVOKE`'s operand via\n\t * {@link emitIndex}. Same {@link MAX_CONSTANT_POOL_INDEX} bound as\n\t * {@link emitUserFunctionBody}.\n\t *\n\t * @throws If more than 256 anonymous bodies are registered on one program.\n\t */\n\temitAnonymousBody(params: string[], program: BytecodeProgram): number {\n\t\tconst idx = this.anonymousBodies.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_ANONYMOUS_BODIES\",\n\t\t\t\t`More than ${MAX_CONSTANT_POOL_INDEX + 1} map/reduce transform expressions on one line, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t);\n\t\t}\n\t\tthis.anonymousBodies.push({ params, program });\n\t\treturn idx;\n\t}\n\n\t/** Overwrite a previously-emitted placeholder operand at `position` with the real jump `target`, once known. */\n\tpatchJump(position: number, target: number): void {\n\t\tif (position < 0 || position >= this.opcodes.length) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"BYTECODE_OPERAND_OUT_OF_RANGE\",\n\t\t\t\t`patchJump was asked to write at position ${position}, outside the ${this.opcodes.length} bytes emitted so far.`,\n\t\t\t\t{ position, length: this.opcodes.length }\n\t\t\t);\n\t\t}\n\t\tthis.opcodes[position] = checkedOperand(target, \"jump target\");\n\t}\n\n\t/**\n\t * Build the accumulated opcodes/numbers/strings into a BytecodeProgram.\n\t * Creates new TypedArrays, the builder can be reused after this call.\n\t */\n\tbuild(): BytecodeProgram {\n\t\treturn {\n\t\t\topcodes: new Uint8Array(this.opcodes),\n\t\t\tnumbers: this.numbers.length > 0 ? new Float64Array(this.numbers) : EMPTY_NUMBERS,\n\t\t\t// Defensive copy when there is anything to copy: reset()'s\n\t\t\t// `.length = 0` would otherwise clear a reference the program still\n\t\t\t// holds. An empty one needs no copy, so it shares the frozen\n\t\t\t// singleton instead of allocating per program.\n\t\t\tstrings: this.strings.length > 0 ? [...this.strings] : (EMPTY_STRINGS as string[]),\n\t\t\thasAsync: this._hasAsync,\n\t\t\tuserFunctionBodies: this.userFunctionBodies.length > 0 ? [...this.userFunctionBodies] : undefined,\n\t\t\tanonymousBodies: this.anonymousBodies.length > 0 ? [...this.anonymousBodies] : undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Build directly into a pre-allocated buffer for zero-copy VM consumption.\n\t *\n\t * When `buf` is provided and large enough, writes into it and returns\n\t * subarray **views** (not copies), the returned TypedArrays share the\n\t * buffer's underlying ArrayBuffer. The caller MUST NOT mutate the buffer\n\t * until the returned BytecodeProgram is no longer needed.\n\t *\n\t * If the caller intends to cache the result, they must copy the TypedArrays\n\t * (e.g. `new Uint8Array(program.opcodes)`) before reusing the buffer pool.\n\t *\n\t * When `buf` is omitted or too small, allocates fresh TypedArrays.\n\t */\n\tbuildInto(buf?: { opcodes: Uint8Array; numbers: Float64Array }): BytecodeProgram {\n\t\tconst opLen = this.opcodes.length;\n\t\tconst numLen = this.numbers.length;\n\n\t\tconst reuseOpcodes = buf && buf.opcodes.length >= opLen;\n\t\tconst reuseNumbers = buf && buf.numbers.length >= numLen;\n\n\t\t// Subarray views that share the buffer's ArrayBuffer (zero-copy)\n\t\tconst opcodes = reuseOpcodes\n\t\t\t? new Uint8Array(buf!.opcodes.buffer, buf!.opcodes.byteOffset, opLen)\n\t\t\t: new Uint8Array(opLen);\n\t\tconst numbers = reuseNumbers\n\t\t\t? new Float64Array(buf!.numbers.buffer, buf!.numbers.byteOffset, numLen)\n\t\t\t: new Float64Array(numLen);\n\n\t\t// Write data into the views\n\t\tfor (let i = 0; i < opLen; i++) opcodes[i] = this.opcodes[i];\n\t\tfor (let i = 0; i < numLen; i++) numbers[i] = this.numbers[i];\n\n\t\treturn {\n\t\t\topcodes,\n\t\t\tnumbers,\n\t\t\tstrings: [...this.strings],\n\t\t\thasAsync: this._hasAsync,\n\t\t\tuserFunctionBodies: this.userFunctionBodies.length > 0 ? [...this.userFunctionBodies] : undefined,\n\t\t\tanonymousBodies: this.anonymousBodies.length > 0 ? [...this.anonymousBodies] : undefined,\n\t\t};\n\t}\n\n\treset(): void {\n\t\t// Retain backing stores with .length = 0 to avoid reallocation on growth.\n\t\t// = [] discards the ArrayBuffer, forcing V8 to reallocate on every push()\n\t\t// threshold (4→8→16→32...). For a 50-opcode expression, that's 3-4 copies.\n\t\tthis.opcodes.length = 0;\n\t\tif (this.numbers.length > 0) {\n\t\t\tthis.numbers.length = 0;\n\t\t\tthis.numberIndex.clear();\n\t\t}\n\t\t// Guarded on being non-empty. reset() runs once per compiled expression\n\t\t// and a CPU profile put it at over a tenth of parse-and-compile, which\n\t\t// is a lot for clearing collections that are usually already empty:\n\t\t// most expressions emit no strings, and user function bodies are rarer\n\t\t// still. Emptying an empty Map is not free, and neither is the write\n\t\t// barrier on a length assignment.\n\t\tif (this.strings.length > 0) {\n\t\t\tthis.strings.length = 0;\n\t\t\tthis.stringIndex.clear();\n\t\t}\n\t\tthis._hasAsync = false;\n\t\tif (this.userFunctionBodies.length > 0) this.userFunctionBodies.length = 0;\n\t\tif (this.anonymousBodies.length > 0) this.anonymousBodies.length = 0;\n\t}\n}\n","/**\n * Turning a `123n` literal's source text into the digits `PUSH_BIGINT` stores.\n *\n * The lexer coalesces thousands groups into the number token it is building,\n * accepting both `,` and `.` as the separator regardless of locale (see\n * `lexer/ExpressionLexer.ts`'s \"Thousands separators\" block). For a NUMBER that\n * is fine, because the separators are stripped again when the text is turned\n * into a double. For a BIGINT nothing stripped them: both consumers took the\n * token text, removed the trailing `n`, and handed the rest straight to\n * `BigInt()`.\n *\n * So `1.000n` reached `BigInt(\"1.000\")`, which throws a raw `SyntaxError` that\n * arrived at the host as UNEXPECTED_ERROR/INTERNAL: the engine reporting its\n * own bug for six characters a user typed. `1.01n` and `1.1n` were fine, which\n * is the tell that the `n` suffix was never the problem, the three-digit\n * thousands group was: a dot followed by exactly three digits is what the lexer\n * swallows, and one followed by one or two digits it leaves alone.\n *\n * Written once here rather than inline at both call sites. There are two\n * (`parser/PrecedenceParser.ts`'s Tier-1 switch and\n * `packages/biginteger/parselets/BigIntNumberParselet.ts`), they already held\n * identical copies of the `n`-stripping, and the two tiers disagreeing about a\n * literal is a bug shape this codebase has had before.\n *\n * @module BigIntLiteral\n */\n\nimport { getLocale } from \"@solve-js/constants/locales\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * Two or more dot-separated groups of three, e.g. `1.234.567`.\n *\n * Unambiguous in any locale, since no locale writes two decimal points, so this\n * is stripped without consulting one. Same regex and same reasoning as\n * `NumberParselet.ts`'s copy for the NUMBER path.\n */\nconst CHAINED_DOT_THOUSANDS_GROUPS = /^\\d{1,3}(\\.\\d{3}){2,}$/;\n\n/** Digits and nothing else, which is what `BigInt()` can be handed safely. */\nconst DIGITS_ONLY = /^\\d+$/;\n\n/**\n * The digit string behind a bigint literal.\n *\n * A bigint literal has no fractional part by construction: the lexer only emits\n * BIGINT when it saw no decimal point of its own and no exponent, so any `.` or\n * `,` still in the text got there as a thousands group. Which of the two the\n * writer meant is a locale question, and answering it wrongly would silently\n * change the value by three orders of magnitude, so only the separator this\n * locale actually uses for grouping is removed. Anything left over is refused\n * rather than guessed at.\n *\n * @param raw - The token's text, with or without the trailing `n`.\n * @param localeCode - The engine's active locale.\n * @returns A string of digits, ready for `BigInt()`.\n * @throws An `INVALID_NUMBER_LITERAL` parsing error when what is left is not a\n * whole number, e.g. `1.000n` in a locale that writes decimals with a dot.\n */\nexport function bigIntLiteralDigits(raw: string, localeCode: string): string {\n\tconst withoutSuffix = raw.endsWith(\"n\") ? raw.slice(0, -1) : raw;\n\n\t// The common case first: nothing was grouped, so there is nothing to decide.\n\tif (DIGITS_ONLY.test(withoutSuffix)) return withoutSuffix;\n\n\tconst digits = CHAINED_DOT_THOUSANDS_GROUPS.test(withoutSuffix)\n\t\t? withoutSuffix.split(\".\").join(\"\")\n\t\t: stripLocaleGrouping(withoutSuffix, localeCode);\n\n\tif (!DIGITS_ONLY.test(digits)) {\n\t\tconst separator = withoutSuffix.includes(\".\") ? \".\" : withoutSuffix.includes(\",\") ? \",\" : withoutSuffix;\n\t\tthrow ErrorFactory.parsing(\n\t\t\t\"INVALID_NUMBER_LITERAL\",\n\t\t\t`\"${raw}\" is not a whole number: \"${separator}\" separates decimals in the ${localeCode} locale, and a whole number cannot have a fractional part.`,\n\t\t\t{ raw, localeCode, separator },\n\t\t);\n\t}\n\treturn digits;\n}\n\n/**\n * Removes the active locale's own thousands separator and nothing else.\n *\n * @param text - The literal without its `n`.\n * @param localeCode - The engine's active locale.\n * @returns The text with grouping removed, which the caller then re-checks.\n */\nfunction stripLocaleGrouping(text: string, localeCode: string): string {\n\tconst thousandsSeparator = getLocale(localeCode).display.thousandsSeparator;\n\treturn thousandsSeparator ? text.split(thousandsSeparator).join(\"\") : text;\n}\n"]}
1
+ {"version":3,"sources":["../src/parser/BindingPower.ts","../src/parser/BytecodeBuilder.ts","../src/parser/BigIntLiteral.ts"],"names":["BindingPower","BUILTIN_INFIX_BP","TokenTypes","_bpTable","buildBindingPowerTable","maxId","name","id","tokenTypeId","table","bp","invalidateBindingPowerTable","MAX_CONSTANT_POOL_INDEX","NEGATIVE_ZERO_KEY","checkedOperand","value","what","ErrorFactory","EMPTY_STRINGS","EMPTY_NUMBERS","BytecodeBuilder","pluginFunctionIndex","argCount","index","op","n","key","idx","s","b","params","program","position","target","buf","opLen","numLen","reuseOpcodes","reuseNumbers","opcodes","numbers","i","CHAINED_DOT_THOUSANDS_GROUPS","DIGITS_ONLY","bigIntLiteralDigits","raw","localeCode","withoutSuffix","digits","stripLocaleGrouping","separator","text","thousandsSeparator","getLocale"],"mappings":"uKAWO,IAAMA,CAAAA,CAAe,CAC1B,MAAA,CAAQ,CAAA,CACR,UAAA,CAAY,EAAA,CACZ,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CAaZ,WAAA,CAAa,EAAA,CAab,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CACZ,UAAA,CAAY,EAAA,CACZ,WAAA,CAAa,EAAA,CACb,KAAA,CAAO,EAAA,CACP,GAAA,CAAK,EAAA,CACL,OAAA,CAAS,EAAA,CAMT,WAAA,CAAa,EAAA,CAIb,QAAA,CAAU,GACV,MAAA,CAAQ,EAAA,CACR,OAAA,CAAS,EAAA,CACT,IAAA,CAAM,EACR,EAiDO,IAAMC,CAAAA,CAA2C,CAEtD,CAACC,mBAAAA,CAAW,IAAI,EAAOF,CAAAA,CAAa,GAAA,CACpC,CAACE,mBAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,GAAA,CACpC,CAACE,mBAAAA,CAAW,IAAI,EAAOF,CAAAA,CAAa,OAAA,CACpC,CAACE,mBAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,OAAA,CACpC,CAACE,mBAAAA,CAAW,GAAG,EAAQF,CAAAA,CAAa,OAAA,CAGpC,CAACE,mBAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,QAAA,CAOpC,CAACE,mBAAAA,CAAW,MAAM,EAAKF,CAAAA,CAAa,SAAA,CACpC,CAACE,mBAAAA,CAAW,OAAO,EAAIF,CAAAA,CAAa,UAAA,CACpC,CAACE,mBAAAA,CAAW,OAAO,EAA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ACR,CASA,SAASC,CAAAA,CAAoBE,CAAAA,CAAcL,CAAAA,CAA4B,CACtE,IAAMM,CAAAA,CAAqBC,mBAAAA,CAAUP,CAAU,CAAA,CAAE,OAAA,CAAQ,kBAAA,CACzD,OAAOM,CAAAA,CAAqBD,CAAAA,CAAK,KAAA,CAAMC,CAAkB,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA,CAAID,CACvE","file":"chunk-K3PZ66XR.cjs","sourcesContent":["/**\n * Named precedence levels for the Pratt parser, from loosest (`Lowest`) to\n * tightest (`Call`) binding. A custom infix parselet compares its own\n * binding power against the current expression's to decide whether to\n * consume the next operator (higher power binds tighter, e.g. `*` over `+`).\n *\n * Package authors reference these when declaring an infix parselet in a\n * package's `infixParselets`. See the built-in packages for examples of\n * picking an appropriate level (e.g. arithmetic `+`/`-` use `Sum`, `*`/`/`\n * use `Product`).\n */\nexport const BindingPower = {\n Lowest: 0,\n Assignment: 10,\n LogicalOr: 12, // `or`, `||` — loosest of the boolean-logic operators\n LogicalAnd: 14, // `&&` — binds tighter than `or` (\"a or b and c\" = \"a or (b and c)\")\n // The word \"and\" (`AND_CONJ`), which is both arithmetic addition (\"5 and 3\"\n // is 8) and boolean conjunction (\"true and false\"). A phrase parselet\n // collecting a list (\"average of X, Y and Z\") parses each argument at this\n // level, and an argument stops at any operator whose power is <= the level it\n // was parsed at, so putting \"and\" here is what makes it end an argument\n // rather than be consumed as the addition it also is. Everything an argument\n // should keep binds tighter, including a genuine \"+\" (`Sum`).\n //\n // It sits BELOW `Conditional` because the boolean reading needs comparisons\n // to be its operands: at 28, \"5 > 3 and 2 > 1\" parsed as \"5 > (3 and 2) > 1\"\n // and answered false. Above `LogicalAnd` so that \"and\" is still the tighter\n // of the two conjunctions, and two steps off each neighbour to leave room.\n Conjunction: 16,\n // The bitwise trio and the shifts, ordered exactly as C and JavaScript order\n // them, which is the order every language that borrowed these operators from\n // C uses: `|` looser than `xor`, `xor` looser than `&`, all three looser than\n // comparison, and the shifts tighter than comparison but looser than `+`.\n // They used to share one level (35) between `Sum` and `Product`, so\n // \"1 + 2 << 3\" answered 17 where JavaScript answers 24 and \"4 & 3 + 1\"\n // answered 1 where JavaScript answers 4. Each has its own level now because\n // a shared level makes \"4 | 6 & 3\" group left instead of letting `&` win.\n //\n // They stay TIGHTER than `Conjunction` so that a phrase argument parsed at\n // that level (\"average of 5 | 3, 2 and 4\") keeps its bitwise operators\n // instead of stopping at the first one.\n BitwiseOr: 18, // `|`\n BitwiseXor: 20, // the `xor` keyword (`BIT_XOR`), not the `^` exponent token\n BitwiseAnd: 22, // `&`\n Conditional: 24, // comparisons (`==`, `<`, `>=`, ...), tighter than the bitwise trio, looser than the shifts\n Shift: 27, // `<<`, `>>`, `>>>`\n Sum: 30,\n Product: 40,\n // `±` (the uncertainty operator), tighter than `+ - * /` and looser than `^`,\n // so the tolerance attaches to its adjacent values: `12.3 ± 0.5 * 4` reads as\n // `(12.3 ± 0.5) * 4` (the parenthesised headline case), and `2 + 3 ± 0.5` as\n // `2 + (3 ± 0.5)`. A Tier-2 parselet (packages/uncertainty/), so this level is\n // read off the parselet rather than the Tier-1 BUILTIN_INFIX_BP table below.\n Uncertainty: 45,\n // `^`, RIGHT-associative: \"2 ^ 3 ^ 2\" is 2^(3^2) = 512, as in mathematics,\n // Python, Ruby and JavaScript's `**`. See PrecedenceParser.parseExpression\n // and BinaryOpParselet for the two places that associativity is implemented.\n Exponent: 50,\n Prefix: 60,\n Postfix: 70,\n Call: 80,\n} as const;\n\n/**\n * Set the binding power of a named operator.\n *\n * Binding power is what decides precedence in the Pratt parser: a higher number\n * binds tighter, so `*` outranks `+`. Changing one changes how every existing\n * expression using that operator parses, which is why packages should allocate\n * a new name rather than adjust a built-in.\n *\n * @param name - Operator name.\n * @param power - Higher binds tighter.\n */\nexport function setBindingPower(name: string, power: number): void {\n (BindingPower as Record<string, number>)[name] = power;\n}\n\n/**\n * Read the binding power of a named operator.\n *\n * @param name - Operator name.\n * @returns Its binding power, or 0 when the name is unknown, which makes an\n * unregistered operator terminate an expression rather than swallow the rest\n * of it.\n */\nexport function getBindingPower(name: string): number {\n return (BindingPower as Record<string, number>)[name] ?? 0;\n}\n\n// ── Built-in Infix Operator Binding Power Table ──────────────────────────────\n// Pre-computed Uint8Array lookup indexed by token typeId.\n// value > 0 → built-in infix operator with that binding power\n// value = 0 → not a built-in infix, fall through to Tier 2 parselet registry\n//\n// Built at module load via buildBindingPowerTable(). The table is sparse\n// most entries are 0 since only ~15 of 80+ token types are infix operators.\n//\n// Performance: Uint8Array[typeId] is a single typed array load, no Map.get()\n// no string hashing, no property chain. V8 eliminates bounds checks when typeId\n// is known to be within array length.\n\nimport { TokenTypes } from \"@solve-js/lexer/Token\";\nimport { tokenTypeId } from \"@solve-js/lexer/Token\";\n\n/**\n * Mapping of token type names → binding powers for built-in infix operators.\n * Only operators listed here get the Tier 1 fast path in PrecedenceParser.\n * All other infix tokens use the Tier 2 parselet registry fallback.\n */\nexport const BUILTIN_INFIX_BP: Record<string, number> = {\n // Arithmetic (infix, left-associative)\n [TokenTypes.PLUS]: BindingPower.Sum,\n [TokenTypes.MINUS]: BindingPower.Sum,\n [TokenTypes.STAR]: BindingPower.Product,\n [TokenTypes.SLASH]: BindingPower.Product,\n [TokenTypes.MOD]: BindingPower.Product,\n\n // Arithmetic (infix, RIGHT-associative, PrecedenceParser handles this specially)\n [TokenTypes.CARET]: BindingPower.Exponent,\n\n // Bitwise and shift (infix, left-associative), one level each, ordered as C\n // and JavaScript order them. `>>>` used to be missing from this table\n // entirely, which left it running at its Tier 2 parselet level while `>>`\n // ran at the Tier 1 one, so \"16 >> 3 & 1\" and \"16 >>> 3 & 1\" grouped\n // differently and answered 0 and 8.\n [TokenTypes.BIT_OR]: BindingPower.BitwiseOr,\n [TokenTypes.BIT_XOR]: BindingPower.BitwiseXor,\n [TokenTypes.BIT_AND]: BindingPower.BitwiseAnd,\n [TokenTypes.LSHIFT]: BindingPower.Shift,\n [TokenTypes.RSHIFT]: BindingPower.Shift,\n [TokenTypes.URSHIFT]: BindingPower.Shift,\n\n // Postfix (no right operand, PrecedenceParser handles this specially)\n [TokenTypes.PERCENT]: BindingPower.Postfix,\n\n // Percentage keyword (infix, left-associative: \"50% of 200\" → MUL)\n [TokenTypes.OF]: BindingPower.Product,\n};\n\n// Note: These token types are intentionally NOT in the BP_TABLE, they stay in\n// the Tier 2 parselet registry because they require complex handling:\n// IN, TO → UoM conversion parselets (peek at target unit token, complex logic)\n// DOT → Property access (chained OBJ_GET, needs left-token tracking)\n// EQUALS → Assignment (VariableParselet handles :var = expr pattern)\n// EQUALITY, NEQ, GTE, LTE → Comparison ops (need dedicated VM opcodes, task 2.15a)\n// COMMA → Argument separator (function calls, array/object literals)\n\n/** Cached BP_TABLE, built once at module load, immutable thereafter. */\nlet _bpTable: Uint8Array | null = null;\n\n/**\n * Build the Uint8Array binding power table indexed by token typeId.\n * Idempotent, returns cached table on subsequent calls.\n *\n * Must be called after all token types are registered (via registerAllTokenTypes())\n * and after plugin providers have registered their token types.\n */\nexport function buildBindingPowerTable(): Uint8Array {\n if (_bpTable) return _bpTable;\n\n // Size to the largest registered typeId + 1\n let maxId = 0;\n for (const name of Object.keys(BUILTIN_INFIX_BP)) {\n const id = tokenTypeId(name);\n if (id > maxId) maxId = id;\n }\n // Also scan all TokenTypes to ensure table covers all registered IDs\n for (const name of Object.values(TokenTypes)) {\n const id = tokenTypeId(name);\n if (id > maxId) maxId = id;\n }\n\n const table = new Uint8Array(maxId + 1);\n for (const [name, bp] of Object.entries(BUILTIN_INFIX_BP)) {\n const id = tokenTypeId(name);\n table[id] = bp;\n }\n\n _bpTable = table;\n return table;\n}\n\n/**\n * Drop the cached table, so the next {@link buildBindingPowerTable} call builds\n * a fresh one sized to the token types registered by then.\n *\n * It does NOT add a plugin's operator to the Tier 1 fast path, which is what\n * this comment used to promise. The values in the table come from\n * `BUILTIN_INFIX_BP`, which is module-private and has no registration path, so\n * a rebuilt table holds the same binding powers and a plugin token still reads\n * 0. `PrecedenceParser.BP_TABLE` is a static initialized once at class\n * definition time and never re-read, so it would not see a rebuild anyway.\n *\n * A plugin's infix operator takes the Tier 2 parselet-registry route instead,\n * which is where an operator whose binding power the engine does not already\n * know is meant to live.\n */\nexport function invalidateBindingPowerTable(): void {\n _bpTable = null;\n}\n","import { OpCode } from \"@solve-js/parser/OpCode\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * `BytecodeProgram.opcodes` is a `Uint8Array`, every operand written into\n * it (including constant-pool indices from {@link BytecodeBuilder.emitNumber}/\n * {@link BytecodeBuilder.emitString}) is truncated to a single byte on\n * `build()`. Exceeding this silently wraps the index (e.g. entry 300 reads\n * back as entry 44), producing a wrong result with no error. See\n * {@link BytecodeBuilder.emitNumber} for the guard that turns this into a\n * thrown error instead.\n */\nconst MAX_CONSTANT_POOL_INDEX = 255;\n\n/** The `numberIndex` key for negative zero, which `Map` would otherwise fold into positive zero. */\nconst NEGATIVE_ZERO_KEY = \"-0\";\n\n/**\n * An operand that fits the byte the opcode stream stores it in, or a\n * structured refusal. `build()` copies the stream into a `Uint8Array`, which\n * keeps the low eight bits of whatever it is given: an operand of 300 used to\n * become 44 with no error, and the program then read a different constant,\n * plugin function or argument count from the one the parselet emitted. Every\n * raw operand goes through here, so a package author's mistake is reported at\n * compile time as a fault in the package rather than answered with a wrong\n * number.\n */\nfunction checkedOperand(value: number, what: string): number {\n\tif (!Number.isInteger(value) || value < 0 || value > 255) {\n\t\tthrow ErrorFactory.parsing(\n\t\t\t\"BYTECODE_OPERAND_OUT_OF_RANGE\",\n\t\t\t`A bytecode ${what} must be an integer from 0 to 255, but ${value} was emitted; the opcode stream stores one byte per operand.`,\n\t\t\t{ value, what }\n\t\t);\n\t}\n\treturn value;\n}\n\n/**\n * Compiled bytecode program produced by {@link BytecodeBuilder}.\n * Ready for consumption by {@link executeBytecode} without further processing.\n */\nexport interface BytecodeProgram {\n\topcodes: Uint8Array;\n\tnumbers: Float64Array;\n\tstrings: string[];\n\t/**\n\t * Numeric constants by opcode position, restored from a snapshot.\n\t *\n\t * Nothing in the compile path writes this: numbers are emitted inline into\n\t * {@link numbers} instead. `build()` used to attach an empty Map to every\n\t * program anyway, which was one allocation per compiled expression, around a\n\t * tenth of parse-and-compile time, for a collection that was never read.\n\t * It is left off now, and only {@link EngineSnapshot} sets it when restoring\n\t * a program that carried one; every reader already guards on its absence.\n\t */\n\tconstants?: Map<number, number>;\n\t/**\n\t * Whether the program contains any async opcodes (CALL_PLUGIN, etc.).\n\t * Set during compilation by the BytecodeBuilder. Allows the engine\n\t * to skip the O(n) resolver preflight check in O(1) for purely\n\t * synchronous expressions like `2 + 2`.\n\t */\n\thasAsync: boolean;\n\t/**\n\t * User-defined-function bodies compiled alongside this program (one\n\t * entry per `name(params) = body` definition on this line). See\n\t * {@link BytecodeBuilder.emitUserFunctionBody}. `OpCode.DEFINE_USER_FUNCTION`'s\n\t * operand is an index into this array, resolved at VM-execution time\n\t * (not parse time) so a diagnostic/lookahead parse that never actually\n\t * executes the definition line has no side effect on `vm.userFunctions`.\n\t */\n\tuserFunctionBodies?: UserFunctionDef[];\n\t/**\n\t * Anonymous function bodies compiled alongside this program, one entry\n\t * per `map`/`reduce` inline transform expression (e.g. the `10*x` in\n\t * `map(10*x, [0,1,500])`). See {@link BytecodeBuilder.emitAnonymousBody}.\n\t * Deliberately a SEPARATE side-table from `userFunctionBodies`, not\n\t * routed through `vm.userFunctions` at all: an inline body has no name\n\t * and must never leak into the persistent name-keyed registry the way\n\t * a real `f(x) = ...` definition does.\n\t */\n\tanonymousBodies?: AnonymousBodyDef[];\n}\n\n/**\n * An anonymous transform body for `map`/`reduce`'s inline-expression form\n * (e.g. `10*x` in `map(10*x, [0,1,500])`, or `acc+x` in `reduce(acc+x,\n * [1,2,3])`). Structurally identical to {@link UserFunctionDef} minus the\n * `name`. See `OpCode.MAP_INVOKE`/`REDUCE_INVOKE` and\n * `vm/VM.ts`'s handlers, which build a call frame from `params`/`args`\n * exactly like `CALL_USER_FUNCTION` does, just without ever registering\n * the body in `vm.userFunctions`.\n */\nexport interface AnonymousBodyDef {\n\tparams: string[];\n\tprogram: BytecodeProgram;\n}\n\n/**\n * A user-defined, parameterized, reusable function's compiled form\n * (`f(x) = 2*x + 1`). See `OpCode.DEFINE_USER_FUNCTION`/`CALL_USER_FUNCTION`\n * and `vm/VM.ts`'s `VM.defineUserFunction`/`getUserFunction`.\n *\n * `program` is the body compiled to its OWN independent `BytecodeProgram`,\n * not a fragment of the definition line's own bytecode. Parameter names\n * inside the body compile to ORDINARY `LOAD_VAR <name>` opcodes, no\n * parse-time rewriting, because parameter resolution happens dynamically\n * at the VM level: `CALL_USER_FUNCTION` pushes a name-keyed call frame\n * (`Map<string, Value>`) before re-executing `program`, and `VM.getVar()`\n * checks the innermost call frame before falling back to the flat\n * document-variable store. This is why a `UNIT`-collision parameter name\n * (e.g. `h` in `area(w, h) = w * h`, which lexes as the \"hour\" unit) needs\n * no special handling anywhere, it's just another `LOAD_VAR \"h\"`, resolved\n * the same way as any other name.\n */\nexport interface UserFunctionDef {\n\tname: string;\n\tparams: string[];\n\tprogram: BytecodeProgram;\n}\n\n/**\n * Shared empty collections for programs that emit none.\n *\n * `build()` runs once per compiled expression, so an empty array allocated\n * there is an allocation per line of every document. Most programs emit no\n * strings at all (only the unit and datetime parselets do), and one that emits\n * no numbers is common too, so both were routinely allocating an empty\n * container that nothing would ever read.\n *\n * Sharing them is safe because a built program is read-only downstream: the VM\n * and the snapshot writer only index and iterate these, and nothing in the\n * engine pushes to `program.strings` or `program.numbers`. They are frozen so\n * that a future writer fails loudly here rather than silently corrupting every\n * other program that shares the instance.\n */\nconst EMPTY_STRINGS: readonly string[] = Object.freeze([]);\nconst EMPTY_NUMBERS = new Float64Array(0);\n\n/**\n * Direct-to-bytecode compiler for the Pratt parser.\n *\n * Accumulates opcodes, numeric constants, and string references during parsing,\n * then produces a {@link BytecodeProgram} for VM execution. Supports:\n * - Standard build via {@link build}\n * - Zero-copy build into pre-allocated buffers via {@link buildInto}\n * - In-place reset for reuse without reallocation\n */\nexport class BytecodeBuilder {\n\tprivate opcodes: number[] = [];\n\tprivate numbers: number[] = [];\n\tprivate strings: string[] = [];\n\tprivate stringIndex = new Map<string, number>();\n\t/** Value (or {@link NEGATIVE_ZERO_KEY}) to its slot in `numbers`, so a repeated literal is emitted once. */\n\tprivate numberIndex = new Map<number | string, number>();\n\tprivate _hasAsync = false;\n\tprivate userFunctionBodies: UserFunctionDef[] = [];\n\tprivate anonymousBodies: AnonymousBodyDef[] = [];\n\n\t/**\n\t * The per-engine `plugin function name -> registry index` map, wired in by\n\t * the engine so {@link emitPluginCall} can resolve a name at emit time. The\n\t * same object reference is shared with every builder in an engine (the pool\n\t * and each ad-hoc nested-body builder), and the engine populates it as\n\t * packages register, so a parselet never sees the numeric index.\n\t */\n\tconstructor(private readonly pluginFunctionIndex?: ReadonlyMap<string, number>) {}\n\n\t/** The name->index map, so a nested-body builder inherits the same resolution. */\n\tget pluginIndexMap(): ReadonlyMap<string, number> | undefined {\n\t\treturn this.pluginFunctionIndex;\n\t}\n\n\t/**\n\t * Emit a plugin-function call by NAME. The engine assigns each registered\n\t * `pluginFunctions` entry an index at registration; this resolves the name to\n\t * that index and emits `CALL_PLUGIN` + index + argCount. Package authors emit\n\t * through this rather than a hand-allocated index.\n\t */\n\temitPluginCall(name: string, argCount: number): void {\n\t\tconst index = this.pluginFunctionIndex?.get(name);\n\t\tif (index === undefined) {\n\t\t\tthrow ErrorFactory.execution(\n\t\t\t\t\"UNKNOWN_PLUGIN_FUNCTION\",\n\t\t\t\t`No registered plugin function named \"${name}\". A package must declare it in its pluginFunctions record and be registered before an expression using it is parsed.`,\n\t\t\t\t{ functionName: name },\n\t\t\t);\n\t\t}\n\t\t// One byte covers the first 256 plugin functions; beyond that, the\n\t\t// wide opcode carries a two-byte little-endian index. Emitting the\n\t\t// narrow form whenever it fits keeps existing bytecode and snapshots\n\t\t// byte-for-byte unchanged. The index cannot exceed 65535 because the\n\t\t// allocator (allocatePluginFunctionIndex) caps it, but guard anyway so\n\t\t// a stray index is a clear error rather than a silently truncated byte.\n\t\tif (index > 0xffff) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"PLUGIN_FUNCTION_INDEX_TOO_LARGE\",\n\t\t\t\t`Plugin-function index ${index} exceeds the two-byte bytecode limit (65535).`,\n\t\t\t\t{ index },\n\t\t\t);\n\t\t}\n\t\tif (index <= 0xff) {\n\t\t\tthis.emitOpcode(OpCode.CALL_PLUGIN);\n\t\t\tthis.emitIndex(index);\n\t\t} else {\n\t\t\tthis.emitOpcode(OpCode.CALL_PLUGIN_WIDE);\n\t\t\tthis.emitIndex(index & 0xff); // low byte\n\t\t\tthis.emitIndex((index >> 8) & 0xff); // high byte\n\t\t}\n\t\tthis.emitIndex(argCount);\n\t}\n\n\t/** Emit an {@link OpCode} instruction. */\n\temitOpcode(op: OpCode): void {\n\t\tthis.opcodes.push(op);\n\t\tif (op === OpCode.CALL_PLUGIN || op === OpCode.CALL_PLUGIN_WIDE) {\n\t\t\tthis._hasAsync = true;\n\t\t}\n\t}\n\n\t/**\n\t * Emit a numeric literal: interns `n` into the program's constant pool\n\t * (deduplicated, like {@link emitString}) and writes its index into the\n\t * opcode stream (read back by the VM as e.g. `PUSH_NUMBER <idx>`).\n\t *\n\t * Deduplicated so that the 256-entry pool counts distinct values rather\n\t * than occurrences: a long line of repeated literals used to exhaust it\n\t * long before it held 256 different numbers. Negative zero keeps its own\n\t * slot, because `1 / -0` is not `1 / 0`; NaN shares one, since every NaN\n\t * reads the same.\n\t *\n\t * @throws If the pool would exceed 256 distinct entries.\n\t */\n\temitNumber(n: number): void {\n\t\tconst key = Object.is(n, -0) ? NEGATIVE_ZERO_KEY : n;\n\t\tlet idx = this.numberIndex.get(key);\n\t\tif (idx === undefined) {\n\t\t\tidx = this.numbers.length;\n\t\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\t\"TOO_MANY_NUMERIC_CONSTANTS\",\n\t\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} distinct numeric literals, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.numbers.push(n);\n\t\t\tthis.numberIndex.set(key, idx);\n\t\t}\n\t\tthis.opcodes.push(idx);\n\t}\n\n\t/**\n\t * Emit a string literal: interns `s` into the program's string pool\n\t * (deduplicated via `stringIndex`) and writes its index into the opcode\n\t * stream. Subject to the same constant-pool bound as {@link emitNumber},\n\t * but since strings ARE deduplicated, only distinct string values count\n\t * against the limit.\n\t *\n\t * @throws If the string pool would exceed 256 distinct entries.\n\t */\n\temitString(s: string): void {\n\t\tlet idx = this.stringIndex.get(s);\n\t\tif (idx === undefined) {\n\t\t\tidx = this.strings.length;\n\t\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\t\"TOO_MANY_STRING_CONSTANTS\",\n\t\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} distinct string literals, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.strings.push(s);\n\t\t\tthis.stringIndex.set(s, idx);\n\t\t}\n\t\tthis.opcodes.push(idx);\n\t}\n\n\t/**\n\t * Emit a raw numeric operand (0-255) following an opcode, e.g. a\n\t * plugin-function index for `CALL_PLUGIN`, or an argument count. Unlike\n\t * {@link emitOpcode}, this does not go through the `OpCode` enum, so\n\t * package authors use this (not an unsafe cast to `OpCode`) to push\n\t * operands their own opcode handler expects to read positionally.\n\t */\n\temitIndex(idx: number): void {\n\t\tthis.opcodes.push(checkedOperand(idx, \"index\"));\n\t}\n\n\t/** Emit a raw byte (0-255), used for fixed small operands like argument counts. */\n\temitByte(b: number): void {\n\t\tthis.opcodes.push(checkedOperand(b, \"byte\"));\n\t}\n\n\t/** Number of opcodes/operands emitted so far, used to compute jump targets before {@link patchJump}. */\n\tget currentLength(): number {\n\t\treturn this.opcodes.length;\n\t}\n\n\t/**\n\t * Register a compiled user-defined-function body, returning its index\n\t * into this program's `userFunctionBodies` side-table, the caller emits\n\t * that index as `DEFINE_USER_FUNCTION`'s operand via {@link emitIndex}.\n\t * Subject to the same {@link MAX_CONSTANT_POOL_INDEX} bound as\n\t * {@link emitNumber}/{@link emitString} (the index itself is a single\n\t * opcode-stream byte), in practice a single line defines at most a\n\t * handful of functions, so this limit is never realistically reached.\n\t *\n\t * @throws If more than 256 function bodies are registered on one program.\n\t */\n\temitUserFunctionBody(name: string, params: string[], program: BytecodeProgram): number {\n\t\tconst idx = this.userFunctionBodies.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_FUNCTION_DEFINITIONS\",\n\t\t\t\t`More than ${MAX_CONSTANT_POOL_INDEX + 1} function definitions on one line, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t);\n\t\t}\n\t\tthis.userFunctionBodies.push({ name, params, program });\n\t\treturn idx;\n\t}\n\n\t/**\n\t * Register a compiled `map`/`reduce` anonymous transform body, returning\n\t * its index into this program's `anonymousBodies` side-table, the\n\t * caller emits that index as `MAP_INVOKE`/`REDUCE_INVOKE`'s operand via\n\t * {@link emitIndex}. Same {@link MAX_CONSTANT_POOL_INDEX} bound as\n\t * {@link emitUserFunctionBody}.\n\t *\n\t * @throws If more than 256 anonymous bodies are registered on one program.\n\t */\n\temitAnonymousBody(params: string[], program: BytecodeProgram): number {\n\t\tconst idx = this.anonymousBodies.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_ANONYMOUS_BODIES\",\n\t\t\t\t`More than ${MAX_CONSTANT_POOL_INDEX + 1} map/reduce transform expressions on one line, exceeding the bytecode constant pool's limit.`,\n\t\t\t\t{ limit: MAX_CONSTANT_POOL_INDEX + 1 }\n\t\t\t);\n\t\t}\n\t\tthis.anonymousBodies.push({ params, program });\n\t\treturn idx;\n\t}\n\n\t/** Overwrite a previously-emitted placeholder operand at `position` with the real jump `target`, once known. */\n\tpatchJump(position: number, target: number): void {\n\t\tif (position < 0 || position >= this.opcodes.length) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"BYTECODE_OPERAND_OUT_OF_RANGE\",\n\t\t\t\t`patchJump was asked to write at position ${position}, outside the ${this.opcodes.length} bytes emitted so far.`,\n\t\t\t\t{ position, length: this.opcodes.length }\n\t\t\t);\n\t\t}\n\t\tthis.opcodes[position] = checkedOperand(target, \"jump target\");\n\t}\n\n\t/**\n\t * Build the accumulated opcodes/numbers/strings into a BytecodeProgram.\n\t * Creates new TypedArrays, the builder can be reused after this call.\n\t */\n\tbuild(): BytecodeProgram {\n\t\treturn {\n\t\t\topcodes: new Uint8Array(this.opcodes),\n\t\t\tnumbers: this.numbers.length > 0 ? new Float64Array(this.numbers) : EMPTY_NUMBERS,\n\t\t\t// Defensive copy when there is anything to copy: reset()'s\n\t\t\t// `.length = 0` would otherwise clear a reference the program still\n\t\t\t// holds. An empty one needs no copy, so it shares the frozen\n\t\t\t// singleton instead of allocating per program.\n\t\t\tstrings: this.strings.length > 0 ? [...this.strings] : (EMPTY_STRINGS as string[]),\n\t\t\thasAsync: this._hasAsync,\n\t\t\tuserFunctionBodies: this.userFunctionBodies.length > 0 ? [...this.userFunctionBodies] : undefined,\n\t\t\tanonymousBodies: this.anonymousBodies.length > 0 ? [...this.anonymousBodies] : undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Build directly into a pre-allocated buffer for zero-copy VM consumption.\n\t *\n\t * When `buf` is provided and large enough, writes into it and returns\n\t * subarray **views** (not copies), the returned TypedArrays share the\n\t * buffer's underlying ArrayBuffer. The caller MUST NOT mutate the buffer\n\t * until the returned BytecodeProgram is no longer needed.\n\t *\n\t * If the caller intends to cache the result, they must copy the TypedArrays\n\t * (e.g. `new Uint8Array(program.opcodes)`) before reusing the buffer pool.\n\t *\n\t * When `buf` is omitted or too small, allocates fresh TypedArrays.\n\t */\n\tbuildInto(buf?: { opcodes: Uint8Array; numbers: Float64Array }): BytecodeProgram {\n\t\tconst opLen = this.opcodes.length;\n\t\tconst numLen = this.numbers.length;\n\n\t\tconst reuseOpcodes = buf && buf.opcodes.length >= opLen;\n\t\tconst reuseNumbers = buf && buf.numbers.length >= numLen;\n\n\t\t// Subarray views that share the buffer's ArrayBuffer (zero-copy)\n\t\tconst opcodes = reuseOpcodes\n\t\t\t? new Uint8Array(buf!.opcodes.buffer, buf!.opcodes.byteOffset, opLen)\n\t\t\t: new Uint8Array(opLen);\n\t\tconst numbers = reuseNumbers\n\t\t\t? new Float64Array(buf!.numbers.buffer, buf!.numbers.byteOffset, numLen)\n\t\t\t: new Float64Array(numLen);\n\n\t\t// Write data into the views\n\t\tfor (let i = 0; i < opLen; i++) opcodes[i] = this.opcodes[i];\n\t\tfor (let i = 0; i < numLen; i++) numbers[i] = this.numbers[i];\n\n\t\treturn {\n\t\t\topcodes,\n\t\t\tnumbers,\n\t\t\tstrings: [...this.strings],\n\t\t\thasAsync: this._hasAsync,\n\t\t\tuserFunctionBodies: this.userFunctionBodies.length > 0 ? [...this.userFunctionBodies] : undefined,\n\t\t\tanonymousBodies: this.anonymousBodies.length > 0 ? [...this.anonymousBodies] : undefined,\n\t\t};\n\t}\n\n\treset(): void {\n\t\t// Retain backing stores with .length = 0 to avoid reallocation on growth.\n\t\t// = [] discards the ArrayBuffer, forcing V8 to reallocate on every push()\n\t\t// threshold (4→8→16→32...). For a 50-opcode expression, that's 3-4 copies.\n\t\tthis.opcodes.length = 0;\n\t\tif (this.numbers.length > 0) {\n\t\t\tthis.numbers.length = 0;\n\t\t\tthis.numberIndex.clear();\n\t\t}\n\t\t// Guarded on being non-empty. reset() runs once per compiled expression\n\t\t// and a CPU profile put it at over a tenth of parse-and-compile, which\n\t\t// is a lot for clearing collections that are usually already empty:\n\t\t// most expressions emit no strings, and user function bodies are rarer\n\t\t// still. Emptying an empty Map is not free, and neither is the write\n\t\t// barrier on a length assignment.\n\t\tif (this.strings.length > 0) {\n\t\t\tthis.strings.length = 0;\n\t\t\tthis.stringIndex.clear();\n\t\t}\n\t\tthis._hasAsync = false;\n\t\tif (this.userFunctionBodies.length > 0) this.userFunctionBodies.length = 0;\n\t\tif (this.anonymousBodies.length > 0) this.anonymousBodies.length = 0;\n\t}\n}\n","/**\n * Turning a `123n` literal's source text into the digits `PUSH_BIGINT` stores.\n *\n * The lexer coalesces thousands groups into the number token it is building,\n * accepting both `,` and `.` as the separator regardless of locale (see\n * `lexer/ExpressionLexer.ts`'s \"Thousands separators\" block). For a NUMBER that\n * is fine, because the separators are stripped again when the text is turned\n * into a double. For a BIGINT nothing stripped them: both consumers took the\n * token text, removed the trailing `n`, and handed the rest straight to\n * `BigInt()`.\n *\n * So `1.000n` reached `BigInt(\"1.000\")`, which throws a raw `SyntaxError` that\n * arrived at the host as UNEXPECTED_ERROR/INTERNAL: the engine reporting its\n * own bug for six characters a user typed. `1.01n` and `1.1n` were fine, which\n * is the tell that the `n` suffix was never the problem, the three-digit\n * thousands group was: a dot followed by exactly three digits is what the lexer\n * swallows, and one followed by one or two digits it leaves alone.\n *\n * Written once here rather than inline at both call sites. There are two\n * (`parser/PrecedenceParser.ts`'s Tier-1 switch and\n * `packages/biginteger/parselets/BigIntNumberParselet.ts`), they already held\n * identical copies of the `n`-stripping, and the two tiers disagreeing about a\n * literal is a bug shape this codebase has had before.\n *\n * @module BigIntLiteral\n */\n\nimport { getLocale } from \"@solve-js/constants/locales\";\nimport { ErrorFactory } from \"@solve-js/errors/UnifiedErrorFramework\";\n\n/**\n * Two or more dot-separated groups of three, e.g. `1.234.567`.\n *\n * Unambiguous in any locale, since no locale writes two decimal points, so this\n * is stripped without consulting one. Same regex and same reasoning as\n * `NumberParselet.ts`'s copy for the NUMBER path.\n */\nconst CHAINED_DOT_THOUSANDS_GROUPS = /^\\d{1,3}(\\.\\d{3}){2,}$/;\n\n/** Digits and nothing else, which is what `BigInt()` can be handed safely. */\nconst DIGITS_ONLY = /^\\d+$/;\n\n/**\n * The digit string behind a bigint literal.\n *\n * A bigint literal has no fractional part by construction: the lexer only emits\n * BIGINT when it saw no decimal point of its own and no exponent, so any `.` or\n * `,` still in the text got there as a thousands group. Which of the two the\n * writer meant is a locale question, and answering it wrongly would silently\n * change the value by three orders of magnitude, so only the separator this\n * locale actually uses for grouping is removed. Anything left over is refused\n * rather than guessed at.\n *\n * @param raw - The token's text, with or without the trailing `n`.\n * @param localeCode - The engine's active locale.\n * @returns A string of digits, ready for `BigInt()`.\n * @throws An `INVALID_NUMBER_LITERAL` parsing error when what is left is not a\n * whole number, e.g. `1.000n` in a locale that writes decimals with a dot.\n */\nexport function bigIntLiteralDigits(raw: string, localeCode: string): string {\n\tconst withoutSuffix = raw.endsWith(\"n\") ? raw.slice(0, -1) : raw;\n\n\t// The common case first: nothing was grouped, so there is nothing to decide.\n\tif (DIGITS_ONLY.test(withoutSuffix)) return withoutSuffix;\n\n\tconst digits = CHAINED_DOT_THOUSANDS_GROUPS.test(withoutSuffix)\n\t\t? withoutSuffix.split(\".\").join(\"\")\n\t\t: stripLocaleGrouping(withoutSuffix, localeCode);\n\n\tif (!DIGITS_ONLY.test(digits)) {\n\t\tconst separator = withoutSuffix.includes(\".\") ? \".\" : withoutSuffix.includes(\",\") ? \",\" : withoutSuffix;\n\t\tthrow ErrorFactory.parsing(\n\t\t\t\"INVALID_NUMBER_LITERAL\",\n\t\t\t`\"${raw}\" is not a whole number: \"${separator}\" separates decimals in the ${localeCode} locale, and a whole number cannot have a fractional part.`,\n\t\t\t{ raw, localeCode, separator },\n\t\t);\n\t}\n\treturn digits;\n}\n\n/**\n * Removes the active locale's own thousands separator and nothing else.\n *\n * @param text - The literal without its `n`.\n * @param localeCode - The engine's active locale.\n * @returns The text with grouping removed, which the caller then re-checks.\n */\nfunction stripLocaleGrouping(text: string, localeCode: string): string {\n\tconst thousandsSeparator = getLocale(localeCode).display.thousandsSeparator;\n\treturn thousandsSeparator ? text.split(thousandsSeparator).join(\"\") : text;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkHG4NPDN5_cjs=require('./chunk-HG4NPDN5.cjs'),chunkFESR6PZI_cjs=require('./chunk-FESR6PZI.cjs'),chunkSF5QVUEI_cjs=require('./chunk-SF5QVUEI.cjs'),chunkABVDKMNF_cjs=require('./chunk-ABVDKMNF.cjs'),chunkWFT3XUSH_cjs=require('./chunk-WFT3XUSH.cjs'),chunkE4HAKNBQ_cjs=require('./chunk-E4HAKNBQ.cjs'),chunkS3SPDK6N_cjs=require('./chunk-S3SPDK6N.cjs'),chunkPHWIO4P3_cjs=require('./chunk-PHWIO4P3.cjs'),chunkEZKR44MA_cjs=require('./chunk-EZKR44MA.cjs'),chunk6SYU4MH7_cjs=require('./chunk-6SYU4MH7.cjs');var $n=class{constructor(){this.consumers=new Map;this.dependencies=new Map;this.writes=new Map;this.lineReads=new Map;this.dataSourceDependencies=new Map;this.dataSourceConsumers=new Map;}registerLine(a,s,u){let c=this.lineReads.get(a);if(c)for(let b of c){let h=this.consumers.get(b);h&&h.delete(a);}this.lineReads.set(a,new Set(s));for(let b of s)this.consumers.has(b)||this.consumers.set(b,new Set),this.consumers.get(b).add(a);if(u.length>0){this.dependencies.set(a,new Set(s)),this.writes.set(a,new Set(u));for(let b of u){let h=this.consumers.get(b);h&&h.delete(a);}}}registerLineDataSourceDependency(a,s,u){let c=JSON.stringify(u),b=`${s}:${c}`;this.dataSourceDependencies.has(a)||this.dataSourceDependencies.set(a,new Set),this.dataSourceDependencies.get(a).add(b),this.dataSourceConsumers.has(b)||this.dataSourceConsumers.set(b,new Set),this.dataSourceConsumers.get(b).add(a);}getAffectedLines(a){let s=new Set,u=[a];for(;u.length>0;){let c=u.pop(),b=this.consumers.get(c);if(b)for(let h of b){if(s.has(h))continue;s.add(h);let f=this.writes.get(h);if(f)for(let y of f)u.push(y);}}return s}getAffectedLinesInOrder(a){let s=this.getAffectedLines(a);if(s.size===0)return [];let u=new Map,c=new Map;for(let y of s)u.has(y)||u.set(y,0),c.has(y)||c.set(y,[]);let b=new Map;for(let y of s){let E=this.writes.get(y);if(E)for(let S of E)b.set(S,y);}for(let y of s){let E=this.lineReads.get(y);if(E)for(let S of E){let T=b.get(S);T!==void 0&&T!==y&&(c.get(T).push(y),u.set(y,(u.get(y)??0)+1));}}let h=[];for(let[y,E]of u)E===0&&h.push(y);if(h.length===0&&s.size>0){let y=Array.from(s).sort((E,S)=>E-S);h.push(y[0]);}let f=[];for(let y=0;y<h.length;y++){let E=h[y];f.push(E);for(let S of c.get(E)??[]){let T=(u.get(S)??1)-1;u.set(S,T),T===0&&h.push(S);}}if(f.length<s.size){let y=new Set(f),E=Array.from(s).filter(S=>!y.has(S)).sort((S,T)=>S-T);f.push(...E);}return f}getAffectedLinesByDataSource(a,s){let u=JSON.stringify(s),c=`${a}:${u}`;return this.dataSourceConsumers.get(c)??new Set}removeLine(a){let s=this.lineReads.get(a);if(s){for(let c of s){let b=this.consumers.get(c);b&&b.delete(a);}this.lineReads.delete(a);}this.dependencies.delete(a),this.writes.delete(a);let u=this.dataSourceDependencies.get(a);if(u){for(let c of u)this.dataSourceConsumers.get(c)?.delete(a);this.dataSourceDependencies.delete(a);}}getConsumers(a){return this.consumers.get(a)??new Set}getDependencies(a){return this.dependencies.get(a)??new Set}getWrites(a){return this.writes.get(a)??new Set}getSnapshot(){let a={};for(let[h,f]of this.consumers)a[h]=Array.from(f);let s={};for(let[h,f]of this.writes)s[h]=Array.from(f);let u={};for(let[h,f]of this.lineReads)u[h]=Array.from(f);let c={};for(let[h,f]of this.dataSourceDependencies)c[h]=Array.from(f);let b={};for(let[h,f]of this.dataSourceConsumers)b[h]=Array.from(f);return {consumers:a,writes:s,reads:u,dataSourceDeps:c,dataSourceConsumers:b}}clear(){this.consumers.clear(),this.dependencies.clear(),this.writes.clear(),this.lineReads.clear(),this.dataSourceDependencies.clear(),this.dataSourceConsumers.clear();}};var Pn=class{constructor(){this.definitions=new Map;}write(a,s,u){this.definitions.has(a)||this.definitions.set(a,[]);let c=this.definitions.get(a);c.push({line:s,expr:u}),c.sort((b,h)=>b.line-h.line);}read(a,s){let u=this.definitions.get(a);if(u){for(let c=u.length-1;c>=0;c--)if(u[c].line<=s)return u[c].expr.lastResult}}invalidateDownstream(a,s){let u=this.definitions.get(a);if(!u)return;let c=u.findIndex(b=>b.line===s);c!==-1&&u.splice(c+1);}clear(){this.definitions.clear();}};var nn={kg:{dim:[1,0,0,0],si:1},g:{dim:[1,0,0,0],si:.001},tonne:{dim:[1,0,0,0],si:1e3},t:{dim:[1,0,0,0],si:1e3},m:{dim:[0,1,0,0],si:1},cm:{dim:[0,1,0,0],si:.01},mm:{dim:[0,1,0,0],si:.001},km:{dim:[0,1,0,0],si:1e3},s:{dim:[0,0,1,0],si:1},ms:{dim:[0,0,1,0],si:.001},min:{dim:[0,0,1,0],si:60},minute:{dim:[0,0,1,0],si:60},minutes:{dim:[0,0,1,0],si:60},h:{dim:[0,0,1,0],si:3600},hr:{dim:[0,0,1,0],si:3600},hour:{dim:[0,0,1,0],si:3600},hours:{dim:[0,0,1,0],si:3600},A:{dim:[0,0,0,1],si:1},mA:{dim:[0,0,0,1],si:.001},kA:{dim:[0,0,0,1],si:1e3},ampere:{dim:[0,0,0,1],si:1},amperes:{dim:[0,0,0,1],si:1},mps2:{dim:[0,1,-2,0],si:1},N:{dim:[1,1,-2,0],si:1},kN:{dim:[1,1,-2,0],si:1e3},newton:{dim:[1,1,-2,0],si:1},newtons:{dim:[1,1,-2,0],si:1},J:{dim:[1,2,-2,0],si:1},kJ:{dim:[1,2,-2,0],si:1e3},MJ:{dim:[1,2,-2,0],si:1e6},joule:{dim:[1,2,-2,0],si:1},joules:{dim:[1,2,-2,0],si:1},Wh:{dim:[1,2,-2,0],si:3600},kWh:{dim:[1,2,-2,0],si:36e5},W:{dim:[1,2,-3,0],si:1},kW:{dim:[1,2,-3,0],si:1e3},MW:{dim:[1,2,-3,0],si:1e6},watt:{dim:[1,2,-3,0],si:1},watts:{dim:[1,2,-3,0],si:1},Pa:{dim:[1,-1,-2,0],si:1},kPa:{dim:[1,-1,-2,0],si:1e3},MPa:{dim:[1,-1,-2,0],si:1e6},pascal:{dim:[1,-1,-2,0],si:1},pascals:{dim:[1,-1,-2,0],si:1},V:{dim:[1,2,-3,-1],si:1},mV:{dim:[1,2,-3,-1],si:.001},kV:{dim:[1,2,-3,-1],si:1e3},volt:{dim:[1,2,-3,-1],si:1},volts:{dim:[1,2,-3,-1],si:1}},st={"1,1,-2,0":"N","1,2,-2,0":"J","1,2,-3,0":"W","1,-1,-2,0":"Pa","1,2,-3,-1":"V"},ot=r=>r.join(",");function tn(r,a,s){if(r.type!==6||a.type!==6)return null;let u=r.unit?nn[r.unit]:void 0,c=a.unit?nn[a.unit]:void 0;if(u===void 0||c===void 0)return null;let b=[u.dim[0]+(s?c.dim[0]:-c.dim[0]),u.dim[1]+(s?c.dim[1]:-c.dim[1]),u.dim[2]+(s?c.dim[2]:-c.dim[2]),u.dim[3]+(s?c.dim[3]:-c.dim[3])],h=st[ot(b)];if(h===void 0)return null;let f=r.toNumber()*u.si,y=a.toNumber()*c.si,E=s?f*y:f/y;return chunkS3SPDK6N_cjs.u(E/nn[h].si,h)}function ut(r,a){let s=a.fields(r).weekday;return s===0||s===6}function Wn(r,a,s){return ut(r,s)?false:a?!a(r):true}function Yn(r,a){let s=a.fields(r);return a.localMidnight(s.year,s.month0,s.day)}function Gn(r,a,s,u,c){let b=Math.trunc(Math.abs(a)),h=a>=0?1:-1,f=r,y=0;for(;b>0;){if(f=c.addDays(f,h),y++,y>u)return null;Wn(f,s,c)&&b--;}return f}function Xn(r,a,s,u,c){let b=Yn(Math.min(r,a),c),h=Yn(Math.max(r,a),c),f=Math.round((h-b)/864e5);if(f>u)return null;let y=0,E=b;for(let S=0;S<=f;S++)Wn(E,s,c)&&y++,E=c.addDays(E,1);return y}var lt={0:{name:"sqrt",min:1,max:1},1:{name:"abs",min:1,max:1},2:{name:"sin",min:1,max:1},3:{name:"cos",min:1,max:1},4:{name:"tan",min:1,max:1},5:{name:"log",min:1,max:1},6:{name:"ceil",min:1,max:1},7:{name:"floor",min:1,max:1},8:{name:"round",min:1,max:2},9:{name:"min",min:1,max:1/0},10:{name:"max",min:1,max:1/0},11:{name:"asin",min:1,max:1},12:{name:"acos",min:1,max:1},13:{name:"atan",min:1,max:1},14:{name:"atan2",min:2,max:2},15:{name:"sinh",min:1,max:1},16:{name:"cosh",min:1,max:1},17:{name:"tanh",min:1,max:1},18:{name:"asinh",min:1,max:1},19:{name:"acosh",min:1,max:1},20:{name:"atanh",min:1,max:1},21:{name:"cbrt",min:1,max:1},22:{name:"clz32",min:1,max:1},23:{name:"expm1",min:1,max:1},24:{name:"exp",min:1,max:1},25:{name:"fround",min:1,max:1},26:{name:"hypot",min:1,max:1/0},27:{name:"imul",min:2,max:2},28:{name:"log10",min:1,max:1},29:{name:"log1p",min:1,max:1},30:{name:"log2",min:1,max:1},31:{name:"pow",min:2,max:2},32:{name:"random",min:0,max:0},33:{name:"sign",min:1,max:1},34:{name:"trunc",min:1,max:1},35:{name:"degtorad",min:1,max:1},36:{name:"radtodeg",min:1,max:1},37:{name:"roll",min:2,max:2},38:{name:"gcd",min:2,max:2},39:{name:"lcm",min:2,max:2},40:{name:"permutation",min:2,max:2},41:{name:"combination",min:2,max:2},42:{name:"average",min:0,max:1/0},43:{name:"median",min:0,max:1/0},44:{name:"total",min:0,max:1/0},45:{name:"count",min:0,max:1/0},46:{name:"proportion",min:3,max:3},47:{name:"clamp",min:3,max:3},48:{name:"hex",min:1,max:1},49:{name:"bin",min:1,max:1},50:{name:"int",min:1,max:1},51:{name:"compoundInterest",min:3,max:3},52:{name:"interestEarned",min:3,max:3},53:{name:"compoundInterestRate",min:3,max:3},54:{name:"compoundInterestYears",min:3,max:3},55:{name:"loanRepayment",min:4,max:4},56:{name:"loanInterest",min:4,max:4},57:{name:"monthlyPayment",min:3,max:3},58:{name:"taxAdd",min:2,max:2},59:{name:"taxRemove",min:2,max:2},60:{name:"inflationAdjust",min:3,max:3},61:{name:"root",min:2,max:2},62:{name:"fact",min:1,max:1},63:{name:"transpose",min:1,max:1},64:{name:"det",min:1,max:1},65:{name:"inv",min:1,max:1},66:{name:"dot",min:2,max:2},67:{name:"expand",min:1,max:1},68:{name:"factor",min:1,max:1},69:{name:"solve",min:3,max:3},70:{name:"der",min:2,max:3},71:{name:"integral",min:2,max:2},72:{name:"taylor",min:4,max:4},73:{name:"jacobian",min:1,max:1/0},74:{name:"imaginary",min:1,max:1},75:{name:"conj",min:1,max:1},76:{name:"re",min:1,max:1},77:{name:"im",min:1,max:1},78:{name:"cancel",min:1,max:1},79:{name:"apart",min:1,max:1},80:{name:"compoundInterestEvery",min:4,max:4},81:{name:"compoundInterestEarnedEvery",min:4,max:4},82:{name:"presentValue",min:3,max:3},83:{name:"roi",min:2,max:2},84:{name:"annualisedReturn",min:3,max:3},85:{name:"taxIn",min:2,max:2},86:{name:"taxOn",min:2,max:2},87:{name:"sind",min:1,max:1},88:{name:"cosd",min:1,max:1},89:{name:"tand",min:1,max:1},90:{name:"asind",min:1,max:1},91:{name:"acosd",min:1,max:1},92:{name:"atand",min:1,max:1},93:{name:"daysCount",min:1,max:1},94:{name:"asTwoUnits",min:3,max:3},95:{name:"makeRate",min:2,max:2},96:{name:"atRate",min:2,max:2},97:{name:"roundToPlaces",min:2,max:2},98:{name:"splitEach",min:2,max:2},99:{name:"savingsGoalPayment",min:3,max:3},100:{name:"savingsGoalPeriods",min:5,max:5},101:{name:"standardDeviation",min:0,max:1/0},102:{name:"sampleStandardDeviation",min:0,max:1/0},103:{name:"variance",min:0,max:1/0},104:{name:"sampleVariance",min:0,max:1/0},105:{name:"spread",min:0,max:1/0},106:{name:"mode",min:0,max:1/0},107:{name:"weightedAverage",min:2,max:1/0}};function Te(r){return r===1?"1 argument":`${r} arguments`}function ct(r){return r.max===1/0?`at least ${Te(r.min)}`:r.min===r.max?Te(r.min):`${r.min} to ${Te(r.max)}`}function Kn(r,a){let s=lt[r];if(s!==void 0&&!(a>=s.min&&a<=s.max))return chunk6SYU4MH7_cjs.c.execution("BUILTIN_ARITY_MISMATCH",`${s.name}() takes ${ct(s)}, but was given ${a===0?"none":Te(a)}`,{functionName:s.name,expectedMin:s.min,expectedMax:s.max,actual:a})}function da(r,a=200,s=5e4,u=50,c=1e5,b=2e6,h=1e4,f=100,y=-100,E=chunkFESR6PZI_cjs.y,S){let T=[],x=new Map,Y=0,z,W,t=[],J=new Map,oe=new Map,H=new Map;return {push(_){if(T.length>=a)throw chunk6SYU4MH7_cjs.c.execution("STACK_LIMIT_EXCEEDED",`Execution exceeded maximum stack depth of ${a}`);T.push(_);},getMaxStackDepth(){return a},getMaxCollectionSize(){return c},getMaxAllocatedElements(){return b},getMaxFunctionCalls(){return h},getMaxDateOffsetYears(){return f},getMinDateOffsetYears(){return y},isHoliday(_){return S?S(_):false},pop(){return m(T)},popNumber(){return m(T).toNumber()},popString(){return j(m(T),"VM.popString()")},peek(){return T[T.length-1]},getStack(){return T},registry:r,getVar(_){if(t.length>0){let g=t[t.length-1].get(_);if(g!==void 0)return g}return x.get(_)},setVar(_,g){x.set(_,g);},deleteVar(_){x.delete(_);},pushCallFrame(_){if(t.length>=u)throw chunk6SYU4MH7_cjs.c.execution("FUNCTION_RECURSION_LIMIT_EXCEEDED",`Function call nesting exceeded maximum depth of ${u} (possible infinite recursion, e.g. f(x) = f(x))`,{maxFunctionRecursionDepth:u});t.push(_);},popCallFrame(){t.pop();},getCallFrame(){return t.length>0?t[t.length-1]:void 0},defineUserFunction(_,g,e){J.set(_,{name:_,params:g,program:e});},getUserFunction(_){return J.get(_)},hasUserFunction(_){return J.has(_)},getVariableEntries(){return Array.from(x.entries())},getUserFunctionDefs(){return Array.from(J.values())},defineEquation(_,g,e){oe.set(_,{variable:_,factorNames:g,rhsProgram:e});},getEquation(_){return oe.get(_)},hasEquation(_){return oe.has(_)},defineScalarEquation(_,g,e){H.set(_,{variable:_,lhsProgram:g,rhsProgram:e});},getScalarEquation(_){return H.get(_)},hasScalarEquation(_){return H.has(_)},reset(){T.length=0,x.clear(),t.length=0,J.clear(),oe.clear(),H.clear(),Y=0,W&&(W(),W=void 0),z=void 0;},get activeSignal(){return z},set activeSignal(_){z=_;},get abortCurrent(){return W},set abortCurrent(_){W=_;},context:E,getMaxInstructions(){return s},getInstructionCount(){return Y},incrementInstructions(_){if(Y+=_,Y>s)throw chunk6SYU4MH7_cjs.c.execution("INSTRUCTION_LIMIT_EXCEEDED",`Execution exceeded maximum of ${s} instructions`)}}}function mt(r,a){return r.rows===1&&r.cols===1?a.data.length:a.rows===1&&a.cols===1?r.data.length:r.cols!==a.rows?0:r.rows*a.cols}function dt(r,a){return !Number.isInteger(a)||a<0?0:r.rows*r.cols*(1+(a<2?1:2*Math.floor(Math.log2(a))))}function Hn(r,a,s){return r.context.networkEnabled?chunkS3SPDK6N_cjs.P("CURRENCY_RATE_UNAVAILABLE",`No exchange rate available for ${a} to ${s}`):chunkS3SPDK6N_cjs.P("NETWORK_DISABLED",`No exchange rate for ${a} to ${s}: live data is switched off for this engine (network.enabled is false)`)}function m(r){if(r.length===0)throw chunk6SYU4MH7_cjs.c.internal({code:"STACK_UNDERFLOW",message:"Stack underflow: an opcode expected a value on the stack but it was empty",expected:"at least one value on the VM stack",found:"an empty stack",suggestion:"this indicates corrupted bytecode or a bug in a package's parselet (mismatched push/pop counts), not a user-input error"});return r.pop()}var at="bytecode is caller input on this entry point: rebuild the program with the engine's compiler, or fix the hand-assembled stream";function ft(r){return typeof r=="number"?chunkABVDKMNF_cjs.b(r):r}function se(r,a,s,u,c,b={}){let h=ft(a);return chunk6SYU4MH7_cjs.c.validation({code:r,message:`Malformed bytecode: ${h} ${s}`,expected:u,found:c,suggestion:at,context:typeof a=="number"?{opcode:a,opcodeName:h,...b}:{site:h,...b}})}function R(r,a,s,u){if(a>=r.length)throw se("MALFORMED_BYTECODE_TRUNCATED",s,`is missing its ${u}: the program ends mid-instruction`,`an operand byte at offset ${a}`,`a program only ${r.length} byte(s) long`,{offset:a,length:r.length,role:u});return r[a]}function an(r,a,s,u,c,b){let h=R(r,a,s,u);if(h>=c)throw se("MALFORMED_BYTECODE_CONSTANT_INDEX",s,`reads ${b} entry ${h}, which does not exist`,`an index below ${c}`,`${h}`,{index:h,poolSize:c,pool:b});return h}function Q(r,a,s,u,c){return Ae(s,R(r,a,u,c),u)}function Ae(r,a,s){let u=r[a];if(typeof u!="string")throw se("MALFORMED_BYTECODE_CONSTANT_INDEX",s,`reads string-pool entry ${a}, which is ${a>=r.length?"past the end of the pool":"not a string"}`,`an index below ${r.length}, holding a string`,a>=r.length?`${a}`:typeof u,{index:a,poolSize:r.length,pool:"string-pool"});return u}function j(r,a,s){if(typeof r.value!="string")throw se("MALFORMED_BYTECODE_OPERAND_TYPE",a,`expected a ${s??"string"} on the stack`,s?`a string value holding the ${s}`:"a string value",`a ${chunkS3SPDK6N_cjs.g[r.type]??"unknown"} value`,s?{role:s,valueType:r.type}:{valueType:r.type});return r.value}function qn(r,a,s){if(r!==0&&r!==1&&r!==2)throw se("MALFORMED_BYTECODE_BODY_KIND",s,`has body kind ${r}, which is not one this VM knows`,"0 (inline body), 1 (builtin function) or 2 (user-defined function)",`${r}`,{kind:r,ref:a})}function pt(r,a){try{return BigInt(r)}catch{throw se("MALFORMED_BYTECODE_BIGINT_LITERAL",a,`cannot read "${r}" as a whole number`,"a string holding an integer, with no decimal point or separators",`"${r}"`,{literal:r})}}function bt(r){if(r===null||typeof r!="object")return `expected a bytecode program, got ${r===null?"null":typeof r}`;let a=r;return typeof a.opcodes?.length!="number"?"the program has no `opcodes` array":typeof a.numbers?.length!="number"?"the program has no `numbers` pool":typeof a.strings?.length!="number"?"the program has no `strings` pool":null}var rn=64,ht=new Set(["BIGINT_DIVISION_BY_ZERO","BIGINT_INEXACT_OPERAND","SYMBOLIC_DIVISION_BY_ZERO","INVALID_DECIMAL_PLACES","INVALID_ROUNDING_INCREMENT"]);function sn(r,a,s,u,c,b,h,f){let y=new Map;for(let x=0;x<r.length;x++)y.set(r[x],s[x]);let E=u.getStack(),S=E.length;u.pushCallFrame(y);let T;try{T=ln(a,u,c,b,h,f);}finally{u.popCallFrame(),E.length>S&&(E.length=S);}if(T.type==="pending")throw chunk6SYU4MH7_cjs.c.execution("MAP_REDUCE_ASYNC_UNSUPPORTED","map/reduce transform bodies calling an async operation (weather, stocks, currency, ...) aren't supported");if(T.type==="error")throw T.error;return T.value}function gt(r,a,s,u,c,b,h){let f=new Map(s.getCallFrame());f.set(r,chunkS3SPDK6N_cjs.K(chunkWFT3XUSH_cjs.q(r)));let y=s.getStack(),E=y.length;s.pushCallFrame(f);let S;try{S=ln(a,s,u,c,b,h);}finally{s.popCallFrame(),y.length>E&&(y.length=E);}if(S.type==="pending")throw chunk6SYU4MH7_cjs.c.execution("SYMBOLIC_ASYNC_UNSUPPORTED","an algebra verb's expression cannot call an async operation (weather, stocks, currency, ...)");if(S.type==="error")throw S.error;return S.value}function jn(r,a){if(r.type!==6||a.type!==6)return null;let s=r.unit,u=a.unit;if(s===void 0||u===void 0)return null;let c=s.indexOf("/"),b=u.indexOf("/");if(c<0||b<0||s.slice(0,c)!==u.slice(0,b))return null;let h=chunkEZKR44MA_cjs.a[s.slice(c+1).toLowerCase()],f=chunkEZKR44MA_cjs.a[u.slice(b+1).toLowerCase()];return h===void 0||f===void 0||h[0]!==f[0]?null:r.toNumber()*(f[1]/h[1])}function yt(r,a){if(r.type!==6||a.type!==6)return null;let s=r.unit,u=a.unit;if(s===void 0||u===void 0||s.includes("/")||u.includes("/"))return null;let c=chunkWFT3XUSH_cjs.ua[s.toUpperCase()]!==void 0,b=chunkWFT3XUSH_cjs.ua[u.toUpperCase()]!==void 0;return c===b?null:chunkS3SPDK6N_cjs.u(r.toNumber()*a.toNumber(),c?s:u)}function zn(r,a,s){if(r.type===5)return a.type===6&&a.unit!==void 0?chunkFESR6PZI_cjs.c(a,a.unit,r.toNumber(),s):a.type!==5&&a.type!==0?null:chunkS3SPDK6N_cjs.N(r.toNumber()+s*a.toNumber());if(a.type!==5)return null;let u=1+s*a.toNumber();if(r.type===0){let c=r.toNumber()*u;return r.uncertainty!==void 0?chunkS3SPDK6N_cjs.q(c,Math.abs(r.uncertainty*u)):chunkS3SPDK6N_cjs.n(c)}return r.type===6&&r.unit!==void 0?chunkFESR6PZI_cjs.c(r,r.unit,a.toNumber(),s):null}function Nt(r,a){let s=r.type===5?r:a.type===5?a:null;if(s===null)return null;let u=s===r?a:r;if(u.type!==0||u.uncertainty===void 0)return null;let c=s.toNumber();return chunkS3SPDK6N_cjs.q(u.toNumber()*c,Math.abs(u.uncertainty*c))}function xt(r,a){let s=r.type===6?r:a,u=r.type===6?a:r;return s.type!==6||s.unit===void 0||!chunkSF5QVUEI_cjs.c.isCurrency(s.unit)||u.type!==0&&u.type!==5||u.rational!==void 0?null:chunkFESR6PZI_cjs.b(s,u.toNumber(),s.unit)}function Et(r,a){if(a.type===5&&r.type===0&&r.uncertainty!==void 0){let s=a.toNumber();return s===0?null:chunkS3SPDK6N_cjs.q(r.toNumber()/s,Math.abs(r.uncertainty/s))}if(r.type===5&&a.type===0&&a.uncertainty!==void 0){let s=a.toNumber();return s===0?null:chunkS3SPDK6N_cjs.q(r.toNumber()/s,Math.abs(r.toNumber()*a.uncertainty/(s*s)))}return null}function It(r){if(r.type===6){let a=r.unit;if(a&&chunkPHWIO4P3_cjs.c(a)==="time")try{return chunkPHWIO4P3_cjs.e(r.toNumber(),a,"ms")}catch{}return 0}return r.toNumber()}var Jn=260;function rt(r,a,s){let u=Math.trunc(Math.abs(a)),b=(a>=0?1:-1)>0?s.getMaxDateOffsetYears():-s.getMinDateOffsetYears(),h=Math.floor(b*Jn);if(u>h)throw chunk6SYU4MH7_cjs.c.execution("DATE_OFFSET_LIMIT_EXCEEDED",`A date offset of ${u.toLocaleString("en-US")} workdays is about ${Math.round(u/Jn).toLocaleString("en-US")} years, past the limit of ${b} years for a workday offset`,{requestedWorkdays:u,limitYears:b,limitWorkdays:h});let f=h*7+7,y=Gn(r,a,E=>s.isHoliday(E),f,s.context.calendar);if(y===null)throw chunk6SYU4MH7_cjs.c.execution("DATE_OFFSET_LIMIT_EXCEEDED",`A working-day offset of ${u.toLocaleString("en-US")} could not be reached within the ${b}-year limit; the configured holiday calendar leaves too few working days`,{requestedWorkdays:u,limitYears:b,maxCalendarSteps:f});return y}var Zn=864e5,kt={month:1,months:1,mo:1,year:12,years:12,yr:12,y:12,a:12,decade:120,decades:120,dec:120,century:1200,centuries:1200,millennium:12e3,millennia:12e3};function it(r,a,s){let u=Math.trunc(a),c=s.addDays(r,u);return Number.isNaN(c)?r+a*Zn:c+(a-u)*Zn}function _t(r,a,s){let u=Math.trunc(a),c=s.addMonths(r,u),b=chunkPHWIO4P3_cjs.e(1,"month","ms");return Number.isNaN(c)?r+a*b:c+(a-u)*b}function Ne(r,a,s,u){if(a.type===6&&a.unit!==void 0){let c=a.unit,b=s*a.toNumber();if(chunkPHWIO4P3_cjs.a(c))return rt(r,b,u);let h=kt[c];if(h!==void 0)return _t(r,b*h,u.context.calendar);if(chunkPHWIO4P3_cjs.c(c)==="time"){let f=0;try{f=chunkPHWIO4P3_cjs.e(1,c,"day");}catch{}if(Number.isInteger(f)&&f>=1)return it(r,b*f,u.context.calendar)}}return r+s*It(a)}function Qn(r,a,s){let u=chunkS3SPDK6N_cjs.B(r.unit);if(a.type===6&&chunkS3SPDK6N_cjs.A(a.unit)){let c=chunkS3SPDK6N_cjs.B(a.unit);return c!==u?chunkS3SPDK6N_cjs.P("TIMECODE_FPS_MISMATCH",`Cannot combine timecodes at different frame rates (${u} fps vs ${c} fps)`):s===1?chunkS3SPDK6N_cjs.u(r.toNumber()+a.toNumber(),r.unit):chunkS3SPDK6N_cjs.u(r.toNumber()-a.toNumber(),"frames")}if(a.type===6&&a.unit==="frames")return chunkS3SPDK6N_cjs.u(r.toNumber()+s*a.toNumber(),r.unit);if(a.type===6&&a.unit&&chunkPHWIO4P3_cjs.c(a.unit)==="time"){let c=chunkPHWIO4P3_cjs.e(a.toNumber(),a.unit,"s");return chunkS3SPDK6N_cjs.u(r.toNumber()+s*c*u,r.unit)}return chunkS3SPDK6N_cjs.u(r.toNumber()+s*a.toNumber(),r.unit)}function xe(r){return r.type===10?r.value:r.toNumber()!==0}function Mt(r,a,s){let u=chunkFESR6PZI_cjs.N(a);if(u===null)return chunkPHWIO4P3_cjs.c(a)!==void 0||chunkSF5QVUEI_cjs.c.isCurrency(a)?chunkS3SPDK6N_cjs.P(chunk6SYU4MH7_cjs.s.DATETIME_NOT_CONVERTIBLE,`A date cannot be read in "${a}". "in <name>" after a date names a time zone, as in "2026-04-03 in Tokyo"`):chunkS3SPDK6N_cjs.P(chunk6SYU4MH7_cjs.s.DATETIME_ZONE_UNKNOWN,`"${a}" is not a time zone this engine knows. Name a city ("in Tokyo"), a standard abbreviation ("in JST") or "in UTC"`);let c=r.toNumber();if(r.grain!=="date"&&r.grain!=="datetime")return chunkS3SPDK6N_cjs.M(c,"instant",u);let b=s.context.calendar,h=b.fields(c);if(r.grain==="date")return chunkS3SPDK6N_cjs.M(chunkE4HAKNBQ_cjs.j(h.year,h.month0,h.day,0,0,u,b),"instant",u);let f=chunkE4HAKNBQ_cjs.j(h.year,h.month0,h.day,h.hour,h.minute,u,b);return chunkS3SPDK6N_cjs.M(f+h.second*1e3+h.millisecond,"instant",u)}function et(r,a){let s=chunkFESR6PZI_cjs.l(r,a);return chunkS3SPDK6N_cjs.P("INCOMPATIBLE_UNITS",s??`Cannot convert ${r} to ${a}: they do not measure the same thing`)}var Ce=65536;function Dt(r,a){if(!Number.isInteger(a)||a<0)return null;if(a===0)return 1;let s=Math.abs(r.toNumber());return s<=1?1:(s<=2?1:Math.log2(s))*a}function St(r,a){let s=1n,u=r,c=a;for(;c>0n;)c%2n===1n&&(s*=u),c/=2n,c>0n&&(u*=u);return s}var on=Ce;function nt(r){let a=r<0n?-r:r;if(a===0n)return 0;let s=Number(a);return Number.isFinite(s)?Math.floor(Math.log2(s))+1:a.toString(16).length*4}function tt(r,a,s){let u=chunkFESR6PZI_cjs.n(r),c=chunkFESR6PZI_cjs.n(a);if(u===0n)return chunkS3SPDK6N_cjs.s(0n);let b=s*Number(c);if(b<=0||nt(u)+b<=on)return chunkS3SPDK6N_cjs.s(s===1?u<<c:u>>c);throw chunk6SYU4MH7_cjs.c.execution("BIGINT_SHIFT_LIMIT_EXCEEDED",`Shifting by ${c} would build an exact integer of about ${(nt(u)+b).toLocaleString("en-US")} bits, past the limit of ${on.toLocaleString("en-US")} bits`,{shift:String(c),limitBits:on})}function un(r,a){let{numerator:s,denominator:u}=chunkS3SPDK6N_cjs.y(r.unit),c=chunkPHWIO4P3_cjs.c(u),b=chunkPHWIO4P3_cjs.c(a.unit);if(!c||c!==b)return chunkS3SPDK6N_cjs.P("RATE_MUL_MEASURE_MISMATCH",`Cannot multiply a "${u}"-denominated rate by "${a.unit}" \u2014 different measures`);let h=chunkPHWIO4P3_cjs.e(a.toNumber(),a.unit,u),f=r.toNumber()*h;return s?chunkS3SPDK6N_cjs.u(f,s):chunkS3SPDK6N_cjs.n(f)}function Tt(r){if(Number.isNaN(r))return "NaN";if(!isFinite(r))return r>0?"Infinity":"-Infinity";let a=r<0,s=Math.abs(r),u=Math.floor(s),c=s-u;if(c<1e-9)return `${a?"-":""}${u}`;let b=0,h=1,f=1,y=0,E=c,S=1e6;for(let x=0;x<30;x++){let Y=Math.floor(E+1e-9),z=Y*h+b,W=Y*y+f;if(W>S||(b=h,h=z,f=y,y=W,Math.abs(c-h/y)<1e-9))break;let t=E-Y;if(t<1e-9)break;E=1/t;}let T=u*y+h;return `${a?"-":""}${T}/${y}`}function At(r){return r.d===1n?String(r.n):`${r.n}/${r.d}`}function Ct(r){let a=r.toNumber(),s=r.type===5?1+a:a;return `${Math.round(s*1e6)/1e6}x`}function Ot(r){if(!Number.isFinite(r))return String(r);if(r===0)return "0e+0";let[a,s]=r.toExponential().split("e");return `${a.includes(".")?a.replace(/0+$/,"").replace(/\.$/,""):a}e${s}`}function ln(r,a,s,u,c,b){let h=bt(r);if(h)return {type:"error",error:chunk6SYU4MH7_cjs.c.validation({code:"MALFORMED_BYTECODE_PROGRAM",message:`Malformed bytecode: ${h}`,expected:"a BytecodeProgram with opcodes, numbers and strings",found:h,suggestion:at})};let{opcodes:f,numbers:y,strings:E,userFunctionBodies:S,anonymousBodies:T}=r,x=0,Y=0,z=a.getMaxInstructions(),W=a.getMaxStackDepth(),t=a.getStack(),J=t.length,oe=s?.hasCollectors??false,H=chunkS3SPDK6N_cjs.j();if(f.length===0)return {type:"value",value:chunkS3SPDK6N_cjs.n(0)};chunkS3SPDK6N_cjs.a(a);try{for(;x<f.length;){if(++Y>z)throw chunk6SYU4MH7_cjs.c.execution("INSTRUCTION_LIMIT_EXCEEDED",`Execution exceeded maximum of ${z} instructions`);if(t.length>W)throw chunk6SYU4MH7_cjs.c.execution("STACK_LIMIT_EXCEEDED",`Execution exceeded maximum stack depth of ${W}`);let g=f[x++];if(oe){let e=t.map(n=>({type:n.type,value:n.value,unit:n.unit}));s.fireVmStep({type:chunkHG4NPDN5_cjs.c.VmStep,elapsedNs:0,expression:u??"",opcode:g,opcodeName:chunkABVDKMNF_cjs.b(g),ip:x-1,stackDepth:t.length,instructionNumber:Y,stack:e});}switch(g){case 0:break;case 1:{let e=m(t);return {type:"value",value:H?chunkS3SPDK6N_cjs.k(e):e}}case 3:{let e=m(t);t.push(e),t.push(e);break}case 2:{let e=m(t),n=m(t);t.push(e),t.push(n);break}case 10:t.push(chunkS3SPDK6N_cjs.n(y[an(f,x++,g,"constant-pool index",y.length,"number-pool")]));break;case 11:t.push(chunkS3SPDK6N_cjs.s(pt(Q(f,x++,E,g,"constant-pool index"),g)));break;case 16:{let e=chunkWFT3XUSH_cjs.ia(Q(f,x++,E,g,"constant-pool index"));t.push(chunkS3SPDK6N_cjs.o(chunkWFT3XUSH_cjs.ra(e),e));break}case 12:t.push(chunkS3SPDK6N_cjs.r(y[an(f,x++,g,"constant-pool index",y.length,"number-pool")]));break;case 13:t.push(chunkS3SPDK6N_cjs.t(Q(f,x++,E,g,"constant-pool index")));break;case 14:t.push(chunkS3SPDK6N_cjs.L(R(f,x++,g,"boolean operand")===1));break;case 20:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0&&n.uncertainty===void 0&&e.uncertainty===void 0){t.push(chunkS3SPDK6N_cjs.n(n.value+e.value));break}let o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.uncertainty!==void 0||e.uncertainty!==void 0){let d=chunkFESR6PZI_cjs.s(n,e,"add");if(d){t.push(d);break}}if(n.rational!==void 0||e.rational!==void 0){let d=chunkFESR6PZI_cjs.r(n,e,"add");if(d){t.push(d);break}}let i=zn(n,e,1),l=i===null?jn(n,e):null;i!==null?t.push(i):l!==null?t.push(chunkS3SPDK6N_cjs.u(l+e.toNumber(),e.unit)):n.type===0&&e.type===0?t.push(chunkS3SPDK6N_cjs.n(n.value+e.value)):n.type===10&&e.type===10?t.push(chunkS3SPDK6N_cjs.L(n.value&&e.value)):n.type===4?e.type===4?t.push(chunkS3SPDK6N_cjs.P("INVALID_DATETIME_OP","Cannot add two datetimes together")):t.push(chunkS3SPDK6N_cjs.M(Ne(n.toNumber(),e,1,a),n.grain,n.zone)):n.type===6&&chunkS3SPDK6N_cjs.A(n.unit)?t.push(Qn(n,e,1)):e.type===4?t.push(chunkS3SPDK6N_cjs.M(Ne(e.toNumber(),n,1,a),e.grain,e.zone)):n.type===3&&e.type===3?t.push(chunkS3SPDK6N_cjs.t(n.value+e.value)):t.push(chunkFESR6PZI_cjs.u(n,e,(d,p)=>d+p,(d,p)=>d+p,"add"));break}case 21:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0&&n.uncertainty===void 0&&e.uncertainty===void 0){t.push(chunkS3SPDK6N_cjs.n(n.value-e.value));break}let o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.uncertainty!==void 0||e.uncertainty!==void 0){let d=chunkFESR6PZI_cjs.s(n,e,"sub");if(d){t.push(d);break}}if(n.rational!==void 0||e.rational!==void 0){let d=chunkFESR6PZI_cjs.r(n,e,"sub");if(d){t.push(d);break}}let i=zn(n,e,-1),l=i===null?jn(n,e):null;i!==null?t.push(i):l!==null?t.push(chunkS3SPDK6N_cjs.u(l-e.toNumber(),e.unit)):n.type===0&&e.type===0?t.push(chunkS3SPDK6N_cjs.n(n.value-e.value)):n.type===4?e.type===4?t.push(chunkS3SPDK6N_cjs.u(n.toNumber()-e.toNumber(),"ms")):t.push(chunkS3SPDK6N_cjs.M(Ne(n.toNumber(),e,-1,a),n.grain,n.zone)):n.type===6&&chunkS3SPDK6N_cjs.A(n.unit)?t.push(Qn(n,e,-1)):e.type===4?t.push(chunkS3SPDK6N_cjs.P("INVALID_DATETIME_OP","Cannot subtract a datetime from a value that is not a datetime")):t.push(chunkFESR6PZI_cjs.u(n,e,(d,p)=>d-p,(d,p)=>d-p,"sub"));break}case 22:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0&&n.uncertainty===void 0&&e.uncertainty===void 0){t.push(chunkS3SPDK6N_cjs.n(n.value*e.value));break}let o=Nt(n,e);if(o){t.push(o);break}if(n.uncertainty!==void 0||e.uncertainty!==void 0){let l=chunkFESR6PZI_cjs.s(n,e,"mul");if(l){t.push(l);break}}if(n.rational!==void 0||e.rational!==void 0){let l=chunkFESR6PZI_cjs.r(n,e,"mul");if(l){t.push(l);break}}let i=xt(n,e);if(i){t.push(i);break}if(n.type===0&&e.type===0)t.push(chunkS3SPDK6N_cjs.n(n.value*e.value));else if(n.type===7&&e.type===7)chunkS3SPDK6N_cjs.d(mt(n.value,e.value),"matrix cells"),t.push(chunkWFT3XUSH_cjs._(n.value,e.value));else if(n.type===6&&chunkS3SPDK6N_cjs.x(n.unit)&&e.type===6&&e.unit)t.push(un(n,e));else if(e.type===6&&chunkS3SPDK6N_cjs.x(e.unit)&&n.type===6&&n.unit)t.push(un(e,n));else {let l=yt(n,e);if(l!==null){t.push(l);break}let d=tn(n,e,!0);d?t.push(d):t.push(chunkFESR6PZI_cjs.u(n,e,(p,M)=>p*M,(p,M)=>p*M,"mul"));}break}case 23:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0&&n.uncertainty===void 0&&e.uncertainty===void 0){let i=n.value,l=e.value;if(Number.isInteger(i)&&Number.isInteger(l)){let d=chunkFESR6PZI_cjs.r(n,e,"div");if(d){t.push(d);break}}t.push(chunkS3SPDK6N_cjs.n(i/l));break}let o=Et(n,e);if(o){t.push(o);break}if(n.uncertainty!==void 0||e.uncertainty!==void 0){let i=chunkFESR6PZI_cjs.s(n,e,"div");if(i){t.push(i);break}}if(n.type===6&&e.type===6){let{lv:i,rv:l,sameMeasure:d}=chunkFESR6PZI_cjs.j(n,e);if(d)t.push(chunkS3SPDK6N_cjs.n(i/l));else if(chunkSF5QVUEI_cjs.c.isCurrency(n.unit)&&chunkSF5QVUEI_cjs.c.isCurrency(e.unit))t.push(chunkS3SPDK6N_cjs.P("INCOMPATIBLE_UNITS",`Cannot combine incompatible units: ${n.unit} and ${e.unit}`));else {let p=tn(n,e,!1);if(p){t.push(p);break}t.push(chunkS3SPDK6N_cjs.w(i/l,n.unit,e.unit));}}else {let i=chunkFESR6PZI_cjs.r(n,e,"div");if(i){t.push(i);break}t.push(chunkFESR6PZI_cjs.u(n,e,(l,d)=>l/d,(l,d)=>{if(d===0n)throw chunkFESR6PZI_cjs.o();return l/d},"div"));}break}case 24:{let e=m(t),n=m(t);t.push(chunkFESR6PZI_cjs.u(n,e,(o,i)=>o%i,(o,i)=>{if(i===0n)throw chunkFESR6PZI_cjs.o();return o%i}));break}case 25:{let e=m(t),n=m(t);if(n.type===13){t.push(n);break}if(e.type===13){t.push(e);break}if(n.type===12){t.push(n);break}if(e.type===12){t.push(e);break}if(n.type===0&&e.type===0){t.push(chunkS3SPDK6N_cjs.n(chunkFESR6PZI_cjs.q(n.value,e.value)));break}if(n.type===7||e.type===7){if(n.type!==7||e.type!==0){t.push(chunkS3SPDK6N_cjs.P("MATRIX_POWER_UNSUPPORTED",`^: a matrix may only be the base, raised to a whole number (as in "[1,2;3,4]^2"); "${chunkS3SPDK6N_cjs.g[n.type]} ^ ${chunkS3SPDK6N_cjs.g[e.type]}" has no matrix reading.`));break}chunkS3SPDK6N_cjs.d(dt(n.value,e.value),"matrix cells"),t.push(chunkWFT3XUSH_cjs.$(n.value,e.value));break}if(n.type===9||e.type===9){t.push(chunkFESR6PZI_cjs.f(n,e));break}if(n.type===2||e.type===2){let o=Dt(n,e.toNumber());if(o!==null){if(o>Ce)throw chunk6SYU4MH7_cjs.c.execution("BIGINT_POW_LIMIT_EXCEEDED",`That power would build an exact integer of about ${Math.round(o).toLocaleString("en-US")} bits, past the limit of ${Ce.toLocaleString("en-US")} bits`,{limitBits:Ce});t.push(chunkS3SPDK6N_cjs.s(St(chunkFESR6PZI_cjs.n(n),chunkFESR6PZI_cjs.n(e))));break}}t.push(chunkS3SPDK6N_cjs.n(chunkFESR6PZI_cjs.q(n.toNumber(),e.toNumber())));break}case 26:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}e.type===2?t.push(chunkS3SPDK6N_cjs.s(-e.value)):e.type===6&&e.exact!==void 0?t.push(chunkS3SPDK6N_cjs.v(-e.toNumber(),e.unit,chunkWFT3XUSH_cjs.ma(e.exact))):e.type===6?t.push(chunkS3SPDK6N_cjs.u(-e.toNumber(),e.unit)):e.type===5?t.push(chunkS3SPDK6N_cjs.N(-e.toNumber())):e.type===9?t.push(chunkFESR6PZI_cjs.g(e)):e.type===0&&e.rational!==void 0?t.push(chunkS3SPDK6N_cjs.p(-e.toNumber(),chunkWFT3XUSH_cjs.j(e.rational))):e.type===0&&e.exact!==void 0?t.push(chunkS3SPDK6N_cjs.o(-e.toNumber(),chunkWFT3XUSH_cjs.ma(e.exact))):t.push(chunkS3SPDK6N_cjs.n(-e.toNumber()));break}case 27:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}e.type===6&&e.exact!==void 0?t.push(chunkS3SPDK6N_cjs.v(e.toNumber(),e.unit,e.exact)):e.type===6?t.push(chunkS3SPDK6N_cjs.u(e.toNumber(),e.unit)):e.type===5?t.push(chunkS3SPDK6N_cjs.N(e.toNumber())):e.type===0&&e.rational!==void 0?t.push(chunkS3SPDK6N_cjs.p(e.toNumber(),e.rational)):e.type===0&&e.exact!==void 0?t.push(chunkS3SPDK6N_cjs.o(e.toNumber(),e.exact)):t.push(chunkS3SPDK6N_cjs.n(e.toNumber()));break}case 28:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}t.push(chunkS3SPDK6N_cjs.q(n.toNumber(),Math.abs(e.toNumber())));break}case 30:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}n.type===2||e.type===2?t.push(tt(n,e,1)):t.push(chunkS3SPDK6N_cjs.n(n.toNumber()<<e.toNumber()));break}case 31:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}n.type===2||e.type===2?t.push(tt(n,e,-1)):t.push(chunkS3SPDK6N_cjs.n(n.toNumber()>>e.toNumber()));break}case 32:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}t.push(chunkS3SPDK6N_cjs.n(n.toNumber()>>>e.toNumber()));break}case 33:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}n.type===2||e.type===2?t.push(chunkS3SPDK6N_cjs.s(chunkFESR6PZI_cjs.n(n)&chunkFESR6PZI_cjs.n(e))):t.push(chunkS3SPDK6N_cjs.n(n.toNumber()&e.toNumber()));break}case 34:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}n.type===2||e.type===2?t.push(chunkS3SPDK6N_cjs.s(chunkFESR6PZI_cjs.n(n)|chunkFESR6PZI_cjs.n(e))):t.push(chunkS3SPDK6N_cjs.n(n.toNumber()|e.toNumber()));break}case 35:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}n.type===2||e.type===2?t.push(chunkS3SPDK6N_cjs.s(chunkFESR6PZI_cjs.n(n)^chunkFESR6PZI_cjs.n(e))):t.push(chunkS3SPDK6N_cjs.n(n.toNumber()^e.toNumber()));break}case 36:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}e.type===2?t.push(chunkS3SPDK6N_cjs.s(~e.value)):t.push(chunkS3SPDK6N_cjs.n(~e.toNumber()));break}case 40:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0){t.push(chunkS3SPDK6N_cjs.L(n.value===e.value));break}let o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.rational!==void 0||e.rational!==void 0){let i=chunkFESR6PZI_cjs.t(n,e);if(i!==null){t.push(chunkS3SPDK6N_cjs.L(i===0));break}}if(n.type===0&&e.type===0)t.push(chunkS3SPDK6N_cjs.L(n.value===e.value));else if(n.type===2||e.type===2){let i=chunkFESR6PZI_cjs.p(n,e);t.push(chunkS3SPDK6N_cjs.L(i===null?n.toNumber()===e.toNumber():i===0));}else if(n.type===3&&e.type===3)t.push(chunkS3SPDK6N_cjs.L(n.value===e.value));else if(n.type===6&&e.type===6){let{equal:i,sameMeasure:l}=chunkFESR6PZI_cjs.k(n,e);t.push(chunkS3SPDK6N_cjs.L(l&&i));}else if(n.type===7&&e.type===7)t.push(chunkWFT3XUSH_cjs.aa(n.value,e.value,(i,l)=>i===l));else if(n.type===14||e.type===14)if(n.type===14&&e.type===14){let i=n.value,l=e.value;t.push(chunkS3SPDK6N_cjs.L(i.r===l.r&&i.g===l.g&&i.b===l.b&&i.a===l.a));}else t.push(chunkS3SPDK6N_cjs.L(!1));else t.push(chunkS3SPDK6N_cjs.L(n.toNumber()===e.toNumber()));break}case 41:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0){t.push(chunkS3SPDK6N_cjs.L(n.value!==e.value));break}let o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.rational!==void 0||e.rational!==void 0){let i=chunkFESR6PZI_cjs.t(n,e);if(i!==null){t.push(chunkS3SPDK6N_cjs.L(i!==0));break}}if(n.type===0&&e.type===0)t.push(chunkS3SPDK6N_cjs.L(n.value!==e.value));else if(n.type===2||e.type===2){let i=chunkFESR6PZI_cjs.p(n,e);t.push(chunkS3SPDK6N_cjs.L(i===null?n.toNumber()!==e.toNumber():i!==0));}else if(n.type===3&&e.type===3)t.push(chunkS3SPDK6N_cjs.L(n.value!==e.value));else if(n.type===6&&e.type===6){let{equal:i,sameMeasure:l}=chunkFESR6PZI_cjs.k(n,e);t.push(chunkS3SPDK6N_cjs.L(!l||!i));}else if(n.type===7&&e.type===7)t.push(chunkWFT3XUSH_cjs.aa(n.value,e.value,(i,l)=>i!==l));else if(n.type===14||e.type===14)if(n.type===14&&e.type===14){let i=n.value,l=e.value;t.push(chunkS3SPDK6N_cjs.L(!(i.r===l.r&&i.g===l.g&&i.b===l.b&&i.a===l.a)));}else t.push(chunkS3SPDK6N_cjs.L(!0));else t.push(chunkS3SPDK6N_cjs.L(n.toNumber()!==e.toNumber()));break}case 42:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0){t.push(chunkS3SPDK6N_cjs.L(n.value<e.value));break}let o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.rational!==void 0||e.rational!==void 0){let i=chunkFESR6PZI_cjs.t(n,e);if(i!==null){t.push(chunkS3SPDK6N_cjs.L(i<0));break}}if(n.type===0&&e.type===0)t.push(chunkS3SPDK6N_cjs.L(n.value<e.value));else if(n.type===2||e.type===2){let i=chunkFESR6PZI_cjs.p(n,e);t.push(chunkS3SPDK6N_cjs.L(i===null?n.toNumber()<e.toNumber():i<0));}else if(n.type===6&&e.type===6){let{lv:i,rv:l,equal:d,sameMeasure:p}=chunkFESR6PZI_cjs.k(n,e);t.push(p?chunkS3SPDK6N_cjs.L(!d&&i<l):chunkFESR6PZI_cjs.m(n,e));}else n.type===7&&e.type===7?t.push(chunkWFT3XUSH_cjs.aa(n.value,e.value,(i,l)=>i<l)):t.push(chunkS3SPDK6N_cjs.L(n.toNumber()<e.toNumber()));break}case 43:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0){t.push(chunkS3SPDK6N_cjs.L(n.value<=e.value));break}let o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.rational!==void 0||e.rational!==void 0){let i=chunkFESR6PZI_cjs.t(n,e);if(i!==null){t.push(chunkS3SPDK6N_cjs.L(i<=0));break}}if(n.type===0&&e.type===0)t.push(chunkS3SPDK6N_cjs.L(n.value<=e.value));else if(n.type===2||e.type===2){let i=chunkFESR6PZI_cjs.p(n,e);t.push(chunkS3SPDK6N_cjs.L(i===null?n.toNumber()<=e.toNumber():i<=0));}else if(n.type===6&&e.type===6){let{lv:i,rv:l,equal:d,sameMeasure:p}=chunkFESR6PZI_cjs.k(n,e);t.push(p?chunkS3SPDK6N_cjs.L(d||i<=l):chunkFESR6PZI_cjs.m(n,e));}else n.type===7&&e.type===7?t.push(chunkWFT3XUSH_cjs.aa(n.value,e.value,(i,l)=>i<=l)):t.push(chunkS3SPDK6N_cjs.L(n.toNumber()<=e.toNumber()));break}case 44:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0){t.push(chunkS3SPDK6N_cjs.L(n.value>e.value));break}let o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.rational!==void 0||e.rational!==void 0){let i=chunkFESR6PZI_cjs.t(n,e);if(i!==null){t.push(chunkS3SPDK6N_cjs.L(i>0));break}}if(n.type===0&&e.type===0)t.push(chunkS3SPDK6N_cjs.L(n.value>e.value));else if(n.type===2||e.type===2){let i=chunkFESR6PZI_cjs.p(n,e);t.push(chunkS3SPDK6N_cjs.L(i===null?n.toNumber()>e.toNumber():i>0));}else if(n.type===6&&e.type===6){let{lv:i,rv:l,equal:d,sameMeasure:p}=chunkFESR6PZI_cjs.k(n,e);t.push(p?chunkS3SPDK6N_cjs.L(!d&&i>l):chunkFESR6PZI_cjs.m(n,e));}else n.type===7&&e.type===7?t.push(chunkWFT3XUSH_cjs.aa(n.value,e.value,(i,l)=>i>l)):t.push(chunkS3SPDK6N_cjs.L(n.toNumber()>e.toNumber()));break}case 45:{let e=m(t),n=m(t);if(n.type===0&&e.type===0&&n.rational===void 0&&e.rational===void 0){t.push(chunkS3SPDK6N_cjs.L(n.value>=e.value));break}let o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.rational!==void 0||e.rational!==void 0){let i=chunkFESR6PZI_cjs.t(n,e);if(i!==null){t.push(chunkS3SPDK6N_cjs.L(i>=0));break}}if(n.type===0&&e.type===0)t.push(chunkS3SPDK6N_cjs.L(n.value>=e.value));else if(n.type===2||e.type===2){let i=chunkFESR6PZI_cjs.p(n,e);t.push(chunkS3SPDK6N_cjs.L(i===null?n.toNumber()>=e.toNumber():i>=0));}else if(n.type===6&&e.type===6){let{lv:i,rv:l,equal:d,sameMeasure:p}=chunkFESR6PZI_cjs.k(n,e);t.push(p?chunkS3SPDK6N_cjs.L(d||i>=l):chunkFESR6PZI_cjs.m(n,e));}else n.type===7&&e.type===7?t.push(chunkWFT3XUSH_cjs.aa(n.value,e.value,(i,l)=>i>=l)):t.push(chunkS3SPDK6N_cjs.L(n.toNumber()>=e.toNumber()));break}case 130:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}t.push(chunkS3SPDK6N_cjs.L(xe(n)&&xe(e)));break}case 131:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}t.push(chunkS3SPDK6N_cjs.L(xe(n)||xe(e)));break}case 132:{let e=m(t),n=m(t),o=m(t),i=chunkS3SPDK6N_cjs.Q(o);if(i){t.push(i);break}t.push(xe(o)?n:e);break}case 50:case 161:{let e;if(g===161){let d=R(f,x++,g,"plugin-function index (low byte)"),p=R(f,x++,g,"plugin-function index (high byte)");e=d|p<<8;}else e=R(f,x++,g,"plugin-function index");let n=R(f,x++,g,"argument count"),o=[];for(let d=0;d<n;d++)o.push(m(t));o.reverse();let i=a.context.pluginFunctions[e],l=chunkS3SPDK6N_cjs.R(o);if(l)t.push(l);else if(!i)t.push(chunkS3SPDK6N_cjs.P("UNKNOWN_PLUGIN_FUNCTION",`Plugin function index ${e} is not registered with this engine`));else {let d=i(o,c);if(d instanceof Promise){if(!a.context.networkEnabled){d.catch(()=>{}),t.push(chunkS3SPDK6N_cjs.P("NETWORK_DISABLED","Live data is switched off for this engine (network.enabled is false), so the result of this call was not awaited"));break}let p=`plugin:${e}:${o.map(V=>`${V.type}:${String(V.value??"")}${V.unit?`:${V.unit}`:""}`).join("|")}`,M=a.activeSignal,C=a.context.pluginFunctionOwners[e]??"";return {type:"pending",queryKey:p,resolver:d,packageId:C,signal:M}}t.push(d);}break}case 51:{let e=R(f,x++,g,"builtin-function index"),n=R(f,x++,g,"argument count"),o=Kn(e,n);if(o)throw o;let i=[],l=!1;for(let M=0;M<n;M++){let C=m(t);C.type===9&&(l=!0),i.push(C);}let d=chunkS3SPDK6N_cjs.R(i);if(d){t.push(d);break}let p=chunkFESR6PZI_cjs.C[e];if(p){let M=i.reverse(),C=l&&!chunkFESR6PZI_cjs.e.has(e);t.push(C?chunkFESR6PZI_cjs.h(e,M):p(M));}else t.push(chunkS3SPDK6N_cjs.P("UNKNOWN_BUILTIN_FUNCTION",`Builtin function index ${e} is not registered`));break}case 150:{let e=R(f,x++,g,"function-body index"),n=S?.[e];if(!n)throw chunk6SYU4MH7_cjs.c.internal("INTERNAL_MISSING_FUNCTION_BODY",`Internal error: DEFINE_USER_FUNCTION referenced missing body index ${e}`,{bodyIdx:e});a.defineUserFunction(n.name,n.params,n.program);break}case 151:{let e=Q(f,x++,E,g,"function-name index"),n=R(f,x++,g,"argument count"),o=[];for(let p=0;p<n;p++)o.push(m(t));o.reverse();let i=a.getUserFunction(e);if(!i)throw chunk6SYU4MH7_cjs.c.execution("UNDEFINED_FUNCTION",`Undefined function: ${e}`,{name:e});if(n!==i.params.length)throw chunk6SYU4MH7_cjs.c.execution("FUNCTION_ARITY_MISMATCH",`${e} expects ${i.params.length} argument(s) but got ${n}`,{name:e,expected:i.params.length,actual:n});let l=new Map;for(let p=0;p<i.params.length;p++)l.set(i.params[p],o[p]);chunkS3SPDK6N_cjs.f(),a.pushCallFrame(l);let d;try{d=ln(i.program,a,s,u,c);}finally{a.popCallFrame();}if(d.type==="pending")throw chunk6SYU4MH7_cjs.c.execution("USER_FUNCTION_ASYNC_UNSUPPORTED",`${e}: user-defined functions with async bodies (weather, stocks, currency, ...) aren't supported`,{name:e});if(d.type==="error")throw d.error;t.push(d.value);break}case 60:{let e=Q(f,x++,E,g,"variable-name index"),n=a.getVar(e);if(n!==void 0)t.push(n);else if(b)t.push(chunkS3SPDK6N_cjs.K(chunkWFT3XUSH_cjs.q(e)));else throw chunk6SYU4MH7_cjs.c.execution("UNDEFINED_VARIABLE",`Undefined variable: ${e}`,{varName:e});break}case 61:{let e=m(t),n=Q(f,x++,E,g,"variable-name index");a.setVar(n,H?chunkS3SPDK6N_cjs.k(e):e),t.push(e);break}case 62:{let e=Q(f,x++,E,g,"variable-name index"),n=chunkFESR6PZI_cjs.J.get(e);if(n===void 0)throw chunk6SYU4MH7_cjs.c.internal({code:"GLOBAL_VARIABLE_NOT_RESOLVED",message:`Global variable "${e}" was read before it resolved`,expected:`global variable "${e}" to already be resolved (async preflight should guarantee this)`,found:"no value in the global variable store",context:{varName:e}});t.push(n);break}case 63:{let e=m(t),n=Q(f,x++,E,g,"variable-name index");chunkFESR6PZI_cjs.J.set(n,H?chunkS3SPDK6N_cjs.k(e):e),t.push(e);break}case 70:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}t.push(chunkS3SPDK6N_cjs.n(e.toNumber()));break}case 71:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}if(e.type===14){let o=e.value;t.push(chunkS3SPDK6N_cjs.G({r:o.r,g:o.g,b:o.b,a:o.a,format:"hex"}));break}t.push(chunkS3SPDK6N_cjs.r(e.type===2?e.value:e.toNumber()));break}case 74:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}t.push(chunkS3SPDK6N_cjs.N(e.toNumber()));break}case 140:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}t.push(chunkS3SPDK6N_cjs.t(e.rational!==void 0?At(e.rational):Tt(e.toNumber())));break}case 141:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}t.push(chunkS3SPDK6N_cjs.t(Ct(e)));break}case 142:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}t.push(chunkS3SPDK6N_cjs.t(Ot(e.toNumber())));break}case 143:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}t.push(chunkS3SPDK6N_cjs.r(e.type===2?e.value:e.toNumber(),"bin"));break}case 144:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}t.push(chunkS3SPDK6N_cjs.r(e.type===2?e.value:e.toNumber(),"oct"));break}case 145:{let e=j(m(t),g,"converter name").toLowerCase(),n=m(t),o=chunkS3SPDK6N_cjs.Q(n);if(o){t.push(o);break}let i=chunkFESR6PZI_cjs.G.get(e);i?t.push(i(n,c)):t.push(chunkS3SPDK6N_cjs.P("UNKNOWN_AS_CONVERTER",`Unknown converter "as ${e}"`));break}case 80:{let e=j(m(t),g,"unit name"),n=m(t),o=chunkS3SPDK6N_cjs.Q(n);if(o){t.push(o);break}let i=chunkFESR6PZI_cjs.a(n,e);i?t.push(chunkS3SPDK6N_cjs.v(n.toNumber(),e,i)):t.push(chunkS3SPDK6N_cjs.u(n.toNumber(),e));break}case 81:{let e=j(m(t),g,"target unit name"),n=j(m(t),g,"source unit name"),o=m(t),i=chunkS3SPDK6N_cjs.Q(o);if(i){t.push(i);break}let l=o.toNumber(),d=chunkPHWIO4P3_cjs.c(n);if(d&&chunkPHWIO4P3_cjs.c(e)===d)t.push(chunkS3SPDK6N_cjs.u(chunkPHWIO4P3_cjs.e(l,n,e),e));else if(chunkSF5QVUEI_cjs.c.isCurrency(n)&&chunkSF5QVUEI_cjs.c.isCurrency(e)){let p=chunkSF5QVUEI_cjs.c.convertSync(l,n,e);p!==null?t.push(chunkS3SPDK6N_cjs.u(p,e)):t.push(Hn(a,n,e));}else {let p=chunkPHWIO4P3_cjs.k(l,n,e);p!==null?t.push(chunkS3SPDK6N_cjs.u(p,e)):t.push(et(n,e));}break}case 85:{let e=j(m(t),g,"unit name"),n=chunkPHWIO4P3_cjs.f(e);t.push(chunkS3SPDK6N_cjs.t(n.length>0?n.join(", "):`No known units for "${e}"`));break}case 83:{let e=j(m(t),g,"unit name"),n=m(t),o=chunkS3SPDK6N_cjs.Q(n);if(o){t.push(o);break}let{value:i,unit:l}=chunkPHWIO4P3_cjs.h(n.toNumber(),e);t.push(chunkS3SPDK6N_cjs.u(i,l));break}case 84:{let e=j(m(t),g,"target unit name"),n=m(t),o=chunkS3SPDK6N_cjs.Q(n);if(o){t.push(o);break}if(n.type===6){let i=n.unit,l=n.toNumber(),d=chunkPHWIO4P3_cjs.c(i);if(d&&chunkPHWIO4P3_cjs.c(e)===d)t.push(chunkS3SPDK6N_cjs.u(chunkPHWIO4P3_cjs.e(l,i,e),e));else if(chunkSF5QVUEI_cjs.c.isCurrency(i)&&chunkSF5QVUEI_cjs.c.isCurrency(e)){let p=chunkSF5QVUEI_cjs.c.convertSync(l,i,e);p!==null?t.push(chunkS3SPDK6N_cjs.u(p,e)):t.push(Hn(a,i,e));}else {let p=chunkPHWIO4P3_cjs.k(l,i,e);p!==null?t.push(chunkS3SPDK6N_cjs.u(p,e)):t.push(et(i,e));}}else n.type===4?t.push(Mt(n,e,a)):t.push(chunkS3SPDK6N_cjs.u(n.toNumber(),e));break}case 82:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}t.push(chunkS3SPDK6N_cjs.n(e.toNumber()));break}case 110:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(e.type!==6||!e.unit){t.push(chunkS3SPDK6N_cjs.P("RATE_MISSING_DENOMINATOR_UNIT",'Cannot build a rate: the right-hand side of "/" has no unit'));break}let i=n.type===6?n.unit??"":"";t.push(chunkS3SPDK6N_cjs.w(n.toNumber()/e.toNumber(),i,e.unit));break}case 111:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.type!==6||!chunkS3SPDK6N_cjs.x(n.unit)){t.push(chunkS3SPDK6N_cjs.P("RATE_MUL_LEFT_NOT_A_RATE",'Left-hand side of a rate multiplication must be a rate (e.g. "$50/week")'));break}if(e.type!==6||!e.unit){t.push(chunkS3SPDK6N_cjs.P("RATE_MUL_RIGHT_MISSING_UNIT","Right-hand side of a rate multiplication must have a unit matching the rate's denominator"));break}t.push(un(n,e));break}case 112:{let e=j(m(t),g,"denominator unit name"),n=m(t),o=chunkS3SPDK6N_cjs.Q(n);if(o){t.push(o);break}if(n.type!==6||!chunkS3SPDK6N_cjs.x(n.unit)){t.push(chunkS3SPDK6N_cjs.P("RATE_CONVERT_NOT_A_RATE","Cannot convert a non-rate value's denominator"));break}let{numerator:i,denominator:l}=chunkS3SPDK6N_cjs.y(n.unit),d=chunkPHWIO4P3_cjs.c(l),p=chunkPHWIO4P3_cjs.c(e);if(!d||d!==p){t.push(chunkS3SPDK6N_cjs.P("RATE_CONVERT_MEASURE_MISMATCH",`Cannot convert a "${l}"-denominated rate to "${e}" \u2014 different measures`));break}let M=chunkPHWIO4P3_cjs.e(1,e,l);t.push(chunkS3SPDK6N_cjs.w(n.toNumber()*M,i,e));break}case 120:{let e=m(t),n=chunkS3SPDK6N_cjs.Q(e);if(n){t.push(n);break}let o=e.toNumber(),i=a.context.calendar,l=i.fields(i.now());t.push(chunkS3SPDK6N_cjs.M(i.localWallClock(l.year,l.month0,l.day,o),"datetime"));break}case 90:t.push(chunkS3SPDK6N_cjs.M(a.context.calendar.now(),"instant"));break;case 95:t.push(chunkS3SPDK6N_cjs.M(y[an(f,x++,g,"constant-pool index",y.length,"number-pool")],"date"));break;case 91:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}t.push(chunkS3SPDK6N_cjs.M(Ne(n.toNumber(),e,1,a),n.grain,n.zone));break}case 92:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}t.push(chunkS3SPDK6N_cjs.M(Ne(n.toNumber(),e,-1,a),n.grain,n.zone));break}case 96:{let e=R(f,x++,g,"workday offset direction")===1?-1:1,n=m(t),o=m(t),i=chunkS3SPDK6N_cjs.Q(o,n);if(i){t.push(i);break}if(n.type!==4){t.push(chunkS3SPDK6N_cjs.P(chunk6SYU4MH7_cjs.r.WORKDAY_OFFSET_EXPECTED_DATE,`"working days after/before/from" expects a date to count from, got ${chunkS3SPDK6N_cjs.g[n.type]??"an unsupported value"}`));break}t.push(chunkS3SPDK6N_cjs.M(rt(n.toNumber(),e*o.toNumber(),a)));break}case 97:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.type!==4||e.type!==4){t.push(chunkS3SPDK6N_cjs.P(chunk6SYU4MH7_cjs.r.WORKDAYS_BETWEEN_EXPECTED_DATES,`"working days between" expects two dates, got ${chunkS3SPDK6N_cjs.g[n.type]??"an unsupported value"} and ${chunkS3SPDK6N_cjs.g[e.type]??"an unsupported value"}`));break}let i=Math.ceil((a.getMaxDateOffsetYears()-a.getMinDateOffsetYears())*366),l=Xn(n.toNumber(),e.toNumber(),d=>a.isHoliday(d),i,a.context.calendar);if(l===null){t.push(chunkS3SPDK6N_cjs.P(chunk6SYU4MH7_cjs.r.WORKDAYS_BETWEEN_RANGE_TOO_LARGE,`The two dates are more than ${a.getMaxDateOffsetYears()-a.getMinDateOffsetYears()} years apart, past the working-day count's limit`));break}t.push(chunkS3SPDK6N_cjs.n(l));break}case 93:case 94:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}let i=e.toNumber(),l=n.toNumber(),d=a.context.calendar.fields(l).weekday,p=g===93?(i-d+7)%7:(d-i+7)%7;p===0&&(p=7),t.push(chunkS3SPDK6N_cjs.M(it(l,g===93?p:-p,a.context.calendar)));break}case 152:{let e=R(f,x++,g,"row count"),n=R(f,x++,g,"column count"),o=e*n,i=chunkS3SPDK6N_cjs.e(o,"matrix cells"),l=null;for(let d=o-1;d>=0;d--){let p=m(t);l===null&&(l=chunkS3SPDK6N_cjs.Q(p)),i[d]=p.type===10||p.type===9?p.value:p.toNumber();}if(l){t.push(l);break}t.push(chunkS3SPDK6N_cjs.C(e,n,chunkWFT3XUSH_cjs.Y(e,n,i)));break}case 153:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.type!==7){t.push(chunkS3SPDK6N_cjs.P("MATRIX_INDEX_NOT_A_MATRIX",'Cannot index a non-matrix value with "[...]".'));break}let i=n.value,l=Math.trunc(e.toNumber());if(l<0||l>=i.data.length){t.push(chunkS3SPDK6N_cjs.P("MATRIX_INDEX_OUT_OF_BOUNDS",`Index ${l} is out of bounds for a ${i.rows}x${i.cols} matrix (valid range: 0-${i.data.length-1}).`));break}let d=chunkWFT3XUSH_cjs.S(i,l);t.push(chunkWFT3XUSH_cjs.X(d));break}case 154:{let e=m(t),n=m(t),o=m(t),i=chunkS3SPDK6N_cjs.Q(o,n,e);if(i){t.push(i);break}if(o.type!==7){t.push(chunkS3SPDK6N_cjs.P("MATRIX_INDEX_NOT_A_MATRIX",'Cannot index a non-matrix value with "[...]".'));break}let l=o.value,d=Math.trunc(n.toNumber()),p=Math.trunc(e.toNumber());if(!chunkWFT3XUSH_cjs.U(l,d,p)){t.push(chunkS3SPDK6N_cjs.P("MATRIX_INDEX_OUT_OF_BOUNDS",`[${d}, ${p}] is out of bounds for a ${l.rows}x${l.cols} matrix.`));break}let M=chunkWFT3XUSH_cjs.T(l,d,p);t.push(chunkWFT3XUSH_cjs.X(M));break}case 156:{let e=m(t),n=m(t),o=chunkS3SPDK6N_cjs.Q(n,e);if(o){t.push(o);break}if(n.type!==0||e.type!==0){t.push(chunkS3SPDK6N_cjs.P("INVALID_RANGE_BOUND",`A range's bounds must be plain numbers (e.g. "0:3").`));break}let i=n.value,l=e.value;if(!Number.isInteger(i)||!Number.isInteger(l)){t.push(chunkS3SPDK6N_cjs.P("NON_INTEGER_RANGE_BOUND",`A range's bounds must be whole numbers, got "${i}:${l}".`));break}if(i>l){t.push(chunkS3SPDK6N_cjs.P("DESCENDING_RANGE",`A range's min (${i}) cannot be greater than its max (${l}) \u2014 did you mean "${l}:${i}"?`));break}t.push(chunkS3SPDK6N_cjs.F(i,l));break}case 155:{let e=m(t),n=m(t),o=m(t),i=chunkS3SPDK6N_cjs.Q(o,n,e);if(i){t.push(i);break}if(o.type!==7){t.push(chunkS3SPDK6N_cjs.P("MATRIX_INDEX_NOT_A_MATRIX",'Cannot slice a non-matrix value with "[...]".'));break}if(n.type!==8||e.type!==8){t.push(chunkS3SPDK6N_cjs.P("INVALID_MATRIX_SLICE_BOUND",'Matrix slicing needs range bounds (e.g. "a[0:1, 1:2]").'));break}let l=o.value,d=n.value,p=e.value;if(d.min<0||d.max>=l.rows||p.min<0||p.max>=l.cols){t.push(chunkS3SPDK6N_cjs.P("MATRIX_INDEX_OUT_OF_BOUNDS",`Slice [${d.min}:${d.max}, ${p.min}:${p.max}] is out of bounds for a ${l.rows}x${l.cols} matrix.`));break}let M=d.max-d.min+1,C=p.max-p.min+1,V=chunkS3SPDK6N_cjs.e(M*C,"matrix cells");for(let L=0;L<M;L++)for(let v=0;v<C;v++)V[L+v*M]=chunkWFT3XUSH_cjs.T(l,d.min+L,p.min+v);t.push(chunkS3SPDK6N_cjs.C(M,C,V));break}case 157:{let e=R(f,x++,g,"body kind"),n=R(f,x++,g,"body reference"),o=R(f,x++,g,"collection count");qn(e,n,g);let i=new Array(o);for(let D=o-1;D>=0;D--)i[D]=m(t);let l=[],d;if(e===0){let D=T?.[n];if(!D)throw chunk6SYU4MH7_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: MAP_INVOKE referenced missing anonymous body index ${n}`,{ref:n});l=D.params,d=D.program;}else if(e===2){let D=Ae(E,n,g),U=a.getUserFunction(D);if(!U){t.push(chunkS3SPDK6N_cjs.P("UNDEFINED_FUNCTION",`map: undefined function "${D}"`));break}if(U.params.length!==o){t.push(chunkS3SPDK6N_cjs.P("FUNCTION_ARITY_MISMATCH",`map: "${D}" expects ${U.params.length} argument(s) but ${o} collection(s) were given`));break}l=U.params,d=U.program;}let p=-1,M=new Array(o),C;for(let D=0;D<o;D++){let U=chunkWFT3XUSH_cjs.ea(i[D],a.getMaxCollectionSize());if(!Array.isArray(U)){C=U;break}if(chunkS3SPDK6N_cjs.c(U.length,"collection elements"),p===-1)p=U.length;else if(U.length!==p){C=chunkS3SPDK6N_cjs.P("MAP_COLLECTION_LENGTH_MISMATCH",`map: all collections must have the same length (got ${p} and ${U.length}).`);break}M[D]=U;}if(C){t.push(C);break}let V=chunkS3SPDK6N_cjs.e(p,"matrix cells"),L;for(let D=0;D<p;D++){let U=new Array(o);for(let ee=0;ee<o;ee++)U[ee]=M[ee][D];let P=e===1?chunkFESR6PZI_cjs.C[n]?.(U)??chunkS3SPDK6N_cjs.P("UNKNOWN_BUILTIN_FUNCTION",`map: unknown builtin function index ${n}`):sn(l,d,U,a,s,u,c,!!b),me=chunkS3SPDK6N_cjs.Q(P);if(me){L=me;break}V[D]=P.type===10||P.type===9?P.value:P.toNumber();}if(L){t.push(L);break}let v=i[0],B=v?.type===7?v.value:void 0;B&&B.rows*B.cols===p?t.push(chunkS3SPDK6N_cjs.C(B.rows,B.cols,V)):t.push(chunkS3SPDK6N_cjs.C(1,p,V));break}case 160:{let e=R(f,x++,g,"plot body reference"),n=R(f,x++,g,"plot expression"),o=Ae(E,n,g),i=m(t).toNumber(),l=m(t).toNumber(),d=T?.[e];if(!d)throw chunk6SYU4MH7_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: PLOT_INVOKE referenced missing anonymous body index ${e}`,{ref:e});if(!Number.isFinite(l)||!Number.isFinite(i)){t.push(chunkS3SPDK6N_cjs.P("PLOT_INVALID_RANGE",`plot: the range bounds must be finite numbers (got ${l} to ${i})`));break}let p=[],M=0,C;for(let D=0;D<rn;D++){let U=l+D/(rn-1)*(i-l),P;try{P=sn(d.params,d.program,[chunkS3SPDK6N_cjs.n(U)],a,s,u,c,!!b);}catch(ee){let Oe=chunk6SYU4MH7_cjs.d(ee);if(!ht.has(Oe.code))throw ee;M++,C=chunkS3SPDK6N_cjs.P(Oe.code,Oe.message);continue}if(P.type===13||P.type===12){M++,C=P;continue}let me=P.toNumber();Number.isFinite(me)&&p.push([U,me]);}if(M===rn&&C!==void 0){t.push(chunkS3SPDK6N_cjs.P(String(C.value),`plot: ${o} has no value at any point over [${l}, ${i}]: ${String(C.unit)}`));break}let V=p.map(D=>D[1]),L=V.length?Math.min(...V):0,v=V.length?Math.max(...V):0,B=D=>Number.isInteger(D)?String(D):String(Number(D.toFixed(2)));t.push(chunkS3SPDK6N_cjs.I({kind:"plot",points:p,label:`${o} over [${B(l)}, ${B(i)}]`,domain:[l,i],range:[L,v],expr:o}));break}case 158:{let e=R(f,x++,g,"body kind"),n=R(f,x++,g,"body reference"),o=R(f,x++,g,"initial-value flag");qn(e,n,g);let i=o?m(t):void 0,l=m(t),d=[],p;if(e===0){let v=T?.[n];if(!v)throw chunk6SYU4MH7_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: REDUCE_INVOKE referenced missing anonymous body index ${n}`,{ref:n});d=v.params,p=v.program;}else if(e===2){let v=Ae(E,n,g),B=a.getUserFunction(v);if(!B){t.push(chunkS3SPDK6N_cjs.P("UNDEFINED_FUNCTION",`reduce: undefined function "${v}"`));break}if(B.params.length!==2){t.push(chunkS3SPDK6N_cjs.P("FUNCTION_ARITY_MISMATCH",`reduce: "${v}" must take exactly 2 arguments (accumulator, element), got ${B.params.length}`));break}d=B.params,p=B.program;}let M=chunkWFT3XUSH_cjs.ea(l,a.getMaxCollectionSize());if(!Array.isArray(M)){t.push(M);break}chunkS3SPDK6N_cjs.c(M.length,"collection elements");let C,V;if(i!==void 0){let v=chunkS3SPDK6N_cjs.Q(i);if(v){t.push(v);break}C=i,V=0;}else {if(M.length===0){t.push(chunkS3SPDK6N_cjs.P("REDUCE_EMPTY_COLLECTION","reduce: cannot reduce an empty collection without an initial value."));break}C=M[0],V=1;}let L;for(let v=V;v<M.length;v++){let B=[C,M[v]],D=e===1?chunkFESR6PZI_cjs.C[n]?.(B)??chunkS3SPDK6N_cjs.P("UNKNOWN_BUILTIN_FUNCTION",`reduce: unknown builtin function index ${n}`):sn(d,p,B,a,s,u,c,!!b),U=chunkS3SPDK6N_cjs.Q(D);if(U){L=U;break}C=D;}if(L){t.push(L);break}t.push(C);break}case 159:{let e=R(f,x++,g,"body reference"),n=T?.[e];if(!n)throw chunk6SYU4MH7_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: BIND_UNKNOWN referenced missing anonymous body index ${e}`,{ref:e});t.push(gt(n.params[0],n.program,a,s,u,c,!!b));break}default:throw se("MALFORMED_BYTECODE_UNKNOWN_OPCODE",g,"has no handler in this virtual machine","an opcode the dispatch switch handles (see parser/OpCode.ts)",`opcode ${g} at offset ${x-1}`,{offset:x-1})}}let _=m(t);return {type:"value",value:H?chunkS3SPDK6N_cjs.k(_):_}}catch(_){return t.length>J&&(t.length=J),{type:"error",error:chunk6SYU4MH7_cjs.d(_)}}finally{chunkS3SPDK6N_cjs.b();}}exports.a=$n;exports.b=Pn;exports.c=da;exports.d=ln;//# sourceMappingURL=chunk-LI6LYJDA.cjs.map
2
+ //# sourceMappingURL=chunk-LI6LYJDA.cjs.map