numbl 0.3.3 → 0.4.1

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 (349) hide show
  1. package/binding.gyp +6 -5
  2. package/dist-cli/cli.js +63077 -42047
  3. package/dist-lib/graphics/types.d.ts +40 -1
  4. package/dist-lib/lib.d.ts +0 -1
  5. package/dist-lib/lib.js +78446 -57671
  6. package/dist-lib/numbl-core/executeCode.d.ts +10 -12
  7. package/dist-lib/numbl-core/executors/classification.d.ts +134 -0
  8. package/dist-lib/numbl-core/executors/handleInline.d.ts +42 -0
  9. package/dist-lib/numbl-core/executors/index.d.ts +0 -3
  10. package/dist-lib/numbl-core/executors/jit/cJitCallExecutor.d.ts +35 -0
  11. package/dist-lib/numbl-core/executors/jit/cJitLoopExecutor.d.ts +31 -0
  12. package/dist-lib/numbl-core/executors/jit/cJitTopLevelExecutor.d.ts +29 -0
  13. package/dist-lib/numbl-core/executors/jit/callExecutor.d.ts +45 -0
  14. package/dist-lib/numbl-core/executors/jit/compileC.d.ts +51 -0
  15. package/dist-lib/numbl-core/executors/jit/compileC.node.d.ts +25 -0
  16. package/dist-lib/numbl-core/executors/jit/hostHelpers.d.ts +27 -0
  17. package/dist-lib/numbl-core/executors/jit/loopExecutor.d.ts +41 -0
  18. package/dist-lib/numbl-core/executors/jit/session.d.ts +17 -0
  19. package/dist-lib/numbl-core/executors/jit/topLevelExecutor.d.ts +36 -0
  20. package/dist-lib/numbl-core/executors/jit/typeAdapter.d.ts +28 -0
  21. package/dist-lib/numbl-core/executors/jit/typeAdapterC.d.ts +73 -0
  22. package/dist-lib/numbl-core/executors/jit/valueAdapter.d.ts +48 -0
  23. package/dist-lib/numbl-core/executors/jit/valueAdapterC.d.ts +108 -0
  24. package/dist-lib/numbl-core/executors/lowering.d.ts +31 -77
  25. package/dist-lib/numbl-core/executors/plugins.d.ts +14 -21
  26. package/dist-lib/numbl-core/helpers/reduction-helpers.d.ts +4 -1
  27. package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +1 -1
  28. package/dist-lib/numbl-core/interpreter/builtins/types.d.ts +0 -18
  29. package/dist-lib/numbl-core/interpreter/interpreter.d.ts +37 -21
  30. package/dist-lib/numbl-core/interpreter/interpreterExec.d.ts +6 -0
  31. package/dist-lib/numbl-core/interpreter/interpreterFunctions.d.ts +13 -1
  32. package/dist-lib/numbl-core/interpreter/interpreterSpecialBuiltins.d.ts +1 -1
  33. package/dist-lib/numbl-core/jit/builtins/defs/_shared.d.ts +43 -0
  34. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/_elemwise.d.ts +123 -0
  35. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/minus.d.ts +2 -0
  36. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/mpower.d.ts +12 -0
  37. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/mrdivide.d.ts +5 -0
  38. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/mtimes.d.ts +2 -0
  39. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/plus.d.ts +2 -0
  40. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/power.d.ts +30 -0
  41. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/rdivide.d.ts +2 -0
  42. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/times.d.ts +2 -0
  43. package/dist-lib/numbl-core/jit/builtins/defs/arithmetic/uminus.d.ts +2 -0
  44. package/dist-lib/numbl-core/jit/builtins/defs/compare/_compare.d.ts +12 -0
  45. package/dist-lib/numbl-core/jit/builtins/defs/compare/eq.d.ts +2 -0
  46. package/dist-lib/numbl-core/jit/builtins/defs/compare/ge.d.ts +2 -0
  47. package/dist-lib/numbl-core/jit/builtins/defs/compare/gt.d.ts +2 -0
  48. package/dist-lib/numbl-core/jit/builtins/defs/compare/le.d.ts +2 -0
  49. package/dist-lib/numbl-core/jit/builtins/defs/compare/lt.d.ts +2 -0
  50. package/dist-lib/numbl-core/jit/builtins/defs/compare/ne.d.ts +2 -0
  51. package/dist-lib/numbl-core/jit/builtins/defs/diag/assert.d.ts +6 -0
  52. package/dist-lib/numbl-core/jit/builtins/defs/io/_format_args.d.ts +17 -0
  53. package/dist-lib/numbl-core/jit/builtins/defs/io/disp.d.ts +2 -0
  54. package/dist-lib/numbl-core/jit/builtins/defs/io/error.d.ts +2 -0
  55. package/dist-lib/numbl-core/jit/builtins/defs/io/fprintf.d.ts +2 -0
  56. package/dist-lib/numbl-core/jit/builtins/defs/io/sprintf.d.ts +2 -0
  57. package/dist-lib/numbl-core/jit/builtins/defs/io/warning.d.ts +15 -0
  58. package/dist-lib/numbl-core/jit/builtins/defs/logical/_shortcircuit.d.ts +30 -0
  59. package/dist-lib/numbl-core/jit/builtins/defs/logical/_unary_pred.d.ts +30 -0
  60. package/dist-lib/numbl-core/jit/builtins/defs/logical/and.d.ts +5 -0
  61. package/dist-lib/numbl-core/jit/builtins/defs/logical/andand.d.ts +1 -0
  62. package/dist-lib/numbl-core/jit/builtins/defs/logical/boolconst.d.ts +3 -0
  63. package/dist-lib/numbl-core/jit/builtins/defs/logical/classBuiltin.d.ts +21 -0
  64. package/dist-lib/numbl-core/jit/builtins/defs/logical/fieldnames.d.ts +15 -0
  65. package/dist-lib/numbl-core/jit/builtins/defs/logical/isa.d.ts +13 -0
  66. package/dist-lib/numbl-core/jit/builtins/defs/logical/iscell.d.ts +8 -0
  67. package/dist-lib/numbl-core/jit/builtins/defs/logical/isempty.d.ts +2 -0
  68. package/dist-lib/numbl-core/jit/builtins/defs/logical/isequal.d.ts +2 -0
  69. package/dist-lib/numbl-core/jit/builtins/defs/logical/isfield.d.ts +20 -0
  70. package/dist-lib/numbl-core/jit/builtins/defs/logical/isinf.d.ts +2 -0
  71. package/dist-lib/numbl-core/jit/builtins/defs/logical/isnan.d.ts +1 -0
  72. package/dist-lib/numbl-core/jit/builtins/defs/logical/isnumeric.d.ts +7 -0
  73. package/dist-lib/numbl-core/jit/builtins/defs/logical/isreal.d.ts +2 -0
  74. package/dist-lib/numbl-core/jit/builtins/defs/logical/isscalar.d.ts +20 -0
  75. package/dist-lib/numbl-core/jit/builtins/defs/logical/isstruct.d.ts +7 -0
  76. package/dist-lib/numbl-core/jit/builtins/defs/logical/logical.d.ts +1 -0
  77. package/dist-lib/numbl-core/jit/builtins/defs/logical/not.d.ts +15 -0
  78. package/dist-lib/numbl-core/jit/builtins/defs/logical/or.d.ts +11 -0
  79. package/dist-lib/numbl-core/jit/builtins/defs/logical/oror.d.ts +1 -0
  80. package/dist-lib/numbl-core/jit/builtins/defs/logical/strcmp.d.ts +21 -0
  81. package/dist-lib/numbl-core/jit/builtins/defs/logical/typequery.d.ts +10 -0
  82. package/dist-lib/numbl-core/jit/builtins/defs/logical/xor.d.ts +12 -0
  83. package/dist-lib/numbl-core/jit/builtins/defs/math/_complex_fold.d.ts +34 -0
  84. package/dist-lib/numbl-core/jit/builtins/defs/math/_unary_real.d.ts +51 -0
  85. package/dist-lib/numbl-core/jit/builtins/defs/math/abs.d.ts +7 -0
  86. package/dist-lib/numbl-core/jit/builtins/defs/math/angle.d.ts +7 -0
  87. package/dist-lib/numbl-core/jit/builtins/defs/math/asinh.d.ts +1 -0
  88. package/dist-lib/numbl-core/jit/builtins/defs/math/atan.d.ts +1 -0
  89. package/dist-lib/numbl-core/jit/builtins/defs/math/atan2.d.ts +3 -0
  90. package/dist-lib/numbl-core/jit/builtins/defs/math/besselh.d.ts +2 -0
  91. package/dist-lib/numbl-core/jit/builtins/defs/math/ceil.d.ts +4 -0
  92. package/dist-lib/numbl-core/jit/builtins/defs/math/conj.d.ts +7 -0
  93. package/dist-lib/numbl-core/jit/builtins/defs/math/constants.d.ts +7 -0
  94. package/dist-lib/numbl-core/jit/builtins/defs/math/cos.d.ts +1 -0
  95. package/dist-lib/numbl-core/jit/builtins/defs/math/cosh.d.ts +1 -0
  96. package/dist-lib/numbl-core/jit/builtins/defs/math/dot.d.ts +20 -0
  97. package/dist-lib/numbl-core/jit/builtins/defs/math/double.d.ts +28 -0
  98. package/dist-lib/numbl-core/jit/builtins/defs/math/exp.d.ts +1 -0
  99. package/dist-lib/numbl-core/jit/builtins/defs/math/fix.d.ts +4 -0
  100. package/dist-lib/numbl-core/jit/builtins/defs/math/floor.d.ts +4 -0
  101. package/dist-lib/numbl-core/jit/builtins/defs/math/hypot.d.ts +3 -0
  102. package/dist-lib/numbl-core/jit/builtins/defs/math/imag.d.ts +7 -0
  103. package/dist-lib/numbl-core/jit/builtins/defs/math/linspace.d.ts +6 -0
  104. package/dist-lib/numbl-core/jit/builtins/defs/math/log.d.ts +4 -0
  105. package/dist-lib/numbl-core/jit/builtins/defs/math/log10.d.ts +3 -0
  106. package/dist-lib/numbl-core/jit/builtins/defs/math/log2.d.ts +5 -0
  107. package/dist-lib/numbl-core/jit/builtins/defs/math/logspace.d.ts +8 -0
  108. package/dist-lib/numbl-core/jit/builtins/defs/math/mod.d.ts +1 -0
  109. package/dist-lib/numbl-core/jit/builtins/defs/math/norm.d.ts +2 -0
  110. package/dist-lib/numbl-core/jit/builtins/defs/math/real.d.ts +7 -0
  111. package/dist-lib/numbl-core/jit/builtins/defs/math/rem.d.ts +3 -0
  112. package/dist-lib/numbl-core/jit/builtins/defs/math/round.d.ts +1 -0
  113. package/dist-lib/numbl-core/jit/builtins/defs/math/sign.d.ts +5 -0
  114. package/dist-lib/numbl-core/jit/builtins/defs/math/sin.d.ts +1 -0
  115. package/dist-lib/numbl-core/jit/builtins/defs/math/sinh.d.ts +1 -0
  116. package/dist-lib/numbl-core/jit/builtins/defs/math/sqrt.d.ts +11 -0
  117. package/dist-lib/numbl-core/jit/builtins/defs/math/tan.d.ts +1 -0
  118. package/dist-lib/numbl-core/jit/builtins/defs/math/tanh.d.ts +1 -0
  119. package/dist-lib/numbl-core/jit/builtins/defs/math/uniquetol.d.ts +22 -0
  120. package/dist-lib/numbl-core/jit/builtins/defs/plot/dispatch.d.ts +6 -0
  121. package/dist-lib/numbl-core/jit/builtins/defs/reduction/_cumulative.d.ts +49 -0
  122. package/dist-lib/numbl-core/jit/builtins/defs/reduction/_shape.d.ts +126 -0
  123. package/dist-lib/numbl-core/jit/builtins/defs/reduction/_variance.d.ts +17 -0
  124. package/dist-lib/numbl-core/jit/builtins/defs/reduction/all.d.ts +1 -0
  125. package/dist-lib/numbl-core/jit/builtins/defs/reduction/any.d.ts +1 -0
  126. package/dist-lib/numbl-core/jit/builtins/defs/reduction/cummax.d.ts +1 -0
  127. package/dist-lib/numbl-core/jit/builtins/defs/reduction/cummin.d.ts +1 -0
  128. package/dist-lib/numbl-core/jit/builtins/defs/reduction/cumprod.d.ts +1 -0
  129. package/dist-lib/numbl-core/jit/builtins/defs/reduction/cumsum.d.ts +1 -0
  130. package/dist-lib/numbl-core/jit/builtins/defs/reduction/diff.d.ts +16 -0
  131. package/dist-lib/numbl-core/jit/builtins/defs/reduction/length.d.ts +2 -0
  132. package/dist-lib/numbl-core/jit/builtins/defs/reduction/max.d.ts +1 -0
  133. package/dist-lib/numbl-core/jit/builtins/defs/reduction/mean.d.ts +1 -0
  134. package/dist-lib/numbl-core/jit/builtins/defs/reduction/min.d.ts +1 -0
  135. package/dist-lib/numbl-core/jit/builtins/defs/reduction/numel.d.ts +2 -0
  136. package/dist-lib/numbl-core/jit/builtins/defs/reduction/prod.d.ts +1 -0
  137. package/dist-lib/numbl-core/jit/builtins/defs/reduction/std.d.ts +1 -0
  138. package/dist-lib/numbl-core/jit/builtins/defs/reduction/sum.d.ts +1 -0
  139. package/dist-lib/numbl-core/jit/builtins/defs/reduction/var.d.ts +1 -0
  140. package/dist-lib/numbl-core/jit/builtins/defs/shape/_construct.d.ts +67 -0
  141. package/dist-lib/numbl-core/jit/builtins/defs/shape/_triangular.d.ts +34 -0
  142. package/dist-lib/numbl-core/jit/builtins/defs/shape/cat.d.ts +33 -0
  143. package/dist-lib/numbl-core/jit/builtins/defs/shape/diag.d.ts +29 -0
  144. package/dist-lib/numbl-core/jit/builtins/defs/shape/eye.d.ts +5 -0
  145. package/dist-lib/numbl-core/jit/builtins/defs/shape/flip.d.ts +7 -0
  146. package/dist-lib/numbl-core/jit/builtins/defs/shape/meshgrid.d.ts +12 -0
  147. package/dist-lib/numbl-core/jit/builtins/defs/shape/ones.d.ts +1 -0
  148. package/dist-lib/numbl-core/jit/builtins/defs/shape/repmat.d.ts +37 -0
  149. package/dist-lib/numbl-core/jit/builtins/defs/shape/reshape.d.ts +39 -0
  150. package/dist-lib/numbl-core/jit/builtins/defs/shape/size.d.ts +20 -0
  151. package/dist-lib/numbl-core/jit/builtins/defs/shape/sort.d.ts +19 -0
  152. package/dist-lib/numbl-core/jit/builtins/defs/shape/transpose.d.ts +6 -0
  153. package/dist-lib/numbl-core/jit/builtins/defs/shape/tril.d.ts +16 -0
  154. package/dist-lib/numbl-core/jit/builtins/defs/shape/triu.d.ts +16 -0
  155. package/dist-lib/numbl-core/jit/builtins/defs/shape/zeros.d.ts +1 -0
  156. package/dist-lib/numbl-core/jit/builtins/defs/system/deal.d.ts +20 -0
  157. package/dist-lib/numbl-core/jit/builtins/defs/system/feval.d.ts +36 -0
  158. package/dist-lib/numbl-core/jit/builtins/defs/system/pathBuiltins.d.ts +4 -0
  159. package/dist-lib/numbl-core/jit/builtins/defs/system/tic.d.ts +8 -0
  160. package/dist-lib/numbl-core/jit/builtins/defs/system/toc.d.ts +5 -0
  161. package/dist-lib/numbl-core/jit/builtins/index.d.ts +16 -0
  162. package/dist-lib/numbl-core/jit/builtins/registry.d.ts +138 -0
  163. package/dist-lib/numbl-core/jit/builtins/runtime/cell/cell.d.ts +24 -0
  164. package/dist-lib/numbl-core/jit/builtins/runtime/indexing/loop_count.d.ts +1 -0
  165. package/dist-lib/numbl-core/jit/builtins/runtime/indexing/range_value.d.ts +1 -0
  166. package/dist-lib/numbl-core/jit/builtins/runtime/indexing/scalar_index.d.ts +11 -0
  167. package/dist-lib/numbl-core/jit/builtins/runtime/indexing/tensor_make_range.d.ts +5 -0
  168. package/dist-lib/numbl-core/jit/builtins/runtime/io/assert_fmt.d.ts +1 -0
  169. package/dist-lib/numbl-core/jit/builtins/runtime/io/disp_complex.d.ts +1 -0
  170. package/dist-lib/numbl-core/jit/builtins/runtime/io/disp_double.d.ts +1 -0
  171. package/dist-lib/numbl-core/jit/builtins/runtime/io/disp_struct.d.ts +1 -0
  172. package/dist-lib/numbl-core/jit/builtins/runtime/io/disp_tensor.d.ts +1 -0
  173. package/dist-lib/numbl-core/jit/builtins/runtime/io/disp_tensor_complex.d.ts +1 -0
  174. package/dist-lib/numbl-core/jit/builtins/runtime/io/error_fmt.d.ts +2 -0
  175. package/dist-lib/numbl-core/jit/builtins/runtime/io/format_complex.d.ts +1 -0
  176. package/dist-lib/numbl-core/jit/builtins/runtime/io/format_double.d.ts +1 -0
  177. package/dist-lib/numbl-core/jit/builtins/runtime/io/format_engine.d.ts +1 -0
  178. package/dist-lib/numbl-core/jit/builtins/runtime/io/fprintf.d.ts +1 -0
  179. package/dist-lib/numbl-core/jit/builtins/runtime/io/sprintf.d.ts +5 -0
  180. package/dist-lib/numbl-core/jit/builtins/runtime/io/warning_fmt.d.ts +2 -0
  181. package/dist-lib/numbl-core/jit/builtins/runtime/plot/plot_dispatch.d.ts +1 -0
  182. package/dist-lib/numbl-core/jit/builtins/runtime/snippets.gen.d.ts +86 -0
  183. package/dist-lib/numbl-core/jit/builtins/runtime/system/cdiv.d.ts +4 -0
  184. package/dist-lib/numbl-core/jit/builtins/runtime/system/cscalar.d.ts +103 -0
  185. package/dist-lib/numbl-core/jit/builtins/runtime/system/deep_clone.d.ts +1 -0
  186. package/dist-lib/numbl-core/jit/builtins/runtime/system/isequal.d.ts +2 -0
  187. package/dist-lib/numbl-core/jit/builtins/runtime/system/tictoc.d.ts +5 -0
  188. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor.d.ts +6 -0
  189. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor_alloc.d.ts +5 -0
  190. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor_alloc_complex.d.ts +6 -0
  191. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor_alloc_nd.d.ts +5 -0
  192. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor_alloc_nd_complex.d.ts +6 -0
  193. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor_copy_complex.d.ts +6 -0
  194. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor_from_matrix.d.ts +5 -0
  195. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor_from_matrix_complex.d.ts +6 -0
  196. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor_from_row.d.ts +5 -0
  197. package/dist-lib/numbl-core/jit/builtins/runtime/tensor/tensor_from_row_complex.d.ts +6 -0
  198. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_cat.d.ts +11 -0
  199. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_cumulative.d.ts +32 -0
  200. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_diag.d.ts +33 -0
  201. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_diff.d.ts +5 -0
  202. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_dot.d.ts +16 -0
  203. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_elemwise_complex.d.ts +90 -0
  204. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_elemwise_real.d.ts +75 -0
  205. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_elemwise_real_fn.d.ts +95 -0
  206. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_eye.d.ts +10 -0
  207. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_fill_nd.d.ts +11 -0
  208. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_fill_square.d.ts +5 -0
  209. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_flip.d.ts +11 -0
  210. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_linspace.d.ts +5 -0
  211. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_logical_real.d.ts +10 -0
  212. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_logspace.d.ts +5 -0
  213. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_meshgrid.d.ts +29 -0
  214. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_mtimes_complex.d.ts +10 -0
  215. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_mtimes_real.d.ts +6 -0
  216. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_norm.d.ts +4 -0
  217. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_ones_nd.d.ts +5 -0
  218. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_ones_square.d.ts +5 -0
  219. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_predicate.d.ts +42 -0
  220. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_reduce_complex.d.ts +53 -0
  221. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_reduce_real.d.ts +42 -0
  222. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_repmat.d.ts +11 -0
  223. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_reshape_nd.d.ts +5 -0
  224. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_reshape_nd_complex.d.ts +6 -0
  225. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_size.d.ts +5 -0
  226. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_sort_real.d.ts +36 -0
  227. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_transpose.d.ts +5 -0
  228. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_transpose_complex.d.ts +6 -0
  229. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_triangular.d.ts +22 -0
  230. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_unary_complex_math.d.ts +128 -0
  231. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_unary_real_math.d.ts +95 -0
  232. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_uniquetol.d.ts +5 -0
  233. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_var.d.ts +12 -0
  234. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_zeros_nd.d.ts +5 -0
  235. package/dist-lib/numbl-core/jit/builtins/runtime/tensor_ops/tensor_zeros_square.d.ts +5 -0
  236. package/dist-lib/numbl-core/jit/builtins/runtime/text/strcmp.d.ts +2 -0
  237. package/dist-lib/numbl-core/jit/codegen/cFormat.d.ts +36 -0
  238. package/dist-lib/numbl-core/jit/codegen/cHelpers.d.ts +48 -0
  239. package/dist-lib/numbl-core/jit/codegen/emit.d.ts +55 -0
  240. package/dist-lib/numbl-core/jit/codegen/emitCellTypedef.d.ts +23 -0
  241. package/dist-lib/numbl-core/jit/codegen/emitExpr.d.ts +33 -0
  242. package/dist-lib/numbl-core/jit/codegen/emitIndex.d.ts +56 -0
  243. package/dist-lib/numbl-core/jit/codegen/emitJs.d.ts +64 -0
  244. package/dist-lib/numbl-core/jit/codegen/emitNamedTypedef.d.ts +58 -0
  245. package/dist-lib/numbl-core/jit/codegen/emitStmt.d.ts +76 -0
  246. package/dist-lib/numbl-core/jit/codegen/emitTensorConcat.d.ts +23 -0
  247. package/dist-lib/numbl-core/jit/codegen/emitTensorConcatJs.d.ts +16 -0
  248. package/dist-lib/numbl-core/jit/codegen/emitTensorFused.d.ts +77 -0
  249. package/dist-lib/numbl-core/jit/codegen/inlinePass.d.ts +66 -0
  250. package/dist-lib/numbl-core/jit/codegen/liveness.d.ts +58 -0
  251. package/dist-lib/numbl-core/jit/codegen/prettyIR.d.ts +24 -0
  252. package/dist-lib/numbl-core/jit/codegen/runtime.d.ts +150 -0
  253. package/dist-lib/numbl-core/jit/compileSpec.d.ts +84 -0
  254. package/dist-lib/numbl-core/jit/compileSpecC.d.ts +93 -0
  255. package/dist-lib/numbl-core/jit/index.d.ts +15 -0
  256. package/dist-lib/numbl-core/jit/lowering/classDefs.d.ts +109 -0
  257. package/dist-lib/numbl-core/jit/lowering/errors.d.ts +35 -0
  258. package/dist-lib/numbl-core/jit/lowering/indexFold.d.ts +31 -0
  259. package/dist-lib/numbl-core/jit/lowering/indexResolve.d.ts +100 -0
  260. package/dist-lib/numbl-core/jit/lowering/ir.d.ts +584 -0
  261. package/dist-lib/numbl-core/jit/lowering/lower.d.ts +271 -0
  262. package/dist-lib/numbl-core/jit/lowering/lowerCellIndex.d.ts +41 -0
  263. package/dist-lib/numbl-core/jit/lowering/lowerCellLit.d.ts +19 -0
  264. package/dist-lib/numbl-core/jit/lowering/lowerClassConstructor.d.ts +55 -0
  265. package/dist-lib/numbl-core/jit/lowering/lowerFuncCall.d.ts +34 -0
  266. package/dist-lib/numbl-core/jit/lowering/lowerHandle.d.ts +57 -0
  267. package/dist-lib/numbl-core/jit/lowering/lowerIndexLoad.d.ts +16 -0
  268. package/dist-lib/numbl-core/jit/lowering/lowerIndexSlice.d.ts +29 -0
  269. package/dist-lib/numbl-core/jit/lowering/lowerIndexSliceStore.d.ts +19 -0
  270. package/dist-lib/numbl-core/jit/lowering/lowerIndexStore.d.ts +14 -0
  271. package/dist-lib/numbl-core/jit/lowering/lowerMethodCall.d.ts +45 -0
  272. package/dist-lib/numbl-core/jit/lowering/lowerMultiAssign.d.ts +36 -0
  273. package/dist-lib/numbl-core/jit/lowering/lowerTensorLit.d.ts +25 -0
  274. package/dist-lib/numbl-core/jit/lowering/rangeCount.d.ts +19 -0
  275. package/dist-lib/numbl-core/jit/lowering/specialize.d.ts +93 -0
  276. package/dist-lib/numbl-core/jit/lowering/types.d.ts +503 -0
  277. package/dist-lib/numbl-core/jit/lowering/walk.d.ts +17 -0
  278. package/dist-lib/numbl-core/jit/numbl/index.d.ts +30 -0
  279. package/dist-lib/numbl-core/jit/parser/astUtils.d.ts +43 -0
  280. package/dist-lib/numbl-core/jit/parser/index.d.ts +12 -0
  281. package/dist-lib/numbl-core/jit/parser/sourceLoc.d.ts +12 -0
  282. package/dist-lib/numbl-core/jit/runtime/context.d.ts +23 -0
  283. package/dist-lib/numbl-core/jit/runtime/inferType.d.ts +10 -0
  284. package/dist-lib/numbl-core/jit/runtime/value.d.ts +101 -0
  285. package/dist-lib/numbl-core/jit/workspace/driverPrologue.d.ts +59 -0
  286. package/dist-lib/numbl-core/jit/workspace/mtoc2UserFunctionLoader.d.ts +62 -0
  287. package/dist-lib/numbl-core/jit/workspace/workspace.d.ts +243 -0
  288. package/dist-lib/numbl-core/jitTypes.d.ts +7 -321
  289. package/dist-lib/numbl-core/jsUserFunctions.d.ts +2 -2
  290. package/dist-lib/numbl-core/parser/ClassParser.d.ts +3 -0
  291. package/dist-lib/numbl-core/runtime/index.d.ts +1 -1
  292. package/dist-lib/numbl-core/runtime/indexing.d.ts +11 -1
  293. package/dist-lib/numbl-core/runtime/plotUtils.d.ts +28 -2
  294. package/dist-lib/numbl-core/runtime/runtime.d.ts +16 -1
  295. package/dist-lib/numbl-core/runtime/runtimePlot.d.ts +5 -0
  296. package/dist-lib/numbl-core/runtime/types.d.ts +19 -3
  297. package/dist-lib/numbl-core/version.d.ts +1 -1
  298. package/dist-lib/numbl-core/workspace/types.d.ts +8 -0
  299. package/dist-plot-viewer/assets/index-DfxsWeyf.js +4426 -0
  300. package/dist-plot-viewer/index.html +1 -1
  301. package/dist-site-viewer/404.html +33 -0
  302. package/dist-site-viewer/assets/index-C5c2lKAx.js +4748 -0
  303. package/dist-site-viewer/assets/index-D5YY8PKx.css +1 -0
  304. package/dist-site-viewer/assets/numbl-worker-CkoM4MUa.js +11836 -0
  305. package/dist-site-viewer/coi-serviceworker.js +70 -0
  306. package/dist-site-viewer/favicon.svg +23 -0
  307. package/dist-site-viewer/index.html +16 -0
  308. package/dist-site-viewer/logo.svg +26 -0
  309. package/dist-site-viewer/numbl-embed.js +111 -0
  310. package/dist-site-viewer/vite.svg +1 -0
  311. package/native/ops/real_unary_elemwise.c +3 -1
  312. package/package.json +15 -9
  313. package/dist-lib/numbl-core/executors/cJit/builtins.d.ts +0 -30
  314. package/dist-lib/numbl-core/executors/cJit/chainCodegen.d.ts +0 -59
  315. package/dist-lib/numbl-core/executors/cJit/chainExecutor.d.ts +0 -27
  316. package/dist-lib/numbl-core/executors/cJit/chainPass.d.ts +0 -42
  317. package/dist-lib/numbl-core/executors/cJit/codegen.d.ts +0 -44
  318. package/dist-lib/numbl-core/executors/cJit/compile.d.ts +0 -45
  319. package/dist-lib/numbl-core/executors/cJit/elemwiseCodegen.d.ts +0 -23
  320. package/dist-lib/numbl-core/executors/cJit/elemwiseStructural.d.ts +0 -33
  321. package/dist-lib/numbl-core/executors/cJit/fuseAnalyze.d.ts +0 -39
  322. package/dist-lib/numbl-core/executors/cJit/fuseCodegen.d.ts +0 -16
  323. package/dist-lib/numbl-core/executors/cJit/fuseExecutor.d.ts +0 -28
  324. package/dist-lib/numbl-core/executors/cJit/loopExecutor.d.ts +0 -32
  325. package/dist-lib/numbl-core/executors/cJit/register.d.ts +0 -10
  326. package/dist-lib/numbl-core/executors/cJit/whitelist.d.ts +0 -15
  327. package/dist-lib/numbl-core/executors/jsJit/callExecutor.d.ts +0 -25
  328. package/dist-lib/numbl-core/executors/jsJit/codegen/jitCodegen.d.ts +0 -7
  329. package/dist-lib/numbl-core/executors/jsJit/codegen/jitCodegenHoist.d.ts +0 -70
  330. package/dist-lib/numbl-core/executors/jsJit/codegen/jsMultiReduction.d.ts +0 -67
  331. package/dist-lib/numbl-core/executors/jsJit/helpers/jitHelpers.d.ts +0 -34
  332. package/dist-lib/numbl-core/executors/jsJit/helpers/jitHelpersComplex.d.ts +0 -21
  333. package/dist-lib/numbl-core/executors/jsJit/helpers/jitHelpersIndex.d.ts +0 -33
  334. package/dist-lib/numbl-core/executors/jsJit/helpers/jitHelpersTensor.d.ts +0 -34
  335. package/dist-lib/numbl-core/executors/jsJit/jitCall.d.ts +0 -59
  336. package/dist-lib/numbl-core/executors/jsJit/jitLoop.d.ts +0 -53
  337. package/dist-lib/numbl-core/executors/jsJit/jitTopLevel.d.ts +0 -44
  338. package/dist-lib/numbl-core/executors/jsJit/loopExecutor.d.ts +0 -15
  339. package/dist-lib/numbl-core/executors/jsJit/lower/blockAnalysis.d.ts +0 -37
  340. package/dist-lib/numbl-core/executors/jsJit/lower/jitBailSafety.d.ts +0 -41
  341. package/dist-lib/numbl-core/executors/jsJit/lower/jitLower.d.ts +0 -136
  342. package/dist-lib/numbl-core/executors/jsJit/lower/jitLowerExpr.d.ts +0 -36
  343. package/dist-lib/numbl-core/executors/jsJit/lower/jitLowerStmt.d.ts +0 -9
  344. package/dist-lib/numbl-core/executors/jsJit/lower/jitLowerTypes.d.ts +0 -29
  345. package/dist-lib/numbl-core/executors/jsJit/lower/scalarEmit.d.ts +0 -58
  346. package/dist-lib/numbl-core/executors/jsJit/shared.d.ts +0 -120
  347. package/dist-lib/numbl-core/executors/jsJit/topLevelExecutor.d.ts +0 -17
  348. package/dist-plot-viewer/assets/index-COAM8o1E.js +0 -4426
  349. /package/dist-lib/numbl-core/{executors/jsJit/helpers → runtime}/alloc.d.ts +0 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Function-shape + statement-level codegen — `emitFunction`,
