digitalmars.D - Triggers
- Sjoerd van Leent (27/27) Aug 05 2009 OK, to make matters worse.
- Jeremie Pelletier (3/43) Aug 05 2009 You can already do something like that, although very hackish: turn on t...
- Sjoerd van Leent (3/49) Aug 06 2009 There comes "AspectD" :-)
OK, to make matters worse. As I was reading so many things about properties, keywords and a bunch of other interesting things, perhaps triggers. Triggers are, in my opinion, functions that act as delegates, and are called before or after one or more other functions. Maybe we can do something with this? It would introduce some aspect programming to D. file 1: class Foo { int mybar; int myother; void bar(int i) { mybar = i; } void other(int i) { myother = i; } } file 2: trigger(before) : "*.void * (int *)" { writefln("calling ", this.currentFunctionName); } trigger(after) : "*.void * (int *)" { writefln("called ", this.currentFunctionName); } This might be something for D3 though...
Aug 05 2009
Sjoerd van Leent Wrote:OK, to make matters worse. As I was reading so many things about properties, keywords and a bunch of other interesting things, perhaps triggers. Triggers are, in my opinion, functions that act as delegates, and are called before or after one or more other functions. Maybe we can do something with this? It would introduce some aspect programming to D. file 1: class Foo { int mybar; int myother; void bar(int i) { mybar = i; } void other(int i) { myother = i; } } file 2: trigger(before) : "*.void * (int *)" { writefln("calling ", this.currentFunctionName); } trigger(after) : "*.void * (int *)" { writefln("called ", this.currentFunctionName); } This might be something for D3 though...You can already do something like that, although very hackish: turn on trace profiling and override the prolog/epilog code from druntime (I think these are called _trace_pro_n and _trace_epi_n, just grep the source for their syntax). Just make *very* sure to use only naked declarations in these and any routine they may call, or else you will just call back into _trace_pro_n until you get a stack overflow.
Aug 05 2009
Jeremie Pelletier Wrote:Sjoerd van Leent Wrote:There comes "AspectD" :-) SjoerdOK, to make matters worse. As I was reading so many things about properties, keywords and a bunch of other interesting things, perhaps triggers. Triggers are, in my opinion, functions that act as delegates, and are called before or after one or more other functions. Maybe we can do something with this? It would introduce some aspect programming to D. file 1: class Foo { int mybar; int myother; void bar(int i) { mybar = i; } void other(int i) { myother = i; } } file 2: trigger(before) : "*.void * (int *)" { writefln("calling ", this.currentFunctionName); } trigger(after) : "*.void * (int *)" { writefln("called ", this.currentFunctionName); } This might be something for D3 though...You can already do something like that, although very hackish: turn on trace profiling and override the prolog/epilog code from druntime (I think these are called _trace_pro_n and _trace_epi_n, just grep the source for their syntax). Just make *very* sure to use only naked declarations in these and any routine they may call, or else you will just call back into _trace_pro_n until you get a stack overflow.
Aug 06 2009