
Saturday, December 30, 2006
Thursday, October 26, 2006
Declarative, Formal, and Extensible Syntax Definition for AspectJ
Aspect-Oriented Programming (AOP) is attracting attention from both research and industry, as illustrated by the ever-growing popularity of AspectJ, the de facto standard AOP extension of Java. From a compiler construction perspective, AspectJ is interesting as it is a typical example of a compositional language, i.e., a language composed of a number of separate languages with different syntactical styles: in addition to plain Java, AspectJ includes a language for defining pointcuts and one for defining advices. Language composition represents a non-trivial challenge for conventional parsing techniques. First, combining several languages with different lexical syntax leads to considerable complexity in the lexical states to be processed. Second, as new language features for AOP are being explored, many research proposals are concerned with further extending the AspectJ language, resulting in a need for an extensible syntax definition.
This paper shows how scannerless parsing elegantly addresses the issues encountered by conventional techniques when parsing AspectJ. We present the design of a modular, extensible, and formal definition of the lexical and context-free aspects of the AspectJ syntax in the Syntax Definition Formalism SDF, which is implemented by a scannerless, generalized-LR parser (SGLR). We introduce grammar mixins as a novel application of SDF's modularity features, which allows the declarative definition of different keyword policies and combination of extensions. We illustrate the modular extensibility of our definition with syntax extensions taken from current research on aspect languages. Finally, benchmarks show that the performance of scannerless generalized-LR parsing for this grammar is comparable to the parser of abc.
Thursday, August 03, 2006
From Vertical to Horizontal Compilation?
After getting rid of nested functions, the next issue on my agenda is to refactor the Stratego compiler to provide a compilation library that offers translation strategies that can be applied to single definitions and that can be composed to form both horizontal and vertical compilers. The first goal of the operation is to improve the performance of the Stratego compiler by eliminating intermediate ATerm files and by increasing the locality of the operations; instead of traversing the entire program for each stage, apply all stages to a single definition, before moving to the next. In the longer term, this refactoring should enable the combination of interpreted, statically compiled, and run-time compiled code. Furthermore, it should facilitate the creation of an open compiler for Stratego that supports languages extension libraries.
The catch of course is in the compositionality of the compilation process. While many stages of the compiler can easily be applied per definition, or are even based on local rewriting, there are several stages that require the whole program. One example, is the stage that combines definitions with the same name into a single definition. A compositional compilation will require a scheme that allows the union of such definitions at link time. Another example, is the 'lifting of dynamic rules', which requires awares of all dynamic rule definition sites in a program to prevent generation of duplicate definition. Turning these operations into 'horizontal' ones may require some new (intermediate) language constructs or meta-data that can be consulted when joining program fragments. Such considerations will no doubt guide the design of a better module system for Stratego. More later.
Getting rid of nested functions
The second part of the renovation was to get rid of nested functions in the generated C code. After a year I have finally managed to finish this part of the renovation. In this blog I'll explain the old and new compilation schemes.
At the same time as the setjmp/longjmp were introduced in the Stratego compiler (somewhere in 2001), I discovered that gcc supported nested functions in C. The following example illustrates why this was a useful feature.
The strategy bottomup
is defined as follows:
bottomup(s) = all(bottomup(s)); sA recursive invocation of
bottomup(s)
is passed to the one-level traversal
operator all
.
In the generated C code, strategy operators are implemented as functions that take a function
pointer as argument. For instance, the all
operator is implemented by the function
SRTS_all
with signature
ATerm SRTS_all(ATerm f(ATerm), ATerm);However, a strategy expression such as
bottomup(s)
is clearly not something with
a function pointer. Therefore, the compiler lifts such expressions from argument positions into
local definitions. Thus, the definition of bottomup
is rewritten to:
bottomup_1_0(e_1 : ATerm() -> ATerm()|) = let a_0(|) = bottomup_1_0(e_1|) in all(a_0|) end ; e_1Now the argument of
all
is just a function name, which can be translated
as passing a function pointer. The definition of a_0
has to be nested in the definition of bottomup
since it refers to the argument e_1
of
that definition.
Nested functions in C provide a very convenient feature for translating such local definitions.
A nested function is an ordinary C function that is defined within the scope of another C function. Thus, it can refer to all arguments and local variables of the enclosing function. This
enables a straightforward implementation of local definitions in Stratego; a local definition is
replaced with a nested function. Using this approach the rewritten definition of bottomup
above is translated as follows:
ATerm bottomup_1_0 (ATerm e_1 (ATerm), ATerm t) { auto ATerm a_0 (ATerm t); ATerm a_0 (ATerm t) { t = bottomup_1_0(e_1, t); if((t == NULL)) goto fail_1 ; return(t); fail_1 : return(NULL); } t = SRTS_all(a_0, t); if((t == NULL)) goto fail_0 ; t = e_1(t); if((t == NULL)) goto fail_0 ; return(t); fail_0 : return(NULL); }While nested functions make the translation of nested definitions straightforward, they posed several problems. In the first place, nested functions are only supported by gcc, reducing the portability of code generated by the Stratego compiler.
Secondly, nested functions in gcc are implemented by means of trampolines, a small piece of code that is generated at run-time and stored on the stack. This code essentially stores the closure of the nested function, that is, a pointer to the actual function and (pointers to) the variables in the enclosing stack-frame(s) to which it has access. The problem with this implementation is that it executes code stored on the stack, which is forbidden on more and more platforms, as it poses a security risk. Thus, we were confronted with users not being able to use Stratego/XT on some platforms.
Finally, the implementation of nested functions in gcc does not have a high priority with gcc developers, which caused build failures for the Stratego/XT distribution with some versions of gcc, especially on MacOSX.
While nested functions were quite convenient, they had to go and be replaced with an explicit
mechanism for handling closures. The mechanism chosen was to use static links to reach stack
frames of enclosing functions and an explicit closure data-structure to represent a function
pointer with its environment. For example, in the new translation scheme, the signature of the SRTS_all
operator becomes:
ATerm SRTS_all(StrSL sl, StrCL s, ATerm t)
StrSL
represents static links and StrCL
is the type of closures.
Locally defined strategies are now translated to top-level (static) functions and an explicit
closure is allocated in the enclosing function. Thus, the bottomup
strategy
is translated to the following pair of C functions:
ATerm bottomup_1_0 (StrSL sl, StrCL e_1, ATerm t) { sl_decl(sl); sl_funs(1); sl_init_fun(0, e_1); { struct str_closure a_0 = { &(lifted_0) , &(frame) }; StrCL lifted_0_cl = &(a_0); t = SRTS_all(sl, lifted_0_cl, t); if((t == NULL)) goto fail_1 ; t = cl_fun(e_1)(cl_sl(e_1), t); if((t == NULL)) goto fail_1 ; } return(t); fail_1 : return(NULL); } static ATerm lifted_0 (StrSL sl, ATerm t) { sl_decl(sl); t = bottomup_1_0(sl_up(sl), sl_fun_cl(0, sl), t); if((t == NULL)) goto fail_2 ; return(t); fail_2 : return(NULL); }The declaration
struct str_closure a_0 = { &(lifted_0) , &(frame) };allocates a closure consisting of a pointer to the function
lifted_0
and
a pointer to the current frame
, which is an explicit data-structure in
which escaping functions and variables are stored. The frame
variable is
declared by the macro sl_decl
at the start of the bottomup_1_0
function. A pointer to this closure (lifted_0_cl
) is passed to the invocation of SRTS_all
.
Note that a call to a function passed as a closure needs unwrapping of the closure into a function pointer and a static link:
t = cl_fun(e_1)(cl_sl(e_1), t);While I started the implementation of this new translation scheme already in September 2005, I didn't get around to finishing it until yesterday. We spent a large effort last Fall to get the documentation of Stratego/XT in better shape, and after that I was busy teaching and doing god knows what, but it was not hacking the Stratego compiler.
With this stumbling block out of the way, the door is open to a whole new set of innovations to the compiler and the Stratego language. A better module system is high on the wish list. Also we want to move from a separation of the compiler in phases to a compiler library that will allow larger parts of the compilation process to be applied to a single definition and elimination of intermediate ATerm files.
Wednesday, July 05, 2006
Learn Stratego/XT at OOPSLA/GPCE
In this tutorial we give an overview of techniques for program transformation, illustrated through the Stratego/XT program transformation system. We explain the general architecture of transformation systems, and how Stratego/XT is used to assemble such systems from components. We introduce a set of ready made components for Java transformation, and show how to program custom transformation components using Stratego. In particular, we show how to express local transformations using rewrite rules and strategies and how context-sensitive transformations can be expressed easily using dynamic rewrite rules. All techniques and language features are illustrated with implementations of transformations on Java programs, that show how to apply all introduced techniques in practice.
See also the page on the GPCE'06 site.
Partial Evaluation and (Semantics-based) Program Manipulation
Last year PEPM broadened its mission from a narrow focus on partial evaluation techniques and applications, to all topics concerned with analysis and manipulation of programs. In particular, the aim is to attract work that applies such techniques to real languages and large code bases. That is, not just design of clever techniques, but also validation of these techniques in practice. The website provides extensive advice for authors of research and tool presentation papers.
- Program and model manipulation techniques such as transformations driven by rules, patterns, or analyses, partial evaluation, specialization, slicing, symbolic execution, refactoring, aspect weaving, decompilation, and obfuscation.
- Program analysis techniques that are used to drive program/model manipulation such as abstract interpretation, static analysis, binding-time analysis, dynamic analysis, constraint solving, and type systems.
- Analysis and transformation for programs/models with advanced features such as objects, generics, ownership types, aspects, reflection, XML type systems, component frameworks, and middleware.
- Techniques that treat programs/models as data objects including meta-programming, generative programming, staged computation, and model-driven program generation and transformation.
- Application of the above techniques including experimental studies, engineering needed for scalability, and benchmarking. Examples of application domains include legacy program understanding and transformation, domain-specific language implementations, scientific computing, middleware frameworks and infrastructure needed for distributed and web-based applications, resource-limited computation, and security.
We especially encourage papers that break new ground including descriptions of how program/model manipulation tools can be integrated into realistic software development processes, descriptions of robust tools capable of effectively handling realistic applications, and new areas of application such as rapidly evolving systems, distributed and webbased programming including middleware manipulation, model-driven development, and on-the-fly program adaptation driven by run-time or sttistical analysis.
Friday, June 30, 2006
From Natural Semantics to Stratego

