RunMat
GitHub

Session Engine

runmat-core owns the host-agnostic execution session. A RunMatSession is the long-lived object that a REPL, notebook host, CLI command, or WebAssembly wrapper uses to submit MATLAB source, keep workspace variables alive, preserve user-defined functions, expose inspection data, handle input, and return structured execution results.

The session is not a second compiler or a second VM. It is the orchestration layer around the parser, HIR/MIR pipeline, VM, optional Turbine JIT, runtime builtins, GPU provider state, and host-facing ABI.

Execution Spine

Loading diagram...

What The Session Owns

Field or subsystemPurpose
variable_arrayVM slot storage used during the current execution.
workspace_bindingsName-to-slot mapping plus stable ABI binding identity.
workspace_valuesDurable variable values retained between requests.
function_registryUser-defined semantic functions retained across interactive inputs.
source_poolInterned source text and names for diagnostics and call stacks.
interrupt_flagCooperative cancellation flag shared with the runtime and VM.
async_input_handlerHost callback for input, keypress, and pause-like interactions.
stats, profiling, telemetryExecution counters and optional host analytics hooks.
compat_mode, top_level_await_enabledPer-session defaults that can be overridden by a request.

RunMatSession rejects concurrent execution on the same session. Hosts that need parallel execution should create separate sessions or serialize requests through one session.

Page Map

PagePurpose
Execution RequestsThe structured request/result ABI around session execution.
Workspace StateHow variable slots, stable binding keys, deltas, removals, and ans work.
Variable InspectionWorkspace entries, previews, materialization, preview tokens, and GPU slices.
Snapshots & ReplayStartup snapshots versus workspace replay state.
Interaction & StreamsConsole streams, warnings, async input, cancellation, diagnostics, and effects.
Host IntegrationCLI, WASM/TypeScript, notebook, editor, and lifecycle responsibilities.

For the compiler stages inside compile_input, see Compilation Pipeline. For bytecode execution details, see VM Interpreter & Bytecode. For native execution, see Turbine JIT Compiler.