December 28, 2021

On Tuesday, 28 December 2021 at 00:32:03 UTC, Paul Backus wrote:

>

The result of .stringof is completely implementation-defined, may change arbitrarily between compiler releases, and is not even guaranteed to be valid D code in the first place.

Wow, I didn't know this.

>

In this case, the simplest solution is to have your code generator accept a string as its input, rather than a type. For example:

enum instantiate(string type, string expr) = type ~ "(" ~ expr ~ ")";
pragma(msg, instantiate!("RVector!(SEXPTYPE.REALSXP)", "x"));

Well the code needs to be responsive from parameter types T generated from other code. I'm allowing the user to create functions select those they wish to access in R by UDA decorators in the D script which I then filter for and wrap the necessary functions generating any type conversion code I need at compile time to create functions callable in R.

December 28, 2021

On Tuesday, 28 December 2021 at 00:42:18 UTC, data pulverizer wrote:

>

On Tuesday, 28 December 2021 at 00:32:03 UTC, Paul Backus wrote:

>

In this case, the simplest solution is to have your code generator accept a string as its input, rather than a type. For example:

enum instantiate(string type, string expr) = type ~ "(" ~ expr ~ ")";
pragma(msg, instantiate!("RVector!(SEXPTYPE.REALSXP)", "x"));

Well the code needs to be responsive from parameter types T generated from other code. I'm allowing the user to create functions select those they wish to access in R by UDA decorators in the D script which I then filter for and wrap the necessary functions generating any type conversion code I need at compile time to create functions callable in R.

I see. So, you need access to the type as a type in order to reflect on it, but you also want it as a string in order to generate code.

My guess is that you don't actually need to use string mixins for most of this, but I can't say for sure without seeing a more complete example.

December 28, 2021

On Tuesday, 28 December 2021 at 00:57:27 UTC, Paul Backus wrote:

> > >
enum instantiate(string type, string expr) = type ~ "(" ~ expr ~ ")";
pragma(msg, instantiate!("RVector!(SEXPTYPE.REALSXP)", "x"));

One possibility is to generate a collection of compile time strings that denote the types and then to a comparison with the type something like is(T == mixin(CString), where CString = "RVector!(SEXPTYPE.REALSXP)" to discover the correct string which I can then use to generate the code without having to use T.stringof anywhere in the code at all.

1 2
Next ›   Last »