numbl 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/README.md +1 -1
  2. package/dist-cli/cli.js +7277 -3344
  3. package/dist-lib/graphics/types.d.ts +262 -0
  4. package/dist-lib/lib.d.ts +19 -0
  5. package/dist-lib/lib.js +53709 -0
  6. package/dist-lib/numbl-core/diagnostics/errors.d.ts +8 -0
  7. package/dist-lib/numbl-core/diagnostics/index.d.ts +27 -0
  8. package/dist-lib/numbl-core/executeCode.d.ts +70 -0
  9. package/dist-lib/numbl-core/externalAccessDirective.d.ts +6 -0
  10. package/dist-lib/numbl-core/fileIOAdapter.d.ts +61 -0
  11. package/dist-lib/numbl-core/functionResolve.d.ts +59 -0
  12. package/dist-lib/numbl-core/helpers/arithmetic.d.ts +47 -0
  13. package/dist-lib/numbl-core/helpers/bessel.d.ts +40 -0
  14. package/dist-lib/numbl-core/helpers/check-helpers.d.ts +50 -0
  15. package/dist-lib/numbl-core/helpers/constants.d.ts +6 -0
  16. package/dist-lib/numbl-core/helpers/dummy.d.ts +5 -0
  17. package/dist-lib/numbl-core/helpers/erf.d.ts +5 -0
  18. package/dist-lib/numbl-core/helpers/linsolve.d.ts +26 -0
  19. package/dist-lib/numbl-core/helpers/ode-rk.d.ts +83 -0
  20. package/dist-lib/numbl-core/helpers/prng.d.ts +17 -0
  21. package/dist-lib/numbl-core/helpers/reduction/cumulative.d.ts +8 -0
  22. package/dist-lib/numbl-core/helpers/reduction/min-max.d.ts +5 -0
  23. package/dist-lib/numbl-core/helpers/reduction-helpers.d.ts +58 -0
  24. package/dist-lib/numbl-core/helpers/registry.d.ts +7 -0
  25. package/dist-lib/numbl-core/helpers/shape-utils.d.ts +7 -0
  26. package/dist-lib/numbl-core/helpers/sparse-arithmetic.d.ts +16 -0
  27. package/dist-lib/numbl-core/helpers/string.d.ts +5 -0
  28. package/dist-lib/numbl-core/interpreter/builtins/arithmetic.d.ts +4 -0
  29. package/dist-lib/numbl-core/interpreter/builtins/array-construction.d.ts +4 -0
  30. package/dist-lib/numbl-core/interpreter/builtins/array-extras.d.ts +5 -0
  31. package/dist-lib/numbl-core/interpreter/builtins/array-manipulation.d.ts +7 -0
  32. package/dist-lib/numbl-core/interpreter/builtins/cell-struct.d.ts +5 -0
  33. package/dist-lib/numbl-core/interpreter/builtins/complex.d.ts +4 -0
  34. package/dist-lib/numbl-core/interpreter/builtins/dictionary.d.ts +15 -0
  35. package/dist-lib/numbl-core/interpreter/builtins/fft.d.ts +7 -0
  36. package/dist-lib/numbl-core/interpreter/builtins/help-text.d.ts +5 -0
  37. package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +34 -0
  38. package/dist-lib/numbl-core/interpreter/builtins/introspection.d.ts +6 -0
  39. package/dist-lib/numbl-core/interpreter/builtins/linear-algebra.d.ts +9 -0
  40. package/dist-lib/numbl-core/interpreter/builtins/math.d.ts +4 -0
  41. package/dist-lib/numbl-core/interpreter/builtins/misc.d.ts +4 -0
  42. package/dist-lib/numbl-core/interpreter/builtins/numerical.d.ts +10 -0
  43. package/dist-lib/numbl-core/interpreter/builtins/predicates.d.ts +4 -0
  44. package/dist-lib/numbl-core/interpreter/builtins/prng.d.ts +4 -0
  45. package/dist-lib/numbl-core/interpreter/builtins/reductions.d.ts +6 -0
  46. package/dist-lib/numbl-core/interpreter/builtins/set-operations.d.ts +4 -0
  47. package/dist-lib/numbl-core/interpreter/builtins/sparse.d.ts +4 -0
  48. package/dist-lib/numbl-core/interpreter/builtins/special-math.d.ts +4 -0
  49. package/dist-lib/numbl-core/interpreter/builtins/string-extras.d.ts +5 -0
  50. package/dist-lib/numbl-core/interpreter/builtins/strings.d.ts +7 -0
  51. package/dist-lib/numbl-core/interpreter/builtins/time-system.d.ts +5 -0
  52. package/dist-lib/numbl-core/interpreter/builtins/type-constructors.d.ts +5 -0
  53. package/dist-lib/numbl-core/interpreter/builtins/types.d.ts +109 -0
  54. package/dist-lib/numbl-core/interpreter/builtins/utility.d.ts +4 -0
  55. package/dist-lib/numbl-core/interpreter/builtins/validation.d.ts +4 -0
  56. package/dist-lib/numbl-core/interpreter/interpreter.d.ts +146 -0
  57. package/dist-lib/numbl-core/interpreter/interpreterExec.d.ts +51 -0
  58. package/dist-lib/numbl-core/interpreter/interpreterFunctions.d.ts +41 -0
  59. package/dist-lib/numbl-core/interpreter/interpreterSpecialBuiltins.d.ts +18 -0
  60. package/dist-lib/numbl-core/interpreter/jit/index.d.ts +7 -0
  61. package/dist-lib/numbl-core/interpreter/jit/jitCodegen.d.ts +5 -0
  62. package/dist-lib/numbl-core/interpreter/jit/jitHelpers.d.ts +5 -0
  63. package/dist-lib/numbl-core/interpreter/jit/jitLoop.d.ts +25 -0
  64. package/dist-lib/numbl-core/interpreter/jit/jitLoopAnalysis.d.ts +25 -0
  65. package/dist-lib/numbl-core/interpreter/jit/jitLower.d.ts +20 -0
  66. package/dist-lib/numbl-core/interpreter/jit/jitTypes.d.ts +168 -0
  67. package/dist-lib/numbl-core/interpreter/types.d.ts +77 -0
  68. package/dist-lib/numbl-core/jsUserFunctions.d.ts +25 -0
  69. package/dist-lib/numbl-core/lexer/helpers.d.ts +15 -0
  70. package/dist-lib/numbl-core/lexer/index.d.ts +4 -0
  71. package/dist-lib/numbl-core/lexer/keywords.d.ts +3 -0
  72. package/dist-lib/numbl-core/lexer/token-config.d.ts +94 -0
  73. package/dist-lib/numbl-core/lexer/tokenizer.d.ts +9 -0
  74. package/dist-lib/numbl-core/lexer/types.d.ts +78 -0
  75. package/dist-lib/numbl-core/lowering/classInfo.d.ts +36 -0
  76. package/dist-lib/numbl-core/lowering/constants.d.ts +4 -0
  77. package/dist-lib/numbl-core/lowering/errors.d.ts +17 -0
  78. package/dist-lib/numbl-core/lowering/index.d.ts +3 -0
  79. package/dist-lib/numbl-core/lowering/itemTypes.d.ts +87 -0
  80. package/dist-lib/numbl-core/lowering/loweringContext.d.ts +206 -0
  81. package/dist-lib/numbl-core/native/bridge-resolve.d.ts +14 -0
  82. package/dist-lib/numbl-core/native/lapack-bridge.d.ts +387 -0
  83. package/dist-lib/numbl-core/native/ts-lapack-bridge.d.ts +9 -0
  84. package/dist-lib/numbl-core/parser/ArgumentsParser.d.ts +28 -0
  85. package/dist-lib/numbl-core/parser/ClassParser.d.ts +18 -0
  86. package/dist-lib/numbl-core/parser/CommandParser.d.ts +31 -0
  87. package/dist-lib/numbl-core/parser/ControlFlowParser.d.ts +16 -0
  88. package/dist-lib/numbl-core/parser/ExpressionParser.d.ts +32 -0
  89. package/dist-lib/numbl-core/parser/FunctionParser.d.ts +10 -0
  90. package/dist-lib/numbl-core/parser/Parser.d.ts +17 -0
  91. package/dist-lib/numbl-core/parser/ParserBase.d.ts +35 -0
  92. package/dist-lib/numbl-core/parser/StatementParser.d.ts +13 -0
  93. package/dist-lib/numbl-core/parser/errors.d.ts +15 -0
  94. package/dist-lib/numbl-core/parser/index.d.ts +7 -0
  95. package/dist-lib/numbl-core/parser/types.d.ts +316 -0
  96. package/dist-lib/numbl-core/runtime/compare.d.ts +5 -0
  97. package/dist-lib/numbl-core/runtime/constructors.d.ts +35 -0
  98. package/dist-lib/numbl-core/runtime/convert.d.ts +10 -0
  99. package/dist-lib/numbl-core/runtime/display.d.ts +6 -0
  100. package/dist-lib/numbl-core/runtime/error.d.ts +73 -0
  101. package/dist-lib/numbl-core/runtime/index.d.ts +12 -0
  102. package/dist-lib/numbl-core/runtime/indexing.d.ts +10 -0
  103. package/dist-lib/numbl-core/runtime/plotUtils.d.ts +215 -0
  104. package/dist-lib/numbl-core/runtime/runtime.d.ts +314 -0
  105. package/dist-lib/numbl-core/runtime/runtimeDispatch.d.ts +27 -0
  106. package/dist-lib/numbl-core/runtime/runtimeHelpers.d.ts +31 -0
  107. package/dist-lib/numbl-core/runtime/runtimeIndexing.d.ts +28 -0
  108. package/dist-lib/numbl-core/runtime/runtimeMemberAccess.d.ts +26 -0
  109. package/dist-lib/numbl-core/runtime/runtimeOperators.d.ts +24 -0
  110. package/dist-lib/numbl-core/runtime/runtimePlot.d.ts +99 -0
  111. package/dist-lib/numbl-core/runtime/sentinels.d.ts +4 -0
  112. package/dist-lib/numbl-core/runtime/specialBuiltinNames.d.ts +2 -0
  113. package/dist-lib/numbl-core/runtime/specialBuiltins.d.ts +13 -0
  114. package/dist-lib/numbl-core/runtime/struct-access.d.ts +6 -0
  115. package/dist-lib/numbl-core/runtime/syncChannel.d.ts +1 -0
  116. package/dist-lib/numbl-core/runtime/tensor-construction.d.ts +10 -0
  117. package/dist-lib/numbl-core/runtime/types.d.ts +110 -0
  118. package/dist-lib/numbl-core/runtime/utils.d.ts +20 -0
  119. package/dist-lib/numbl-core/stdlib-bundle.d.ts +3 -0
  120. package/dist-lib/numbl-core/systemAdapter.d.ts +23 -0
  121. package/dist-lib/numbl-core/version.d.ts +2 -0
  122. package/dist-lib/numbl-core/workspace/index.d.ts +4 -0
  123. package/dist-lib/numbl-core/workspace/types.d.ts +16 -0
  124. package/dist-lib/ts-lapack/src/BLAS/daxpy.d.ts +1 -0
  125. package/dist-lib/ts-lapack/src/BLAS/dcopy.d.ts +1 -0
  126. package/dist-lib/ts-lapack/src/BLAS/ddot.d.ts +1 -0
  127. package/dist-lib/ts-lapack/src/BLAS/dgemm.d.ts +1 -0
  128. package/dist-lib/ts-lapack/src/BLAS/dgemm_optimized.d.ts +1 -0
  129. package/dist-lib/ts-lapack/src/BLAS/dgemv.d.ts +1 -0
  130. package/dist-lib/ts-lapack/src/BLAS/dger.d.ts +1 -0
  131. package/dist-lib/ts-lapack/src/BLAS/dnrm2.d.ts +1 -0
  132. package/dist-lib/ts-lapack/src/BLAS/drot.d.ts +1 -0
  133. package/dist-lib/ts-lapack/src/BLAS/dscal.d.ts +1 -0
  134. package/dist-lib/ts-lapack/src/BLAS/dswap.d.ts +1 -0
  135. package/dist-lib/ts-lapack/src/BLAS/dtrmm.d.ts +1 -0
  136. package/dist-lib/ts-lapack/src/BLAS/dtrmv.d.ts +1 -0
  137. package/dist-lib/ts-lapack/src/BLAS/dtrsm.d.ts +1 -0
  138. package/dist-lib/ts-lapack/src/BLAS/idamax.d.ts +1 -0
  139. package/dist-lib/ts-lapack/src/SRC/dbdsqr.d.ts +10 -0
  140. package/dist-lib/ts-lapack/src/SRC/dgebak.d.ts +1 -0
  141. package/dist-lib/ts-lapack/src/SRC/dgebal.d.ts +5 -0
  142. package/dist-lib/ts-lapack/src/SRC/dgebd2.d.ts +1 -0
  143. package/dist-lib/ts-lapack/src/SRC/dgebrd.d.ts +1 -0
  144. package/dist-lib/ts-lapack/src/SRC/dgeev.d.ts +3 -0
  145. package/dist-lib/ts-lapack/src/SRC/dgehd2.d.ts +1 -0
  146. package/dist-lib/ts-lapack/src/SRC/dgehrd.d.ts +1 -0
  147. package/dist-lib/ts-lapack/src/SRC/dgelq2.d.ts +1 -0
  148. package/dist-lib/ts-lapack/src/SRC/dgelqf.d.ts +1 -0
  149. package/dist-lib/ts-lapack/src/SRC/dgeqr2.d.ts +1 -0
  150. package/dist-lib/ts-lapack/src/SRC/dgeqrf.d.ts +1 -0
  151. package/dist-lib/ts-lapack/src/SRC/dgeqrf_optimized.d.ts +1 -0
  152. package/dist-lib/ts-lapack/src/SRC/dgesvd.d.ts +28 -0
  153. package/dist-lib/ts-lapack/src/SRC/dgetrf.d.ts +1 -0
  154. package/dist-lib/ts-lapack/src/SRC/dgetrf2.d.ts +1 -0
  155. package/dist-lib/ts-lapack/src/SRC/dgetri.d.ts +1 -0
  156. package/dist-lib/ts-lapack/src/SRC/dhseqr.d.ts +32 -0
  157. package/dist-lib/ts-lapack/src/SRC/dlabrd.d.ts +1 -0
  158. package/dist-lib/ts-lapack/src/SRC/dlacpy.d.ts +18 -0
  159. package/dist-lib/ts-lapack/src/SRC/dladiv.d.ts +9 -0
  160. package/dist-lib/ts-lapack/src/SRC/dlaexc.d.ts +21 -0
  161. package/dist-lib/ts-lapack/src/SRC/dlahqr.d.ts +24 -0
  162. package/dist-lib/ts-lapack/src/SRC/dlahr2.d.ts +1 -0
  163. package/dist-lib/ts-lapack/src/SRC/dlaln2.d.ts +5 -0
  164. package/dist-lib/ts-lapack/src/SRC/dlamch.d.ts +1 -0
  165. package/dist-lib/ts-lapack/src/SRC/dlange.d.ts +1 -0
  166. package/dist-lib/ts-lapack/src/SRC/dlanv2.d.ts +12 -0
  167. package/dist-lib/ts-lapack/src/SRC/dlapy2.d.ts +1 -0
  168. package/dist-lib/ts-lapack/src/SRC/dlaqr1.d.ts +1 -0
  169. package/dist-lib/ts-lapack/src/SRC/dlaqr30.d.ts +81 -0
  170. package/dist-lib/ts-lapack/src/SRC/dlaqr5.d.ts +38 -0
  171. package/dist-lib/ts-lapack/src/SRC/dlarf.d.ts +18 -0
  172. package/dist-lib/ts-lapack/src/SRC/dlarf1f.d.ts +1 -0
  173. package/dist-lib/ts-lapack/src/SRC/dlarfb.d.ts +25 -0
  174. package/dist-lib/ts-lapack/src/SRC/dlarfg.d.ts +4 -0
  175. package/dist-lib/ts-lapack/src/SRC/dlarft.d.ts +20 -0
  176. package/dist-lib/ts-lapack/src/SRC/dlarfx.d.ts +17 -0
  177. package/dist-lib/ts-lapack/src/SRC/dlartg.d.ts +5 -0
  178. package/dist-lib/ts-lapack/src/SRC/dlas2.d.ts +4 -0
  179. package/dist-lib/ts-lapack/src/SRC/dlascl.d.ts +1 -0
  180. package/dist-lib/ts-lapack/src/SRC/dlaset.d.ts +19 -0
  181. package/dist-lib/ts-lapack/src/SRC/dlasr.d.ts +1 -0
  182. package/dist-lib/ts-lapack/src/SRC/dlassq.d.ts +18 -0
  183. package/dist-lib/ts-lapack/src/SRC/dlasv2.d.ts +8 -0
  184. package/dist-lib/ts-lapack/src/SRC/dlaswp.d.ts +1 -0
  185. package/dist-lib/ts-lapack/src/SRC/dlasy2.d.ts +5 -0
  186. package/dist-lib/ts-lapack/src/SRC/dorg2r.d.ts +1 -0
  187. package/dist-lib/ts-lapack/src/SRC/dorgbr.d.ts +1 -0
  188. package/dist-lib/ts-lapack/src/SRC/dorghr.d.ts +1 -0
  189. package/dist-lib/ts-lapack/src/SRC/dorgl2.d.ts +1 -0
  190. package/dist-lib/ts-lapack/src/SRC/dorglq.d.ts +1 -0
  191. package/dist-lib/ts-lapack/src/SRC/dorgqr.d.ts +1 -0
  192. package/dist-lib/ts-lapack/src/SRC/dorgqr_optimized.d.ts +1 -0
  193. package/dist-lib/ts-lapack/src/SRC/dorm2r.d.ts +1 -0
  194. package/dist-lib/ts-lapack/src/SRC/dormhr.d.ts +1 -0
  195. package/dist-lib/ts-lapack/src/SRC/dormqr.d.ts +1 -0
  196. package/dist-lib/ts-lapack/src/SRC/dpotf2.d.ts +1 -0
  197. package/dist-lib/ts-lapack/src/SRC/dtrevc3.d.ts +27 -0
  198. package/dist-lib/ts-lapack/src/SRC/dtrexc.d.ts +24 -0
  199. package/dist-lib/ts-lapack/src/SRC/dtrti2.d.ts +1 -0
  200. package/dist-lib/ts-lapack/src/SRC/dtrtri.d.ts +1 -0
  201. package/dist-lib/ts-lapack/src/utils/constants.d.ts +28 -0
  202. package/dist-lib/ts-lapack/src/utils/iladlc.d.ts +1 -0
  203. package/dist-lib/ts-lapack/src/utils/iladlr.d.ts +1 -0
  204. package/dist-lib/ts-lapack/src/utils/ilaenv.d.ts +1 -0
  205. package/dist-lib/ts-lapack/src/utils/xerbla.d.ts +1 -0
  206. package/dist-plot-viewer/assets/index-BjKyNJgj.js +4426 -0
  207. package/dist-plot-viewer/index.html +1 -1
  208. package/package.json +12 -2
  209. package/dist-plot-viewer/assets/index-BMYdzDaW.js +0 -4426
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Static AST analysis to determine input/output variables for loop JIT.
3
+ *
4
+ * Walks the loop body (and condition for while) to collect:
5
+ * - assigned: variables written inside the loop
6
+ * - referenced: variables read inside the loop
7
+ * - hasReturn: whether the loop body contains a return statement
8
+ */
9
+ import type { Stmt } from "../../parser/types.js";
10
+ export interface LoopVarInfo {
11
+ /** Variables referenced in the loop that must come from enclosing scope */
12
+ inputs: string[];
13
+ /** Variables assigned in the loop body (written back after JIT execution) */
14
+ outputs: string[];
15
+ /** Whether the loop body contains a return statement (skip JIT if true) */
16
+ hasReturn: boolean;
17
+ }
18
+ /** Analyze a for loop statement for JIT compilation. */
19
+ export declare function analyzeForLoop(stmt: Stmt & {
20
+ type: "For";
21
+ }): LoopVarInfo;
22
+ /** Analyze a while loop statement for JIT compilation. */
23
+ export declare function analyzeWhileLoop(stmt: Stmt & {
24
+ type: "While";
25
+ }): LoopVarInfo;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * AST -> JIT IR lowering with type propagation.
3
+ *
4
+ * Returns null if any unsupported construct is encountered,
5
+ * causing the entire function to fall back to interpretation.
6
+ */
7
+ import type { FunctionDef } from "../types.js";
8
+ import type { Interpreter } from "../interpreter.js";
9
+ import { type JitType, type JitStmt } from "./jitTypes.js";
10
+ export interface LoweringResult {
11
+ body: JitStmt[];
12
+ outputNames: string[];
13
+ localVars: Set<string>;
14
+ hasTensorOps: boolean;
15
+ /** Generated JS code for called user functions: jitName → code */
16
+ generatedFns: Map<string, string>;
17
+ /** Type of the first output variable after lowering */
18
+ outputType: JitType | null;
19
+ }
20
+ export declare function lowerFunction(fn: FunctionDef, argTypes: JitType[], nargout: number, interp?: Interpreter, generatedFns?: Map<string, string>, loweringInProgress?: Set<string>): LoweringResult | null;
@@ -0,0 +1,168 @@
1
+ /**
2
+ * JIT type system and IR node definitions.
3
+ */
4
+ import type { BinaryOperation, UnaryOperation } from "../../parser/types.js";
5
+ export type SignCategory = "positive" | "nonneg" | "nonpositive" | "negative";
6
+ export type JitType = {
7
+ kind: "number";
8
+ exact?: number;
9
+ sign?: SignCategory;
10
+ } | {
11
+ kind: "boolean";
12
+ value?: boolean;
13
+ } | {
14
+ kind: "complex_or_number";
15
+ pureImaginary?: boolean;
16
+ } | {
17
+ kind: "tensor";
18
+ isComplex: boolean;
19
+ shape?: number[];
20
+ ndim?: number;
21
+ isLogical?: boolean;
22
+ nonneg?: boolean;
23
+ } | {
24
+ kind: "string";
25
+ value?: string;
26
+ } | {
27
+ kind: "char";
28
+ value?: string;
29
+ } | {
30
+ kind: "struct";
31
+ fields?: Record<string, JitType>;
32
+ } | {
33
+ kind: "class_instance";
34
+ className: string;
35
+ isHandleClass?: boolean;
36
+ fields?: Record<string, JitType>;
37
+ } | {
38
+ kind: "sparse_matrix";
39
+ isComplex: boolean;
40
+ m?: number;
41
+ n?: number;
42
+ } | {
43
+ kind: "cell";
44
+ shape?: number[];
45
+ } | {
46
+ kind: "dictionary";
47
+ } | {
48
+ kind: "unknown";
49
+ };
50
+ export declare function signFromNumber(v: number): SignCategory | undefined;
51
+ export declare function isNonneg(t: JitType): boolean;
52
+ export declare function flipSign(s?: SignCategory): SignCategory | undefined;
53
+ export declare function unifySign(a?: SignCategory, b?: SignCategory): SignCategory | undefined;
54
+ export declare function jitTypeKey(t: JitType): string;
55
+ export declare function computeJitCacheKey(nargout: number, argTypes: JitType[]): string;
56
+ /** Compute a unique JS function name for a JIT'd specialization. */
57
+ export declare function computeJitFnName(identity: string, funcName: string): string;
58
+ /** Widen/unify two types at control-flow join points. */
59
+ export declare function unifyJitTypes(a: JitType, b: JitType): JitType;
60
+ export declare function isScalarType(t: JitType): boolean;
61
+ export declare function isNumericScalarType(t: JitType): boolean;
62
+ export declare function isTensorType(t: JitType): boolean;
63
+ export declare function isComplexType(t: JitType): boolean;
64
+ /** Types that support arithmetic binary operations in the JIT. */
65
+ export declare function isArithmeticType(t: JitType): boolean;
66
+ export declare function shapeAfterReduction(shape: number[], dim?: number): {
67
+ scalar: true;
68
+ } | {
69
+ scalar: false;
70
+ shape: number[];
71
+ };
72
+ export type JitExpr = {
73
+ tag: "NumberLiteral";
74
+ value: number;
75
+ jitType: JitType;
76
+ } | {
77
+ tag: "ImagLiteral";
78
+ jitType: JitType;
79
+ } | {
80
+ tag: "Var";
81
+ name: string;
82
+ jitType: JitType;
83
+ } | {
84
+ tag: "Binary";
85
+ op: BinaryOperation;
86
+ left: JitExpr;
87
+ right: JitExpr;
88
+ jitType: JitType;
89
+ } | {
90
+ tag: "Unary";
91
+ op: UnaryOperation;
92
+ operand: JitExpr;
93
+ jitType: JitType;
94
+ } | {
95
+ tag: "StringLiteral";
96
+ value: string;
97
+ isChar: boolean;
98
+ jitType: JitType;
99
+ } | {
100
+ tag: "Call";
101
+ name: string;
102
+ args: JitExpr[];
103
+ jitType: JitType;
104
+ } | {
105
+ tag: "UserCall";
106
+ jitName: string;
107
+ name: string;
108
+ args: JitExpr[];
109
+ jitType: JitType;
110
+ } | {
111
+ tag: "Index";
112
+ base: JitExpr;
113
+ indices: JitExpr[];
114
+ jitType: JitType;
115
+ } | {
116
+ tag: "TensorLiteral";
117
+ rows: JitExpr[][];
118
+ nRows: number;
119
+ nCols: number;
120
+ jitType: JitType;
121
+ };
122
+ export type JitStmt = {
123
+ tag: "Assign";
124
+ name: string;
125
+ expr: JitExpr;
126
+ } | {
127
+ tag: "If";
128
+ cond: JitExpr;
129
+ thenBody: JitStmt[];
130
+ elseifBlocks: {
131
+ cond: JitExpr;
132
+ body: JitStmt[];
133
+ }[];
134
+ elseBody: JitStmt[] | null;
135
+ } | {
136
+ tag: "For";
137
+ varName: string;
138
+ start: JitExpr;
139
+ step: JitExpr | null;
140
+ end: JitExpr;
141
+ body: JitStmt[];
142
+ } | {
143
+ tag: "While";
144
+ cond: JitExpr;
145
+ body: JitStmt[];
146
+ } | {
147
+ tag: "Break";
148
+ } | {
149
+ tag: "Continue";
150
+ } | {
151
+ tag: "Return";
152
+ } | {
153
+ tag: "ExprStmt";
154
+ expr: JitExpr;
155
+ } | {
156
+ tag: "MultiAssign";
157
+ names: (string | null)[];
158
+ callName: string;
159
+ args: JitExpr[];
160
+ outputTypes: JitType[];
161
+ } | {
162
+ tag: "SetLoc";
163
+ line: number;
164
+ };
165
+ export interface JitCacheEntry {
166
+ fn: (...args: unknown[]) => unknown;
167
+ source: string;
168
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Shared types for the interpreter: Environment, control flow signals, FunctionDef.
3
+ */
4
+ import type { Stmt, ArgumentsBlock } from "../parser/types.js";
5
+ import type { Runtime } from "../runtime/runtime.js";
6
+ import type { RuntimeValue } from "../runtime/types.js";
7
+ import type { JitType } from "./jit/jitTypes.js";
8
+ export declare class BreakSignal {
9
+ readonly _tag = "break";
10
+ }
11
+ export declare class ContinueSignal {
12
+ readonly _tag = "continue";
13
+ }
14
+ export declare class ReturnSignal {
15
+ values: RuntimeValue[];
16
+ readonly _tag = "return";
17
+ constructor(values: RuntimeValue[]);
18
+ }
19
+ export type ControlSignal = BreakSignal | ContinueSignal | ReturnSignal;
20
+ export declare class Environment {
21
+ private parent?;
22
+ private vars;
23
+ /** When true, writes to variables found in parent go to the parent (nested function semantics). */
24
+ isNested: boolean;
25
+ /** Nested function definitions registered during execution. */
26
+ nestedFunctions: Map<string, {
27
+ fn: FunctionDef;
28
+ env: Environment;
29
+ }>;
30
+ /** Names declared as `global` in this scope — reads/writes go through rt.$g */
31
+ globalNames: Set<string>;
32
+ /** Names declared as `persistent` in this scope */
33
+ persistentNames: Set<string>;
34
+ /** Function ID for persistent variable storage */
35
+ persistentFuncId: string | undefined;
36
+ /** Back-reference to the runtime (needed for global/persistent access) */
37
+ rt: Runtime | null;
38
+ constructor(parent?: Environment | undefined);
39
+ get(name: string): RuntimeValue | undefined;
40
+ /** Set variable — for nested scopes, writes to parent if variable exists there. */
41
+ set(name: string, value: RuntimeValue): void;
42
+ /** Always writes to this scope (for parameter binding). */
43
+ setLocal(name: string, value: RuntimeValue): void;
44
+ has(name: string): boolean;
45
+ /** Check if this scope directly owns a variable (not parent). */
46
+ hasLocal(name: string): boolean;
47
+ /** Find the environment that owns a variable. */
48
+ private findOwner;
49
+ /** Look up a nested function definition in this scope or parent scopes. */
50
+ getNestedFunction(name: string): {
51
+ fn: FunctionDef;
52
+ env: Environment;
53
+ } | undefined;
54
+ localNames(): string[];
55
+ /** Create a snapshot of this environment (copies all variables by value).
56
+ * Used for anonymous functions which capture values at definition time. */
57
+ snapshot(): Environment;
58
+ toRecord(): Record<string, RuntimeValue>;
59
+ }
60
+ export interface FunctionDef {
61
+ name: string;
62
+ params: string[];
63
+ outputs: string[];
64
+ body: Stmt[];
65
+ argumentsBlocks?: ArgumentsBlock[];
66
+ /** JIT compilation cache: maps signature key -> compiled entry or null (failed). */
67
+ _jitCache?: Map<string, {
68
+ fn: (...args: unknown[]) => unknown;
69
+ source: string;
70
+ } | null>;
71
+ /** Progressive type widening: last unified arg types, keyed by nargout. */
72
+ _lastJitArgTypes?: Map<number, JitType[]>;
73
+ }
74
+ /** Create a FunctionDef from an AST Function statement. */
75
+ export declare function funcDefFromStmt(stmt: Stmt & {
76
+ type: "Function";
77
+ }): FunctionDef;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Loader for .js user functions.
3
+ *
4
+ * Evaluates .js files that define IBuiltins via register({ resolve, jitEmit? }).
5
+ * Supports optional WASM and native shared library bindings via directives:
6
+ * // wasm: <name>
7
+ * // native: <name>
8
+ */
9
+ import type { WorkspaceFile, NativeBridge } from "./workspace/index.js";
10
+ import type { IBuiltin } from "./interpreter/builtins/types.js";
11
+ /**
12
+ * Load .js user function files and return them as IBuiltin objects.
13
+ *
14
+ * Each .js file calls register({ resolve, jitEmit? }) to define an IBuiltin.
15
+ * resolve(argTypes, nargout) returns { outputTypes, apply } or null.
16
+ *
17
+ * A .js file can specify bindings via directives at the top of the file:
18
+ * // wasm: <name> — load a WASM module (looked up by name in wasmFiles)
19
+ * // native: <name> — load a native shared library (resolved relative to .js file)
20
+ *
21
+ * Files whose basename starts with `_` are library files. They must not call
22
+ * register() and instead export values via `return`. Other .js files can import
23
+ * them with `importJS("_name")`.
24
+ */
25
+ export declare function loadJsUserFunctions(jsFiles: WorkspaceFile[], wasmFiles?: WorkspaceFile[], nativeBridge?: NativeBridge): IBuiltin[];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Helper functions for the lexer.
3
+ */
4
+ import { Token } from "./types.js";
5
+ export declare function isAlpha(ch: string): boolean;
6
+ export declare function isAlnum(ch: string): boolean;
7
+ export declare function isDigit(ch: string): boolean;
8
+ export declare function isWhitespace(ch: string): boolean;
9
+ /** Check if a token represents a "value" for transpose disambiguation. */
10
+ export declare function isValueToken(tok: Token): boolean;
11
+ /**
12
+ * Find the first line terminator (\n or \r\n or \r) in `s`.
13
+ * Returns [index, length] or undefined.
14
+ */
15
+ export declare function findLineTerminator(s: string, offset?: number): [number, number] | undefined;
@@ -0,0 +1,4 @@
1
+ export { Token } from "./types.js";
2
+ export { KEYWORDS, VALUE_KEYWORDS } from "./keywords.js";
3
+ export { isAlpha, isAlnum, isDigit, isWhitespace, isValueToken, findLineTerminator, } from "./helpers.js";
4
+ export { tokenize, tokenizeDetailed } from "./tokenizer.js";
@@ -0,0 +1,3 @@
1
+ import { Token } from "./types.js";
2
+ export declare const KEYWORDS: ReadonlyMap<string, Token>;
3
+ export declare const VALUE_KEYWORDS: ReadonlySet<Token>;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Token configuration types and loader.
3
+ */
4
+ import { Token } from "./types.js";
5
+ export interface OperatorConfig {
6
+ pattern: string;
7
+ token: string;
8
+ special?: string;
9
+ }
10
+ export interface BlockCommentConfig {
11
+ start: string;
12
+ end: string;
13
+ consumeTrailingNewline?: boolean;
14
+ }
15
+ export interface SectionMarkerConfig {
16
+ pattern: string;
17
+ requireLineStart: boolean;
18
+ token: string;
19
+ consumeToEOL: boolean;
20
+ consumeTrailingNewline?: boolean;
21
+ fallbackToLineComment?: boolean;
22
+ }
23
+ export interface LineCommentConfig {
24
+ start: string;
25
+ }
26
+ export interface CommentsConfig {
27
+ blockComment: BlockCommentConfig;
28
+ sectionMarker: SectionMarkerConfig;
29
+ lineComment: LineCommentConfig;
30
+ }
31
+ export interface StringDisambiguation {
32
+ type: "transpose";
33
+ transposeToken: string;
34
+ conditions: {
35
+ requireAdjacency: boolean;
36
+ requirePrevValueOrDot: boolean;
37
+ };
38
+ }
39
+ export interface StringConfig {
40
+ delimiter: string;
41
+ escape: string;
42
+ token: string;
43
+ allowMultiline: boolean;
44
+ disambiguation?: StringDisambiguation;
45
+ }
46
+ export interface SpecialPatternConfig {
47
+ pattern: string;
48
+ token: string;
49
+ consumeToEOL?: boolean;
50
+ consumeTrailingNewline?: boolean;
51
+ coalesceMultiple?: boolean;
52
+ setsLineStart?: boolean;
53
+ }
54
+ export interface NumbersConfig {
55
+ allowUnderscores: boolean;
56
+ stripUnderscores: boolean;
57
+ integerToken: string;
58
+ floatToken: string;
59
+ exponentChars: string[];
60
+ decimalPoint: string;
61
+ dotOperatorPrefixes: string[];
62
+ }
63
+ export interface IdentifiersConfig {
64
+ token: string;
65
+ startChars: "alpha";
66
+ continueChars: "alnum";
67
+ }
68
+ export interface TokenConfig {
69
+ operators: {
70
+ twoChar: OperatorConfig[];
71
+ singleChar: OperatorConfig[];
72
+ };
73
+ comments: CommentsConfig;
74
+ strings: StringConfig[];
75
+ special: {
76
+ ellipsis: SpecialPatternConfig;
77
+ newline: SpecialPatternConfig;
78
+ };
79
+ numbers: NumbersConfig;
80
+ identifiers: IdentifiersConfig;
81
+ }
82
+ export declare const TOKEN_CONFIG: TokenConfig;
83
+ /**
84
+ * Build a map from pattern to token for two-character operators.
85
+ */
86
+ export declare function buildTwoCharMap(): Map<string, Token>;
87
+ /**
88
+ * Build a map from pattern to token for single-character operators.
89
+ */
90
+ export declare function buildSingleCharMap(): Map<string, Token>;
91
+ /**
92
+ * Get the special behavior flag for a single-character operator.
93
+ */
94
+ export declare function getSingleCharSpecial(pattern: string): string | undefined;
@@ -0,0 +1,9 @@
1
+ import { SpannedToken, Token } from "./types.js";
2
+ /**
3
+ * Tokenize source into a flat token array (no newlines).
4
+ */
5
+ export declare function tokenize(input: string): Token[];
6
+ /**
7
+ * Tokenize source with full span information.
8
+ */
9
+ export declare function tokenizeDetailed(input: string): SpannedToken[];
@@ -0,0 +1,78 @@
1
+ export declare enum Token {
2
+ Integer = 0,
3
+ Float = 1,
4
+ Str = 2,
5
+ Char = 3,
6
+ Ident = 4,
7
+ Function = 5,
8
+ If = 6,
9
+ Else = 7,
10
+ ElseIf = 8,
11
+ For = 9,
12
+ While = 10,
13
+ Break = 11,
14
+ Continue = 12,
15
+ Return = 13,
16
+ End = 14,
17
+ ClassDef = 15,
18
+ Properties = 16,
19
+ Methods = 17,
20
+ Events = 18,
21
+ Enumeration = 19,
22
+ Arguments = 20,
23
+ Import = 21,
24
+ Switch = 22,
25
+ Case = 23,
26
+ Otherwise = 24,
27
+ Try = 25,
28
+ Catch = 26,
29
+ Global = 27,
30
+ Persistent = 28,
31
+ True = 29,
32
+ False = 30,
33
+ Plus = 31,
34
+ Minus = 32,
35
+ Star = 33,
36
+ Slash = 34,
37
+ Backslash = 35,
38
+ Caret = 36,
39
+ And = 37,
40
+ Or = 38,
41
+ Tilde = 39,
42
+ At = 40,
43
+ Question = 41,
44
+ Less = 42,
45
+ Greater = 43,
46
+ Dot = 44,
47
+ Colon = 45,
48
+ Comma = 46,
49
+ Assign = 47,
50
+ Semicolon = 48,
51
+ LParen = 49,
52
+ RParen = 50,
53
+ LBracket = 51,
54
+ RBracket = 52,
55
+ LBrace = 53,
56
+ RBrace = 54,
57
+ DotStar = 55,
58
+ DotSlash = 56,
59
+ DotBackslash = 57,
60
+ DotCaret = 58,
61
+ AndAnd = 59,
62
+ OrOr = 60,
63
+ Equal = 61,
64
+ NotEqual = 62,
65
+ LessEqual = 63,
66
+ GreaterEqual = 64,
67
+ Transpose = 65,
68
+ Ellipsis = 66,
69
+ Newline = 67,
70
+ Section = 68,
71
+ Error = 69
72
+ }
73
+ export interface SpannedToken {
74
+ token: Token;
75
+ lexeme: string;
76
+ start: number;
77
+ end: number;
78
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Class information types and extraction utilities.
3
+ */
4
+ import { type Expr, type Stmt } from "../parser/index.js";
5
+ /**
6
+ * Metadata about a class definition.
7
+ * The ctx field is typed as 'unknown' to avoid circular dependencies with LoweringContext.
8
+ * At runtime, it will hold a LoweringContext instance.
9
+ */
10
+ export interface ClassInfo {
11
+ name: string;
12
+ qualifiedName: string;
13
+ fileName: string;
14
+ source: string;
15
+ superClass: string | null;
16
+ propertyNames: string[];
17
+ propertyDefaults: Map<string, Expr>;
18
+ methodNames: Set<string>;
19
+ staticMethodNames: Set<string>;
20
+ constructorName: string | null;
21
+ ast: Stmt & {
22
+ type: "ClassDef";
23
+ };
24
+ inferiorClasses: string[];
25
+ externalMethodFiles: Map<string, {
26
+ fileName: string;
27
+ source: string;
28
+ }>;
29
+ ctx?: any;
30
+ }
31
+ /**
32
+ * Extract ClassInfo from a parsed ClassDef AST node.
33
+ */
34
+ export declare function extractClassInfo(classDef: Stmt & {
35
+ type: "ClassDef";
36
+ }, qualifiedName: string, fileName: string, source: string): ClassInfo;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Built-in Constants and Functions
3
+ */
4
+ export declare const BUILTIN_CONSTANTS: Set<string>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Semantic Errors
3
+ */
4
+ import type { Span } from "../parser";
5
+ export declare class SemanticError extends Error {
6
+ span: Span | null;
7
+ identifier: string | null;
8
+ /** Resolved source file name (set by prepare.ts) */
9
+ file: string | null;
10
+ /** Resolved 1-based line number (set by prepare.ts) */
11
+ line: number | null;
12
+ /** Resolved 1-based column number (set by prepare.ts) */
13
+ column: number | undefined;
14
+ constructor(message: string, span?: Span | null, identifier?: string | null);
15
+ withSpan(span: Span): SemanticError;
16
+ withIdentifier(identifier: string): SemanticError;
17
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./errors.js";
2
+ export * from "./constants.js";
3
+ export { BinaryOperation } from "../parser/index.js";
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Type System for IR
3
+ */
4
+ export type ItemType = {
5
+ kind: "Number";
6
+ } | {
7
+ kind: "ComplexNumber";
8
+ } | {
9
+ kind: "Boolean";
10
+ } | {
11
+ kind: "Char";
12
+ } | {
13
+ kind: "String";
14
+ } | {
15
+ kind: "Tensor";
16
+ isComplex?: boolean;
17
+ isLogical?: boolean;
18
+ } | {
19
+ kind: "Cell";
20
+ elementType: ItemType | "unknown";
21
+ length: number | "unknown";
22
+ } | {
23
+ kind: "Function";
24
+ params: ItemType[];
25
+ returns: ItemType;
26
+ } | {
27
+ kind: "Struct";
28
+ knownFields: Record<string, ItemType>;
29
+ } | {
30
+ kind: "Void";
31
+ } | {
32
+ kind: "Unknown";
33
+ } | {
34
+ kind: "Union";
35
+ types: ItemType[];
36
+ } | {
37
+ kind: "MultipleOutputs";
38
+ outputTypes: ItemType[];
39
+ } | {
40
+ kind: "ClassInstance";
41
+ className: string;
42
+ } | {
43
+ kind: "DummyHandle";
44
+ } | {
45
+ kind: "SparseMatrix";
46
+ isComplex?: boolean;
47
+ } | {
48
+ kind: "Dictionary";
49
+ };
50
+ /** Returns true if the type is definitely Num, false if definitely not, undefined if unknown. */
51
+ export declare function isNum(t: ItemType): boolean | undefined;
52
+ /** Returns true if the type is definitely Tensor, false if definitely not, undefined if unknown. */
53
+ export declare function isTensor(t: ItemType): boolean | undefined;
54
+ /** Returns true if the type is definitely Complex, false if definitely not, undefined if unknown. */
55
+ export declare function isComplex(t: ItemType): boolean | undefined;
56
+ /** Returns true if the type is fully unknown ({kind: "Unknown"}). */
57
+ export declare function isFullyUnknown(t: ItemType): boolean;
58
+ /** Returns true if the type is definitely String, false if definitely not, undefined if unknown. */
59
+ export declare function isString(t: ItemType): boolean | undefined;
60
+ /** Returns true if the type is definitely Char, false if definitely not, undefined if unknown. */
61
+ export declare function isChar(t: ItemType): boolean | undefined;
62
+ export declare const IType: {
63
+ Num: ItemType;
64
+ Complex: ItemType;
65
+ Bool: ItemType;
66
+ Logical: ItemType;
67
+ Char: ItemType;
68
+ String: ItemType;
69
+ Void: ItemType;
70
+ Unknown: ItemType;
71
+ DummyHandle: ItemType;
72
+ SparseMatrix: ItemType;
73
+ Dictionary: ItemType;
74
+ /** Create a Num type */
75
+ num(): ItemType;
76
+ tensor(opts?: {
77
+ isComplex?: boolean;
78
+ isLogical?: boolean;
79
+ }): ItemType;
80
+ cell(elementType?: ItemType | "unknown", length?: number | "unknown"): ItemType;
81
+ func(params: ItemType[], returns: ItemType): ItemType;
82
+ struct(fields?: Record<string, ItemType>): ItemType;
83
+ sparseMatrix(isComplex?: boolean): ItemType;
84
+ union(types: ItemType[]): ItemType;
85
+ /** Unify two types, producing a common supertype */
86
+ unify(a: ItemType | undefined, b: ItemType | undefined): ItemType | undefined;
87
+ };