xdl-matlab

Crates.ioxdl-matlab
lib.rsxdl-matlab
version0.1.1
created_at2025-12-31 18:33:24.435726+00
updated_at2025-12-31 22:19:10.131965+00
descriptionExtended Data Language (XDL) - Rust implementation
homepagehttps://turingworks.github.io/xdl
repositoryhttps://github.com/turingworks/xdl
max_upload_size
id2015119
size124,939
ravituringworks (ravituringworks)

documentation

README

XDL-MATLAB: MATLAB Compatibility Layer

This crate provides MATLAB/Octave compatibility for XDL, enabling:

  • Loading and executing .m files
  • Transpiling MATLAB syntax to XDL
  • Mapping MATLAB functions to XDL equivalents

Features

Syntax Transpilation

Converts MATLAB code to XDL-compatible syntax:

  • Comments: %;
  • Arrays: 1-based → 0-based indexing
  • Loops: for i = 1:10for i = 0, 9
  • Element-wise ops: .**, .//, .^^

Function Mapping (~80 functions)

MATLAB XDL Notes
zeros(n) FLTARR(n) Array creation
sin(x) SIN(x) Trig functions
mean(x) MEAN(x) Statistics
plot(x, y) PLOT, y, x Plotting
disp(x) PRINT, x I/O

See function_map.rs for complete list.

Usage

As a Library

use xdl_matlab::transpile_matlab_to_xdl;

let matlab_code = r#"
x = zeros(10, 1);
for i = 1:10
    x(i) = sin(i * 0.1);
end
"#;

let xdl_code = transpile_matlab_to_xdl(matlab_code)?;
println!("{}", xdl_code);

Load .m Files

use xdl_matlab::load_matlab_file;

let xdl_code = load_matlab_file(Path::new("script.m"))?;
// Execute with XDL interpreter

Example

Input MATLAB:

% Calculate mean
x = zeros(10, 1);
for i = 1:10
    x(i) = i * 2;
end
mean_x = mean(x);
disp('Mean value:');
disp(mean_x);

Output XDL:

; Calculate mean
x = FLTARR ( 10 , 1 )
for i = 0, 9
  x [ i ] = i * 2
endfor
mean_x = MEAN ( x )
PRINT , 'Mean value:'
PRINT , mean_x

Limitations

Current Implementation

  • Basic syntax only: Functions, loops, conditionals
  • Simple indexing: Multi-dimensional arrays need work
  • No cell arrays: {} syntax not yet supported
  • No classes/objects: OOP features not implemented

Index Adjustment

MATLAB uses 1-based indexing, XDL uses 0-based:

x(1)    % MATLAB: first element
x[0]    % XDL: first element

The transpiler automatically adjusts simple numeric indices.

Roadmap

  • Lexer for MATLAB syntax
  • Basic transpiler (assignments, loops, functions)
  • Function name mapping (~80 functions)
  • Matrix operations and slicing
  • Cell arrays and structures
  • Handle/function handles (@func syntax)
  • MEX file interface
  • Package manager integration
  • Advanced indexing (end, :, etc.)

Testing

cargo test -p xdl-matlab

Contributing

Function mappings and syntax rules are in:

  • function_map.rs - Add new MATLAB→XDL function mappings
  • transpiler.rs - Extend syntax transpilation rules
  • lexer.rs - Handle new token types

License

Same as parent XDL project.

Commit count: 0

cargo fmt