Hey everyone! π
I wanted to share a project I've been pouring my heart into: Astmize. It's an open-source Python-to-C++ transpiler built entirely from my mobile phone (using mobile editors since I don't own a PC at the moment).
Instead of using basic regex or string replacement, Astmize parses Python code into an Abstract Syntax Tree (AST) and maps the logical nodes directly into structurally equivalent, clean C++ code.
π The C++ Design Bottleneck I Had to Solve
While developing the transpiler from my screen, I hit a massive roadblock regarding type emission. As we know, C++ is statically typed and strictly forbids using auto for non-static class data members without a direct initialization expression, because the compiler must determine the exact object memory layout at compile time.
In Python, fields are dynamically assigned inside __init__ via arguments (e.g., self.speed = speed). Initially, my compiler emitted auto speed; inside the generated C++ class struct, leading to immediate compilation failures.
π‘ The Solution: Smart Type Inference Engine
To fix this from my phone, I implemented a custom Type Inference Engine in the Python backend that utilizes three core heuristics:
- RHS Node Evaluation: Evaluates the Right-Hand Side assignment node to detect concrete primitive constants or explicit type initializers.
-
Variable Tokenization: Automatically splits attribute names by underscores and parses individual tokens against an explicit C++ type keyword library (e.g., detecting
is_orhas_prefixes infers abool; tokenizingplayer_speedmapsspeedtoint). -
Safe Fallback Mechanism: If the type remains completely ambiguous, it safely defaults to
intinstead of emitting an illegalauto, ensuring structural layout validity and preventing compilation blocks.
The live dashboard integrates with standard GCC/Clang via the Wandbox API to compile and run the generated C++ code instantly on the fly.
π Check it out here:
- Live Web App: https://thespacetimedebugger.github.io/Astmize/
- GitHub Repository: https://github.com/TheSpacetimeDebugger/Astmize.git
I'd absolutely love to get your feedback on the generated C++ structure, how you handle strict type emission in metaprogramming/transpilers, and if there are any C++ edge cases I should guard against!
Drop a β on GitHub if you find the concept interesting! Happy coding! π

Top comments (0)