MultiGen is a Python-to-multiple-languages code generator that translates Python code to C, C++, Rust, Go, Haskell, OCaml, and LLVM IR while preserving semantics and performance characteristics.
Changes since the last Release
Added
-
mgen checkCLI command -- Validates Python files against the supported subset without convertingmgen check file.pyreports valid/invalid with tier level and violation detailsmgen check --report file.pyoutputs the full feature support report- Wires up the existing
SubsetValidatorto a standalone CLI subcommand - Supports multiple input files in a single invocation
-
List slicing across all text-based backends (6/7 backends)
arr[1:3],arr[1:],arr[:2]now work in C++, Go, Rust, OCaml (C and Haskell already supported)- C++:
vector<T>(v.begin() + start, v.begin() + stop)iterator-pair constructor - Go: Native slice syntax
v[start:stop] - Rust:
v[start..stop].to_vec()range indexing - OCaml:
Array.sub v start length - C: Loop-based slicing (existing, regression tested)
- Haskell:
drop/take(existing, regression tested) - LLVM not yet supported (requires IR-level changes)
-
F-string format specifications (all 7 backends)
- Numeric precision:
f"{x:.2f}",f"{x:.4e}" - Integer formatting:
f"{n:d}",f"{n:x}",f"{n:X}",f"{n:o}" - Shared utilities:
extract_format_spec()andformat_spec_to_printf()inconverter_utils.py - C/C++: printf-style
%.2f/snprintfformatting - Go: Printf verbs in
fmt.Sprintf(%.2f,%x) - Rust:
format!macro with:{spec}syntax (:.2,:x) - Haskell:
Text.Printf.printfwith printf-style format strings - OCaml:
Printf.sprintfwith printf-style format strings - Conversion flags (
!r,!s,!a) remain unsupported
- Numeric precision:
-
finallyclause for try/except (all 7 backends)try/except/finallyblocks now accepted by the validator- C++: Finally body emitted sequentially after try/catch block
- C: Finally body emitted after
MGEN_END_TRYmacro - Go:
defer func(){}()block for cleanup semantics - Rust: Finally body emitted after
catch_unwindmatch block - Haskell: Finally body emitted after
catchexpression - OCaml: Finally body emitted after
try/withexpression
-
elseclause for try/except (all 7 backends)try/except/elseblocks now accepted by the validator- Else body appended to end of try body (runs only when no exception raised)
- All 7 backends: C++, C, Go, Rust, Haskell, OCaml emit else body with comment marker
- Combined
try/except/else/finallyfully supported
-
String slicing (6/7 backends)
s[1:3],s[1:],s[:2]on string variables now work- C++:
s.substr(start, length)-- detectsstd::stringtype from variable context - Rust:
s[start..stop].to_string()-- detectsStringtype from variable types - OCaml:
String.sub s start length-- detectsstrtype from parameter/variable tracking - Go: Native
s[start:stop]-- works identically to list slicing - Haskell:
drop/take-- strings are[Char], same as list slicing - C:
mgen_substring(s, start, length)-- detectschar*type - LLVM not yet supported (requires IR-level changes)
-
68 new tests in
tests/test_check_slice_fspec_finally.pyTestCheckCommand(5 tests): CLI parser, valid/invalid/missing file handling, multi-fileTestSlice*(14 tests): Validation + list slicing code generation for 6 backendsTestFStringFormatSpec*(17 tests): Validation + code generation for all 7 backendsTestFinally*(9 tests): Validation + code generation for all 7 backendsTestStringSlice*(9 tests): String slicing for C++, Go, Rust, OCaml, HaskellTestElse*(10 tests): Validation + else clause code generation for all 7 backendsTestElseValidation(3 tests): else valid, else+finally valid, chaining still rejected
Changed
-
Test count: 1285 -> 1353 (68 new tests, 2 updated from rejection to acceptance)
-
Validator: F-string
format_specno longer rejected; validated against supported spec patterns -
Validator:
finallyandelseclauses no longer rejected; exception handling now fully supported -
Validator: Exception handling constraints updated:
["No exception chaining (raise ... from ...)"] -
Validator: Added
_extract_format_spec_string()and_is_supported_format_spec()helper methods -
CLI: New
checksubcommand added alongsideconvert,build,batch,clean,backends -
OCaml backend: Function parameter types now tracked in
self.variablesfor type-aware slicing -
Documentation migrated from Sphinx to MkDocs (Material theme)
- All 11 RST files converted to Markdown with updated content
mkdocs.ymlwith Material theme, mkdocstrings for API docs, full nav- 19 existing reference/technical docs integrated into nav
make docs/make docs-serve/make docs-deploytargets updatedpyproject.tomldependencies: sphinx -> mkdocs/mkdocs-material/mkdocstringssite/added to.gitignore- Old
docs/sphinx/directory removed
Removed
- 17 stale/historical doc files cleaned up from
docs/anddocs/dev/