openalgo-script 0.4.0 → 0.6.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.
Files changed (359) hide show
  1. package/CHANGELOG.md +1050 -0
  2. package/README.md +111 -27
  3. package/dist/adapters/charts/driving.d.ts +50 -0
  4. package/dist/adapters/charts/driving.d.ts.map +1 -0
  5. package/dist/adapters/charts/driving.js +57 -0
  6. package/dist/adapters/charts/driving.js.map +1 -0
  7. package/dist/adapters/charts/run.d.ts +20 -0
  8. package/dist/adapters/charts/run.d.ts.map +1 -1
  9. package/dist/adapters/charts/run.js +89 -16
  10. package/dist/adapters/charts/run.js.map +1 -1
  11. package/dist/adapters/charts/tables.d.ts +6 -19
  12. package/dist/adapters/charts/tables.d.ts.map +1 -1
  13. package/dist/adapters/charts/tables.js.map +1 -1
  14. package/dist/adapters/charts/undrawable.d.ts +4 -0
  15. package/dist/adapters/charts/undrawable.d.ts.map +1 -0
  16. package/dist/adapters/charts/undrawable.js +47 -0
  17. package/dist/adapters/charts/undrawable.js.map +1 -0
  18. package/dist/adapters/charts/venue.d.ts +73 -0
  19. package/dist/adapters/charts/venue.d.ts.map +1 -0
  20. package/dist/adapters/charts/venue.js +104 -0
  21. package/dist/adapters/charts/venue.js.map +1 -0
  22. package/dist/core/accounting/analysis.d.ts +111 -0
  23. package/dist/core/accounting/analysis.d.ts.map +1 -0
  24. package/dist/core/accounting/analysis.js +123 -0
  25. package/dist/core/accounting/analysis.js.map +1 -0
  26. package/dist/core/accounting/equity.d.ts +33 -0
  27. package/dist/core/accounting/equity.d.ts.map +1 -1
  28. package/dist/core/accounting/equity.js +12 -0
  29. package/dist/core/accounting/equity.js.map +1 -1
  30. package/dist/core/accounting/index.d.ts +2 -0
  31. package/dist/core/accounting/index.d.ts.map +1 -1
  32. package/dist/core/accounting/index.js +1 -0
  33. package/dist/core/accounting/index.js.map +1 -1
  34. package/dist/core/accounting/report.d.ts +3 -0
  35. package/dist/core/accounting/report.d.ts.map +1 -1
  36. package/dist/core/accounting/report.js +2 -0
  37. package/dist/core/accounting/report.js.map +1 -1
  38. package/dist/core/accounting/statistics.d.ts +12 -0
  39. package/dist/core/accounting/statistics.d.ts.map +1 -1
  40. package/dist/core/accounting/statistics.js +23 -1
  41. package/dist/core/accounting/statistics.js.map +1 -1
  42. package/dist/core/backtest/case.d.ts +60 -0
  43. package/dist/core/backtest/case.d.ts.map +1 -0
  44. package/dist/core/backtest/case.js +319 -0
  45. package/dist/core/backtest/case.js.map +1 -0
  46. package/dist/core/backtest/compare.d.ts.map +1 -1
  47. package/dist/core/backtest/compare.js +2 -0
  48. package/dist/core/backtest/compare.js.map +1 -1
  49. package/dist/core/backtest/deliver.d.ts +93 -0
  50. package/dist/core/backtest/deliver.d.ts.map +1 -0
  51. package/dist/core/backtest/deliver.js +94 -0
  52. package/dist/core/backtest/deliver.js.map +1 -0
  53. package/dist/core/backtest/drive.d.ts +101 -8
  54. package/dist/core/backtest/drive.d.ts.map +1 -1
  55. package/dist/core/backtest/drive.js +114 -158
  56. package/dist/core/backtest/drive.js.map +1 -1
  57. package/dist/core/backtest/index.d.ts +26 -12
  58. package/dist/core/backtest/index.d.ts.map +1 -1
  59. package/dist/core/backtest/index.js +21 -10
  60. package/dist/core/backtest/index.js.map +1 -1
  61. package/dist/core/backtest/record.d.ts +63 -2
  62. package/dist/core/backtest/record.d.ts.map +1 -1
  63. package/dist/core/backtest/record.js +71 -4
  64. package/dist/core/backtest/record.js.map +1 -1
  65. package/dist/core/backtest/replay.d.ts.map +1 -1
  66. package/dist/core/backtest/replay.js +11 -1
  67. package/dist/core/backtest/replay.js.map +1 -1
  68. package/dist/core/backtest/simulate.d.ts +113 -1
  69. package/dist/core/backtest/simulate.d.ts.map +1 -1
  70. package/dist/core/backtest/simulate.js +123 -5
  71. package/dist/core/backtest/simulate.js.map +1 -1
  72. package/dist/core/backtest/walk.d.ts +39 -0
  73. package/dist/core/backtest/walk.d.ts.map +1 -0
  74. package/dist/core/backtest/walk.js +125 -0
  75. package/dist/core/backtest/walk.js.map +1 -0
  76. package/dist/core/catalogue/catalogue.generated.d.ts +179 -2
  77. package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -1
  78. package/dist/core/catalogue/catalogue.generated.js +19 -2
  79. package/dist/core/catalogue/catalogue.generated.js.map +1 -1
  80. package/dist/core/catalogue/types.d.ts +8 -2
  81. package/dist/core/catalogue/types.d.ts.map +1 -1
  82. package/dist/core/catalogue/values.generated.d.ts +51 -0
  83. package/dist/core/catalogue/values.generated.d.ts.map +1 -1
  84. package/dist/core/check/assigned.d.ts +19 -0
  85. package/dist/core/check/assigned.d.ts.map +1 -0
  86. package/dist/core/check/assigned.js +14 -0
  87. package/dist/core/check/assigned.js.map +1 -0
  88. package/dist/core/check/call-sites.d.ts.map +1 -1
  89. package/dist/core/check/call-sites.js +9 -4
  90. package/dist/core/check/call-sites.js.map +1 -1
  91. package/dist/core/check/calls.d.ts.map +1 -1
  92. package/dist/core/check/calls.js +12 -4
  93. package/dist/core/check/calls.js.map +1 -1
  94. package/dist/core/check/check.d.ts.map +1 -1
  95. package/dist/core/check/check.js +15 -2
  96. package/dist/core/check/check.js.map +1 -1
  97. package/dist/core/check/checker.d.ts +26 -0
  98. package/dist/core/check/checker.d.ts.map +1 -1
  99. package/dist/core/check/checker.js +38 -2
  100. package/dist/core/check/checker.js.map +1 -1
  101. package/dist/core/check/constant.d.ts +16 -0
  102. package/dist/core/check/constant.d.ts.map +1 -1
  103. package/dist/core/check/constant.js +52 -0
  104. package/dist/core/check/constant.js.map +1 -1
  105. package/dist/core/check/deleted.d.ts +3 -0
  106. package/dist/core/check/deleted.d.ts.map +1 -0
  107. package/dist/core/check/deleted.js +109 -0
  108. package/dist/core/check/deleted.js.map +1 -0
  109. package/dist/core/check/expressions.js +1 -1
  110. package/dist/core/check/expressions.js.map +1 -1
  111. package/dist/core/check/library-orders.js +2 -2
  112. package/dist/core/check/library-orders.js.map +1 -1
  113. package/dist/core/check/library-output.d.ts.map +1 -1
  114. package/dist/core/check/library-output.js +1 -0
  115. package/dist/core/check/library-output.js.map +1 -1
  116. package/dist/core/check/library-prose.generated.js +12 -12
  117. package/dist/core/check/library-prose.generated.js.map +1 -1
  118. package/dist/core/check/library.d.ts +7 -0
  119. package/dist/core/check/library.d.ts.map +1 -1
  120. package/dist/core/check/library.js +1 -0
  121. package/dist/core/check/library.js.map +1 -1
  122. package/dist/core/check/surface.d.ts +9 -0
  123. package/dist/core/check/surface.d.ts.map +1 -1
  124. package/dist/core/check/surface.js +13 -0
  125. package/dist/core/check/surface.js.map +1 -1
  126. package/dist/core/emit/canonical.d.ts +22 -8
  127. package/dist/core/emit/canonical.d.ts.map +1 -1
  128. package/dist/core/emit/canonical.js +67 -6
  129. package/dist/core/emit/canonical.js.map +1 -1
  130. package/dist/core/engine/arithmetic.d.ts +6 -25
  131. package/dist/core/engine/arithmetic.d.ts.map +1 -1
  132. package/dist/core/engine/arithmetic.js +48 -3
  133. package/dist/core/engine/arithmetic.js.map +1 -1
  134. package/dist/core/engine/bar-source.d.ts +65 -0
  135. package/dist/core/engine/bar-source.d.ts.map +1 -0
  136. package/dist/core/engine/bar-source.js +58 -0
  137. package/dist/core/engine/bar-source.js.map +1 -0
  138. package/dist/core/engine/engine.d.ts +9 -11
  139. package/dist/core/engine/engine.d.ts.map +1 -1
  140. package/dist/core/engine/engine.js +24 -24
  141. package/dist/core/engine/engine.js.map +1 -1
  142. package/dist/core/engine/guard.d.ts.map +1 -1
  143. package/dist/core/engine/guard.js +10 -0
  144. package/dist/core/engine/guard.js.map +1 -1
  145. package/dist/core/engine/host.d.ts +4 -2
  146. package/dist/core/engine/host.d.ts.map +1 -1
  147. package/dist/core/engine/host.js.map +1 -1
  148. package/dist/core/engine/index.d.ts +2 -1
  149. package/dist/core/engine/index.d.ts.map +1 -1
  150. package/dist/core/engine/index.js +1 -1
  151. package/dist/core/engine/index.js.map +1 -1
  152. package/dist/core/engine/library/arrays.d.ts.map +1 -1
  153. package/dist/core/engine/library/arrays.js +8 -2
  154. package/dist/core/engine/library/arrays.js.map +1 -1
  155. package/dist/core/engine/library/binding.d.ts +2 -0
  156. package/dist/core/engine/library/binding.d.ts.map +1 -1
  157. package/dist/core/engine/library/binding.js.map +1 -1
  158. package/dist/core/engine/library/code-points.d.ts +40 -0
  159. package/dist/core/engine/library/code-points.d.ts.map +1 -0
  160. package/dist/core/engine/library/code-points.js +74 -0
  161. package/dist/core/engine/library/code-points.js.map +1 -0
  162. package/dist/core/engine/library/index.d.ts +13 -0
  163. package/dist/core/engine/library/index.d.ts.map +1 -1
  164. package/dist/core/engine/library/index.js +15 -0
  165. package/dist/core/engine/library/index.js.map +1 -1
  166. package/dist/core/engine/library/objects.d.ts.map +1 -1
  167. package/dist/core/engine/library/objects.js +1 -1
  168. package/dist/core/engine/library/objects.js.map +1 -1
  169. package/dist/core/engine/library/text.d.ts.map +1 -1
  170. package/dist/core/engine/library/text.js +51 -34
  171. package/dist/core/engine/library/text.js.map +1 -1
  172. package/dist/core/engine/load.d.ts +20 -0
  173. package/dist/core/engine/load.d.ts.map +1 -1
  174. package/dist/core/engine/load.js +62 -0
  175. package/dist/core/engine/load.js.map +1 -1
  176. package/dist/core/engine/request-body.d.ts +3 -1
  177. package/dist/core/engine/request-body.d.ts.map +1 -1
  178. package/dist/core/engine/request-body.js +3 -1
  179. package/dist/core/engine/request-body.js.map +1 -1
  180. package/dist/core/engine/request-plan.d.ts +3 -3
  181. package/dist/core/engine/request-plan.js +3 -3
  182. package/dist/core/engine/requests.d.ts +2 -2
  183. package/dist/core/engine/requests.d.ts.map +1 -1
  184. package/dist/core/engine/requests.js +5 -4
  185. package/dist/core/engine/requests.js.map +1 -1
  186. package/dist/core/engine/series.d.ts +18 -6
  187. package/dist/core/engine/series.d.ts.map +1 -1
  188. package/dist/core/engine/series.js +24 -5
  189. package/dist/core/engine/series.js.map +1 -1
  190. package/dist/core/engine/session/record.d.ts +4 -4
  191. package/dist/core/engine/session/record.js +4 -4
  192. package/dist/core/engine/verify-tables.d.ts.map +1 -1
  193. package/dist/core/engine/verify-tables.js +41 -0
  194. package/dist/core/engine/verify-tables.js.map +1 -1
  195. package/dist/core/importer/calls.d.ts +29 -0
  196. package/dist/core/importer/calls.d.ts.map +1 -0
  197. package/dist/core/importer/calls.js +267 -0
  198. package/dist/core/importer/calls.js.map +1 -0
  199. package/dist/core/importer/context.d.ts +118 -0
  200. package/dist/core/importer/context.d.ts.map +1 -0
  201. package/dist/core/importer/context.js +120 -0
  202. package/dist/core/importer/context.js.map +1 -0
  203. package/dist/core/importer/expressions.d.ts +44 -0
  204. package/dist/core/importer/expressions.d.ts.map +1 -0
  205. package/dist/core/importer/expressions.js +223 -0
  206. package/dist/core/importer/expressions.js.map +1 -0
  207. package/dist/core/importer/importer.d.ts +13 -0
  208. package/dist/core/importer/importer.d.ts.map +1 -0
  209. package/dist/core/importer/importer.js +220 -0
  210. package/dist/core/importer/importer.js.map +1 -0
  211. package/dist/core/importer/index.d.ts +20 -0
  212. package/dist/core/importer/index.d.ts.map +1 -0
  213. package/dist/core/importer/index.js +18 -0
  214. package/dist/core/importer/index.js.map +1 -0
  215. package/dist/core/importer/lexer.d.ts +68 -0
  216. package/dist/core/importer/lexer.d.ts.map +1 -0
  217. package/dist/core/importer/lexer.js +207 -0
  218. package/dist/core/importer/lexer.js.map +1 -0
  219. package/dist/core/importer/names.d.ts +41 -0
  220. package/dist/core/importer/names.d.ts.map +1 -0
  221. package/dist/core/importer/names.js +78 -0
  222. package/dist/core/importer/names.js.map +1 -0
  223. package/dist/core/importer/orders.d.ts +8 -0
  224. package/dist/core/importer/orders.d.ts.map +1 -0
  225. package/dist/core/importer/orders.js +332 -0
  226. package/dist/core/importer/orders.js.map +1 -0
  227. package/dist/core/importer/outputs.d.ts +19 -0
  228. package/dist/core/importer/outputs.d.ts.map +1 -0
  229. package/dist/core/importer/outputs.js +266 -0
  230. package/dist/core/importer/outputs.js.map +1 -0
  231. package/dist/core/importer/parser.d.ts +5 -0
  232. package/dist/core/importer/parser.d.ts.map +1 -0
  233. package/dist/core/importer/parser.js +439 -0
  234. package/dist/core/importer/parser.js.map +1 -0
  235. package/dist/core/importer/presence.d.ts +32 -0
  236. package/dist/core/importer/presence.d.ts.map +1 -0
  237. package/dist/core/importer/presence.js +146 -0
  238. package/dist/core/importer/presence.js.map +1 -0
  239. package/dist/core/importer/settle.d.ts +23 -0
  240. package/dist/core/importer/settle.d.ts.map +1 -0
  241. package/dist/core/importer/settle.js +135 -0
  242. package/dist/core/importer/settle.js.map +1 -0
  243. package/dist/core/importer/statements.d.ts +4 -0
  244. package/dist/core/importer/statements.d.ts.map +1 -0
  245. package/dist/core/importer/statements.js +339 -0
  246. package/dist/core/importer/statements.js.map +1 -0
  247. package/dist/core/importer/syntax.d.ts +182 -0
  248. package/dist/core/importer/syntax.d.ts.map +1 -0
  249. package/dist/core/importer/syntax.js +14 -0
  250. package/dist/core/importer/syntax.js.map +1 -0
  251. package/dist/core/importer/table.d.ts +52 -0
  252. package/dist/core/importer/table.d.ts.map +1 -0
  253. package/dist/core/importer/table.js +156 -0
  254. package/dist/core/importer/table.js.map +1 -0
  255. package/dist/core/importer/values.d.ts +27 -0
  256. package/dist/core/importer/values.d.ts.map +1 -0
  257. package/dist/core/importer/values.js +236 -0
  258. package/dist/core/importer/values.js.map +1 -0
  259. package/dist/core/index.d.ts +22 -5
  260. package/dist/core/index.d.ts.map +1 -1
  261. package/dist/core/index.js +19 -3
  262. package/dist/core/index.js.map +1 -1
  263. package/dist/core/stdlib/calendar/civil.d.ts.map +1 -1
  264. package/dist/core/stdlib/calendar/civil.js +5 -2
  265. package/dist/core/stdlib/calendar/civil.js.map +1 -1
  266. package/dist/core/stdlib/index.d.ts +1 -1
  267. package/dist/core/stdlib/index.d.ts.map +1 -1
  268. package/dist/core/stdlib/index.js +1 -1
  269. package/dist/core/stdlib/index.js.map +1 -1
  270. package/dist/core/stdlib/maths/index.d.ts +1 -1
  271. package/dist/core/stdlib/maths/index.d.ts.map +1 -1
  272. package/dist/core/stdlib/maths/index.js +1 -1
  273. package/dist/core/stdlib/maths/index.js.map +1 -1
  274. package/dist/core/stdlib/maths/rounding.d.ts +5 -0
  275. package/dist/core/stdlib/maths/rounding.d.ts.map +1 -1
  276. package/dist/core/stdlib/maths/rounding.js +19 -1
  277. package/dist/core/stdlib/maths/rounding.js.map +1 -1
  278. package/dist/core/version/version.generated.d.ts +1 -1
  279. package/dist/core/version/version.generated.js +1 -1
  280. package/package.json +17 -2
  281. package/spec/README.md +2 -1
  282. package/spec/errors.json +383 -23
  283. package/src/adapters/charts/driving.ts +109 -0
  284. package/src/adapters/charts/run.ts +126 -28
  285. package/src/adapters/charts/tables.ts +6 -19
  286. package/src/adapters/charts/undrawable.ts +51 -0
  287. package/src/adapters/charts/venue.ts +132 -0
  288. package/src/core/accounting/analysis.ts +188 -0
  289. package/src/core/accounting/equity.ts +38 -0
  290. package/src/core/accounting/index.ts +2 -0
  291. package/src/core/accounting/report.ts +5 -0
  292. package/src/core/accounting/statistics.ts +38 -1
  293. package/src/core/backtest/case.ts +395 -0
  294. package/src/core/backtest/compare.ts +2 -0
  295. package/src/core/backtest/deliver.ts +161 -0
  296. package/src/core/backtest/drive.ts +233 -217
  297. package/src/core/backtest/index.ts +26 -12
  298. package/src/core/backtest/record.ts +134 -5
  299. package/src/core/backtest/replay.ts +11 -1
  300. package/src/core/backtest/simulate.ts +201 -6
  301. package/src/core/backtest/walk.ts +182 -0
  302. package/src/core/catalogue/catalogue.generated.ts +19 -2
  303. package/src/core/catalogue/types.ts +8 -2
  304. package/src/core/catalogue/values.generated.ts +16 -0
  305. package/src/core/check/assigned.ts +31 -0
  306. package/src/core/check/call-sites.ts +11 -4
  307. package/src/core/check/calls.ts +13 -4
  308. package/src/core/check/check.ts +14 -2
  309. package/src/core/check/checker.ts +39 -2
  310. package/src/core/check/constant.ts +57 -0
  311. package/src/core/check/deleted.ts +135 -0
  312. package/src/core/check/expressions.ts +1 -1
  313. package/src/core/check/library-orders.ts +2 -2
  314. package/src/core/check/library-output.ts +1 -0
  315. package/src/core/check/library-prose.generated.ts +12 -12
  316. package/src/core/check/library.ts +8 -0
  317. package/src/core/check/surface.ts +16 -0
  318. package/src/core/emit/canonical.ts +67 -9
  319. package/src/core/engine/arithmetic.ts +23 -3
  320. package/src/core/engine/bar-source.ts +113 -0
  321. package/src/core/engine/engine.ts +26 -25
  322. package/src/core/engine/guard.ts +12 -1
  323. package/src/core/engine/host.ts +4 -2
  324. package/src/core/engine/index.ts +2 -1
  325. package/src/core/engine/library/arrays.ts +8 -2
  326. package/src/core/engine/library/binding.ts +2 -0
  327. package/src/core/engine/library/code-points.ts +73 -0
  328. package/src/core/engine/library/index.ts +17 -0
  329. package/src/core/engine/library/objects.ts +1 -6
  330. package/src/core/engine/library/text.ts +53 -35
  331. package/src/core/engine/load.ts +68 -0
  332. package/src/core/engine/request-body.ts +5 -7
  333. package/src/core/engine/request-plan.ts +3 -3
  334. package/src/core/engine/requests.ts +11 -8
  335. package/src/core/engine/series.ts +30 -6
  336. package/src/core/engine/session/record.ts +4 -4
  337. package/src/core/engine/verify-tables.ts +43 -0
  338. package/src/core/importer/calls.ts +274 -0
  339. package/src/core/importer/context.ts +197 -0
  340. package/src/core/importer/expressions.ts +247 -0
  341. package/src/core/importer/importer.ts +226 -0
  342. package/src/core/importer/index.ts +19 -0
  343. package/src/core/importer/lexer.ts +285 -0
  344. package/src/core/importer/names.ts +104 -0
  345. package/src/core/importer/orders.ts +307 -0
  346. package/src/core/importer/outputs.ts +245 -0
  347. package/src/core/importer/parser.ts +436 -0
  348. package/src/core/importer/presence.ts +164 -0
  349. package/src/core/importer/settle.ts +141 -0
  350. package/src/core/importer/statements.ts +331 -0
  351. package/src/core/importer/syntax.ts +144 -0
  352. package/src/core/importer/table.ts +191 -0
  353. package/src/core/importer/values.ts +241 -0
  354. package/src/core/index.ts +29 -2
  355. package/src/core/stdlib/calendar/civil.ts +5 -2
  356. package/src/core/stdlib/index.ts +1 -0
  357. package/src/core/stdlib/maths/index.ts +1 -0
  358. package/src/core/stdlib/maths/rounding.ts +23 -1
  359. package/src/core/version/version.generated.ts +1 -1