3
+ * `emitBody`, `emitStmt`, and the locals-collection / param-list
4
+ * helpers they share. Statement emit is mutually recursive with body
5
+ * emit (If/While/For wrap nested bodies), so they live together.
6
+ *
7
+ * Expression-side emit lives in `emitExpr.ts`; index slice store /
8
+ * scalar offset and named-typedef helpers are in their own modules.
9
+ */
10
+ import type { IRExpr, IRFunc, IRStmt } from "../lowering/ir.js";
11
+ import { type Type } from "../lowering/types.js";
12
+ import { type RuntimeState } from "./runtime.js";
13
+ import { type FutureTouchMap } from "./liveness.js";
14
+ /** Default initializer for a freshly-declared non-owned local. Owned
15
+ * types (tensors, structs, classes, handles) route through their
16
+ * `_empty()` helper instead and never hit this path; everything
17
+ * reaching here is scalar real numeric, so `0.0` always fits. */
18
+ export declare function defaultInitFor(): string;
19
+ export declare function fnRetType(fn: IRFunc): string;
20
+ export declare function fnParamList(fn: IRFunc): string;
21
+ /** Walk `stmts` once and split the result into owned vs non-owned
22
+ * locals. Every local is pre-declared at function top — owned with
23
+ * the per-type `_empty()` helper, scalars with the default init
24
+ * (`0.0` / `0`). The non-owned half also picks up For loop vars and
25
+ * multi-assign slot bindings so that a later read of a variable
26
+ * first written inside an If / While / For body (reachable via
27
+ * `mergeBranchEnvs` keeping partial-branch keys) doesn't reference
28
+ * an out-of-scope C local. */
29
+ export declare function collectLocals(stmts: IRStmt[]): {
30
+ owned: {
31
+ cName: string;
32
+ ty: Type;
33
+ }[];
34
+ scalars: {
35
+ cName: string;
36
+ ty: Type;
37
+ }[];
38
+ };
39
+ /** Emits the function/scope's exit cleanup + return statements at a
40
+ * given indent. Called from two places: at every `ReturnFromFunction`
41
+ * site (inline cleanup — no goto), and at the fall-through bottom of
42
+ * the function. Single source of truth so the two callers can't
43
+ * drift on which locals get freed in what order.
44
+ *
45
+ * Why inline rather than goto-to-a-shared-tail: c2js can't translate
46
+ * C `goto`, and we want a single C emit that works for both targets.
47
+ * Inlining produces some duplication when a function has many early
48
+ * returns and many owned locals, but typical mtoc2 functions are
49
+ * small and the C compiler dedupes-by-tail-merge anyway. */
50
+ export type EmitReturnTail = (indent: string) => string;
51
+ export declare function emitFunction(fn: IRFunc, state: RuntimeState,
52
+ /** Storage-class qualifier on the function definition. Default is
53
+ * `static` (file-scope, the C-AOT whole-program convention). Pass
54
+ * `""` to omit the qualifier — the function then gets external
55
+ * linkage so a JIT host can resolve it via `dlsym` / koffi after
56
+ * `dlopen`'ing the compiled `.so`. */
57
+ storageClass?: "static" | ""): string;
58
+ /** Emit a sequence of statements with their per-stmt early-frees.
59
+ * After each stmt, owned C-names that aren't in the stmt's
60
+ * futureTouchOut (i.e. their last use was at this stmt) get a
61
+ * `<owned-kind>_free(&v);` call dispatched on the variable's
62
+ * recorded owned type. Scope-exit frees still emit unconditionally
63
+ * — they're no-ops for buffers already nulled by the early-free. */
64
+ export declare function emitBody(stmts: IRStmt[], indent: string, state: RuntimeState, futureTouches: FutureTouchMap, ownedTypes: ReadonlyMap<string, Type>, emitReturnTail: EmitReturnTail): string;
65
+ /** Compute a column-major linear offset expression from cell-brace
66
+ * indices. The base's shape supplies the row count for the 2-D
67
+ * formula. Indices are 1-based in source; we subtract 1 to land
68
+ * in C's 0-based slot/buffer array. */
69
+ export declare function cellLinearOffsetExpr(indices: ReadonlyArray<IRExpr>, baseTy: Extract<Type, {
70
+ kind: "Cell";
71
+ }>, baseCName: string, state: RuntimeState): string;
72
+ /** Try to compute a static slot offset from a tuple cell's indices.
73
+ * Returns `null` if any index isn't a NumLit. */
74
+ export declare function tryStaticCellOffset(indices: ReadonlyArray<IRExpr>, baseTy: Extract<Type, {
75
+ kind: "Cell";
76
+ }>): number | null;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `TensorConcat` codegen — the bracket-concatenation IR node produced
3
+ * by `lowerTensorLit`'s mixed-cell path (`[a, b; c, d]` where at least
4
+ * one cell is a tensor). Two paths: a fully-static one that bakes per-
5
+ * cell row/col offsets into literals, and a dynamic one that walks
6
+ * runtime `.dims[k]` reads.
7
+ *
8
+ * Both emit a GCC statement-expression that allocs a destination
9
+ * tensor, writes every cell's rectangle, and evaluates to the
10
+ * destination. ANF guarantees every tensor cell is already a Var, so
11
+ * cell reads carry no allocation cost.
12
+ *
13
+ * Mirrors numbl's `catAlongDim` (runtime/tensor-construction.ts) for
14
+ * the output layout — column-major destination, per-cell rectangle.
15
+ */
16
+ import type { IRExpr } from "../lowering/ir.js";
17
+ import { type RuntimeState } from "./runtime.js";
18
+ /** Top-level entry: dispatch to the static or dynamic codegen path
19
+ * based on whether every per-cell dim and the output shape are
20
+ * compile-time known. */
21
+ export declare function emitTensorConcat(e: Extract<IRExpr, {
22
+ kind: "TensorConcat";
23
+ }>, state: RuntimeState): string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * JS sibling of `emitTensorConcat.ts`. Same two-path structure
3
+ * (fully-static vs. runtime-dim), same per-cell rectangle-copy
4
+ * shape — only the language and field names differ:
5
+ * `.real` (C) → `.data` (JS)
6
+ * `.dims[k]` (C) → `.shape[k]` (JS)
7
+ *
8
+ * GCC statement-expressions don't exist in JS; the destination
9
+ * tensor and per-cell writes are wrapped in an IIFE that returns
10
+ * the result.
11
+ */
12
+ import type { IRExpr } from "../lowering/ir.js";
13
+ import { type RuntimeState } from "./runtime.js";
14
+ export declare function emitTensorConcatJs(e: Extract<IRExpr, {
15
+ kind: "TensorConcat";
16
+ }>, state: RuntimeState, emit: (e: IRExpr, state: RuntimeState) => string): string;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Elementwise-fused tensor Assign emission.
3
+ *
4
+ * For an Assign whose RHS is a pure elementwise expression and whose
5
+ * multi-element operands all share the target's static shape, emit a
6
+ * single inline iter loop instead of nested runtime-helper calls:
7
+ *
8
+ * // c = a + b; emits:
9
+ * {
10
+ * mtoc2_tensor_t _r = mtoc2_tensor_alloc_nd(a.ndim, a.dims);
11
+ * long _mtoc2_n = 1; for (int _mtoc2_i = 0; _mtoc2_i < _r.ndim; _mtoc2_i++) _mtoc2_n *= _r.dims[_mtoc2_i];
12
+ * MTOC2_OMP_PARFOR_N
13
+ * for (long _mtoc2_i = 0; _mtoc2_i < _mtoc2_n; _mtoc2_i++) _r.real[_mtoc2_i] = (a.real[_mtoc2_i] + b.real[_mtoc2_i]);
14
+ * mtoc2_tensor_assign(&c, _r);
15
+ * }
16
+ *
17
+ * The local element-count + iter variables use the `_mtoc2_` reserved
18
+ * prefix so they can't collide with user-scope identifiers (`n`, `i`
19
+ * are common single-letter names in MATLAB and would shadow the
20
+ * function param / local on the enclosing block if we declared them
21
+ * with their natural names).
22
+ *
23
+ * For a single-Binary RHS this is equivalent (post-`-O3`) to the
24
+ * existing `mtoc2_tensor_assign(&c, mtoc2_tensor_plus_tt(a, b))`
25
+ * path — the helper's body is literally the same loop. The point of
26
+ * doing the inlining at the IR level is that the `--inline-temps`
27
+ * pass (phase 2) can fold a chain like `_t1 = a * b; c = _t1 + d`
28
+ * into `c = (a * b) + d`, which the fused emitter then renders as
29
+ * one loop with no intermediate tensor allocation.
30
+ *
31
+ * Phase 1 (this file) only handles the *same-static-shape* case. If
32
+ * any multi-element operand has a statically-different shape from
33
+ * the target, the Assign falls back to the runtime-helper path
34
+ * (`mtoc2_tensor_<op>_bcast_tt(...)`). Broadcast fusion is phase 3.
35
+ */
36
+ import type { Assign, IRExpr } from "../lowering/ir.js";
37
+ import { type RuntimeState } from "./runtime.js";
38
+ /** True iff `e` is a pure-elementwise expression — only NumLit / Var /
39
+ * Binary / Unary / Call to a builtin that has a `perSlotC` hook. No
40
+ * owned producers (TensorBuild, TensorConcat, IndexSlice), no
41
+ * non-elementwise calls (mtimes, reshape, sum, …), no user-fn calls,
42
+ * no HandleLit, no IndexLoad/HandleCaptureLoad/MemberLoad, etc.
43
+ *
44
+ * These are exactly the node kinds the per-slot renderer below
45
+ * knows how to walk. */
46
+ export declare function isPureElementwiseExpr(e: IRExpr): boolean;
47
+ /** True iff the fused emitter can handle this Assign. Requires:
48
+ * - target is a real-double multi-element tensor
49
+ * - RHS is pure elementwise (see `isPureElementwiseExpr`)
50
+ * - every multi-element Var in the RHS shares the target's static
51
+ * shape (no broadcasting in this phase)
52
+ * - no complex tensor anywhere in the RHS — the per-slot renderer
53
+ * addresses tensors as `<cName>.real[i]` and drops the imag lane.
54
+ * Complex sites take the runtime-helper path. */
55
+ export declare function isFusableAssign(s: Assign): boolean;
56
+ /** A fusable Assign needs a runtime shape guard iff it reads two or more
57
+ * DISTINCT multi-element operands AND at least one carries a dynamic
58
+ * (non-exact) dim. In that case `isFusableAssign` matched the operands
59
+ * on a shared static dim PATTERN, but their runtime extents aren't
60
+ * proven equal (`ones(1,n) + ones(1,m)`), so the fused loop — which
61
+ * reads every operand over the shape source's linear extent — could
62
+ * read out of bounds. With all-exact dims the pattern match already
63
+ * proves equality, and a single distinct operand is its own shape
64
+ * source; neither needs the guard. */
65
+ export declare function fusedAssignNeedsShapeGuard(s: Assign): boolean;
66
+ /** Emit the fused inline iter loop. Pre-condition:
67
+ * `isFusableAssign(s)` returned true.
68
+ *
69
+ * When `fallbackStmt` is supplied (the caller passes it iff
70
+ * `fusedAssignNeedsShapeGuard(s)` is true), the fast loop is wrapped in
71
+ * a runtime shape-equality guard: every other distinct multi-element
72
+ * operand must match the shape source's runtime shape, else the assign
73
+ * defers to `fallbackStmt` — the bcast-aware helper path, which
74
+ * broadcasts compatible shapes and raises "Matrix dimensions must
75
+ * agree" on incompatible ones. Mirrors the JS `tt_kernel` deferring to
76
+ * `bcast_kernel`. */
77
+ export declare function emitTensorAssignFused(s: Assign, indent: string, state: RuntimeState, fallbackStmt?: string): string;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * `--inline-temps` IR-to-IR rewrite: substitutes a single-use
3
+ * producer Assign's RHS into its consumer's RHS and removes the
4
+ * producer.
5
+ *
6
+ * After ANF normalization every owned-producing tensor expression
7
+ * lives in its own `_mtoc2_t<N>` temp. Without inlining, a chain
8
+ * like
9
+ *
10
+ * _t8 = rx .^ 2
11
+ * _t9 = ry .^ 2
12
+ * _t10 = _t8 + _t9
13
+ * r2 = _t10 + 0.01
14
+ *
15
+ * emits four separate fused loops with three intermediate allocs.
16
+ * After inlining (this pass), the chain collapses to
17
+ *
18
+ * r2 = (rx .^ 2 + ry .^ 2 + 0.01)
19
+ *
20
+ * which the elementwise-fused emitter (`emitTensorFused.ts`) renders
21
+ * as a single iter loop. No intermediate tensors, no extra passes
22
+ * through memory.
23
+ *
24
+ * Gates (must all hold to inline producer P into consumer C):
25
+ *
26
+ * 1. P is an Assign producing a real-double multi-element tensor.
27
+ * 2. P's RHS is pure elementwise — only NumLit / Var / Binary /
28
+ * Unary / Call to a builtin that has `perSlotC`. No
29
+ * TensorBuild / TensorConcat / IndexLoad / IndexSlice /
30
+ * MemberLoad / HandleLit / etc.
31
+ * 3. P's LHS cName is used exactly once in the body. Function
32
+ * output cNames get a `+1` protective bump so the returned
33
+ * value is never elided.
34
+ * 4. The single use is in another Assign's RHS, in a slot
35
+ * position (subexpression of Binary / Unary / Call args). NOT
36
+ * as the base of an IndexLoad / IndexSlice / MemberLoad, NOT
37
+ * inside a TensorBuild / TensorConcat / StructLit / HandleLit.
38
+ * 5. C is also fusable (same predicate as `isFusableAssign`).
39
+ * 6. P and C are at the same body level (no inlining across
40
+ * If / While / For — nested bodies are inlined separately).
41
+ * 7. No statement between P and C writes to P's LHS or to any
42
+ * free Var in P's RHS, and no statement reads P's LHS except
43
+ * C. Control flow (If / While / For / Break / Continue /
44
+ * ReturnFromFunction) ends the safe window.
45
+ *
46
+ * Algorithm: per body, iterate `inlineOnePass` to fixed point.
47
+ * Each pass scans producers in source order, finds the first
48
+ * inlinable pair, substitutes, and returns the new body. Chained
49
+ * inlining (`a → b → c`) needs multiple iterations because each
50
+ * substitution can flip a previously-multi-use cName to single-use;
51
+ * we cap at 32 iterations defensively.
52
+ *
53
+ * Preserves: post-inlining the IR is still well-typed (each node's
54
+ * `.ty` is unchanged — the substitution copies the producer's RHS
55
+ * subtree verbatim); the ANF invariant for owned producers still
56
+ * holds because we only inline producers whose RHS is NOT itself
57
+ * an owned producer (no TensorBuild / Call-to-direct-owned-builtin
58
+ * / etc.); and the `isFusableAssign` predicate that gates the
59
+ * emit-path routing still accepts the consumer after substitution
60
+ * (shape checks compose under inlining — see the design notes in
61
+ * `emitTensorFused.ts`).
62
+ */
63
+ import type { IRProgram } from "../lowering/ir.js";
64
+ /** Top-level entry. Mutates `prog.topLevelStmts` and each function's
65
+ * `body` in place when inlining fires. */
66
+ export declare function inlinePass(prog: IRProgram): void;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Backward dataflow over the lowered IR computing per-statement
3
+ * "future-touch" sets for owned-heap-value variables — currently
4
+ * just multi-element tensors (`isOwned` in types.ts). An owned `v`'s
5
+ * future-touch set at statement `s` is the union of vars touched
6
+ * (read OR written) by any successor of `s` in the structured CFG.
7
+ *
8
+ * Drives the "early free" emission in emit.ts: an owned `v` whose
9
+ * last touch is statement `s` (i.e. `v` is in
10
+ * `(uses ∪ defs)(s)` but NOT in `futureTouchOut(s)`) gets a
11
+ * `mtoc2_tensor_free(&v)` immediately after `s`'s C output, rather
12
+ * than waiting for scope exit.
13
+ *
14
+ * Why "touch" (uses ∪ defs) rather than standard liveness (uses with
15
+ * kill on def)? Reassignment goes through `mtoc2_tensor_assign(&v,
16
+ * ...)`, which already releases the prior buffer. If `v`'s next
17
+ * interaction is a reassignment, an early-free at the previous use
18
+ * would be redundant — better to let the assign helper handle it.
19
+ * The future-touch set captures exactly that: a redef counts as a
20
+ * future touch and suppresses the early-free emission.
21
+ *
22
+ * Only owned variables are tracked; scalar `double` locals live in
23
+ * C automatic storage and have no heap to release.
24
+ *
25
+ * Loops resolve by fixpoint over the body's "after-body-last" set.
26
+ * Break / Continue / ReturnFromFunction consult the enclosing
27
+ * context for their target's future touches.
28
+ *
29
+ * Direct port of mtoc's `src/codegen/liveness.ts`, adapted for
30
+ * mtoc2's simpler IR (no Disp/Error/Assert/Fprintf/MultiAssignCall/
31
+ * IndexStore/etc. yet).
32
+ */
33
+ import type { IRStmt } from "../lowering/ir.js";
34
+ import { type Type } from "../lowering/types.js";
35
+ /** Per-statement future-touch sets, keyed by the IRStmt object
36
+ * reference. Each entry holds the set of owned C-names that may be
37
+ * touched (read or written) at any successor of the statement. */
38
+ export type FutureTouchMap = ReadonlyMap<IRStmt, ReadonlySet<string>>;
39
+ /** Compute per-statement future-touch sets for a body of statements.
40
+ * For function bodies whose output slots include owned values, pass
41
+ * one `{ cName, ty }` per owned output. The analyzer seeds the body-
42
+ * end future-touch with each owned-output C-name — otherwise the
43
+ * implicit return / sret writes would see the final defs as "last
44
+ * touches" and emit stray early-frees of the values we're about to
45
+ * transfer to the caller. Pass an empty array for main, scalar-
46
+ * returning functions, or functions with no owned outputs. */
47
+ export declare function computeFutureTouches(stmts: ReadonlyArray<IRStmt>, ownedOutputs?: ReadonlyArray<{
48
+ cName: string;
49
+ ty: Type;
50
+ }>): FutureTouchMap;
51
+ /** After emitting `s`, return the set of owned C-names that should
52
+ * be freed immediately (no future touch). Helper for emit.ts.
53
+ *
54
+ * The scope-exit free walk emits frees for every owned local
55
+ * unconditionally — early-frees null out the buffer and every owned
56
+ * `_free` helper is NULL-safe, so a scope-exit free of an already-
57
+ * freed local is redundant but safe. */
58
+ export declare function earlyFreeCandidates(s: IRStmt, futureTouches: FutureTouchMap): Set<string>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Numbl-like pretty-printer for the IR. Used by the C emitter to
3
+ * annotate the generated source with readable comments — function
4
+ * signatures with detailed type info, and a per-statement summary
5
+ * of the lowered expression above each emitted block.
6
+ *
7
+ * The output is NOT a faithful reproduction of the user's source
8
+ * (synthetic names like `_mtoc2_t1`, ANF temps, and folded branches
9
+ * are visible). It IS a faithful render of what the IR actually says
10
+ * after lowering — useful when debugging the translator.
11
+ */
12
+ import type { IRStmt, IRFunc, IRProgram } from "../lowering/ir.js";
13
+ /** One-line summary of a statement (no trailing newline). Returns null
14
+ * for stmts the emitter handles structurally (compound-block bodies
15
+ * get their own per-stmt comments inside). */
16
+ export declare function irStmtHeader(s: IRStmt): string | null;
17
+ /** Multi-line C block comment for a function specialization, listing
18
+ * name, mangled C identifier, per-parameter types, and output types. */
19
+ export declare function irFuncDocComment(fn: IRFunc): string;
20
+ /** Render the whole lowered IR as a numbl-like script with one block
21
+ * per function specialization plus a trailing top-level body. Used by
22
+ * the IDE's Internals tab in interpreter mode, where no codegen
23
+ * artifact exists. */
24
+ export declare function prettyIRProgram(prog: IRProgram): string;
@@ -0,0 +1,150 @@
1
+ /**
2
+ * mtoc2 runtime helpers — small C snippets inlined into the generated
3
+ * source on demand.
4
+ *
5
+ * Each helper lives in its own .h file under `runtime/` so it can be
6
+ * edited with normal C tooling (clangd, syntax highlighting). The .h
7
+ * sources are inlined into `runtime/snippets.gen.ts` by
8
+ * `scripts/build_runtime_snippets.ts`; this module reads them from
9
+ * there (rather than the filesystem at load time) so the translator
10
+ * bundles in the browser.
11
+ *
12
+ * Each helper is referenced by a stable name (e.g. "mtoc2_disp_double").
13
+ * Snippets can declare other snippets they depend on; the activator
14
+ * pulls dependencies in first.
15
+ */
16
+ import type { Builtin } from "../builtins/registry.js";
17
+ /** Minimal Workspace shape consulted at emit time. Importing the
18
+ * concrete Workspace class would create a cycle (workspace ↔ codegen);
19
+ * the structural type below captures exactly what codegen needs. */
20
+ export interface WorkspaceLike {
21
+ getUserBuiltin(name: string): Builtin | undefined;
22
+ }
23
+ export interface RuntimeSnippet {
24
+ /** Standard-library headers parsed out of the source file. */
25
+ headers: ReadonlyArray<string>;
26
+ /** Body of the snippet (definitions only — `#include`s removed). */
27
+ code: string;
28
+ /** Paired JS body, when a `<basename>.js` sibling exists in the
29
+ * runtime directory. Populated by `loadSnippet` from
30
+ * `JS_SNIPPETS[<basename>.js]`. `emitJs` activates and inlines
31
+ * this; if absent, the snippet is C-only (the builtin that owns
32
+ * it has no JS path yet). */
33
+ jsCode?: string;
34
+ /** Other helpers (by name) this snippet depends on. The activator
35
+ * pulls these in first so their definitions come before this
36
+ * snippet's. Cycles are not supported — keep the graph acyclic. */
37
+ deps: ReadonlyArray<string>;
38
+ /** `.h` filename this snippet was loaded from (e.g.
39
+ * `tensor_alloc_nd.h`). Used to build the JS-import dep map at
40
+ * activation time. Optional because user-supplied inline snippets
41
+ * have no on-disk file. */
42
+ srcFilename?: string;
43
+ }
44
+ /**
45
+ * Parse a raw snippet source string into its `headers` and `code` parts.
46
+ *
47
+ * The strict `#include` pattern accepted is:
48
+ * optional-whitespace `#` optional-whitespace `include`
49
+ * whitespace `<header>` or `"header"` optional-trailing-whitespace
50
+ *
51
+ * Any line whose trimmed form starts with `#include` but does NOT match
52
+ * that pattern is rejected.
53
+ */
54
+ export declare function parseSnippetSource(raw: string): {
55
+ headers: string[];
56
+ code: string;
57
+ };
58
+ /** Public re-export for callers that don't have a `RuntimeState` (the
59
+ * build-snippets script). Resolves against the global registry only. */
60
+ export declare function getRuntimeSnippet(name: string): RuntimeSnippet;
61
+ /** Inline snippet definition supplied by a user `.mtoc2.js` builtin's
62
+ * `emitC` / `emitJs` via `useRuntime({...})`. Once registered on a
63
+ * `RuntimeState`, subsequent activations of the same `name` are
64
+ * deduplicated.
65
+ *
66
+ * `code` is the C body (required for `emitC` consumers); `jsCode`
67
+ * is the optional JS body (required for `emitJs` consumers but
68
+ * ignored on the C path). A builtin that supports both backends
69
+ * supplies both; one that only supports C may omit `jsCode`. */
70
+ export interface InlineSnippet {
71
+ name: string;
72
+ code: string;
73
+ jsCode?: string;
74
+ headers?: ReadonlyArray<string>;
75
+ deps?: ReadonlyArray<string>;
76
+ }
77
+ export interface RuntimeState {
78
+ /** Insertion-ordered set of activated snippet names. */
79
+ active: Set<string>;
80
+ /** Counter for `MultiAssignCall` discard-temp suffixes so adjacent
81
+ * multi-output call sites don't collide on `_mtoc2_discard_<N>_<i>`
82
+ * names. Incremented each time a multi-output call is emitted. */
83
+ multiAssignCallCounter: number;
84
+ /** Workspace-scoped snippets registered via the user `useRuntime`
85
+ * callback. Looked up by name alongside the global registry. */
86
+ extraSnippets: Map<string, RuntimeSnippet>;
87
+ /** Workspace reference for resolving names to `.mtoc2.js` user
88
+ * builtins during emit. Undefined for non-workspace-driven codegen
89
+ * (the snippet-build script, vitest unit tests that bypass the
90
+ * workspace). */
91
+ workspace?: WorkspaceLike;
92
+ /** JS-side helper: cName list of the currently-emitting user
93
+ * function's outputs. Set by `emitFunction` before walking the
94
+ * body and cleared after so `ReturnFromFunction` can emit a
95
+ * return matching the function's shape (bare value / array /
96
+ * nothing). Undefined at top level. */
97
+ currentFnOutputs?: ReadonlyArray<string>;
98
+ /** Set when the program contains a scalar indexed STORE, which
99
+ * emits the grow-aware `mtoc2_idx_*_grow` bounds checks. The
100
+ * host-entry function (storage class `""`) then arms a `setjmp`
101
+ * guard so a runtime grow (`v(k) = x`, k past the runtime extent)
102
+ * `longjmp`s back and returns cleanly for a host-side bail to the
103
+ * interpreter, instead of `exit(1)`. Computed by a pre-pass in
104
+ * `emit.ts` so it's set regardless of function emission order. */
105
+ usedGrowBail?: boolean;
106
+ }
107
+ export declare function newRuntimeState(workspace?: WorkspaceLike): RuntimeState;
108
+ /** Look up a `Builtin` for an emit-time call. Consults the workspace's
109
+ * `.mtoc2.js` user builtins first (so a `foo.mtoc2.js` overrides any
110
+ * identically-named built-in for callers in this workspace), then
111
+ * falls back to the global registry. */
112
+ export declare function lookupBuiltin(state: RuntimeState, name: string): Builtin | undefined;
113
+ /** Activate a snippet by its registered name. Pulls its `deps` in first
114
+ * so they appear before it in the final emission order. Also pulls in
115
+ * JS-import deps inferred from the snippet's paired `.js` sibling
116
+ * (built by `scripts/build_runtime_snippets.ts` into `JS_IMPORTS`),
117
+ * so cross-snippet JS calls resolve at runtime even when the C deps
118
+ * field doesn't enumerate them. Idempotent. */
119
+ export declare function useRuntimeByName(state: RuntimeState, name: string): void;
120
+ /** Register-and-activate an inline snippet supplied by a user builtin.
121
+ * First call registers the snippet on the state; subsequent calls
122
+ * (with the same name) are no-ops at the registration step and just
123
+ * re-activate through the global pathway. */
124
+ export declare function useRuntimeInline(state: RuntimeState, snippet: InlineSnippet): void;
125
+ /** Build the `useRuntime` callback passed into a `Builtin.emit` call.
126
+ * Accepts either a name (resolved against the global mtoc2 runtime
127
+ * registry) or an `InlineSnippet` (registered on the current state).
128
+ * Centralized here so every emit call site activates snippets
129
+ * uniformly. */
130
+ export declare function makeEmitUseRuntime(state: RuntimeState): (spec: string | InlineSnippet) => void;
131
+ /** All headers required by the activated snippets, in insertion order. */
132
+ export declare function collectRuntimeHeaders(state: RuntimeState): string[];
133
+ /** Concatenated bodies (definitions) of activated snippets, in
134
+ * activation (dep-respecting) order. */
135
+ export declare function renderRuntimeBodies(state: RuntimeState): string;
136
+ /** JS counterpart of `renderRuntimeBodies` — concatenates the `jsCode`
137
+ * fields of activated snippets, in dependency order, skipping
138
+ * snippets that have no JS body. The result is plain JS source
139
+ * ready to inline at the top of the emitted module so subsequent
140
+ * call-site code can reference helpers by bare name.
141
+ *
142
+ * Symmetric with the C side: the same `state.active` set drives
143
+ * both renderers — a builtin activates `mtoc2_disp_double` once,
144
+ * the C path emits `disp_double.h`'s body, the JS path emits
145
+ * `disp_double.js`'s body. */
146
+ export declare function renderJsRuntimeBodies(state: RuntimeState): string;
147
+ /** Stable always-emitted header set — every translation includes these
148
+ * so the user-level code can rely on stdio/math without each builtin
149
+ * re-declaring them. Kept tiny on purpose. */
150
+ export declare const BASE_HEADERS: ReadonlyArray<string>;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * JIT entry point for sibling consumers (e.g. numbl's executor
3
+ * registry) that want to compile a single user-function
4
+ * specialization on demand instead of running mtoc2 as a whole-program
5
+ * AOT translator.
6
+ *
7
+ * Bypasses the script-level driver (`translate.ts` / `lowerProject`)
8
+ * and produces an emitted JS module that returns a factory
9
+ * `($h) => specFn`. The caller evaluates the source with
10
+ * `new Function(source)()`, invokes the factory once per spec to bind
11
+ * its I/O hooks, then calls `specFn(...args)` per dispatch. Per-call
12
+ * dispatch has no I/O setup cost.
13
+ *
14
+ * The `lowerer` argument is the JIT spec cache: passing the same
15
+ * `Lowerer` instance across calls means `Lowerer.specializations`
16
+ * accumulates compiled IR across the session, so repeated calls to the
17
+ * same `(funcDecl, argTypes, nargout)` triple skip the lowering cost.
18
+ *
19
+ * Caller responsibilities:
20
+ *
21
+ * - **Strip `exact` before calling.** Runtime-observed scalars should
22
+ * arrive as opaque-sign types (`scalarDouble("unknown")`,
23
+ * `tensorDouble(shape)` without exact data) so that `f(1); f(2);
24
+ * f(3)` doesn't shard the spec cache by value. `compileSpec` runs
25
+ * `withoutExact` as a defensive second pass.
26
+ * - **Treat lowering errors as JIT bailouts.** `UnsupportedConstruct`
27
+ * and `TypeError` from the lowerer propagate to the caller as the
28
+ * "decline this JIT proposal" signal — the caller falls back to its
29
+ * interpreter for that dispatch.
30
+ *
31
+ * The emitted module includes every spec currently in
32
+ * `lowerer.specializations` (not just the entry spec), because the
33
+ * entry spec's body references its transitively-called specs by their
34
+ * mangled cNames. Dead specs from prior compileSpec calls are bounded
35
+ * by `MTOC2_MAX_SPECS_PER_FUNCTION` and don't affect correctness; if
36
+ * profiling shows the re-emit cost dominates, a future change can do
37
+ * a reachability walk over the entry's IR body.
38
+ */
39
+ import type { Stmt } from "./parser/index.js";
40
+ import type { Lowerer } from "./lowering/lower.js";
41
+ import type { Workspace } from "./workspace/workspace.js";
42
+ import { type Type } from "./lowering/types.js";
43
+ type FuncStmt = Extract<Stmt, {
44
+ type: "Function";
45
+ }>;
46
+ export interface CompileSpecArgs {
47
+ /** Workspace whose files are pre-registered. Safe to share across
48
+ * many `compileSpec` calls — `Workspace.finalize()` is idempotent
49
+ * and nothing in the workspace mutates during lowering. */
50
+ workspace: Workspace;
51
+ /** Lowerer whose `.specializations` map persists across calls. Pass
52
+ * the same instance throughout the JIT session so cached lowerings
53
+ * are reused. */
54
+ lowerer: Lowerer;
55
+ /** The function AST to specialize. Caller fetches via
56
+ * `workspace.ctx.fileASTCache` or `workspace.resolve(...)`. */
57
+ funcDecl: FuncStmt;
58
+ /** Argument types for this specialization. Caller should already
59
+ * have stripped `exact`; `compileSpec` runs `withoutExact` again
60
+ * defensively. */
61
+ argTypes: Type[];
62
+ /** Number of outputs the call site requests. Salts the spec key. */
63
+ nargout: number;
64
+ }
65
+ export interface CompileSpecResult {
66
+ /** Mangled spec name (the IRFunc cName). Useful for caller-side
67
+ * cache keys and tracing. */
68
+ cName: string;
69
+ /** Full module source. Use:
70
+ *
71
+ * ```ts
72
+ * const factory = new Function(source)();
73
+ * const specFn = factory({ write: (s) => ... });
74
+ * const out = specFn(...args);
75
+ * ```
76
+ *
77
+ * `$h.write` must be a synchronous string sink that consumes
78
+ * `disp` / `fprintf` output. */
79
+ source: string;
80
+ /** Names of runtime snippets activated by emit. Diagnostic only. */
81
+ activatedSnippets: ReadonlyArray<string>;
82
+ }
83
+ export declare function compileSpec(args: CompileSpecArgs): CompileSpecResult;
84
+ export {};