numbl 0.4.3 → 0.4.5

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 (29) hide show
  1. package/README.md +5 -1
  2. package/dist-cli/cli.js +10689 -8543
  3. package/dist-lib/graphics/figuresReducer.d.ts +14 -1
  4. package/dist-lib/graphics/types.d.ts +60 -0
  5. package/dist-lib/lib.js +24594 -22515
  6. package/dist-lib/numbl-core/executeCode.d.ts +10 -0
  7. package/dist-lib/numbl-core/executors/handleInline.d.ts +18 -2
  8. package/dist-lib/numbl-core/executors/jit/valueAdapter.d.ts +16 -9
  9. package/dist-lib/numbl-core/jit/compileSpecC.d.ts +7 -0
  10. package/dist-lib/numbl-core/jit/lowering/definiteAssign.d.ts +42 -0
  11. package/dist-lib/numbl-core/lexer/types.d.ts +62 -61
  12. package/dist-lib/numbl-core/native/ts-lapack-eig-complex.d.ts +32 -0
  13. package/dist-lib/numbl-core/runtime/plotBuiltinDispatch.d.ts +6 -0
  14. package/dist-lib/numbl-core/runtime/plotUtils.d.ts +55 -2
  15. package/dist-lib/numbl-core/runtime/runtime.d.ts +25 -0
  16. package/dist-lib/numbl-core/runtime/runtimePlot.d.ts +6 -0
  17. package/dist-lib/numbl-core/runtime/struct-access.d.ts +4 -0
  18. package/dist-lib/numbl-core/runtime/uihtmlSession.d.ts +40 -0
  19. package/dist-lib/numbl-core/version.d.ts +1 -1
  20. package/dist-plot-viewer/assets/index-CPiPZdGN.js +4504 -0
  21. package/dist-plot-viewer/index.html +1 -1
  22. package/dist-site-viewer/assets/index-Y_Z9U6zO.js +4826 -0
  23. package/dist-site-viewer/assets/numbl-worker-CdHI6Ort.js +12088 -0
  24. package/dist-site-viewer/index.html +1 -1
  25. package/dist-site-viewer/numbl-embed.js +131 -18
  26. package/package.json +1 -1
  27. package/dist-plot-viewer/assets/index-ClpZQuMR.js +0 -4426
  28. package/dist-site-viewer/assets/index-CgKjTQT7.js +0 -4748
  29. package/dist-site-viewer/assets/numbl-worker-DarsHbBe.js +0 -11993
@@ -10,6 +10,8 @@ import type { FileIOAdapter } from "./fileIOAdapter.js";
10
10
  import type { SystemAdapter } from "./systemAdapter.js";
11
11
  import type { WorkspaceFile } from "../numbl-core/workspace/index.js";
12
12
  import type { NativeBridge } from "./workspace/index.js";