@@ -1,16 +1,77 @@
1
1
  import { sha256 } from './sha256.js';
2
2
  /**
3
- * A number, shortest round trip.
3
+ * A number as text: the one writer.
4
4
  *
5
- * The host's own shortest form is already the shortest that reads back
6
- * identically. What it is not is the spelling the specification asks for: a
7
- * positive exponent is written with a `+` that the format does not allow, so
8
- * that one sign is removed and nothing else is touched.
5
+ * Two engines compare numbers as bits, but they compare text in a case file, an
6
+ * expected column, a table cell and `text(x)`, so how a number becomes text has
7
+ * to be one rule that both implement, and in this repository it has to be one
8
+ * function. This is that function. `scripts/check-number-writer.mjs` reads
9
+ * every file under `src` and refuses a conversion outside this module, so a
10
+ * number cannot reach text by a host's default somewhere else and disagree with
11
+ * this one by a plus sign.
12
+ *
13
+ * **The digits are the host's and the layout is not.** The shortest decimal
14
+ * digit string that reads back as the same binary64 is what every host this
15
+ * engine runs on produces, and what a second engine's host produces too; that
16
+ * part is taken from the host's own shortest form. Where the two hosts part
17
+ * company is the layout, when a value is written positionally and when with an
18
+ * exponent, and how the exponent is spelled, so that half is written here from
19
+ * the rule in `language.md` 5.5 and not left to the host. The rule is the one
20
+ * the first host follows natively, minus the `+` it writes on a positive
21
+ * exponent, and `spec/vectors/number-text.json` holds the boundary cases a
22
+ * second engine checks itself against.
9
23
  */
