solve-engine 2.32.0 → 2.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{EngineError-CqGtaT_v.d.cts → EngineError-Bm4OYmw8.d.cts} +6 -0
- package/dist/{EngineError-CqGtaT_v.d.ts → EngineError-Bm4OYmw8.d.ts} +6 -0
- package/dist/{Lexer-CqFjYoRA.d.ts → Lexer-DPn5dfCH.d.ts} +1 -13
- package/dist/{Lexer-sCI05tqO.d.cts → Lexer-DaWkCu84.d.cts} +1 -13
- package/dist/{PackageCompatibility-phvSFP4f.d.ts → PackageCompatibility-CkzZfoJ3.d.ts} +1 -1
- package/dist/{PackageCompatibility-Bn-T_xKW.d.cts → PackageCompatibility-E_5GtcQW.d.cts} +1 -1
- package/dist/{PackageRegistry-C78jVkI9.d.ts → PackageRegistry-DSqic8kz.d.ts} +132 -23
- package/dist/{PackageRegistry-B-C1duZw.d.cts → PackageRegistry-js47hr28.d.cts} +132 -23
- package/dist/{Parselet-Dgymjxzd.d.ts → Parselet-CQjcHOKw.d.ts} +13 -6
- package/dist/{Parselet-DF3864la.d.cts → Parselet-s1sRRn8H.d.cts} +13 -6
- package/dist/{TokenNormalizer-Pe3_390t.d.cts → TokenNormalizer-D382VSYh.d.cts} +4 -1
- package/dist/{TokenNormalizer-IF7nPRMp.d.ts → TokenNormalizer-DAzPp-j1.d.ts} +4 -1
- package/dist/{VMBuiltins-BkKzhj6C.d.cts → VMBuiltins-JCavlQUj.d.cts} +53 -18
- package/dist/{VMBuiltins-Du9y8sEo.d.ts → VMBuiltins-qgzA6qGi.d.ts} +53 -18
- package/dist/{VMCheckpoints-WdUQrdc9.d.cts → VMCheckpoints-BxPzmdu0.d.cts} +2 -2
- package/dist/{VMCheckpoints-gvy_yxYh.d.ts → VMCheckpoints-DjjE92mf.d.ts} +2 -2
- package/dist/{Value-BYHw-x7q.d.cts → Value-2TIKi-YL.d.cts} +19 -0
- package/dist/{Value-BYHw-x7q.d.ts → Value-2TIKi-YL.d.ts} +19 -0
- package/dist/{WorkerError-DTrl3Jag.d.ts → WorkerError-BaN8_eok.d.ts} +1 -1
- package/dist/{WorkerError-CRoM8Ju1.d.cts → WorkerError-CexHHmbb.d.cts} +1 -1
- package/dist/{chunk-IJE4AEDX.js → chunk-24OW3AAU.js} +3 -3
- package/dist/{chunk-IJE4AEDX.js.map → chunk-24OW3AAU.js.map} +1 -1
- package/dist/{chunk-CAJTDZ5B.cjs → chunk-2XOLAHW6.cjs} +2 -2
- package/dist/{chunk-CAJTDZ5B.cjs.map → chunk-2XOLAHW6.cjs.map} +1 -1
- package/dist/{chunk-AGCNMEP2.cjs → chunk-3MG7VIPL.cjs} +2 -2
- package/dist/{chunk-AGCNMEP2.cjs.map → chunk-3MG7VIPL.cjs.map} +1 -1
- package/dist/chunk-4ASM522I.js +2 -0
- package/dist/chunk-4ASM522I.js.map +1 -0
- package/dist/{chunk-KH4QXKLT.js → chunk-4MD5L23F.js} +2 -2
- package/dist/{chunk-KH4QXKLT.js.map → chunk-4MD5L23F.js.map} +1 -1
- package/dist/{chunk-IQVSCL2R.js → chunk-4XWZXP6I.js} +3 -3
- package/dist/{chunk-IQVSCL2R.js.map → chunk-4XWZXP6I.js.map} +1 -1
- package/dist/{chunk-RELMEWY6.js → chunk-6G2NES2I.js} +2 -2
- package/dist/chunk-6G2NES2I.js.map +1 -0
- package/dist/{chunk-CDE2ZUGG.js → chunk-6NL7RBAG.js} +2 -2
- package/dist/{chunk-CDE2ZUGG.js.map → chunk-6NL7RBAG.js.map} +1 -1
- package/dist/{chunk-SUAGBRQ7.cjs → chunk-6SYU4MH7.cjs} +2 -2
- package/dist/chunk-6SYU4MH7.cjs.map +1 -0
- package/dist/chunk-72J5V7SN.cjs +2 -0
- package/dist/chunk-72J5V7SN.cjs.map +1 -0
- package/dist/{chunk-TSJ4RQLZ.js → chunk-AENL3Z66.js} +2 -2
- package/dist/{chunk-TSJ4RQLZ.js.map → chunk-AENL3Z66.js.map} +1 -1
- package/dist/chunk-APYRNAU2.js +2 -0
- package/dist/chunk-APYRNAU2.js.map +1 -0
- package/dist/{chunk-AXTYQFIV.cjs → chunk-D7URPV5Z.cjs} +3 -3
- package/dist/{chunk-AXTYQFIV.cjs.map → chunk-D7URPV5Z.cjs.map} +1 -1
- package/dist/chunk-DB5ISONG.js +2 -0
- package/dist/chunk-DB5ISONG.js.map +1 -0
- package/dist/chunk-DGDVY6XI.js +3 -0
- package/dist/chunk-DGDVY6XI.js.map +1 -0
- package/dist/chunk-EOKHRS2T.js +2 -0
- package/dist/chunk-EOKHRS2T.js.map +1 -0
- package/dist/{chunk-NQFCXLEF.js → chunk-EOO6M65F.js} +2 -2
- package/dist/{chunk-NQFCXLEF.js.map → chunk-EOO6M65F.js.map} +1 -1
- package/dist/{chunk-A764BY7L.cjs → chunk-EQNKDTMX.cjs} +2 -2
- package/dist/{chunk-A764BY7L.cjs.map → chunk-EQNKDTMX.cjs.map} +1 -1
- package/dist/chunk-FESR6PZI.cjs +2 -0
- package/dist/chunk-FESR6PZI.cjs.map +1 -0
- package/dist/chunk-G2LCDR52.cjs +3 -0
- package/dist/chunk-G2LCDR52.cjs.map +1 -0
- package/dist/chunk-G5TZ6TDA.js +2 -0
- package/dist/chunk-G5TZ6TDA.js.map +1 -0
- package/dist/chunk-GDLYXRMA.cjs +2 -0
- package/dist/chunk-GDLYXRMA.cjs.map +1 -0
- package/dist/{chunk-7DJYS5PO.cjs → chunk-HSTGWWU2.cjs} +2 -2
- package/dist/{chunk-7DJYS5PO.cjs.map → chunk-HSTGWWU2.cjs.map} +1 -1
- package/dist/{chunk-OE2DBN4K.js → chunk-INMJ7ZXL.js} +2 -2
- package/dist/chunk-INMJ7ZXL.js.map +1 -0
- package/dist/chunk-ITH2RLRG.js +5 -0
- package/dist/chunk-ITH2RLRG.js.map +1 -0
- package/dist/{chunk-5AKT36UK.cjs → chunk-K3PZ66XR.cjs} +2 -2
- package/dist/{chunk-5AKT36UK.cjs.map → chunk-K3PZ66XR.cjs.map} +1 -1
- package/dist/chunk-LI6LYJDA.cjs +2 -0
- package/dist/chunk-LI6LYJDA.cjs.map +1 -0
- package/dist/{chunk-WQGHJAW2.cjs → chunk-M4UC2PB6.cjs} +2 -2
- package/dist/{chunk-WQGHJAW2.cjs.map → chunk-M4UC2PB6.cjs.map} +1 -1
- package/dist/chunk-O7HF345B.js +2 -0
- package/dist/chunk-O7HF345B.js.map +1 -0
- package/dist/{chunk-CM2WM5CM.cjs → chunk-OBZJKZ2F.cjs} +2 -2
- package/dist/{chunk-CM2WM5CM.cjs.map → chunk-OBZJKZ2F.cjs.map} +1 -1
- package/dist/{chunk-Q7TBBV62.cjs → chunk-P5YWBIIU.cjs} +2 -2
- package/dist/chunk-P5YWBIIU.cjs.map +1 -0
- package/dist/chunk-PICFFFJV.js +3 -0
- package/dist/chunk-PICFFFJV.js.map +1 -0
- package/dist/{chunk-P43SV4NJ.cjs → chunk-QOOTRUY7.cjs} +3 -3
- package/dist/{chunk-P43SV4NJ.cjs.map → chunk-QOOTRUY7.cjs.map} +1 -1
- package/dist/chunk-R3W53ZMP.cjs +2 -0
- package/dist/chunk-R3W53ZMP.cjs.map +1 -0
- package/dist/chunk-RMDCGYZM.js +2 -0
- package/dist/chunk-RMDCGYZM.js.map +1 -0
- package/dist/{chunk-CB3EXUM2.js → chunk-RU3KGJRA.js} +2 -2
- package/dist/chunk-RU3KGJRA.js.map +1 -0
- package/dist/chunk-S3SPDK6N.cjs +2 -0
- package/dist/chunk-S3SPDK6N.cjs.map +1 -0
- package/dist/chunk-SF5QVUEI.cjs +3 -0
- package/dist/chunk-SF5QVUEI.cjs.map +1 -0
- package/dist/{chunk-FXB5GCBT.js → chunk-TJKN466F.js} +2 -2
- package/dist/{chunk-FXB5GCBT.js.map → chunk-TJKN466F.js.map} +1 -1
- package/dist/{chunk-VLX7ZVK4.js → chunk-U5MESNRT.js} +2 -2
- package/dist/{chunk-VLX7ZVK4.js.map → chunk-U5MESNRT.js.map} +1 -1
- package/dist/chunk-WCVPXBCW.cjs +5 -0
- package/dist/chunk-WCVPXBCW.cjs.map +1 -0
- package/dist/{chunk-YWF6C2IO.cjs → chunk-WFT3XUSH.cjs} +2 -2
- package/dist/{chunk-YWF6C2IO.cjs.map → chunk-WFT3XUSH.cjs.map} +1 -1
- package/dist/{chunk-3ZGFAE3Q.js → chunk-X2GQAKL2.js} +2 -2
- package/dist/{chunk-3ZGFAE3Q.js.map → chunk-X2GQAKL2.js.map} +1 -1
- package/dist/{chunk-G3POUURF.js → chunk-YID47OPR.js} +2 -2
- package/dist/{chunk-G3POUURF.js.map → chunk-YID47OPR.js.map} +1 -1
- package/dist/chunk-YV4GDW5A.cjs +2 -0
- package/dist/chunk-YV4GDW5A.cjs.map +1 -0
- package/dist/chunk-ZSXQP7PD.cjs +2 -0
- package/dist/chunk-ZSXQP7PD.cjs.map +1 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/engine.cjs +1 -1
- package/dist/engine.d.cts +10 -10
- package/dist/engine.d.ts +10 -10
- package/dist/engine.js +1 -1
- package/dist/engine.worker.cjs +1 -1
- package/dist/engine.worker.cjs.map +1 -1
- package/dist/engine.worker.js +1 -1
- package/dist/engine.worker.js.map +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 +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/language.d.cts +9 -9
- package/dist/language.d.ts +9 -9
- package/dist/lexer.cjs +1 -1
- package/dist/lexer.d.cts +3 -3
- package/dist/lexer.d.ts +3 -3
- package/dist/lexer.js +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 +8 -8
- package/dist/packages.d.ts +8 -8
- 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-BYkKNpql.d.cts → pipeline-Bum6y1B9.d.cts} +1 -1
- package/dist/{pipeline-Cl7KW8CB.d.ts → pipeline-DOo3KHaq.d.ts} +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.cts +69 -3
- package/dist/resolvers.d.ts +69 -3
- package/dist/resolvers.js +1 -1
- package/dist/temporal.cjs +1 -1
- package/dist/temporal.js +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +9 -9
- package/dist/testing.d.ts +9 -9
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/uom.cjs +1 -1
- package/dist/uom.d.cts +35 -2
- package/dist/uom.d.ts +35 -2
- package/dist/uom.js +1 -1
- package/dist/vm.cjs +1 -1
- package/dist/vm.d.cts +6 -6
- package/dist/vm.d.ts +6 -6
- package/dist/vm.js +1 -1
- package/dist/worker.cjs +2 -2
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +9 -9
- package/dist/worker.d.ts +9 -9
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-4DR5RBHQ.cjs +0 -2
- package/dist/chunk-4DR5RBHQ.cjs.map +0 -1
- package/dist/chunk-4IC5OARK.js +0 -3
- package/dist/chunk-4IC5OARK.js.map +0 -1
- package/dist/chunk-7ODHPWQC.js +0 -5
- package/dist/chunk-7ODHPWQC.js.map +0 -1
- package/dist/chunk-A755LVPT.cjs +0 -2
- package/dist/chunk-A755LVPT.cjs.map +0 -1
- package/dist/chunk-AF6NDOIE.js +0 -2
- package/dist/chunk-AF6NDOIE.js.map +0 -1
- package/dist/chunk-B2NL65FI.js +0 -2
- package/dist/chunk-B2NL65FI.js.map +0 -1
- package/dist/chunk-CB3EXUM2.js.map +0 -1
- package/dist/chunk-DUFEONVN.cjs +0 -3
- package/dist/chunk-DUFEONVN.cjs.map +0 -1
- package/dist/chunk-IJHL3LMH.js +0 -2
- package/dist/chunk-IJHL3LMH.js.map +0 -1
- package/dist/chunk-LCYQQFUH.cjs +0 -2
- package/dist/chunk-LCYQQFUH.cjs.map +0 -1
- package/dist/chunk-LP3JYC3A.js +0 -2
- package/dist/chunk-LP3JYC3A.js.map +0 -1
- package/dist/chunk-OE2DBN4K.js.map +0 -1
- package/dist/chunk-OKKGPINQ.cjs +0 -5
- package/dist/chunk-OKKGPINQ.cjs.map +0 -1
- package/dist/chunk-OM7NOHJF.cjs +0 -2
- package/dist/chunk-OM7NOHJF.cjs.map +0 -1
- package/dist/chunk-PTXUWGRR.js +0 -3
- package/dist/chunk-PTXUWGRR.js.map +0 -1
- package/dist/chunk-Q7TBBV62.cjs.map +0 -1
- package/dist/chunk-RELMEWY6.js.map +0 -1
- package/dist/chunk-SFM4XFGJ.js +0 -2
- package/dist/chunk-SFM4XFGJ.js.map +0 -1
- package/dist/chunk-SRAU3BLV.cjs +0 -3
- package/dist/chunk-SRAU3BLV.cjs.map +0 -1
- package/dist/chunk-SUAGBRQ7.cjs.map +0 -1
- package/dist/chunk-UNKZ5XRC.cjs +0 -2
- package/dist/chunk-UNKZ5XRC.cjs.map +0 -1
- package/dist/chunk-WU7SBKVU.cjs +0 -2
- package/dist/chunk-WU7SBKVU.cjs.map +0 -1
- package/dist/chunk-X5K72MBV.js +0 -2
- package/dist/chunk-X5K72MBV.js.map +0 -1
- package/dist/chunk-ZVPZQ66D.cjs +0 -2
- package/dist/chunk-ZVPZQ66D.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { B as BytecodeBuilder } from './BytecodeBuilder-DSWKZi4f.js';
|
|
2
2
|
import { T as Token } from './Token-D8f7yaz1.js';
|
|
3
|
-
import { D as DiagnosticPipeline } from './pipeline-
|
|
3
|
+
import { D as DiagnosticPipeline } from './pipeline-DOo3KHaq.js';
|
|
4
4
|
import { C as CalendarBackend } from './CalendarBackend-MdS3Bb4P.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -77,16 +77,15 @@ declare class ParseletRegistry {
|
|
|
77
77
|
* one higher. That is the standard encoding for a left-associative
|
|
78
78
|
* operator, and it is what the parser itself does, see
|
|
79
79
|
* `PrecedenceParser.parseExpression()`'s `bp + 1` for the right operand.
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* `
|
|
83
|
-
* the interface. See {@link ParseletBindingPowers} for why scraping a
|
|
84
|
-
* plausible-looking one off the parselet is worse than not reporting it.
|
|
80
|
+
* An operator that declares `rightAssociative` (`^`) is reported with the
|
|
81
|
+
* right power one BELOW the left, which is how it parses its right operand
|
|
82
|
+
* (see `parseRightOperand`), and `associativity` says which in words.
|
|
85
83
|
*/
|
|
86
84
|
getAllInfix(): Array<{
|
|
87
85
|
tokenType: string;
|
|
88
86
|
leftBindingPower: number;
|
|
89
87
|
rightBindingPower: number;
|
|
88
|
+
associativity: "left" | "right";
|
|
90
89
|
category?: string;
|
|
91
90
|
}>;
|
|
92
91
|
/** Number of registered prefix parselets. */
|
|
@@ -363,6 +362,14 @@ interface InfixParselet {
|
|
|
363
362
|
readonly category: string;
|
|
364
363
|
/** Binding power (precedence), property access avoids vtable dispatch in hot loop */
|
|
365
364
|
readonly bindingPower: number;
|
|
365
|
+
/**
|
|
366
|
+
* Whether the operator groups from the right (`2 ^ 3 ^ 2` is `2 ^ (3 ^ 2)`).
|
|
367
|
+
* Absent means left, which is what every operator but exponentiation
|
|
368
|
+
* wants. Read by {@link parseRightOperand}, and reported by
|
|
369
|
+
* `ParseletRegistry.getAllInfix` so a precedence table built from the
|
|
370
|
+
* registry says what the parser does.
|
|
371
|
+
*/
|
|
372
|
+
readonly rightAssociative?: boolean;
|
|
366
373
|
parse(parser: PrecedenceParser, left: Token, token: Token, builder: BytecodeBuilder): void;
|
|
367
374
|
}
|
|
368
375
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { B as BytecodeBuilder } from './BytecodeBuilder-DSWKZi4f.cjs';
|
|
2
2
|
import { T as Token } from './Token-D8f7yaz1.cjs';
|
|
3
|
-
import { D as DiagnosticPipeline } from './pipeline-
|
|
3
|
+
import { D as DiagnosticPipeline } from './pipeline-Bum6y1B9.cjs';
|
|
4
4
|
import { C as CalendarBackend } from './CalendarBackend-MdS3Bb4P.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -77,16 +77,15 @@ declare class ParseletRegistry {
|
|
|
77
77
|
* one higher. That is the standard encoding for a left-associative
|
|
78
78
|
* operator, and it is what the parser itself does, see
|
|
79
79
|
* `PrecedenceParser.parseExpression()`'s `bp + 1` for the right operand.
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* `
|
|
83
|
-
* the interface. See {@link ParseletBindingPowers} for why scraping a
|
|
84
|
-
* plausible-looking one off the parselet is worse than not reporting it.
|
|
80
|
+
* An operator that declares `rightAssociative` (`^`) is reported with the
|
|
81
|
+
* right power one BELOW the left, which is how it parses its right operand
|
|
82
|
+
* (see `parseRightOperand`), and `associativity` says which in words.
|
|
85
83
|
*/
|
|
86
84
|
getAllInfix(): Array<{
|
|
87
85
|
tokenType: string;
|
|
88
86
|
leftBindingPower: number;
|
|
89
87
|
rightBindingPower: number;
|
|
88
|
+
associativity: "left" | "right";
|
|
90
89
|
category?: string;
|
|
91
90
|
}>;
|
|
92
91
|
/** Number of registered prefix parselets. */
|
|
@@ -363,6 +362,14 @@ interface InfixParselet {
|
|
|
363
362
|
readonly category: string;
|
|
364
363
|
/** Binding power (precedence), property access avoids vtable dispatch in hot loop */
|
|
365
364
|
readonly bindingPower: number;
|
|
365
|
+
/**
|
|
366
|
+
* Whether the operator groups from the right (`2 ^ 3 ^ 2` is `2 ^ (3 ^ 2)`).
|
|
367
|
+
* Absent means left, which is what every operator but exponentiation
|
|
368
|
+
* wants. Read by {@link parseRightOperand}, and reported by
|
|
369
|
+
* `ParseletRegistry.getAllInfix` so a precedence table built from the
|
|
370
|
+
* registry says what the parser does.
|
|
371
|
+
*/
|
|
372
|
+
readonly rightAssociative?: boolean;
|
|
366
373
|
parse(parser: PrecedenceParser, left: Token, token: Token, builder: BytecodeBuilder): void;
|
|
367
374
|
}
|
|
368
375
|
|
|
@@ -605,7 +605,10 @@ declare class TokenNormalizer {
|
|
|
605
605
|
* @param tokens - Raw tokens from the lexer
|
|
606
606
|
* @param onFusion - Optional fusion callback (overrides {@link NormalizerOptions.onFusion})
|
|
607
607
|
* @returns Normalized tokens ready for parsing
|
|
608
|
-
* @throws {Error} If the normalized token count exceeds maxTokens
|
|
608
|
+
* @throws {Error} If the normalized token count exceeds maxTokens, or the
|
|
609
|
+
* stream is still changing after maxPasses passes (a rule chain that never
|
|
610
|
+
* settles): NORMALIZER_PASS_LIMIT_EXCEEDED, rather than a stream that is
|
|
611
|
+
* quietly whatever the last pass left.
|
|
609
612
|
*/
|
|
610
613
|
normalize(tokens: Token[], onFusion?: (fusion: TokenFusion) => void): Token[];
|
|
611
614
|
}
|
|
@@ -605,7 +605,10 @@ declare class TokenNormalizer {
|
|
|
605
605
|
* @param tokens - Raw tokens from the lexer
|
|
606
606
|
* @param onFusion - Optional fusion callback (overrides {@link NormalizerOptions.onFusion})
|
|
607
607
|
* @returns Normalized tokens ready for parsing
|
|
608
|
-
* @throws {Error} If the normalized token count exceeds maxTokens
|
|
608
|
+
* @throws {Error} If the normalized token count exceeds maxTokens, or the
|
|
609
|
+
* stream is still changing after maxPasses passes (a rule chain that never
|
|
610
|
+
* settles): NORMALIZER_PASS_LIMIT_EXCEEDED, rather than a stream that is
|
|
611
|
+
* quietly whatever the last pass left.
|
|
609
612
|
*/
|
|
610
613
|
normalize(tokens: Token[], onFusion?: (fusion: TokenFusion) => void): Token[];
|
|
611
614
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { V as Value } from './Value-
|
|
1
|
+
import { V as Value } from './Value-2TIKi-YL.cjs';
|
|
2
2
|
import { U as UserFunctionDef, A as AnonymousBodyDef, a as BytecodeProgram } from './BytecodeBuilder-DSWKZi4f.cjs';
|
|
3
3
|
import { C as CalendarBackend } from './CalendarBackend-MdS3Bb4P.cjs';
|
|
4
|
-
import { E as EngineError } from './EngineError-
|
|
5
|
-
import { D as DiagnosticPipeline } from './pipeline-
|
|
4
|
+
import { E as EngineError } from './EngineError-Bm4OYmw8.cjs';
|
|
5
|
+
import { D as DiagnosticPipeline } from './pipeline-Bum6y1B9.cjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Create a new VM instance with the given opcode registry and configurable limits.
|
|
@@ -13,7 +13,11 @@ import { D as DiagnosticPipeline } from './pipeline-BYkKNpql.cjs';
|
|
|
13
13
|
* - An instruction counter (bounded by `maxInstructions`)
|
|
14
14
|
* - An AbortSignal for async cancellation
|
|
15
15
|
*
|
|
16
|
-
* @param registry -
|
|
16
|
+
* @param registry - Never consulted, and kept only so the parameter list a
|
|
17
|
+
* host already calls with keeps working. The dispatch loop refuses any
|
|
18
|
+
* opcode it has no arm for, whatever a registry claims about it; a package
|
|
19
|
+
* reaches the VM through `pluginFunctions` and `CALL_PLUGIN`. See
|
|
20
|
+
* `OpRegistry.ts`, and the deprecation there.
|
|
17
21
|
* @param maxStackDepth - Maximum stack slots (default 200)
|
|
18
22
|
* @param maxInstructions - Maximum opcodes per expression (default 50000)
|
|
19
23
|
* @param maxFunctionRecursionDepth - Maximum nested user-defined-function
|
|
@@ -176,9 +180,12 @@ type EvalResult = {
|
|
|
176
180
|
* switches (OpCode values 0–200) into a jump table with O(1) dispatch.
|
|
177
181
|
* All handler code is inlined directly in the switch cases, allowing
|
|
178
182
|
* TurboFan to optimize across opcode boundaries.
|
|
179
|
-
* - ADD/SUB/MUL
|
|
180
|
-
*
|
|
181
|
-
*
|
|
183
|
+
* - ADD/SUB/MUL/DIV and the six comparisons open with an inlined plain-number
|
|
184
|
+
* branch: two Numbers carrying no rational or uncertainty sidecar (>90% of
|
|
185
|
+
* arithmetic ops) are answered before any helper (fault propagation,
|
|
186
|
+
* percentage, rate period, money, unit, `binaryOp()`) is called. The
|
|
187
|
+
* sidecar checks are what keep the branch honest: an exact fraction or a
|
|
188
|
+
* measurement takes the ladder below it, exactly as before.
|
|
182
189
|
* - Tracing uses a boolean guard (`shouldTrace`) that the JIT eliminates
|
|
183
190
|
* entirely when diagnostics are disabled. No function call overhead.
|
|
184
191
|
* - `Value.toNumber()` caches its result, computed once, read thereafter.
|
|
@@ -346,26 +353,44 @@ interface ScalarEquationDef {
|
|
|
346
353
|
rhsProgram: BytecodeProgram;
|
|
347
354
|
}
|
|
348
355
|
/**
|
|
349
|
-
* Handler function for
|
|
350
|
-
* No longer dispatched directly from the VM switch, plugins register
|
|
351
|
-
* functions in pluginFunctionRegistry instead.
|
|
356
|
+
* Handler function for a custom opcode, in the shape the VM never calls.
|
|
352
357
|
*
|
|
353
|
-
* @deprecated
|
|
354
|
-
*
|
|
358
|
+
* @deprecated Nothing dispatches to a handler of this type. A package reaches
|
|
359
|
+
* the VM through `IEnginePackage.pluginFunctions`, which `CALL_PLUGIN`
|
|
360
|
+
* resolves per engine. Removed in the next major with {@link OpRegistry}.
|
|
355
361
|
*/
|
|
356
362
|
type OpcodeHandler = (vm: VM, opcodes: Uint8Array, ip: number, numbers: Float64Array, strings: string[]) => number;
|
|
357
|
-
/**
|
|
363
|
+
/**
|
|
364
|
+
* Registration payload for an opcode handler.
|
|
365
|
+
*
|
|
366
|
+
* @deprecated See {@link OpcodeHandler}. Removed in the next major.
|
|
367
|
+
*/
|
|
358
368
|
interface IOpcodeHandlerRegistration {
|
|
359
369
|
opcode: number;
|
|
360
370
|
handler: OpcodeHandler;
|
|
361
371
|
pluginName: string;
|
|
362
372
|
}
|
|
363
373
|
/**
|
|
364
|
-
*
|
|
374
|
+
* A table of custom opcode handlers the virtual machine never reads.
|
|
365
375
|
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
376
|
+
* This once described an extension point: a package allocated an opcode from
|
|
377
|
+
* the dynamic range (201 to 254), registered a handler for it, and the VM's
|
|
378
|
+
* dispatch switch was meant to call that handler from its default arm. The
|
|
379
|
+
* switch never consulted the registry, and until recently had no default arm
|
|
380
|
+
* at all, so a registered opcode ran as a no-op and the program failed some
|
|
381
|
+
* instructions later with a misleading STACK_UNDERFLOW. The dispatch loop now
|
|
382
|
+
* refuses any opcode it has no arm for, at that instruction, with
|
|
383
|
+
* `MALFORMED_BYTECODE_UNKNOWN_OPCODE`, whatever a registry claims about it.
|
|
384
|
+
*
|
|
385
|
+
* The class, the {@link sharedOpRegistry} singleton, the `registry` field on
|
|
386
|
+
* {@link VM} and the first parameter of `createVM()` are kept so the calls a
|
|
387
|
+
* host already makes keep compiling and running; every one of them is
|
|
388
|
+
* deprecated and goes in the next major. A package that wants the VM to run
|
|
389
|
+
* its code declares `IEnginePackage.pluginFunctions`, which `CALL_PLUGIN`
|
|
390
|
+
* resolves through the engine's own context, one table per engine.
|
|
391
|
+
*
|
|
392
|
+
* @deprecated Never consulted by the VM. Use `IEnginePackage.pluginFunctions`.
|
|
393
|
+
* Removed in the next major.
|
|
369
394
|
*/
|
|
370
395
|
declare class OpRegistry {
|
|
371
396
|
private handlers;
|
|
@@ -435,6 +460,11 @@ interface VM {
|
|
|
435
460
|
popString(): string;
|
|
436
461
|
peek(): Value;
|
|
437
462
|
getStack(): Value[];
|
|
463
|
+
/**
|
|
464
|
+
* The registry this machine was built with, which it never reads.
|
|
465
|
+
*
|
|
466
|
+
* @deprecated See {@link OpRegistry}. Removed in the next major.
|
|
467
|
+
*/
|
|
438
468
|
registry: OpRegistry;
|
|
439
469
|
/**
|
|
440
470
|
* Read a variable by name, checks the INNERMOST active user-defined-
|
|
@@ -550,7 +580,12 @@ interface VM {
|
|
|
550
580
|
*/
|
|
551
581
|
context: EngineContext;
|
|
552
582
|
}
|
|
553
|
-
/**
|
|
583
|
+
/**
|
|
584
|
+
* The registry every `createVM()` call without one of its own is handed.
|
|
585
|
+
*
|
|
586
|
+
* @deprecated See {@link OpRegistry}: the VM never reads it. Removed in the
|
|
587
|
+
* next major, together with `createVM()`'s first parameter.
|
|
588
|
+
*/
|
|
554
589
|
declare const sharedOpRegistry: OpRegistry;
|
|
555
590
|
|
|
556
591
|
/** Serialized snapshot of the dependency graph for diagnostic rendering. */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { V as Value } from './Value-
|
|
1
|
+
import { V as Value } from './Value-2TIKi-YL.js';
|
|
2
2
|
import { U as UserFunctionDef, A as AnonymousBodyDef, a as BytecodeProgram } from './BytecodeBuilder-DSWKZi4f.js';
|
|
3
3
|
import { C as CalendarBackend } from './CalendarBackend-MdS3Bb4P.js';
|
|
4
|
-
import { E as EngineError } from './EngineError-
|
|
5
|
-
import { D as DiagnosticPipeline } from './pipeline-
|
|
4
|
+
import { E as EngineError } from './EngineError-Bm4OYmw8.js';
|
|
5
|
+
import { D as DiagnosticPipeline } from './pipeline-DOo3KHaq.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Create a new VM instance with the given opcode registry and configurable limits.
|
|
@@ -13,7 +13,11 @@ import { D as DiagnosticPipeline } from './pipeline-Cl7KW8CB.js';
|
|
|
13
13
|
* - An instruction counter (bounded by `maxInstructions`)
|
|
14
14
|
* - An AbortSignal for async cancellation
|
|
15
15
|
*
|
|
16
|
-
* @param registry -
|
|
16
|
+
* @param registry - Never consulted, and kept only so the parameter list a
|
|
17
|
+
* host already calls with keeps working. The dispatch loop refuses any
|
|
18
|
+
* opcode it has no arm for, whatever a registry claims about it; a package
|
|
19
|
+
* reaches the VM through `pluginFunctions` and `CALL_PLUGIN`. See
|
|
20
|
+
* `OpRegistry.ts`, and the deprecation there.
|
|
17
21
|
* @param maxStackDepth - Maximum stack slots (default 200)
|
|
18
22
|
* @param maxInstructions - Maximum opcodes per expression (default 50000)
|
|
19
23
|
* @param maxFunctionRecursionDepth - Maximum nested user-defined-function
|
|
@@ -176,9 +180,12 @@ type EvalResult = {
|
|
|
176
180
|
* switches (OpCode values 0–200) into a jump table with O(1) dispatch.
|
|
177
181
|
* All handler code is inlined directly in the switch cases, allowing
|
|
178
182
|
* TurboFan to optimize across opcode boundaries.
|
|
179
|
-
* - ADD/SUB/MUL
|
|
180
|
-
*
|
|
181
|
-
*
|
|
183
|
+
* - ADD/SUB/MUL/DIV and the six comparisons open with an inlined plain-number
|
|
184
|
+
* branch: two Numbers carrying no rational or uncertainty sidecar (>90% of
|
|
185
|
+
* arithmetic ops) are answered before any helper (fault propagation,
|
|
186
|
+
* percentage, rate period, money, unit, `binaryOp()`) is called. The
|
|
187
|
+
* sidecar checks are what keep the branch honest: an exact fraction or a
|
|
188
|
+
* measurement takes the ladder below it, exactly as before.
|
|
182
189
|
* - Tracing uses a boolean guard (`shouldTrace`) that the JIT eliminates
|
|
183
190
|
* entirely when diagnostics are disabled. No function call overhead.
|
|
184
191
|
* - `Value.toNumber()` caches its result, computed once, read thereafter.
|
|
@@ -346,26 +353,44 @@ interface ScalarEquationDef {
|
|
|
346
353
|
rhsProgram: BytecodeProgram;
|
|
347
354
|
}
|
|
348
355
|
/**
|
|
349
|
-
* Handler function for
|
|
350
|
-
* No longer dispatched directly from the VM switch, plugins register
|
|
351
|
-
* functions in pluginFunctionRegistry instead.
|
|
356
|
+
* Handler function for a custom opcode, in the shape the VM never calls.
|
|
352
357
|
*
|
|
353
|
-
* @deprecated
|
|
354
|
-
*
|
|
358
|
+
* @deprecated Nothing dispatches to a handler of this type. A package reaches
|
|
359
|
+
* the VM through `IEnginePackage.pluginFunctions`, which `CALL_PLUGIN`
|
|
360
|
+
* resolves per engine. Removed in the next major with {@link OpRegistry}.
|
|
355
361
|
*/
|
|
356
362
|
type OpcodeHandler = (vm: VM, opcodes: Uint8Array, ip: number, numbers: Float64Array, strings: string[]) => number;
|
|
357
|
-
/**
|
|
363
|
+
/**
|
|
364
|
+
* Registration payload for an opcode handler.
|
|
365
|
+
*
|
|
366
|
+
* @deprecated See {@link OpcodeHandler}. Removed in the next major.
|
|
367
|
+
*/
|
|
358
368
|
interface IOpcodeHandlerRegistration {
|
|
359
369
|
opcode: number;
|
|
360
370
|
handler: OpcodeHandler;
|
|
361
371
|
pluginName: string;
|
|
362
372
|
}
|
|
363
373
|
/**
|
|
364
|
-
*
|
|
374
|
+
* A table of custom opcode handlers the virtual machine never reads.
|
|
365
375
|
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
376
|
+
* This once described an extension point: a package allocated an opcode from
|
|
377
|
+
* the dynamic range (201 to 254), registered a handler for it, and the VM's
|
|
378
|
+
* dispatch switch was meant to call that handler from its default arm. The
|
|
379
|
+
* switch never consulted the registry, and until recently had no default arm
|
|
380
|
+
* at all, so a registered opcode ran as a no-op and the program failed some
|
|
381
|
+
* instructions later with a misleading STACK_UNDERFLOW. The dispatch loop now
|
|
382
|
+
* refuses any opcode it has no arm for, at that instruction, with
|
|
383
|
+
* `MALFORMED_BYTECODE_UNKNOWN_OPCODE`, whatever a registry claims about it.
|
|
384
|
+
*
|
|
385
|
+
* The class, the {@link sharedOpRegistry} singleton, the `registry` field on
|
|
386
|
+
* {@link VM} and the first parameter of `createVM()` are kept so the calls a
|
|
387
|
+
* host already makes keep compiling and running; every one of them is
|
|
388
|
+
* deprecated and goes in the next major. A package that wants the VM to run
|
|
389
|
+
* its code declares `IEnginePackage.pluginFunctions`, which `CALL_PLUGIN`
|
|
390
|
+
* resolves through the engine's own context, one table per engine.
|
|
391
|
+
*
|
|
392
|
+
* @deprecated Never consulted by the VM. Use `IEnginePackage.pluginFunctions`.
|
|
393
|
+
* Removed in the next major.
|
|
369
394
|
*/
|
|
370
395
|
declare class OpRegistry {
|
|
371
396
|
private handlers;
|
|
@@ -435,6 +460,11 @@ interface VM {
|
|
|
435
460
|
popString(): string;
|
|
436
461
|
peek(): Value;
|
|
437
462
|
getStack(): Value[];
|
|
463
|
+
/**
|
|
464
|
+
* The registry this machine was built with, which it never reads.
|
|
465
|
+
*
|
|
466
|
+
* @deprecated See {@link OpRegistry}. Removed in the next major.
|
|
467
|
+
*/
|
|
438
468
|
registry: OpRegistry;
|
|
439
469
|
/**
|
|
440
470
|
* Read a variable by name, checks the INNERMOST active user-defined-
|
|
@@ -550,7 +580,12 @@ interface VM {
|
|
|
550
580
|
*/
|
|
551
581
|
context: EngineContext;
|
|
552
582
|
}
|
|
553
|
-
/**
|
|
583
|
+
/**
|
|
584
|
+
* The registry every `createVM()` call without one of its own is handed.
|
|
585
|
+
*
|
|
586
|
+
* @deprecated See {@link OpRegistry}: the VM never reads it. Removed in the
|
|
587
|
+
* next major, together with `createVM()`'s first parameter.
|
|
588
|
+
*/
|
|
554
589
|
declare const sharedOpRegistry: OpRegistry;
|
|
555
590
|
|
|
556
591
|
/** Serialized snapshot of the dependency graph for diagnostic rendering. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V as Value } from './Value-
|
|
2
|
-
import { V as VM } from './VMBuiltins-
|
|
1
|
+
import { V as Value } from './Value-2TIKi-YL.cjs';
|
|
2
|
+
import { V as VM } from './VMBuiltins-JCavlQUj.cjs';
|
|
3
3
|
import { U as UserFunctionDef } from './BytecodeBuilder-DSWKZi4f.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V as Value } from './Value-
|
|
2
|
-
import { V as VM } from './VMBuiltins-
|
|
1
|
+
import { V as Value } from './Value-2TIKi-YL.js';
|
|
2
|
+
import { V as VM } from './VMBuiltins-qgzA6qGi.js';
|
|
3
3
|
import { U as UserFunctionDef } from './BytecodeBuilder-DSWKZi4f.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -469,6 +469,25 @@ declare class Value {
|
|
|
469
469
|
* Called by ValueArena.acquire(), zero allocation, just field assignment.
|
|
470
470
|
*/
|
|
471
471
|
recycle(type: ValueType, value: number | bigint | string | boolean | MatrixData | RangeData | ColourData | SplitData | ChartData | IpCidrData | SymbolicNode, unit?: string): void;
|
|
472
|
+
/**
|
|
473
|
+
* A fresh Value carrying everything this one does: the payload, the unit,
|
|
474
|
+
* the cached number and every sidecar, present or future.
|
|
475
|
+
*
|
|
476
|
+
* The inverse of {@link recycle}, and written as a whole-object copy rather
|
|
477
|
+
* than a list of fields on purpose. `persistentValue()` used to name the
|
|
478
|
+
* sidecars it copied, and the two it did not name (`decimalPlaces`,
|
|
479
|
+
* `timedOut`) were silently dropped by every viewport evaluation, so
|
|
480
|
+
* `3.14159 to 4 dp` displayed as 3.14 there and as 3.1416 on a single line.
|
|
481
|
+
* A sidecar added later is carried here without this method knowing its
|
|
482
|
+
* name, which closes that class of bug rather than the one instance.
|
|
483
|
+
*
|
|
484
|
+
* Shallow, as the old copy was: a matrix, a chart or a symbolic tree is
|
|
485
|
+
* shared with the original, which is fine because a Value's payload is
|
|
486
|
+
* treated as immutable everywhere outside the arena's own `recycle()`.
|
|
487
|
+
*
|
|
488
|
+
* @returns A new Value equal to this one in every field.
|
|
489
|
+
*/
|
|
490
|
+
clone(): Value;
|
|
472
491
|
isNumber(): this is Value & {
|
|
473
492
|
value: number;
|
|
474
493
|
};
|
|
@@ -469,6 +469,25 @@ declare class Value {
|
|
|
469
469
|
* Called by ValueArena.acquire(), zero allocation, just field assignment.
|
|
470
470
|
*/
|
|
471
471
|
recycle(type: ValueType, value: number | bigint | string | boolean | MatrixData | RangeData | ColourData | SplitData | ChartData | IpCidrData | SymbolicNode, unit?: string): void;
|
|
472
|
+
/**
|
|
473
|
+
* A fresh Value carrying everything this one does: the payload, the unit,
|
|
474
|
+
* the cached number and every sidecar, present or future.
|
|
475
|
+
*
|
|
476
|
+
* The inverse of {@link recycle}, and written as a whole-object copy rather
|
|
477
|
+
* than a list of fields on purpose. `persistentValue()` used to name the
|
|
478
|
+
* sidecars it copied, and the two it did not name (`decimalPlaces`,
|
|
479
|
+
* `timedOut`) were silently dropped by every viewport evaluation, so
|
|
480
|
+
* `3.14159 to 4 dp` displayed as 3.14 there and as 3.1416 on a single line.
|
|
481
|
+
* A sidecar added later is carried here without this method knowing its
|
|
482
|
+
* name, which closes that class of bug rather than the one instance.
|
|
483
|
+
*
|
|
484
|
+
* Shallow, as the old copy was: a matrix, a chart or a symbolic tree is
|
|
485
|
+
* shared with the original, which is fine because a Value's payload is
|
|
486
|
+
* treated as immutable everywhere outside the arena's own `recycle()`.
|
|
487
|
+
*
|
|
488
|
+
* @returns A new Value equal to this one in every field.
|
|
489
|
+
*/
|
|
490
|
+
clone(): Value;
|
|
472
491
|
isNumber(): this is Value & {
|
|
473
492
|
value: number;
|
|
474
493
|
};
|
|
@@ -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-Bm4OYmw8.js';
|
|
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-Bm4OYmw8.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Structured errors for the off-main-thread worker harness, and the pair of
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {a}from'./chunk-RAF57WYO.js';import {m,n,h as h$1}from'./chunk-
|
|
2
|
-
`),r=new Array(t.length);for(let s=0;s<t.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:a(t[s]),text:t[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:t[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let n=[],t=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a$1=[];for(let o of s.insertLines){let c=this.nextLineId++;a$1.push(c),n.push(c),this.lines.set(c,{lineId:c,textHash: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$1)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a$1);for(let o of l)t.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:n,removed:t}}insertLines(e,n){let t={startLine:e,deleteCount:0,insertLines:n};return this.applyChanges([t]).inserted}deleteLines(e,n){let t={startLine:e,deleteCount:n-e+1,insertLines:[]};return this.applyChanges([t]).removed}editLine(e,n){let t=this.getLineAt(e);if(!t)return false;let r=a(n);return r===t.textHash?false:(t.text=n,t.textHash=r,t.expressions=[],t.bytecodes=[],t.results=[],t.result=null,t.inlineSolveCount=0,t.dirty=true,this.dirtyLineIds.add(t.lineId),t.isEmpty=n.trim().length===0,true)}getLineAt(e){let n=e-1,t=this.orderTree.getAt(n);if(t!==void 0)return this.lines.get(t)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let n=1;for(let t of this.orderTree)this._positionCache.set(t,n++);return this._positionCache.get(e)??-1}getVisibleLines(e,n){let t=this.orderTree.getRange(e-1,n-1),r=[];for(let s of t){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 n of this.lines.values())n.dirty&&e.push(n);return e}hasAnyDirtyLineBefore(e){for(let n of this.dirtyLineIds){let t=this.getLinePosition(n);if(t>=1&&t<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let n of this.dirtyLineIds){let t=this.lines.get(n);if(!t||!t.isVariableDef)continue;let r=this.getLinePosition(n);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,n){let t=this.lines.get(e);return t!==void 0&&t.textHash===n}markClean(e){let n=this.lines.get(e);n&&(n.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let n=this.getLineAt(e);n&&(n.dirty=true,this.dirtyLineIds.add(n.lineId));}markDirty(e){let n=this.lines.get(e);n&&(n.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,n,t,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=n,o.result=n[0]?.[0]??null,o.bytecodes=t,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,n,t,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=n,l.bytecodes=t,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 n=this.lines.get(e);n&&(yield n);}}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(){if(this.worker)return this.worker;let e=h$1();if(e===null)throw new Error("no engine worker factory registered, so compilation stays on the main thread");return this.worker=e(),this.worker.onmessage=n=>{let t=n.data;if(!t||t.type!=="COMPILE_RESULT")return;let r=this.pending.get(t.id);if(!r)return;this.pending.delete(t.id);let s=[];for(let i of t.results)s.push(this.reconstructResult(i));r.resolve(s);},this.worker.onerror=n=>{for(let[t,r]of this.pending)r.reject(new Error(`Compilation worker error: ${n.message}`)),this.pending.delete(t);},this.worker}async compileBatch(e){if(e.length===0)return [];let n=this.ensureWorker(),t=this.nextId++;return new Promise((r,s)=>{this.pending.set(t,{resolve:r,reject:s}),n.postMessage({type:"COMPILE_BATCH",id:t,items:e});})}storeResults(e,n){let t=new Map;for(let i of e){if(i.error)continue;let a=n.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=t.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},t.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 t){if(a.bytecodes.length===0)continue;let o=n.getLineById(i)?.inlineSolveCount??0;n.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 n=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),t=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:n,numbers:t,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,J=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,n){return {startLine:e*U+1,endLine:Math.min((e+1)*U,n)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,n){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let t=n.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(t),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-J),c=Math.min(i,s+J);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,n,t);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,n,t);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,n,t);}getPreloadTargets(e,n){let t=this.savedDirection;if(!t)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(n.lineCount),l=[];if(t==="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,n.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=n.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=c$1.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,n,t){let r=u.pageRange(e,t);for(let s=r.startLine;s<=r.endLine;s++){let i=n.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,n,t){let r=u.pageRange(e,t);for(let s=r.startLine;s<=r.endLine;s++){let i=n.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,n.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,n,t){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=n,this.dag=n.getDag(),this.checkpointer=t??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=J$1.subscribe(r=>{for(let s of this.dag.getAffectedLines(K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,n){this.engine.setKeystrokeSignal(n??null),h();try{this.reseedAccumulators();let t=[],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);t.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:t,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),i();}}backgroundCompile(e){let n=[],t=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=t;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);n.push(a);}return n}dispatchBackgroundCompiles(e){let n=this.collectInvisibleCompileTargets(e);n.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(n).then(t=>{this.compilationWorker.storeResults(t,this.doc);}).catch(t=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let n={startLine:1,endLine:this.doc.lineCount};return this.evaluate(n,e)}setViewport(e,n){if(this.engine.setKeystrokeSignal(n??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,n);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),i();}}applyTransaction(e){let n=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)n.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let t=new Set;for(let s of n){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&t.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of t)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 n=this.doc.lineCount;for(let t=1;t<=n;t++){let r=this.dag.getWrites(t);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(t);break}}}}collectEvalResults(e,n){let t=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(n,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);t.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:t,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,n,t){let r={lineId:e.lineId,lineNumber:n};if(e.isEmpty||m(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?t?this.evaluateTier1(e,n,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,n,s,i,r):t&&e.bytecodes.length>0?this.evaluateTier2(e,n,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,n,t,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 t){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(n,y);b=[m],d=m,L=this.engine.getLineCache().get(n,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([P$1("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 C of x)l.add(C);for(let C of E)o.add(C);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof b$2&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let C of x)l.add(C);if(Array.isArray(E))for(let C of E)o.add(C);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,t,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=t):this.doc.updateLineResult(e.lineId,i,a,t,h,v,c,r),this.dag.registerLine(n,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(n,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,n,t){if(e.bytecodes.length===0)return {...t,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,n);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([P$1("exec_failed",c)]);}return this.dag.registerLine(n,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...t,tier:2,result:s,results:r,error:i}}evaluateTier3(e,n,t,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of t)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,n),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,t,i,g,h,o,r),this.dag.registerLine(n,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(n,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 n=this.pageManager.getPreloadTargets(e,this.doc);n.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(n).then(t=>{this.compilationWorker.storeResults(t,this.doc);}).catch(t=>{}));}collectInvisibleCompileTargets(e){let n=[],t=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=t;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||m(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&n.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return n}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let n=e.text.trim();if(n.length===0)return {expressions:[],inlineSolveCount:0};let t=c$1.findInlineSolves(e.text);return t.length>0?{expressions:t.map(r=>r.expression),inlineSolveCount:t.length}:{expressions:[n],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,n$1={inputType:"markdown"}){let t=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=n(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(t);}}export{R as a,Y as b,w as c,ie as d};//# sourceMappingURL=chunk-IJE4AEDX.js.map
|
|
3
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {a}from'./chunk-RAF57WYO.js';import {m,n,h as h$1}from'./chunk-ITH2RLRG.js';import {b as b$1}from'./chunk-76F3LCIL.js';import {J as J$1,K}from'./chunk-INMJ7ZXL.js';import {h,i,P as P$1}from'./chunk-O7HF345B.js';import {b}from'./chunk-AENL3Z66.js';import {c as c$1}from'./chunk-6NL7RBAG.js';import {c,b as b$2}from'./chunk-6G2NES2I.js';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,n){let[t,r]=I(this.root,e);this.root=S(S(t,te(n)),r);}deleteAt(e){if(e<0||e>=(this.root?.size??0))return;let[n,t]=I(this.root,e),[r,s]=I(t,1),i=r?r.lineId:void 0;return this.root=S(n,s),i}spliceAt(e,n,t){let r=Math.max(0,e),s=Math.min(Math.max(0,n),(this.root?.size??0)-r),[i,a]=I(this.root,r),[l,o]=I(a,s),c=ne(l),d=B(t,0,t.length);return this.root=S(S(i,d),o),c}replaceAll(e){this.root=B(e,0,e.length);}getRange(e,n){let t=Math.max(0,e),r=Math.min((this.root?.size??0)-1,n);if(t>r)return [];let s=[];return this.collectRange(this.root,t,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,n){let t=e.left?e.left.size:0;return n<t?this.nodeAt(e.left,n):n===t?e:this.nodeAt(e.right,n-t-1)}collectRange(e,n,t,r,s){if(!e)return;let i=e.left?e.left.size:0,a=r+i;a>n&&e.left&&this.collectRange(e.left,n,t,r,s),a>=n&&a<=t&&s.push(e.lineId),a<t&&e.right&&this.collectRange(e.right,n,t,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 S(u,e){return u?e?u.priority>e.priority?(u.right=S(u.right,e),T(u),u):(e.left=S(u,e.left),T(e),e):u:e}function I(u,e){if(!u)return [null,null];let n=u.left?u.left.size:0;if(e<=n){let[t,r]=I(u.left,e);return u.left=r,T(u),[t,u]}else {let[t,r]=I(u.right,e-n-1);return u.right=t,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,n){if(e>=n)return null;let t=Math.floor((e+n)/2),r=re(t);return {lineId:u[t],size:n-e,priority:r,left:B(u,e,t),right:B(u,t+1,n)}}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=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(b$1(e,this.maxLines)>this.maxLines)throw 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 t=e.split(`
|
|
2
|
+
`),r=new Array(t.length);for(let s=0;s<t.length;s++){let i=this.nextLineId++;r[s]=i,this.lines.set(i,{lineId:i,textHash:a(t[s]),text:t[s],expressions:[],bytecodes:[],reads:[],writes:[],results:[],result:null,dirty:true,isVariableDef:false,isEmpty:t[s].trim().length===0,inlineSolveCount:0});}this.orderTree.replaceAll(r);for(let s of r)this.dirtyLineIds.add(s);}applyChanges(e){let n=[],t=[],r=[...e].sort((s,i)=>i.startLine-s.startLine);for(let s of r){let i=s.startLine-1,a$1=[];for(let o of s.insertLines){let c=this.nextLineId++;a$1.push(c),n.push(c),this.lines.set(c,{lineId:c,textHash: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$1)this.dirtyLineIds.add(o);let l=this.orderTree.spliceAt(i,s.deleteCount,a$1);for(let o of l)t.push(o),this.lines.delete(o),this.dirtyLineIds.delete(o);}return this._positionCache=null,{inserted:n,removed:t}}insertLines(e,n){let t={startLine:e,deleteCount:0,insertLines:n};return this.applyChanges([t]).inserted}deleteLines(e,n){let t={startLine:e,deleteCount:n-e+1,insertLines:[]};return this.applyChanges([t]).removed}editLine(e,n){let t=this.getLineAt(e);if(!t)return false;let r=a(n);return r===t.textHash?false:(t.text=n,t.textHash=r,t.expressions=[],t.bytecodes=[],t.results=[],t.result=null,t.inlineSolveCount=0,t.dirty=true,this.dirtyLineIds.add(t.lineId),t.isEmpty=n.trim().length===0,true)}getLineAt(e){let n=e-1,t=this.orderTree.getAt(n);if(t!==void 0)return this.lines.get(t)}getLinePosition(e){if(this._positionCache)return this._positionCache.get(e)??-1;this._positionCache=new Map;let n=1;for(let t of this.orderTree)this._positionCache.set(t,n++);return this._positionCache.get(e)??-1}getVisibleLines(e,n){let t=this.orderTree.getRange(e-1,n-1),r=[];for(let s of t){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 n of this.lines.values())n.dirty&&e.push(n);return e}hasAnyDirtyLineBefore(e){for(let n of this.dirtyLineIds){let t=this.getLinePosition(n);if(t>=1&&t<e)return true}return false}hasAnyDirtyVariableDefLineBefore(e){for(let n of this.dirtyLineIds){let t=this.lines.get(n);if(!t||!t.isVariableDef)continue;let r=this.getLinePosition(n);if(r>=1&&r<e)return true}return false}get dirtyCount(){return this.dirtyLineIds.size}isBytecodeValid(e,n){let t=this.lines.get(e);return t!==void 0&&t.textHash===n}markClean(e){let n=this.lines.get(e);n&&(n.dirty=false,this.dirtyLineIds.delete(e));}markDirtyByLineNumber(e){let n=this.getLineAt(e);n&&(n.dirty=true,this.dirtyLineIds.add(n.lineId));}markDirty(e){let n=this.lines.get(e);n&&(n.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,n,t,r,s,i,a,l=0){let o=this.lines.get(e);o&&(o.results=n,o.result=n[0]?.[0]??null,o.bytecodes=t,o.expressions=r,o.reads=s,o.writes=i,o.isVariableDef=a,o.inlineSolveCount=l,o.dirty=false,this.dirtyLineIds.delete(e));}updateLineCompiled(e,n,t,r,s,i,a=0){let l=this.lines.get(e);l&&(l.expressions=n,l.bytecodes=t,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 n=this.lines.get(e);n&&(yield n);}}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(){if(this.worker)return this.worker;let e=h$1();if(e===null)throw new Error("no engine worker factory registered, so compilation stays on the main thread");return this.worker=e(),this.worker.onmessage=n=>{let t=n.data;if(!t||t.type!=="COMPILE_RESULT")return;let r=this.pending.get(t.id);if(!r)return;this.pending.delete(t.id);let s=[];for(let i of t.results)s.push(this.reconstructResult(i));r.resolve(s);},this.worker.onerror=n=>{for(let[t,r]of this.pending)r.reject(new Error(`Compilation worker error: ${n.message}`)),this.pending.delete(t);},this.worker}async compileBatch(e){if(e.length===0)return [];let n=this.ensureWorker(),t=this.nextId++;return new Promise((r,s)=>{this.pending.set(t,{resolve:r,reject:s}),n.postMessage({type:"COMPILE_BATCH",id:t,items:e});})}storeResults(e,n){let t=new Map;for(let i of e){if(i.error)continue;let a=n.getLineById(i.lineId);if(!a||a.textHash!==i.compiledAgainstHash)continue;let l=t.get(i.lineId);l||(l={bytecodes:[],reads:new Set,writes:new Set,isVariableDef:false,expressions:a.expressions.length>0?[...a.expressions]:[],textHash:i.compiledAgainstHash},t.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 t){if(a.bytecodes.length===0)continue;let o=n.getLineById(i)?.inlineSolveCount??0;n.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 n=e.opcodesLength>0?new Uint8Array(e.opcodesBuffer,0,e.opcodesLength):new Uint8Array(0),t=e.numbersLength>0?new Float64Array(e.numbersBuffer,0,e.numbersLength):new Float64Array(0),r={opcodes:n,numbers:t,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,J=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,n){return {startLine:e*U+1,endLine:Math.min((e+1)*U,n)}}detectDirection(e){return this.lastViewportStart===null?null:e.startLine>this.lastViewportStart?"down":e.startLine<this.lastViewportStart?"up":null}maintainAfterEval(e,n){this.savedDirection=this.detectDirection(e),this.lastViewportStart=e.startLine;let t=n.lineCount,r=u.pageForLine(e.startLine),s=u.pageForLine(e.endLine),i=u.pageForLine(t),a=Math.max(0,r-k),l=Math.min(i,s+k),o=Math.max(0,r-J),c=Math.min(i,s+J);for(let h=a;h<=l;h++)this.touchPage(h);for(let h=o;h<=c;h++)h>=a&&h<=l||this.evictPageResults(h,n,t);let d=o-1,p=Math.max(0,d-X+1);for(let h=p;h<=d;h++)this.evictPageBytecode(h,n,t);let f=c+1,g=Math.min(i,f+X-1);for(let h=f;h<=g;h++)this.evictPageBytecode(h,n,t);}getPreloadTargets(e,n){let t=this.savedDirection;if(!t)return [];let r=[],s=u.pageForLine(e.endLine),i=u.pageForLine(e.startLine),a=u.pageForLine(n.lineCount),l=[];if(t==="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,n.lineCount);for(let d=c.startLine;d<=c.endLine;d++){let p=n.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=c$1.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,n,t){let r=u.pageRange(e,t);for(let s=r.startLine;s<=r.endLine;s++){let i=n.getLineAt(s);i&&!i.isVariableDef&&i.results.length>0&&(i.results=[],i.result=null);}}evictPageBytecode(e,n,t){let r=u.pageRange(e,t);for(let s=r.startLine;s<=r.endLine;s++){let i=n.getLineAt(s);!i||i.isVariableDef||(i.bytecodes.length>0||i.results.length>0)&&(i.bytecodes=[],i.results=[],i.result=null,n.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,n,t){this.compilationWorker=null;this.globalUnsubscribe=null;this.doc=e,this.engine=n,this.dag=n.getDag(),this.checkpointer=t??null,this.pageManager=new H,this.engine.setDocumentModel(this.doc),this.globalUnsubscribe=J$1.subscribe(r=>{for(let s of this.dag.getAffectedLines(K(r)))this.doc.markDirtyByLineNumber(s);});}evaluate(e,n){this.engine.setKeystrokeSignal(n??null),h();try{this.reseedAccumulators();let t=[],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);t.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:t,resultMap:r,tierCounts:s}}finally{this.engine.setKeystrokeSignal(null),i();}}backgroundCompile(e){let n=[],t=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=t;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);n.push(a);}return n}dispatchBackgroundCompiles(e){let n=this.collectInvisibleCompileTargets(e);n.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(n).then(t=>{this.compilationWorker.storeResults(t,this.doc);}).catch(t=>{}));}terminateWorker(){this.compilationWorker&&(this.compilationWorker.terminate(),this.compilationWorker=null),this.globalUnsubscribe&&(this.globalUnsubscribe(),this.globalUnsubscribe=null);}getDoc(){return this.doc}evaluateAll(e){let n={startLine:1,endLine:this.doc.lineCount};return this.evaluate(n,e)}setViewport(e,n){if(this.engine.setKeystrokeSignal(n??null),e.startLine>1&&this.hasDirtyLinesBefore(e.startLine))return this.checkpointer?.clear(),this.evaluate(e,n);this.pageManager.maintainAfterEval(e,this.doc),this.preloadNextPages(e),this.restoreTo(e.startLine-1),h();try{return this.collectEvalResults(e.startLine,e.endLine)}finally{this.engine.setKeystrokeSignal(null),i();}}applyTransaction(e){let n=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)n.add(o);this.dag.removeLine(a),this.engine.getLineCache().removeAllForLine(a);}let t=new Set;for(let s of n){let i=this.dag.getAffectedLines(s);for(let a of i){let l=this.doc.getLineAt(a);l&&t.add(l.lineId);}}let r=this.doc.applyChanges(e);this.checkpointer?.clear();for(let s of t)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 n=this.doc.lineCount;for(let t=1;t<=n;t++){let r=this.dag.getWrites(t);if(r.size!==0){for(let s of r)if(e.has(s)){this.doc.markDirtyByLineNumber(t);break}}}}collectEvalResults(e,n){let t=[],r=new Map,s={tier1:0,tier2:0,tier3:0,skipped:0},i=this.doc.lineCount,a=Math.min(n,i);for(let l=e;l<=a;l++){let o=this.doc.getLineAt(l);if(!o)continue;let c=this.evaluateSingleLine(o,l,true);t.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:t,resultMap:r,tierCounts:s}}hasDirtyLinesBefore(e){return this.doc.hasAnyDirtyVariableDefLineBefore(e)}evaluateSingleLine(e,n,t){let r={lineId:e.lineId,lineNumber:n};if(e.isEmpty||m(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?t?this.evaluateTier1(e,n,s,i,r):e.bytecodes.length>0&&e.bytecodes.length===s.length&&!e.isVariableDef?{...r,tier:0,result:null,error:null}:this.evaluateTier3(e,n,s,i,r):t&&e.bytecodes.length>0?this.evaluateTier2(e,n,r):{...r,tier:0,result:null,error:null}}evaluateTier1(e,n,t,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 t){if(!y.trim())continue;let b=null,L;try{let m=this.engine.evaluateLine(n,y);b=[m],d=m,L=this.engine.getLineCache().get(n,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([P$1("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 C of x)l.add(C);for(let C of E)o.add(C);E.length>0&&(c=!0);}catch(m){if(a.push({opcodes:new Uint8Array(0),numbers:new Float64Array(0),strings:[],hasAsync:false}),m instanceof b$2&&m.context){let x=m.context.reads,E=m.context.writes;if(Array.isArray(x))for(let C of x)l.add(C);if(Array.isArray(E))for(let C of E)o.add(C);}}}let h=[...l],v=[...o];return f||g?(this.doc.updateLineCompiled(e.lineId,t,a,h,v,c,r),e.results=i,e.result=i[0]?.[0]??null,e.inlineSolveCount=r,e.expressions=t):this.doc.updateLineResult(e.lineId,i,a,t,h,v,c,r),this.dag.registerLine(n,h,v),this.checkpointer&&v.length>0&&!f&&!g&&this.checkpointer.snapshot(n,e.lineId,v),{...s,tier:1,result:d,results:i,error:p}}evaluateTier2(e,n,t){if(e.bytecodes.length===0)return {...t,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,n);s=o,r.push([o]);}catch(o){let c=o instanceof Error?o.message:String(o);i||(i=c),a=true,r.push([P$1("exec_failed",c)]);}return this.dag.registerLine(n,e.reads,e.writes),e.results=r,e.result=r[0]?.[0]??null,a&&this.doc.markDirty(e.lineId),{...t,tier:2,result:s,results:r,error:i}}evaluateTier3(e,n,t,r,s){let i=[],a=new Set,l=new Set,o=false,c=null,d=null,p=false,f=false;for(let v of t)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,n),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,t,i,g,h,o,r),this.dag.registerLine(n,g,h),o&&c&&!p&&!f&&(e.results=[[c]],e.result=c,this.doc.markClean(e.lineId),this.checkpointer&&this.checkpointer.snapshot(n,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 n=this.pageManager.getPreloadTargets(e,this.doc);n.length!==0&&(this.compilationWorker||(this.compilationWorker=new A),this.compilationWorker.compileBatch(n).then(t=>{this.compilationWorker.storeResults(t,this.doc);}).catch(t=>{}));}collectInvisibleCompileTargets(e){let n=[],t=this.doc.lineCount,r=e.endLine+1;for(let s=r;s<=t;s++){let i=this.doc.getLineAt(s);if(!i||!i.dirty||i.bytecodes.length>0&&!i.isVariableDef||i.isEmpty||m(i.text))continue;let{expressions:a}=this.extractExpressions(i);if(a.length!==0)for(let l of a)l.trim()&&n.push({lineId:i.lineId,expression:l,textHash:i.textHash});}return n}extractExpressions(e){if(e.expressions.length>0)return {expressions:e.expressions,inlineSolveCount:e.inlineSolveCount};let n=e.text.trim();if(n.length===0)return {expressions:[],inlineSolveCount:0};let t=c$1.findInlineSolves(e.text);return t.length>0?{expressions:t.map(r=>r.expression),inlineSolveCount:t.length}:{expressions:[n],inlineSolveCount:0}}};function ee(u){return typeof u.unit=="string"?u.unit:String(u.value)}function ie(u,e,n$1={inputType:"markdown"}){let t=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=n(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(t);}}export{R as a,Y as b,w as c,ie as d};//# sourceMappingURL=chunk-24OW3AAU.js.map
|
|
3
|
+
//# sourceMappingURL=chunk-24OW3AAU.js.map
|