solve-engine 2.23.0 → 2.24.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.
- package/README.md +82 -32
- package/dist/{Configuration-BGQn-cJ8.d.cts → Configuration-DnzYPmoK.d.cts} +33 -0
- package/dist/{Configuration-BGQn-cJ8.d.ts → Configuration-DnzYPmoK.d.ts} +33 -0
- package/dist/{EngineError-DTk7I7hZ.d.cts → EngineError-D1kXsjIj.d.cts} +4 -0
- package/dist/{EngineError-DTk7I7hZ.d.ts → EngineError-D1kXsjIj.d.ts} +4 -0
- package/dist/{PackageCompatibility-BGXSFuL9.d.ts → PackageCompatibility-Bq82y0ZN.d.ts} +1 -1
- package/dist/{PackageCompatibility-BZCqaTOO.d.cts → PackageCompatibility-CeAPVHZr.d.cts} +1 -1
- package/dist/{PackageRegistry-rMGnTh7W.d.cts → PackageRegistry-B9-7fJGH.d.cts} +16 -11
- package/dist/{PackageRegistry-BRoVOYzg.d.ts → PackageRegistry-CDEgfhT_.d.ts} +16 -11
- package/dist/{Parselet-Bkbp9CKD.d.cts → Parselet-4oH5OuRt.d.cts} +1 -1
- package/dist/{Parselet-B-WyUtX4.d.ts → Parselet-BwDqKFfK.d.ts} +1 -1
- package/dist/{ScopeManager-gB9UengK.d.ts → ScopeManager-BQBhlDAu.d.ts} +38 -7
- package/dist/{ScopeManager-bCYewWVt.d.cts → ScopeManager-DrXB3Nvm.d.cts} +38 -7
- package/dist/{VMCheckpoints-DGar9Yg8.d.cts → VMCheckpoints-BK32PTl2.d.cts} +2 -2
- package/dist/{VMCheckpoints-BDRY1Kx8.d.ts → VMCheckpoints-C5jC92o3.d.ts} +2 -2
- package/dist/{Value-DCTqTSeP.d.cts → Value-Ds3Gy07C.d.cts} +1 -1
- package/dist/{Value-DCTqTSeP.d.ts → Value-Ds3Gy07C.d.ts} +1 -1
- package/dist/{WorkerError-DpZgKRks.d.ts → WorkerError-CVQbs6_D.d.ts} +1 -1
- package/dist/{WorkerError-DGBNM3gA.d.cts → WorkerError-DaNWQFp1.d.cts} +1 -1
- package/dist/chunk-2BXNZM3G.js +2 -0
- package/dist/chunk-2BXNZM3G.js.map +1 -0
- package/dist/chunk-2JSNWYYA.cjs +3 -0
- package/dist/chunk-2JSNWYYA.cjs.map +1 -0
- package/dist/{chunk-J7ABVGZH.cjs → chunk-2VE4OW4A.cjs} +2 -2
- package/dist/{chunk-J7ABVGZH.cjs.map → chunk-2VE4OW4A.cjs.map} +1 -1
- package/dist/{chunk-HMC7FJO7.js → chunk-3SHWTGTP.js} +2 -2
- package/dist/{chunk-HMC7FJO7.js.map → chunk-3SHWTGTP.js.map} +1 -1
- package/dist/{chunk-EN3CDYOS.cjs → chunk-5GL4SAVH.cjs} +2 -2
- package/dist/{chunk-EN3CDYOS.cjs.map → chunk-5GL4SAVH.cjs.map} +1 -1
- package/dist/{chunk-SGIDBZ4T.cjs → chunk-72N3ZRVE.cjs} +2 -2
- package/dist/chunk-72N3ZRVE.cjs.map +1 -0
- package/dist/{chunk-CHSO3DCS.js → chunk-7EP36NXE.js} +3 -3
- package/dist/{chunk-CHSO3DCS.js.map → chunk-7EP36NXE.js.map} +1 -1
- package/dist/chunk-A4JV7HRB.js +3 -0
- package/dist/chunk-A4JV7HRB.js.map +1 -0
- package/dist/chunk-AUOE7MFI.cjs +2 -0
- package/dist/chunk-AUOE7MFI.cjs.map +1 -0
- package/dist/chunk-BDF4VCQX.js +3 -0
- package/dist/chunk-BDF4VCQX.js.map +1 -0
- package/dist/{chunk-3SSMOVWB.cjs → chunk-CDNJZBM3.cjs} +2 -2
- package/dist/{chunk-3SSMOVWB.cjs.map → chunk-CDNJZBM3.cjs.map} +1 -1
- package/dist/{chunk-YAONCEAW.cjs → chunk-CMZSK6FY.cjs} +3 -3
- package/dist/{chunk-YAONCEAW.cjs.map → chunk-CMZSK6FY.cjs.map} +1 -1
- package/dist/chunk-D2Q2VFJ6.js +2 -0
- package/dist/chunk-D2Q2VFJ6.js.map +1 -0
- package/dist/{chunk-75JLWK4L.cjs → chunk-DA7M6H63.cjs} +2 -2
- package/dist/{chunk-75JLWK4L.cjs.map → chunk-DA7M6H63.cjs.map} +1 -1
- package/dist/chunk-ELQQKZN3.cjs +3 -0
- package/dist/{chunk-PIZQIQVM.js.map → chunk-ELQQKZN3.cjs.map} +1 -1
- package/dist/chunk-F7QIBC4B.cjs +3 -0
- package/dist/chunk-F7QIBC4B.cjs.map +1 -0
- package/dist/chunk-GP4H5OIT.js +3 -0
- package/dist/chunk-GP4H5OIT.js.map +1 -0
- package/dist/chunk-HQ7BKXG7.js +2 -0
- package/dist/chunk-HQ7BKXG7.js.map +1 -0
- package/dist/{chunk-KRXO3MOW.cjs → chunk-IHAZL4EF.cjs} +2 -2
- package/dist/chunk-IHAZL4EF.cjs.map +1 -0
- package/dist/{chunk-7E7NXKQ5.js → chunk-IJHL3LMH.js} +2 -2
- package/dist/chunk-IJHL3LMH.js.map +1 -0
- package/dist/{chunk-3GR46UOX.js → chunk-IPSOWFCA.js} +2 -2
- package/dist/{chunk-3GR46UOX.js.map → chunk-IPSOWFCA.js.map} +1 -1
- package/dist/chunk-LM6ZQUEU.js +2 -0
- package/dist/chunk-LM6ZQUEU.js.map +1 -0
- package/dist/{chunk-N37PUZJR.cjs → chunk-LTJV3VJE.cjs} +2 -2
- package/dist/{chunk-N37PUZJR.cjs.map → chunk-LTJV3VJE.cjs.map} +1 -1
- package/dist/chunk-MWWAKZOD.cjs +3 -0
- package/dist/chunk-MWWAKZOD.cjs.map +1 -0
- package/dist/chunk-NUF66H57.js +5 -0
- package/dist/chunk-NUF66H57.js.map +1 -0
- package/dist/{chunk-MRRMIBHE.js → chunk-OMHRBKAT.js} +2 -2
- package/dist/{chunk-MRRMIBHE.js.map → chunk-OMHRBKAT.js.map} +1 -1
- package/dist/{chunk-4ETS224G.js → chunk-PTQCHMYA.js} +2 -2
- package/dist/{chunk-4ETS224G.js.map → chunk-PTQCHMYA.js.map} +1 -1
- package/dist/{chunk-4DJJIUQF.js → chunk-PWWQZFAE.js} +2 -2
- package/dist/chunk-PWWQZFAE.js.map +1 -0
- package/dist/chunk-RE6AIU6Y.js +3 -0
- package/dist/chunk-RE6AIU6Y.js.map +1 -0
- package/dist/chunk-RECRD45C.cjs +5 -0
- package/dist/chunk-RECRD45C.cjs.map +1 -0
- package/dist/{chunk-O3BDXOQJ.js → chunk-RENO2AWO.js} +2 -2
- package/dist/{chunk-O3BDXOQJ.js.map → chunk-RENO2AWO.js.map} +1 -1
- package/dist/chunk-RMCN5WFO.cjs +2 -0
- package/dist/chunk-RMCN5WFO.cjs.map +1 -0
- package/dist/{chunk-TL545PXW.cjs → chunk-RN3ISTM3.cjs} +2 -2
- package/dist/{chunk-TL545PXW.cjs.map → chunk-RN3ISTM3.cjs.map} +1 -1
- package/dist/{chunk-JYLNQOPU.cjs → chunk-S46R5QZP.cjs} +2 -2
- package/dist/{chunk-JYLNQOPU.cjs.map → chunk-S46R5QZP.cjs.map} +1 -1
- package/dist/{chunk-USQ4KL6S.cjs → chunk-UPH22K2T.cjs} +2 -2
- package/dist/chunk-UPH22K2T.cjs.map +1 -0
- package/dist/{chunk-KEA5HRL3.js → chunk-UXR7JIPX.js} +2 -2
- package/dist/{chunk-KEA5HRL3.js.map → chunk-UXR7JIPX.js.map} +1 -1
- package/dist/chunk-UY3ID6JF.cjs +2 -0
- package/dist/chunk-UY3ID6JF.cjs.map +1 -0
- package/dist/{chunk-JVMINMAB.js → chunk-WFOQRPA6.js} +2 -2
- package/dist/{chunk-JVMINMAB.js.map → chunk-WFOQRPA6.js.map} +1 -1
- package/dist/{chunk-AF7HQN6I.js → chunk-XFJABR3B.js} +2 -2
- package/dist/chunk-XFJABR3B.js.map +1 -0
- package/dist/{chunk-LNZNJSRW.cjs → chunk-ZVPZQ66D.cjs} +2 -2
- package/dist/chunk-ZVPZQ66D.cjs.map +1 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.d.cts +9 -9
- package/dist/engine.d.ts +9 -9
- package/dist/engine.js +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.d.cts +3 -3
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +1 -1
- package/dist/format.cjs +1 -1
- package/dist/format.d.cts +1 -1
- package/dist/format.d.ts +1 -1
- package/dist/format.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -9
- package/dist/index.d.ts +11 -9
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/language.d.cts +8 -8
- package/dist/language.d.ts +8 -8
- package/dist/lexer.cjs +1 -1
- package/dist/lexer.js +1 -1
- package/dist/normalizer.cjs +1 -1
- package/dist/normalizer.d.cts +14 -8
- package/dist/normalizer.d.ts +14 -8
- package/dist/normalizer.js +1 -1
- package/dist/packages.cjs +1 -1
- package/dist/packages.d.cts +7 -7
- package/dist/packages.d.ts +7 -7
- package/dist/packages.js +1 -1
- package/dist/parser.cjs +1 -1
- package/dist/parser.d.cts +3 -3
- package/dist/parser.d.ts +3 -3
- package/dist/parser.js +1 -1
- package/dist/{pipeline-B4wf3M1h.d.cts → pipeline-69q2tsLE.d.cts} +1 -1
- package/dist/{pipeline-QIT4iD8f.d.ts → pipeline-DTqGLPsV.d.ts} +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.cts +18 -2
- package/dist/resolvers.d.ts +18 -2
- package/dist/resolvers.js +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.d.cts +8 -8
- package/dist/testing.d.ts +8 -8
- package/dist/testing.js +1 -1
- package/dist/uom.cjs +1 -1
- package/dist/uom.d.cts +1 -1
- package/dist/uom.d.ts +1 -1
- package/dist/uom.js +1 -1
- package/dist/vm.cjs +1 -1
- package/dist/vm.d.cts +7 -7
- package/dist/vm.d.ts +7 -7
- package/dist/vm.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +31 -22
- package/dist/worker.d.ts +31 -22
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-42JXN3BH.js +0 -5
- package/dist/chunk-42JXN3BH.js.map +0 -1
- package/dist/chunk-4DJJIUQF.js.map +0 -1
- package/dist/chunk-6YM67DWH.cjs +0 -3
- package/dist/chunk-6YM67DWH.cjs.map +0 -1
- package/dist/chunk-7E7NXKQ5.js.map +0 -1
- package/dist/chunk-7SZBEE5R.cjs +0 -2
- package/dist/chunk-7SZBEE5R.cjs.map +0 -1
- package/dist/chunk-A5M4QZIK.js +0 -2
- package/dist/chunk-A5M4QZIK.js.map +0 -1
- package/dist/chunk-AF7HQN6I.js.map +0 -1
- package/dist/chunk-ALY4ZMYO.js +0 -2
- package/dist/chunk-ALY4ZMYO.js.map +0 -1
- package/dist/chunk-BRJ4RT5U.js +0 -2
- package/dist/chunk-BRJ4RT5U.js.map +0 -1
- package/dist/chunk-CO2BI6WL.cjs +0 -3
- package/dist/chunk-CO2BI6WL.cjs.map +0 -1
- package/dist/chunk-EQDT42JG.js +0 -3
- package/dist/chunk-EQDT42JG.js.map +0 -1
- package/dist/chunk-FMMT5C5H.cjs +0 -3
- package/dist/chunk-FMMT5C5H.cjs.map +0 -1
- package/dist/chunk-FP6Z6PYR.js +0 -2
- package/dist/chunk-FP6Z6PYR.js.map +0 -1
- package/dist/chunk-H3JXNH7X.cjs +0 -3
- package/dist/chunk-H3JXNH7X.cjs.map +0 -1
- package/dist/chunk-HZOLIL5T.js +0 -3
- package/dist/chunk-HZOLIL5T.js.map +0 -1
- package/dist/chunk-KRXO3MOW.cjs.map +0 -1
- package/dist/chunk-KVLJDOZ7.cjs +0 -5
- package/dist/chunk-KVLJDOZ7.cjs.map +0 -1
- package/dist/chunk-LNZNJSRW.cjs.map +0 -1
- package/dist/chunk-PIZQIQVM.js +0 -3
- package/dist/chunk-QTSDIDAS.js +0 -3
- package/dist/chunk-QTSDIDAS.js.map +0 -1
- package/dist/chunk-SGIDBZ4T.cjs.map +0 -1
- package/dist/chunk-UNKSCVIL.cjs +0 -2
- package/dist/chunk-UNKSCVIL.cjs.map +0 -1
- package/dist/chunk-USQ4KL6S.cjs.map +0 -1
- package/dist/chunk-XDXIPVZB.cjs +0 -2
- package/dist/chunk-XDXIPVZB.cjs.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a,c}from'./chunk-IJMNVBIS.js';import {a as a$1}from'./chunk-LHLW7JLS.js';import {c as c$1}from'./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {a,c}from'./chunk-IJMNVBIS.js';import {a as a$1}from'./chunk-LHLW7JLS.js';import {c as c$1}from'./chunk-BDF4VCQX.js';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 l={[a.PLUS]:o.Sum,[a.MINUS]:o.Sum,[a.STAR]:o.Product,[a.SLASH]:o.Product,[a.MOD]:o.Product,[a.CARET]:o.Exponent,[a.BIT_OR]:o.BitwiseOr,[a.BIT_XOR]:o.BitwiseXor,[a.BIT_AND]:o.BitwiseAnd,[a.LSHIFT]:o.Shift,[a.RSHIFT]:o.Shift,[a.URSHIFT]:o.Shift,[a.PERCENT]:o.Postfix,[a.OF]:o.Product},h=null;function _(){if(h)return h;let s=0;for(let e of Object.keys(l)){let t=c(e);t>s&&(s=t);}for(let e of Object.values(a)){let t=c(e);t>s&&(s=t);}let n=new Uint8Array(s+1);for(let[e,t]of Object.entries(l)){let u=c(e);n[u]=t;}return h=n,n}function T(){h=null;}var r=255,B=Object.freeze([]),I=new Float64Array(0),f=class{constructor(n){this.pluginFunctionIndex=n;this.opcodes=[];this.numbers=[];this.strings=[];this.stringIndex=new Map;this._hasAsync=false;this.userFunctionBodies=[];this.anonymousBodies=[];}get pluginIndexMap(){return this.pluginFunctionIndex}emitPluginCall(n,e){let t=this.pluginFunctionIndex?.get(n);if(t===void 0)throw c$1.execution("UNKNOWN_PLUGIN_FUNCTION",`No registered plugin function named "${n}". A package must declare it in its pluginFunctions record and be registered before an expression using it is parsed.`,{functionName:n});if(t>65535)throw c$1.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(e);}emitOpcode(n){this.opcodes.push(n),(n===50||n===161)&&(this._hasAsync=true);}emitNumber(n){let e=this.numbers.length;if(e>r)throw c$1.parsing("TOO_MANY_NUMERIC_CONSTANTS",`Expression has more than ${r+1} numeric literals, exceeding the bytecode constant pool's limit.`,{limit:r+1});this.numbers.push(n),this.opcodes.push(e);}emitString(n){let e=this.stringIndex.get(n);if(e===void 0){if(e=this.strings.length,e>r)throw c$1.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(n),this.stringIndex.set(n,e);}this.opcodes.push(e);}emitIndex(n){this.opcodes.push(n);}emitByte(n){this.opcodes.push(n);}get currentLength(){return this.opcodes.length}emitUserFunctionBody(n,e,t){let u=this.userFunctionBodies.length;if(u>r)throw c$1.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:n,params:e,program:t}),u}emitAnonymousBody(n,e){let t=this.anonymousBodies.length;if(t>r)throw c$1.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:n,program:e}),t}patchJump(n,e){this.opcodes[n]=e;}build(){return {opcodes:new Uint8Array(this.opcodes),numbers:this.numbers.length>0?new Float64Array(this.numbers):I,strings:this.strings.length>0?[...this.strings]:B,hasAsync:this._hasAsync,userFunctionBodies:this.userFunctionBodies.length>0?[...this.userFunctionBodies]:void 0,anonymousBodies:this.anonymousBodies.length>0?[...this.anonymousBodies]:void 0}}buildInto(n){let e=this.opcodes.length,t=this.numbers.length,u=n&&n.opcodes.length>=e,b=n&&n.numbers.length>=t,m=u?new Uint8Array(n.opcodes.buffer,n.opcodes.byteOffset,e):new Uint8Array(e),g=b?new Float64Array(n.numbers.buffer,n.numbers.byteOffset,t):new Float64Array(t);for(let d=0;d<e;d++)m[d]=this.opcodes[d];for(let d=0;d<t;d++)g[d]=this.numbers[d];return {opcodes:m,numbers:g,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.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 A=/^\d{1,3}(\.\d{3}){2,}$/,y=/^\d+$/;function w(s,n){let e=s.endsWith("n")?s.slice(0,-1):s;if(y.test(e))return e;let t=A.test(e)?e.split(".").join(""):x(e,n);if(!y.test(t)){let u=e.includes(".")?".":e.includes(",")?",":e;throw c$1.parsing("INVALID_NUMBER_LITERAL",`"${s}" is not a whole number: "${u}" separates decimals in the ${n} locale, and a whole number cannot have a fractional part.`,{raw:s,localeCode:n,separator:u})}return t}function x(s,n){let e=a$1(n).display.thousandsSeparator;return e?s.split(e).join(""):s}export{o as a,_ as b,T as c,f as d,w as e};//# sourceMappingURL=chunk-RENO2AWO.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-RENO2AWO.js.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","EMPTY_STRINGS","EMPTY_NUMBERS","BytecodeBuilder","pluginFunctionIndex","argCount","index","ErrorFactory","op","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":"4HAWO,IAAMA,CAAAA,CAAe,CAC1B,MAAA,CAAQ,CAAA,CACR,WAAY,EAAA,CACZ,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CAaZ,WAAA,CAAa,GAab,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CACZ,UAAA,CAAY,EAAA,CACZ,YAAa,EAAA,CACb,KAAA,CAAO,EAAA,CACP,GAAA,CAAK,EAAA,CACL,OAAA,CAAS,GAMT,WAAA,CAAa,EAAA,CAIb,QAAA,CAAU,EAAA,CACV,MAAA,CAAQ,EAAA,CACR,QAAS,EAAA,CACT,IAAA,CAAM,EACR,EAiDA,IAAMC,CAAAA,CAA2C,CAE/C,CAACC,CAAAA,CAAW,IAAI,EAAOF,CAAAA,CAAa,GAAA,CACpC,CAACE,CAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,GAAA,CACpC,CAACE,EAAW,IAAI,EAAOF,CAAAA,CAAa,OAAA,CACpC,CAACE,CAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,OAAA,CACpC,CAACE,CAAAA,CAAW,GAAG,EAAQF,CAAAA,CAAa,OAAA,CAGpC,CAAC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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 */\nconst 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/**\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\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: appends `n` to the program's constant pool and\n\t * writes its index into the opcode stream (read back by the VM as e.g.\n\t * `PUSH_NUMBER <idx>`).\n\t *\n\t * Numeric constants are NOT deduplicated (unlike {@link emitString})\n\t * every call appends a new entry, so an expression with more than\n\t * {@link MAX_CONSTANT_POOL_INDEX}+1 distinct numeric-literal occurrences\n\t * throws rather than silently wrapping the index (see\n\t * `MAX_CONSTANT_POOL_INDEX`'s doc for what that would otherwise do).\n\t *\n\t * @throws If the constant pool would exceed 256 entries.\n\t */\n\temitNumber(n: number): void {\n\t\tconst idx = this.numbers.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_NUMERIC_CONSTANTS\",\n\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} numeric literals, 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.numbers.push(n);\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(idx);\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(b);\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\tthis.opcodes[position] = 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\tthis.numbers.length = 0;\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","EMPTY_STRINGS","EMPTY_NUMBERS","BytecodeBuilder","pluginFunctionIndex","argCount","index","ErrorFactory","op","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":"4HAWO,IAAMA,CAAAA,CAAe,CAC1B,MAAA,CAAQ,CAAA,CACR,WAAY,EAAA,CACZ,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CAaZ,WAAA,CAAa,GAab,SAAA,CAAW,EAAA,CACX,UAAA,CAAY,EAAA,CACZ,UAAA,CAAY,EAAA,CACZ,YAAa,EAAA,CACb,KAAA,CAAO,EAAA,CACP,GAAA,CAAK,EAAA,CACL,OAAA,CAAS,GAMT,WAAA,CAAa,EAAA,CAIb,QAAA,CAAU,EAAA,CACV,MAAA,CAAQ,EAAA,CACR,QAAS,EAAA,CACT,IAAA,CAAM,EACR,EAiDA,IAAMC,CAAAA,CAA2C,CAE/C,CAACC,CAAAA,CAAW,IAAI,EAAOF,CAAAA,CAAa,GAAA,CACpC,CAACE,CAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,GAAA,CACpC,CAACE,EAAW,IAAI,EAAOF,CAAAA,CAAa,OAAA,CACpC,CAACE,CAAAA,CAAW,KAAK,EAAMF,CAAAA,CAAa,OAAA,CACpC,CAACE,CAAAA,CAAW,GAAG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O2AWO.js","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 */\nconst 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/**\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\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: appends `n` to the program's constant pool and\n\t * writes its index into the opcode stream (read back by the VM as e.g.\n\t * `PUSH_NUMBER <idx>`).\n\t *\n\t * Numeric constants are NOT deduplicated (unlike {@link emitString})\n\t * every call appends a new entry, so an expression with more than\n\t * {@link MAX_CONSTANT_POOL_INDEX}+1 distinct numeric-literal occurrences\n\t * throws rather than silently wrapping the index (see\n\t * `MAX_CONSTANT_POOL_INDEX`'s doc for what that would otherwise do).\n\t *\n\t * @throws If the constant pool would exceed 256 entries.\n\t */\n\temitNumber(n: number): void {\n\t\tconst idx = this.numbers.length;\n\t\tif (idx > MAX_CONSTANT_POOL_INDEX) {\n\t\t\tthrow ErrorFactory.parsing(\n\t\t\t\t\"TOO_MANY_NUMERIC_CONSTANTS\",\n\t\t\t\t`Expression has more than ${MAX_CONSTANT_POOL_INDEX + 1} numeric literals, 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.numbers.push(n);\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(idx);\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(b);\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\tthis.opcodes[position] = 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\tthis.numbers.length = 0;\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'),chunkAUOE7MFI_cjs=require('./chunk-AUOE7MFI.cjs'),chunkMWWAKZOD_cjs=require('./chunk-MWWAKZOD.cjs'),chunkABVDKMNF_cjs=require('./chunk-ABVDKMNF.cjs'),chunk2VE4OW4A_cjs=require('./chunk-2VE4OW4A.cjs'),chunkDA7M6H63_cjs=require('./chunk-DA7M6H63.cjs'),chunkZKFCKAIX_cjs=require('./chunk-ZKFCKAIX.cjs'),chunkEZKR44MA_cjs=require('./chunk-EZKR44MA.cjs'),chunkELQQKZN3_cjs=require('./chunk-ELQQKZN3.cjs');var vt=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 m=this.lineReads.get(a);if(m)for(let g of m){let h=this.consumers.get(g);h&&h.delete(a);}this.lineReads.set(a,new Set(s));for(let g of s)this.consumers.has(g)||this.consumers.set(g,new Set),this.consumers.get(g).add(a);if(u.length>0){this.dependencies.set(a,new Set(s)),this.writes.set(a,new Set(u));for(let g of u){let h=this.consumers.get(g);h&&h.delete(a);}}}registerLineDataSourceDependency(a,s,u){let m=JSON.stringify(u),g=`${s}:${m}`;this.dataSourceDependencies.has(a)||this.dataSourceDependencies.set(a,new Set),this.dataSourceDependencies.get(a).add(g),this.dataSourceConsumers.has(g)||this.dataSourceConsumers.set(g,new Set),this.dataSourceConsumers.get(g).add(a);}getAffectedLines(a){let s=new Set,u=[a];for(;u.length>0;){let m=u.pop(),g=this.consumers.get(m);if(g)for(let h of g){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,m=new Map;for(let y of s)u.has(y)||u.set(y,0),m.has(y)||m.set(y,[]);let g=new Map;for(let y of s){let x=this.writes.get(y);if(x)for(let S of x)g.set(S,y);}for(let y of s){let x=this.lineReads.get(y);if(x)for(let S of x){let O=g.get(S);O!==void 0&&O!==y&&(m.get(O).push(y),u.set(y,(u.get(y)??0)+1));}}let h=[];for(let[y,x]of u)x===0&&h.push(y);if(h.length===0&&s.size>0){let y=Array.from(s).sort((x,S)=>x-S);h.push(y[0]);}let f=[];for(;h.length>0;){let y=h.shift();f.push(y);for(let x of m.get(y)??[]){let S=(u.get(x)??1)-1;u.set(x,S),S===0&&h.push(x);}}if(f.length<s.size){let y=new Set(f),x=Array.from(s).filter(S=>!y.has(S)).sort((S,O)=>S-O);f.push(...x);}return f}getAffectedLinesByDataSource(a,s){let u=JSON.stringify(s),m=`${a}:${u}`;return this.dataSourceConsumers.get(m)??new Set}removeLine(a){let s=this.lineReads.get(a);if(s){for(let m of s){let g=this.consumers.get(m);g&&g.delete(a);}this.lineReads.delete(a);}this.dependencies.delete(a),this.writes.delete(a);let u=this.dataSourceDependencies.get(a);if(u){for(let m of u)this.dataSourceConsumers.get(m)?.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 m={};for(let[h,f]of this.dataSourceDependencies)m[h]=Array.from(f);let g={};for(let[h,f]of this.dataSourceConsumers)g[h]=Array.from(f);return {consumers:a,writes:s,reads:u,dataSourceDeps:m,dataSourceConsumers:g}}clear(){this.consumers.clear(),this.dependencies.clear(),this.writes.clear(),this.lineReads.clear(),this.dataSourceDependencies.clear(),this.dataSourceConsumers.clear();}};var Rt=class{constructor(){this.definitions=new Map;}write(a,s,u){this.definitions.has(a)||this.definitions.set(a,[]);let m=this.definitions.get(a);m.push({line:s,expr:u}),m.sort((g,h)=>g.line-h.line);}read(a,s){let u=this.definitions.get(a);if(u){for(let m=u.length-1;m>=0;m--)if(u[m].line<=s)return u[m].expr.lastResult}}invalidateDownstream(a,s){let u=this.definitions.get(a);if(!u)return;let m=u.findIndex(g=>g.line===s);m!==-1&&u.splice(m+1);}clear(){this.definitions.clear();}};var je={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}},nn={"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"},an=r=>r.join(",");function ze(r,a,s){if(r.type!==6||a.type!==6)return null;let u=r.unit?je[r.unit]:void 0,m=a.unit?je[a.unit]:void 0;if(u===void 0||m===void 0)return null;let g=[u.dim[0]+(s?m.dim[0]:-m.dim[0]),u.dim[1]+(s?m.dim[1]:-m.dim[1]),u.dim[2]+(s?m.dim[2]:-m.dim[2]),u.dim[3]+(s?m.dim[3]:-m.dim[3])],h=nn[an(g)];if(h===void 0)return null;let f=r.toNumber()*u.si,y=a.toNumber()*m.si,x=s?f*y:f/y;return chunkDA7M6H63_cjs.u(x/je[h].si,h)}function rn(r){let a=new Date(r).getDay();return a===0||a===6}function Bt(r,a){return rn(r)?false:a?!a(r):true}function Vt(r){let a=new Date(r);return new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime()}function Lt(r,a,s,u){let m=Math.trunc(Math.abs(a)),g=a>=0?1:-1,h=new Date(r),f=0;for(;m>0;){if(h.setDate(h.getDate()+g),f++,f>u)return null;Bt(h.getTime(),s)&&m--;}return h.getTime()}function Ft(r,a,s,u){let m=Vt(Math.min(r,a)),g=Vt(Math.max(r,a)),h=Math.round((g-m)/864e5);if(h>u)return null;let f=0,y=new Date(m);for(let x=0;x<=h;x++)Bt(y.getTime(),s)&&f++,y.setDate(y.getDate()+1);return f}var sn={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 ke(r){return r===1?"1 argument":`${r} arguments`}function on(r){return r.max===1/0?`at least ${ke(r.min)}`:r.min===r.max?ke(r.min):`${r.min} to ${ke(r.max)}`}function $t(r,a){let s=sn[r];if(s!==void 0&&!(a>=s.min&&a<=s.max))return chunkELQQKZN3_cjs.c.execution("BUILTIN_ARITY_MISMATCH",`${s.name}() takes ${on(s)}, but was given ${a===0?"none":ke(a)}`,{functionName:s.name,expectedMin:s.min,expectedMax:s.max,actual:a})}function ia(r,a=200,s=5e4,u=50,m=1e5,g=2e6,h=1e4,f=100,y=-100,x=chunkAUOE7MFI_cjs.y,S){let O=[],E=new Map,F=0,j,$,n=[],Q=new Map,X=new Map,K=new Map;return {push(d){if(O.length>=a)throw chunkELQQKZN3_cjs.c.execution("STACK_LIMIT_EXCEEDED",`Execution exceeded maximum stack depth of ${a}`);O.push(d);},getMaxStackDepth(){return a},getMaxCollectionSize(){return m},getMaxAllocatedElements(){return g},getMaxFunctionCalls(){return h},getMaxDateOffsetYears(){return f},getMinDateOffsetYears(){return y},isHoliday(d){return S?S(d):false},pop(){return c(O)},popNumber(){return c(O).toNumber()},popString(){return q(c(O),"VM.popString()")},peek(){return O[O.length-1]},getStack(){return O},registry:r,getVar(d){if(n.length>0){let e=n[n.length-1].get(d);if(e!==void 0)return e}return E.get(d)},setVar(d,e){E.set(d,e);},deleteVar(d){E.delete(d);},pushCallFrame(d){if(n.length>=u)throw chunkELQQKZN3_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});n.push(d);},popCallFrame(){n.pop();},getCallFrame(){return n.length>0?n[n.length-1]:void 0},defineUserFunction(d,e,t){Q.set(d,{name:d,params:e,program:t});},getUserFunction(d){return Q.get(d)},hasUserFunction(d){return Q.has(d)},getVariableEntries(){return Array.from(E.entries())},getUserFunctionDefs(){return Array.from(Q.values())},defineEquation(d,e,t){X.set(d,{variable:d,factorNames:e,rhsProgram:t});},getEquation(d){return X.get(d)},hasEquation(d){return X.has(d)},defineScalarEquation(d,e,t){K.set(d,{variable:d,lhsProgram:e,rhsProgram:t});},getScalarEquation(d){return K.get(d)},hasScalarEquation(d){return K.has(d)},reset(){O.length=0,E.clear(),n.length=0,Q.clear(),X.clear(),K.clear(),F=0,$&&($(),$=void 0),j=void 0;},get activeSignal(){return j},set activeSignal(d){j=d;},get abortCurrent(){return $},set abortCurrent(d){$=d;},context:x,getMaxInstructions(){return s},getInstructionCount(){return F},incrementInstructions(d){if(F+=d,F>s)throw chunkELQQKZN3_cjs.c.execution("INSTRUCTION_LIMIT_EXCEEDED",`Execution exceeded maximum of ${s} instructions`)}}}function un(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 ln(r,a){return !Number.isInteger(a)||a<0?0:r.rows*r.cols*(1+(a<2?1:2*Math.floor(Math.log2(a))))}function Pt(r,a,s){return r.context.networkEnabled?chunkDA7M6H63_cjs.P("CURRENCY_RATE_UNAVAILABLE",`No exchange rate available for ${a} to ${s}`):chunkDA7M6H63_cjs.P("NETWORK_DISABLED",`No exchange rate for ${a} to ${s}: live data is switched off for this engine (network.enabled is false)`)}function c(r){if(r.length===0)throw chunkELQQKZN3_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 Zt="bytecode is caller input on this entry point: rebuild the program with the engine's compiler, or fix the hand-assembled stream";function mn(r){return typeof r=="number"?chunkABVDKMNF_cjs.b(r):r}function oe(r,a,s,u,m,g={}){let h=mn(a);return chunkELQQKZN3_cjs.c.validation({code:r,message:`Malformed bytecode: ${h} ${s}`,expected:u,found:m,suggestion:Zt,context:typeof a=="number"?{opcode:a,opcodeName:h,...g}:{site:h,...g}})}function U(r,a,s,u){if(a>=r.length)throw oe("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 Je(r,a,s,u,m,g){let h=U(r,a,s,u);if(h>=m)throw oe("MALFORMED_BYTECODE_CONSTANT_INDEX",s,`reads ${g} entry ${h}, which does not exist`,`an index below ${m}`,`${h}`,{index:h,poolSize:m,pool:g});return h}function J(r,a,s,u,m){return Te(s,U(r,a,u,m),u)}function Te(r,a,s){let u=r[a];if(typeof u!="string")throw oe("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 q(r,a,s){if(typeof r.value!="string")throw oe("MALFORMED_BYTECODE_OPERAND_TYPE",a,`expected a ${s??"string"} on the stack`,s?`a string value holding the ${s}`:"a string value",`a ${chunkDA7M6H63_cjs.g[r.type]??"unknown"} value`,s?{role:s,valueType:r.type}:{valueType:r.type});return r.value}function Yt(r,a,s){if(r!==0&&r!==1&&r!==2)throw oe("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 cn(r,a){try{return BigInt(r)}catch{throw oe("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 pn(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 Wt=64;function Qe(r,a,s,u,m,g,h,f){let y=new Map;for(let S=0;S<r.length;S++)y.set(r[S],s[S]);u.pushCallFrame(y);let x;try{x=tt(a,u,m,g,h,f);}finally{u.popCallFrame();}if(x.type==="pending")throw chunkELQQKZN3_cjs.c.execution("MAP_REDUCE_ASYNC_UNSUPPORTED","map/reduce transform bodies calling an async operation (weather, stocks, currency, ...) aren't supported");if(x.type==="error")throw x.error;return x.value}function dn(r,a,s,u,m,g,h){let f=new Map(s.getCallFrame());f.set(r,chunkDA7M6H63_cjs.K(chunk2VE4OW4A_cjs.q(r))),s.pushCallFrame(f);let y;try{y=tt(a,s,u,m,g,h);}finally{s.popCallFrame();}if(y.type==="pending")throw chunkELQQKZN3_cjs.c.execution("SYMBOLIC_ASYNC_UNSUPPORTED","an algebra verb's expression cannot call an async operation (weather, stocks, currency, ...)");if(y.type==="error")throw y.error;return y.value}function Gt(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 m=s.indexOf("/"),g=u.indexOf("/");if(m<0||g<0||s.slice(0,m)!==u.slice(0,g))return null;let h=chunkEZKR44MA_cjs.a[s.slice(m+1).toLowerCase()],f=chunkEZKR44MA_cjs.a[u.slice(g+1).toLowerCase()];return h===void 0||f===void 0||h[0]!==f[0]?null:r.toNumber()*(f[1]/h[1])}function Xt(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 m=chunk2VE4OW4A_cjs.ua[s.toUpperCase()]!==void 0,g=chunk2VE4OW4A_cjs.ua[u.toUpperCase()]!==void 0;return m===g?null:chunkDA7M6H63_cjs.u(r.toNumber()*a.toNumber(),m?s:u)}function Kt(r,a,s){if(r.type===5)return a.type===6&&a.unit!==void 0?chunkAUOE7MFI_cjs.c(a,a.unit,r.toNumber(),s):a.type!==5&&a.type!==0?null:chunkDA7M6H63_cjs.N(r.toNumber()+s*a.toNumber());if(a.type!==5)return null;let u=1+s*a.toNumber();if(r.type===0){let m=r.toNumber()*u;return r.uncertainty!==void 0?chunkDA7M6H63_cjs.q(m,Math.abs(r.uncertainty*u)):chunkDA7M6H63_cjs.n(m)}return r.type===6&&r.unit!==void 0?chunkAUOE7MFI_cjs.c(r,r.unit,a.toNumber(),s):null}function fn(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 m=s.toNumber();return chunkDA7M6H63_cjs.q(u.toNumber()*m,Math.abs(u.uncertainty*m))}function bn(r,a){let s=r.type===6?r:a,u=r.type===6?a:r;return s.type!==6||s.unit===void 0||!chunkMWWAKZOD_cjs.c.isCurrency(s.unit)||u.type!==0&&u.type!==5||u.rational!==void 0?null:chunkAUOE7MFI_cjs.b(s,u.toNumber(),s.unit)}function hn(r,a){if(a.type===5&&r.type===0&&r.uncertainty!==void 0){let s=a.toNumber();return s===0?null:chunkDA7M6H63_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:chunkDA7M6H63_cjs.q(r.toNumber()/s,Math.abs(r.toNumber()*a.uncertainty/(s*s)))}return null}function gn(r){if(r.type===6){let a=r.unit;if(a&&chunkZKFCKAIX_cjs.c(a)==="time")try{return chunkZKFCKAIX_cjs.e(r.toNumber(),a,"ms")}catch{}return 0}return r.toNumber()}var Ht=260;function en(r,a,s){let u=Math.trunc(Math.abs(a)),g=(a>=0?1:-1)>0?s.getMaxDateOffsetYears():-s.getMinDateOffsetYears(),h=Math.floor(g*Ht);if(u>h)throw chunkELQQKZN3_cjs.c.execution("DATE_OFFSET_LIMIT_EXCEEDED",`A date offset of ${u.toLocaleString("en-US")} workdays is about ${Math.round(u/Ht).toLocaleString("en-US")} years, past the limit of ${g} years for a workday offset`,{requestedWorkdays:u,limitYears:g,limitWorkdays:h});let f=h*7+7,y=Lt(r,a,x=>s.isHoliday(x),f);if(y===null)throw chunkELQQKZN3_cjs.c.execution("DATE_OFFSET_LIMIT_EXCEEDED",`A working-day offset of ${u.toLocaleString("en-US")} could not be reached within the ${g}-year limit; the configured holiday calendar leaves too few working days`,{requestedWorkdays:u,limitYears:g,maxCalendarSteps:f});return y}var qt=864e5,yn={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 tn(r,a){let s=Math.trunc(a),u=new Date(r);u.setDate(u.getDate()+s);let m=u.getTime();return Number.isNaN(m)?r+a*qt:m+(a-s)*qt}function Nn(r,a){let s=Math.trunc(a),u=new Date(r),m=u.getDate();u.setDate(1),u.setMonth(u.getMonth()+s),u.setDate(Math.min(m,chunkAUOE7MFI_cjs.L(u.getFullYear(),u.getMonth())));let g=u.getTime(),h=chunkZKFCKAIX_cjs.e(1,"month","ms");return Number.isNaN(g)?r+a*h:g+(a-s)*h}function he(r,a,s,u){if(a.type===6&&a.unit!==void 0){let m=a.unit,g=s*a.toNumber();if(chunkZKFCKAIX_cjs.a(m))return en(r,g,u);let h=yn[m];if(h!==void 0)return Nn(r,g*h);if(chunkZKFCKAIX_cjs.c(m)==="time"){let f=0;try{f=chunkZKFCKAIX_cjs.e(1,m,"day");}catch{}if(Number.isInteger(f)&&f>=1)return tn(r,g*f)}}return r+s*gn(a)}function jt(r,a,s){let u=chunkDA7M6H63_cjs.B(r.unit);if(a.type===6&&chunkDA7M6H63_cjs.A(a.unit)){let m=chunkDA7M6H63_cjs.B(a.unit);return m!==u?chunkDA7M6H63_cjs.P("TIMECODE_FPS_MISMATCH",`Cannot combine timecodes at different frame rates (${u} fps vs ${m} fps)`):s===1?chunkDA7M6H63_cjs.u(r.toNumber()+a.toNumber(),r.unit):chunkDA7M6H63_cjs.u(r.toNumber()-a.toNumber(),"frames")}if(a.type===6&&a.unit==="frames")return chunkDA7M6H63_cjs.u(r.toNumber()+s*a.toNumber(),r.unit);if(a.type===6&&a.unit&&chunkZKFCKAIX_cjs.c(a.unit)==="time"){let m=chunkZKFCKAIX_cjs.e(a.toNumber(),a.unit,"s");return chunkDA7M6H63_cjs.u(r.toNumber()+s*m*u,r.unit)}return chunkDA7M6H63_cjs.u(r.toNumber()+s*a.toNumber(),r.unit)}function ge(r){return r.type===10?r.value:r.toNumber()!==0}function zt(r,a){let s=chunkAUOE7MFI_cjs.l(r,a);return chunkDA7M6H63_cjs.P("INCOMPATIBLE_UNITS",s??`Cannot convert ${r} to ${a}: they do not measure the same thing`)}var Se=65536;function xn(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 En(r,a){let s=1n,u=r,m=a;for(;m>0n;)m%2n===1n&&(s*=u),m/=2n,m>0n&&(u*=u);return s}var Ze=Se;function Jt(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 Qt(r,a,s){let u=chunkAUOE7MFI_cjs.n(r),m=chunkAUOE7MFI_cjs.n(a);if(u===0n)return chunkDA7M6H63_cjs.s(0n);let g=s*Number(m);if(g<=0||Jt(u)+g<=Ze)return chunkDA7M6H63_cjs.s(s===1?u<<m:u>>m);throw chunkELQQKZN3_cjs.c.execution("BIGINT_SHIFT_LIMIT_EXCEEDED",`Shifting by ${m} would build an exact integer of about ${(Jt(u)+g).toLocaleString("en-US")} bits, past the limit of ${Ze.toLocaleString("en-US")} bits`,{shift:String(m),limitBits:Ze})}function et(r,a){let{numerator:s,denominator:u}=chunkDA7M6H63_cjs.y(r.unit),m=chunkZKFCKAIX_cjs.c(u),g=chunkZKFCKAIX_cjs.c(a.unit);if(!m||m!==g)return chunkDA7M6H63_cjs.P("RATE_MUL_MEASURE_MISMATCH",`Cannot multiply a "${u}"-denominated rate by "${a.unit}" \u2014 different measures`);let h=chunkZKFCKAIX_cjs.e(a.toNumber(),a.unit,u),f=r.toNumber()*h;return s?chunkDA7M6H63_cjs.u(f,s):chunkDA7M6H63_cjs.n(f)}function In(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),m=s-u;if(m<1e-9)return `${a?"-":""}${u}`;let g=0,h=1,f=1,y=0,x=m,S=1e6;for(let E=0;E<30;E++){let F=Math.floor(x+1e-9),j=F*h+g,$=F*y+f;if($>S||(g=h,h=j,f=y,y=$,Math.abs(m-h/y)<1e-9))break;let n=x-F;if(n<1e-9)break;x=1/n;}let O=u*y+h;return `${a?"-":""}${O}/${y}`}function Dn(r){return r.d===1n?String(r.n):`${r.n}/${r.d}`}function Mn(r){let a=r.toNumber(),s=r.type===5?1+a:a;return `${Math.round(s*1e6)/1e6}x`}function _n(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 tt(r,a,s,u,m,g){let h=pn(r);if(h)return {type:"error",error:chunkELQQKZN3_cjs.c.validation({code:"MALFORMED_BYTECODE_PROGRAM",message:`Malformed bytecode: ${h}`,expected:"a BytecodeProgram with opcodes, numbers and strings",found:h,suggestion:Zt})};let{opcodes:f,numbers:y,strings:x,userFunctionBodies:S,anonymousBodies:O}=r,E=0,F=0,j=a.getMaxInstructions(),$=a.getMaxStackDepth(),n=a.getStack(),Q=s?.hasCollectors??false,X=chunkDA7M6H63_cjs.j();if(f.length===0)return {type:"value",value:chunkDA7M6H63_cjs.n(0)};chunkDA7M6H63_cjs.a(a);try{for(;E<f.length;){if(++F>j)throw chunkELQQKZN3_cjs.c.execution("INSTRUCTION_LIMIT_EXCEEDED",`Execution exceeded maximum of ${j} instructions`);if(n.length>$)throw chunkELQQKZN3_cjs.c.execution("STACK_LIMIT_EXCEEDED",`Execution exceeded maximum stack depth of ${$}`);let d=f[E++];if(Q){let e=n.map(t=>({type:t.type,value:t.value,unit:t.unit}));s.fireVmStep({type:chunkHG4NPDN5_cjs.c.VmStep,elapsedNs:0,expression:u??"",opcode:d,opcodeName:chunkABVDKMNF_cjs.b(d),ip:E-1,stackDepth:n.length,instructionNumber:F,stack:e});}switch(d){case 0:break;case 1:{let e=c(n);return {type:"value",value:X?chunkDA7M6H63_cjs.k(e):e}}case 3:{let e=c(n);n.push(e),n.push(e);break}case 2:{let e=c(n),t=c(n);n.push(e),n.push(t);break}case 10:n.push(chunkDA7M6H63_cjs.n(y[Je(f,E++,d,"constant-pool index",y.length,"number-pool")]));break;case 11:n.push(chunkDA7M6H63_cjs.s(cn(J(f,E++,x,d,"constant-pool index"),d)));break;case 16:{let e=chunk2VE4OW4A_cjs.ia(J(f,E++,x,d,"constant-pool index"));n.push(chunkDA7M6H63_cjs.o(chunk2VE4OW4A_cjs.ra(e),e));break}case 12:n.push(chunkDA7M6H63_cjs.r(y[Je(f,E++,d,"constant-pool index",y.length,"number-pool")]));break;case 13:n.push(chunkDA7M6H63_cjs.t(J(f,E++,x,d,"constant-pool index")));break;case 14:n.push(chunkDA7M6H63_cjs.L(U(f,E++,d,"boolean operand")===1));break;case 20:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.uncertainty!==void 0||e.uncertainty!==void 0){let p=chunkAUOE7MFI_cjs.s(t,e,"add");if(p){n.push(p);break}}if(t.rational!==void 0||e.rational!==void 0){let p=chunkAUOE7MFI_cjs.r(t,e,"add");if(p){n.push(p);break}}let i=Kt(t,e,1),l=i===null?Gt(t,e):null;i!==null?n.push(i):l!==null?n.push(chunkDA7M6H63_cjs.u(l+e.toNumber(),e.unit)):t.type===0&&e.type===0?n.push(chunkDA7M6H63_cjs.n(t.value+e.value)):t.type===10&&e.type===10?n.push(chunkDA7M6H63_cjs.L(t.value&&e.value)):t.type===4?e.type===4?n.push(chunkDA7M6H63_cjs.P("INVALID_DATETIME_OP","Cannot add two datetimes together")):n.push(chunkDA7M6H63_cjs.M(he(t.toNumber(),e,1,a))):t.type===6&&chunkDA7M6H63_cjs.A(t.unit)?n.push(jt(t,e,1)):e.type===4?n.push(chunkDA7M6H63_cjs.M(he(e.toNumber(),t,1,a))):t.type===3&&e.type===3?n.push(chunkDA7M6H63_cjs.t(t.value+e.value)):n.push(chunkAUOE7MFI_cjs.u(t,e,(p,b)=>p+b,(p,b)=>p+b,"add"));break}case 21:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.uncertainty!==void 0||e.uncertainty!==void 0){let p=chunkAUOE7MFI_cjs.s(t,e,"sub");if(p){n.push(p);break}}if(t.rational!==void 0||e.rational!==void 0){let p=chunkAUOE7MFI_cjs.r(t,e,"sub");if(p){n.push(p);break}}let i=Kt(t,e,-1),l=i===null?Gt(t,e):null;i!==null?n.push(i):l!==null?n.push(chunkDA7M6H63_cjs.u(l-e.toNumber(),e.unit)):t.type===0&&e.type===0?n.push(chunkDA7M6H63_cjs.n(t.value-e.value)):t.type===4?e.type===4?n.push(chunkDA7M6H63_cjs.u(t.toNumber()-e.toNumber(),"ms")):n.push(chunkDA7M6H63_cjs.M(he(t.toNumber(),e,-1,a))):t.type===6&&chunkDA7M6H63_cjs.A(t.unit)?n.push(jt(t,e,-1)):e.type===4?n.push(chunkDA7M6H63_cjs.P("INVALID_DATETIME_OP","Cannot subtract a datetime from a value that is not a datetime")):n.push(chunkAUOE7MFI_cjs.u(t,e,(p,b)=>p-b,(p,b)=>p-b,"sub"));break}case 22:{let e=c(n),t=c(n),o=fn(t,e);if(o){n.push(o);break}if(t.uncertainty!==void 0||e.uncertainty!==void 0){let l=chunkAUOE7MFI_cjs.s(t,e,"mul");if(l){n.push(l);break}}if(t.rational!==void 0||e.rational!==void 0){let l=chunkAUOE7MFI_cjs.r(t,e,"mul");if(l){n.push(l);break}}let i=bn(t,e);if(i){n.push(i);break}if(t.type===0&&e.type===0)n.push(chunkDA7M6H63_cjs.n(t.value*e.value));else if(t.type===7&&e.type===7)chunkDA7M6H63_cjs.d(un(t.value,e.value),"matrix cells"),n.push(chunk2VE4OW4A_cjs._(t.value,e.value));else if(t.type===6&&chunkDA7M6H63_cjs.x(t.unit)&&e.type===6&&e.unit)n.push(et(t,e));else if(e.type===6&&chunkDA7M6H63_cjs.x(e.unit)&&t.type===6&&t.unit)n.push(et(e,t));else if(Xt(t,e)!==null)n.push(Xt(t,e));else {let l=ze(t,e,!0);l?n.push(l):n.push(chunkAUOE7MFI_cjs.u(t,e,(p,b)=>p*b,(p,b)=>p*b,"mul"));}break}case 23:{let e=c(n),t=c(n),o=hn(t,e);if(o){n.push(o);break}if(t.uncertainty!==void 0||e.uncertainty!==void 0){let i=chunkAUOE7MFI_cjs.s(t,e,"div");if(i){n.push(i);break}}if(t.type===6&&e.type===6){let{lv:i,rv:l,sameMeasure:p}=chunkAUOE7MFI_cjs.j(t,e);if(p)n.push(chunkDA7M6H63_cjs.n(i/l));else if(chunkMWWAKZOD_cjs.c.isCurrency(t.unit)&&chunkMWWAKZOD_cjs.c.isCurrency(e.unit))n.push(chunkDA7M6H63_cjs.P("INCOMPATIBLE_UNITS",`Cannot combine incompatible units: ${t.unit} and ${e.unit}`));else {let b=ze(t,e,!1);if(b){n.push(b);break}n.push(chunkDA7M6H63_cjs.w(i/l,t.unit,e.unit));}}else {let i=chunkAUOE7MFI_cjs.r(t,e,"div");if(i){n.push(i);break}n.push(chunkAUOE7MFI_cjs.u(t,e,(l,p)=>l/p,(l,p)=>{if(p===0n)throw chunkAUOE7MFI_cjs.o();return l/p},"div"));}break}case 24:{let e=c(n),t=c(n);n.push(chunkAUOE7MFI_cjs.u(t,e,(o,i)=>o%i,(o,i)=>{if(i===0n)throw chunkAUOE7MFI_cjs.o();return o%i}));break}case 25:{let e=c(n),t=c(n);if(t.type===13){n.push(t);break}if(e.type===13){n.push(e);break}if(t.type===12){n.push(t);break}if(e.type===12){n.push(e);break}if(t.type===0&&e.type===0){n.push(chunkDA7M6H63_cjs.n(chunkAUOE7MFI_cjs.q(t.value,e.value)));break}if(t.type===7||e.type===7){if(t.type!==7||e.type!==0){n.push(chunkDA7M6H63_cjs.P("MATRIX_POWER_UNSUPPORTED",`^: a matrix may only be the base, raised to a whole number (as in "[1,2;3,4]^2"); "${chunkDA7M6H63_cjs.g[t.type]} ^ ${chunkDA7M6H63_cjs.g[e.type]}" has no matrix reading.`));break}chunkDA7M6H63_cjs.d(ln(t.value,e.value),"matrix cells"),n.push(chunk2VE4OW4A_cjs.$(t.value,e.value));break}if(t.type===9||e.type===9){n.push(chunkAUOE7MFI_cjs.f(t,e));break}if(t.type===2||e.type===2){let o=xn(t,e.toNumber());if(o!==null){if(o>Se)throw chunkELQQKZN3_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 ${Se.toLocaleString("en-US")} bits`,{limitBits:Se});n.push(chunkDA7M6H63_cjs.s(En(chunkAUOE7MFI_cjs.n(t),chunkAUOE7MFI_cjs.n(e))));break}}n.push(chunkDA7M6H63_cjs.n(chunkAUOE7MFI_cjs.q(t.toNumber(),e.toNumber())));break}case 26:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}e.type===2?n.push(chunkDA7M6H63_cjs.s(-e.value)):e.type===6&&e.exact!==void 0?n.push(chunkDA7M6H63_cjs.v(-e.toNumber(),e.unit,chunk2VE4OW4A_cjs.ma(e.exact))):e.type===6?n.push(chunkDA7M6H63_cjs.u(-e.toNumber(),e.unit)):e.type===5?n.push(chunkDA7M6H63_cjs.N(-e.toNumber())):e.type===9?n.push(chunkAUOE7MFI_cjs.g(e)):e.type===0&&e.rational!==void 0?n.push(chunkDA7M6H63_cjs.p(-e.toNumber(),chunk2VE4OW4A_cjs.j(e.rational))):e.type===0&&e.exact!==void 0?n.push(chunkDA7M6H63_cjs.o(-e.toNumber(),chunk2VE4OW4A_cjs.ma(e.exact))):n.push(chunkDA7M6H63_cjs.n(-e.toNumber()));break}case 27:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}e.type===6&&e.exact!==void 0?n.push(chunkDA7M6H63_cjs.v(e.toNumber(),e.unit,e.exact)):e.type===6?n.push(chunkDA7M6H63_cjs.u(e.toNumber(),e.unit)):e.type===5?n.push(chunkDA7M6H63_cjs.N(e.toNumber())):e.type===0&&e.rational!==void 0?n.push(chunkDA7M6H63_cjs.p(e.toNumber(),e.rational)):e.type===0&&e.exact!==void 0?n.push(chunkDA7M6H63_cjs.o(e.toNumber(),e.exact)):n.push(chunkDA7M6H63_cjs.n(e.toNumber()));break}case 28:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}n.push(chunkDA7M6H63_cjs.q(t.toNumber(),Math.abs(e.toNumber())));break}case 30:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}t.type===2||e.type===2?n.push(Qt(t,e,1)):n.push(chunkDA7M6H63_cjs.n(t.toNumber()<<e.toNumber()));break}case 31:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}t.type===2||e.type===2?n.push(Qt(t,e,-1)):n.push(chunkDA7M6H63_cjs.n(t.toNumber()>>e.toNumber()));break}case 32:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}n.push(chunkDA7M6H63_cjs.n(t.toNumber()>>>e.toNumber()));break}case 33:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}t.type===2||e.type===2?n.push(chunkDA7M6H63_cjs.s(chunkAUOE7MFI_cjs.n(t)&chunkAUOE7MFI_cjs.n(e))):n.push(chunkDA7M6H63_cjs.n(t.toNumber()&e.toNumber()));break}case 34:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}t.type===2||e.type===2?n.push(chunkDA7M6H63_cjs.s(chunkAUOE7MFI_cjs.n(t)|chunkAUOE7MFI_cjs.n(e))):n.push(chunkDA7M6H63_cjs.n(t.toNumber()|e.toNumber()));break}case 35:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}t.type===2||e.type===2?n.push(chunkDA7M6H63_cjs.s(chunkAUOE7MFI_cjs.n(t)^chunkAUOE7MFI_cjs.n(e))):n.push(chunkDA7M6H63_cjs.n(t.toNumber()^e.toNumber()));break}case 36:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}e.type===2?n.push(chunkDA7M6H63_cjs.s(~e.value)):n.push(chunkDA7M6H63_cjs.n(~e.toNumber()));break}case 40:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkAUOE7MFI_cjs.t(t,e);if(i!==null){n.push(chunkDA7M6H63_cjs.L(i===0));break}}if(t.type===0&&e.type===0)n.push(chunkDA7M6H63_cjs.L(t.value===e.value));else if(t.type===2||e.type===2){let i=chunkAUOE7MFI_cjs.p(t,e);n.push(chunkDA7M6H63_cjs.L(i===null?t.toNumber()===e.toNumber():i===0));}else if(t.type===3&&e.type===3)n.push(chunkDA7M6H63_cjs.L(t.value===e.value));else if(t.type===6&&e.type===6){let{equal:i,sameMeasure:l}=chunkAUOE7MFI_cjs.k(t,e);n.push(chunkDA7M6H63_cjs.L(l&&i));}else if(t.type===7&&e.type===7)n.push(chunk2VE4OW4A_cjs.aa(t.value,e.value,(i,l)=>i===l));else if(t.type===14||e.type===14)if(t.type===14&&e.type===14){let i=t.value,l=e.value;n.push(chunkDA7M6H63_cjs.L(i.r===l.r&&i.g===l.g&&i.b===l.b&&i.a===l.a));}else n.push(chunkDA7M6H63_cjs.L(!1));else n.push(chunkDA7M6H63_cjs.L(t.toNumber()===e.toNumber()));break}case 41:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkAUOE7MFI_cjs.t(t,e);if(i!==null){n.push(chunkDA7M6H63_cjs.L(i!==0));break}}if(t.type===0&&e.type===0)n.push(chunkDA7M6H63_cjs.L(t.value!==e.value));else if(t.type===2||e.type===2){let i=chunkAUOE7MFI_cjs.p(t,e);n.push(chunkDA7M6H63_cjs.L(i===null?t.toNumber()!==e.toNumber():i!==0));}else if(t.type===3&&e.type===3)n.push(chunkDA7M6H63_cjs.L(t.value!==e.value));else if(t.type===6&&e.type===6){let{equal:i,sameMeasure:l}=chunkAUOE7MFI_cjs.k(t,e);n.push(chunkDA7M6H63_cjs.L(!l||!i));}else if(t.type===7&&e.type===7)n.push(chunk2VE4OW4A_cjs.aa(t.value,e.value,(i,l)=>i!==l));else if(t.type===14||e.type===14)if(t.type===14&&e.type===14){let i=t.value,l=e.value;n.push(chunkDA7M6H63_cjs.L(!(i.r===l.r&&i.g===l.g&&i.b===l.b&&i.a===l.a)));}else n.push(chunkDA7M6H63_cjs.L(!0));else n.push(chunkDA7M6H63_cjs.L(t.toNumber()!==e.toNumber()));break}case 42:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkAUOE7MFI_cjs.t(t,e);if(i!==null){n.push(chunkDA7M6H63_cjs.L(i<0));break}}if(t.type===0&&e.type===0)n.push(chunkDA7M6H63_cjs.L(t.value<e.value));else if(t.type===2||e.type===2){let i=chunkAUOE7MFI_cjs.p(t,e);n.push(chunkDA7M6H63_cjs.L(i===null?t.toNumber()<e.toNumber():i<0));}else if(t.type===6&&e.type===6){let{lv:i,rv:l,equal:p,sameMeasure:b}=chunkAUOE7MFI_cjs.k(t,e);n.push(b?chunkDA7M6H63_cjs.L(!p&&i<l):chunkAUOE7MFI_cjs.m(t,e));}else t.type===7&&e.type===7?n.push(chunk2VE4OW4A_cjs.aa(t.value,e.value,(i,l)=>i<l)):n.push(chunkDA7M6H63_cjs.L(t.toNumber()<e.toNumber()));break}case 43:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkAUOE7MFI_cjs.t(t,e);if(i!==null){n.push(chunkDA7M6H63_cjs.L(i<=0));break}}if(t.type===0&&e.type===0)n.push(chunkDA7M6H63_cjs.L(t.value<=e.value));else if(t.type===2||e.type===2){let i=chunkAUOE7MFI_cjs.p(t,e);n.push(chunkDA7M6H63_cjs.L(i===null?t.toNumber()<=e.toNumber():i<=0));}else if(t.type===6&&e.type===6){let{lv:i,rv:l,equal:p,sameMeasure:b}=chunkAUOE7MFI_cjs.k(t,e);n.push(b?chunkDA7M6H63_cjs.L(p||i<=l):chunkAUOE7MFI_cjs.m(t,e));}else t.type===7&&e.type===7?n.push(chunk2VE4OW4A_cjs.aa(t.value,e.value,(i,l)=>i<=l)):n.push(chunkDA7M6H63_cjs.L(t.toNumber()<=e.toNumber()));break}case 44:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkAUOE7MFI_cjs.t(t,e);if(i!==null){n.push(chunkDA7M6H63_cjs.L(i>0));break}}if(t.type===0&&e.type===0)n.push(chunkDA7M6H63_cjs.L(t.value>e.value));else if(t.type===2||e.type===2){let i=chunkAUOE7MFI_cjs.p(t,e);n.push(chunkDA7M6H63_cjs.L(i===null?t.toNumber()>e.toNumber():i>0));}else if(t.type===6&&e.type===6){let{lv:i,rv:l,equal:p,sameMeasure:b}=chunkAUOE7MFI_cjs.k(t,e);n.push(b?chunkDA7M6H63_cjs.L(!p&&i>l):chunkAUOE7MFI_cjs.m(t,e));}else t.type===7&&e.type===7?n.push(chunk2VE4OW4A_cjs.aa(t.value,e.value,(i,l)=>i>l)):n.push(chunkDA7M6H63_cjs.L(t.toNumber()>e.toNumber()));break}case 45:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.rational!==void 0||e.rational!==void 0){let i=chunkAUOE7MFI_cjs.t(t,e);if(i!==null){n.push(chunkDA7M6H63_cjs.L(i>=0));break}}if(t.type===0&&e.type===0)n.push(chunkDA7M6H63_cjs.L(t.value>=e.value));else if(t.type===2||e.type===2){let i=chunkAUOE7MFI_cjs.p(t,e);n.push(chunkDA7M6H63_cjs.L(i===null?t.toNumber()>=e.toNumber():i>=0));}else if(t.type===6&&e.type===6){let{lv:i,rv:l,equal:p,sameMeasure:b}=chunkAUOE7MFI_cjs.k(t,e);n.push(b?chunkDA7M6H63_cjs.L(p||i>=l):chunkAUOE7MFI_cjs.m(t,e));}else t.type===7&&e.type===7?n.push(chunk2VE4OW4A_cjs.aa(t.value,e.value,(i,l)=>i>=l)):n.push(chunkDA7M6H63_cjs.L(t.toNumber()>=e.toNumber()));break}case 130:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}n.push(chunkDA7M6H63_cjs.L(ge(t)&&ge(e)));break}case 131:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}n.push(chunkDA7M6H63_cjs.L(ge(t)||ge(e)));break}case 132:{let e=c(n),t=c(n),o=c(n),i=chunkDA7M6H63_cjs.Q(o);if(i){n.push(i);break}n.push(ge(o)?t:e);break}case 50:case 161:{let e;if(d===161){let p=U(f,E++,d,"plugin-function index (low byte)"),b=U(f,E++,d,"plugin-function index (high byte)");e=p|b<<8;}else e=U(f,E++,d,"plugin-function index");let t=U(f,E++,d,"argument count"),o=[];for(let p=0;p<t;p++)o.push(c(n));o.reverse();let i=a.context.pluginFunctions[e],l=chunkDA7M6H63_cjs.R(o);if(l)n.push(l);else if(!i)n.push(chunkDA7M6H63_cjs.P("UNKNOWN_PLUGIN_FUNCTION",`Plugin function index ${e} is not registered with this engine`));else {let p=i(o,m);if(p instanceof Promise){if(!a.context.networkEnabled){p.catch(()=>{}),n.push(chunkDA7M6H63_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 b=`plugin:${e}:${o.map(R=>`${R.type}:${String(R.value??"")}${R.unit?`:${R.unit}`:""}`).join("|")}`,I=a.activeSignal,C=a.context.pluginFunctionOwners[e]??"";return {type:"pending",queryKey:b,resolver:p,packageId:C,signal:I}}n.push(p);}break}case 51:{let e=U(f,E++,d,"builtin-function index"),t=U(f,E++,d,"argument count"),o=$t(e,t);if(o)throw o;let i=[],l=!1;for(let I=0;I<t;I++){let C=c(n);C.type===9&&(l=!0),i.push(C);}let p=chunkDA7M6H63_cjs.R(i);if(p){n.push(p);break}let b=chunkAUOE7MFI_cjs.C[e];if(b){let I=i.reverse(),C=l&&!chunkAUOE7MFI_cjs.e.has(e);n.push(C?chunkAUOE7MFI_cjs.h(e,I):b(I));}else n.push(chunkDA7M6H63_cjs.P("UNKNOWN_BUILTIN_FUNCTION",`Builtin function index ${e} is not registered`));break}case 150:{let e=U(f,E++,d,"function-body index"),t=S?.[e];if(!t)throw chunkELQQKZN3_cjs.c.internal("INTERNAL_MISSING_FUNCTION_BODY",`Internal error: DEFINE_USER_FUNCTION referenced missing body index ${e}`,{bodyIdx:e});a.defineUserFunction(t.name,t.params,t.program);break}case 151:{let e=J(f,E++,x,d,"function-name index"),t=U(f,E++,d,"argument count"),o=[];for(let b=0;b<t;b++)o.push(c(n));o.reverse();let i=a.getUserFunction(e);if(!i)throw chunkELQQKZN3_cjs.c.execution("UNDEFINED_FUNCTION",`Undefined function: ${e}`,{name:e});if(t!==i.params.length)throw chunkELQQKZN3_cjs.c.execution("FUNCTION_ARITY_MISMATCH",`${e} expects ${i.params.length} argument(s) but got ${t}`,{name:e,expected:i.params.length,actual:t});let l=new Map;for(let b=0;b<i.params.length;b++)l.set(i.params[b],o[b]);chunkDA7M6H63_cjs.f(),a.pushCallFrame(l);let p;try{p=tt(i.program,a,s,u,m);}finally{a.popCallFrame();}if(p.type==="pending")throw chunkELQQKZN3_cjs.c.execution("USER_FUNCTION_ASYNC_UNSUPPORTED",`${e}: user-defined functions with async bodies (weather, stocks, currency, ...) aren't supported`,{name:e});if(p.type==="error")throw p.error;n.push(p.value);break}case 60:{let e=J(f,E++,x,d,"variable-name index"),t=a.getVar(e);if(t!==void 0)n.push(t);else if(g)n.push(chunkDA7M6H63_cjs.K(chunk2VE4OW4A_cjs.q(e)));else throw chunkELQQKZN3_cjs.c.execution("UNDEFINED_VARIABLE",`Undefined variable: ${e}`,{varName:e});break}case 61:{let e=c(n),t=J(f,E++,x,d,"variable-name index");a.setVar(t,X?chunkDA7M6H63_cjs.k(e):e),n.push(e);break}case 62:{let e=J(f,E++,x,d,"variable-name index"),t=chunkAUOE7MFI_cjs.J.get(e);if(t===void 0)throw chunkELQQKZN3_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}});n.push(t);break}case 63:{let e=c(n),t=J(f,E++,x,d,"variable-name index");chunkAUOE7MFI_cjs.J.set(t,X?chunkDA7M6H63_cjs.k(e):e),n.push(e);break}case 70:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}n.push(chunkDA7M6H63_cjs.n(e.toNumber()));break}case 71:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}if(e.type===14){let o=e.value;n.push(chunkDA7M6H63_cjs.G({r:o.r,g:o.g,b:o.b,a:o.a,format:"hex"}));break}n.push(chunkDA7M6H63_cjs.r(e.type===2?e.value:e.toNumber()));break}case 74:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}n.push(chunkDA7M6H63_cjs.N(e.toNumber()));break}case 140:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}n.push(chunkDA7M6H63_cjs.t(e.rational!==void 0?Dn(e.rational):In(e.toNumber())));break}case 141:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}n.push(chunkDA7M6H63_cjs.t(Mn(e)));break}case 142:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}n.push(chunkDA7M6H63_cjs.t(_n(e.toNumber())));break}case 143:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}n.push(chunkDA7M6H63_cjs.r(e.type===2?e.value:e.toNumber(),"bin"));break}case 144:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}n.push(chunkDA7M6H63_cjs.r(e.type===2?e.value:e.toNumber(),"oct"));break}case 145:{let e=q(c(n),d,"converter name").toLowerCase(),t=c(n),o=chunkDA7M6H63_cjs.Q(t);if(o){n.push(o);break}let i=chunkAUOE7MFI_cjs.G.get(e);i?n.push(i(t)):n.push(chunkDA7M6H63_cjs.P("UNKNOWN_AS_CONVERTER",`Unknown converter "as ${e}"`));break}case 80:{let e=q(c(n),d,"unit name"),t=c(n),o=chunkDA7M6H63_cjs.Q(t);if(o){n.push(o);break}let i=chunkAUOE7MFI_cjs.a(t,e);i?n.push(chunkDA7M6H63_cjs.v(t.toNumber(),e,i)):n.push(chunkDA7M6H63_cjs.u(t.toNumber(),e));break}case 81:{let e=q(c(n),d,"target unit name"),t=q(c(n),d,"source unit name"),o=c(n),i=chunkDA7M6H63_cjs.Q(o);if(i){n.push(i);break}let l=o.toNumber(),p=chunkZKFCKAIX_cjs.c(t),b=chunkMWWAKZOD_cjs.c.isCurrency(t)&&chunkMWWAKZOD_cjs.c.isCurrency(e);if(p&&chunkZKFCKAIX_cjs.c(e)===p)n.push(chunkDA7M6H63_cjs.u(chunkZKFCKAIX_cjs.e(l,t,e),e));else if(b){let I=chunkMWWAKZOD_cjs.c.convertSync(l,t,e);I!==null?n.push(chunkDA7M6H63_cjs.u(I,e)):n.push(Pt(a,t,e));}else {let I=chunkZKFCKAIX_cjs.k(l,t,e);I!==null?n.push(chunkDA7M6H63_cjs.u(I,e)):n.push(zt(t,e));}break}case 85:{let e=q(c(n),d,"unit name"),t=chunkZKFCKAIX_cjs.f(e);n.push(chunkDA7M6H63_cjs.t(t.length>0?t.join(", "):`No known units for "${e}"`));break}case 83:{let e=q(c(n),d,"unit name"),t=c(n),o=chunkDA7M6H63_cjs.Q(t);if(o){n.push(o);break}let{value:i,unit:l}=chunkZKFCKAIX_cjs.h(t.toNumber(),e);n.push(chunkDA7M6H63_cjs.u(i,l));break}case 84:{let e=q(c(n),d,"target unit name"),t=c(n),o=chunkDA7M6H63_cjs.Q(t);if(o){n.push(o);break}if(t.type===6){let i=t.unit,l=t.toNumber(),p=chunkZKFCKAIX_cjs.c(i),b=chunkMWWAKZOD_cjs.c.isCurrency(i)&&chunkMWWAKZOD_cjs.c.isCurrency(e);if(p&&chunkZKFCKAIX_cjs.c(e)===p)n.push(chunkDA7M6H63_cjs.u(chunkZKFCKAIX_cjs.e(l,i,e),e));else if(b){let I=chunkMWWAKZOD_cjs.c.convertSync(l,i,e);I!==null?n.push(chunkDA7M6H63_cjs.u(I,e)):n.push(Pt(a,i,e));}else {let I=chunkZKFCKAIX_cjs.k(l,i,e);I!==null?n.push(chunkDA7M6H63_cjs.u(I,e)):n.push(zt(i,e));}}else n.push(chunkDA7M6H63_cjs.u(t.toNumber(),e));break}case 82:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}n.push(chunkDA7M6H63_cjs.n(e.toNumber()));break}case 110:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(e.type!==6||!e.unit){n.push(chunkDA7M6H63_cjs.P("RATE_MISSING_DENOMINATOR_UNIT",'Cannot build a rate: the right-hand side of "/" has no unit'));break}let i=t.type===6?t.unit??"":"";n.push(chunkDA7M6H63_cjs.w(t.toNumber()/e.toNumber(),i,e.unit));break}case 111:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.type!==6||!chunkDA7M6H63_cjs.x(t.unit)){n.push(chunkDA7M6H63_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){n.push(chunkDA7M6H63_cjs.P("RATE_MUL_RIGHT_MISSING_UNIT","Right-hand side of a rate multiplication must have a unit matching the rate's denominator"));break}n.push(et(t,e));break}case 112:{let e=q(c(n),d,"denominator unit name"),t=c(n),o=chunkDA7M6H63_cjs.Q(t);if(o){n.push(o);break}if(t.type!==6||!chunkDA7M6H63_cjs.x(t.unit)){n.push(chunkDA7M6H63_cjs.P("RATE_CONVERT_NOT_A_RATE","Cannot convert a non-rate value's denominator"));break}let{numerator:i,denominator:l}=chunkDA7M6H63_cjs.y(t.unit),p=chunkZKFCKAIX_cjs.c(l),b=chunkZKFCKAIX_cjs.c(e);if(!p||p!==b){n.push(chunkDA7M6H63_cjs.P("RATE_CONVERT_MEASURE_MISMATCH",`Cannot convert a "${l}"-denominated rate to "${e}" \u2014 different measures`));break}let I=chunkZKFCKAIX_cjs.e(1,e,l);n.push(chunkDA7M6H63_cjs.w(t.toNumber()*I,i,e));break}case 120:{let e=c(n),t=chunkDA7M6H63_cjs.Q(e);if(t){n.push(t);break}let o=e.toNumber(),i=new Date,l=new Date(i.getFullYear(),i.getMonth(),i.getDate(),0,0,0,0);l.setMinutes(o),n.push(chunkDA7M6H63_cjs.M(l.getTime()));break}case 90:n.push(chunkDA7M6H63_cjs.M(Date.now()));break;case 95:n.push(chunkDA7M6H63_cjs.M(y[Je(f,E++,d,"constant-pool index",y.length,"number-pool")]));break;case 91:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}n.push(chunkDA7M6H63_cjs.M(he(t.toNumber(),e,1,a)));break}case 92:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}n.push(chunkDA7M6H63_cjs.M(he(t.toNumber(),e,-1,a)));break}case 96:{let e=U(f,E++,d,"workday offset direction")===1?-1:1,t=c(n),o=c(n),i=chunkDA7M6H63_cjs.Q(o,t);if(i){n.push(i);break}if(t.type!==4){n.push(chunkDA7M6H63_cjs.P(chunkELQQKZN3_cjs.r.WORKDAY_OFFSET_EXPECTED_DATE,`"working days after/before/from" expects a date to count from, got ${chunkDA7M6H63_cjs.g[t.type]??"an unsupported value"}`));break}n.push(chunkDA7M6H63_cjs.M(en(t.toNumber(),e*o.toNumber(),a)));break}case 97:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.type!==4||e.type!==4){n.push(chunkDA7M6H63_cjs.P(chunkELQQKZN3_cjs.r.WORKDAYS_BETWEEN_EXPECTED_DATES,`"working days between" expects two dates, got ${chunkDA7M6H63_cjs.g[t.type]??"an unsupported value"} and ${chunkDA7M6H63_cjs.g[e.type]??"an unsupported value"}`));break}let i=Math.ceil((a.getMaxDateOffsetYears()-a.getMinDateOffsetYears())*366),l=Ft(t.toNumber(),e.toNumber(),p=>a.isHoliday(p),i);if(l===null){n.push(chunkDA7M6H63_cjs.P(chunkELQQKZN3_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}n.push(chunkDA7M6H63_cjs.n(l));break}case 93:case 94:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}let i=e.toNumber(),l=t.toNumber(),p=new Date(l).getDay(),b=d===93?(i-p+7)%7:(p-i+7)%7;b===0&&(b=7),n.push(chunkDA7M6H63_cjs.M(tn(l,d===93?b:-b)));break}case 152:{let e=U(f,E++,d,"row count"),t=U(f,E++,d,"column count"),o=e*t,i=chunkDA7M6H63_cjs.e(o,"matrix cells"),l=null;for(let p=o-1;p>=0;p--){let b=c(n);l===null&&(l=chunkDA7M6H63_cjs.Q(b)),i[p]=b.type===10||b.type===9?b.value:b.toNumber();}if(l){n.push(l);break}n.push(chunkDA7M6H63_cjs.C(e,t,chunk2VE4OW4A_cjs.Y(e,t,i)));break}case 153:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.type!==7){n.push(chunkDA7M6H63_cjs.P("MATRIX_INDEX_NOT_A_MATRIX",'Cannot index a non-matrix value with "[...]".'));break}let i=t.value,l=Math.trunc(e.toNumber());if(l<0||l>=i.data.length){n.push(chunkDA7M6H63_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 p=chunk2VE4OW4A_cjs.S(i,l);n.push(chunk2VE4OW4A_cjs.X(p));break}case 154:{let e=c(n),t=c(n),o=c(n),i=chunkDA7M6H63_cjs.Q(o,t,e);if(i){n.push(i);break}if(o.type!==7){n.push(chunkDA7M6H63_cjs.P("MATRIX_INDEX_NOT_A_MATRIX",'Cannot index a non-matrix value with "[...]".'));break}let l=o.value,p=Math.trunc(t.toNumber()),b=Math.trunc(e.toNumber());if(!chunk2VE4OW4A_cjs.U(l,p,b)){n.push(chunkDA7M6H63_cjs.P("MATRIX_INDEX_OUT_OF_BOUNDS",`[${p}, ${b}] is out of bounds for a ${l.rows}x${l.cols} matrix.`));break}let I=chunk2VE4OW4A_cjs.T(l,p,b);n.push(chunk2VE4OW4A_cjs.X(I));break}case 156:{let e=c(n),t=c(n),o=chunkDA7M6H63_cjs.Q(t,e);if(o){n.push(o);break}if(t.type!==0||e.type!==0){n.push(chunkDA7M6H63_cjs.P("INVALID_RANGE_BOUND",`A range's bounds must be plain numbers (e.g. "0:3").`));break}let i=t.value,l=e.value;if(!Number.isInteger(i)||!Number.isInteger(l)){n.push(chunkDA7M6H63_cjs.P("NON_INTEGER_RANGE_BOUND",`A range's bounds must be whole numbers, got "${i}:${l}".`));break}if(i>l){n.push(chunkDA7M6H63_cjs.P("DESCENDING_RANGE",`A range's min (${i}) cannot be greater than its max (${l}) \u2014 did you mean "${l}:${i}"?`));break}n.push(chunkDA7M6H63_cjs.F(i,l));break}case 155:{let e=c(n),t=c(n),o=c(n),i=chunkDA7M6H63_cjs.Q(o,t,e);if(i){n.push(i);break}if(o.type!==7){n.push(chunkDA7M6H63_cjs.P("MATRIX_INDEX_NOT_A_MATRIX",'Cannot slice a non-matrix value with "[...]".'));break}if(t.type!==8||e.type!==8){n.push(chunkDA7M6H63_cjs.P("INVALID_MATRIX_SLICE_BOUND",'Matrix slicing needs range bounds (e.g. "a[0:1, 1:2]").'));break}let l=o.value,p=t.value,b=e.value;if(p.min<0||p.max>=l.rows||b.min<0||b.max>=l.cols){n.push(chunkDA7M6H63_cjs.P("MATRIX_INDEX_OUT_OF_BOUNDS",`Slice [${p.min}:${p.max}, ${b.min}:${b.max}] is out of bounds for a ${l.rows}x${l.cols} matrix.`));break}let I=p.max-p.min+1,C=b.max-b.min+1,R=chunkDA7M6H63_cjs.e(I*C,"matrix cells");for(let B=0;B<I;B++)for(let _=0;_<C;_++)R[B+_*I]=chunk2VE4OW4A_cjs.T(l,p.min+B,b.min+_);n.push(chunkDA7M6H63_cjs.C(I,C,R));break}case 157:{let e=U(f,E++,d,"body kind"),t=U(f,E++,d,"body reference"),o=U(f,E++,d,"collection count");Yt(e,t,d);let i=new Array(o);for(let k=o-1;k>=0;k--)i[k]=c(n);let l=[],p;if(e===0){let k=O?.[t];if(!k)throw chunkELQQKZN3_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: MAP_INVOKE referenced missing anonymous body index ${t}`,{ref:t});l=k.params,p=k.program;}else if(e===2){let k=Te(x,t,d),v=a.getUserFunction(k);if(!v){n.push(chunkDA7M6H63_cjs.P("UNDEFINED_FUNCTION",`map: undefined function "${k}"`));break}if(v.params.length!==o){n.push(chunkDA7M6H63_cjs.P("FUNCTION_ARITY_MISMATCH",`map: "${k}" expects ${v.params.length} argument(s) but ${o} collection(s) were given`));break}l=v.params,p=v.program;}let b=-1,I=new Array(o),C;for(let k=0;k<o;k++){let v=chunk2VE4OW4A_cjs.ea(i[k],a.getMaxCollectionSize());if(!Array.isArray(v)){C=v;break}if(chunkDA7M6H63_cjs.c(v.length,"collection elements"),b===-1)b=v.length;else if(v.length!==b){C=chunkDA7M6H63_cjs.P("MAP_COLLECTION_LENGTH_MISMATCH",`map: all collections must have the same length (got ${b} and ${v.length}).`);break}I[k]=v;}if(C){n.push(C);break}let R=chunkDA7M6H63_cjs.e(b,"matrix cells"),B;for(let k=0;k<b;k++){let v=new Array(o);for(let ye=0;ye<o;ye++)v[ye]=I[ye][k];let re=e===1?chunkAUOE7MFI_cjs.C[t]?.(v)??chunkDA7M6H63_cjs.P("UNKNOWN_BUILTIN_FUNCTION",`map: unknown builtin function index ${t}`):Qe(l,p,v,a,s,u,m,!!g),nt=chunkDA7M6H63_cjs.Q(re);if(nt){B=nt;break}R[k]=re.type===10||re.type===9?re.value:re.toNumber();}if(B){n.push(B);break}let _=i[0],V=_?.type===7?_.value:void 0;V&&V.rows*V.cols===b?n.push(chunkDA7M6H63_cjs.C(V.rows,V.cols,R)):n.push(chunkDA7M6H63_cjs.C(1,b,R));break}case 160:{let e=U(f,E++,d,"plot body reference"),t=U(f,E++,d,"plot expression"),o=Te(x,t,d),i=c(n).toNumber(),l=c(n).toNumber(),p=O?.[e];if(!p)throw chunkELQQKZN3_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)){n.push(chunkDA7M6H63_cjs.P("PLOT_INVALID_RANGE",`plot: the range bounds must be finite numbers (got ${l} to ${i})`));break}let b=[];for(let _=0;_<Wt;_++){let V=l+_/(Wt-1)*(i-l),k;try{k=Qe(p.params,p.program,[chunkDA7M6H63_cjs.n(V)],a,s,u,m,!!g).toNumber();}catch{continue}Number.isFinite(k)&&b.push([V,k]);}let I=b.map(_=>_[1]),C=I.length?Math.min(...I):0,R=I.length?Math.max(...I):0,B=_=>Number.isInteger(_)?String(_):String(Number(_.toFixed(2)));n.push(chunkDA7M6H63_cjs.I({kind:"plot",points:b,label:`${o} over [${B(l)}, ${B(i)}]`,domain:[l,i],range:[C,R],expr:o}));break}case 158:{let e=U(f,E++,d,"body kind"),t=U(f,E++,d,"body reference"),o=U(f,E++,d,"initial-value flag");Yt(e,t,d);let i=o?c(n):void 0,l=c(n),p=[],b;if(e===0){let _=O?.[t];if(!_)throw chunkELQQKZN3_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: REDUCE_INVOKE referenced missing anonymous body index ${t}`,{ref:t});p=_.params,b=_.program;}else if(e===2){let _=Te(x,t,d),V=a.getUserFunction(_);if(!V){n.push(chunkDA7M6H63_cjs.P("UNDEFINED_FUNCTION",`reduce: undefined function "${_}"`));break}if(V.params.length!==2){n.push(chunkDA7M6H63_cjs.P("FUNCTION_ARITY_MISMATCH",`reduce: "${_}" must take exactly 2 arguments (accumulator, element), got ${V.params.length}`));break}p=V.params,b=V.program;}let I=chunk2VE4OW4A_cjs.ea(l,a.getMaxCollectionSize());if(!Array.isArray(I)){n.push(I);break}chunkDA7M6H63_cjs.c(I.length,"collection elements");let C,R;if(i!==void 0){let _=chunkDA7M6H63_cjs.Q(i);if(_){n.push(_);break}C=i,R=0;}else {if(I.length===0){n.push(chunkDA7M6H63_cjs.P("REDUCE_EMPTY_COLLECTION","reduce: cannot reduce an empty collection without an initial value."));break}C=I[0],R=1;}let B;for(let _=R;_<I.length;_++){let V=[C,I[_]],k=e===1?chunkAUOE7MFI_cjs.C[t]?.(V)??chunkDA7M6H63_cjs.P("UNKNOWN_BUILTIN_FUNCTION",`reduce: unknown builtin function index ${t}`):Qe(p,b,V,a,s,u,m,!!g),v=chunkDA7M6H63_cjs.Q(k);if(v){B=v;break}C=k;}if(B){n.push(B);break}n.push(C);break}case 159:{let e=U(f,E++,d,"body reference"),t=O?.[e];if(!t)throw chunkELQQKZN3_cjs.c.internal("INTERNAL_MISSING_ANONYMOUS_BODY",`Internal error: BIND_UNKNOWN referenced missing anonymous body index ${e}`,{ref:e});n.push(dn(t.params[0],t.program,a,s,u,m,!!g));break}}}let K=c(n);return {type:"value",value:X?chunkDA7M6H63_cjs.k(K):K}}catch(K){return {type:"error",error:chunkELQQKZN3_cjs.d(K)}}finally{chunkDA7M6H63_cjs.b();}}exports.a=vt;exports.b=Rt;exports.c=ia;exports.d=tt;//# sourceMappingURL=chunk-RMCN5WFO.cjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-RMCN5WFO.cjs.map
|