Heterogeneous Multi-Stage Programming

semanticscholar(2005)

引用 0|浏览0
暂无评分
摘要
Previous work on semantics-based multi-stage programming (MSP) language design focused on homogeneous designs, where the generating and the generated languages are the same. Homogeneous designs simply add a hygienic quasi-quotation and evaluation mechanism to a base language. An apparent disadvantage of this approach is that the programmer is bound to both the expressivity and performance characteristics of the base language. This paper proposes a practical means to avoid this by providing specialized translations from subsets of the base language to different target languages. This approach preserves the homogeneous " look " of multi-stage programs, and, more importantly, the static guarantees about the generated code. In addition, compared to an explicitly heterogeneous approach, it promotes reuse of generator source code and systematic exploration of the performance characteristics of the target languages. This is a revised version based on a conference paper of the same title 4). To illustrate the proposed approach, we design and implement a translation to a subset of C suitable for numerical computation, and show that it preserves static typing. The translation is implemented, and evaluated with several benchmarks. The implementation is available in the online distribution of MetaOCaml. Multi-stage programming (MSP) languages allow the programmer to use abstraction mechanisms such as functions, objects, and modules, without having to pay a runtime overhead for them due to the generation of specialized code. Operationally, these languages provide quasi-quotation and eval mechanisms similar to those of LISP and Scheme. In addition, to avoid accidental capture, bound variables are always renamed, and values produced by quasi-quotes can only be de-constructed by eval. This makes reasoning about quoted terms as programs sound 18) , even in the untyped setting. Several type systems have been developed that statically ensure that all programs generated using these constructs are well-typed (see for example 19, 1)). Currently, the main examples of MSP languages include MetaScheme 7) , MetaML 20) , MetaOCaml 10) , and Metaphor 11). They are based, respectively, on Scheme, Standard ML, OCaml, and Java/C#. In all these cases, the language design is homogeneous, in that quoted values are fragments of the base language. Homogeneity has three distinct advantages. First, it is convenient for the language designer, as it often reduces the size of the definitions needed to model a language, and makes extensions to arbitrary stages feasible at little cost. Second, it is convenient for the language implementor, as it allows the implementation …
更多
查看译文
AI 理解论文
溯源树
样例
生成溯源树,研究论文发展脉络
Chat Paper
正在生成论文摘要