Quick Start Guide¶
This guide walks you through your first MultiGen conversion.
Basic Conversion¶
Create a simple Python file fibonacci.py:
def fibonacci(n: int) -> int:
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
def main() -> None:
result: int = fibonacci(10)
print(f"Fibonacci(10) = {result}")
if __name__ == "__main__":
main()
Convert to C:
This generates fibonacci.c with a self-contained C implementation.
Validating Before Conversion¶
Check if your Python file is compatible with MultiGen:
This reports whether the file is valid, its tier level, and any violations -- without generating any code.
Building and Running¶
Compile with any C compiler:
Or let MultiGen generate a Makefile:
Supported Targets¶
Convert to different languages:
# C++
multigen convert -t cpp fibonacci.py
# Rust
multigen convert -t rust fibonacci.py
# Go
multigen convert -t go fibonacci.py
# Haskell
multigen convert -t haskell fibonacci.py
# OCaml
multigen convert -t ocaml fibonacci.py
# LLVM IR
multigen convert -t llvm fibonacci.py
Advanced Example¶
Create wordcount.py with more complex features:
from pathlib import Path
def count_words(text: str) -> dict[str, int]:
counts: dict[str, int] = {}
words: list[str] = text.lower().split()
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
return counts
def main() -> None:
path: Path = Path("input.txt")
text: str = path.read_text()
counts: dict[str, int] = count_words(text)
for word, count in counts.items():
print(f"{word}: {count}")
if __name__ == "__main__":
main()
Convert to Rust:
This demonstrates:
- File I/O (Path operations)
- Dictionaries with type inference
- String operations
- For-each loops
Next Steps¶
- Backend Guide -- Learn about backend-specific features
- Pipeline API -- API reference for programmatic use