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
package/dist/vm.d.cts ADDED
@@ -0,0 +1,68 @@
1
+ import { P as PluginFunctionHandler } from './ScopeManager-CKfQtl7l.cjs';
2
+ export { B as Bytecode, D as DependencyGraph, E as ExpressionRecord, O as OpRegistry, S as ScopeManager, V as VM, c as createVM, e as executeBytecode, s as sharedOpRegistry } from './ScopeManager-CKfQtl7l.cjs';
3
+ import { V as Value } from './Value-KtAQNHur.cjs';
4
+ export { M as MatrixData, a as MatrixEntry, R as RangeData, b as ValueType, c as bigIntValue, d as colVectorValue, h as hexValue, m as matrixValue, n as numberValue, r as rangeValue, e as rowVectorValue, s as stringValue, u as uomValue } from './Value-KtAQNHur.cjs';
5
+ export { V as VMCheckpoint, a as VMCheckpointer } from './VMCheckpoints-CqFuLwrT.cjs';
6
+ import './BytecodeBuilder-3egMyuDi.cjs';
7
+ import './EngineError-DvPSnhZi.cjs';
8
+ import './pipeline-DPUQt7yL.cjs';
9
+ import './variables.cjs';
10
+
11
+ /**
12
+ * Registry of built-in mathematical functions.
13
+ * Indexed by the number pushed as an operand of OpCode.CALL_BUILTIN.
14
+ */
15
+ declare const builtinFunctions: Record<number, (args: Value[]) => Value>;
16
+ /**
17
+ * Registry of package-registered functions, indexed by the number pushed as an
18
+ * operand of `OpCode.CALL_PLUGIN`.
19
+ *
20
+ * Functions may return a promise. The orchestrator resolves it and re-executes
21
+ * rather than blocking the VM.
22
+ *
23
+ * Populated declaratively via {@link IEnginePackage.pluginFunctions} at
24
+ * package-registration time. Entries are cleared on unregister.
25
+ *
26
+ * @deprecated This is the {@link defaultEngineContext}'s map, kept as a
27
+ * module-level alias so existing callers keep working during the context
28
+ * migration. An engine registers into its own context, so writing here affects
29
+ * only code that has not been migrated. Take an {@link EngineContext} instead.
30
+ */
31
+ declare const pluginFunctionRegistry: Record<number, PluginFunctionHandler>;
32
+ /**
33
+ * Allocate a unique index into {@link pluginFunctionRegistry} for a package's
34
+ * plugin function.
35
+ *
36
+ * Call once per function, typically at module scope, right where the
37
+ * function is defined, and store the result in a constant. Don't hardcode
38
+ * an index: two packages independently picking the same arbitrary number
39
+ * would silently overwrite each other's handler in the shared registry.
40
+ *
41
+ * @throws If the index pool (0-255, a single opcode-stream byte) is exhausted.
42
+ */
43
+ declare function allocatePluginFunctionIndex(): number;
44
+
45
+ /**
46
+ * Unify two Value operands that may carry units of measurement.
47
+ * Returns numeric values in a common unit (or undefined unit if incompatible).
48
+ */
49
+ declare function unifyUom(l: Value, r: Value): {
50
+ lv: number;
51
+ rv: number;
52
+ unit: string | undefined;
53
+ sameMeasure: boolean;
54
+ };
55
+ /**
56
+ * Apply a numeric binary operation with type-aware dispatch.
57
+ * Handles BigInt, UoM, Vector, Symbolic, and plain Number operands.
58
+ *
59
+ * @param symbolicOp - which SymbolicNode kind to build when either operand
60
+ * is Symbolic (`symbolic/SymbolicNode.ts`). Only ADD/SUB/MUL/DIV pass this (the
61
+ * "four arithmetic opcodes" the symbolic-algebra phase scopes itself
62
+ * to), MOD's own call site passes nothing, so a Symbolic operand there
63
+ * falls through to the ordinary numeric path (`toNumber()` -> 0), an
64
+ * explicit, disclosed scope boundary rather than an oversight.
65
+ */
66
+ declare function binaryOp(l: Value, r: Value, op: (a: number, b: number) => number, bigOp?: (a: bigint, b: bigint) => bigint, symbolicOp?: "add" | "sub" | "mul" | "div"): Value;
67
+
68
+ export { Value, allocatePluginFunctionIndex, binaryOp, builtinFunctions, pluginFunctionRegistry, unifyUom };
package/dist/vm.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ import { P as PluginFunctionHandler } from './ScopeManager-B5k0nk05.js';
2
+ export { B as Bytecode, D as DependencyGraph, E as ExpressionRecord, O as OpRegistry, S as ScopeManager, V as VM, c as createVM, e as executeBytecode, s as sharedOpRegistry } from './ScopeManager-B5k0nk05.js';
3
+ import { V as Value } from './Value-KtAQNHur.js';
4
+ export { M as MatrixData, a as MatrixEntry, R as RangeData, b as ValueType, c as bigIntValue, d as colVectorValue, h as hexValue, m as matrixValue, n as numberValue, r as rangeValue, e as rowVectorValue, s as stringValue, u as uomValue } from './Value-KtAQNHur.js';
5
+ export { V as VMCheckpoint, a as VMCheckpointer } from './VMCheckpoints-BmDwIXgK.js';
6
+ import './BytecodeBuilder-3egMyuDi.js';
7
+ import './EngineError-DvPSnhZi.js';
8
+ import './pipeline-CrsRPmsv.js';
9
+ import './variables.js';
10
+
11
+ /**
12
+ * Registry of built-in mathematical functions.
13
+ * Indexed by the number pushed as an operand of OpCode.CALL_BUILTIN.
14
+ */
15
+ declare const builtinFunctions: Record<number, (args: Value[]) => Value>;
16
+ /**
17
+ * Registry of package-registered functions, indexed by the number pushed as an
18
+ * operand of `OpCode.CALL_PLUGIN`.
19
+ *
20
+ * Functions may return a promise. The orchestrator resolves it and re-executes
21
+ * rather than blocking the VM.
22
+ *
23
+ * Populated declaratively via {@link IEnginePackage.pluginFunctions} at
24
+ * package-registration time. Entries are cleared on unregister.
25
+ *
26
+ * @deprecated This is the {@link defaultEngineContext}'s map, kept as a
27
+ * module-level alias so existing callers keep working during the context
28
+ * migration. An engine registers into its own context, so writing here affects
29
+ * only code that has not been migrated. Take an {@link EngineContext} instead.
30
+ */
31
+ declare const pluginFunctionRegistry: Record<number, PluginFunctionHandler>;
32
+ /**
33
+ * Allocate a unique index into {@link pluginFunctionRegistry} for a package's
34
+ * plugin function.
35
+ *
36
+ * Call once per function, typically at module scope, right where the
37
+ * function is defined, and store the result in a constant. Don't hardcode
38
+ * an index: two packages independently picking the same arbitrary number
39
+ * would silently overwrite each other's handler in the shared registry.
40
+ *
41
+ * @throws If the index pool (0-255, a single opcode-stream byte) is exhausted.
42
+ */
43
+ declare function allocatePluginFunctionIndex(): number;
44
+
45
+ /**
46
+ * Unify two Value operands that may carry units of measurement.
47
+ * Returns numeric values in a common unit (or undefined unit if incompatible).
48
+ */
49
+ declare function unifyUom(l: Value, r: Value): {
50
+ lv: number;
51
+ rv: number;
52
+ unit: string | undefined;
53
+ sameMeasure: boolean;
54
+ };
55
+ /**
56
+ * Apply a numeric binary operation with type-aware dispatch.
57
+ * Handles BigInt, UoM, Vector, Symbolic, and plain Number operands.
58
+ *
59
+ * @param symbolicOp - which SymbolicNode kind to build when either operand
60
+ * is Symbolic (`symbolic/SymbolicNode.ts`). Only ADD/SUB/MUL/DIV pass this (the
61
+ * "four arithmetic opcodes" the symbolic-algebra phase scopes itself
62
+ * to), MOD's own call site passes nothing, so a Symbolic operand there
63
+ * falls through to the ordinary numeric path (`toNumber()` -> 0), an
64
+ * explicit, disclosed scope boundary rather than an oversight.
65
+ */
66
+ declare function binaryOp(l: Value, r: Value, op: (a: number, b: number) => number, bigOp?: (a: bigint, b: bigint) => bigint, symbolicOp?: "add" | "sub" | "mul" | "div"): Value;
67
+
68
+ export { Value, allocatePluginFunctionIndex, binaryOp, builtinFunctions, pluginFunctionRegistry, unifyUom };
package/dist/vm.js ADDED
@@ -0,0 +1,194 @@
1
+ export { DependencyGraph, ScopeManager, createVM, executeBytecode } from './chunk-QWY3VEZN.js';
2
+ import './chunk-G535KJEG.js';
3
+ export { OpRegistry, allocatePluginFunctionIndex, binaryOp, builtinFunctions, pluginFunctionRegistry, sharedOpRegistry, unifyUom } from './chunk-4QADQTWS.js';
4
+ import './chunk-GCM5JHMX.js';
5
+ import './chunk-DM3LMRBC.js';
6
+ import './chunk-75JP4BZX.js';
7
+ import './chunk-Z4X2RWOF.js';
8
+ import './chunk-34RRD7PC.js';
9
+ export { Value, ValueType, bigIntValue, colVectorValue, hexValue, matrixValue, numberValue, rangeValue, rowVectorValue, stringValue, uomValue } from './chunk-BVAR5J2F.js';
10
+ import './chunk-NH2O2AUR.js';
11
+ import './chunk-4MG4XKO2.js';
12
+ import './chunk-6RDSQURE.js';
13
+ import './chunk-YLJ4XMA6.js';
14
+
15
+ // src/vm/VMCheckpoints.ts
16
+ var VMCheckpointer = class {
17
+ constructor(vm) {
18
+ /** Ordered array of checkpoints (ascending lineNumber). */
19
+ this.checkpoints = [];
20
+ this.vm = vm;
21
+ }
22
+ // ── Snapshot ─────────────────────────────────────────────────────
23
+ /**
24
+ * Create a checkpoint at the current line, recording the VM values of
25
+ * the specified variables.
26
+ *
27
+ * Uses prototypal inheritance: `Object.create(parent.variables)` so
28
+ * that inherited variable lookups fall through to previous checkpoints
29
+ * without copying all variables into each checkpoint.
30
+ *
31
+ * @param lineNumber 1-based line position.
32
+ * @param lineId Persistent line ID from DocumentModel.
33
+ * @param variableNames Names of variables that were written at this line.
34
+ * @returns The new checkpoint, or null if no variable names provided.
35
+ */
36
+ snapshot(lineNumber, lineId, variableNames) {
37
+ if (variableNames.length === 0) return null;
38
+ const parent = this.checkpoints.length > 0 ? this.checkpoints[this.checkpoints.length - 1] : null;
39
+ const variables = Object.create(
40
+ parent?.variables ?? null
41
+ );
42
+ const functions = Object.create(
43
+ parent?.functions ?? null
44
+ );
45
+ for (const name of variableNames) {
46
+ if (this.vm.hasUserFunction(name)) {
47
+ const fn = this.vm.getUserFunction(name);
48
+ if (fn) functions[name] = fn;
49
+ continue;
50
+ }
51
+ const val = this.vm.getVar(name);
52
+ if (val !== void 0) {
53
+ variables[name] = val;
54
+ }
55
+ }
56
+ const checkpoint = {
57
+ lineNumber,
58
+ lineId,
59
+ variables,
60
+ functions,
61
+ parent
62
+ };
63
+ this.checkpoints.push(checkpoint);
64
+ return checkpoint;
65
+ }
66
+ // ── Restore ──────────────────────────────────────────────────────
67
+ /**
68
+ * Restore the VM to the state at or just after the given line number.
69
+ *
70
+ * Finds the nearest checkpoint whose `lineNumber <= targetLineNumber`,
71
+ * then replays all variable definitions from root → that checkpoint
72
+ * into the VM via `setVar()`. The VM's stack is also reset.
73
+ *
74
+ * If no checkpoint exists at or before the target line, the VM is
75
+ * fully reset (empty scope, empty stack).
76
+ *
77
+ * **Performance:** O(number of checkpoints × variables per checkpoint).
78
+ * With prototypal inheritance, `Object.keys()` on each checkpoint
79
+ * returns only the variables that were set at that checkpoint (not
80
+ * inherited ones), so the total work is O(total variable definitions
81
+ * in the document), which is < 100 for typical Obsidian documents.
82
+ *
83
+ * @param lineNumber Target 1-based line number. The VM will have the
84
+ * state that existed AFTER evaluating lines up to `lineNumber`.
85
+ */
86
+ restoreTo(lineNumber) {
87
+ const target = this.getNearestCheckpoint(lineNumber);
88
+ if (!target) {
89
+ this.vm.reset();
90
+ return;
91
+ }
92
+ const chain = [];
93
+ let current = target;
94
+ while (current) {
95
+ chain.unshift(current);
96
+ current = current.parent;
97
+ }
98
+ this.vm.reset();
99
+ for (const cp of chain) {
100
+ for (const key of Object.keys(cp.variables)) {
101
+ this.vm.setVar(key, cp.variables[key]);
102
+ }
103
+ for (const key of Object.keys(cp.functions)) {
104
+ const fn = cp.functions[key];
105
+ this.vm.defineUserFunction(fn.name, fn.params, fn.program);
106
+ }
107
+ }
108
+ }
109
+ // ── Queries ──────────────────────────────────────────────────────
110
+ /**
111
+ * Find the nearest checkpoint at or before the given line number.
112
+ *
113
+ * Uses linear scan (checkpoints are sorted by lineNumber and the list
114
+ * is short, typically < 20 for Obsidian documents). Can be upgraded
115
+ * to binary search if needed for documents with 1000+ variable defs.
116
+ *
117
+ * @returns The nearest checkpoint, or null if none exists before the line.
118
+ */
119
+ getNearestCheckpoint(lineNumber) {
120
+ let result = null;
121
+ for (const cp of this.checkpoints) {
122
+ if (cp.lineNumber <= lineNumber) {
123
+ result = cp;
124
+ } else {
125
+ break;
126
+ }
127
+ }
128
+ return result;
129
+ }
130
+ /**
131
+ * Get a specific checkpoint by its line number.
132
+ * @returns The checkpoint, or undefined if not found.
133
+ */
134
+ getCheckpointAt(lineNumber) {
135
+ return this.checkpoints.find((cp) => cp.lineNumber === lineNumber);
136
+ }
137
+ /**
138
+ * Get the entire checkpoint chain from root to the last checkpoint.
139
+ * Useful for debugging and serialization.
140
+ */
141
+ getAllCheckpoints() {
142
+ return this.checkpoints;
143
+ }
144
+ /**
145
+ * Look up a variable's value through the checkpoint chain.
146
+ *
147
+ * Walks the prototype chain starting from the most recent checkpoint,
148
+ * looking for the variable name as an own property. This is O(depth)
149
+ * where depth is the number of checkpoints since the variable was
150
+ * last set.
151
+ *
152
+ * **Note:** This queries the checkpointer's snapshot, not the VM.
153
+ * The VM may have been modified since the last snapshot (e.g., by
154
+ * Tier 2 execution of non-variable-def lines that don't create checkpoints).
155
+ *
156
+ * @returns The Value, or undefined if the variable was never set.
157
+ */
158
+ lookupVariable(name) {
159
+ if (this.checkpoints.length === 0) return void 0;
160
+ const latest = this.checkpoints[this.checkpoints.length - 1];
161
+ let scope = latest.variables;
162
+ while (scope) {
163
+ if (Object.prototype.hasOwnProperty.call(scope, name)) {
164
+ return scope[name];
165
+ }
166
+ scope = Object.getPrototypeOf(scope);
167
+ }
168
+ return void 0;
169
+ }
170
+ // ── Lifecycle ────────────────────────────────────────────────────
171
+ /**
172
+ * Clear all checkpoints. The underlying VM is NOT reset, call
173
+ * `vm.reset()` separately if needed.
174
+ */
175
+ clear() {
176
+ this.checkpoints = [];
177
+ }
178
+ /** Number of checkpoints stored. */
179
+ get count() {
180
+ return this.checkpoints.length;
181
+ }
182
+ /** Returns true if no checkpoints have been created. */
183
+ get isEmpty() {
184
+ return this.checkpoints.length === 0;
185
+ }
186
+ /** The associated VM instance. */
187
+ get vmInstance() {
188
+ return this.vm;
189
+ }
190
+ };
191
+
192
+ export { VMCheckpointer };
193
+ //# sourceMappingURL=vm.js.map
194
+ //# sourceMappingURL=vm.js.map
package/dist/vm.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vm/VMCheckpoints.ts"],"names":[],"mappings":"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","file":"vm.js","sourcesContent":["import { Value } from \"@solve-js/vm/Value\";\nimport type { VM } from \"@solve-js/vm/OpRegistry\";\nimport type { UserFunctionDef } from \"@solve-js/parser/BytecodeBuilder\";\n\n// ── VMCheckpoint ────────────────────────────────────────────────────────\n\n/**\n * A point-in-time snapshot of VM variable state.\n *\n * Uses **prototypal inheritance** for memory efficiency: each checkpoint's\n * `variables` object has its parent checkpoint's `variables` as its\n * `__proto__`. This means a `getVar(\"x\")` lookup walks the prototype chain\n * until it finds `x`, and only variables that CHANGED at this checkpoint\n * consume heap space. Unchanged variables are inherited from the parent.\n *\n * ```text\n * Checkpoint 0 (root): {} // empty scope\n * Checkpoint 1 (:x=5): { x: 5 } __proto__ → 0\n * Checkpoint 2 (:y=8): { y: 8 } __proto__ → 1\n * Checkpoint 3 (:x=3): { x: 3 } __proto__ → 2 // shadows x=5\n * ```\n *\n * To look up `x` at checkpoint 3: find own `x=3` → done.\n * To look up `y` at checkpoint 3: not own → walk proto to checkpoint 2 → `y=8`.\n * To look up `z` at checkpoint 3: not found anywhere → undefined.\n *\n * **Memory:** O(number of variable definitions) heap, independent of\n * document length. Typical Obsidian documents have < 100 variable defs,\n * so total checkpoint heap is < 10 KB.\n */\nexport interface VMCheckpoint {\n\t/** 1-based line number where this checkpoint was created. */\n\tlineNumber: number;\n\t/** Persistent line ID from DocumentModel. */\n\tlineId: number;\n\t/**\n\t * Variable name → Value at this checkpoint.\n\t * Own properties are variables set/updated at this line.\n\t * The prototype chain provides inherited variables from parent checkpoints.\n\t */\n\tvariables: Record<string, Value>;\n\t/**\n\t * User-defined-function name → definition at this checkpoint. SEPARATE\n\t * from `variables` above (not prototypally chained the same way\n\t * `restoreTo()` replays every checkpoint in the chain in order, so a\n\t * later redefinition of the same function name naturally overwrites an\n\t * earlier one during replay, without needing its own prototype walk).\n\t *\n\t * Without this field, a function definition's checkpoint entry would be\n\t * SILENTLY LOST: `snapshot()` used to call `vm.getVar(name)` for every\n\t * written name, which returns `undefined` for a function name (function\n\t * defs live in `vm.userFunctions`, not the flat variable store), and a\n\t * `val !== undefined` guard silently skipped it. A scroll-triggered\n\t * `restoreTo()` would then reset the VM and replay only `variables`,\n\t * making a function defined above the new viewport vanish (calling it\n\t * would throw `UNDEFINED_FUNCTION`) even though the document still\n\t * shows its definition line as clean/cached.\n\t */\n\tfunctions: Record<string, UserFunctionDef>;\n\t/** Parent checkpoint (closer to document start), or null for root. */\n\tparent: VMCheckpoint | null;\n}\n\n// ── VMCheckpointer ──────────────────────────────────────────────────────\n\n/**\n * Manages VM state checkpoints for the three-tier evaluation strategy.\n *\n * **Checkpoint creation:** After a variable-definition line executes\n * (Tier 1 or Tier 3), `snapshot()` records the current values of the\n * written variables. The checkpoint is linked via prototypal inheritance\n * to the previous checkpoint, so only changed variables consume memory.\n *\n * **Checkpoint restoration:** Before evaluating a viewport whose start line\n * is not line 1, `restoreTo(lineNumber)` resets the VM and replays all\n * variable definitions up to and including that line. This avoids\n * re-evaluating the entire document from line 1 on every scroll.\n *\n * **Thread safety:** Checkpoints are created synchronously on the main\n * thread during evaluation. They are immutable after creation (Value is\n * an immutable type), so no synchronization is needed.\n *\n * **Integration with Phase 5.2e:** `setViewport()` will use `getNearestCheckpoint()`\n * to find the checkpoint just before the new viewport start, then call\n * `restoreTo()` to set up the VM before evaluating only the visible lines.\n * This is the key to O(visible lines) scrolling instead of O(document).\n */\nexport class VMCheckpointer {\n\t/** Ordered array of checkpoints (ascending lineNumber). */\n\tprivate checkpoints: VMCheckpoint[] = [];\n\t/** The VM instance whose variables are snapshotted/restored. */\n\tprivate vm: VM;\n\n\tconstructor(vm: VM) {\n\t\tthis.vm = vm;\n\t}\n\n\t// ── Snapshot ─────────────────────────────────────────────────────\n\n\t/**\n\t * Create a checkpoint at the current line, recording the VM values of\n\t * the specified variables.\n\t *\n\t * Uses prototypal inheritance: `Object.create(parent.variables)` so\n\t * that inherited variable lookups fall through to previous checkpoints\n\t * without copying all variables into each checkpoint.\n\t *\n\t * @param lineNumber 1-based line position.\n\t * @param lineId Persistent line ID from DocumentModel.\n\t * @param variableNames Names of variables that were written at this line.\n\t * @returns The new checkpoint, or null if no variable names provided.\n\t */\n\tsnapshot(\n\t\tlineNumber: number,\n\t\tlineId: number,\n\t\tvariableNames: string[]\n\t): VMCheckpoint | null {\n\t\tif (variableNames.length === 0) return null;\n\n\t\tconst parent =\n\t\t\tthis.checkpoints.length > 0\n\t\t\t\t? this.checkpoints[this.checkpoints.length - 1]\n\t\t\t\t: null;\n\n\t\t// Create prototypal chain: new checkpoint inherits from parent\n\t\tconst variables: Record<string, Value> = Object.create(\n\t\t\tparent?.variables ?? null\n\t\t) as Record<string, Value>;\n\t\tconst functions: Record<string, UserFunctionDef> = Object.create(\n\t\t\tparent?.functions ?? null\n\t\t) as Record<string, UserFunctionDef>;\n\n\t\t// Record current VM values for the written names, routing each into\n\t\t// the right bag (a name is either a variable or a user-defined\n\t\t// function, never both; see VMCheckpoint.functions's doc comment for\n\t\t// why this dispatch is required, not optional).\n\t\tfor (const name of variableNames) {\n\t\t\tif (this.vm.hasUserFunction(name)) {\n\t\t\t\tconst fn = this.vm.getUserFunction(name);\n\t\t\t\tif (fn) functions[name] = fn;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst val = this.vm.getVar(name);\n\t\t\tif (val !== undefined) {\n\t\t\t\tvariables[name] = val;\n\t\t\t}\n\t\t}\n\n\t\tconst checkpoint: VMCheckpoint = {\n\t\t\tlineNumber,\n\t\t\tlineId,\n\t\t\tvariables,\n\t\t\tfunctions,\n\t\t\tparent,\n\t\t};\n\t\tthis.checkpoints.push(checkpoint);\n\t\treturn checkpoint;\n\t}\n\n\t// ── Restore ──────────────────────────────────────────────────────\n\n\t/**\n\t * Restore the VM to the state at or just after the given line number.\n\t *\n\t * Finds the nearest checkpoint whose `lineNumber <= targetLineNumber`,\n\t * then replays all variable definitions from root → that checkpoint\n\t * into the VM via `setVar()`. The VM's stack is also reset.\n\t *\n\t * If no checkpoint exists at or before the target line, the VM is\n\t * fully reset (empty scope, empty stack).\n\t *\n\t * **Performance:** O(number of checkpoints × variables per checkpoint).\n\t * With prototypal inheritance, `Object.keys()` on each checkpoint\n\t * returns only the variables that were set at that checkpoint (not\n\t * inherited ones), so the total work is O(total variable definitions\n\t * in the document), which is < 100 for typical Obsidian documents.\n\t *\n\t * @param lineNumber Target 1-based line number. The VM will have the\n\t * state that existed AFTER evaluating lines up to `lineNumber`.\n\t */\n\trestoreTo(lineNumber: number): void {\n\t\tconst target = this.getNearestCheckpoint(lineNumber);\n\t\tif (!target) {\n\t\t\tthis.vm.reset();\n\t\t\treturn;\n\t\t}\n\n\t\t// Collect the checkpoint chain from root to target.\n\t\t// Walk parent links and reverse so root is first.\n\t\tconst chain: VMCheckpoint[] = [];\n\t\tlet current: VMCheckpoint | null = target;\n\t\twhile (current) {\n\t\t\tchain.unshift(current);\n\t\t\tcurrent = current.parent;\n\t\t}\n\n\t\tthis.vm.reset();\n\t\tfor (const cp of chain) {\n\t\t\t// Object.keys() returns only OWN enumerable properties\n\t\t\t// it does NOT include inherited properties from the prototype chain.\n\t\t\t// This means we only set variables that were defined/updated at this\n\t\t\t// specific checkpoint, not all variables from parent checkpoints.\n\t\t\tfor (const key of Object.keys(cp.variables)) {\n\t\t\t\tthis.vm.setVar(key, cp.variables[key]);\n\t\t\t}\n\t\t\t// Replay function definitions the same way, a later checkpoint's\n\t\t\t// redefinition of the same name naturally overwrites an earlier\n\t\t\t// one since the chain replays in root-to-target order.\n\t\t\tfor (const key of Object.keys(cp.functions)) {\n\t\t\t\tconst fn = cp.functions[key];\n\t\t\t\tthis.vm.defineUserFunction(fn.name, fn.params, fn.program);\n\t\t\t}\n\t\t}\n\t}\n\n\t// ── Queries ──────────────────────────────────────────────────────\n\n\t/**\n\t * Find the nearest checkpoint at or before the given line number.\n\t *\n\t * Uses linear scan (checkpoints are sorted by lineNumber and the list\n\t * is short, typically < 20 for Obsidian documents). Can be upgraded\n\t * to binary search if needed for documents with 1000+ variable defs.\n\t *\n\t * @returns The nearest checkpoint, or null if none exists before the line.\n\t */\n\tgetNearestCheckpoint(lineNumber: number): VMCheckpoint | null {\n\t\tlet result: VMCheckpoint | null = null;\n\t\tfor (const cp of this.checkpoints) {\n\t\t\tif (cp.lineNumber <= lineNumber) {\n\t\t\t\tresult = cp;\n\t\t\t} else {\n\t\t\t\tbreak; // checkpoints are sorted ascending\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get a specific checkpoint by its line number.\n\t * @returns The checkpoint, or undefined if not found.\n\t */\n\tgetCheckpointAt(lineNumber: number): VMCheckpoint | undefined {\n\t\treturn this.checkpoints.find((cp) => cp.lineNumber === lineNumber);\n\t}\n\n\t/**\n\t * Get the entire checkpoint chain from root to the last checkpoint.\n\t * Useful for debugging and serialization.\n\t */\n\tgetAllCheckpoints(): readonly VMCheckpoint[] {\n\t\treturn this.checkpoints;\n\t}\n\n\t/**\n\t * Look up a variable's value through the checkpoint chain.\n\t *\n\t * Walks the prototype chain starting from the most recent checkpoint,\n\t * looking for the variable name as an own property. This is O(depth)\n\t * where depth is the number of checkpoints since the variable was\n\t * last set.\n\t *\n\t * **Note:** This queries the checkpointer's snapshot, not the VM.\n\t * The VM may have been modified since the last snapshot (e.g., by\n\t * Tier 2 execution of non-variable-def lines that don't create checkpoints).\n\t *\n\t * @returns The Value, or undefined if the variable was never set.\n\t */\n\tlookupVariable(name: string): Value | undefined {\n\t\tif (this.checkpoints.length === 0) return undefined;\n\n\t\tconst latest = this.checkpoints[this.checkpoints.length - 1];\n\t\tlet scope: Record<string, Value> | null = latest.variables;\n\t\twhile (scope) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(scope, name)) {\n\t\t\t\treturn scope[name];\n\t\t\t}\n\t\t\tscope = Object.getPrototypeOf(scope) as Record<string, Value> | null;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t// ── Lifecycle ────────────────────────────────────────────────────\n\n\t/**\n\t * Clear all checkpoints. The underlying VM is NOT reset, call\n\t * `vm.reset()` separately if needed.\n\t */\n\tclear(): void {\n\t\tthis.checkpoints = [];\n\t}\n\n\t/** Number of checkpoints stored. */\n\tget count(): number {\n\t\treturn this.checkpoints.length;\n\t}\n\n\t/** Returns true if no checkpoints have been created. */\n\tget isEmpty(): boolean {\n\t\treturn this.checkpoints.length === 0;\n\t}\n\n\t/** The associated VM instance. */\n\tget vmInstance(): VM {\n\t\treturn this.vm;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solve-engine",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "The expression evaluation engine behind Solve — lexer, parser, bytecode VM, and an extensible package system.",
5
5
  "keywords": [
6
6
  "expression-evaluator",
@@ -201,15 +201,14 @@
201
201
  },
202
202
  "scripts": {
203
203
  "build": "tsup",
204
+ "prepublishOnly": "npm run build && node ../../scripts/assert-publishable.mjs .",
204
205
  "dev": "tsup --watch",
205
206
  "test": "jest --config jest.config.cjs --no-coverage",
206
207
  "typecheck": "tsgo --noEmit --skipLibCheck",
207
208
  "typecheck:tsc": "tsc --noEmit --skipLibCheck"
208
209
  },
209
210
  "dependencies": {
210
- "@tanstack/query-core": "^5.100.10",
211
- "semver": "^7.6.0",
212
- "tslib": "^2.6.1"
211
+ "@tanstack/query-core": "^5.100.10"
213
212
  },
214
213
  "devDependencies": {
215
214
  "@jest/globals": "^30.4.1",
@@ -217,6 +216,7 @@
217
216
  "@types/semver": "^7.5.0",
218
217
  "convert": "^7.0.0",
219
218
  "jest": "^30.4.2",
219
+ "semver": "^7.6.0",
220
220
  "ts-jest": "^29.4.12",
221
221
  "tsup": "8.5.1",
222
222
  "typescript": "5.9.3"