Created: 2012/11/08 20:27:15+0000 Revised: 2012/11/08 20:27:15+0000 Revisions:  2 1

Not long after learning about Tcl's trace command I first heard about aspect-oriented programming. I saw some similarities between the two but the friend who told me about aspect-oriented programming wasn't so keen.

I implemented some code that took advantage of trace to measure the execution time of a procedure. Trace added procedures to execute when entering or leaving the timed procedure. These were used to modify a stack that contained the start times of the procedures being watched

This provides much more restrictive functionality then could be obtained with a dedicated implementation for aspects. Aside from it only providing performance information: it matches on the exact name of the procedure, it does not provide pattern matching; it allows code to be added at the execution of a procedure, it does not allow code to be added to the call of the procedure and it allows code to be added before and after a procedure, it does not allow code to replace a procedure. To address some of these limitations with trace I decided to implement a Tcl package that allows the static weaving of code into procedures.

I defined new procedures to create, pointcuts, advice, aspects, and procedures. The procedures for pointcuts and advice both allow an optional name and return a handle. This allows them to be reused or to be used only once. Each aspect is created from the handles to a pointcut and a piece of advice. The new procedure to create procedures uses the same signature as proc but weaves the body with any matching aspects.

One of the limitations of this is the reduced number of joinpoints available in Tcl compared to Java. Types, visibility and annotations have all been removed leaving names and the number of arguments.

Work on this is going very quickly, when I can find the time, because of the nature of Tcl. I will make this available as soon as I can.