MATLAB File Support in XDL
Overview
XDL CLI and GUI now support loading and executing MATLAB .m files. The files are automatically detected by their .m extension and transpiled to XDL code before execution.
Usage
CLI
# Run a MATLAB .m file directly
xdl script.m
# The CLI will automatically:
# 1. Detect the .m extension
# 2. Transpile the MATLAB code to XDL
# 3. Execute the transpiled XDL code
GUI
- Open XDL GUI
- Go to File > Open…
- The file chooser now accepts both
.xdland.mfiles - Select a
.mfile - The MATLAB code will be automatically transpiled and loaded into the editor
- Click Execute to run the code
Features
- Automatic Detection: Files with
.mextension are automatically recognized as MATLAB files - Seamless Transpilation: MATLAB syntax is converted to XDL syntax behind the scenes
- Function Mapping: Common MATLAB functions are mapped to their XDL equivalents
- Error Reporting: Transpilation errors are clearly reported to the user
Current Limitations
The MATLAB transpiler is a work in progress and has some limitations:
- Array Literals: Array literal syntax
[1, 2, 3]is not fully supported yet- Workaround: Use alternative syntax or XDL’s array functions
-
Complex Expressions: Some complex MATLAB expressions may not transpile correctly
- Advanced Features: Advanced MATLAB features like classes, packages, and some built-in functions may not be supported
Example
MATLAB Code (test_simple.m)
% Simple calculation
x = 5;
y = x * 2;
disp(y);
Execution
$ xdl test_simple.m
10
Implementation Details
CLI Integration
- File:
xdl-cli/src/main.rs - Function:
execute_file() - The function checks the file extension and calls
xdl_matlab::transpile_matlab_to_xdl()for.mfiles
GUI Integration
- File:
xdl-gui/src/gui.rs - Location: File Open dialog callback
- The GUI detects
.mfiles and transpiles them before loading into the editor
Future Improvements
- Complete array literal support
- Better error messages with line number mapping
- Support for more MATLAB functions
- MATLAB-specific debugging features
- Option to view transpiled XDL code before execution