solve-engine 1.0.0-beta.0 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/dist/BytecodeBuilder-3egMyuDi.d.cts +274 -0
  2. package/dist/BytecodeBuilder-3egMyuDi.d.ts +274 -0
  3. package/dist/Configuration-fVpd-HC-.d.cts +228 -0
  4. package/dist/Configuration-fVpd-HC-.d.ts +228 -0
  5. package/dist/EngineError-DvPSnhZi.d.cts +304 -0
  6. package/dist/EngineError-DvPSnhZi.d.ts +304 -0
  7. package/dist/Lexer-BJdhlnej.d.cts +531 -0
  8. package/dist/Lexer-D9l4Yrk2.d.ts +531 -0
  9. package/dist/NormalizerRule-BrVoVjmP.d.cts +163 -0
  10. package/dist/NormalizerRule-CEjf1FyD.d.ts +163 -0
  11. package/dist/PackageRegistry-D-Tv_7ca.d.cts +2572 -0
  12. package/dist/PackageRegistry-DaH4aIKP.d.ts +2572 -0
  13. package/dist/Parselet-CK8cQu2a.d.cts +299 -0
  14. package/dist/Parselet-ConOIdRO.d.ts +299 -0
  15. package/dist/ScopeManager-B5k0nk05.d.ts +559 -0
  16. package/dist/ScopeManager-CKfQtl7l.d.cts +559 -0
  17. package/dist/Token-0jpvUdPY.d.cts +245 -0
  18. package/dist/Token-0jpvUdPY.d.ts +245 -0
  19. package/dist/VMCheckpoints-BmDwIXgK.d.ts +171 -0
  20. package/dist/VMCheckpoints-CqFuLwrT.d.cts +171 -0
  21. package/dist/Value-KtAQNHur.d.cts +295 -0
  22. package/dist/Value-KtAQNHur.d.ts +295 -0
  23. package/dist/chunk-2RWAXT6O.js +3 -0
  24. package/dist/chunk-2RWAXT6O.js.map +1 -0
  25. package/dist/chunk-34RRD7PC.js +1492 -0
  26. package/dist/chunk-34RRD7PC.js.map +1 -0
  27. package/dist/chunk-3PPFLFH4.js +5097 -0
  28. package/dist/chunk-3PPFLFH4.js.map +1 -0
  29. package/dist/chunk-3VGDNEE3.js +84 -0
  30. package/dist/chunk-3VGDNEE3.js.map +1 -0
  31. package/dist/chunk-3YNVWKR2.cjs +370 -0
  32. package/dist/chunk-3YNVWKR2.cjs.map +1 -0
  33. package/dist/chunk-47LRVGOT.cjs +316 -0
  34. package/dist/chunk-47LRVGOT.cjs.map +1 -0
  35. package/dist/chunk-4MG4XKO2.js +1644 -0
  36. package/dist/chunk-4MG4XKO2.js.map +1 -0
  37. package/dist/chunk-4QADQTWS.js +2392 -0
  38. package/dist/chunk-4QADQTWS.js.map +1 -0
  39. package/dist/chunk-53B6KDDJ.cjs +1651 -0
  40. package/dist/chunk-53B6KDDJ.cjs.map +1 -0
  41. package/dist/chunk-5X2PTP6F.cjs +104 -0
  42. package/dist/chunk-5X2PTP6F.cjs.map +1 -0
  43. package/dist/chunk-5YEMOYSE.js +264 -0
  44. package/dist/chunk-5YEMOYSE.js.map +1 -0
  45. package/dist/chunk-64W6GLLZ.js +481 -0
  46. package/dist/chunk-64W6GLLZ.js.map +1 -0
  47. package/dist/chunk-6BKTCEUP.cjs +233 -0
  48. package/dist/chunk-6BKTCEUP.cjs.map +1 -0
  49. package/dist/chunk-6NTVRDQV.cjs +1642 -0
  50. package/dist/chunk-6NTVRDQV.cjs.map +1 -0
  51. package/dist/chunk-6RDSQURE.js +290 -0
  52. package/dist/chunk-6RDSQURE.js.map +1 -0
  53. package/dist/chunk-75JP4BZX.js +93 -0
  54. package/dist/chunk-75JP4BZX.js.map +1 -0
  55. package/dist/chunk-B7LXJ6LC.cjs +36 -0
  56. package/dist/chunk-B7LXJ6LC.cjs.map +1 -0
  57. package/dist/chunk-BVAR5J2F.js +257 -0
  58. package/dist/chunk-BVAR5J2F.js.map +1 -0
  59. package/dist/chunk-C4XZV6E7.cjs +269 -0
  60. package/dist/chunk-C4XZV6E7.cjs.map +1 -0
  61. package/dist/chunk-CCJPSHGI.cjs +40 -0
  62. package/dist/chunk-CCJPSHGI.cjs.map +1 -0
  63. package/dist/chunk-CLL7RUQV.cjs +316 -0
  64. package/dist/chunk-CLL7RUQV.cjs.map +1 -0
  65. package/dist/chunk-DM3LMRBC.js +329 -0
  66. package/dist/chunk-DM3LMRBC.js.map +1 -0
  67. package/dist/chunk-DUEZFTK2.js +38 -0
  68. package/dist/chunk-DUEZFTK2.js.map +1 -0
  69. package/dist/chunk-EBSPLUW4.cjs +489 -0
  70. package/dist/chunk-EBSPLUW4.cjs.map +1 -0
  71. package/dist/chunk-EHAHVROS.cjs +261 -0
  72. package/dist/chunk-EHAHVROS.cjs.map +1 -0
  73. package/dist/chunk-EIGTWK5N.js +167 -0
  74. package/dist/chunk-EIGTWK5N.js.map +1 -0
  75. package/dist/chunk-EPOXXJBK.js +96 -0
  76. package/dist/chunk-EPOXXJBK.js.map +1 -0
  77. package/dist/chunk-FEAIOR7N.cjs +91 -0
  78. package/dist/chunk-FEAIOR7N.cjs.map +1 -0
  79. package/dist/chunk-G535KJEG.js +312 -0
  80. package/dist/chunk-G535KJEG.js.map +1 -0
  81. package/dist/chunk-GCM5JHMX.js +88 -0
  82. package/dist/chunk-GCM5JHMX.js.map +1 -0
  83. package/dist/chunk-GOLDJNMZ.js +368 -0
  84. package/dist/chunk-GOLDJNMZ.js.map +1 -0
  85. package/dist/chunk-GW32KPCU.cjs +360 -0
  86. package/dist/chunk-GW32KPCU.cjs.map +1 -0
  87. package/dist/chunk-HTXVVJRA.cjs +1549 -0
  88. package/dist/chunk-HTXVVJRA.cjs.map +1 -0
  89. package/dist/chunk-HWSZJQCI.js +311 -0
  90. package/dist/chunk-HWSZJQCI.js.map +1 -0
  91. package/dist/chunk-IF532O7C.js +101 -0
  92. package/dist/chunk-IF532O7C.js.map +1 -0
  93. package/dist/chunk-J73SJHR3.cjs +2415 -0
  94. package/dist/chunk-J73SJHR3.cjs.map +1 -0
  95. package/dist/chunk-JBSYC7BB.cjs +7473 -0
  96. package/dist/chunk-JBSYC7BB.cjs.map +1 -0
  97. package/dist/chunk-KVILKGMS.js +228 -0
  98. package/dist/chunk-KVILKGMS.js.map +1 -0
  99. package/dist/chunk-LIPPNDBE.js +258 -0
  100. package/dist/chunk-LIPPNDBE.js.map +1 -0
  101. package/dist/chunk-LR7YASZF.cjs +172 -0
  102. package/dist/chunk-LR7YASZF.cjs.map +1 -0
  103. package/dist/chunk-M4N5GA5Z.cjs +309 -0
  104. package/dist/chunk-M4N5GA5Z.cjs.map +1 -0
  105. package/dist/chunk-M5LX5AOO.js +7459 -0
  106. package/dist/chunk-M5LX5AOO.js.map +1 -0
  107. package/dist/chunk-MZOVP3WI.cjs +96 -0
  108. package/dist/chunk-MZOVP3WI.cjs.map +1 -0
  109. package/dist/chunk-N5YFR4UP.cjs +10 -0
  110. package/dist/chunk-N5YFR4UP.cjs.map +1 -0
  111. package/dist/chunk-NGBBNL4K.cjs +4 -0
  112. package/dist/chunk-NGBBNL4K.cjs.map +1 -0
  113. package/dist/chunk-NH2O2AUR.js +146 -0
  114. package/dist/chunk-NH2O2AUR.js.map +1 -0
  115. package/dist/chunk-NLNDMWZC.js +31 -0
  116. package/dist/chunk-NLNDMWZC.js.map +1 -0
  117. package/dist/chunk-NMCRQP3Z.cjs +778 -0
  118. package/dist/chunk-NMCRQP3Z.cjs.map +1 -0
  119. package/dist/chunk-NMD5VRN4.cjs +1327 -0
  120. package/dist/chunk-NMD5VRN4.cjs.map +1 -0
  121. package/dist/chunk-OC6LTXYS.cjs +286 -0
  122. package/dist/chunk-OC6LTXYS.cjs.map +1 -0
  123. package/dist/chunk-OT6OJY7C.cjs +114 -0
  124. package/dist/chunk-OT6OJY7C.cjs.map +1 -0
  125. package/dist/chunk-PFSDGGYL.js +8 -0
  126. package/dist/chunk-PFSDGGYL.js.map +1 -0
  127. package/dist/chunk-QNJ4ACRT.cjs +155 -0
  128. package/dist/chunk-QNJ4ACRT.cjs.map +1 -0
  129. package/dist/chunk-QWY3VEZN.js +1637 -0
  130. package/dist/chunk-QWY3VEZN.js.map +1 -0
  131. package/dist/chunk-RFYD5TJE.js +111 -0
  132. package/dist/chunk-RFYD5TJE.js.map +1 -0
  133. package/dist/chunk-RIN643A3.js +354 -0
  134. package/dist/chunk-RIN643A3.js.map +1 -0
  135. package/dist/chunk-RZCWSXTA.cjs +5122 -0
  136. package/dist/chunk-RZCWSXTA.cjs.map +1 -0
  137. package/dist/chunk-SDGRK7EP.js +774 -0
  138. package/dist/chunk-SDGRK7EP.js.map +1 -0
  139. package/dist/chunk-VEKIWQ3F.cjs +39 -0
  140. package/dist/chunk-VEKIWQ3F.cjs.map +1 -0
  141. package/dist/chunk-WQTTOGXC.cjs +99 -0
  142. package/dist/chunk-WQTTOGXC.cjs.map +1 -0
  143. package/dist/chunk-X6K3HUOY.cjs +86 -0
  144. package/dist/chunk-X6K3HUOY.cjs.map +1 -0
  145. package/dist/chunk-XJCMXB2E.cjs +333 -0
  146. package/dist/chunk-XJCMXB2E.cjs.map +1 -0
  147. package/dist/chunk-XVWCOTR6.js +1324 -0
  148. package/dist/chunk-XVWCOTR6.js.map +1 -0
  149. package/dist/chunk-YLJ4XMA6.js +33 -0
  150. package/dist/chunk-YLJ4XMA6.js.map +1 -0
  151. package/dist/chunk-Z2XP767T.cjs +35 -0
  152. package/dist/chunk-Z2XP767T.cjs.map +1 -0
  153. package/dist/chunk-Z4X2RWOF.js +37 -0
  154. package/dist/chunk-Z4X2RWOF.js.map +1 -0
  155. package/dist/constants.cjs +22 -0
  156. package/dist/constants.cjs.map +1 -0
  157. package/dist/constants.d.cts +12 -0
  158. package/dist/constants.d.ts +12 -0
  159. package/dist/constants.js +5 -0
  160. package/dist/constants.js.map +1 -0
  161. package/dist/engine.cjs +79 -0
  162. package/dist/engine.cjs.map +1 -0
  163. package/dist/engine.d.cts +587 -0
  164. package/dist/engine.d.ts +587 -0
  165. package/dist/engine.js +34 -0
  166. package/dist/engine.js.map +1 -0
  167. package/dist/errors.cjs +81 -0
  168. package/dist/errors.cjs.map +1 -0
  169. package/dist/errors.d.cts +95 -0
  170. package/dist/errors.d.ts +95 -0
  171. package/dist/errors.js +4 -0
  172. package/dist/errors.js.map +1 -0
  173. package/dist/format.cjs +171 -0
  174. package/dist/format.cjs.map +1 -0
  175. package/dist/format.d.cts +51 -0
  176. package/dist/format.d.ts +51 -0
  177. package/dist/format.js +168 -0
  178. package/dist/format.js.map +1 -0
  179. package/dist/index.cjs +97 -0
  180. package/dist/index.cjs.map +1 -0
  181. package/dist/index.d.cts +152 -0
  182. package/dist/index.d.ts +152 -0
  183. package/dist/index.js +75 -0
  184. package/dist/index.js.map +1 -0
  185. package/dist/language.cjs +308 -0
  186. package/dist/language.cjs.map +1 -0
  187. package/dist/language.d.cts +110 -0
  188. package/dist/language.d.ts +110 -0
  189. package/dist/language.js +287 -0
  190. package/dist/language.js.map +1 -0
  191. package/dist/lexer.cjs +64 -0
  192. package/dist/lexer.cjs.map +1 -0
  193. package/dist/lexer.d.cts +56 -0
  194. package/dist/lexer.d.ts +56 -0
  195. package/dist/lexer.js +11 -0
  196. package/dist/lexer.js.map +1 -0
  197. package/dist/normalizer.cjs +40 -0
  198. package/dist/normalizer.cjs.map +1 -0
  199. package/dist/normalizer.d.cts +364 -0
  200. package/dist/normalizer.d.ts +364 -0
  201. package/dist/normalizer.js +11 -0
  202. package/dist/normalizer.js.map +1 -0
  203. package/dist/packages.cjs +121 -0
  204. package/dist/packages.cjs.map +1 -0
  205. package/dist/packages.d.cts +691 -0
  206. package/dist/packages.d.ts +691 -0
  207. package/dist/packages.js +24 -0
  208. package/dist/packages.js.map +1 -0
  209. package/dist/parser.cjs +55 -0
  210. package/dist/parser.cjs.map +1 -0
  211. package/dist/parser.d.cts +46 -0
  212. package/dist/parser.d.ts +46 -0
  213. package/dist/parser.js +10 -0
  214. package/dist/parser.js.map +1 -0
  215. package/dist/pipeline-CrsRPmsv.d.ts +285 -0
  216. package/dist/pipeline-DPUQt7yL.d.cts +285 -0
  217. package/dist/resolvers.cjs +13 -0
  218. package/dist/resolvers.cjs.map +1 -0
  219. package/dist/resolvers.d.cts +111 -0
  220. package/dist/resolvers.d.ts +111 -0
  221. package/dist/resolvers.js +4 -0
  222. package/dist/resolvers.js.map +1 -0
  223. package/dist/services.cjs +21 -0
  224. package/dist/services.cjs.map +1 -0
  225. package/dist/services.d.cts +30 -0
  226. package/dist/services.d.ts +30 -0
  227. package/dist/services.js +4 -0
  228. package/dist/services.js.map +1 -0
  229. package/dist/uom.cjs +56 -0
  230. package/dist/uom.cjs.map +1 -0
  231. package/dist/uom.d.cts +224 -0
  232. package/dist/uom.d.ts +224 -0
  233. package/dist/uom.js +11 -0
  234. package/dist/uom.js.map +1 -0
  235. package/dist/utilities.cjs +32 -0
  236. package/dist/utilities.cjs.map +1 -0
  237. package/dist/utilities.d.cts +113 -0
  238. package/dist/utilities.d.ts +113 -0
  239. package/dist/utilities.js +7 -0
  240. package/dist/utilities.js.map +1 -0
  241. package/dist/variables.cjs +17 -0
  242. package/dist/variables.cjs.map +1 -0
  243. package/dist/variables.d.cts +87 -0
  244. package/dist/variables.d.ts +87 -0
  245. package/dist/variables.js +4 -0
  246. package/dist/variables.js.map +1 -0
  247. package/dist/vm.cjs +284 -0
  248. package/dist/vm.cjs.map +1 -0
  249. package/dist/vm.d.cts +68 -0
  250. package/dist/vm.d.ts +68 -0
  251. package/dist/vm.js +194 -0
  252. package/dist/vm.js.map +1 -0
  253. package/package.json +4 -4
