RunMat Language Coverage

RunMat's goal is to provide a high-performance, modern runtime to execute MATLAB code, with complete language grammar and semantics. This document tracks language coverage in RunMat and compares it to GNU Octave where helpful. It focuses on core language features (syntax and semantics), not breadth of numeric libraries or toolboxes.

Language Feature Compatibility

Feature CategoryLanguage FeatureRunMat StatusOctave StatusNotes
Variables & Data TypesDefault numeric doubleColumn-major numeric tensors (f64).
Character arrays '...'Char row vectors implemented.
String arrays "..."RunMat StringArray with MATLAB-parity indexing/comparison; Octave's string type coverage varies.
ans default variable (REPL)Handled by REPL.
global variablesName-based, cross-function binding; write-through semantics.
persistent variablesPer-function lifetime, name- and slot-based restore.
Logical scalars/arraysFirst-class logical type: scalar bool and N-D LogicalArray. islogical, class, isa, size, numel, isempty follow MATLAB; predicates (isnan, isfinite, isinf, comparisons) produce logical arrays; masks are preserved in indexing and assignment.
Integer scalars (int8uint64)Per-width scalar types (int8uint64) (not a single platform int) with class/isa parity and numeric ops routed through MATLAB-compatible paths; integer arrays are planned.
Complex numbersComplex scalars and arrays with arithmetic, comparisons, transpose (' conjugate, .' non-conjugate), element-wise power, and matrix power (integer exponents).
Matrices & ArraysLiterals [ … ]Rectangular and ragged cell literals supported; numeric tensors support rectangular construction.
Empty []Shape-consistent behavior.
Advanced Data TypesCell arrays { … }{} indexing, expansion, assignment; expansion into slice targets.
Structs s.fieldDot access, nested assignment, field scatter over cells.
Function handles @(x)x^2, closuresAnonymous functions, free-var capture, feval, nested functions.
OperatorsArithmetic + - * / \ ^Left division and element-wise left division supported.
Element-wise .* ./ .\ .^Broadcasting via slice rules; BLAS/LAPACK in runtime where applicable.
Relational == ~= < <= > >=Element-wise on arrays; scalar fallbacks.
Logical element-wise (&, |, ~)Element-wise logicals on numeric/logical masks.
Logical short-circuit (&&, ||)Semantics match MATLAB short-circuit rules.
Transpose ', non-conjugate .'Distinction modeled; ' is conjugate transpose for complex and .' is non-conjugate; identical for real inputs.
Colon : (ranges)Construction and indexing; start:step:end with step validation.
Statements & Control Flowif/elseif/else/endFull semantics.
for loopsRange iteration; standard MATLAB semantics.
while loopsFull semantics.
switch/case/otherwise/endParser and VM supported.
break, continue, returnFull semantics.
try/catch/end, rethrowMException objects with identifiers/messages.
FunctionsDefinitions (function … end)Named inputs/outputs, nested functions, closures.
Multiple returns [a,b]=f()Multi-LHS with placeholders (~), shape semantics enforced at runtime.
Anonymous functions @(...), closuresFree-var capture, closure creation, handles.
varargin / varargoutCell packing/unpacking; MATLAB-compatible arity checks with error ids (TooManyInputs, VarargoutMismatch).
nargin / nargoutMATLAB-parity dynamic per-call counts, including multi-output calls.
Indexing & Data AccessA(...) numeric indexingN-D, 1-D linear, mixed selectors.
Slicing A(:, 1:3)MATLAB-parity N-D gather/scatter with broadcast; 2-D fast paths.
Logical indexing A(A>5)MATLAB-parity masks, mixed selectors, and assignment semantics.
end in indexingMATLAB-parity end, end-k, and N-D end arithmetic across dims.
Struct field access s.fWith field scatter over cells.
Cell content C{...}Indexing and comma-list expansion.
Function/cell expansion into slice targetsMATLAB-compatible expansion into arbitrary slices using packing (PackToRow/Col); Octave behavior varies by construct.
Object-Oriented ProgrammingclassdefFull parser + runtime registry (attributes, methods/properties); Octave's classdef support is partial.
Properties/Methods (static/instance), attributesMATLAB-parity access control, Dependent, static props/methods; Octave coverage is limited.
EnumerationsParser + registration; MATLAB-parity execution supported.
Eventsaddlistener/notify with callback dispatch and listener lifecycle (enabled/valid); integrates with isvalid/delete.
Handle classes < handleIdentity semantics, isvalid/delete, equality/inequality by identity, method/indexing dispatch via underlying target.
Operator overloadingplus, mtimes, relational/logical dispatch with MATLAB-parity precedence; PICs planned in JIT.
Dot/method obj.method()Instance and static dispatch; precedence with imports.
Packages, Imports & Name Resolutionimport pkg.* / import pkg.nameMATLAB-parity precedence and diagnostics; Octave support varies.
Metaclass operator ?pkg.ClassEnables static property/method access and participates in Class.* import resolution; not available in Octave.
Resolution precedence (locals > user > specific > wildcard > Class.*)Exact MATLAB precedence; Octave differs in several cases.
Scripting & SyntaxScripts (.m)Full support.
% commentsSingle-line comments.
Block comments %{ … %}Block comment parsing.
Line continuation ...Full support.
Semicolon to suppress outputFull support.
Comma to separate statementsStatement sequencing.
Command-form calls func arg1 arg2Hardened parser (ambiguous cases resolved) with MATLAB-compatible rules.
Exceptions & ErrorsMException, identifiers/messagesMATLAB-compatible MException identifiers/messages across indexing, arity, and OOP; Octave identifiers differ.

