RubyWrite: A Ruby-Embedded Domain-Specific Language for High-Level Transformations Andrew Keep, Arun Chauhan, Chun-Yu Shei, and Pushkar Ratnalikar Indiana University, Bloomington, IN 47405, USA {akeep,achauhan,cshei,pratnali}@cs.indiana.edu Abstract. We introduce a Domain Specific Language (DSL), called RubyWrite, embedded within Ruby, with the goal of providing an ex- tensible, effective, portable, and easy to use framework for encoding source-level transformations. Embedding within Ruby provides access to the powerful features of Ruby, including its purely object-oriented design and meta-programming capabilities. The syntactic flexibility and advanced language features of Ruby drove our choice of it as the host lan- guage. Easy integration of external C interfaces seamlessly within Ruby lets us move performance critical operations to C, or link with external libraries. RubyWrite was developed to aid our compiler research where it provides the core of three compiler infrastructure development projects, and is used as a teaching aid in a graduate-level compilers course. We expect RubyWrite to be widely applicable and a proof of concept in leveraging an existing modern language to write a portable compiler in- frastructure core. 1 Introduction We describe a Domain Specific Language (DSL), embedded within Ruby, aimed at simplifying the task of source-level transformations through term-rewriting. The DSL, called RubyWrite, is motivated by the need for a compiler development environment that allows easy integration of source-level transformations with program analysis. After spending frustrating months trying to develop a compiler for matlab in C++ a few years ago, we made the decision to move to a domain-specific lan- guage for compiler development. The development experience in C++ had been excruciatingly slow and error-prone. After a pilot study, Stratego/XT [1] was se- lected as an appropriate language, due to its powerful term-rewriting capabilities, clean and compact syntax, and built-in support for data flow analysis. It resulted in an immediate order of magnitude productivity gain in our development ef- fort. It also proved to be an effective teaching aid in a graduate-level compilers course, letting students implement advanced compiler techniques within class assignments—something that would have been unthinkable in a general-purpose language like C++ without substantial preparatory efforts. As the compiler development effort in our research group progressed, the analysis became more and more sophisticated. We needed static-single assign- ment form, dependence analysis, and advanced memory-behavior analysis, all