numbl 0.4.21 → 0.4.22

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 (281) hide show
  1. package/binding.gyp +12 -6
  2. package/dist-browser/browser/index.d.ts +1 -1
  3. package/dist-browser/browser/mip.d.ts +7 -0
  4. package/dist-browser/browser/protocol.d.ts +1 -1
  5. package/dist-browser/browser.js +1 -1
  6. package/dist-browser/db/operations.d.ts +0 -1
  7. package/dist-browser/gpuHelper.d.ts +29 -0
  8. package/dist-browser/hooks/projectFilesState.d.ts +37 -0
  9. package/dist-browser/numbl-core/execSession.d.ts +39 -0
  10. package/dist-browser/numbl-core/executeCode.d.ts +10 -1
  11. package/dist-browser/numbl-core/executors/classification.d.ts +2 -10
  12. package/dist-browser/numbl-core/executors/jit/backend.d.ts +65 -0
  13. package/dist-browser/numbl-core/executors/jit/cBackend.d.ts +22 -0
  14. package/dist-browser/numbl-core/executors/jit/callExecutor.d.ts +13 -44
  15. package/dist-browser/numbl-core/executors/jit/hostHelpers.d.ts +24 -0
  16. package/dist-browser/numbl-core/executors/jit/jsBackend.d.ts +15 -0
  17. package/dist-browser/numbl-core/executors/jit/loopExecutor.d.ts +13 -40
  18. package/dist-browser/numbl-core/executors/jit/session.d.ts +1 -1
  19. package/dist-browser/numbl-core/executors/jit/topLevelExecutor.d.ts +13 -33
  20. package/dist-browser/numbl-core/executors/jit/valueAdapterC.d.ts +32 -48
  21. package/dist-browser/numbl-core/executors/lowering.d.ts +38 -96
  22. package/dist-browser/numbl-core/executors/plugins.d.ts +14 -28
  23. package/dist-browser/numbl-core/executors/registry.d.ts +32 -133
  24. package/dist-browser/numbl-core/executors/types.d.ts +30 -92
  25. package/dist-browser/numbl-core/functionResolve.d.ts +3 -13
  26. package/dist-browser/numbl-core/helpers/check-helpers.d.ts +0 -5
  27. package/dist-browser/numbl-core/helpers/glob.d.ts +14 -0
  28. package/dist-browser/numbl-core/helpers/linsolve.d.ts +3 -13
  29. package/dist-browser/numbl-core/helpers/reduction-helpers.d.ts +2 -4
  30. package/dist-browser/numbl-core/helpers/shape-utils.d.ts +10 -0
  31. package/dist-browser/numbl-core/interpreter/builtins/index.d.ts +3 -1
  32. package/dist-browser/numbl-core/interpreter/builtins/time-system.d.ts +0 -1
  33. package/dist-browser/numbl-core/interpreter/builtins/types.d.ts +7 -7
  34. package/dist-browser/numbl-core/interpreter/interpreter.d.ts +6 -6
  35. package/dist-browser/numbl-core/interpreter/interpreterFunctions.d.ts +9 -1
  36. package/dist-browser/numbl-core/interpreter/interpreterSpecialBuiltins.d.ts +6 -3
  37. package/dist-browser/numbl-core/jit/builtins/defs/_shared.d.ts +1 -5
  38. package/dist-browser/numbl-core/jit/builtins/defs/arithmetic/_elemwise.d.ts +1 -2
  39. package/dist-browser/numbl-core/jit/builtins/defs/logical/_unary_pred.d.ts +3 -3
  40. package/dist-browser/numbl-core/jit/builtins/defs/logical/fieldnames.d.ts +1 -1
  41. package/dist-browser/numbl-core/jit/builtins/defs/logical/strcmp.d.ts +1 -1
  42. package/dist-browser/numbl-core/jit/builtins/defs/math/_unary_real.d.ts +5 -2
  43. package/dist-browser/numbl-core/jit/builtins/defs/math/realsqrt.d.ts +6 -0
  44. package/dist-browser/numbl-core/jit/builtins/defs/reduction/_shape.d.ts +0 -5
  45. package/dist-browser/numbl-core/jit/builtins/defs/shape/_construct.d.ts +0 -4
  46. package/dist-browser/numbl-core/jit/builtins/defs/shape/_triangular.d.ts +2 -8
  47. package/dist-browser/numbl-core/jit/builtins/defs/system/deal.d.ts +4 -5
  48. package/dist-browser/numbl-core/jit/builtins/defs/system/feval.d.ts +7 -29
  49. package/dist-browser/numbl-core/jit/builtins/registry.d.ts +15 -30
  50. package/dist-browser/numbl-core/jit/builtins/runtime/system/cdiv.d.ts +4 -0
  51. package/dist-browser/numbl-core/jit/builtins/runtime/system/cscalar.d.ts +4 -0
  52. package/dist-browser/numbl-core/jit/builtins/runtime/tensor_ops/tensor_elemwise_real_fn.d.ts +45 -15
  53. package/dist-browser/numbl-core/jit/builtins/runtime/tensor_ops/tensor_reduce_real.d.ts +5 -5
  54. package/dist-browser/numbl-core/jit/builtins/runtime/tensor_ops/tensor_unary_real_math.d.ts +6 -0
  55. package/dist-browser/numbl-core/jit/codegen/emit.d.ts +9 -30
  56. package/dist-browser/numbl-core/jit/codegen/emitJs.d.ts +9 -27
  57. package/dist-browser/numbl-core/jit/codegen/emitStmt.d.ts +8 -31
  58. package/dist-browser/numbl-core/jit/codegen/emitTensorFused.d.ts +10 -9
  59. package/dist-browser/numbl-core/jit/codegen/inlinePass.d.ts +39 -48
  60. package/dist-browser/numbl-core/jit/codegen/prettyIR.d.ts +1 -6
  61. package/dist-browser/numbl-core/jit/codegen/runtime.d.ts +7 -28
  62. package/dist-browser/numbl-core/jit/compileSpec.d.ts +3 -6
  63. package/dist-browser/numbl-core/jit/compileSpecC.d.ts +5 -0
  64. package/dist-browser/numbl-core/jit/lowering/assignedFlags.d.ts +24 -0
  65. package/dist-browser/numbl-core/jit/lowering/definiteAssign.d.ts +3 -1
  66. package/dist-browser/numbl-core/jit/lowering/errors.d.ts +3 -15
  67. package/dist-browser/numbl-core/jit/lowering/ir.d.ts +0 -2
  68. package/dist-browser/numbl-core/jit/lowering/lower.d.ts +4 -12
  69. package/dist-browser/numbl-core/jit/lowering/types.d.ts +2 -7
  70. package/dist-browser/numbl-core/jit/numbl/index.d.ts +5 -14
  71. package/dist-browser/numbl-core/jit/parser/index.d.ts +4 -9
  72. package/dist-browser/numbl-core/jit/workspace/workspace.d.ts +32 -136
  73. package/dist-browser/numbl-core/jitDeclineDiagnostics.d.ts +1 -1
  74. package/dist-browser/numbl-core/jsUserFunctions.d.ts +10 -12
  75. package/dist-browser/numbl-core/lowering/classInfo.d.ts +4 -1
  76. package/dist-browser/numbl-core/lowering/loweringContext.d.ts +15 -23
  77. package/dist-browser/numbl-core/native/lapack-bridge.d.ts +111 -130
  78. package/dist-browser/numbl-core/native/ts-lapack-bridge.d.ts +4 -5
  79. package/dist-browser/numbl-core/native/ts-lapack-complex.d.ts +23 -0
  80. package/dist-browser/numbl-core/native/ts-lapack-qr-lu.d.ts +37 -0
  81. package/dist-browser/numbl-core/native/wasm-lapack-bridge.d.ts +4 -5
  82. package/dist-browser/numbl-core/ops/dispatch.d.ts +4 -5
  83. package/dist-browser/numbl-core/parser/types.d.ts +1 -21
  84. package/{dist-lib/numbl-core/runtime → dist-browser/numbl-core/plotting}/axisCommand.d.ts +2 -2
  85. package/dist-browser/{graphics → numbl-core/plotting}/axisLimits.d.ts +14 -2
  86. package/dist-browser/numbl-core/plotting/builtins.d.ts +8 -0
  87. package/dist-browser/numbl-core/plotting/colormaps.d.ts +10 -0
  88. package/dist-browser/numbl-core/{runtime/plotBuiltinDispatch.d.ts → plotting/dispatch.d.ts} +14 -25
  89. package/dist-browser/numbl-core/plotting/imagescExtent.d.ts +19 -0
  90. package/dist-browser/numbl-core/{runtime/runtimePlot.d.ts → plotting/instructions.d.ts} +5 -17
  91. package/dist-browser/numbl-core/plotting/parseArgsChart.d.ts +94 -0
  92. package/dist-browser/numbl-core/plotting/parseArgsCommon.d.ts +64 -0
  93. package/dist-browser/numbl-core/plotting/parseArgsLine.d.ts +103 -0
  94. package/dist-browser/numbl-core/plotting/parseArgsPatch.d.ts +38 -0
  95. package/dist-browser/numbl-core/plotting/parseArgsQuiver.d.ts +32 -0
  96. package/dist-browser/numbl-core/plotting/parseArgsSurface.d.ts +75 -0
  97. package/dist-browser/numbl-core/plotting/streamline.d.ts +16 -0
  98. package/{dist-graphics/graphics → dist-browser/numbl-core/plotting}/types.d.ts +9 -7
  99. package/dist-browser/numbl-core/runtime/cow.d.ts +0 -8
  100. package/dist-browser/numbl-core/runtime/refcount.d.ts +0 -3
  101. package/dist-browser/numbl-core/runtime/registerSpecial.d.ts +15 -0
  102. package/dist-browser/numbl-core/runtime/runtime.d.ts +11 -35
  103. package/dist-browser/numbl-core/runtime/runtimeDispatch.d.ts +6 -0
  104. package/dist-browser/numbl-core/runtime/specialBuiltins.d.ts +3 -9
  105. package/dist-browser/numbl-core/runtime/uihtmlSession.d.ts +5 -13
  106. package/dist-browser/numbl-core/runtime/utils.d.ts +4 -1
  107. package/dist-browser/numbl-core/version.d.ts +1 -1
  108. package/dist-browser/numbl-core/workspace/workspace.d.ts +64 -0
  109. package/dist-browser/vfs/syncVfsChanges.d.ts +2 -2
  110. package/dist-cli/cli.js +74244 -80566
  111. package/dist-graphics/graphics/FigureView.d.ts +1 -1
  112. package/dist-graphics/graphics/SurfView.d.ts +3 -2
  113. package/dist-graphics/graphics/drawPlot.d.ts +1 -1
  114. package/dist-graphics/graphics/exportFigureHdf5.d.ts +1 -1
  115. package/dist-graphics/graphics/figureHashTransport.d.ts +1 -1
  116. package/dist-graphics/graphics/figureUpload.d.ts +1 -1
  117. package/dist-graphics/graphics/importFigureHdf5.d.ts +1 -1
  118. package/dist-graphics/graphics/openInFigureViewer.d.ts +1 -1
  119. package/dist-graphics/graphics/plotHelpers.d.ts +1 -1
  120. package/dist-graphics/graphics/plotLegend.d.ts +1 -1
  121. package/dist-graphics/graphics/plotMarkers.d.ts +1 -1
  122. package/dist-graphics/graphics/restoreNaNs.d.ts +1 -1
  123. package/dist-graphics/graphics/uihtmlRelay.d.ts +16 -0
  124. package/dist-graphics/graphics-lib.d.ts +3 -3
  125. package/dist-graphics/index.js +294 -328
  126. package/{dist-lib/graphics → dist-graphics/numbl-core/plotting}/axisLimits.d.ts +14 -2
  127. package/dist-graphics/numbl-core/plotting/colormaps.d.ts +10 -0
  128. package/dist-graphics/numbl-core/plotting/imagescExtent.d.ts +19 -0
  129. package/{dist-browser/graphics → dist-graphics/numbl-core/plotting}/types.d.ts +9 -7
  130. package/dist-lib/browser/mip.d.ts +17 -0
  131. package/dist-lib/cli-scan.d.ts +8 -1
  132. package/dist-lib/lib.d.ts +1 -1
  133. package/dist-lib/lib.js +29201 -35301
  134. package/dist-lib/node.js +22 -14
  135. package/dist-lib/numbl-core/execSession.d.ts +39 -0
  136. package/dist-lib/numbl-core/executeCode.d.ts +10 -1
  137. package/dist-lib/numbl-core/executors/classification.d.ts +2 -10
  138. package/dist-lib/numbl-core/executors/jit/backend.d.ts +65 -0
  139. package/dist-lib/numbl-core/executors/jit/cBackend.d.ts +22 -0
  140. package/dist-lib/numbl-core/executors/jit/callExecutor.d.ts +13 -44
  141. package/dist-lib/numbl-core/executors/jit/hostHelpers.d.ts +24 -0
  142. package/dist-lib/numbl-core/executors/jit/jsBackend.d.ts +15 -0
  143. package/dist-lib/numbl-core/executors/jit/loopExecutor.d.ts +13 -40
  144. package/dist-lib/numbl-core/executors/jit/session.d.ts +1 -1
  145. package/dist-lib/numbl-core/executors/jit/topLevelExecutor.d.ts +13 -33
  146. package/dist-lib/numbl-core/executors/jit/valueAdapterC.d.ts +32 -48
  147. package/dist-lib/numbl-core/executors/lowering.d.ts +38 -96
  148. package/dist-lib/numbl-core/executors/plugins.d.ts +14 -28
  149. package/dist-lib/numbl-core/executors/registry.d.ts +32 -133
  150. package/dist-lib/numbl-core/executors/types.d.ts +30 -92
  151. package/dist-lib/numbl-core/functionResolve.d.ts +3 -13
  152. package/dist-lib/numbl-core/helpers/check-helpers.d.ts +0 -5
  153. package/dist-lib/numbl-core/helpers/glob.d.ts +14 -0
  154. package/dist-lib/numbl-core/helpers/linsolve.d.ts +3 -13
  155. package/dist-lib/numbl-core/helpers/reduction-helpers.d.ts +2 -4
  156. package/dist-lib/numbl-core/helpers/shape-utils.d.ts +10 -0
  157. package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +3 -1
  158. package/dist-lib/numbl-core/interpreter/builtins/time-system.d.ts +0 -1
  159. package/dist-lib/numbl-core/interpreter/builtins/types.d.ts +7 -7
  160. package/dist-lib/numbl-core/interpreter/interpreter.d.ts +6 -6
  161. package/dist-lib/numbl-core/interpreter/interpreterFunctions.d.ts +9 -1
  162. package/dist-lib/numbl-core/interpreter/interpreterSpecialBuiltins.d.ts +6 -3
  163. package/dist-lib/numbl-core/jit/builtins/defs/_shared.d.ts +1 -5
  164. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/_elemwise.d.ts +1 -2
  165. package/dist-lib/numbl-core/jit/builtins/defs/logical/_unary_pred.d.ts +3 -3
  166. package/dist-lib/numbl-core/jit/builtins/defs/logical/fieldnames.d.ts +1 -1
  167. package/dist-lib/numbl-core/jit/builtins/defs/logical/strcmp.d.ts +1 -1
  168. package/dist-lib/numbl-core/jit/builtins/defs/math/_unary_real.d.ts +5 -2
  169. package/dist-lib/numbl-core/jit/builtins/defs/math/realsqrt.d.ts +6 -0
  170. package/dist-lib/numbl-core/jit/builtins/defs/reduction/_shape.d.ts +0 -5
  171. package/dist-lib/numbl-core/jit/builtins/defs/shape/_construct.d.ts +0 -4
  172. package/dist-lib/numbl-core/jit/builtins/defs/shape/_triangular.d.ts +2 -8
  173. package/dist-lib/numbl-core/jit/builtins/defs/system/deal.d.ts +4 -5
  174. package/dist-lib/numbl-core/jit/builtins/defs/system/feval.d.ts +7 -29
  175. package/dist-lib/numbl-core/jit/builtins/registry.d.ts +15 -30
  176. package/dist-lib/numbl-core/jit/builtins/runtime/system/cdiv.d.ts +4 -0
  177. package/dist-lib/numbl-core/jit/builtins/runtime/system/cscalar.d.ts +4 -0
  178. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_elemwise_real_fn.d.ts +45 -15
  179. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_reduce_real.d.ts +5 -5
  180. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_unary_real_math.d.ts +6 -0
  181. package/dist-lib/numbl-core/jit/codegen/emit.d.ts +9 -30
  182. package/dist-lib/numbl-core/jit/codegen/emitJs.d.ts +9 -27
  183. package/dist-lib/numbl-core/jit/codegen/emitStmt.d.ts +8 -31
  184. package/dist-lib/numbl-core/jit/codegen/emitTensorFused.d.ts +10 -9
  185. package/dist-lib/numbl-core/jit/codegen/inlinePass.d.ts +39 -48
  186. package/dist-lib/numbl-core/jit/codegen/prettyIR.d.ts +1 -6
  187. package/dist-lib/numbl-core/jit/codegen/runtime.d.ts +7 -28
  188. package/dist-lib/numbl-core/jit/compileSpec.d.ts +3 -6
  189. package/dist-lib/numbl-core/jit/compileSpecC.d.ts +5 -0
  190. package/dist-lib/numbl-core/jit/lowering/assignedFlags.d.ts +24 -0
  191. package/dist-lib/numbl-core/jit/lowering/definiteAssign.d.ts +3 -1
  192. package/dist-lib/numbl-core/jit/lowering/errors.d.ts +3 -15
  193. package/dist-lib/numbl-core/jit/lowering/ir.d.ts +0 -2
  194. package/dist-lib/numbl-core/jit/lowering/lower.d.ts +4 -12
  195. package/dist-lib/numbl-core/jit/lowering/types.d.ts +2 -7
  196. package/dist-lib/numbl-core/jit/numbl/index.d.ts +5 -14
  197. package/dist-lib/numbl-core/jit/parser/index.d.ts +4 -9
  198. package/dist-lib/numbl-core/jit/workspace/workspace.d.ts +32 -136
  199. package/dist-lib/numbl-core/jitDeclineDiagnostics.d.ts +1 -1
  200. package/dist-lib/numbl-core/jsUserFunctions.d.ts +10 -12
  201. package/dist-lib/numbl-core/lowering/classInfo.d.ts +4 -1
  202. package/dist-lib/numbl-core/lowering/loweringContext.d.ts +15 -23
  203. package/dist-lib/numbl-core/native/lapack-bridge.d.ts +111 -130
  204. package/dist-lib/numbl-core/native/ts-lapack-bridge.d.ts +4 -5
  205. package/dist-lib/numbl-core/native/ts-lapack-complex.d.ts +23 -0
  206. package/dist-lib/numbl-core/native/ts-lapack-qr-lu.d.ts +37 -0
  207. package/dist-lib/numbl-core/native/wasm-lapack-bridge.d.ts +4 -5
  208. package/dist-lib/numbl-core/ops/dispatch.d.ts +4 -5
  209. package/dist-lib/numbl-core/parser/types.d.ts +1 -21
  210. package/{dist-browser/numbl-core/runtime → dist-lib/numbl-core/plotting}/axisCommand.d.ts +2 -2
  211. package/{dist-graphics/graphics → dist-lib/numbl-core/plotting}/axisLimits.d.ts +14 -2
  212. package/dist-lib/numbl-core/plotting/builtins.d.ts +8 -0
  213. package/dist-lib/numbl-core/plotting/colormaps.d.ts +10 -0
  214. package/dist-lib/numbl-core/{runtime/plotBuiltinDispatch.d.ts → plotting/dispatch.d.ts} +14 -25
  215. package/dist-lib/numbl-core/plotting/imagescExtent.d.ts +19 -0
  216. package/dist-lib/numbl-core/{runtime/runtimePlot.d.ts → plotting/instructions.d.ts} +5 -17
  217. package/dist-lib/numbl-core/plotting/parseArgsChart.d.ts +94 -0
  218. package/dist-lib/numbl-core/plotting/parseArgsCommon.d.ts +64 -0
  219. package/dist-lib/numbl-core/plotting/parseArgsLine.d.ts +103 -0
  220. package/dist-lib/numbl-core/plotting/parseArgsPatch.d.ts +38 -0
  221. package/dist-lib/numbl-core/plotting/parseArgsQuiver.d.ts +32 -0
  222. package/dist-lib/numbl-core/plotting/parseArgsSurface.d.ts +75 -0
  223. package/dist-lib/numbl-core/plotting/streamline.d.ts +16 -0
  224. package/dist-lib/{graphics → numbl-core/plotting}/types.d.ts +9 -7
  225. package/dist-lib/numbl-core/runtime/cow.d.ts +0 -8
  226. package/dist-lib/numbl-core/runtime/refcount.d.ts +0 -3
  227. package/dist-lib/numbl-core/runtime/registerSpecial.d.ts +15 -0
  228. package/dist-lib/numbl-core/runtime/runtime.d.ts +11 -35
  229. package/dist-lib/numbl-core/runtime/runtimeDispatch.d.ts +6 -0
  230. package/dist-lib/numbl-core/runtime/specialBuiltins.d.ts +3 -9
  231. package/dist-lib/numbl-core/runtime/uihtmlSession.d.ts +5 -13
  232. package/dist-lib/numbl-core/runtime/utils.d.ts +4 -1
  233. package/dist-lib/numbl-core/version.d.ts +1 -1
  234. package/dist-lib/numbl-core/workspace/workspace.d.ts +64 -0
  235. package/dist-lib/vfs/unzipToFiles.d.ts +7 -0
  236. package/dist-plot-viewer/assets/index-C0fIevlp.js +4504 -0
  237. package/dist-plot-viewer/index.html +1 -1
  238. package/dist-site-viewer/assets/index-BDaviCH6.js +4832 -0
  239. package/dist-site-viewer/assets/numbl-worker-D6m4K2PP.js +5691 -0
  240. package/dist-site-viewer/index.html +2 -2
  241. package/native/numbl_addon.cpp +2 -12
  242. package/native/numbl_addon_common.h +0 -5
  243. package/package.json +6 -5
  244. package/dist-browser/hooks/useProjectFiles.d.ts +0 -45
  245. package/dist-browser/numbl-core/executors/context.d.ts +0 -76
  246. package/dist-browser/numbl-core/executors/index.d.ts +0 -14
  247. package/dist-browser/numbl-core/executors/jit/cJitCallExecutor.d.ts +0 -35
  248. package/dist-browser/numbl-core/executors/jit/cJitLoopExecutor.d.ts +0 -31
  249. package/dist-browser/numbl-core/executors/jit/cJitTopLevelExecutor.d.ts +0 -29
  250. package/dist-browser/numbl-core/helpers/dummy.d.ts +0 -5
  251. package/dist-browser/numbl-core/jit/runtime/context.d.ts +0 -23
  252. package/dist-browser/numbl-core/jit/runtime/inferType.d.ts +0 -10
  253. package/dist-browser/numbl-core/jit/runtime/value.d.ts +0 -101
  254. package/dist-browser/numbl-core/jit/workspace/driverPrologue.d.ts +0 -59
  255. package/dist-browser/numbl-core/jit/workspace/mtoc2UserFunctionLoader.d.ts +0 -62
  256. package/dist-browser/numbl-core/native/bridge-resolve.d.ts +0 -14
  257. package/dist-browser/numbl-core/runtime/plotUtils.d.ts +0 -336
  258. package/dist-browser/numbl-core/runtime/specialBuiltinNames.d.ts +0 -2
  259. package/dist-graphics/graphics/surfColormap.d.ts +0 -2
  260. package/dist-lib/numbl-core/executors/context.d.ts +0 -76
  261. package/dist-lib/numbl-core/executors/index.d.ts +0 -14
  262. package/dist-lib/numbl-core/executors/jit/cJitCallExecutor.d.ts +0 -35
  263. package/dist-lib/numbl-core/executors/jit/cJitLoopExecutor.d.ts +0 -31
  264. package/dist-lib/numbl-core/executors/jit/cJitTopLevelExecutor.d.ts +0 -29
  265. package/dist-lib/numbl-core/helpers/dummy.d.ts +0 -5
  266. package/dist-lib/numbl-core/jit/runtime/context.d.ts +0 -23
  267. package/dist-lib/numbl-core/jit/runtime/inferType.d.ts +0 -10
  268. package/dist-lib/numbl-core/jit/runtime/value.d.ts +0 -101
  269. package/dist-lib/numbl-core/jit/workspace/driverPrologue.d.ts +0 -59
  270. package/dist-lib/numbl-core/jit/workspace/mtoc2UserFunctionLoader.d.ts +0 -62
  271. package/dist-lib/numbl-core/native/bridge-resolve.d.ts +0 -14
  272. package/dist-lib/numbl-core/runtime/plotUtils.d.ts +0 -336
  273. package/dist-lib/numbl-core/runtime/specialBuiltinNames.d.ts +0 -2
  274. package/dist-plot-viewer/assets/index-YeXWXIxH.js +0 -4504
  275. package/dist-site-viewer/assets/index-DrtkDG_M.js +0 -4832
  276. package/dist-site-viewer/assets/numbl-worker-Dz_Z8B9u.js +0 -5327
  277. package/native/elemwise.cpp +0 -360
  278. package/native/unary_elemwise.cpp +0 -67
  279. /package/dist-browser/{graphics → numbl-core/plotting}/figuresReducer.d.ts +0 -0
  280. /package/dist-graphics/{graphics → numbl-core/plotting}/figuresReducer.d.ts +0 -0
  281. /package/dist-lib/{graphics → numbl-core/plotting}/figuresReducer.d.ts +0 -0
