Skip to content

colswap/sm5-binary-translator

Repository files navigation

SM5 to Sonata Binary Translator ("SM5 RosettaX")

This project is a binary translator, inspired by Apple's Rosetta technology [cite: 1128, 1131-1132, 1138]. It implements a function rosettax that translates bytecode from one virtual machine (SM5) to another (Sonata) [cite: 1143-1144, 1173-1174].

Project Context

  • Course: 4190.310 Programming Languages (Spring 2025)
  • Institution: Seoul National University
  • Tech Stack: OCaml

The Challenge: Simulating Continuations

The core challenge of this project lies in the architectural difference between the two VMs:

  • SM5 (Source): A 5-component machine (S, M, E, C, K) that includes a dedicated K (Continuation) stack to manage function calls and returns[cite: 1149].
  • Sonata (Target): A 4-component machine (S, M, E, C) that has no K stack[cite: 1150].

Core Implementation

This translator, rosettax: Sm5.command -> Sonata.command [cite: 1173-1174], re-implements the K (Continuation) stack in software.

  • Continuation Management: It translates SM5's call and return (empty C) instructions [cite: 1151-1165] into a series of Sonata instructions.
  • Manual Stack Handling: The translator generates Sonata bytecode that manually saves and restores continuations (the "what to do next" code and environment) onto Sonata's main S (Stack) or M (Memory) [cite: 1166-1172].
  • Transparency: This allows SM5 programs, which rely on the K stack, to run "transparently to users" [cite: 1135] on the Sonata machine, which has no such feature.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published