pub struct PythonBackend {
pub module: PythonModule,
pub fn_map: HashMap<String, String>,
pub fresh_counter: usize,
}Expand description
Python code generation backend.
Compiles LCNF function declarations to a PythonModule containing
Python 3.10+ code with type hints.
Fields§
§module: PythonModuleThe module being built.
fn_map: HashMap<String, String>Mapping from LCNF names to mangled Python names.
fresh_counter: usizeCounter for generating fresh temporary variable names.
Implementations§
Source§impl PythonBackend
impl PythonBackend
Sourcepub fn mangle_name(&self, name: &str) -> String
pub fn mangle_name(&self, name: &str) -> String
Mangle an LCNF name into a valid Python identifier.
Rules:
- Replace
.with_ - Replace
'(prime) with_prime - Replace
-with_ - Prefix Python reserved words with
_
Sourcepub fn compile_module(decls: &[LcnfFunDecl]) -> Result<String, String>
pub fn compile_module(decls: &[LcnfFunDecl]) -> Result<String, String>
Top-level entry point: compile a slice of LCNF function declarations into a Python module string.
Sourcepub fn compile_decl(
&mut self,
decl: &LcnfFunDecl,
) -> Result<PythonFunction, String>
pub fn compile_decl( &mut self, decl: &LcnfFunDecl, ) -> Result<PythonFunction, String>
Compile a single LCNF function declaration into a PythonFunction.
Sourcepub fn emit_module(&self) -> String
pub fn emit_module(&self) -> String
Emit the compiled module as a Python string.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PythonBackend
impl RefUnwindSafe for PythonBackend
impl Send for PythonBackend
impl Sync for PythonBackend
impl Unpin for PythonBackend
impl UnsafeUnpin for PythonBackend
impl UnwindSafe for PythonBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more