🤖 AI Summary
Shallow embedding of macros in host languages like Scheme suffers from poor compile-time performance and limited extensibility. This paper proposes a hybrid embedding approach based on *micros*: source-language syntax is first translated into an intermediate representation (IR) via micros, thereby combining the semantic rigor of deep embedding with the expressive flexibility of shallow embedding. The IR design adopts scalable patterns and abstraction encapsulation mechanisms, enabling dynamic extension of both the IR and its associated operations. To our knowledge, this is the first approach to achieve both high compilation performance and strong language extensibility in static-type-language compilation. Experimental evaluation on the Racket platform demonstrates that our method significantly outperforms conventional macro-based embedding in compilation speed while preserving excellent language extensibility.
📝 Abstract
Macro embedding is a popular approach to defining extensible shallow embeddings of object languages in Scheme like host languages. While macro embedding has even been shown to enable implementing extensible typed languages in systems like Racket, it comes at a cost: compile-time performance. In this paper, we revisit micros - syntax to intermediate representation (IR) transformers, rather than source syntax to source syntax transformers (macros). Micro embedding enables stopping at an IR, producing a deep embedding and enabling high performance compile-time functions over an efficient IR, before shallowly embedding the IR back into source syntax. Combining micros with several design patterns to enable the IR and functions over it to be extensible, we achieve extensible hybrid embedding of statically typed languages with significantly improved compile-time compared to macro-embedding approaches. We describe our design patterns and propose new abstractions packaging these patterns.