A Domain-Specific Aspect Language for Transforming MATLAB Programs * João M. P. Cardoso Dep. Engenharia Informática Faculdade de Engenharia (FEUP) Universidade do Porto, Porto, Portugal jmpc@acm.org Pedro C. Diniz Dep. Engenharia Informática UTL/IST/INESC-ID Lisboa, Portugal pedro.diniz@ist.utl.pt Miguel P. Monteiro Dep. Informática Universidade Nova de Lisboa Monte de Caparica, Portugal mmonteiro@di.fct.unl.pt João M. Fernandes, João Saraiva Dep. Informática / CCTC Universidade do Minho Braga, Portugal {jmf,jas}@di.uminho.pt ABSTRACT Aspect-oriented programming provides powerful ways to augment programs with information out of the scope of the base language while avoiding harming code readability and thus portability. MATLAB is a popular modeling/programming language that will strongly benefit of aspect-oriented programming features. For instance, MATLAB programmers could use aspects to provide information such as restrictions on allowed data types and/or val- ues, monitoring specific aspects of the execution such as the effec- tive dataset sizes or if a given variable ever assumes a specific value, without “polluting” the code with “check code”. This paper describes the main concepts of a domain-specific aspect language (DSAL) for specifying transformations of MATLAB programs in view of supporting optimizations by facilitating the experimenta- tion of alternative implementations. This DSAL specifies aspect modules structured in three sections: intersections equivalent to AspectJ poincuts, actions equivalent to AspectJ advice, and con- ditions that control triggering of actions. Support for aspect com- position strategies and aspect parameterization of tokens from the base program are also supported. We believe the described fea- tures complement and enhance MATLAB programming in sub- stantial and valuable ways. Keywords Aspect-Oriented Programming, Strategic Programming, Domain- Specific Languages, MATLAB. 1. INTRODUCTION MATLAB [1] is an interpreted, imperative programming language mainly based on matrix-shaped double precision data types and operations on them. It is widely used in scientific computing, control systems, signal processing, image processing, system en- gineering and simulation. MATLAB relies heavily on matrix data types and provides some base parametric primitive data types such as integer and fixed-point variables. However, the flexibility of its interpretative nature also hinders performance, forcing program- mers to develop reference versions of the program functionality in languages such as C/C++, especially when targeting embedded systems. When doing so, programmers effectively freeze impor- tant decisions relating to specific data types and program structure thereby forsaking most of MATLAB’s flexibility. These unwar- ranted specializations are exacerbated by changing program re- quirements (e.g., power vs. performance) or target architecture features (e.g., CPU vs. GPU). Available MATLAB features and packages help programmers to focus on problem solving and allow high expressiveness when dealing with matrix computations, thus contributing to enhanced productivity. However, when it comes to evaluate specific features such as exploiting non-uniform fixed-point representations, moni- toring certain variables during a timing window, or to include handlers to watch specific behaviors, the programmer is over- whelmed by cumbersome, error-prone and tedious tasks. Each time these kinds of features are necessary, invasive changes on the original code are required, as well as the insertion of new code related to non-core concerns. This problem is felt in other imple- mentation issues as well, since MATLAB can be regarded as a specification rather than an implementation language. In previous work [2], we proposed aspect-oriented features to MATLAB to support monitoring of variable values, testing the use of alternative implementations, handling of specific condi- tions and specifying data types. Our current efforts focus on aug- menting the MATLAB programming methodology by using a DSAL with more powerful aspect-oriented concepts. Those con- cepts will allow the exploration of specific features within the system’s design and implementation space, debugging and moni- toring, and specification of programmers’s knowledge about an algorithm not directly captured in the MATLAB program struc- ture. In our approach, a single version of the specification can be used throughout the entire development cycle rather than main- taining multiple versions, as is presently the case. We believe this separation helps the development, simulation, exploration and implementation phases. In this paper we address some of the issues resulting from the inflexibility of existing programming languages, using an aspect- oriented approach. We propose aspect modules expressed in a domain-specific language based on the key concepts of joinpoint selection (select) composition (apply) and conditional binding * This work has been partially supported by FCT (Portuguese Science Foundation) under grant (POCTI, PTDC/EIA/70271/2006).