www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - generative programming and debugging

reply Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
Do anybody know a good way to (statically) debug a generated code?
Currently it takes lots of effort to determine the place, where the
code is being incorrectly generated.
Oct 19 2011
next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 10/19/2011 11:07 AM, Gor Gyolchanyan wrote:
 Do anybody know a good way to (statically) debug a generated code?
 Currently it takes lots of effort to determine the place, where the
 code is being incorrectly generated.
pragma(msg, foo()); // debug mixin(foo()); You can additionally use something in the lines of the following if it is not immediately obvious which function generated the incorrect code. import std.stdio, std.conv; string X(string file=__FILE__, int line=__LINE__){ return "// "~file~"("~to!string(line)~")\n"; } string foo(){ string r; foreach(i;0..3) r~=q{writeln("hello world");}~X(); foreach(i;0..3) r~=q{writekn("hello world");}~X(); // whoops return r; } void main(){ pragma(msg, foo()); mixin(foo()); } It would be kinda nice if the compiler pointed directly to the source location that generated the incorrect code.
Oct 19 2011
parent reply Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
good point. I'll need to generate comments for that code, that contain
information about the place, where the code was generated.

There are 2 things I'd really like to have:
1. Be able to obtain the name (possibly an alias) of a function on the
call stack on the given depth.
2. Be able to obtain file and line of a function on the call stack on
the given depth.
This would be awesome for generating very convenient debug info.

On Wed, Oct 19, 2011 at 2:32 PM, Timon Gehr <timon.gehr gmx.ch> wrote:
 On 10/19/2011 11:07 AM, Gor Gyolchanyan wrote:
 Do anybody know a good way to (statically) debug a generated code?
 Currently it takes lots of effort to determine the place, where the
 code is being incorrectly generated.
pragma(msg, foo()); // debug mixin(foo()); You can additionally use something in the lines of the following if it is not immediately obvious which function generated the incorrect code. import std.stdio, std.conv; string X(string file=3D__FILE__, int line=3D__LINE__){ =A0 =A0 return "// "~file~"("~to!string(line)~")\n"; } string foo(){ =A0 =A0string r; =A0 =A0foreach(i;0..3) r~=3Dq{writeln("hello world");}~X(); =A0 =A0foreach(i;0..3) r~=3Dq{writekn("hello world");}~X(); // whoops =A0 =A0return r; } void main(){ =A0 =A0pragma(msg, foo()); =A0 =A0mixin(foo()); } It would be kinda nice if the compiler pointed directly to the source location that generated the incorrect code.
Oct 19 2011
parent Don <nospam nospam.com> writes:
On 19.10.2011 12:50, Gor Gyolchanyan wrote:
 good point. I'll need to generate comments for that code, that contain
 information about the place, where the code was generated.

 There are 2 things I'd really like to have:
 1. Be able to obtain the name (possibly an alias) of a function on the
 call stack on the given depth.
 2. Be able to obtain file and line of a function on the call stack on
 the given depth.
 This would be awesome for generating very convenient debug info.
I've made a couple of improvements to the CTFE engine for the next release, which gives a substantially better call stack trace when an error occurs. Please suggest further improvements.
 On Wed, Oct 19, 2011 at 2:32 PM, Timon Gehr<timon.gehr gmx.ch>  wrote:
 On 10/19/2011 11:07 AM, Gor Gyolchanyan wrote:
 Do anybody know a good way to (statically) debug a generated code?
 Currently it takes lots of effort to determine the place, where the
 code is being incorrectly generated.
pragma(msg, foo()); // debug mixin(foo()); You can additionally use something in the lines of the following if it is not immediately obvious which function generated the incorrect code. import std.stdio, std.conv; string X(string file=__FILE__, int line=__LINE__){ return "// "~file~"("~to!string(line)~")\n"; } string foo(){ string r; foreach(i;0..3) r~=q{writeln("hello world");}~X(); foreach(i;0..3) r~=q{writekn("hello world");}~X(); // whoops return r; } void main(){ pragma(msg, foo()); mixin(foo()); } It would be kinda nice if the compiler pointed directly to the source location that generated the incorrect code.
I don't know how it could really do that. I mean, what if at the end of foo, you looped over 'r' and changed every 'k' to 'l', and every 'l' to 'k'? Then the first line would be the one with the error!
Oct 19 2011
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2011-10-19 11:07, Gor Gyolchanyan wrote:
 Do anybody know a good way to (statically) debug a generated code?
 Currently it takes lots of effort to determine the place, where the
 code is being incorrectly generated.
The Eclipse plugin Descent has support for compile time debugging. It also have a compile time view which shows the result of string mixins and template mixins. -- /Jacob Carlborg
Oct 19 2011
next sibling parent reply Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
This is cool. Unfortunately, descent is a big pain to use for everything else.

On Wed, Oct 19, 2011 at 3:12 PM, Jacob Carlborg <doob me.com> wrote:
 On 2011-10-19 11:07, Gor Gyolchanyan wrote:
 Do anybody know a good way to (statically) debug a generated code?
 Currently it takes lots of effort to determine the place, where the
 code is being incorrectly generated.
The Eclipse plugin Descent has support for compile time debugging. It also have a compile time view which shows the result of string mixins and template mixins. -- /Jacob Carlborg
Oct 19 2011
parent Jacob Carlborg <doob me.com> writes:
On 2011-10-19 13:21, Gor Gyolchanyan wrote:
 This is cool. Unfortunately, descent is a big pain to use for everything else.
Well, it might be worth to just start up eclipse once in a while for cases like these.
 On Wed, Oct 19, 2011 at 3:12 PM, Jacob Carlborg<doob me.com>  wrote:
 On 2011-10-19 11:07, Gor Gyolchanyan wrote:
 Do anybody know a good way to (statically) debug a generated code?
 Currently it takes lots of effort to determine the place, where the
 code is being incorrectly generated.
The Eclipse plugin Descent has support for compile time debugging. It also have a compile time view which shows the result of string mixins and template mixins. -- /Jacob Carlborg
-- /Jacob Carlborg
Oct 19 2011
prev sibling parent reply Ary Manzana <ary esperanto.org.ar> writes:
On 10/19/11 8:12 AM, Jacob Carlborg wrote:
 On 2011-10-19 11:07, Gor Gyolchanyan wrote:
 Do anybody know a good way to (statically) debug a generated code?
 Currently it takes lots of effort to determine the place, where the
 code is being incorrectly generated.
The Eclipse plugin Descent has support for compile time debugging. It also have a compile time view which shows the result of string mixins and template mixins.
Does it still work? I have the idea that once I abandon a project it somehow stops working. :-P
Oct 19 2011
parent Jacob Carlborg <doob me.com> writes:
On 2011-10-19 17:42, Ary Manzana wrote:
 On 10/19/11 8:12 AM, Jacob Carlborg wrote:
 On 2011-10-19 11:07, Gor Gyolchanyan wrote:
 Do anybody know a good way to (statically) debug a generated code?
 Currently it takes lots of effort to determine the place, where the
 code is being incorrectly generated.
The Eclipse plugin Descent has support for compile time debugging. It also have a compile time view which shows the result of string mixins and template mixins.
Does it still work? I have the idea that once I abandon a project it somehow stops working. :-P
Descent is quite slow and often freezes, otherwise it's working quite well. -- /Jacob Carlborg
Oct 19 2011