10
24
  export function canonicalNumber(value) {
11
25
  if (!Number.isFinite(value))
12
26
  throw new Error('a compiled program holds finite numbers only');
13
- return String(value === 0 ? 0 : value).replace('e+', 'e');
27
+ // Zero and negative zero are one value to the language (compiled-program.md
28
+ // 3.1) and one spelling here.
29
+ if (value === 0)
30
+ return '0';
31
+ const { digits, point } = shortestDigits(Math.abs(value));
32
+ return (value < 0 ? '-' : '') + layout(digits, point);
33
+ }
34
+ /**
35
+ * The shortest round trip digits of a positive finite magnitude, and where the
36
+ * decimal point falls: the value is `0.d1d2...dk` times ten to the `point`.
37
+ *
38
+ * Read out of the host's own shortest form rather than computed here, because
39
+ * the search for the shortest digit string is the one part of the conversion
40
+ * every host already agrees on. Whatever layout the host chose is undone: the
41
+ * digits and the point are all that is kept.
42
+ */
43
+ function shortestDigits(magnitude) {
44
+ const shown = String(magnitude);
45
+ const e = shown.indexOf('e');
46
+ const mantissa = e < 0 ? shown : shown.slice(0, e);
47
+ const exponent = e < 0 ? 0 : Number(shown.slice(e + 1));
48
+ const dot = mantissa.indexOf('.');
49
+ const whole = dot < 0 ? mantissa : mantissa.slice(0, dot);
50
+ const fraction = dot < 0 ? '' : mantissa.slice(dot + 1);
51
+ let digits = whole + fraction;
52
+ let point = whole.length + exponent;
53
+ // A positional form below one carries leading zeros that are not digits of
54
+ // the value, and a whole number carries trailing zeros that are its layout.
55
+ while (digits.startsWith('0')) {
56
+ digits = digits.slice(1);
57
+ point -= 1;
58
+ }
59
+ while (digits.endsWith('0'))
60
+ digits = digits.slice(0, -1);
61
+ return { digits, point };
62
+ }
63
+ /** `language.md` 5.5: positional between the two thresholds, an exponent outside them. */
64
+ function layout(digits, point) {
65
+ const count = digits.length;
66
+ if (count <= point && point <= 21)
67
+ return digits + '0'.repeat(point - count);
68
+ if (0 < point && point <= 21)
69
+ return `${digits.slice(0, point)}.${digits.slice(point)}`;
70
+ if (-6 < point && point <= 0)
71
+ return `0.${'0'.repeat(-point)}${digits}`;
72
+ const exponent = point - 1;
73
+ const lead = count === 1 ? digits : `${digits[0]}.${digits.slice(1)}`;
74
+ return `${lead}e${exponent < 0 ? '-' : ''}${String(Math.abs(exponent))}`;
14
75
  }
