def transpile(source, transpiler): """ Transpile a single python translation unit (a python script) into Rust code. """ tree = ast.parse(source) add_variable_context(tree) add_scope_context(tree) add_list_calls(tree) infer_meta = infer_types(tree) detect_mutable_vars(tree) detect_nesting_levels(tree) add_annotation_flags(tree) add_imports(tree) out = [] code = transpiler.visit(tree) + "\n" headers = transpiler.headers(infer_meta) if headers: out.append(headers) usings = transpiler.usings() if usings: out.append(usings) out.append(code) return "\n".join(out)
def transpile(source): """ Transpile a single python translation unit (a python script) into Kotlin code. """ tree = ast.parse(source) add_variable_context(tree) add_scope_context(tree) add_list_calls(tree) detect_mutable_vars(tree) add_annotation_flags(tree) add_imports(tree) transpiler = KotlinTranspiler() return transpiler.visit(tree)