Abstract
Automated program translation remains a significant challenge in software engineering, requiring a balance between behavioral correctness, scalability to large codebases, and the generation of idiomatic, maintainable code. Traditional compilers often prioritize scalability at the expense of readability, while modern Large Language Models (LLMs) produce idiomatic code that frequently suffers from correctness issues as program size increases. This paper introduces Skel, a framework that utilizes "program skeletons" to decompose the translation task. By separating high-level program structure from low-level implementation fragments and enforcing local semantic requirements, Skel achieves high automation rates and maintains correctness across real-world Python-to-JavaScript migrations.
1. Introduction
Translating legacy codebases—such as migrating a Python library to a modern JavaScript environment—is a complex task. The primary difficulty lies in a "trilemma": the resulting code must be correct (behaviorally equivalent), scalable (applicable to large programs), and idiomatic (readable and maintainable).
Existing solutions typically fall into two camps. Rule-based compilers are scalable but often produce non-idiomatic, "bogus" code that is difficult for humans to maintain. Conversely, LLMs excel at generating idiomatic code but struggle with the "compound effect" of errors; a minor hallucination in a single function can propagate through a large codebase, making debugging nearly impossible. Skel addresses these issues by decomposing the translation process into verifiable, local tasks.
2. Methodology
The core innovation of the Skel framework is the Program Skeleton, which serves as a structural blueprint for the translation. The framework operates through four primary components:
2.1 SkelCR: Intermediate Representation
Skel extracts a high-level syntactic skeleton from the source Python code using an intermediate representation called SkelCR. This skeleton captures function signatures, class structures, and lexical scopes—elements that generally share structural similarities between Python and JavaScript—while leaving the specific logic of code fragments as "holes" to be filled.
2.2 ProcEmu: The Semantic Model
To handle complex API calls and logic, Skel treats each code fragment as a standalone "communicating process." The ProcEmu component records the observable effects of these fragments during execution, including input parameters, return values, and external function calls. This creates a precise semantic specification for each fragment.
2.3 Execution-Order Translation (EOT) Loop
The EOT loop serves as the system's orchestration engine. It iterates through the program's execution path, identifying missing fragments and prompting an LLM to synthesize the corresponding JavaScript code. The synthesis is constrained by the observable effects recorded by ProcEmu, ensuring the new fragment fits the original program's logic.
2.4 Spot-Checking and Refinement
Skel employs a refinement loop inspired by Counter-Example Guided Inductive Synthesis (CEGIS). If a synthesized fragment fails to match the source's behavior during execution, the system provides the LLM with a counterexample and requests a correction. This ensures that errors are isolated and resolved locally before they can affect the broader system.
3. Experimental Evaluation
The authors evaluated Skel using nine real-world Python programs. The dataset included five modules from existing neural translation benchmarks (ranging from 121 to 882 lines of code) and four larger, diverse programs sourced from GitHub. These new additions, including a TOML parser and the py-evtx Windows event log parser, reached up to 2,400 lines of code, representing a significant increase in scale over typical academic benchmarks.
4. Key Results
Skel demonstrated superior performance compared to end-to-end LLM approaches and standard divide-and-conquer methods:
- High Automation: Across 466 functions, Skel achieved a 95% automation rate using GPT-4 as the synthesis backend.
- Zero-Touch Success: Four out of the nine programs were translated successfully with zero human intervention, passing all original test suites.
- Error Isolation: Compared to a standard LLM approach that required manual intervention for over 93 functions, Skel only required 23 manual fixes across the entire dataset.
- Scalability: The framework successfully handled programs nearly 20 times larger than those found in traditional neural translation research.
5. Discussion and Limitations
The success of Skel stems from the Indistinguishability Principle: a translated fragment does not need to be a literal line-for-line copy, provided its external behavior is indistinguishable from the source. This allows the LLM to use idiomatic target-language features, such as replacing complex Python loops with JavaScript's Array.forEach.
However, some limitations remain. Currently, Skel relies on default type mappings (e.g., Python List to JavaScript Array), which may not always be optimal. Additionally, APIs with opaque side effects (like I/O operations) require manual "shims" to be modeled correctly. Finally, complex language-specific features like multiple inheritance in Python do not always have direct structural equivalents in JavaScript, requiring pre-translation refactoring.
6. Conclusion
By transforming a monolithic translation problem into a series of small, verifiable tasks, Skel provides a robust roadmap for automated code migration. The framework successfully bridges the gap between the structural reliability of compilers and the idiomatic flexibility of LLMs, enabling the scalable translation of real-world software.
Summary updated