RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.2, Nov 26, 2026 ·

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
    • Virtual Machine (VM)
    • Bytecode Compilation
    • Interpreter Dispatch & Execution Loop
    • Indexing Subsystem
    • Callable Resolution & Function Dispatch
    • JIT Compiler
    • JIT Pipeline
    • Memory Management
Docs>Runtime>Execution Engines

Interpreter Dispatch & Execution Loop

The RunMat interpreter executes the bytecode emitted by the VM compiler. It is an async instruction loop over Instr values, with runtime state held in InterpreterState and passed into the dispatch layer as a mutable DispatchState. The loop owns the program counter, value stack, variable slots, try/catch stack, semantic function resolver hooks, and optional native-acceleration fusion plan.

Runtime State

InterpreterState is created from a Bytecode program and the caller's initial variable slots. Before execution begins, the interpreter installs semantic function hooks, prepares workspace state, initializes GC roots, and activates a fusion plan when the native-accel feature is enabled.

Key Runtime Fields

FieldPurpose
bytecodeThe instruction stream, variable metadata, function registry, and fusion metadata.
stackTemporary operand stack used by bytecode instructions.
varsWorkspace or frame-local variable slots addressed by LoadVar, StoreVar, and local fallbacks.
contextCall stack, local frame storage, instruction pointer metadata, and async task tracking.
pcProgram counter into bytecode.instructions.
try_stackStack of scoped catch targets used by try/catch bytecode.
last_exceptionLast caught exception value, used by exception-sensitive built-ins such as rethrow.

Exact native continuation

The compiler retains a portable MIR-program-point to bytecode-PC map for boundaries where the VM operand stack is empty. When native execution exits at one of those verified boundaries, Core can resume this same interpreter loop with materialized variable assignment state, global and persistent aliases, omitted inputs, nargin and nargout, imports, source context, and the exact next pc. The bytecode before that boundary is not executed again. If the native frame contains state the interpreter cannot represent exactly, execution stays in the generic-native continuation instead.

Execution Loop

The main loop in run_interpreter_inner repeatedly fetches the instruction at pc, offers eligible spans to the fusion executor, dispatches the instruction, and then applies the resulting control-flow decision.

Loading diagram...

Instruction Dispatch

dispatch_instruction receives three grouped inputs:

  • DispatchMeta: the current instruction, function registry, source metadata, call spans, and call-count context.
  • DispatchState: mutable stack, variables, context, try stack, imports, aliases, persistent state, missing-input slots, and pc.
  • DispatchHooks: callbacks used by the runner for residency cleanup and workspace or persistent-variable synchronization.

The dispatcher first gives broad instruction families to specialized modules. Indexing, object, and arithmetic handlers return true when they consume the instruction. The remaining bytecode variants are handled by the central match in dispatch/mod.rs.

Loading diagram...

Dispatch Categories

CategoryRepresentative InstructionsPrimary Handler
IndexingIndex, StoreIndex, IndexSlice, StoreSliceExprinterpreter/dispatch/indexing.rs
Arithmetic and logical opsAdd, Sub, Mul, comparisons, boolean opsinterpreter/dispatch/arithmetic.rs
Object supportObject literals and object operationsinterpreter/dispatch/object.rs
Variables and stackLoadVar, StoreVar, LoadLocal, Pop, Swapinterpreter/dispatch/mod.rs
Control flowJump, JumpIfFalse, EnterTry, Returnops/control_flow.rs
CallsBuilt-ins, semantic functions, feval, multi-output callsinterpreter/dispatch/calls.rs and call/*
AsyncSemantic futures, Spawn, Awaitinterpreter/dispatch/mod.rs

Indexed assignment instructions push the updated base value back onto the stack. Follow-up bytecode is responsible for storing that value into the target variable or local slot with StoreVar or StoreLocal.

Exception Routing

try/catch is represented directly in bytecode. EnterTry pushes a compiler-assigned scope and catch target onto try_stack. MIR control-flow analysis identifies the complete try-only region, including nested branches, loops, and await continuations. LeaveTry removes that exact scope on each normal edge out of the protected region; it does not accidentally remove an enclosing handler or require the try body to fit in one basic block. If a handler returns RuntimeError, the runner calls redirect_exception_to_catch.

When a catch target exists, the VM:

  • Pops the innermost active catch entry while retaining enclosing handlers.
  • Converts the runtime error into Runtime's canonical MException.
  • Stores that exception into the optional catch variable slot.
  • Updates last_exception.
  • Sets pc to the catch handler.

If no catch entry exists, the error leaves the interpreter.

Semantic Function Hooks

Before entering the loop, the interpreter installs scoped semantic invoker and resolver ports backed by the bytecode FunctionRegistry and selected RuntimeContext. This lets the runtime call back into bytecode-defined functions from several paths: direct semantic calls, closures, feval, object dispatch, and end-expression calls inside indexing. Selected callback factories return a fallible canonical continuation owner with rooted arguments/results; admission failure is terminal before the callback body is constructed, and execution failure is terminal after selection.

Those ports are scoped by guards. Bound semantic calls depend on the exact-definition port and retained callable generation being active; an ordinary numeric semantic callback cannot confer that authority. Without the interpreter-installed invoker, a semantic function ID cannot be executed by the runtime layer. Legacy context-free embedding callbacks use distinct Unscoped* aliases and unbounded-only adapters, not the selected-context admission route.

From here, call-specific behavior is covered in Callable Resolution & Function Dispatch, and indexing-specific behavior is covered in Indexing Subsystem.

On this page
  • Runtime State
  • Key Runtime Fields
  • Exact native continuation
  • Execution Loop
  • Instruction Dispatch
  • Dispatch Categories
  • Exception Routing
  • Semantic Function Hooks