Notes on semantics parity

  • N-D indexing/slicing: RunMat implements gather/scatter with broadcast rules, logical masks, colon, and end arithmetic across dimensions; 2-D fast paths for entire rows/columns are included. Error identifiers match MATLAB (MATLAB:SliceNonTensor, MATLAB:IndexStepZero, etc.).
  • Multi-LHS and expansion: [a,b]=f() and [~,b]=f() are supported; function and cell expansions into slice targets are handled with dynamic packing (PackToRow/PackToCol).
  • Varargs and counts: varargin/varargout with strict count checks and nargin/nargout report per-call counts consistently across single and multi-output call sites.
  • OOP: Static/instance members, operator overloading (plus, mtimes, relational/logical) and subsref/subsasgn dispatch ordering with standardized negative errors (MATLAB:MissingSubsref, MATLAB:MissingSubsasgn).
  • Imports and precedence: Specific imports shadow wildcard; locals and user functions take precedence; Class.* static resolution participates last; ambiguities are surfaced with clear diagnostics.
  • Metaclass: ?pkg.Class produces a class reference enabling static property/method access and works with import resolution.

Nuanced examples (advanced features)

1) Varargin/varargout with precise output arity

function [a, b, varargout] = head_tail(varargin)
  if nargin < 1
    error('MATLAB:NotEnoughInputs', 'Need at least one input');
  end
  a = varargin{1};
  if nargin >= 2, b = varargin{2}; else, b = 0; end
  varargout = varargin(3:end);
end

% Calls
[x, y] = head_tail(10, 20);           % x=10, y=20
[x, y, c, d] = head_tail(1, 2, 3, 4); % varargout -> c=3, d=4

2) Expansion into slice targets (functions and cells)

function [r1, r2, r3] = triple(x)
  r1 = x; r2 = 2*x; r3 = 3*x;
end

A = zeros(5,3);
J = [1,3,2];
A(:,J) = triple(7);  % expand into full columns in order J

C = {11, 22, 33};
A(2,:) = C{:};      % expand cell contents across a row slice

3) Classdef with static/instance, dependent props, and operator overloads

classdef Point
  properties(Dependent)
    r
  end
  properties
    x; y;
  end
  methods
    function obj = Point(x,y), obj.x=x; obj.y=y; end
    function v = get.r(obj), v = hypot(obj.x, obj.y); end
    function z = plus(a,b), z = Point(a.x+b.x, a.y+b.y); end
  end
  methods(Static)
    function o = origin(), o = Point(0,0); end
  end
end

p = Point(3,4);     % p.r == 5
q = Point.origin(); % static method
z = p + q;          % operator overloading via plus

4) Metaclass operator and imports precedence

import mypkg.Point.*   % wildcard
import mypkg.utils.norm2  % specific import takes precedence

mc = ?mypkg.Point;     % metaclass for static access
v = mc.origin();       % static call via metaclass

5) Try/catch and standardized MException

try
  A = zeros(2,2);
  A(:, 0) = 1;  % invalid subscript
catch e
  assert(strcmp(e.identifier, 'MATLAB:IndexOutOfBounds'));
  rethrow(e);   % rethrow preserves identifier/message
end

6) Globals and persistents (name binding + lifetime)

function setg(v)
  global G; G = v;   % write-through, visible to other functions
end

function y = counter()
  persistent k;
  if isempty(k), k = 0; end
  k = k + 1; y = k;
end

Where RunMat intentionally goes beyond MATLAB

  • GPU-native tensor execution: When a device provider is registered, element-wise ops and matrix multiply execute on the GPU and return opaque GpuTensorHandles, keeping data resident on device across chained ops. CPU paths remain available with identical MATLAB-compatible semantics.
  • Automatic device planning (in progress): A planner is being integrated to pick device placement based on tensor sizes/shapes and fuse compatible operations to minimize host↔device transfers, with room for overlapping compute/transfer via streams and memory pools.
  • Zero-temporary slice expansion: Expansion of function outputs and cell contents into slice targets writes directly to the destination using dynamic packing, avoiding intermediate temporaries and reducing peak memory for large assignments.
  • HIR-powered developer tooling: The HIR/type system tracks value kinds and tensor shapes across control flow and imports, enabling richer LSP features (hover types, shape/arity hints, precise go-to-definition across packages/classes, property completions from the class registry).
  • Deterministic import diagnostics: MATLAB-parity import precedence with explicit, readable diagnostics for shadows/ambiguities (including participation of Class.* statics) improves debugging and code navigation.
  • Stable, testable exceptions: A uniform MException model with stable identifiers/messages across indexing, arity, expansion, and OOP paths makes failures easy to assert in tests and consistent across releases.
  • Memory safety by construction: Rust implementation eliminates entire classes of memory bugs while sustaining high performance under heavy workloads.

Where RunMat intentionally goes beyond Octave

  • 100% MATLAB language semantics coverage: Full parity for syntax, operators, control flow, indexing/slicing (incl. end arithmetic), OOP (classdef, properties/methods, operator overloading), events/handles, name resolution, and standardized MException identifiers. Practically, this means your existing MATLAB scripts run unchanged on RunMat. Octave remains partial or divergent in several of these areas (e.g., classdef/events/metaclass support and precedence nuances).
  • Metaclass operator ?Class and static access through Class.* imports.
  • Consistent precedence for specific vs wildcard imports, including Class.* statics.
  • N-D end arithmetic across dimensions in both gather and scatter with broadcast-correct semantics and 2-D fast paths.
  • Function/cell expansion directly into slice targets with dynamic packing without intermediate temporaries.
  • Uniform MException identifier/message model across indexing, arity, expansion, and OOP error paths.

If you notice any discrepancy with MATLAB semantics, please open an issue with a minimal reproducer so we can add a conformance test.