Career Evolution (Moving to Delft)
![]() |
=> |
![]() |
Model-Driven Software Evolution
If you have an interest in program transformation and domain-specific languages, and the ambition to contribute to the state-of-the-art in these areas, then you might consider applying for one of these jobs. Official job adverts will be available later (we really just learned about acceptance), but in the mean time you can contact me if you have questions.
Here is the summary of the research proposal:
The promise of model-driven engineering (MDE) is that the development and maintenance effort can be reduced by working at the model instead of the code level. Models define what is variable in a system, and code generators produce the functionality that is common in the application domain.
The problem with model-driven engineering is that it can lead to a lock-in in the abstractions and generator technology adopted at project initiation. Software systems need to evolve, and systems built using model-driven approaches are no exception. What complicates model-driven engineering is that it requires multiple dimensions of evolution. In regular evolution, the modeling language is used to make the changes. In meta-model evolution, changes are required to the modeling notation. In platform evolution, the code generators and application framework change to reflect new requirements on the target platform. Finally, in abstraction evolution, new modeling languages are added to the set of (modeling) languages to reflect increased understanding of a technical or business domain. While MDE has been optimized for regular evolution, presently little or no support exists for metamodel, platform and abstraction evolution. It is this gap that this project proposes to address.
The first fundamental premise of this proposal is that evolution should be a continuous process. Software development is a continuous search for recurring patterns, which can be captured using domain-specific modeling languages. After developing a number of systems using a particular meta-model, new patterns may be recognized that can be captured in a higher-level or richter meta-model. The second premise is that reengineering of legacy systems to the model-driven paradigm should be a special case of this continuous evolution, and should be performed incrementally.
The goal of this project is to develop a systematic approach to model-driven software evolution. This approach includes methods, techniques, and underlying tool support. We will develop a prototype programming environment that assists software engineers with the introduction, development, and maintenance of models and domain-specific languages.
Friday, May 12, 2006
Software Transformation Systems
Wednesday, May 10, 2006
Transformations for Abstractions (Looking for a Postdoc or PhD student)
This proposal is about techniques at the intersection of two areas of software engineering. (1) In order to automate software engineering we would like to automate the process of producing programs by means of automatic transformations, thereby computing with programs as we do with other data. (2) In order to improve the expressivity of programming languages to the concepts and notations of specific application domains, we would would like to extend general-purpose languages with domain-specific abstractions. Combining these desiderata leads to the need to extend transformations for new domain-specific abstractions.
The goal of this project is to develop a systematic approach to the extension of general purpose languages with domain-specific abstractions, integrating those abstractions in the syntax and transformations of the programming environment. This requires research into the following issues:
- strategies for the definition of domain abstractions
- mechanisms for open extensibility of transformations
- methods and patterns for design of open transformations
- constraints for independent extensibility of transformations
- derivation of transformation extensions from definitions of abstractions
If you are interested in the project, either as a candidate for the position or as a collaborator, I would like to hear from you. Further information (such as the full project proposal) is available on request.
Sunday, May 07, 2006
Image Transformation
![]() |
=> |
![]() |
=> |
![]() |



