A Bytecode-Compiled, Type-safe, Multi-Stage Language

Inspired by the su esses of program generation, partial evaluation, and runtime ode generation, multi-stage languages were developed as a uniform, high-level, and prin ipled view of staging. Our urrent goal is to demonstrate the utility of these languages in a pra ti al implementation. As a rst step this paper presents MetaOCaml, a type-safe, multi-stage language, built as an extension to OCaml's byteode ompiler. Future-stage omputations are represented as sour e programs. This makes it possible to ensure typesafety, produ e better dynami ally ompiled ode, and apply ru ial runtime sour e-to-sour e transformations su h as tag elimination. We have used MetaOCaml to measure performan e for a set of small staged programs. The gains are onsistent with those of partial evaluation and runtime ode generation, and support the laim that multi-stage languages are well-suited for building staged interpreters, even when the runtime ompilation times are taken into a ount.