15
76
  export function canonicalString(value) {
16
77
  let out = '"';
@@ -1 +1 @@
1
- {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../../src/core/emit/canonical.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C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C;aACnE,IAAI,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,IAAI,GAAG,CAAC;IACrB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,mDAAmD,OAAO,KAAK,EAAE,CAAC,CAAC;AACrF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,UAAU,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAwB;IAClD,OAAO,UAAU,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;AACnD,CAAC"}
@@ -1,28 +1,3 @@
1
- /**
2
- * The operator instructions, `compiled-program.md` 4.5 to 4.7.
3
- *
4
- * Five rules live in this file and nowhere else, which is section 7's claim
5
- * about the whole language: absence propagates through arithmetic and ordering
6
- * comparison, is total under equality, is three-valued under `and`, `or` and
7
- * `not`, and is false at a branch. The last one is `JUMP_FALSE` and is in the
8
- * machine; the other four are here. An engine that gets all five right has the
9
- * whole of `language.md` section 6, and an engine that special cases absence
10
- * anywhere else has a bug.
11
- *
12
- * Two details that look like nothing and are not:
13
- *
14
- * **Finiteness is checked after each individual operation**, not at the end of
15
- * an expression, so `(1e308 * 10) / 10` is absent rather than `1e307`. Checking
16
- * per expression would make the answer depend on where an engine happened to
17
- * round, which is the whole failure this project exists to prevent.
18
- *
19
- * **`MOD` is truncated division and the library's `mod` is floored.** They are
20
- * different functions with the same name in two places on purpose: the operator
21
- * follows the sign of its left operand, which is what every language's `%`
22
- * does, and the library call follows the sign of its right operand, which is
23
- * what a script wants when it wraps an index. Collapsing them would silently
24
- * change one of the two.
25
- */
26
1
  import type { Value } from './values/index.js';
27
2
  /** Whether a corrupt program reached an operator with tags it cannot take. */
28
3
  export declare class OperandMismatch extends Error {
@@ -53,6 +28,12 @@ export declare function negate(a: Value): Value;
53
28
  * absence is treated two ways, and it is deliberate: an operator that can
54
29
  * itself be absent gives a script no way to ask whether a value is absent at
55
30
  * all, so equality is the exception and every other comparison is not.
31
+ *
32
+ * **Two strings are ordered by code point** (`language.md` 9.3, `stdlib.md`
33
+ * section 10), through the one order `sort` uses, and not by the host's own
34
+ * operator, which orders by sixteen bit unit and puts a symbol outside the
35
+ * basic plane below the last thousands of the plane. Numbers take the host's
36
+ * operator, which is the binary64 order every engine shares.
56
37
  */
57
38
  export declare function compare(opcode: 'LT' | 'LE' | 'GT' | 'GE', a: Value, b: Value): Value;
58
39
  /** `EQ` and `NE` are total: they always produce a boolean. */
@@ -1 +1 @@
1
- {"version":3,"file":"arithmetic.d.ts","sourceRoot":"","sources":["../../../src/core/engine/arithmetic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,8EAA8E;AAC9E,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM;CAK3B;AAED;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAK7C;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAElD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAElD;AAED,iEAAiE;AACjE,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAIhD;AAED,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAInD;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAItC;AAaD;;;;;;;;GAQG;AACH,wBA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,GAAG,KAAK,CAIhD;AAED,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAInD;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAItC;AAaD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAcpF;AAgBD,8DAA8D;AAC9D,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,OAAO,CAElD;AAED,0EAA0E;AAC1E,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAInC;AAED;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAK7C;AAED,iFAAiF;AACjF,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAK5C;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAE9C"}
@@ -1,3 +1,29 @@
1
+ /**
2
+ * The operator instructions, `compiled-program.md` 4.5 to 4.7.
3
+ *
4
+ * Five rules live in this file and nowhere else, which is section 7's claim
5
+ * about the whole language: absence propagates through arithmetic and ordering
6
+ * comparison, is total under equality, is three-valued under `and`, `or` and
7
+ * `not`, and is false at a branch. The last one is `JUMP_FALSE` and is in the
8
+ * machine; the other four are here. An engine that gets all five right has the
9
+ * whole of `language.md` section 6, and an engine that special cases absence
10
+ * anywhere else has a bug.
11
+ *
12
+ * Two details that look like nothing and are not:
13
+ *
14
+ * **Finiteness is checked after each individual operation**, not at the end of
15
+ * an expression, so `(1e308 * 10) / 10` is absent rather than `1e307`. Checking
16
+ * per expression would make the answer depend on where an engine happened to
17
+ * round, which is the whole failure this project exists to prevent.
18
+ *
19
+ * **`MOD` is truncated division and the library's `mod` is floored.** They are
20
+ * different functions with the same name in two places on purpose: the operator
21
+ * follows the sign of its left operand, which is what every language's `%`
22
+ * does, and the library call follows the sign of its right operand, which is
23
+ * what a script wants when it wraps an index. Collapsing them would silently
24
+ * change one of the two.
25
+ */
26
+ import { compareStrings } from './library/index.js';
1
27
  import { ABSENT, numberValue, valuesEqual } from './values/index.js';
2
28
  /** Whether a corrupt program reached an operator with tags it cannot take. */
3
29
  export class OperandMismatch extends Error {
@@ -69,13 +95,19 @@ function numeric(opcode, a, b, of) {
69
95
  * absence is treated two ways, and it is deliberate: an operator that can
70
96
  * itself be absent gives a script no way to ask whether a value is absent at
71
97
  * all, so equality is the exception and every other comparison is not.
98
+ *
99
+ * **Two strings are ordered by code point** (`language.md` 9.3, `stdlib.md`
100
+ * section 10), through the one order `sort` uses, and not by the host's own
101
+ * operator, which orders by sixteen bit unit and puts a symbol outside the
102
+ * basic plane below the last thousands of the plane. Numbers take the host's
103
+ * operator, which is the binary64 order every engine shares.
72
104
  */
73
105
  export function compare(opcode, a, b) {
74
106
  if (a === null || b === null)
75
107
  return ABSENT;
76
- const bothNumbers = typeof a === 'number' && typeof b === 'number';
77
- const bothStrings = typeof a === 'string' && typeof b === 'string';
78
- if (!bothNumbers && !bothStrings)
108
+ if (typeof a === 'string' && typeof b === 'string')
109
+ return ordered(opcode, compareStrings(a, b));
110
+ if (typeof a !== 'number' || typeof b !== 'number')
79
111
  throw new OperandMismatch(opcode);
80
112
  switch (opcode) {
81
113
  case 'LT':
@@ -88,6 +120,19 @@ export function compare(opcode, a, b) {
88
120
  return a >= b;
89
121
  }
90
122
  }
123
+ /** An ordering comparison read off a three way order: negative, zero or positive. */
124
+ function ordered(opcode, order) {
125
+ switch (opcode) {
126
+ case 'LT':
127
+ return order < 0;
128
+ case 'LE':
129
+ return order <= 0;
130
+ case 'GT':
131
+ return order > 0;
132
+ default:
133
+ return order >= 0;
134
+ }
135
+ }
91
136
  /** `EQ` and `NE` are total: they always produce a boolean. */
92
137
  export function equals(a, b) {
93
138
  return valuesEqual(a, b);
@@ -1 +1 @@
1
- {"version":3,"file":"arithmetic.js","sourceRoot":"","sources":["../../../src/core/engine/arithmetic.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErE,8EAA8E;AAC9E,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,MAAM,CAAS;IAExB,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,CAAC,CAAQ,EAAE,CAAQ;IACpC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAC5C,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9E,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACjE,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,CAAQ,EAAE,CAAQ;IACzC,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,CAAQ,EAAE,CAAQ;IACz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S;QAAE,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;IAC7D,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,CAAC,CAAQ,EAAE,CAAQ;IACpC,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAC7C,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAC5C,IAAI,OAAO,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;IACvF,OAAO,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,EAAE,CAAC,CAAQ,EAAE,CAAQ;IACnC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAC5C,IAAI,OAAO,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;IACtF,OAAO,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAY;IACnC,OAAO,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Where the bars a run reads come from: an array of records, or columns.
3
+ *
4
+ * The bar cycle reads one bar at a time and does not care where its fields come
5
+ * from, so the representation is decided at the door and nowhere else. Two are
6
+ * accepted (issue 0005):
7
+ *
8
+ * - **Records**, one `HostBar` per bar, which is the live path: one bar arrives
9
+ * at a time and an array of one is absurd.
10
+ * - **Columns**, one array per field, owned by the host. A long history held as
11
+ * columns costs about a third of the memory of one object per bar and no
12
+ * allocation per bar at rest, and a store that already holds bars as columns
13
+ * can hand over typed array views with no parse at all. The engine reads
14
+ * `open[i]` when bar `i` executes and builds the one record that execution
15
+ * needs, which is gone by the next bar.
16
+ *
17
+ * **In a column, absence is `null` or `NaN`.** A typed array cannot hold `null`,
18
+ * and a price the host does not have is absent, never zero (`host-interface.md`
19
+ * 3.1), so `NaN` is the typed array's spelling of it. A time that is `NaN` is a
20
+ * bar with no time, which the hand-over refuses with OS6025 exactly as it
21
+ * refuses a record with none.
22
+ *
23
+ * **The number of bars is the length of `time`.** A shorter price, volume or
24
+ * interest column reads as absent past its end, which is the same thing a hole in
25
+ * a record is, and nothing is invented to fill it.
26
+ */
27
+ import type { HostBar } from './bars.js';
28
+ /** Numbers by bar index, absent written as `null` or `NaN`. */
29
+ export type BarColumn = ArrayLike<number | null>;
30
+ /** A history as columns, one per field of `host-interface.md` 3.1. */
31
+ export interface BarColumns {
32
+ readonly time: BarColumn;
33
+ readonly open: BarColumn;
34
+ readonly high: BarColumn;
35
+ readonly low: BarColumn;
36
+ readonly close: BarColumn;
37
+ readonly volume?: BarColumn;
38
+ readonly oi?: BarColumn;
39
+ }
40
+ /** What the bar cycle and the fold read: how many bars, and bar `i`. */
41
+ export interface BarSource {
42
+ readonly length: number;
43
+ at(index: number): HostBar | undefined;
44
+ }
45
+ export declare function isColumns(bars: readonly HostBar[] | BarColumns): bars is BarColumns;
46
+ /** Either form, as the bar cycle and the fold read it. */
47
+ export declare function sourceOf(bars: readonly HostBar[] | BarColumns): BarSource;
48
+ export declare function recordSource(bars: readonly HostBar[]): BarSource;
49
+ export declare function columnSource(columns: BarColumns): BarSource;
50
+ /**
51
+ * The bars a run has been handed: a whole history, then whatever arrives live.
52
+ *
53
+ * `run` replaces the history; `append` and `update` write one bar over it. A
54
+ * bar written live is held as the record it arrived as, which is the only form
55
+ * a live bar has.
56
+ */
57
+ export declare class KnownBars implements BarSource {
58
+ private base;
59
+ private readonly live;
60
+ get length(): number;
61
+ at(index: number): HostBar | undefined;
62
+ set(index: number, bar: HostBar): void;
63
+ reset(base: BarSource): void;
64
+ }
65
+ //# sourceMappingURL=bar-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bar-source.d.ts","sourceRoot":"","sources":["../../../src/core/engine/bar-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,+DAA+D;AAC/D,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAEjD,sEAAsE;AACtE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC;CACzB;AAED,wEAAwE;AACxE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CACxC;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,UAAU,GAAG,IAAI,IAAI,UAAU,CAEnF;AAED,0DAA0D;AAC1D,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,UAAU,GAAG,SAAS,CAEzE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,CAEhE;AAOD,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAiB3D;AAED;;;;;;GAMG;AACH,qBAAa,SAAU,YAAW,SAAS;IACzC,OAAO,CAAC,IAAI,CAA+B;IAC3C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IAEtC,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAItC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IAItC,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;CAI7B"}
@@ -0,0 +1,58 @@
1
+ export function isColumns(bars) {
2
+ return !Array.isArray(bars);
3
+ }
4
+ /** Either form, as the bar cycle and the fold read it. */
5
+ export function sourceOf(bars) {
6
+ return isColumns(bars) ? columnSource(bars) : recordSource(bars);
7
+ }
8
+ export function recordSource(bars) {
9
+ return { get length() { return bars.length; }, at: (index) => bars[index] };
10
+ }
11
+ function cell(column, index) {
12
+ const value = column === undefined || index >= column.length ? null : column[index];
13
+ return value === null || value === undefined || Number.isNaN(value) ? null : value;
14
+ }
15
+ export function columnSource(columns) {
16
+ const length = columns.time.length;
17
+ return {
18
+ length,
19
+ at(index) {
20
+ if (index < 0 || index >= length)
21
+ return undefined;
22
+ return {
23
+ time: cell(columns.time, index),
24
+ open: cell(columns.open, index),
25
+ high: cell(columns.high, index),
26
+ low: cell(columns.low, index),
27
+ close: cell(columns.close, index),
28
+ volume: cell(columns.volume, index),
29
+ oi: cell(columns.oi, index),
30
+ };
31
+ },
32
+ };
33
+ }
34
+ /**
35
+ * The bars a run has been handed: a whole history, then whatever arrives live.
36
+ *
37
+ * `run` replaces the history; `append` and `update` write one bar over it. A
38
+ * bar written live is held as the record it arrived as, which is the only form
39
+ * a live bar has.
40
+ */
41
+ export class KnownBars {
42
+ base = recordSource([]);
43
+ live = [];
44
+ get length() {
45
+ return Math.max(this.base.length, this.live.length);
46
+ }
47
+ at(index) {
48
+ return this.live[index] ?? this.base.at(index);
49
+ }
50
+ set(index, bar) {
51
+ this.live[index] = bar;
52
+ }
53
+ reset(base) {
54
+ this.base = base;
55
+ this.live.length = 0;
56
+ }
57
+ }
58
+ //# sourceMappingURL=bar-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bar-source.js","sourceRoot":"","sources":["../../../src/core/engine/bar-source.ts"],"names":[],"mappings":"AAgDA,MAAM,UAAU,SAAS,CAAC,IAAqC;IAC7D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,QAAQ,CAAC,IAAqC;IAC5D,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAwB;IACnD,OAAO,EAAE,IAAI,MAAM,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;AAC9E,CAAC;AAED,SAAS,IAAI,CAAC,MAA6B,EAAE,KAAa;IACxD,MAAM,KAAK,GAAG,MAAM,KAAK,SAAS,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpF,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAmB;IAC9C,MAAM,MAAM,GAAG,OAAO,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IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACvB,CAAC;CACF"}
@@ -6,6 +6,7 @@ import type { Grid } from './grids.js';
6
6
  import type { LedgerRow, OrderFrame } from './ledger/index.js';
7
7
  import type { CompiledProgram } from './types.js';
8
8
  import type { RequestPlan } from './request-plan.js';
9
+ import type { BarColumns } from './bar-source.js';
9
10
  import type { Value } from './values/index.js';
10
11
  import type { Drawing } from './drawings.js';
11
12
  import type { BarResult, RunResult } from './results.js';
@@ -47,7 +48,7 @@ export declare class Engine {
47
48
  * chart bar is inside, and on a live feed there is nothing there yet. That is
48
49
  * the mode repainting on history, permanently and by design.
49
50
  */
50
- private known;
51
+ private readonly known;
51
52
  private supplied;
52
53
  private index;
53
54
  private updates;
@@ -96,7 +97,12 @@ export declare class Engine {
96
97
  * pane with nothing drawn on it is what a study that computed nothing also
97
98
  * produces and only the engine can tell the two apart.
98
99
  */
99
- run(bars: readonly HostBar[], states?: readonly BarState[]): RunResult;
100
+ run(bars: readonly HostBar[] | BarColumns, states?: readonly BarState[]): RunResult;
101
+ /**
102
+ * The dataset a driver appends one bar at a time, handed to the fold before
103
+ * bar 0 as `run` hands it, so a `"lookahead"` read reads it as history.
104
+ */
105
+ history(bars: readonly HostBar[] | BarColumns): void;
100
106
  /**
101
107
  * A frame from the destination, `host-interface.md` 7.2. Held until the next
102
108
  * bar begins rather than folded where it lands: nothing reaches a running
@@ -107,15 +113,6 @@ export declare class Engine {
107
113
  /** The strategy's own ledger, `stdlib.md` 17.7, oldest row first. */
108
114
  orders(): readonly LedgerRow[];
109
115
  private execute;
110
- /**
111
- * A bar that failed.
112
- *
113
- * Steps 7 to 11 do not run, the bar's output columns keep whatever the
114
- * previous execution published or stay absent, and the engine reports the
115
- * error with its code and source position. It does not continue to the next
116
- * bar with a half executed state, so the journal is rolled back and the
117
- * script is marked stopped.
118
- */
119
116
  /**
120
117
  * A hand-over the engine refuses, before any of it has been executed.
121
118
  *
@@ -126,6 +123,7 @@ export declare class Engine {
126
123
  * state nobody can account for.
127
124
  */
128
125
  private refuse;
126
+ /** A bar that failed: steps 7 to 11 do not run, the journal rolls back, the script stops. */
129
127
  private stopped;
130
128
  /** Step 11, and the sweep that pays for the objects the bar left behind. */
131
129
  private checkpoint;
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/core/engine/engine.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAY,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAI7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAK7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAY,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAc;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CA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,7 +13,8 @@ import { Registers } from './registers.js';
13
13
  import { Grids } from './grids.js';
14
14
  import { ledgerFor, routedEffects } from './orders.js';
15
15
  import { NO_SESSION, sessionReader } from './session/index.js';
16
- import { noBars, outOfOrder } from './series.js';
16
+ import { handOver, noBars } from './series.js';
17
+ import { KnownBars, sourceOf } from './bar-source.js';
17
18
  import { barMinutesOf } from './timeframe.js';
18
19
  import { RequestSet } from './requests.js';
19
20
  import { Heap } from './values/index.js';
@@ -56,7 +57,7 @@ export class Engine {
56
57
  * chart bar is inside, and on a live feed there is nothing there yet. That is
57
58
  * the mode repainting on history, permanently and by design.
58
59
  */
59
- known = [];
60
+ known = new KnownBars();
60
61
  supplied = 0;
61
62
  index = -1;
62
63
  updates = 0;
@@ -155,7 +156,7 @@ export class Engine {
155
156
  // that has already failed keeps the failure it has, which is the one that
156
157
  // explains what went wrong first.
157
158
  if (this.failure === undefined) {
158
- const problem = outOfOrder(bar, this.known[this.index], this.index + 1);
159
+ const problem = handOver(bar, this.known.at(this.index), this.index + 1);
159
160
  if (problem !== undefined)
160
161
  return this.refuse(problem);
161
162
  }
@@ -167,7 +168,7 @@ export class Engine {
167
168
  this.started = true;
168
169
  this.previousClose = this.lastClose;
169
170
  if (this.known.length <= this.index)
170
- this.known[this.index] = bar;
171
+ this.known.set(this.index, bar);
171
172
  return this.execute(bar, state, true);
172
173
  }
173
174
  /**
@@ -185,7 +186,7 @@ export class Engine {
185
186
  // update whose time has moved back onto the bar before it is a series the
186
187
  // engine cannot run on, whatever it is called.
187
188
  if (this.failure === undefined) {
188
- const problem = outOfOrder(bar, this.known[this.index - 1], this.index);
189
+ const problem = handOver(bar, this.known.at(this.index - 1), this.index);
189
190
  if (problem !== undefined)
190
191
  return this.refuse(problem);
191
192
  }
@@ -193,7 +194,7 @@ export class Engine {
193
194
  this.updates += 1;
194
195
  // A revision replaces the bar the fold already read, so the bucket it is
195
196
  // inside is rebuilt from this reading rather than from the one it replaced.
196
- this.known[this.index] = bar;
197
+ this.known.set(this.index, bar);
197
198
  return this.execute(bar, state, false);
198
199
  }
199
200
  /**
@@ -211,27 +212,34 @@ export class Engine {
211
212
  * produces and only the engine can tell the two apart.
212
213
  */
213
214
  run(bars, states = []) {
215
+ const source = sourceOf(bars);
214
216
  const out = [];
215
- // A dataset with nothing in it is the one hand-over that has no bar to
216
- // report against, so it is answered here rather than by the loop below,
217
- // which would run no iterations and return a clean, empty, wordless result.
218
- if (bars.length === 0 && !this.started) {
217
+ // No bars at all is answered here: the loop below would return an empty, wordless result.
218
+ if (source.length === 0 && !this.started) {
219
219
  const diagnostic = this.failure ?? noBars(this.options.host?.instrument);
220
220
  this.failure = diagnostic;
221
221
  return { bars: [], diagnostic };
222
222
  }
223
- this.known = [...bars];
224
- for (let i = 0; i < bars.length; i += 1) {
225
- const bar = bars[i];
223
+ this.known.reset(source);
224
+ for (let i = 0; i < source.length; i += 1) {
225
+ const bar = source.at(i);
226
226
  if (bar === undefined)
227
227
  continue;
228
- const result = this.append(bar, states[i] ?? {}, bars.length);
228
+ const result = this.append(bar, states[i] ?? {}, source.length);
229
229
  out.push(result);
230
230
  if (result.diagnostic !== undefined)
231
231
  return { bars: out, diagnostic: result.diagnostic };
232
232
  }
233
233
  return { bars: out, diagnostic: undefined };
234
234
  }
235
+ /**
236
+ * The dataset a driver appends one bar at a time, handed to the fold before
237
+ * bar 0 as `run` hands it, so a `"lookahead"` read reads it as history.
238
+ */
239
+ history(bars) {
240
+ if (!this.started)
241
+ this.known.reset(sourceOf(bars));
242
+ }
235
243
  /**
236
244
  * A frame from the destination, `host-interface.md` 7.2. Held until the next
237
245
  * bar begins rather than folded where it lands: nothing reaches a running
@@ -266,7 +274,7 @@ export class Engine {
266
274
  // session or is inside the one that bar was already in. Read from the bars
267
275
  // themselves rather than carried, so a re-executed bar compares against the
268
276
  // same neighbour it compared against the first time.
269
- const previous = this.known[index - 1]?.time ?? null;
277
+ const previous = this.known.at(index - 1)?.time ?? null;
270
278
  this.facts = factsFor(index, this.supplied, state, isNew, this.updates, this.sessions.factsAt(bar.time ?? null, previous));
271
279
  this.view = barViewOf(bar, this.facts, this.previousClose);
272
280
  try {
@@ -331,15 +339,6 @@ export class Engine {
331
339
  diagnostic: undefined,
332
340
  };
333
341
  }
334
- /**
335
- * A bar that failed.
336
- *
337
- * Steps 7 to 11 do not run, the bar's output columns keep whatever the
338
- * previous execution published or stay absent, and the engine reports the
339
- * error with its code and source position. It does not continue to the next
340
- * bar with a half executed state, so the journal is rolled back and the
341
- * script is marked stopped.
342
- */
343
342
  /**
344
343
  * A hand-over the engine refuses, before any of it has been executed.
345
344
  *
@@ -361,6 +360,7 @@ export class Engine {
361
360
  diagnostic,
362
361
  };
363
362
  }
363
+ /** A bar that failed: steps 7 to 11 do not run, the journal rolls back, the script stops. */
364
364
  stopped(thrown) {
365
365
  const diagnostic = thrown instanceof ScriptError ? thrown.diagnostic : unexpected('the bar', thrown);
366
366
  this.rollback();