@@ -0,0 +1,171 @@
1
+ import { V as Value } from './Value-KtAQNHur.cjs';
2
+ import { V as VM } from './ScopeManager-CKfQtl7l.cjs';
3
+ import { U as UserFunctionDef } from './BytecodeBuilder-3egMyuDi.cjs';
4
+
5
+ /**
6
+ * A point-in-time snapshot of VM variable state.
7
+ *
8
+ * Uses **prototypal inheritance** for memory efficiency: each checkpoint's
9
+ * `variables` object has its parent checkpoint's `variables` as its
10
+ * `__proto__`. This means a `getVar("x")` lookup walks the prototype chain
11
+ * until it finds `x`, and only variables that CHANGED at this checkpoint
12
+ * consume heap space. Unchanged variables are inherited from the parent.
13
+ *
14
+ * ```text
15
+ * Checkpoint 0 (root): {} // empty scope
16
+ * Checkpoint 1 (:x=5): { x: 5 } __proto__ → 0
17
+ * Checkpoint 2 (:y=8): { y: 8 } __proto__ → 1
18
+ * Checkpoint 3 (:x=3): { x: 3 } __proto__ → 2 // shadows x=5
19
+ * ```
20
+ *
21
+ * To look up `x` at checkpoint 3: find own `x=3` → done.
22
+ * To look up `y` at checkpoint 3: not own → walk proto to checkpoint 2 → `y=8`.
23
+ * To look up `z` at checkpoint 3: not found anywhere → undefined.
24
+ *
25
+ * **Memory:** O(number of variable definitions) heap, independent of
26
+ * document length. Typical Obsidian documents have < 100 variable defs,
27
+ * so total checkpoint heap is < 10 KB.
28
+ */
29
+ interface VMCheckpoint {
30
+ /** 1-based line number where this checkpoint was created. */
31
+ lineNumber: number;
32
+ /** Persistent line ID from DocumentModel. */
33
+ lineId: number;
34
+ /**
35
+ * Variable name → Value at this checkpoint.
36
+ * Own properties are variables set/updated at this line.
37
+ * The prototype chain provides inherited variables from parent checkpoints.
38
+ */
39
+ variables: Record<string, Value>;
40
+ /**
41
+ * User-defined-function name → definition at this checkpoint. SEPARATE
42
+ * from `variables` above (not prototypally chained the same way
43
+ * `restoreTo()` replays every checkpoint in the chain in order, so a
44
+ * later redefinition of the same function name naturally overwrites an
45
+ * earlier one during replay, without needing its own prototype walk).
46
+ *
47
+ * Without this field, a function definition's checkpoint entry would be
48
+ * SILENTLY LOST: `snapshot()` used to call `vm.getVar(name)` for every
49
+ * written name, which returns `undefined` for a function name (function
50
+ * defs live in `vm.userFunctions`, not the flat variable store), and a
51
+ * `val !== undefined` guard silently skipped it. A scroll-triggered
52
+ * `restoreTo()` would then reset the VM and replay only `variables`,
53
+ * making a function defined above the new viewport vanish (calling it
54
+ * would throw `UNDEFINED_FUNCTION`) even though the document still
55
+ * shows its definition line as clean/cached.
56
+ */
57
+ functions: Record<string, UserFunctionDef>;
58
+ /** Parent checkpoint (closer to document start), or null for root. */
59
+ parent: VMCheckpoint | null;
60
+ }
61
+ /**
62
+ * Manages VM state checkpoints for the three-tier evaluation strategy.
63
+ *
64
+ * **Checkpoint creation:** After a variable-definition line executes
65
+ * (Tier 1 or Tier 3), `snapshot()` records the current values of the
66
+ * written variables. The checkpoint is linked via prototypal inheritance
67
+ * to the previous checkpoint, so only changed variables consume memory.
68
+ *
69
+ * **Checkpoint restoration:** Before evaluating a viewport whose start line
70
+ * is not line 1, `restoreTo(lineNumber)` resets the VM and replays all
71
+ * variable definitions up to and including that line. This avoids
72
+ * re-evaluating the entire document from line 1 on every scroll.
73
+ *
74
+ * **Thread safety:** Checkpoints are created synchronously on the main
75
+ * thread during evaluation. They are immutable after creation (Value is
76
+ * an immutable type), so no synchronization is needed.
77
+ *
78
+ * **Integration with Phase 5.2e:** `setViewport()` will use `getNearestCheckpoint()`
79
+ * to find the checkpoint just before the new viewport start, then call
80
+ * `restoreTo()` to set up the VM before evaluating only the visible lines.
81
+ * This is the key to O(visible lines) scrolling instead of O(document).
82
+ */
83
+ declare class VMCheckpointer {
84
+ /** Ordered array of checkpoints (ascending lineNumber). */
85
+ private checkpoints;
86
+ /** The VM instance whose variables are snapshotted/restored. */
87
+ private vm;
88
+ constructor(vm: VM);
89
+ /**
90
+ * Create a checkpoint at the current line, recording the VM values of
91
+ * the specified variables.
92
+ *
93
+ * Uses prototypal inheritance: `Object.create(parent.variables)` so
94
+ * that inherited variable lookups fall through to previous checkpoints
95
+ * without copying all variables into each checkpoint.
96
+ *
97
+ * @param lineNumber 1-based line position.
98
+ * @param lineId Persistent line ID from DocumentModel.
99
+ * @param variableNames Names of variables that were written at this line.
100
+ * @returns The new checkpoint, or null if no variable names provided.
101
+ */
102
+ snapshot(lineNumber: number, lineId: number, variableNames: string[]): VMCheckpoint | null;
103
+ /**
104
+ * Restore the VM to the state at or just after the given line number.
105
+ *
106
+ * Finds the nearest checkpoint whose `lineNumber <= targetLineNumber`,
107
+ * then replays all variable definitions from root → that checkpoint
108
+ * into the VM via `setVar()`. The VM's stack is also reset.
109
+ *
110
+ * If no checkpoint exists at or before the target line, the VM is
111
+ * fully reset (empty scope, empty stack).
112
+ *
113
+ * **Performance:** O(number of checkpoints × variables per checkpoint).
114
+ * With prototypal inheritance, `Object.keys()` on each checkpoint
115
+ * returns only the variables that were set at that checkpoint (not
116
+ * inherited ones), so the total work is O(total variable definitions
117
+ * in the document), which is < 100 for typical Obsidian documents.
118
+ *
119
+ * @param lineNumber Target 1-based line number. The VM will have the
120
+ * state that existed AFTER evaluating lines up to `lineNumber`.
121
+ */
122
+ restoreTo(lineNumber: number): void;
123
+ /**
124
+ * Find the nearest checkpoint at or before the given line number.
125
+ *
126
+ * Uses linear scan (checkpoints are sorted by lineNumber and the list
127
+ * is short, typically < 20 for Obsidian documents). Can be upgraded
128
+ * to binary search if needed for documents with 1000+ variable defs.
129
+ *
130
+ * @returns The nearest checkpoint, or null if none exists before the line.
131
+ */
132
+ getNearestCheckpoint(lineNumber: number): VMCheckpoint | null;
133
+ /**
134
+ * Get a specific checkpoint by its line number.
135
+ * @returns The checkpoint, or undefined if not found.
136
+ */
137
+ getCheckpointAt(lineNumber: number): VMCheckpoint | undefined;
138
+ /**
139
+ * Get the entire checkpoint chain from root to the last checkpoint.
140
+ * Useful for debugging and serialization.
141
+ */
142
+ getAllCheckpoints(): readonly VMCheckpoint[];
143
+ /**
144
+ * Look up a variable's value through the checkpoint chain.
145
+ *
146
+ * Walks the prototype chain starting from the most recent checkpoint,
147
+ * looking for the variable name as an own property. This is O(depth)
148
+ * where depth is the number of checkpoints since the variable was
149
+ * last set.
150
+ *
151
+ * **Note:** This queries the checkpointer's snapshot, not the VM.
152
+ * The VM may have been modified since the last snapshot (e.g., by
153
+ * Tier 2 execution of non-variable-def lines that don't create checkpoints).
154
+ *
155
+ * @returns The Value, or undefined if the variable was never set.
156
+ */
157
+ lookupVariable(name: string): Value | undefined;
158
+ /**
159
+ * Clear all checkpoints. The underlying VM is NOT reset, call
160
+ * `vm.reset()` separately if needed.
161
+ */
162
+ clear(): void;
163
+ /** Number of checkpoints stored. */
164
+ get count(): number;
165
+ /** Returns true if no checkpoints have been created. */
166
+ get isEmpty(): boolean;
167
+ /** The associated VM instance. */
168
+ get vmInstance(): VM;
169
+ }
170
+
171
+ export { type VMCheckpoint as V, VMCheckpointer as a };
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Exact rational arithmetic over `bigint`, the coefficient type for every
3
+ * part of the symbolic algebra system.
4
+ *
5
+ * A computer-algebra system cannot work in IEEE doubles. Factoring
6
+ * `x^2 - x/3 - 2/3` needs `1/3` to stay `1/3` rather than becoming
7
+ * `0.3333333333333333`, and the rational-root theorem tests candidate roots
8
+ * by exact division, where a rounding error is indistinguishable from a
9
+ * genuine root. Every coefficient in `SymbolicNode`, `Polynomial`, `Factor`
10
+ * and `Solve` is a Rational for that reason.
11
+ *
12
+ * Values are always normalized on construction (`d > 0n`, `gcd(|n|, d) === 1n`,
13
+ * zero is exactly `0n/1n`), so structural equality on the `{n, d}` pair is
14
+ * mathematical equality, and the pair can be used directly as a cache key.
15
+ *
16
+ * A Rational holds two `bigint`s. Structured clone, which is what the
17
+ * playground's `postMessage` uses to ship a `SymbolicNode` to the VM trace
18
+ * view, handles bigint correctly. `JSON.stringify` does not: it throws
19
+ * `TypeError: Do not know how to serialize a BigInt`. Do not introduce a JSON
20
+ * round-trip anywhere a Rational can reach.
21
+ */
22
+ /**
23
+ * An exact rational number.
24
+ *
25
+ * Always normalized, see this module's own doc comment for the invariant.
26
+ * Construct via {@link rational} or {@link rationalFromNumber} rather than as
27
+ * an object literal, which would bypass normalization.
28
+ */
29
+ interface Rational {
30
+ /** Signed numerator. Carries the sign of the whole value. */
31
+ readonly n: bigint;
32
+ /** Denominator, always strictly positive. */
33
+ readonly d: bigint;
34
+ }
35
+
36
+ /**
37
+ * Exact complex arithmetic over the Gaussian rationals.
38
+ *
39
+ * Both components are {@link Rational}, so this is exact in the same sense the
40
+ * rest of the system is: `(1+2i)/(3-4i)` has an exact answer and gets it,
41
+ * rather than a pair of doubles that are nearly right. That matters most where
42
+ * a complex value has to be recognised as zero, which is how a cubic's
43
+ * *casus irreducibilis* is detected and how a conjugate pair cancels.
44
+ *
45
+ * ## Why the number tower stops here
46
+ *
47
+ * Real values stay {@link Rational} throughout. A complex value only appears
48
+ * when something genuinely produces one: a negative discriminant, a square root
49
+ * of a negative number, or an explicit `i`. That keeps every real-only path
50
+ * paying nothing for complex support, and it keeps `factor` and `solve` working
51
+ * over the rationals by default, which is what a CAS is expected to do.
52
+ *
53
+ * A complex whose imaginary part is zero is collapsed back to a real constant
54
+ * at the boundary, so `(1+i)*(1-i)` reads as `2` rather than `2+0i`.
55
+ */
56
+
57
+ /**
58
+ * An exact complex number, `re + im * i`, with both parts rational.
59
+ *
60
+ * Construct through {@link complex} rather than as an object literal, so the
61
+ * real-collapse convention below stays consistent.
62
+ */
63
+ interface Complex {
64
+ /** Real part. */
65
+ readonly re: Rational;
66
+ /** Imaginary part. Zero means this value is really a real number. */
67
+ readonly im: Rational;
68
+ }
69
+
70
+ /**
71
+ * The symbolic expression tree: an algebraic formula over free variables,
72
+ * rather than a concrete number.
73
+ *
74
+ * This is the data type the whole symbolic algebra system manipulates. It is
75
+ * deliberately a plain discriminated union of immutable object literals, not a
76
+ * class hierarchy, so a node can cross the worker boundary by structured clone
77
+ * (see `diagnostics/events.ts`, which carries these in its VM trace payload)
78
+ * and so pattern matching in the simplifier stays exhaustive under the
79
+ * compiler's own checking.
80
+ *
81
+ * Two variants exist here that the original bounded simplifier did not have,
82
+ * and they are what unlocks the rest of the system:
83
+ *
84
+ * - `pow` gives exponentiation a representation. Without it `x^2` had nowhere
85
+ * to go, and `OpCode.EXP` fell through to `Math.pow(0, 2)` because
86
+ * `Value.toNumber()` reports `0` for a symbolic operand, so `x^2 + 3x + 2`
87
+ * silently evaluated to `3x+2`. Polynomials, derivatives and roots all need it.
88
+ * - `call` gives function application a representation, so `sqrt(x)` and
89
+ * `sin(x)` carry through a symbolic expression instead of collapsing to
90
+ * `sqrt(0)`.
91
+ *
92
+ * Coefficients are exact rationals, never doubles. See `Rational.ts` for why.
93
+ */
94
+
95
+ /**
96
+ * A symbolic (algebraic) expression tree.
97
+ *
98
+ * Build nodes through the constructor functions in this module rather than as
99
+ * object literals, so constants normalize consistently.
100
+ */
101
+ type SymbolicNode = {
102
+ kind: "const";
103
+ value: Rational;
104
+ } | {
105
+ kind: "complex";
106
+ value: Complex;
107
+ } | {
108
+ kind: "var";
109
+ name: string;
110
+ } | {
111
+ kind: "add";
112
+ left: SymbolicNode;
113
+ right: SymbolicNode;
114
+ } | {
115
+ kind: "sub";
116
+ left: SymbolicNode;
117
+ right: SymbolicNode;
118
+ } | {
119
+ kind: "mul";
120
+ left: SymbolicNode;
121
+ right: SymbolicNode;
122
+ } | {
123
+ kind: "div";
124
+ left: SymbolicNode;
125
+ right: SymbolicNode;
126
+ } | {
127
+ kind: "neg";
128
+ operand: SymbolicNode;
129
+ } | {
130
+ kind: "pow";
131
+ base: SymbolicNode;
132
+ exponent: SymbolicNode;
133
+ } | {
134
+ kind: "call";
135
+ name: string;
136
+ args: readonly SymbolicNode[];
137
+ };
138
+
139
+ /**
140
+ * A single matrix cell. `boolean` covers element-wise comparison results
141
+ * (`[1,6;3,8] < [5,2;7,4]` produces a Matrix of booleans, not numbers). A
142
+ * `SymbolicNode` cell is a free-variable algebraic entry, e.g. `s =
143
+ * [sx,0,0;0,sy,0;0,0,1]` where `sx`/`sy` are never assigned, so those
144
+ * cells store a real `SymbolicNode` (a bare `var` node initially) rather
145
+ * than degrading to `0`. See `MatrixOps.ts`'s `entryToSymbolic()`/
146
+ * `symbolicToEntry()` for the two-way conversion every symbolic-aware
147
+ * matrix op (multiply, inverse, determinant) uses.
148
+ */
149
+ type MatrixEntry = number | boolean | SymbolicNode;
150
+ /**
151
+ * A general rows×cols matrix, a vector is just a 1×N (row) or N×1 (column)
152
+ * matrix. `data` is COLUMN-MAJOR (`data[row + col*rows]`), matching the
153
+ * spec's own `a[index]` column-major indexing semantics directly (no
154
+ * translation needed for single-index reads). `hasSymbolic` lets every
155
+ * numeric matrix op fast-path the all-numeric case with one boolean check,
156
+ * mirroring `binaryOp()`'s existing Number+Number fast path, computed by
157
+ * `matrixValue()` itself (true the moment any cell is a `SymbolicNode`
158
+ * object rather than a plain number/boolean), not something callers set
159
+ * by hand.
160
+ */
161
+ interface MatrixData {
162
+ readonly rows: number;
163
+ readonly cols: number;
164
+ readonly data: readonly MatrixEntry[];
165
+ readonly hasSymbolic: boolean;
166
+ }
167
+ /** A first-class integer range `min:max`, both bounds inclusive. */
168
+ interface RangeData {
169
+ readonly min: number;
170
+ readonly max: number;
171
+ }
172
+ /**
173
+ * Discriminated union tag for {@link Value} objects.
174
+ *
175
+ * Determines the runtime type of a Value and how its `value` field should
176
+ * be interpreted. Used by the VM for type-aware dispatch in arithmetic,
177
+ * comparison, and conversion operations.
178
+ */
179
+ declare enum ValueType {
180
+ /** Plain 64-bit floating point number (IEEE 754 double) */
181
+ Number = 0,
182
+ Hex = 1,
183
+ BigInt = 2,
184
+ String = 3,
185
+ Datetime = 4,
186
+ Percentage = 5,
187
+ Uom = 6,
188
+ /** General rows×cols matrix (a vector is a 1×N or N×1 matrix). Value is {@link MatrixData}. */
189
+ Matrix = 7,
190
+ /** A first-class integer range `min:max`, both inclusive. Value is {@link RangeData}. */
191
+ Range = 8,
192
+ /** A symbolic/algebraic expression tree (free-variable formula, not a concrete number). Value is a `SymbolicNode` (`@solve-js/symbolic`). */
193
+ Symbolic = 9,
194
+ /** Boolean true/false. Value is `boolean`. */
195
+ Boolean = 10,
196
+ /** Unit of measurement token (lexer only, not a runtime value). */
197
+ Unit = 11,
198
+ /** Async result pending resolution. Value stores the queryKey string. */
199
+ Pending = 12,
200
+ /** Plugin-raised error propagated through the DAG. Value stores error code, unit stores message. */
201
+ Error = 13
202
+ }
203
+ /**
204
+ * Universal runtime value for the solve-js VM.
205
+ *
206
+ * Carries a {@link ValueType} discriminant, a polymorphic `value` payload,
207
+ * and an optional `unit` string (for UoM values). Treated as immutable after
208
+ * construction, the arena reuses objects internally via `recycle()`, but
209
+ * external code should never mutate Value fields.
210
+ *
211
+ * A cached `_cachedNumber` avoids repeated `toNumber()` computation on
212
+ * hot paths (ADD/SUB/MUL in the VM dispatch loop).
213
+ */
214
+ declare class Value {
215
+ private _cachedNumber;
216
+ type: ValueType;
217
+ value: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode;
218
+ unit?: string;
219
+ /** Set by async resolvers when a fetch timed out, the result is a fallback (typically 0). */
220
+ timedOut?: boolean;
221
+ constructor(type: ValueType, value: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode, unit?: string);
222
+ /**
223
+ * Phase 5.3: Reset all fields for arena reuse.
224
+ * Called by ValueArena.acquire(), zero allocation, just field assignment.
225
+ */
226
+ recycle(type: ValueType, value: number | bigint | string | boolean | MatrixData | RangeData | SymbolicNode, unit?: string): void;
227
+ isNumber(): this is Value & {
228
+ value: number;
229
+ };
230
+ isHex(): this is Value & {
231
+ value: number;
232
+ };
233
+ isBigInt(): this is Value & {
234
+ value: bigint;
235
+ };
236
+ isString(): this is Value & {
237
+ value: string;
238
+ };
239
+ isMatrix(): this is Value & {
240
+ value: MatrixData;
241
+ };
242
+ /** A Matrix shaped like a vector, 1×N (row) or N×1 (column). */
243
+ isVectorShape(): boolean;
244
+ isRange(): this is Value & {
245
+ value: RangeData;
246
+ };
247
+ isSymbolic(): this is Value & {
248
+ value: SymbolicNode;
249
+ };
250
+ toNumber(): number;
251
+ isNaN(): boolean;
252
+ }
253
+ /**
254
+ * Create a Number-typed Value. Uses the arena when active for zero-allocation.
255
+ * This is the most common factory, over 90% of all Value creations.
256
+ */
257
+ declare function numberValue(n: number): Value;
258
+ /** Which base a {@link ValueType.Hex} value is displayed in. */
259
+ type DisplayBase = "hex" | "bin" | "oct";
260
+ /**
261
+ * Create a Hex-typed Value: a **number** that displays in another base.
262
+ *
263
+ * The type is numeric on purpose, and that is the whole point of it. A base is
264
+ * a way of writing a quantity, not a different kind of quantity, so `0xFF + 1`
265
+ * has to be 256. Returning a string instead makes it 1, because a string reads
266
+ * as zero in arithmetic, and nothing about that failure is visible at the point
267
+ * of use.
268
+ *
269
+ * @param n - The number itself, in full precision.
270
+ * @param base - How to display it, defaulting to hexadecimal. Carried in the
271
+ * `unit` slot, which is free for this type.
272
+ */
273
+ declare function hexValue(n: number, base?: DisplayBase): Value;
274
+ /** Create a BigInt-typed Value (arbitrary-precision integer). */
275
+ declare function bigIntValue(n: bigint): Value;
276
+ /** Create a String-typed Value. */
277
+ declare function stringValue(s: string): Value;
278
+ /** Create a Unit-of-Measurement Value (typed number with unit annotation). */
279
+ declare function uomValue(n: number, unit: string): Value;
280
+ /**
281
+ * Create a Matrix value from an explicit shape + column-major data array.
282
+ * `data.length` must equal `rows*cols`, callers building a matrix from
283
+ * row-major source syntax (e.g. the `[1,2;3,4]` literal) must transpose
284
+ * into column-major order before calling this; see `MatrixOps.ts`'s
285
+ * `rowMajorToColumnMajor()`.
286
+ */
287
+ declare function matrixValue(rows: number, cols: number, data: readonly MatrixEntry[]): Value;
288
+ /** A 1×N row-vector Matrix, row-major and column-major storage are identical for a single row. */
289
+ declare function rowVectorValue(data: readonly number[]): Value;
290
+ /** An N×1 column-vector Matrix, row-major and column-major storage are identical for a single column. */
291
+ declare function colVectorValue(data: readonly number[]): Value;
292
+ /** Create a Range value, a first-class integer range `min:max`, both bounds inclusive. */
293
+ declare function rangeValue(min: number, max: number): Value;
294
+
295
+ export { type MatrixData as M, type RangeData as R, type SymbolicNode as S, Value as V, type MatrixEntry as a, ValueType as b, bigIntValue as c, colVectorValue as d, rowVectorValue as e, hexValue as h, matrixValue as m, numberValue as n, rangeValue as r, stringValue as s, uomValue as u };