Papers
Topics
Authors
Recent
Search
2000 character limit reached

Program Skeletons for Automated Program Translation

Published 10 Apr 2025 in cs.PL and cs.SE | (2504.07483v2)

Abstract: Translating software between programming languages is a challenging task, for which automated techniques have been elusive and hard to scale up to larger programs. A key difficulty in cross-language translation is that one has to re-express the intended behavior of the source program into idiomatic constructs of a different target language. This task needs abstracting away from the source language-specific details, while keeping the overall functionality the same. In this work, we propose a novel and systematic approach for making such translation amenable to automation based on a framework we call program skeletons. A program skeleton retains the high-level structure of the source program by abstracting away and effectively summarizing lower-level concrete code fragments, which can be mechanically translated to the target programming language. A skeleton, by design, permits many different ways of filling in the concrete implementation for fragments, which can work in conjunction with existing data-driven code synthesizers. Most importantly, skeletons can conceptually enable sound decomposition, i.e., if each individual fragment is correctly translated, taken together with the mechanically translated skeleton, the final translated program is deemed to be correct as a whole. We present a prototype system called Skel embodying the idea of skeleton-based translation from Python to JavaScript. Our results show promising scalability compared to prior works. For 9 real-world Python programs, some with more than about 1k lines of code, 95% of their code fragments can be automatically translated, while about 5% require manual effort. All the final translations are correct with respect to whole-program test suites.

Summary

  • The paper introduces a novel method using program skeletons to abstract high-level code structure for translating Python to JavaScript.
  • It employs a synthesis process with an Execution-order Translation loop to validate fragment correctness incrementally.
  • The framework integrates type mapping and semantic checks, demonstrating scalability and automation advancements in code translation.

Program Skeletons for Automated Program Translation

The paper "Program Skeletons for Automated Program Translation" presents an innovative approach to address the long-standing challenge of code translation across programming languages. It introduces the concept of "program skeletons" to facilitate automated translation while maintaining idiomatic programming practices in the target language.

Introduction to Program Skeletons

Program skeletons abstract away the lower-level details of the source code while preserving the high-level structure. This abstraction is crucial for converting programs from one language to another, especially when they exhibit syntactic and semantic differences. The skeleton retains the core structure and inserts placeholders for the actual code fragments, which are later synthesized to fit the target language.

Figure 1: An illustrative program skeleton demonstrating high-level source code abstraction.

Figure 1

Figure 1: An illustrative program skeleton retaining core program structure with placeholders.

Skeleton-Based Translation Framework

The proposed framework is embodied in a system called Skel, which automates the translation of Python programs into JavaScript. Skel operates by maintaining the overall syntactic structure and utilizing existing code synthesizers to fill in the placeholders.

Figure 2: An example Python program and its JavaScript translation, highlighting parallel structures.

Figure 2

Figure 2: Syntactic similarity at the lexical scope level between Python and JavaScript.

The core idea involves a sound decomposition of the translation task: if each placeholder is correctly filled, the combined program ensures correctness. Skel uses this decomposition to scale up translation capabilities, effectively handling large programs.

Execution and Process Modelling

Skel employs a conceptual model where the program execution is represented as a series of "processes” communicating via messages. This model enables capturing the observable effects of code fragments, which form the basis of the semantic requirements for placeholders.

Figure 3: A graph representation of the syntactic structure showing a program's skeleton.

Figure 3

Figure 3: Graphical depiction of the syntactic structure highlighting lexical scopes and relations.

The darkblue semantics model used in Skel ensures that fragment processes can be isolated and checked for correctness independently. This separation of concerns is key to leveraging modern LLMs for code synthesis.

Type Mapping and Semantic Specifications

Skel integrates a type mapping system to convert Python types into their JavaScript counterparts during translation. This mapping is pivotal in maintaining type consistency and enabling the semantic requirements to align with target language constructs.

Figure 4: Type mapping used by Skel for converting Python observable effects into JavaScript.

Figure 4

Figure 4: Illustration of type mapping for semantic conversion in program skeletons.

Synthesis and Refinement

The synthesis process uses an Execution-order Translation (EOT) loop where code fragments are incrementally synthesized and refined based on dynamic checks against the semantic requirements.

Figure 5: The EOT loop process for synthesizing and refining code fragments.

Figure 5

Figure 5: The EOT loop illustrating fragment verification and iterative refinement.

Skel performs step-by-step validation against semantic requirements, with each step refining the synthesized code until it meets the specified requirements.

Conclusion

The research presents a robust method for automated program translation through the use of program skeletons. By focusing on maintaining high-level structure and systematically filling in details using modern synthesizers, Skel showcases significant improvements in scalability and automation.

The implications for future developments in AI include potential advancements in automated code synthesis and program translation with broader applications across various languages and domains. While Skel demonstrates effectiveness on Python-to-JavaScript translations, the framework could be adapted to support additional language pairs, improving the automation of migration tasks in industry settings.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.

Tweets

Sign up for free to view the 2 tweets with 0 likes about this paper.