solve-engine 2.24.0 → 2.25.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/dist/{BytecodeBuilder-aqVa7Plx.d.cts → BytecodeBuilder-DSWKZi4f.d.cts} +11 -9
- package/dist/{BytecodeBuilder-aqVa7Plx.d.ts → BytecodeBuilder-DSWKZi4f.d.ts} +11 -9
- package/dist/{EngineError-D1kXsjIj.d.cts → EngineError-fR1K1rvx.d.cts} +2 -0
- package/dist/{EngineError-D1kXsjIj.d.ts → EngineError-fR1K1rvx.d.ts} +2 -0
- package/dist/{Lexer-CqagTewQ.d.ts → Lexer-Bmctxl0n.d.ts} +84 -35
- package/dist/{Lexer-CCHFDcgP.d.cts → Lexer-aB95pjoX.d.cts} +84 -35
- package/dist/{PackageCompatibility-Bq82y0ZN.d.ts → PackageCompatibility-BludTs7v.d.ts} +1 -1
- package/dist/{PackageCompatibility-CeAPVHZr.d.cts → PackageCompatibility-CUVg8tmt.d.cts} +1 -1
- package/dist/{PackageRegistry-CDEgfhT_.d.ts → PackageRegistry-DT-x32OM.d.ts} +54 -6
- package/dist/{PackageRegistry-B9-7fJGH.d.cts → PackageRegistry-Dvn4i2QK.d.cts} +54 -6
- package/dist/{Parselet-4oH5OuRt.d.cts → Parselet-BawfGuTF.d.cts} +7 -1
- package/dist/{Parselet-BwDqKFfK.d.ts → Parselet-DqTbbtWA.d.ts} +7 -1
- package/dist/{ScopeManager-BQBhlDAu.d.ts → ScopeManager-B636am7Y.d.ts} +2 -2
- package/dist/{ScopeManager-DrXB3Nvm.d.cts → ScopeManager-CdwX0VTw.d.cts} +2 -2
- package/dist/{TokenNormalizer-OTPS0Otq.d.ts → TokenNormalizer-CLBtiE8M.d.ts} +45 -26
- package/dist/{TokenNormalizer-MXaKLJ_m.d.cts → TokenNormalizer-CjTDmHgB.d.cts} +45 -26
- package/dist/{VMCheckpoints-BK32PTl2.d.cts → VMCheckpoints-CYqeq8IV.d.cts} +2 -2
- package/dist/{VMCheckpoints-C5jC92o3.d.ts → VMCheckpoints-DDlxNssY.d.ts} +2 -2
- package/dist/{WorkerError-DaNWQFp1.d.cts → WorkerError-B1dF3VYT.d.cts} +1 -1
- package/dist/{WorkerError-CVQbs6_D.d.ts → WorkerError-dneODN-u.d.ts} +1 -1
- package/dist/{chunk-CMZSK6FY.cjs → chunk-4BAUQE6A.cjs} +3 -3
- package/dist/{chunk-CMZSK6FY.cjs.map → chunk-4BAUQE6A.cjs.map} +1 -1
- package/dist/chunk-4BRTUFTH.js +2 -0
- package/dist/chunk-4BRTUFTH.js.map +1 -0
- package/dist/{chunk-UY3ID6JF.cjs → chunk-4NZXCHQL.cjs} +2 -2
- package/dist/chunk-4NZXCHQL.cjs.map +1 -0
- package/dist/chunk-57PSJQQW.js +3 -0
- package/dist/chunk-57PSJQQW.js.map +1 -0
- package/dist/chunk-634ILVMP.cjs +2 -0
- package/dist/{chunk-AUOE7MFI.cjs.map → chunk-634ILVMP.cjs.map} +1 -1
- package/dist/{chunk-3SHWTGTP.js → chunk-63ZOOUOL.js} +2 -2
- package/dist/{chunk-3SHWTGTP.js.map → chunk-63ZOOUOL.js.map} +1 -1
- package/dist/chunk-72PYPENZ.js +2 -0
- package/dist/chunk-72PYPENZ.js.map +1 -0
- package/dist/chunk-77KI7AKJ.cjs +2 -0
- package/dist/chunk-77KI7AKJ.cjs.map +1 -0
- package/dist/chunk-7DP57BA7.js +2 -0
- package/dist/chunk-7DP57BA7.js.map +1 -0
- package/dist/chunk-7N3IJSWF.js +5 -0
- package/dist/chunk-7N3IJSWF.js.map +1 -0
- package/dist/chunk-BMXYR5LI.cjs +2 -0
- package/dist/chunk-BMXYR5LI.cjs.map +1 -0
- package/dist/{chunk-HQ7BKXG7.js → chunk-DUYTXLO2.js} +2 -2
- package/dist/chunk-DUYTXLO2.js.map +1 -0
- package/dist/chunk-EL2XUOWX.js +2 -0
- package/dist/chunk-EL2XUOWX.js.map +1 -0
- package/dist/{chunk-MWWAKZOD.cjs → chunk-FYAMQFZZ.cjs} +3 -3
- package/dist/{chunk-MWWAKZOD.cjs.map → chunk-FYAMQFZZ.cjs.map} +1 -1
- package/dist/chunk-FYTB7SDP.cjs +2 -0
- package/dist/chunk-FYTB7SDP.cjs.map +1 -0
- package/dist/chunk-GBCN7FNV.cjs +2 -0
- package/dist/chunk-GBCN7FNV.cjs.map +1 -0
- package/dist/{chunk-PTQCHMYA.js → chunk-JFZ5SLF7.js} +2 -2
- package/dist/{chunk-PTQCHMYA.js.map → chunk-JFZ5SLF7.js.map} +1 -1
- package/dist/{chunk-RMCN5WFO.cjs → chunk-JSM3O7EM.cjs} +2 -2
- package/dist/{chunk-RMCN5WFO.cjs.map → chunk-JSM3O7EM.cjs.map} +1 -1
- package/dist/chunk-MZMA32NE.js +3 -0
- package/dist/chunk-MZMA32NE.js.map +1 -0
- package/dist/{chunk-D2Q2VFJ6.js → chunk-N4SSR7Q6.js} +2 -2
- package/dist/{chunk-D2Q2VFJ6.js.map → chunk-N4SSR7Q6.js.map} +1 -1
- package/dist/{chunk-RN3ISTM3.cjs → chunk-NEGZZB7F.cjs} +2 -2
- package/dist/{chunk-RN3ISTM3.cjs.map → chunk-NEGZZB7F.cjs.map} +1 -1
- package/dist/{chunk-IPSOWFCA.js → chunk-NMU5E7W7.js} +2 -2
- package/dist/{chunk-IPSOWFCA.js.map → chunk-NMU5E7W7.js.map} +1 -1
- package/dist/chunk-OB2VX4IL.js +2 -0
- package/dist/chunk-OB2VX4IL.js.map +1 -0
- package/dist/{chunk-OMHRBKAT.js → chunk-OONQ3V3I.js} +2 -2
- package/dist/{chunk-OMHRBKAT.js.map → chunk-OONQ3V3I.js.map} +1 -1
- package/dist/{chunk-LTJV3VJE.cjs → chunk-RAPEZR5L.cjs} +2 -2
- package/dist/{chunk-LTJV3VJE.cjs.map → chunk-RAPEZR5L.cjs.map} +1 -1
- package/dist/{chunk-UXR7JIPX.js → chunk-RDYXH7ML.js} +2 -2
- package/dist/{chunk-UXR7JIPX.js.map → chunk-RDYXH7ML.js.map} +1 -1
- package/dist/{chunk-CDNJZBM3.cjs → chunk-SAF3B3AX.cjs} +2 -2
- package/dist/{chunk-CDNJZBM3.cjs.map → chunk-SAF3B3AX.cjs.map} +1 -1
- package/dist/chunk-SPOVFRZO.cjs +5 -0
- package/dist/chunk-SPOVFRZO.cjs.map +1 -0
- package/dist/{chunk-DA7M6H63.cjs → chunk-SQHBOWES.cjs} +2 -2
- package/dist/{chunk-DA7M6H63.cjs.map → chunk-SQHBOWES.cjs.map} +1 -1
- package/dist/{chunk-2BXNZM3G.js → chunk-UF5XMZTT.js} +2 -2
- package/dist/{chunk-2BXNZM3G.js.map → chunk-UF5XMZTT.js.map} +1 -1
- package/dist/chunk-UV3EUIBT.cjs +3 -0
- package/dist/chunk-UV3EUIBT.cjs.map +1 -0
- package/dist/chunk-VMSCRVNX.cjs +2 -0
- package/dist/chunk-VMSCRVNX.cjs.map +1 -0
- package/dist/{chunk-2VE4OW4A.cjs → chunk-WGP4UUO5.cjs} +2 -2
- package/dist/{chunk-2VE4OW4A.cjs.map → chunk-WGP4UUO5.cjs.map} +1 -1
- package/dist/{chunk-F7QIBC4B.cjs → chunk-XBGK3TTU.cjs} +3 -3
- package/dist/{chunk-F7QIBC4B.cjs.map → chunk-XBGK3TTU.cjs.map} +1 -1
- package/dist/{chunk-GP4H5OIT.js → chunk-XHQYHXRE.js} +3 -3
- package/dist/{chunk-GP4H5OIT.js.map → chunk-XHQYHXRE.js.map} +1 -1
- package/dist/{chunk-RE6AIU6Y.js → chunk-XX55RR4Q.js} +3 -3
- package/dist/{chunk-RE6AIU6Y.js.map → chunk-XX55RR4Q.js.map} +1 -1
- package/dist/chunk-YBQPEWT7.cjs +3 -0
- package/dist/chunk-YBQPEWT7.cjs.map +1 -0
- package/dist/{chunk-7EP36NXE.js → chunk-ZDCZ5IDD.js} +3 -3
- package/dist/{chunk-7EP36NXE.js.map → chunk-ZDCZ5IDD.js.map} +1 -1
- package/dist/constants.cjs +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.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +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.cjs.map +1 -1
- package/dist/lexer.d.cts +8 -7
- package/dist/lexer.d.ts +8 -7
- package/dist/lexer.js +1 -1
- package/dist/lexer.js.map +1 -1
- package/dist/normalizer.cjs +1 -1
- package/dist/normalizer.d.cts +2 -2
- package/dist/normalizer.d.ts +2 -2
- 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 +2 -2
- package/dist/parser.d.ts +2 -2
- package/dist/parser.js +1 -1
- package/dist/resolvers.d.cts +1 -1
- package/dist/resolvers.d.ts +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 +5 -5
- package/dist/vm.d.ts +5 -5
- package/dist/vm.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.d.cts +8 -8
- package/dist/worker.d.ts +8 -8
- package/dist/worker.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-2JSNWYYA.cjs +0 -3
- package/dist/chunk-2JSNWYYA.cjs.map +0 -1
- package/dist/chunk-5GL4SAVH.cjs +0 -2
- package/dist/chunk-5GL4SAVH.cjs.map +0 -1
- package/dist/chunk-72N3ZRVE.cjs +0 -2
- package/dist/chunk-72N3ZRVE.cjs.map +0 -1
- package/dist/chunk-A4JV7HRB.js +0 -3
- package/dist/chunk-A4JV7HRB.js.map +0 -1
- package/dist/chunk-AUOE7MFI.cjs +0 -2
- package/dist/chunk-BDF4VCQX.js +0 -3
- package/dist/chunk-BDF4VCQX.js.map +0 -1
- package/dist/chunk-ELQQKZN3.cjs +0 -3
- package/dist/chunk-ELQQKZN3.cjs.map +0 -1
- package/dist/chunk-HQ7BKXG7.js.map +0 -1
- package/dist/chunk-IHAZL4EF.cjs +0 -2
- package/dist/chunk-IHAZL4EF.cjs.map +0 -1
- package/dist/chunk-LM6ZQUEU.js +0 -2
- package/dist/chunk-LM6ZQUEU.js.map +0 -1
- package/dist/chunk-NUF66H57.js +0 -5
- package/dist/chunk-NUF66H57.js.map +0 -1
- package/dist/chunk-PWWQZFAE.js +0 -2
- package/dist/chunk-PWWQZFAE.js.map +0 -1
- package/dist/chunk-RECRD45C.cjs +0 -5
- package/dist/chunk-RECRD45C.cjs.map +0 -1
- package/dist/chunk-RENO2AWO.js +0 -2
- package/dist/chunk-RENO2AWO.js.map +0 -1
- package/dist/chunk-S46R5QZP.cjs +0 -2
- package/dist/chunk-S46R5QZP.cjs.map +0 -1
- package/dist/chunk-UPH22K2T.cjs +0 -2
- package/dist/chunk-UPH22K2T.cjs.map +0 -1
- package/dist/chunk-UY3ID6JF.cjs.map +0 -1
- package/dist/chunk-WFOQRPA6.js +0 -2
- package/dist/chunk-WFOQRPA6.js.map +0 -1
- package/dist/chunk-XFJABR3B.js +0 -2
- package/dist/chunk-XFJABR3B.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { a as PrecedenceParser, b as PrefixParselet, I as InfixParselet } from './Parselet-
|
|
1
|
+
import { a as PrecedenceParser, b as PrefixParselet, I as InfixParselet } from './Parselet-BawfGuTF.cjs';
|
|
2
2
|
import { V as Value, a as ValueType } from './Value-Ds3Gy07C.cjs';
|
|
3
|
-
import { M as MarkdownLineType, L as Lexer, e as TokenCategory, c as LexerVocabulary } from './Lexer-
|
|
3
|
+
import { M as MarkdownLineType, L as Lexer, e as TokenCategory, c as LexerVocabulary } from './Lexer-aB95pjoX.cjs';
|
|
4
4
|
import { IAsyncResolver } from './resolvers.cjs';
|
|
5
|
-
import { T as TokenFusion, c as TokenNormalizer, a as NormalizerRule } from './TokenNormalizer-
|
|
6
|
-
import { D as DependencyGraph, V as VM, a as DagSnapshot, b as EngineContext, S as ScopeManager, P as PluginFunctionHandler } from './ScopeManager-
|
|
7
|
-
import { a as BytecodeProgram } from './BytecodeBuilder-
|
|
5
|
+
import { T as TokenFusion, c as TokenNormalizer, a as NormalizerRule } from './TokenNormalizer-CjTDmHgB.cjs';
|
|
6
|
+
import { D as DependencyGraph, V as VM, a as DagSnapshot, b as EngineContext, S as ScopeManager, P as PluginFunctionHandler } from './ScopeManager-CdwX0VTw.cjs';
|
|
7
|
+
import { a as BytecodeProgram } from './BytecodeBuilder-DSWKZi4f.cjs';
|
|
8
8
|
import { QueryClient } from '@tanstack/query-core';
|
|
9
|
-
import { E as EngineError } from './EngineError-
|
|
9
|
+
import { E as EngineError } from './EngineError-fR1K1rvx.cjs';
|
|
10
10
|
import { a as DiagnosticReportJSON, D as DiagnosticPipeline } from './pipeline-69q2tsLE.cjs';
|
|
11
11
|
import { T as Token } from './Token-CbP_OutD.cjs';
|
|
12
12
|
import { E as EngineConfigOverride, a as EngineConfig } from './Configuration-DnzYPmoK.cjs';
|
|
@@ -1640,6 +1640,13 @@ declare class ExpressionEngine {
|
|
|
1640
1640
|
* every `name(` call word instead of one rule per package.
|
|
1641
1641
|
*/
|
|
1642
1642
|
private callFusions;
|
|
1643
|
+
/**
|
|
1644
|
+
* Which packages claim each call-fusion word, in registration order. The
|
|
1645
|
+
* newest claim is the one {@link callFusions} holds; removing a package
|
|
1646
|
+
* hands the word back to the previous claimant rather than deleting it
|
|
1647
|
+
* for both.
|
|
1648
|
+
*/
|
|
1649
|
+
private callFusionOwners;
|
|
1643
1650
|
/**
|
|
1644
1651
|
* Incremental index behind the package-compatibility check. Kept in step
|
|
1645
1652
|
* with {@link registeredPackages} so each `registerPackage` costs O(that
|
|
@@ -1806,6 +1813,45 @@ declare class ExpressionEngine {
|
|
|
1806
1813
|
/** TanStack Query client, injected into resolvers for cache reads/writes. */
|
|
1807
1814
|
readonly queryClient: QueryClient;
|
|
1808
1815
|
private bytecodeCache;
|
|
1816
|
+
/**
|
|
1817
|
+
* What the front half of the pipeline produced for a cached program: the
|
|
1818
|
+
* normalised tokens the program was compiled from and the reads and
|
|
1819
|
+
* writes extracted from them. Keyed like {@link bytecodeCache} and kept
|
|
1820
|
+
* in step with it (same eviction, same clears), so a hit here means a hit
|
|
1821
|
+
* there.
|
|
1822
|
+
*
|
|
1823
|
+
* A bytecode-cache hit used to pay for the whole front half anyway: the
|
|
1824
|
+
* length check, lexing, normalising, the complexity score, the three
|
|
1825
|
+
* effectful-grammar tries and the reads/writes extraction all ran before
|
|
1826
|
+
* `bytecodeCache.get`, and on a cache-hit evaluation of an ordinary line
|
|
1827
|
+
* lexing and normalising were about two fifths of the cost. Everything
|
|
1828
|
+
* the later stages read from the front half is remembered here instead,
|
|
1829
|
+
* so a hit skips straight to the async preflight and the VM. Entries
|
|
1830
|
+
* restored from a snapshot carry a program but no front half; the first
|
|
1831
|
+
* evaluation after a restore runs the full front half once and fills it.
|
|
1832
|
+
* The memory is a few hundred bytes per cached expression, bounded by the
|
|
1833
|
+
* same `defaultCacheSize` as the programs.
|
|
1834
|
+
*/
|
|
1835
|
+
private compiledFrontHalf;
|
|
1836
|
+
/**
|
|
1837
|
+
* Expressions whose last parse threw, with what the front half produced
|
|
1838
|
+
* for them. A line that does not parse is the ordinary state of a line
|
|
1839
|
+
* being typed, and every re-evaluation of the document lexed, normalised
|
|
1840
|
+
* and re-parsed it, paying for the throw each time. The entry is used
|
|
1841
|
+
* only after the effectful-grammar tries, which still run because they
|
|
1842
|
+
* read the VM (a stored equation, a running total), so nothing that
|
|
1843
|
+
* depends on document state is skipped: only the pure front half and the
|
|
1844
|
+
* parse that is known to fail. The error object is the one first thrown,
|
|
1845
|
+
* so its timestamp is the first failure's. Cleared with the compiled
|
|
1846
|
+
* caches, because the vocabulary and parselet changes that would change
|
|
1847
|
+
* a program can change whether a line parses at all. Bounded by the same
|
|
1848
|
+
* `defaultCacheSize` as the programs.
|
|
1849
|
+
*/
|
|
1850
|
+
private failedParses;
|
|
1851
|
+
/** Whether `expression` can be answered without lexing or normalising: both compiled caches hold it, or its parse is known to fail. */
|
|
1852
|
+
private frontHalfCached;
|
|
1853
|
+
/** Drop every cached program, its front half and every remembered parse failure. Every invalidation goes through here so the three cannot drift. */
|
|
1854
|
+
private clearCompiledCache;
|
|
1809
1855
|
/**
|
|
1810
1856
|
* Insert into the bytecode cache, evicting the oldest entry when full.
|
|
1811
1857
|
*
|
|
@@ -1818,6 +1864,8 @@ declare class ExpressionEngine {
|
|
|
1818
1864
|
* the bytecode-cache benefit on re-evaluation regardless of config.
|
|
1819
1865
|
*/
|
|
1820
1866
|
private cacheBytecode;
|
|
1867
|
+
/** Remember a parse failure, evicting the oldest when full: bounded like the program cache. */
|
|
1868
|
+
private rememberFailedParse;
|
|
1821
1869
|
private pluginFunctionIndexByName;
|
|
1822
1870
|
private builderPool;
|
|
1823
1871
|
private builderPoolIndex;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BytecodeBuilder } from './BytecodeBuilder-
|
|
1
|
+
import { B as BytecodeBuilder } from './BytecodeBuilder-DSWKZi4f.cjs';
|
|
2
2
|
import { T as Token } from './Token-CbP_OutD.cjs';
|
|
3
3
|
import { D as DiagnosticPipeline } from './pipeline-69q2tsLE.cjs';
|
|
4
4
|
|
|
@@ -222,6 +222,8 @@ declare class PrecedenceParser {
|
|
|
222
222
|
* @param _builder - accepted for parselet API compatibility; always uses `this.builder`.
|
|
223
223
|
*/
|
|
224
224
|
parseExpression(minBp?: number, _builder?: BytecodeBuilder): void;
|
|
225
|
+
/** The prefix and infix loop of {@link parseExpression}, run with the depth already counted and the builder in place. */
|
|
226
|
+
private parseExpressionBody;
|
|
225
227
|
/**
|
|
226
228
|
* Parse a prefix token. Built-in tokens (NUMBER, IDENT, LPAREN, etc.) are
|
|
227
229
|
* handled inline with zero registry lookup. Everything else falls through
|
|
@@ -300,6 +302,10 @@ declare class PrecedenceParser {
|
|
|
300
302
|
private consumeParamName;
|
|
301
303
|
private parseUserFunctionDefinition;
|
|
302
304
|
private parseUserFunctionCall;
|
|
305
|
+
/** The source span of `token`: where an editor underlines the error. */
|
|
306
|
+
private spanOf;
|
|
307
|
+
/** An empty span just after the last token: where a line that stops short is pointed at. */
|
|
308
|
+
private spanAtEnd;
|
|
303
309
|
consume(expectedType?: string): Token;
|
|
304
310
|
match(expectedType: string): boolean;
|
|
305
311
|
peek(): Token | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BytecodeBuilder } from './BytecodeBuilder-
|
|
1
|
+
import { B as BytecodeBuilder } from './BytecodeBuilder-DSWKZi4f.js';
|
|
2
2
|
import { T as Token } from './Token-CbP_OutD.js';
|
|
3
3
|
import { D as DiagnosticPipeline } from './pipeline-DTqGLPsV.js';
|
|
4
4
|
|
|
@@ -222,6 +222,8 @@ declare class PrecedenceParser {
|
|
|
222
222
|
* @param _builder - accepted for parselet API compatibility; always uses `this.builder`.
|
|
223
223
|
*/
|
|
224
224
|
parseExpression(minBp?: number, _builder?: BytecodeBuilder): void;
|
|
225
|
+
/** The prefix and infix loop of {@link parseExpression}, run with the depth already counted and the builder in place. */
|
|
226
|
+
private parseExpressionBody;
|
|
225
227
|
/**
|
|
226
228
|
* Parse a prefix token. Built-in tokens (NUMBER, IDENT, LPAREN, etc.) are
|
|
227
229
|
* handled inline with zero registry lookup. Everything else falls through
|
|
@@ -300,6 +302,10 @@ declare class PrecedenceParser {
|
|
|
300
302
|
private consumeParamName;
|
|
301
303
|
private parseUserFunctionDefinition;
|
|
302
304
|
private parseUserFunctionCall;
|
|
305
|
+
/** The source span of `token`: where an editor underlines the error. */
|
|
306
|
+
private spanOf;
|
|
307
|
+
/** An empty span just after the last token: where a line that stops short is pointed at. */
|
|
308
|
+
private spanAtEnd;
|
|
303
309
|
consume(expectedType?: string): Token;
|
|
304
310
|
match(expectedType: string): boolean;
|
|
305
311
|
peek(): Token | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { V as Value } from './Value-Ds3Gy07C.js';
|
|
2
|
-
import { U as UserFunctionDef, A as AnonymousBodyDef, a as BytecodeProgram } from './BytecodeBuilder-
|
|
3
|
-
import { E as EngineError } from './EngineError-
|
|
2
|
+
import { U as UserFunctionDef, A as AnonymousBodyDef, a as BytecodeProgram } from './BytecodeBuilder-DSWKZi4f.js';
|
|
3
|
+
import { E as EngineError } from './EngineError-fR1K1rvx.js';
|
|
4
4
|
import { D as DiagnosticPipeline } from './pipeline-DTqGLPsV.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { V as Value } from './Value-Ds3Gy07C.cjs';
|
|
2
|
-
import { U as UserFunctionDef, A as AnonymousBodyDef, a as BytecodeProgram } from './BytecodeBuilder-
|
|
3
|
-
import { E as EngineError } from './EngineError-
|
|
2
|
+
import { U as UserFunctionDef, A as AnonymousBodyDef, a as BytecodeProgram } from './BytecodeBuilder-DSWKZi4f.cjs';
|
|
3
|
+
import { E as EngineError } from './EngineError-fR1K1rvx.cjs';
|
|
4
4
|
import { D as DiagnosticPipeline } from './pipeline-69q2tsLE.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -320,14 +320,16 @@ interface NormalizerOptions {
|
|
|
320
320
|
*/
|
|
321
321
|
onFusion?: (fusion: TokenFusion) => void;
|
|
322
322
|
/**
|
|
323
|
-
* Try every registered rule at every position, ignoring the shape
|
|
323
|
+
* Try every registered rule at every position, ignoring both the shape
|
|
324
|
+
* index and the first-token buckets the first call uses.
|
|
324
325
|
*
|
|
325
|
-
* Diagnostic only, and much slower. It exists so the
|
|
326
|
-
* compared against the
|
|
327
|
-
*
|
|
326
|
+
* Diagnostic only, and much slower. It exists so the filtered walks can be
|
|
327
|
+
* compared against the exhaustive one over a corpus: each filter is pure,
|
|
328
|
+
* so all of them must agree token for token, and a rule whose declared
|
|
328
329
|
* {@link NormalizerRule.shape} is too narrow shows up as a difference rather
|
|
329
330
|
* than as a feature that quietly stopped working.
|
|
330
|
-
* `NormalizerIndexFidelity.spec`
|
|
331
|
+
* `NormalizerIndexFidelity.spec` and `RuleHintsMatchGuards.spec` are the
|
|
332
|
+
* consumers.
|
|
331
333
|
*
|
|
332
334
|
* @default false
|
|
333
335
|
*/
|
|
@@ -393,13 +395,12 @@ declare class TokenNormalizer {
|
|
|
393
395
|
*/
|
|
394
396
|
private sortedRulesCache;
|
|
395
397
|
/**
|
|
396
|
-
* Per-token-type view of the priority-sorted rules
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
* in the same priority order {@link getSortedRules} produces.
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* identifier. Invalidated alongside {@link sortedRulesCache}.
|
|
398
|
+
* Per-token-type view of the priority-sorted rules, for the one
|
|
399
|
+
* {@link normalize} call that runs before the index exists: for a token
|
|
400
|
+
* type, the rules whose first declared slot admits it (or constrains no
|
|
401
|
+
* type at all), in the same priority order {@link getSortedRules} produces.
|
|
402
|
+
* See {@link rulesForTokenType}. Built once per distinct type and cached,
|
|
403
|
+
* invalidated alongside {@link sortedRulesCache}.
|
|
403
404
|
*/
|
|
404
405
|
private rulesByTokenType;
|
|
405
406
|
/**
|
|
@@ -421,7 +422,10 @@ declare class TokenNormalizer {
|
|
|
421
422
|
* what evaluating a single expression on a fresh engine does, would never
|
|
422
423
|
* reach the payback. Skipping the build on the first call keeps that case at
|
|
423
424
|
* the cost it had before the index existed, and a document reaches line two
|
|
424
|
-
* immediately.
|
|
425
|
+
* immediately. The first call is not unfiltered, though: it reads the same
|
|
426
|
+
* first-slot types the index would, through {@link rulesForTokenType}, so a
|
|
427
|
+
* single expression still skips every rule that could not start at its
|
|
428
|
+
* tokens.
|
|
425
429
|
*/
|
|
426
430
|
private normalizeCalls;
|
|
427
431
|
/**
|
|
@@ -467,12 +471,8 @@ declare class TokenNormalizer {
|
|
|
467
471
|
*/
|
|
468
472
|
private getSortedRules;
|
|
469
473
|
/**
|
|
470
|
-
* The priority-sorted rules
|
|
471
|
-
*
|
|
472
|
-
* A rule that declares a different trigger would have returned null here
|
|
473
|
-
* anyway, so omitting it is behaviour-preserving. Built once per distinct type
|
|
474
|
-
* and cached, which is what turns the per-position rule scan from "try all R
|
|
475
|
-
* rules" into "try only the ones that could fire on this token".
|
|
474
|
+
* The shape index over the priority-sorted rules, built on first use after
|
|
475
|
+
* a mutation and cached. See {@link RuleIndex}.
|
|
476
476
|
*/
|
|
477
477
|
private getRuleIndex;
|
|
478
478
|
/**
|
|
@@ -492,16 +492,35 @@ declare class TokenNormalizer {
|
|
|
492
492
|
* wins on both counts. Worst case is 32 iterations per word of pure integer
|
|
493
493
|
* work.
|
|
494
494
|
*
|
|
495
|
-
* With `null`
|
|
496
|
-
*
|
|
495
|
+
* With `null` there is no index to consult, for one of two reasons: this is
|
|
496
|
+
* the first call, which reads the first-token bucket from
|
|
497
|
+
* {@link rulesForTokenType}, or {@link NormalizerOptions.ignoreRuleIndex} is
|
|
498
|
+
* set, which is the exhaustive scan every filter is measured against. Both
|
|
499
|
+
* hand back a cached list directly, since the caller only reads it.
|
|
497
500
|
*
|
|
498
|
-
*
|
|
499
|
-
* before calling again. Copying the surviving rules out here
|
|
500
|
-
* yielding them lazily is deliberate twice over: it keeps the
|
|
501
|
-
* scratch buffer from being read after the next position
|
|
502
|
-
* it avoids a generator on the hottest loop in the pass.
|
|
501
|
+
* With a mask, returns a buffer reused across positions, so the caller must
|
|
502
|
+
* finish with it before calling again. Copying the surviving rules out here
|
|
503
|
+
* rather than yielding them lazily is deliberate twice over: it keeps the
|
|
504
|
+
* mask's own scratch buffer from being read after the next position
|
|
505
|
+
* overwrites it, and it avoids a generator on the hottest loop in the pass.
|
|
503
506
|
*/
|
|
504
507
|
private rulesAt;
|
|
508
|
+
/**
|
|
509
|
+
* The priority-sorted rules that could start at a token of `type`, for the
|
|
510
|
+
* first {@link normalize} call, which runs before the index is built.
|
|
511
|
+
*
|
|
512
|
+
* The filter is the first slot of each rule's {@link effectiveShape}: a rule
|
|
513
|
+
* naming types there is bucketed under exactly those, and one naming none is
|
|
514
|
+
* in every bucket. That is the same declaration the index reads at its first
|
|
515
|
+
* plane, only without the value axis, so a rule the bucket omits is one the
|
|
516
|
+
* index would omit too, and one that would have returned null here anyway.
|
|
517
|
+
* An earlier version read only the older `startTokenTypes` hint, which most
|
|
518
|
+
* rules had by then replaced with a `shape`, so the first call tried nearly
|
|
519
|
+
* every rule at every position and a fresh engine evaluating one expression
|
|
520
|
+
* paid several times the rule calls of the second line of a document.
|
|
521
|
+
*
|
|
522
|
+
* Built once per distinct type and cached until the rule set changes.
|
|
523
|
+
*/
|
|
505
524
|
private rulesForTokenType;
|
|
506
525
|
/**
|
|
507
526
|
* Get the number of currently registered rules (excludes phrase trie entries).
|
|
@@ -320,14 +320,16 @@ interface NormalizerOptions {
|
|
|
320
320
|
*/
|
|
321
321
|
onFusion?: (fusion: TokenFusion) => void;
|
|
322
322
|
/**
|
|
323
|
-
* Try every registered rule at every position, ignoring the shape
|
|
323
|
+
* Try every registered rule at every position, ignoring both the shape
|
|
324
|
+
* index and the first-token buckets the first call uses.
|
|
324
325
|
*
|
|
325
|
-
* Diagnostic only, and much slower. It exists so the
|
|
326
|
-
* compared against the
|
|
327
|
-
*
|
|
326
|
+
* Diagnostic only, and much slower. It exists so the filtered walks can be
|
|
327
|
+
* compared against the exhaustive one over a corpus: each filter is pure,
|
|
328
|
+
* so all of them must agree token for token, and a rule whose declared
|
|
328
329
|
* {@link NormalizerRule.shape} is too narrow shows up as a difference rather
|
|
329
330
|
* than as a feature that quietly stopped working.
|
|
330
|
-
* `NormalizerIndexFidelity.spec`
|
|
331
|
+
* `NormalizerIndexFidelity.spec` and `RuleHintsMatchGuards.spec` are the
|
|
332
|
+
* consumers.
|
|
331
333
|
*
|
|
332
334
|
* @default false
|
|
333
335
|
*/
|
|
@@ -393,13 +395,12 @@ declare class TokenNormalizer {
|
|
|
393
395
|
*/
|
|
394
396
|
private sortedRulesCache;
|
|
395
397
|
/**
|
|
396
|
-
* Per-token-type view of the priority-sorted rules
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
* in the same priority order {@link getSortedRules} produces.
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* identifier. Invalidated alongside {@link sortedRulesCache}.
|
|
398
|
+
* Per-token-type view of the priority-sorted rules, for the one
|
|
399
|
+
* {@link normalize} call that runs before the index exists: for a token
|
|
400
|
+
* type, the rules whose first declared slot admits it (or constrains no
|
|
401
|
+
* type at all), in the same priority order {@link getSortedRules} produces.
|
|
402
|
+
* See {@link rulesForTokenType}. Built once per distinct type and cached,
|
|
403
|
+
* invalidated alongside {@link sortedRulesCache}.
|
|
403
404
|
*/
|
|
404
405
|
private rulesByTokenType;
|
|
405
406
|
/**
|
|
@@ -421,7 +422,10 @@ declare class TokenNormalizer {
|
|
|
421
422
|
* what evaluating a single expression on a fresh engine does, would never
|
|
422
423
|
* reach the payback. Skipping the build on the first call keeps that case at
|
|
423
424
|
* the cost it had before the index existed, and a document reaches line two
|
|
424
|
-
* immediately.
|
|
425
|
+
* immediately. The first call is not unfiltered, though: it reads the same
|
|
426
|
+
* first-slot types the index would, through {@link rulesForTokenType}, so a
|
|
427
|
+
* single expression still skips every rule that could not start at its
|
|
428
|
+
* tokens.
|
|
425
429
|
*/
|
|
426
430
|
private normalizeCalls;
|
|
427
431
|
/**
|
|
@@ -467,12 +471,8 @@ declare class TokenNormalizer {
|
|
|
467
471
|
*/
|
|
468
472
|
private getSortedRules;
|
|
469
473
|
/**
|
|
470
|
-
* The priority-sorted rules
|
|
471
|
-
*
|
|
472
|
-
* A rule that declares a different trigger would have returned null here
|
|
473
|
-
* anyway, so omitting it is behaviour-preserving. Built once per distinct type
|
|
474
|
-
* and cached, which is what turns the per-position rule scan from "try all R
|
|
475
|
-
* rules" into "try only the ones that could fire on this token".
|
|
474
|
+
* The shape index over the priority-sorted rules, built on first use after
|
|
475
|
+
* a mutation and cached. See {@link RuleIndex}.
|
|
476
476
|
*/
|
|
477
477
|
private getRuleIndex;
|
|
478
478
|
/**
|
|
@@ -492,16 +492,35 @@ declare class TokenNormalizer {
|
|
|
492
492
|
* wins on both counts. Worst case is 32 iterations per word of pure integer
|
|
493
493
|
* work.
|
|
494
494
|
*
|
|
495
|
-
* With `null`
|
|
496
|
-
*
|
|
495
|
+
* With `null` there is no index to consult, for one of two reasons: this is
|
|
496
|
+
* the first call, which reads the first-token bucket from
|
|
497
|
+
* {@link rulesForTokenType}, or {@link NormalizerOptions.ignoreRuleIndex} is
|
|
498
|
+
* set, which is the exhaustive scan every filter is measured against. Both
|
|
499
|
+
* hand back a cached list directly, since the caller only reads it.
|
|
497
500
|
*
|
|
498
|
-
*
|
|
499
|
-
* before calling again. Copying the surviving rules out here
|
|
500
|
-
* yielding them lazily is deliberate twice over: it keeps the
|
|
501
|
-
* scratch buffer from being read after the next position
|
|
502
|
-
* it avoids a generator on the hottest loop in the pass.
|
|
501
|
+
* With a mask, returns a buffer reused across positions, so the caller must
|
|
502
|
+
* finish with it before calling again. Copying the surviving rules out here
|
|
503
|
+
* rather than yielding them lazily is deliberate twice over: it keeps the
|
|
504
|
+
* mask's own scratch buffer from being read after the next position
|
|
505
|
+
* overwrites it, and it avoids a generator on the hottest loop in the pass.
|
|
503
506
|
*/
|
|
504
507
|
private rulesAt;
|
|
508
|
+
/**
|
|
509
|
+
* The priority-sorted rules that could start at a token of `type`, for the
|
|
510
|
+
* first {@link normalize} call, which runs before the index is built.
|
|
511
|
+
*
|
|
512
|
+
* The filter is the first slot of each rule's {@link effectiveShape}: a rule
|
|
513
|
+
* naming types there is bucketed under exactly those, and one naming none is
|
|
514
|
+
* in every bucket. That is the same declaration the index reads at its first
|
|
515
|
+
* plane, only without the value axis, so a rule the bucket omits is one the
|
|
516
|
+
* index would omit too, and one that would have returned null here anyway.
|
|
517
|
+
* An earlier version read only the older `startTokenTypes` hint, which most
|
|
518
|
+
* rules had by then replaced with a `shape`, so the first call tried nearly
|
|
519
|
+
* every rule at every position and a fresh engine evaluating one expression
|
|
520
|
+
* paid several times the rule calls of the second line of a document.
|
|
521
|
+
*
|
|
522
|
+
* Built once per distinct type and cached until the rule set changes.
|
|
523
|
+
*/
|
|
505
524
|
private rulesForTokenType;
|
|
506
525
|
/**
|
|
507
526
|
* Get the number of currently registered rules (excludes phrase trie entries).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { V as Value } from './Value-Ds3Gy07C.cjs';
|
|
2
|
-
import { V as VM } from './ScopeManager-
|
|
3
|
-
import { U as UserFunctionDef } from './BytecodeBuilder-
|
|
2
|
+
import { V as VM } from './ScopeManager-CdwX0VTw.cjs';
|
|
3
|
+
import { U as UserFunctionDef } from './BytecodeBuilder-DSWKZi4f.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A point-in-time snapshot of VM variable state.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { V as Value } from './Value-Ds3Gy07C.js';
|
|
2
|
-
import { V as VM } from './ScopeManager-
|
|
3
|
-
import { U as UserFunctionDef } from './BytecodeBuilder-
|
|
2
|
+
import { V as VM } from './ScopeManager-B636am7Y.js';
|
|
3
|
+
import { U as UserFunctionDef } from './BytecodeBuilder-DSWKZi4f.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A point-in-time snapshot of VM variable state.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as ErrorCategory, S as SourceSpan, E as EngineError } from './EngineError-
|
|
1
|
+
import { c as ErrorCategory, S as SourceSpan, E as EngineError } from './EngineError-fR1K1rvx.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Structured errors for the off-main-thread worker harness, and the pair of
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as ErrorCategory, S as SourceSpan, E as EngineError } from './EngineError-
|
|
1
|
+
import { c as ErrorCategory, S as SourceSpan, E as EngineError } from './EngineError-fR1K1rvx.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Structured errors for the off-main-thread worker harness, and the pair of
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var chunkEFJCC6FJ_cjs=require('./chunk-EFJCC6FJ.cjs'),
|
|
2
|
-
`),r=new Array(n.length);for(let s=0;s<n.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:chunkEFJCC6FJ_cjs.a(n[s]),text:n[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:n[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let t=[],n=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a=[];for(let o of s.insertLines){let c=this.nextLineId++;a.push(c),t.push(c),this.lines.set(c,{lineId:c,textHash:chunkEFJCC6FJ_cjs.a(o),text:o,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:o.trim().length===0,inlineSolveCount:0});}for(let o of a)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a);for(let o of l)n.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:t,removed:n}}insertLines(e,t){let n={startLine:e,deleteCount:0,insertLines:t};return this.applyChanges([n]).inserted}deleteLines(e,t){let n={startLine:e,deleteCount:t-e+1,insertLines:[]};return this.applyChanges([n]).removed}editLine(e,t){let n=this.getLineAt(e);if(!n)return false;let r=chunkEFJCC6FJ_cjs.a(t);return r===n.textHash?false:(n.text=t,n.textHash=r,n.expressions=[],n.bytecodes=[],n.results=[],n.result=null,n.inlineSolveCount=0,n.dirty=true,this.dirtyLineIds.add(n.lineId),n.isEmpty=t.trim().length===0,true)}getLineAt(e){let t=e-1,n=this.orderTree.getAt(t);if(n!==void 0)return this.lines.get(n)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let t=1;for(let n of this.orderTree)this._positionCache.set(n,t++);return this._positionCache.get(e)??-1}getVisibleLines(e,t){let n=this.orderTree.getRange(e-1,t-1),r=[];for(let s of n){let i=this.lines.get(s);i&&r.push(i);}return r}getAllLines(){return this.getVisibleLines(1,this.lineCount)}getLineById(e){return this.lines.get(e)}getDirtyLines(){let e=[];for(let t of this.lines.values())t.dirty&&e.push(t);return e}hasAnyDirtyLineBefore(e){for(let t of this.dirtyLineIds){let n=this.getLinePosition(t);if(n>=1&&n<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let t of this.dirtyLineIds){let n=this.lines.get(t);if(!n||!n.isVariableDef)continue;let r=this.getLinePosition(t);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,t){let n=this.lines.get(e);return n!==void 0&&n.textHash===t}markClean(e){let t=this.lines.get(e);t&&(t.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let t=this.getLineAt(e);t&&(t.dirty=true,this.dirtyLineIds.add(t.lineId));}markDirty(e){let t=this.lines.get(e);t&&(t.dirty=true,this.dirtyLineIds.add(e));}invalidateAll(){for(let e of this.lines.values())e.dirty=true;this.dirtyLineIds=new Set(this.lines.keys());}updateLineResult(e,t,n,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=t,o.result=t[0]?.[0]??null,o.bytecodes=n,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=t,l.bytecodes=n,l.reads=r,l.writes=s,l.isVariableDef=i,l.inlineSolveCount=a);}get lineCount(){return this.orderTree.length}get isEmpty(){return this.orderTree.isEmpty}*[Symbol.iterator](){for(let e of this.orderTree){let t=this.lines.get(e);t&&(yield t);}}clear(){this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.nextLineId=1;}toJSON(){return {lineCount:this.lineCount,lines:this.getAllLines().map(e=>({lineId:e.lineId,text:e.text.substring(0,80),textHash:e.textHash,dirty:e.dirty,isVariableDef:e.isVariableDef,isEmpty:e.isEmpty,hasBytecode:e.bytecodes.length>0,hasResult:e.results.length>0,inlineSolveCount:e.inlineSolveCount,reads:e.reads,writes:e.writes}))}}};var A=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){return this.worker?this.worker:(this.worker=chunkRECRD45C_cjs.g(),this.worker.onmessage=e=>{let t=e.data;if(!t||t.type!=="COMPILE_RESULT")return;let n=this.pending.get(t.id);if(!n)return;this.pending.delete(t.id);let r=[];for(let s of t.results)r.push(this.reconstructResult(s));n.resolve(r);},this.worker.onerror=e=>{for(let[t,n]of this.pending)n.reject(new Error(`Compilation worker error: ${e.message}`)),this.pending.delete(t);},this.worker)}async compileBatch(e){if(e.length===0)return [];let t=this.ensureWorker(),n=this.nextId++;return new Promise((r,s)=>{this.pending.set(n,{resolve:r,reject:s}),t.postMessage({type:"COMPILE_BATCH",id:n,items:e});})}storeResults(e,t){let n=new Map;for(let i of e){if(i.error)continue;let a=t.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=n.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},n.set(i.lineId,l)),l.bytecodes.push(i.program);for(let o of i.reads)l.reads.add(o);for(let o of i.writes)l.writes.add(o);i.isVariableDef&&(l.isVariableDef=true);}let s=0;for(let[i,a]of n){if(a.bytecodes.length===0)continue;let o=t.getLineById(i)?.inlineSolveCount??0;t.updateLineCompiled(i,a.expressions,a.bytecodes,[...a.reads],[...a.writes],a.isVariableDef,o),s+=a.bytecodes.length;}return s}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.pending.clear());}get isActive(){return this.worker!==null}reconstructResult(e){if(e.error)return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:{opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false},reads:[],writes:[],isVariableDef:false,error:e.error};let t=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),n=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:t,numbers:n,strings:e.strings,hasAsync:false};return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:r,reads:e.reads,writes:e.writes,isVariableDef:e.isVariableDef,error:null}}};var U=128,k=3,Z=6,Q=2,X=k,H=class u{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/U)}static pageRange(e,t){return {startLine:e*U+1,endLine:Math.min((e+1)*U,t)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,t){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let n=t.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(n),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-Z),c=Math.min(i,s+Z);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,t,n);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,t,n);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(t.lineCount),l=[];if(n==="down"){let o=s+k+1,c=Math.min(o+Q-1,a);for(let d=o;d<=c&&d<=a;d++)l.push(d);}else {let o=i-k-1;for(let c=o;c>o-Q&&c>=0;c--)l.push(c);}for(let o of l){let c=u.pageRange(o,t.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=t.getLineAt(d);if(p&&p.dirty&&!(p.bytecodes.length>0&&!p.isVariableDef)&&!p.isEmpty)if(p.expressions.length>0)for(let f of p.expressions)f.trim()&&r.push({lineId:p.lineId,expression:f,textHash:p.textHash});else {let f=chunkIHAZL4EF_cjs.c.findInlineSolves(p.text);if(f.length>0)for(let g of f)g.expression.trim()&&r.push({lineId:p.lineId,expression:g.expression,textHash:p.textHash});else {let g=p.text.trim();g&&r.push({lineId:p.lineId,expression:g,textHash:p.textHash});}}}}return r}clear(){this.pageAccess.clear(),this.accessSeq=0,this.lastViewportStart=null,this.savedDirection=null;}touchPage(e){this.pageAccess.set(e,++this.accessSeq);}evictPageResults(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,t.markDirty(i.lineId));}}};var Y=(r=>(r[r.Tier1=1]="Tier1",r[r.Tier2=2]="Tier2",r[r.Tier3=3]="Tier3",r[r.Skipped=0]="Skipped",r))(Y||{}),w=class{constructor(e,t,n){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=chunkAUOE7MFI_cjs.J.subscribe(r=>{for(let s of this.dag.getAffectedLines(chunkAUOE7MFI_cjs.K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),chunkDA7M6H63_cjs.h();try{this.reseedAccumulators();let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(e.endLine,i);for(let l=1;l<=a;l++){let o=this.doc.getLineAt(l);if(!o){s.skipped++;continue}let c=l>=e.startLine&&l<=e.endLine,d=this.evaluateSingleLine(o,l,c);n.push(d),d.tier===1?s.tier1++:d.tier===2?s.tier2++:d.tier===3?s.tier3++:s.skipped++,d.results&&c&&r.set(l,d.results.flat());}return this.pageManager.maintainAfterEval(e,this.doc),{lines:n,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),chunkDA7M6H63_cjs.i();}}backgroundCompile(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef)continue;let a=this.evaluateSingleLine(i,s,false);t.push(a);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let t={startLine:1,endLine:this.doc.lineCount};return this.evaluate(t,e)}setViewport(e,t){if(this.engine.setKeystrokeSignal(t??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,t);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),chunkDA7M6H63_cjs.h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),chunkDA7M6H63_cjs.i();}}applyTransaction(e){let t=new Set;for(let s of e)for(let i=0;i<s.deleteCount;i++){let a=s.startLine+i,l=this.dag.getWrites(a);for(let o of l)t.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let n=new Set;for(let s of t){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&n.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of n)this.doc.markDirty(s);return this.dag.clear(),{inserted:r.inserted,removed:r.removed}}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let r=this.dag.getWrites(n);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(n);break}}}}collectEvalResults(e,t){let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(t,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);n.push(c),c.tier===1?s.tier1++:c.tier===2?s.tier2++:c.tier===3?s.tier3++:s.skipped++,c.results&&r.set(l,c.results.flat());}return {lines:n,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,t,n){let r={lineId:e.lineId,lineNumber:t};if(e.isEmpty||chunkRECRD45C_cjs.l(e.text))return e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null};let{expressions:s,inlineSolveCount:i}=this.extractExpressions(e);return s.length===0?(e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null}):e.dirty?n?this.evaluateTier1(e,t,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,t,s,i,r):n&&e.bytecodes.length>0?this.evaluateTier2(e,t,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,t,n,r,s){let i=[],a=[],l=new Set,o=new Set,c=false,d=null,p=null,f=false,g=false;for(let y of n){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(t,y);b=[m],d=m,L=this.engine.getLineCache().get(t,y);}catch(m){let x=m instanceof Error?m.message:String(m);p||(p=x),f=true,b=null;}if(b&&b.some(m=>m.type===12)&&(g=true),b?i.push(b):i.push([chunkDA7M6H63_cjs.P("eval_failed",p??"unknown error")]),L){a.push(L.bytecode);for(let m of L.readVariables)l.add(m);L.writeVariable&&(o.add(L.writeVariable),c=true);}else try{let{program:m,reads:x,writes:E}=this.engine.compileExpression(y);a.push(m);for(let S of x)l.add(S);for(let S of E)o.add(S);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof chunkELQQKZN3_cjs.b&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let S of x)l.add(S);if(Array.isArray(E))for(let S of E)o.add(S);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,n,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=n):this.doc.updateLineResult(e.lineId,i,a,n,h,v,c,r),this.dag.registerLine(t,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(t,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,t,n){if(e.bytecodes.length===0)return {...n,tier:0,result:null,error:null};let r=[],s=null,i=null,a=false;for(let l of e.bytecodes)if(l.opcodes.length!==0)try{let o=this.engine.executeCached(l,t);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([chunkDA7M6H63_cjs.P("exec_failed",c)]);}return this.dag.registerLine(t,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...n,tier:2,result:s,results:r,error:i}}evaluateTier3(e,t,n,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of n)if(v.trim())try{let{program:y,reads:b,writes:L}=this.engine.compileExpression(v);i.push(y);for(let m of b)a.add(m);for(let m of L)l.add(m);L.length>0&&(o=!0),L.length>0&&y.opcodes.length>0&&(c=this.engine.executeCached(y,t),c&&c.type===12&&(f=!0));}catch(y){let b=y instanceof Error?y.message:String(y);d||(d=b),p=true,i.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false});}let g=[...a],h=[...l];return this.doc.updateLineCompiled(e.lineId,n,i,g,h,o,r),this.dag.registerLine(t,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(t,e.lineId,h)),{...s,tier:3,result:c,results:o&&c&&!p&&!f?[[c]]:void 0,error:d}}restoreTo(e){this.checkpointer&&this.checkpointer.restoreTo(e);}getCheckpointer(){return this.checkpointer}getPageManager(){return this.pageManager}preloadNextPages(e){let t=this.pageManager.getPreloadTargets(e,this.doc);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||chunkRECRD45C_cjs.l(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&t.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return t}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let t=e.text.trim();if(t.length===0)return {expressions:[],inlineSolveCount:0};let n=chunkIHAZL4EF_cjs.c.findInlineSolves(e.text);return n.length>0?{expressions:n.map(r=>r.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,t={inputType:"markdown"}){let n=u.getDocumentModel(),r=new R;r.setDocument(e);let s=new w(r,u);try{let i=r.lineCount;s.evaluate({startLine:1,endLine:i});let a=[],l=[],o=0;for(let c=1;c<=i;c++){let d=r.getLineAt(c),p=d.text,f=o,g=o+p.length;o=g+1;let h=d.inlineSolveCount>0,v=[],y=null,b=null;d.isEmpty||(h?v=chunkRECRD45C_cjs.m(p,c).map((L,m)=>{let x=d.results[m]?.[0]??null;if(x&&x.type===13){let E=ee(x);return l.push(`Line ${c}: ${E}`),{...L,result:null,error:E}}return {...L,result:x,error:null}}):(y=d.expressions[0]??null,b=d.result??null,b&&b.type===13&&l.push(`Line ${c}: ${ee(b)}`))),a.push({lineNumber:c,text:p,startPosition:f,endPosition:g,isEmpty:d.isEmpty,hasInlineSolves:h,inlineSolves:v,expression:y,error:null,result:b});}return {lines:a,totalLines:i,errors:l}}finally{s.terminateWorker(),u.setDocumentModel(n);}}exports.a=R;exports.b=Y;exports.c=w;exports.d=ie;//# sourceMappingURL=chunk-CMZSK6FY.cjs.map
|
|
3
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
'use strict';var chunkEFJCC6FJ_cjs=require('./chunk-EFJCC6FJ.cjs'),chunkSPOVFRZO_cjs=require('./chunk-SPOVFRZO.cjs'),chunkUURM7P3P_cjs=require('./chunk-UURM7P3P.cjs'),chunk634ILVMP_cjs=require('./chunk-634ILVMP.cjs'),chunkSQHBOWES_cjs=require('./chunk-SQHBOWES.cjs'),chunk4NZXCHQL_cjs=require('./chunk-4NZXCHQL.cjs'),chunkBMXYR5LI_cjs=require('./chunk-BMXYR5LI.cjs'),chunkYBQPEWT7_cjs=require('./chunk-YBQPEWT7.cjs');var P=class{constructor(){this.root=null;}get length(){return this.root?this.root.size:0}get isEmpty(){return this.root===null}getAt(e){if(!(e<0||e>=(this.root?.size??0)))return this.nodeAt(this.root,e).lineId}insertAt(e,t){let[n,r]=I(this.root,e);this.root=C(C(n,te(t)),r);}deleteAt(e){if(e<0||e>=(this.root?.size??0))return;let[t,n]=I(this.root,e),[r,s]=I(n,1),i=r?r.lineId:void 0;return this.root=C(t,s),i}spliceAt(e,t,n){let r=Math.max(0,e),s=Math.min(Math.max(0,t),(this.root?.size??0)-r),[i,a]=I(this.root,r),[l,o]=I(a,s),c=ne(l),d=B(n,0,n.length);return this.root=C(C(i,d),o),c}replaceAll(e){this.root=B(e,0,e.length);}getRange(e,t){let n=Math.max(0,e),r=Math.min((this.root?.size??0)-1,t);if(n>r)return [];let s=[];return this.collectRange(this.root,n,r,0,s),s}clear(){this.root=null;}*[Symbol.iterator](){yield*this.inOrder(this.root);}*inOrder(e){e&&(yield*this.inOrder(e.left),yield e.lineId,yield*this.inOrder(e.right));}nodeAt(e,t){let n=e.left?e.left.size:0;return t<n?this.nodeAt(e.left,t):t===n?e:this.nodeAt(e.right,t-n-1)}collectRange(e,t,n,r,s){if(!e)return;let i=e.left?e.left.size:0,a=r+i;a>t&&e.left&&this.collectRange(e.left,t,n,r,s),a>=t&&a<=n&&s.push(e.lineId),a<n&&e.right&&this.collectRange(e.right,t,n,a+1,s);}};function te(u){return {lineId:u,size:1,priority:Math.random(),left:null,right:null}}function T(u){u.size=1+(u.left?u.left.size:0)+(u.right?u.right.size:0);}function C(u,e){return u?e?u.priority>e.priority?(u.right=C(u.right,e),T(u),u):(e.left=C(u,e.left),T(e),e):u:e}function I(u,e){if(!u)return [null,null];let t=u.left?u.left.size:0;if(e<=t){let[n,r]=I(u.left,e);return u.left=r,T(u),[n,u]}else {let[n,r]=I(u.right,e-t-1);return u.right=n,T(u),[u,r]}}function ne(u){let e=[];return F(u,e),e}function F(u,e){u&&(F(u.left,e),e.push(u.lineId),F(u.right,e));}function B(u,e,t){if(e>=t)return null;let n=Math.floor((e+t)/2),r=re(n);return {lineId:u[n],size:t-e,priority:r,left:B(u,e,n),right:B(u,n+1,t)}}function re(u){let e=u;return e=(e>>16^e)*73244475,e=(e>>16^e)*73244475,e=e>>16^e,e/4294967295}var R=class{constructor(e=chunk4NZXCHQL_cjs.b.performance.maxDocumentLines){this.lines=new Map;this.orderTree=new P;this.nextLineId=1;this._positionCache=null;this.dirtyLineIds=new Set;this.maxLines=e;}setDocument(e){if(chunkUURM7P3P_cjs.b(e,this.maxLines)>this.maxLines)throw chunkYBQPEWT7_cjs.c.execution("DOCUMENT_TOO_LARGE",`This document has more than ${this.maxLines.toLocaleString("en-US")} lines, which is the most the engine will hold at once`,{maxLines:this.maxLines});this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.dirtyLineIds.clear(),this.nextLineId=1;let n=e.split(`
|
|
2
|
+
`),r=new Array(n.length);for(let s=0;s<n.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:chunkEFJCC6FJ_cjs.a(n[s]),text:n[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:n[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let t=[],n=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a=[];for(let o of s.insertLines){let c=this.nextLineId++;a.push(c),t.push(c),this.lines.set(c,{lineId:c,textHash:chunkEFJCC6FJ_cjs.a(o),text:o,expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:o.trim().length===0,inlineSolveCount:0});}for(let o of a)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a);for(let o of l)n.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:t,removed:n}}insertLines(e,t){let n={startLine:e,deleteCount:0,insertLines:t};return this.applyChanges([n]).inserted}deleteLines(e,t){let n={startLine:e,deleteCount:t-e+1,insertLines:[]};return this.applyChanges([n]).removed}editLine(e,t){let n=this.getLineAt(e);if(!n)return false;let r=chunkEFJCC6FJ_cjs.a(t);return r===n.textHash?false:(n.text=t,n.textHash=r,n.expressions=[],n.bytecodes=[],n.results=[],n.result=null,n.inlineSolveCount=0,n.dirty=true,this.dirtyLineIds.add(n.lineId),n.isEmpty=t.trim().length===0,true)}getLineAt(e){let t=e-1,n=this.orderTree.getAt(t);if(n!==void 0)return this.lines.get(n)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let t=1;for(let n of this.orderTree)this._positionCache.set(n,t++);return this._positionCache.get(e)??-1}getVisibleLines(e,t){let n=this.orderTree.getRange(e-1,t-1),r=[];for(let s of n){let i=this.lines.get(s);i&&r.push(i);}return r}getAllLines(){return this.getVisibleLines(1,this.lineCount)}getLineById(e){return this.lines.get(e)}getDirtyLines(){let e=[];for(let t of this.lines.values())t.dirty&&e.push(t);return e}hasAnyDirtyLineBefore(e){for(let t of this.dirtyLineIds){let n=this.getLinePosition(t);if(n>=1&&n<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let t of this.dirtyLineIds){let n=this.lines.get(t);if(!n||!n.isVariableDef)continue;let r=this.getLinePosition(t);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,t){let n=this.lines.get(e);return n!==void 0&&n.textHash===t}markClean(e){let t=this.lines.get(e);t&&(t.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let t=this.getLineAt(e);t&&(t.dirty=true,this.dirtyLineIds.add(t.lineId));}markDirty(e){let t=this.lines.get(e);t&&(t.dirty=true,this.dirtyLineIds.add(e));}invalidateAll(){for(let e of this.lines.values())e.dirty=true;this.dirtyLineIds=new Set(this.lines.keys());}updateLineResult(e,t,n,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=t,o.result=t[0]?.[0]??null,o.bytecodes=n,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,t,n,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=t,l.bytecodes=n,l.reads=r,l.writes=s,l.isVariableDef=i,l.inlineSolveCount=a);}get lineCount(){return this.orderTree.length}get isEmpty(){return this.orderTree.isEmpty}*[Symbol.iterator](){for(let e of this.orderTree){let t=this.lines.get(e);t&&(yield t);}}clear(){this.lines.clear(),this.orderTree.clear(),this._positionCache=null,this.nextLineId=1;}toJSON(){return {lineCount:this.lineCount,lines:this.getAllLines().map(e=>({lineId:e.lineId,text:e.text.substring(0,80),textHash:e.textHash,dirty:e.dirty,isVariableDef:e.isVariableDef,isEmpty:e.isEmpty,hasBytecode:e.bytecodes.length>0,hasResult:e.results.length>0,inlineSolveCount:e.inlineSolveCount,reads:e.reads,writes:e.writes}))}}};var A=class{constructor(){this.worker=null;this.nextId=1;this.pending=new Map;}ensureWorker(){return this.worker?this.worker:(this.worker=chunkSPOVFRZO_cjs.g(),this.worker.onmessage=e=>{let t=e.data;if(!t||t.type!=="COMPILE_RESULT")return;let n=this.pending.get(t.id);if(!n)return;this.pending.delete(t.id);let r=[];for(let s of t.results)r.push(this.reconstructResult(s));n.resolve(r);},this.worker.onerror=e=>{for(let[t,n]of this.pending)n.reject(new Error(`Compilation worker error: ${e.message}`)),this.pending.delete(t);},this.worker)}async compileBatch(e){if(e.length===0)return [];let t=this.ensureWorker(),n=this.nextId++;return new Promise((r,s)=>{this.pending.set(n,{resolve:r,reject:s}),t.postMessage({type:"COMPILE_BATCH",id:n,items:e});})}storeResults(e,t){let n=new Map;for(let i of e){if(i.error)continue;let a=t.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=n.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},n.set(i.lineId,l)),l.bytecodes.push(i.program);for(let o of i.reads)l.reads.add(o);for(let o of i.writes)l.writes.add(o);i.isVariableDef&&(l.isVariableDef=true);}let s=0;for(let[i,a]of n){if(a.bytecodes.length===0)continue;let o=t.getLineById(i)?.inlineSolveCount??0;t.updateLineCompiled(i,a.expressions,a.bytecodes,[...a.reads],[...a.writes],a.isVariableDef,o),s+=a.bytecodes.length;}return s}terminate(){this.worker&&(this.worker.terminate(),this.worker=null,this.pending.clear());}get isActive(){return this.worker!==null}reconstructResult(e){if(e.error)return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:{opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false},reads:[],writes:[],isVariableDef:false,error:e.error};let t=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),n=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:t,numbers:n,strings:e.strings,hasAsync:false};return {lineId:e.lineId,compiledAgainstHash:e.compiledAgainstHash,program:r,reads:e.reads,writes:e.writes,isVariableDef:e.isVariableDef,error:null}}};var U=128,k=3,Z=6,Q=2,X=k,H=class u{constructor(){this.lastViewportStart=null;this.savedDirection=null;this.pageAccess=new Map;this.accessSeq=0;}static pageForLine(e){return Math.floor((e-1)/U)}static pageRange(e,t){return {startLine:e*U+1,endLine:Math.min((e+1)*U,t)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,t){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let n=t.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(n),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-Z),c=Math.min(i,s+Z);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,t,n);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,t,n);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,t,n);}getPreloadTargets(e,t){let n=this.savedDirection;if(!n)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(t.lineCount),l=[];if(n==="down"){let o=s+k+1,c=Math.min(o+Q-1,a);for(let d=o;d<=c&&d<=a;d++)l.push(d);}else {let o=i-k-1;for(let c=o;c>o-Q&&c>=0;c--)l.push(c);}for(let o of l){let c=u.pageRange(o,t.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=t.getLineAt(d);if(p&&p.dirty&&!(p.bytecodes.length>0&&!p.isVariableDef)&&!p.isEmpty)if(p.expressions.length>0)for(let f of p.expressions)f.trim()&&r.push({lineId:p.lineId,expression:f,textHash:p.textHash});else {let f=chunkBMXYR5LI_cjs.c.findInlineSolves(p.text);if(f.length>0)for(let g of f)g.expression.trim()&&r.push({lineId:p.lineId,expression:g.expression,textHash:p.textHash});else {let g=p.text.trim();g&&r.push({lineId:p.lineId,expression:g,textHash:p.textHash});}}}}return r}clear(){this.pageAccess.clear(),this.accessSeq=0,this.lastViewportStart=null,this.savedDirection=null;}touchPage(e){this.pageAccess.set(e,++this.accessSeq);}evictPageResults(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,t,n){let r=u.pageRange(e,n);for(let s=r.startLine;s<=r.endLine;s++){let i=t.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,t.markDirty(i.lineId));}}};var Y=(r=>(r[r.Tier1=1]="Tier1",r[r.Tier2=2]="Tier2",r[r.Tier3=3]="Tier3",r[r.Skipped=0]="Skipped",r))(Y||{}),w=class{constructor(e,t,n){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=t,this.dag=t.getDag(),this.checkpointer=n??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=chunk634ILVMP_cjs.J.subscribe(r=>{for(let s of this.dag.getAffectedLines(chunk634ILVMP_cjs.K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,t){this.engine.setKeystrokeSignal(t??null),chunkSQHBOWES_cjs.h();try{this.reseedAccumulators();let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(e.endLine,i);for(let l=1;l<=a;l++){let o=this.doc.getLineAt(l);if(!o){s.skipped++;continue}let c=l>=e.startLine&&l<=e.endLine,d=this.evaluateSingleLine(o,l,c);n.push(d),d.tier===1?s.tier1++:d.tier===2?s.tier2++:d.tier===3?s.tier3++:s.skipped++,d.results&&c&&r.set(l,d.results.flat());}return this.pageManager.maintainAfterEval(e,this.doc),{lines:n,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),chunkSQHBOWES_cjs.i();}}backgroundCompile(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef)continue;let a=this.evaluateSingleLine(i,s,false);t.push(a);}return t}dispatchBackgroundCompiles(e){let t=this.collectInvisibleCompileTargets(e);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let t={startLine:1,endLine:this.doc.lineCount};return this.evaluate(t,e)}setViewport(e,t){if(this.engine.setKeystrokeSignal(t??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,t);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),chunkSQHBOWES_cjs.h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),chunkSQHBOWES_cjs.i();}}applyTransaction(e){let t=new Set;for(let s of e)for(let i=0;i<s.deleteCount;i++){let a=s.startLine+i,l=this.dag.getWrites(a);for(let o of l)t.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let n=new Set;for(let s of t){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&n.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of n)this.doc.markDirty(s);return this.dag.clear(),{inserted:r.inserted,removed:r.removed}}reseedAccumulators(){let e=this.engine.resetAccumulators();if(e.size===0)return;let t=this.doc.lineCount;for(let n=1;n<=t;n++){let r=this.dag.getWrites(n);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(n);break}}}}collectEvalResults(e,t){let n=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(t,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);n.push(c),c.tier===1?s.tier1++:c.tier===2?s.tier2++:c.tier===3?s.tier3++:s.skipped++,c.results&&r.set(l,c.results.flat());}return {lines:n,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,t,n){let r={lineId:e.lineId,lineNumber:t};if(e.isEmpty||chunkSPOVFRZO_cjs.l(e.text))return e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null};let{expressions:s,inlineSolveCount:i}=this.extractExpressions(e);return s.length===0?(e.isEmpty=true,this.doc.markClean(e.lineId),{...r,tier:0,result:null,error:null}):e.dirty?n?this.evaluateTier1(e,t,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,t,s,i,r):n&&e.bytecodes.length>0?this.evaluateTier2(e,t,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,t,n,r,s){let i=[],a=[],l=new Set,o=new Set,c=false,d=null,p=null,f=false,g=false;for(let y of n){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(t,y);b=[m],d=m,L=this.engine.getLineCache().get(t,y);}catch(m){let x=m instanceof Error?m.message:String(m);p||(p=x),f=true,b=null;}if(b&&b.some(m=>m.type===12)&&(g=true),b?i.push(b):i.push([chunkSQHBOWES_cjs.P("eval_failed",p??"unknown error")]),L){a.push(L.bytecode);for(let m of L.readVariables)l.add(m);L.writeVariable&&(o.add(L.writeVariable),c=true);}else try{let{program:m,reads:x,writes:E}=this.engine.compileExpression(y);a.push(m);for(let S of x)l.add(S);for(let S of E)o.add(S);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof chunkYBQPEWT7_cjs.b&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let S of x)l.add(S);if(Array.isArray(E))for(let S of E)o.add(S);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,n,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=n):this.doc.updateLineResult(e.lineId,i,a,n,h,v,c,r),this.dag.registerLine(t,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(t,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,t,n){if(e.bytecodes.length===0)return {...n,tier:0,result:null,error:null};let r=[],s=null,i=null,a=false;for(let l of e.bytecodes)if(l.opcodes.length!==0)try{let o=this.engine.executeCached(l,t);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([chunkSQHBOWES_cjs.P("exec_failed",c)]);}return this.dag.registerLine(t,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...n,tier:2,result:s,results:r,error:i}}evaluateTier3(e,t,n,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of n)if(v.trim())try{let{program:y,reads:b,writes:L}=this.engine.compileExpression(v);i.push(y);for(let m of b)a.add(m);for(let m of L)l.add(m);L.length>0&&(o=!0),L.length>0&&y.opcodes.length>0&&(c=this.engine.executeCached(y,t),c&&c.type===12&&(f=!0));}catch(y){let b=y instanceof Error?y.message:String(y);d||(d=b),p=true,i.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false});}let g=[...a],h=[...l];return this.doc.updateLineCompiled(e.lineId,n,i,g,h,o,r),this.dag.registerLine(t,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(t,e.lineId,h)),{...s,tier:3,result:c,results:o&&c&&!p&&!f?[[c]]:void 0,error:d}}restoreTo(e){this.checkpointer&&this.checkpointer.restoreTo(e);}getCheckpointer(){return this.checkpointer}getPageManager(){return this.pageManager}preloadNextPages(e){let t=this.pageManager.getPreloadTargets(e,this.doc);t.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(t).then(n=>{this.compilationWorker.storeResults(n,this.doc);}).catch(n=>{}));}collectInvisibleCompileTargets(e){let t=[],n=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=n;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||chunkSPOVFRZO_cjs.l(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&t.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return t}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let t=e.text.trim();if(t.length===0)return {expressions:[],inlineSolveCount:0};let n=chunkBMXYR5LI_cjs.c.findInlineSolves(e.text);return n.length>0?{expressions:n.map(r=>r.expression),inlineSolveCount:n.length}:{expressions:[t],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,t={inputType:"markdown"}){let n=u.getDocumentModel(),r=new R;r.setDocument(e);let s=new w(r,u);try{let i=r.lineCount;s.evaluate({startLine:1,endLine:i});let a=[],l=[],o=0;for(let c=1;c<=i;c++){let d=r.getLineAt(c),p=d.text,f=o,g=o+p.length;o=g+1;let h=d.inlineSolveCount>0,v=[],y=null,b=null;d.isEmpty||(h?v=chunkSPOVFRZO_cjs.m(p,c).map((L,m)=>{let x=d.results[m]?.[0]??null;if(x&&x.type===13){let E=ee(x);return l.push(`Line ${c}: ${E}`),{...L,result:null,error:E}}return {...L,result:x,error:null}}):(y=d.expressions[0]??null,b=d.result??null,b&&b.type===13&&l.push(`Line ${c}: ${ee(b)}`))),a.push({lineNumber:c,text:p,startPosition:f,endPosition:g,isEmpty:d.isEmpty,hasInlineSolves:h,inlineSolves:v,expression:y,error:null,result:b});}return {lines:a,totalLines:i,errors:l}}finally{s.terminateWorker(),u.setDocumentModel(n);}}exports.a=R;exports.b=Y;exports.c=w;exports.d=ie;//# sourceMappingURL=chunk-4BAUQE6A.cjs.map
|
|
3
|
+
//# sourceMappingURL=chunk-4BAUQE6A.cjs.map
|