13
+ import { type UihtmlSession } from "./runtime/uihtmlSession.js";
14
+ export type { UihtmlSession } from "./runtime/uihtmlSession.js";
13
15
  export interface ExecOptions {
14
16
  onOutput?: (text: string) => void;
15
17
  onDrawnow?: (plotInstructions: PlotInstruction[]) => void;
@@ -48,6 +50,10 @@ export interface ExecOptions {
48
50
  implicitCwdPath?: string | null;
49
51
  /** SharedArrayBuffer for cooperative cancellation. Int32[0] != 0 means cancelled. */
50
52
  cancelSAB?: SharedArrayBuffer;
53
+ /** Hook for `sendEventToHTMLSource(src,name,data)` — pushes an event from a
54
+ * uihtml callback back to the component's page (MATLAB → JS). `dataJson` is
55
+ * the data already `jsonencode`d. The host forwards it to the iframe. */
56
+ onHtmlSourceEvent?: (compId: string, name: string, dataJson: string) => void;
51
57
  }
52
58
  export interface BuiltinProfileEntry {
53
59
  totalTimeMs: number;
@@ -94,5 +100,9 @@ export interface ExecResult {
94
100
  workspaceFiles?: WorkspaceFile[];
95
101
  /** Final implicit cwd path (for REPL persistence across commands). */
96
102
  implicitCwdPath?: string | null;
103
+ /** Present when the run left `uihtml` reverse-channel callbacks registered.
104
+ * The host retains this to dispatch later iframe events into the still-live
105
+ * interpreter (see UihtmlSession). Absent for normal runs (no overhead). */
106
+ uihtmlSession?: UihtmlSession;
97
107
  }
98
108
  export declare function executeCode(source: string, options?: ExecOptions, workspaceFiles?: WorkspaceFile[], mainFileName?: string, searchPaths?: string[], nativeBridge?: NativeBridge): ExecResult;
@@ -19,6 +19,20 @@
19
19
  * detect captures against the handle's own recorded definition
20
20
  * environment, so the test reflects what the handle actually closed
21
21
  * over, not a syntactic guess.
22
+ *
23
+ * A second constraint applies at the relocation site. A body name that
24
+ * is NOT a variable in the def env resolves at definition time to a
25
+ * function (or is undefined). After relocation into the loop's synthetic
26
+ * scope, that same name may be bound as a variable (a loop input or
27
+ * assigned local). Re-lowering would then capture the loop variable
28
+ * instead of resolving the function/undefined the handle saw — silently
29
+ * turning `@(t) sq(t)` from a function call into an array index, or
30
+ * masking an undefined-variable error. So the caller passes the set of
31
+ * names that will be in scope at the relocation site, and we decline
32
+ * when a free body name collides with it. A name that is purely a
33
+ * function (never an env variable) is not in that set, so the common
34
+ * `@(t) sq(t)` case still inlines; only the genuine shadowing case
35
+ * declines (and falls back to the interpreter).
22
36
  */
23
37
  import type { Expr } from "../parser/index.js";
24
38
  /**
@@ -33,10 +47,12 @@ import type { Expr } from "../parser/index.js";
33
47
  * shadow across files), AND
34
48
  * - for an anonymous handle, it is capture-free: no name its body
35
49
  * references (other than its own params) exists as a variable in the
36
- * handle's recorded definition environment.
50
+ * handle's recorded definition environment, AND no free body name
51
+ * collides with `relocScopeNames` (the names that will be in scope
52
+ * where the handle is inlined).
37
53
  *
38
54
  * Named (`@name`) handles are always capture-free. Anything the lowerer
39
55
  * ultimately can't compile (e.g. a builtin target) simply makes the
40
56
  * enclosing unit decline to the interpreter — still correct.
41
57
  */
42
- export declare function inlinableHandleExpr(val: unknown, compileFile: string): Expr | null;
58
+ export declare function inlinableHandleExpr(val: unknown, compileFile: string, relocScopeNames?: ReadonlySet<string>): Expr | null;
@@ -22,20 +22,27 @@
22
22
  * have caused `propose()` to decline earlier.
23
23
  */
24
24
  import { type RuntimeValue } from "../../runtime/types.js";
25
- import type { JitType } from "../../jitTypes.js";
25
+ import type { Type } from "../../jit/index.js";
26
26
  /** numbl RuntimeValue → mtoc2 emit-JS value shape. Owned-typed
27
27
  * values (tensors) get their data buffer cloned so mtoc2's spec
28
28
  * body can mutate freely without leaking the change back through
29
29
  * numbl's caller-side env.
30
30
  *
31
- * `targetType` is the JitType the spec was COMPILED for at this
32
- * parameter. Type-widening can reuse a complex specialization for a
33
- * later real/boolean scalar call (both keys collapse to
34
- * `complex_or_number`); the complex-typed body reads `.re`/`.im`, so a
35
- * bare JS number arriving there yields `undefined` NaN. Box such a
36
- * scalar into `{re, im:0}` to mirror the C adapter (valueAdapterC),
37
- * which already boxes a real as a complex with `im=0`. */
38
- export declare function numblToJit(v: RuntimeValue, targetType?: JitType): unknown;
31
+ * `paramType` is the compiler `Type` the spec was COMPILED for at this
32
+ * parameter. It reconciles two value/type mismatches at the boundary,
33
+ * both mirroring the C adapter (valueAdapterC):
34
+ *
35
+ * 1. **1×1 tensor scalar param.** The compiler collapses a [1,1]
36
+ * tensor type to a scalar `double`/`complex` (`!isMultiElement`),
37
+ * so scalar codegen reads a bare number / `{re, im}`. A 1×1
38
+ * `RuntimeTensor` value must therefore be unwrapped to its element;
39
+ * otherwise the tensor OBJECT leaks into scalar arithmetic and
40
+ * `a.data[i] + b` becomes `number + object = NaN`.
41
+ * 2. **real → complex-scalar param.** Type-widening can reuse a complex
42
+ * specialization for a later real/boolean scalar call; the
43
+ * complex-typed body reads `.re`/`.im`, so a bare number must be
44
+ * boxed into `{re, im:0}`. */
45
+ export declare function numblToJit(v: RuntimeValue, paramType?: Type): unknown;
39
46
  /** mtoc2 emit-JS return value → numbl RuntimeValue. */
40
47
  export declare function jitToNumbl(v: unknown): RuntimeValue;
41
48
  /** True if `e` is the grow-bail sentinel thrown by the emitted JS
@@ -75,6 +75,13 @@ export interface CompileSpecCArgs {
75
75
  argTypes: Type[];
76
76
  /** Number of outputs the call site requests. Salts the spec key. */
77
77
  nargout: number;
78
+ /** True when the entry `funcDecl` is a synthetic wrapper (loop or
79
+ * top-level body), whose declared outputs may include the loop variable
80
+ * and other loop-body locals that are legitimately unassigned on a
81
+ * zero-iteration run. Suppresses the output-definite-assignment check on
82
+ * the entry spec (callees are still fully checked). Defaults to false
83
+ * (a real user-function entry, e.g. the call executor). */
84
+ entrySynthetic?: boolean;
78
85
  }
79
86
  export interface CompileSpecCResult {
80
87
  /** Mangled spec name. Same as `signature.cName`. */
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Conservative definite-assignment check for the C backend.
3
+ *
4
+ * The C-JIT predeclares every function local at the top of the emitted
5
+ * function with a default value (`double x = 0.0;`, an empty owned struct,
6
+ * …). C has no "unassigned" sentinel, so a variable that is assigned ONLY
7
+ * on a path that doesn't run — e.g. inside a `for` loop with an empty range,
8
+ * or one arm of an `if` with no matching `else` — leaks its default value
9
+ * when read afterwards. The interpreter and JS-JIT instead leave the binding
10
+ * absent: the interpreter raises "Undefined function or variable", and the
11
+ * JS-JIT returns `undefined` which fails to marshal back and bails to the
12
+ * interpreter. So at `--opt 2` a use-before-assign silently returns 0 while
13
+ * `--opt 0/1` (correctly) raise.
14
+ *
15
+ * Rather than model MATLAB's binding-absent semantics in C, we DECLINE: if a
16
+ * variable that is assigned somewhere in the function may be read before it
17
+ * is definitely assigned, throw `UnsupportedConstruct`. The C-JIT executor
18
+ * catches that and falls back to the JS-JIT / interpreter, which handle the
19
+ * case correctly. Declining is always safe — it can only cost a fallback,
20
+ * never correctness — so the analysis is deliberately conservative:
21
+ *
22
+ * - On the READ side it may under-approximate (a missed read kind just
23
+ * means we don't catch that particular use-before-assign — still safe).
24
+ * - On the ASSIGNMENT side it must not under-approximate, or we'd flag a
25
+ * valid program; the `assert_jit c` integration tests guard against
26
+ * over-declining real code.
27
+ */
28
+ import type { IRFunc } from "./ir.js";
29
+ /**
30
+ * Throw `UnsupportedConstruct` if `fn` may read a local variable before it
31
+ * is definitely assigned. Parameters are assigned on entry.
32
+ *
33
+ * `checkOutputs` additionally rejects a function whose declared output may
34
+ * be returned before assignment (MATLAB's "Output argument not assigned").
35
+ * Enable it only for REAL user functions: a synthetic loop/top-level wrapper
36
+ * lists the loop variable (and other loop-body locals) as pseudo-outputs
37
+ * that are legitimately unassigned when the loop runs zero times, so the
38
+ * check would over-decline every loop.
39
+ */
40
+ export declare function assertDefiniteAssignment(fn: IRFunc, opts?: {
41
+ checkOutputs: boolean;
42
+ }): void;
@@ -9,67 +9,68 @@ export declare enum Token {
9
9
  Else = 7,
10
10
  ElseIf = 8,
11
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
- Directive = 70
12
+ ParFor = 10,
13
+ While = 11,
14
+ Break = 12,
15
+ Continue = 13,
16
+ Return = 14,
17
+ End = 15,
18
+ ClassDef = 16,
19
+ Properties = 17,
20
+ Methods = 18,
21
+ Events = 19,
22
+ Enumeration = 20,
23
+ Arguments = 21,
24
+ Import = 22,
25
+ Switch = 23,
26
+ Case = 24,
27
+ Otherwise = 25,
28
+ Try = 26,
29
+ Catch = 27,
30
+ Global = 28,
31
+ Persistent = 29,
32
+ True = 30,
33
+ False = 31,
34
+ Plus = 32,
35
+ Minus = 33,
36
+ Star = 34,
37
+ Slash = 35,
38
+ Backslash = 36,
39
+ Caret = 37,
40
+ And = 38,
41
+ Or = 39,
42
+ Tilde = 40,
43
+ At = 41,
44
+ Question = 42,
45
+ Less = 43,
46
+ Greater = 44,
47
+ Dot = 45,
48
+ Colon = 46,
49
+ Comma = 47,
50
+ Assign = 48,
51
+ Semicolon = 49,
52
+ LParen = 50,
53
+ RParen = 51,
54
+ LBracket = 52,
55
+ RBracket = 53,
56
+ LBrace = 54,
57
+ RBrace = 55,
58
+ DotStar = 56,
59
+ DotSlash = 57,
60
+ DotBackslash = 58,
61
+ DotCaret = 59,
62
+ AndAnd = 60,
63
+ OrOr = 61,
64
+ Equal = 62,
65
+ NotEqual = 63,
66
+ LessEqual = 64,
67
+ GreaterEqual = 65,
68
+ Transpose = 66,
69
+ Ellipsis = 67,
70
+ Newline = 68,
71
+ Section = 69,
72
+ Error = 70,
73
+ Directive = 71
73
74
  }
74
75
  export interface SpannedToken {
75
76
  token: Token;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Pure-TypeScript complex non-symmetric eigensolver — a zgeev-equivalent for
3
+ * the ts-lapack bridge (browser path, no native LAPACK addon).
4
+ *
5
+ * Ported from the netlib LAPACK reference (zgeev → zgehd2 / zunghr → zlahqr →
6
+ * ztrevc). Simplifications relative to zgeev, valid for the well-scaled inputs
7
+ * numbl produces (the acceptance bar is residual-based, A*V≈V*D / W^H*A≈D*W^H,
8
+ * not bit-matching MKL):
9
+ * - No balancing (zgebal/zgebak) — ILO=1, IHI=N.
10
+ * - No norm scaling (zlascl).
11
+ * - Eigenvector back-substitution uses plain triangular solves with the
12
+ * ztrevc SMIN diagonal regularization, instead of the overflow-safe zlatrs.
13
+ *
14
+ * Eigenvectors are normalized to unit Euclidean norm with the largest-magnitude
15
+ * component made real (the documented zgeev convention).
16
+ *
17
+ * All matrices are column-major with leading dimension n, split into parallel
18
+ * real/imag Float64Arrays — matching the bridge's eigComplex I/O shape.
19
+ */
20
+ /**
21
+ * Complex eigendecomposition (zgeev-equivalent). Matches the LapackBridge
22
+ * eigComplex contract: column-major real/imag inputs, returns eigenvalues and
23
+ * (optionally) left/right eigenvectors.
24
+ */
25
+ export declare function eigComplexTs(dataRe: Float64Array, dataIm: Float64Array, n: number, computeVL: boolean, computeVR: boolean): {
26
+ wRe: Float64Array;
27
+ wIm: Float64Array;
28
+ VLRe?: Float64Array;
29
+ VLIm?: Float64Array;
30
+ VRRe?: Float64Array;
31
+ VRIm?: Float64Array;
32
+ };
@@ -42,6 +42,12 @@ import type { PlotInstruction } from "../../graphics/types.js";
42
42
  export interface PlotDispatchState {
43
43
  holdState: boolean;
44
44
  tiledLayoutState: TiledLayoutState | null;
45
+ /** Current figure handle (0 = none created yet). */
46
+ currentFigureHandle?: number;
47
+ /** Highest figure handle allocated so far. `figure` with no argument
48
+ * creates a NEW figure with handle `maxFigureHandle + 1` (MATLAB
49
+ * semantics), rather than always reusing handle 1. */
50
+ maxFigureHandle?: number;
45
51
  }
46
52
  /** Active tiled-layout grid. `mode` controls how the grid grows: in
47
53
  * `flow` (default), nexttile expands rows/cols to fit; `vertical` and
@@ -5,8 +5,9 @@
5
5
  * plot(X1,Y1,LineSpec1,...), and Name-Value pairs like 'Color','r','LineWidth',2.
6
6
  */
7
7
  import { type RuntimeValue } from "./types.js";
8
- export type { PlotTrace, Plot3Trace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, Quiver3Trace, } from "../../graphics/types.js";
9
- import type { PlotTrace, Plot3Trace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, Quiver3Trace } from "../../graphics/types.js";
8
+ export type { PlotTrace, Plot3Trace, PatchTrace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, Quiver3Trace, } from "../../graphics/types.js";
9
+ import type { PlotTrace, Plot3Trace, PatchTrace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, Quiver3Trace } from "../../graphics/types.js";
10
+ export declare function resolveColor(v: RuntimeValue | string): [number, number, number] | undefined;
10
11
  export interface ParsedLineSpec {
11
12
  color?: string;
12
13
  lineStyle?: string;
@@ -24,6 +25,58 @@ export declare function parsePlotArgs(args: RuntimeValue[]): PlotTrace[];
24
25
  * plot3(..., Name, Value)
25
26
  */
26
27
  export declare function parsePlot3Args(args: RuntimeValue[]): Plot3Trace[];
28
+ /** Result of parsing line() arguments: a set of 2-D or 3-D traces. */
29
+ export type ParsedLine = {
30
+ kind: "2d";
31
+ traces: PlotTrace[];
32
+ } | {
33
+ kind: "3d";
34
+ traces: Plot3Trace[];
35
+ };
36
+ /**
37
+ * Parse line() arguments.
38
+ *
39
+ * Supported forms:
40
+ * line — line from (0,0) to (1,1)
41
+ * line(x, y) — 2-D line(s)
42
+ * line(x, y, z) — 3-D line(s)
43
+ * line(___, Name, Value) — Color/LineStyle/LineWidth/Marker/...
44
+ * line('XData', x, 'YData', y, ...) — low-level form (black line)
45
+ * line(ax, ___) — leading axes handle (ignored)
46
+ *
47
+ * Like plot/plot3, vector inputs make a single line and matrix inputs make one
48
+ * line per column.
49
+ */
50
+ export declare function parseLineArgs(args: RuntimeValue[]): ParsedLine;
51
+ /** Apply a single patch property (lower-cased key) to the trace. Shared by the
52
+ * Name-Value, struct, and `set`/handle paths. */
53
+ export declare function applyPatchProp(trace: PatchTrace, key: string, val: RuntimeValue): void;
54
+ /**
55
+ * Parse patch() arguments into a canonical PatchTrace.
56
+ *
57
+ * Supported forms:
58
+ * patch(X, Y, C) — 2-D polygons, color C
59
+ * patch(X, Y, Z, C) — 3-D polygons
60
+ * patch('XData', X, 'YData', Y[, 'ZData', Z]) — coords as name-value
61
+ * patch('Faces', F, 'Vertices', V) — faces/vertices model
62
+ * patch(S) — struct of patch properties
63
+ * patch(___, Name, Value) — patch properties
64
+ * patch(ax, ___) — leading axes handle (ignored)
65
+ */
66
+ export declare function parsePatchArgs(args: RuntimeValue[]): PatchTrace;
67
+ /**
68
+ * Parse fill() arguments into one patch trace per (X,Y,C) group. fill is the
69
+ * 2-D coordinate form of patch repeated over groups, so it reuses the patch
70
+ * vertex/color/property helpers — the only fill-specific logic is splitting
71
+ * the argument list into X,Y,C triplets.
72
+ *
73
+ * Supported forms:
74
+ * fill(X, Y, C)
75
+ * fill(X1, Y1, C1, ..., Xn, Yn, Cn)
76
+ * fill(___, Name, Value)
77
+ * fill(ax, ___)
78
+ */
79
+ export declare function parseFillArgs(args: RuntimeValue[]): PatchTrace[];
27
80
  /**
28
81
  * Parse surf() arguments.
29
82
  *
@@ -32,6 +32,27 @@ export declare class Runtime {
32
32
  plotInstructions: PlotInstruction[];
33
33
  variableValues: Record<string, RuntimeValue>;
34
34
  holdState: boolean;
35
+ /** Figure-handle tracking for MATLAB-style `figure` allocation: `figure`
36
+ * with no argument creates a new figure (`maxFigureHandle + 1`). */
37
+ currentFigureHandle: number;
38
+ maxFigureHandle: number;
39
+ /** Monotonic id source for graphics handles whose trace can be live-updated
40
+ * via `set` / `update_trace` (e.g. lines returned by `line`). */
41
+ graphicsIdCounter: number;
42
+ /** Reverse channel for `uihtml` components (HTML → MATLAB). Maps a component
43
+ * id (the `uihtml` instruction's `id`) to the callback handles registered
44
+ * for it. When non-empty after a run, the host keeps this runtime alive so
45
+ * iframe events can re-enter the interpreter and invoke these handles.
46
+ * Handles are incref'd while stored (see registeruihtmlcallback). */
47
+ uihtmlCallbacks: Map<string, {
48
+ HTMLEventReceived?: RuntimeValue;
49
+ DataChanged?: RuntimeValue;
50
+ }>;
51
+ /** Hook invoked by `sendEventToHTMLSource(src, name, data)` to push an event
52
+ * from MATLAB back to a uihtml component's page. `dataJson` is the data
53
+ * already `jsonencode`d. Set from ExecOptions; the host forwards it to the
54
+ * iframe. */
55
+ onHtmlSourceEvent?: (compId: string, name: string, dataJson: string) => void;
35
56
  tiledLayoutState: {
36
57
  rows: number;
37
58
  cols: number;
@@ -139,6 +160,10 @@ export declare class Runtime {
139
160
  * every value adopted into the scope is decref'd. Used by `execStmt`
140
161
  * to bound the lifetime of expression transients to one statement. */
141
162
  withScope<T>(fn: () => T): T;
163
+ /** Register the implicit default figure (handle 1) the first time a graphics
164
+ * op runs without an explicit `figure`, so a later no-arg `figure` allocates
165
+ * a new handle instead of reusing 1 (MATLAB semantics). */
166
+ ensureCurrentFigure(): void;
142
167
  private initBuiltins;
143
168
  profileEnter(key: string): void;
144
169
  profileLeave(): void;
@@ -47,6 +47,9 @@ export declare function plotInstr(plotInstructions: PlotInstruction[], instr: {
47
47
  } | {
48
48
  type: "set_grid";
49
49
  value: unknown;
50
+ } | {
51
+ type: "set_box";
52
+ value: unknown;
50
53
  } | {
51
54
  type: "set_zlabel";
52
55
  text: unknown;
@@ -68,6 +71,9 @@ export declare function plotInstr(plotInstructions: PlotInstruction[], instr: {
68
71
  export declare function viewCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
69
72
  export declare function plotCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
70
73
  export declare function plot3Call(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
74
+ export declare function lineCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
75
+ export declare function patchCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
76
+ export declare function fillCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
71
77
  export declare function surfCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
72
78
  export declare function surfaceCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
73
79
  export declare function imagescCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
@@ -3,5 +3,9 @@
3
3
  */
4
4
  import { type RuntimeValue } from "./types.js";
5
5
  import { type RefcountRuntime } from "./refcount.js";
6
+ export declare function applyHandleProperty(trace: Record<string, unknown>, traceType: string, field: string, value: RuntimeValue): {
7
+ key: string;
8
+ value: unknown;
9
+ };
6
10
  export declare function getRTValueField(base: RuntimeValue, field: string): RuntimeValue;
7
11
  export declare function setRTValueField(base: RuntimeValue, field: string, value: RuntimeValue, rt?: RefcountRuntime): RuntimeValue;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * uihtml reverse channel (HTML → MATLAB) for a finished run.
3
+ *
4
+ * When a script creates a `uihtml` component with a callback
5
+ * (HTMLEventReceivedFcn / DataChangedFcn), the run leaves entries in
6
+ * `rt.uihtmlCallbacks`. `executeCode` then builds a `UihtmlSession` and returns
7
+ * it so the host (the worker) can keep the interpreter alive and re-enter it
8
+ * when an event arrives from the iframe — mirroring MATLAB, where the script
9
+ * returns but its callbacks keep firing.
10
+ *
11
+ * Dispatch re-activates the run's own special-builtin closures (captured at
12
+ * end-of-run, NOT re-registered — re-registering would reset their counters)
13
+ * and pushes the runtime so `disp`, plotting, and `sendEventToHTMLSource`
14
+ * inside the callback reach this runtime. This mirrors executeCode's own
15
+ * save/restore of SPECIAL_BUILTIN_NAMES.
16
+ */
17
+ import type { Runtime } from "./runtime.js";
18
+ import type { PlotInstruction } from "../../graphics/types.js";
19
+ import { type IBuiltin } from "../interpreter/builtins/types.js";
20
+ export interface UihtmlSession {
21
+ /** True while at least one component still has a registered callback. */
22
+ hasCallbacks(): boolean;
23
+ /** Dispatch an event from a component's page into MATLAB. `eventType` is
24
+ * "HTMLEventReceived" (JS `sendEventToMATLAB`) or "DataChanged" (JS set
25
+ * `htmlComponent.Data`). `payload.data` is the structured-clone'd JS value.
26
+ * New plot output is flushed via `onDrawnow`; outgoing
27
+ * `sendEventToHTMLSource` calls go through `rt.onHtmlSourceEvent`. */
28
+ dispatchEvent(compId: string, eventType: "HTMLEventReceived" | "DataChanged", payload: {
29
+ name?: string;
30
+ data: unknown;
31
+ }): void;
32
+ /** Release the retained callback handles (and their refs). */
33
+ dispose(): void;
34
+ }
35
+ /**
36
+ * Build a session over a runtime that registered uihtml callbacks.
37
+ * `activeSpecials` is a snapshot of this runtime's special-builtin closures,
38
+ * captured at end-of-run while they are still installed globally.
39
+ */
40
+ export declare function createUihtmlSession(rt: Runtime, activeSpecials: Map<string, IBuiltin>, onDrawnow?: (plotInstructions: PlotInstruction[]) => void): UihtmlSession;
@@ -1,2 +1,2 @@
1
1
  /** Numbl version, used for JIT disk cache invalidation. */
2
- export declare const NUMBL_VERSION = "0.4.3";
2
+ export declare const NUMBL_VERSION = "0.4.5";