Date of Award

Spring 1-1-2013

Document Type

Dissertation

Degree Name

Doctor of Philosophy (PhD)

Department

Electrical, Computer & Energy Engineering

First Advisor

Jeremy Siek

Second Advisor

Bor-Yuh Evan Chang

Third Advisor

Jaakko Jarvi

Fourth Advisor

Sriram Sankaranarayanan

Fifth Advisor

Fabio Somenzi

Abstract

Reflective Metaprogramming is capable of inspecting code, enables us to write templates, and can automatically instantiate templates according to the meta information obtained by reflection. Reflective metaprogramming supports the writing of generic and reusable software components. However, there are the challenges of designing a reflective metaprogramming language. One challenge is the design of the type system: in a language with type-reflective metaprogramming, type expressions in the residual program may be the result of meta computation, making the type system difficult to guarantee that the residual code in a metaprogram is statically type safe without sacrificing language expressiveness. Another challenge is the deign of reflective metaprogramming language. Some previous work proposed pattern-based reflection for inspecting and generating class members, but with limited ways that generated declarations can be composed.

In this thesis, we present incremental type-checking for reflective metaprograms. It detects errors earlier than C++ templates without sacrificing flexibility: we incrementally type check code fragments as they are created and spliced together during meta computation. We use type variables to represent type expressions that are not yet normalized and a new dynamic variation on existential types to represent residual code fragments. A type error in a code fragment is treated as a run-time error of the meta computation.

In this thesis, we present pattern-based traits, a language design, embodied in PTFJ (Pattern-based Traits for Featherweight Java), that combines pattern-based reflection with the expressiveness of trait composition. Pattern-based traits can group, name, and manipulate sets of member declarations. Parameterizing traits over such sets can further increase the expressiveness of pattern-based reflection.

Share

COinS