package/dist-lib/node.js CHANGED
@@ -67,6 +67,24 @@ function scanMFiles(dirPath, excludeFile) {
67
67
  return files;
68
68
  }
69
69
 
70
+ // src/numbl-core/helpers/glob.ts
71
+ var PATH_TOKENS = {
72
+ "**/": "(?:.*/)?",
73
+ "**": ".*",
74
+ "*": "[^/]*",
75
+ "?": "[^/]"
76
+ };
77
+ function globToRegExp(pattern, opts = {}) {
78
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&");
79
+ let body;
80
+ if (!opts.paths) {
81
+ body = escaped.replace(/\*/g, ".*").replace(/\?/g, ".");
82
+ } else {
83
+ body = escaped.replace(/\*\*\/|\*\*|\*|\?/g, (m) => PATH_TOKENS[m]);
84
+ }
85
+ return new RegExp("^" + body + "$");
86
+ }
87
+
70
88
  // src/cli-fileio.ts
71
89
  function expandTilde(filepath) {
72
90
  if (filepath.startsWith("~/")) {
@@ -458,9 +476,7 @@ var NodeFileIOAdapter = class {
458
476
  const lastSep = Math.max(p.lastIndexOf("/"), p.lastIndexOf("\\"));
459
477
  const dir = lastSep >= 0 ? p.slice(0, lastSep) : ".";
460
478
  const globPat = lastSep >= 0 ? p.slice(lastSep + 1) : p;
461
- const re = new RegExp(
462
- "^" + globPat.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".") + "$"
463
- );
479
+ const re = globToRegExp(globPat);
464
480
  let entries;
465
481
  try {
466
482
  entries = readdirSync2(dir);
@@ -547,9 +563,7 @@ var NodeFileIOAdapter = class {
547
563
  const last = basename(p);
548
564
  if (last.includes("*") || last.includes("?")) {
549
565
  const dir = dirname(abs);
550
- const re = new RegExp(
551
- "^" + last.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".") + "$"
552
- );
566
+ const re = globToRegExp(last);
553
567
  let dirEntries;
554
568
  try {
555
569
  dirEntries = readdirSync2(dir);
@@ -642,9 +656,7 @@ var NodeFileIOAdapter = class {
642
656
  );
643
657
  const dir = lastSep >= 0 ? pattern.slice(0, lastSep) : ".";
644
658
  const globPat = lastSep >= 0 ? pattern.slice(lastSep + 1) : pattern;
645
- const re = new RegExp(
646
- "^" + globPat.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".") + "$"
647
- );
659
+ const re = globToRegExp(globPat);
648
660
  const absDir = resolve(dir);
649
661
  const results = [];
650
662
  let entries;
@@ -685,11 +697,7 @@ var NodeFileIOAdapter = class {
685
697
  return [];
686
698
  }
687
699
  const suffix = norm.slice(idx);
688
- const DIRS = "\0";
689
- const ANY = "";
690
- const re = new RegExp(
691
- "^" + suffix.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, DIRS).replace(/\*\*/g, ANY).replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(new RegExp(DIRS, "g"), "(?:.*/)?").replace(new RegExp(ANY, "g"), ".*") + "$"
692
- );
700
+ const re = globToRegExp(suffix, { paths: true });
693
701
  const results = [];
694
702
  const pushIfMatch = (rel, name, folder, bytes, isdir, mtimeMs) => {
695
703
  if (re.test(rel)) results.push({ name, folder, bytes, isdir, mtimeMs });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * REPL-style session over `executeCode`. Each call builds a fresh runtime, so
3
+ * the state a session carries from one call to the next is threaded through
4
+ * here: workspace variables, plot hold state, figure handles, search paths and
5
+ * workspace files (as changed by addpath/rmpath), the implicit cwd, and the
6
+ * uihtml session left by the latest run. Used by the CLI REPL and the
7
+ * browser workers.
8
+ */
9
+ import { type ExecOptions, type ExecResult, type FigureHandles, type UihtmlSession } from "./executeCode.js";
10
+ import type { RuntimeValue } from "./runtime/index.js";
11
+ import type { NativeBridge, WorkspaceFile } from "./workspace/types.js";
12
+ export declare class ExecSession {
13
+ variableValues: Record<string, RuntimeValue>;
14
+ holdState: boolean;
15
+ figureHandles: FigureHandles;
16
+ workspaceFiles: WorkspaceFile[];
17
+ searchPaths: string[] | undefined;
18
+ implicitCwdPath: string | null | undefined;
19
+ /** Live uihtml callbacks from the latest run, if any (see UihtmlSession). */
20
+ uihtmlSession: UihtmlSession | null;
21
+ /** Appended to the search paths of every `execute` unless already present
22
+ * (e.g. the mip core directory). */
23
+ extraSearchPaths: string[];
24
+ nativeBridge: NativeBridge | undefined;
25
+ constructor(init?: {
26
+ workspaceFiles?: WorkspaceFile[];
27
+ searchPaths?: string[];
28
+ nativeBridge?: NativeBridge;
29
+ });
30
+ /** Run `code` against the carried state and adopt the result's state. A
31
+ * new run supersedes the previous uihtml session; on error the rest of
32
+ * the state is left unchanged. */
33
+ execute(code: string, options?: ExecOptions, mainFileName?: string): ExecResult;
34
+ /** Carry a successful run's state forward. */
35
+ adopt(result: ExecResult): void;
36
+ /** Forget variables, hold state and figures (paths and cwd are kept). */
37
+ clearWorkspace(): void;
38
+ disposeUihtmlSession(): void;
39
+ }
@@ -5,7 +5,7 @@
5
5
  * creates an Interpreter, and runs the AST.
6
6
  */
7
7
  import type { RuntimeValue } from "./runtime/index.js";
8
- import type { PlotInstruction } from "../graphics/types.js";
8
+ import type { PlotInstruction } from "./plotting/types.js";
9
9
  import type { FileIOAdapter } from "./fileIOAdapter.js";
10
10
  import type { SystemAdapter } from "./systemAdapter.js";
11
11
  import type { WorkspaceFile } from "../numbl-core/workspace/index.js";
@@ -31,6 +31,9 @@ export interface ExecOptions {
31
31
  onJitBail?: (message: string) => void;
32
32
  /** Initial hold state for plotting (persisted across REPL executions). */
33
33
  initialHoldState?: boolean;
34
+ /** Current and largest figure handle so far (persisted across REPL
35
+ * executions, so a bare `figure` keeps allocating new figures). */
36
+ initialFigureHandles?: FigureHandles;
34
37
  /** Override or add builtins for this execution only. */
35
38
  customBuiltins?: Record<string, (nargout: number, args: any[]) => any>;
36
39
  /** Platform-specific file I/O adapter (e.g. Node.js fs). */
@@ -92,6 +95,7 @@ export interface ExecResult {
92
95
  returnValue: RuntimeValue;
93
96
  variableValues: Record<string, RuntimeValue>;
94
97
  holdState: boolean;
98
+ figureHandles: FigureHandles;
95
99
  profileData?: ProfileData;
96
100
  dispatchUnknownCounts?: Record<string, number>;
97
101
  /** Updated search paths (set when addpath/rmpath was called). */
@@ -105,4 +109,9 @@ export interface ExecResult {
105
109
  * interpreter (see UihtmlSession). Absent for normal runs (no overhead). */
106
110
  uihtmlSession?: UihtmlSession;
107
111
  }
112
+ /** Figure-handle state of a run (see Runtime.currentFigureHandle). */
113
+ export interface FigureHandles {
114
+ current: number;
115
+ max: number;
116
+ }
108
117
  export declare function executeCode(source: string, options?: ExecOptions, workspaceFiles?: WorkspaceFile[], mainFileName?: string, searchPaths?: string[], nativeBridge?: NativeBridge): ExecResult;
@@ -105,17 +105,9 @@ export interface CallClassification {
105
105
  readonly fn: FunctionDef;
106
106
  readonly nargout: number;
107
107
  readonly argTypes: readonly JitType[];
108
+ /** Compile-cache key within the FunctionDef owner: arg types + nargout
109
+ * (the spec is specialized on both). */
108
110
  readonly cacheKey: string;
109
- /**
110
- * Effective parameter names for this specialization. Mirrors
111
- * `fn.params` for non-varargin functions. For varargin functions,
112
- * the trailing `varargin` is replaced with one synthetic name per
113
- * variadic arg (`$va_0`, `$va_1`, …). argTypes is one-to-one with
114
- * effectiveParams.
115
- */
116
- readonly effectiveParams: readonly string[];
117
- /** Number of variadic args (0 when fn has no varargin). */
118
- readonly nVarargin: number;
119
111
  /** Function body contains a `%!numbl:assert_jit c` directive (C-JIT variant). */
120
112
  readonly assertsCJit: boolean;
121
113
  }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The JIT backend strategy.
3
+ *
4
+ * The three shape executors (top-level, loop, call) are written once
5
+ * against `JitBackend`; `jsBackend` (`compileSpec` + `new Function`) and
6
+ * `cBackend` (`compileSpecC` + `cc` + koffi) supply what differs: type
7
+ * feasibility, compile, and how a compiled spec is called.
8
+ */
9
+ import type { Interpreter } from "../../interpreter/interpreter.js";
10
+ import type { JitType } from "../../jitTypes.js";
11
+ import type { Stmt } from "../../parser/index.js";
12
+ import type { RuntimeValue } from "../../runtime/types.js";
13
+ import { type Type as CompilerType } from "../../jit/index.js";
14
+ import type { RunResult } from "../types.js";
15
+ export type FuncStmt = Extract<Stmt, {
16
+ type: "Function";
17
+ }>;
18
+ export interface CompileRequest {
19
+ /** Executor name, for diagnostics. */
20
+ readonly where: string;
21
+ readonly funcDecl: FuncStmt;
22
+ readonly argTypes: CompilerType[];
23
+ readonly nargout: number;
24
+ /** True when `funcDecl` wraps a script body or loop rather than a
25
+ * user function (relaxes the C entry-output check). */
26
+ readonly synthetic: boolean;
27
+ /** Suffix for the `onJitCompile` label, e.g. `(number) -> nargout=1`. */
28
+ readonly describe: string;
29
+ }
30
+ export interface JitBackend<A = unknown> {
31
+ readonly lang: "js" | "c";
32
+ /** Executor-name prefix: `jit` or `cjit`. */
33
+ readonly prefix: string;
34
+ /** Whether the backend can run in this interpreter at all. */
35
+ available(interp: Interpreter): boolean;
36
+ /** Translate a numbl input type to a compiler type; null declines. */
37
+ mapType(jt: JitType): CompilerType | null;
38
+ /** Compile a spec. May throw `UnsupportedConstruct` / `JitTypeError`
39
+ * (see `compileUnit`); returns null for any other decline. */
40
+ compile(req: CompileRequest, interp: Interpreter): A | null;
41
+ /** Call a compiled spec. Returns its outputs (`undefined` for one the
42
+ * spec left unassigned), or null to bail to the interpreter. */
43
+ invoke(art: A, args: readonly (RuntimeValue | undefined)[], interp: Interpreter, where: string): (RuntimeValue | undefined)[] | null;
44
+ }
45
+ /** `backend.compile`, turning a compiler rejection into a recorded
46
+ * decline (null). Only the compiler's own decline errors are caught. */
47
+ export declare function compileUnit<A>(backend: JitBackend<A>, req: CompileRequest, interp: Interpreter): A | null;
48
+ /** Map every input type through the backend; null if any declines. */
49
+ export declare function mapTypes(backend: JitBackend, types: readonly JitType[]): CompilerType[] | null;
50
+ /** `%!numbl:assert_jit c` requires C-JIT at --opt 2, so the JS backend
51
+ * declines such units there: they either C-JIT or fall through to the
52
+ * interpreter, which raises on the directive. Plain `assert_jit` only
53
+ * requires JS-JIT at --opt 1 and does not gate here. */
54
+ export declare function declinedByAssertC(backend: JitBackend, interp: Interpreter, assertsCJit: boolean): boolean;
55
+ /** The loop-depth gate shared by the loop and call shapes: decline while
56
+ * an enclosing loop is running, since compiling that loop captures this
57
+ * unit. Lifts when every enclosing loop was itself declined
58
+ * (`Interpreter.jitDeclinedLoopDepth`). */
59
+ export declare function insideCompiledLoop(interp: Interpreter): boolean;
60
+ /** A synthetic `FuncStmt` wrapping a script body or loop: params are the
61
+ * env inputs, outputs the env outputs. */
62
+ export declare function synthesizeFuncStmt(name: string, inputs: readonly string[], outputs: readonly string[], body: Stmt[], fileName: string): FuncStmt;
63
+ /** Run a compiled script-body or loop spec against the interpreter env:
64
+ * read `inputs` from it, write back the `outputs` the spec assigned. */
65
+ export declare function runInEnv<A>(backend: JitBackend<A>, art: A, inputs: readonly string[], outputs: readonly string[], interp: Interpreter, where: string): RunResult;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * C backend: `compileSpecC` → `cc -shared` → koffi `dlopen`.
3
+ *
4
+ * Node only. Imported solely by `compileC.node.ts`, which registers it at
5
+ * bootstrap, so the browser bundle never pulls in the C compile graph.
6
+ * See `valueAdapterC.ts` for the marshaling protocol.
7
+ */
8
+ import { type CompileSpecCResult, type SpecCSignature, type Type } from "../../jit/index.js";
9
+ import { type CompiledC } from "./compileC.js";
10
+ import { bindGrowBail, makeCMarshalCtx, type HostWriteBinding } from "./valueAdapterC.js";
11
+ import type { JitBackend } from "./backend.js";
12
+ interface CArtifact {
13
+ readonly compiled: CompiledC;
14
+ readonly signature: SpecCSignature;
15
+ readonly assignedFlags: CompileSpecCResult["assignedFlags"];
16
+ readonly paramTypes: Type[];
17
+ readonly ctx: ReturnType<typeof makeCMarshalCtx>;
18
+ readonly hostWrite: HostWriteBinding;
19
+ readonly growBail: ReturnType<typeof bindGrowBail>;
20
+ }
21
+ export declare const cBackend: JitBackend<CArtifact>;
22
+ export {};
@@ -1,51 +1,20 @@
1
1
  /**
2
- * jit-call — executor that compiles user-function calls via mtoc2's
3
- * `compileSpec` JIT entry point and runs the emitted JS in-process.
2
+ * `<prefix>-call` — compiles a user-function call specialized on its
3
+ * argument types and nargout.
4
4
  *
5
- * Replaces the JS-JIT call executor at `--opt 1`. The shape of the
6
- * fallback path is the same: on rejection (mtoc2's
7
- * `UnsupportedConstruct` / `TypeError` during lowering, or a JitType
8
- * the type adapter can't translate), `propose()` declines and the
9
- * dispatcher falls through to the next executor / interpreter.
10
- *
11
- * Key differences from JS-JIT:
12
- *
13
- * - **No mid-run bailouts.** mtoc2 either lowers cleanly or rejects
14
- * statically. When `compile()` returns, the artifact will run to
15
- * completion. `bailRisk` is `false`.
16
- * - **Shared `Lowerer.specializations` is the cache.** One Workspace
17
- * + Lowerer pair per LoweringContext (i.e. per execution session);
18
- * accumulating specs persist across calls so a function called
19
- * repeatedly with the same arg signature reuses the prior compile.
20
- * - **Output-count support.** `nargout >= 1` (single-output and
21
- * multi-output `[a, b, ...] = f(x)`). `nargout === 0` (bare-stmt
22
- * `f();`) is declined because mtoc2's nargout=0 spec emits a no-
23
- * return body, but numbl's interpreter still uses the first
24
- * declared output for `ans` binding — let the interpreter handle.
25
- * - **Loop-depth gate.** Declines when `interp.loopDepth > 0` so a
26
- * hot loop iterating function calls doesn't pay per-call JIT
27
- * propose / spec-cache overhead. Once an outer call is JIT'd, its
28
- * loops run inside mtoc2's compiled code anyway. The gate lifts when
29
- * every enclosing loop was itself declined: nothing above will be
30
- * compiled then, and an expensive callee would otherwise run
31
- * interpreted all the way down (`Interpreter.jitDeclinedLoopDepth`).
5
+ * Declines `nargout === 0` (bare `f();`): the interpreter still binds the
6
+ * first declared output to `ans`, but a nargout=0 spec returns nothing.
7
+ * Declines inside a loop that is itself being compiled (see
8
+ * `insideCompiledLoop`): the call then runs inside that compiled loop.
32
9
  */
33
10
  import type { Executor } from "../types.js";
34
- import { type JitType } from "../../jitTypes.js";
35
- import type { FunctionDef } from "../../interpreter/types.js";
36
- import { type Type as CompilerType } from "../../jit/index.js";
37
- interface JitCallData {
38
- readonly fn: FunctionDef;
39
- readonly nargout: number;
40
- readonly argTypes: readonly JitType[];
41
- readonly compilerArgTypes: readonly CompilerType[];
11
+ import type { CallClassification } from "../classification.js";
12
+ import type { Type as CompilerType } from "../../jit/index.js";
13
+ import { type JitBackend } from "./backend.js";
14
+ interface CallData {
15
+ readonly c: CallClassification;
16
+ readonly argTypes: CompilerType[];
42
17
  readonly args: readonly unknown[];
43
18
  }
44
- interface CompiledArtifact {
45
- readonly specFn: (...args: unknown[]) => unknown;
46
- /** The spec's declared output types — needed to convert a returned
47
- * struct back (an untagged JS object otherwise). */
48
- readonly outputTypes: ReadonlyArray<CompilerType>;
49
- }
50
- export declare const jitCallExecutor: Executor<JitCallData, CompiledArtifact | null>;
19
+ export declare function makeCallExecutor<A>(backend: JitBackend<A>): Executor<"call", CallData, A | null>;
51
20
  export {};
@@ -13,6 +13,11 @@
13
13
  * so `colorbar('off')` / `pcolor(...)` / etc. produce the same
14
14
  * plot-instruction stream as the interpreter would.
15
15
  *
16
+ * - `elemwise` — the interpreter's element-wise tensor kernels (native
17
+ * addon when loaded). The JS runtime snippets use them for large
18
+ * tensors, so --opt 0 and --opt 1 compute the same bits and large
19
+ * element-wise work runs as SIMD C rather than a scalar JS loop.
20
+ *
16
21
  * The unknown-name fallthrough (when `dispatchPlotBuiltin` returns
17
22
  * false) is a programmer error: every name mtoc2's plot builtin
18
23
  * registration covers is in `PLOT_ALL_NAMES`, which is sourced from
@@ -20,6 +25,16 @@
20
25
  * mismatch is loud rather than silently dropping a side effect.
21
26
  */
22
27
  import type { Runtime } from "../../runtime/runtime.js";
28
+ /** Element-wise kernels exposed to the JS runtime snippets as
29
+ * `$elemwise` (see `runtime-globals.d.ts`). `out` has `a`'s length. */
30
+ export interface JitElemwiseHost {
31
+ binary(op: string, a: Float64Array, b: Float64Array, out: Float64Array): void;
32
+ scalarBinary(op: string, s: number, a: Float64Array, scalarOnLeft: boolean, out: Float64Array): void;
33
+ /** False when `op` has no host kernel (the caller runs its own loop). */
34
+ unary(op: string, a: Float64Array, out: Float64Array): boolean;
35
+ /** NaN-skipping `min` / `max` over all of `a` (non-empty). */
36
+ minmax(op: "min" | "max", a: Float64Array): number;
37
+ }
23
38
  export interface JitHostHelpers {
24
39
  write: (s: string) => void;
25
40
  plotDispatch: (name: string, args: unknown[]) => void;
@@ -27,5 +42,14 @@ export interface JitHostHelpers {
27
42
  * (the same `rngRandom` the interpreter uses), so JIT'd and interpreted
28
43
  * `rand` draw from one shared, `rng(seed)`-controllable stream. */
29
44
  rand: () => number;
45
+ elemwise: JitElemwiseHost;
30
46
  }
31
47
  export declare function buildHostHelpers(rt: Runtime): JitHostHelpers;
48
+ /** The output sink for a compiled C call: passes program output to
49
+ * `rt.output` and turns plot records into plot instructions. A record may
50
+ * arrive in several chunks; it ends at a newline. Call `flush` after the C
51
+ * call returns. */
52
+ export declare function cOutputSink(rt: Runtime): {
53
+ write: (s: string) => void;
54
+ flush: () => void;
55
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * JS backend: `compileSpec` emits a JS factory, materialized with
3
+ * `new Function` and run in-process.
4
+ */
5
+ import { type Type as CompilerType } from "../../jit/index.js";
6
+ import type { JitBackend } from "./backend.js";
7
+ interface JsArtifact {
8
+ readonly specFn: (...args: unknown[]) => unknown;
9
+ readonly argTypes: readonly CompilerType[];
10
+ /** Needed to rebuild a returned struct (an untagged JS object). */
11
+ readonly outputTypes: readonly CompilerType[];
12
+ readonly nargout: number;
13
+ }
14
+ export declare const jsBackend: JitBackend<JsArtifact>;
15
+ export {};
@@ -1,46 +1,19 @@
1
1
  /**
2
- * jit-loop — compiles a single For/While stmt via mtoc2's
3
- * `compileSpec` with the loop wrapped as a synthetic user function
4
- * whose params are the variables the loop reads (env inputs) and
5
- * whose outputs are the variables it assigns that are live after the
6
- * loop (filtered in classification).
2
+ * `<prefix>-loop` — compiles a single For/While stmt, wrapped as a
3
+ * synthetic function whose params are the variables the loop reads from
4
+ * the env and whose outputs are the variables it assigns that are live
5
+ * after the loop (filtered in classification).
7
6
  *
8
- * Mirrors `topLevelExecutor.ts` — the only structural difference is
9
- * that the synthetic body is a single-element `[loopStmt]` instead of
10
- * a whole script body.
11
- *
12
- * Loop-depth gate: fires when `interp.loopDepth === 0`, or when every
13
- * enclosing loop has been declined by the JIT. A loop dispatched while the
14
- * interpreter iterates an enclosing loop-body would pay per-iter
15
- * propose/cache overhead with no speedup, because the *outer* loop is the
16
- * natural JIT entry point (it captures the inner loop's body and runs it
17
- * natively in mtoc2-emitted code) — but that only holds when the outer loop
18
- * actually compiles. If it declined, the interpreter is walking its body and
19
- * this loop is the outermost thing still compilable, so the gate lifts
20
- * (`Interpreter.jitDeclinedLoopDepth`).
7
+ * Fires for outermost loops only, unless every enclosing loop was itself
8
+ * declined (see `insideCompiledLoop`).
21
9
  */
22
10
  import type { Executor } from "../types.js";
23
- import { type JitType } from "../../jitTypes.js";
24
- import type { Stmt } from "../../parser/index.js";
25
- import { type Type as CompilerType } from "../../jit/index.js";
26
- import type { ConstHandle } from "../classification.js";
27
- interface JitLoopData {
28
- readonly loopStmt: Stmt & {
29
- type: "For" | "While";
30
- };
31
- readonly inputs: readonly string[];
32
- readonly outputs: readonly string[];
33
- readonly inputTypes: readonly JitType[];
34
- readonly compilerInputTypes: readonly CompilerType[];
35
- readonly constHandles: readonly ConstHandle[];
36
- readonly currentFile: string;
37
- readonly cacheKey: string;
38
- }
39
- interface CompiledArtifact {
40
- readonly specFn: (...args: unknown[]) => unknown;
41
- /** The synthetic spec's output types, so a struct written back into the
42
- * env is rebuilt as a struct (the emitted value is an untagged object). */
43
- readonly outputTypes: ReadonlyArray<CompilerType>;
11
+ import type { LoopClassification } from "../classification.js";
12
+ import type { Type as CompilerType } from "../../jit/index.js";
13
+ import { type JitBackend } from "./backend.js";
14
+ interface LoopData {
15
+ readonly c: LoopClassification;
16
+ readonly argTypes: CompilerType[];
44
17
  }
45
- export declare const jitLoopExecutor: Executor<JitLoopData, CompiledArtifact | null>;
18
+ export declare function makeLoopExecutor<A>(backend: JitBackend<A>): Executor<"loop", LoopData, A | null>;
46
19
  export {};
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Per-LoweringContext mtoc2 session state shared between
3
- * `jitCallExecutor` and `jitTopLevelExecutor`. One `Workspace`
3
+ * the JIT executors (both backends). One `Workspace`
4
4
  * (built from numbl's existing `LoweringContext`) and one `Lowerer`
5
5
  * per execution session, so the `Lowerer.specializations` cache
6
6
  * persists across whole-scope + per-call dispatches.
@@ -1,39 +1,19 @@
1
1
  /**
2
- * jit-top-level — compiles a script body via mtoc2's `compileSpec`
3
- * with the body wrapped as a synthetic user function whose params are
4
- * the variables the body reads (env inputs) and whose outputs are the
5
- * variables it assigns (env outputs).
2
+ * `<prefix>-top-level` — compiles a whole script body, wrapped as a
3
+ * synthetic function whose params are the variables the body reads from
4
+ * the env and whose outputs are the variables it assigns.
6
5
  *
7
- * The interpreter calls `Registry.tryRunWholeScope` once at script
8
- * start; we register this via `registerWholeScope`. On compile
9
- * success the entire script runs in mtoc2-emitted JS; on
10
- * `UnsupportedConstruct` / `TypeError` we decline and the dispatcher
11
- * falls through to per-stmt dispatch (where jit-call still handles
12
- * individual user-function calls).
13
- *
14
- * Top-level loops *inside* the script execute as part of the
15
- * compiled artifact, so `loopDepth` only gates dispatch-level calls,
16
- * not this whole-scope attempt.
6
+ * The interpreter calls `Registry.tryRunWholeScope` once at script start.
7
+ * On a decline the per-stmt loop runs instead, where the loop and call
8
+ * executors still get their chance.
17
9
  */
18
10
  import type { Executor } from "../types.js";
19
- import { type JitType } from "../../jitTypes.js";
20
- import type { Stmt } from "../../parser/index.js";
21
- import { type Type as CompilerType } from "../../jit/index.js";
22
- interface JitTopLevelData {
23
- readonly stmts: readonly Stmt[];
24
- readonly inputs: readonly string[];
25
- readonly outputs: readonly string[];
26
- readonly inputTypes: readonly JitType[];
27
- readonly compilerInputTypes: readonly CompilerType[];
28
- readonly currentFile: string;
29
- readonly cacheKey: string;
30
- }
31
- interface CompiledArtifact {
32
- readonly specFn: (...args: unknown[]) => unknown;
33
- readonly nargout: number;
34
- /** The synthetic spec's output types, so a struct written back into the
35
- * env is rebuilt as a struct (the emitted value is an untagged object). */
36
- readonly outputTypes: ReadonlyArray<CompilerType>;
11
+ import type { TopLevelClassification } from "../classification.js";
12
+ import type { Type as CompilerType } from "../../jit/index.js";
13
+ import { type JitBackend } from "./backend.js";
14
+ interface TopLevelData {
15
+ readonly c: TopLevelClassification;
16
+ readonly argTypes: CompilerType[];
37
17
  }
38
- export declare const jitTopLevelExecutor: Executor<JitTopLevelData, CompiledArtifact | null>;
18
+ export declare function makeTopLevelExecutor<A>(backend: JitBackend<A>): Executor<"top-level", TopLevelData, A | null>;
39
19
  export {};
@@ -5,22 +5,14 @@
5
5
  * `RuntimeValue` to / from the C ABI mtoc2 expects across the koffi
6
6
  * FFI boundary.
7
7
  *
8
- * **Copy budget** (see CLAUDE memo `feedback-no-silent-bails.md`
9
- * and the user's "no extra copies" guideline):
8
+ * **Copy budget**:
10
9
  * - Scalars: zero copies; passed by value in koffi's args array.
11
- * - Tensors: one copy in, one copy out. mtoc2's call convention
12
- * requires the callee own its tensor params (it frees them at
13
- * scope exit), so the input data must be copied into a
14
- * `koffi.alloc`'d malloc-backed buffer that mtoc2 can free.
15
- * Reused / shared buffer would either (a) get freed under
16
- * numbl's still-live Float64Array, or (b) require extending
17
- * mtoc2 with borrowed-param semantics — deferred.
18
- *
19
- * - Output tensors arrive as `mtoc2_tensor_t` with mtoc2_alloc'd
20
- * `real`/`imag` pointers. Caller (this adapter) copies the data
21
- * into a fresh `Float64Array`, then calls `free()` on the
22
- * pointers (`koffi`-bound `free` from libc) to release mtoc2's
23
- * buffers.
10
+ * - Tensors: one copy in, one copy out. The callee owns (and frees at
11
+ * scope exit) its tensor params, so input data is copied into
12
+ * buffers from the `.so`'s own `mtoc2_jit_malloc`. Output tensors
13
+ * arrive with callee-allocated `real`/`imag`; they are copied into
14
+ * fresh `Float64Array`s and released with `mtoc2_jit_free`. Both
15
+ * copies are bulk `koffi.encode` / `koffi.decode` calls.
24
16
  */
25
17
  import { RuntimeTensor, type RuntimeValue } from "../../runtime/types.js";
26
18
  import type { Type, NumericType } from "../../jit/index.js";
@@ -28,31 +20,31 @@ import type { KoffiLib } from "./compileC.js";
28
20
  /** Loose koffi typing — same shape as in typeAdapterC.ts. */
29
21
  type KoffiAny = any;
30
22
  interface Koffi {
31
- alloc(type: string, count: number): any;
32
- decode(ptr: unknown, type: string, count: number): any;
33
- encode(buf: any, type: string, value: any): void;
34
- address(buf: any): any;
23
+ encode(ptr: unknown, type: string, value: Float64Array, len: number): void;
24
+ decode(ptr: unknown, type: string, len: number): Float64Array;
35
25
  }
36
26
  /** A function that frees the `mtoc2_alloc`'d buffer at the given
37
27
  * pointer. Resolved via koffi against libc's `free`. The .so we
38
28
  * dlopen pulls in libc anyway, so binding through the same lib is
39
29
  * zero-cost. */
40
30
  type FreeFn = (ptr: unknown) => void;
31
+ type MallocFn = (bytes: number) => unknown;
41
32
  interface MarshalCtx {
42
33
  readonly koffi: Koffi;
34
+ readonly malloc: MallocFn;
43
35
  readonly free: FreeFn;
44
36
  }
37
+ export interface HostWriteBinding {
38
+ /** Run `fn` (the C call) with the `.so`'s output routed to `write`. */
39
+ run<T>(write: (s: string) => void, fn: () => T): T;
40
+ }
45
41
  /** Bind numbl's output sink into an emitted C `.so` so program output
46
- * (disp / fprintf / …) routes through `write` instead of libc stdout
47
- * — see `runtime/io/host_output.h`. Returns a `dispose()` the caller
48
- * MUST invoke after the C call returns (success or throw) to unbind
49
- * and free the koffi callback.
42
+ * (disp / fprintf / …) routes through the host instead of libc stdout
43
+ * (see `runtime/io/host_output.h`). Done once per loaded `.so`.
50
44
  *
51
45
  * When the spec emitted no output, `mtoc2_set_host_write` is absent
52
46
  * from the `.so`; binding then no-ops (the C code never writes). */
53
- export declare function bindHostWrite(koffi: KoffiAny, lib: KoffiLib, write: (s: string) => void): {
54
- dispose(): void;
55
- };
47
+ export declare function bindHostWrite(koffi: KoffiAny, lib: KoffiLib): HostWriteBinding;
56
48
  /** Bind the emitted `.so`'s grow-bail flag accessors. A runtime
57
49
  * indexed-store grow (`v(k) = x`, k past the runtime extent) sets a
58
50
  * flag in the `.so` and `longjmp`s back to the host-entry function's
@@ -68,35 +60,27 @@ export declare function bindGrowBail(lib: KoffiLib): {
68
60
  reset(): void;
69
61
  bailed(): boolean;
70
62
  };
71
- /** Build a marshaling context from a koffi lib handle. The host
72
- * passes the lib it got from `compileAndLoadC`; we resolve `free`
73
- * against that same lib (libc symbols are reachable through any
74
- * dlopen'd .so). */
63
+ /** Build a marshaling context from a koffi lib handle. `mtoc2_jit_malloc`
64
+ * / `mtoc2_jit_free` are exported by every JIT `.so` (see
65
+ * `jit/codegen/emit.ts`), so host-side buffers use the same allocator
66
+ * the emitted code frees with. */
75
67
  export declare function makeCMarshalCtx(koffi: Koffi, lib: KoffiLib): MarshalCtx;
76
- /** Marshaled-input bookkeeping returned by `marshalInputs`. The
77
- * caller is responsible for invoking `release()` once the C call
78
- * has returned (success or throw). `release` does nothing for
79
- * scalar inputs (no allocation); for tensor inputs it's also a
80
- * no-op: mtoc2's spec body frees the buffers at its scope exit.
81
- * Kept as an explicit handle so a future change to lifetime
82
- * semantics has a single place to update. */
68
+ /** Marshaled-input bookkeeping returned by `marshalInputs`. The callee
69
+ * takes ownership of tensor buffers once it is called; `release()`
70
+ * frees them for a call that never happened (marshaling or koffi
71
+ * argument-conversion failure). */
83
72
  export interface MarshaledInputs {
84
73
  /** The values to splat into the koffi call, in order. */
85
74
  readonly args: unknown[];
86
75
  release(): void;
87
76
  }
88
- /** Convert a numbl `RuntimeValue` to the matching koffi-callable
89
- * arg for a parameter of mtoc2 `Type`. */
77
+ /** Convert numbl `RuntimeValue`s to koffi-callable args for parameters of
78
+ * the given compiler `Type`s, or null if a value doesn't fit its type. */
90
79
  export declare function marshalInputs(ctx: MarshalCtx, paramTypes: ReadonlyArray<Type>, values: ReadonlyArray<RuntimeValue | undefined>): MarshaledInputs | null;
91
- /** Convert a returned C tensor struct (decoded by koffi into a JS
92
- * object with `{real, imag, ndim, dims}`) to a numbl RuntimeTensor.
93
- * Reads `n = product(dims[0..ndim])` doubles from each lane, then
94
- * frees mtoc2's buffers.
95
- *
96
- * For `Numeric` outputs that aren't multi-element (scalars), the
97
- * caller passes the bare value through `unmarshalScalarOutput`
98
- * instead — koffi unboxes them automatically.
99
- */
80
+ /** Convert a returned C tensor struct (decoded by koffi into a JS object
81
+ * with `{real, imag, ndim, dims}`) to a numbl RuntimeTensor, then free
82
+ * the callee's buffers. Scalar outputs go through
83
+ * `unmarshalScalarOutput` instead. */
100
84
  export declare function unmarshalTensorOutput(ctx: MarshalCtx, ret: KoffiAny, ty: NumericType): RuntimeTensor;
101
85
  /** Convert a bare scalar return value to a numbl RuntimeValue.
102
86
  *