Re: anyway to debug nogc code with writeln?

2018-09-03 Thread aliak via Digitalmars-d-learn

On Saturday, 1 September 2018 at 22:38:46 UTC, Ali Çehreli wrote:

You can strip off any attribute with SetFunctionAttributes:

import std.stdio;

// Adapted from std.traits.SetFunctionAttributes documentation
import std.traits;
auto assumeNoGC(T)(T t)
if (isFunctionPointer!T || isDelegate!T)
{
enum attrs = functionAttributes!T | FunctionAttribute.nogc;
return cast(SetFunctionAttributes!(T, functionLinkage!T, 
attrs)) t;

}

void f(T)(auto ref T) {
writeln("yo");
}

@nogc void main() {
assumeNoGC(() => f(3));
// or
assumeNoGC( { writeln("yo"); });
}

Ali


Ah this works! Can define a debugWriteln then that can be used 
from anywhere without having to re attribute all the functions.


Thanks!


Re: anyway to debug nogc code with writeln?

2018-09-02 Thread Dennis via Digitalmars-d-learn

On Saturday, 1 September 2018 at 21:53:03 UTC, aliak wrote:

Anyway around this?


I don't know if your situation allows it, but you can mark f 
explicitly as always @nogc. If your design assumes that it's 
@nogc, it's a good idea to add the attribute anyway.


You can also use the C printf function:
```
import core.stdc.stdio: printf;
printf("yo\n");
```


Re: anyway to debug nogc code with writeln?

2018-09-01 Thread Ali Çehreli via Digitalmars-d-learn

You can strip off any attribute with SetFunctionAttributes:

import std.stdio;

// Adapted from std.traits.SetFunctionAttributes documentation
import std.traits;
auto assumeNoGC(T)(T t)
if (isFunctionPointer!T || isDelegate!T)
{
enum attrs = functionAttributes!T | FunctionAttribute.nogc;
return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
}

void f(T)(auto ref T) {
writeln("yo");
}

@nogc void main() {
assumeNoGC(() => f(3));
// or
assumeNoGC( { writeln("yo"); });
}

Ali