Why does the following program write the message 'Foo' twice?

2014-03-19 Thread Gary Willoughby

Why does the following program write the message 'Foo' twice?

void main(string[] args)
{
pragma(msg, Foo);
}


Re: Why does the following program write the message 'Foo' twice?

2014-03-19 Thread Dicebot

On Wednesday, 19 March 2014 at 10:08:50 UTC, Gary Willoughby
wrote:

Why does the following program write the message 'Foo' twice?

void main(string[] args)
{
pragma(msg, Foo);
}


Once upon compilation and once upon run-time. I don't know if it
is intended design but this is how `pragma(msg)` works if put
into function body.


Re: Why does the following program write the message 'Foo' twice?

2014-03-19 Thread Vladimir Panteleev
On Wednesday, 19 March 2014 at 10:08:50 UTC, Gary Willoughby 
wrote:

Why does the following program write the message 'Foo' twice?

void main(string[] args)
{
pragma(msg, Foo);
}


The message is not printed by the program, but by the compiler.

If you build the program via dmd, the message is only printed 
once.


If you use rdmd, it will be printed twice, because rdmd invokes 
dmd once to gather the program's dependencies, and a second time 
to actually build the program.


Re: Why does the following program write the message 'Foo' twice?

2014-03-19 Thread Dicebot

Disregard my comment, Vladimir is right :)


Re: Why does the following program write the message 'Foo' twice?

2014-03-19 Thread Gary Willoughby
On Wednesday, 19 March 2014 at 10:10:18 UTC, Vladimir Panteleev 
wrote:
If you use rdmd, it will be printed twice, because rdmd invokes 
dmd once to gather the program's dependencies, and a second 
time to actually build the program.


Yes i'm using rdmd. Thanks.


Re: reflection over templates

2014-03-19 Thread Dicebot
On Wednesday, 19 March 2014 at 16:18:17 UTC, Andrej Mitrovic 
wrote:

And after we determine it is a template, can we extract the
required arguments list like we can with a regular function at
all?


Well there's TemplateArgsOf for *instantiations*, but I'm not 
sure how
one would do it with non-instantiations. In particular how 
would we
create a tuple of template parameter types where one of the 
parameters

was an alias?

E.g.:

template Foo(int, alias X);

alias Args = TypeTuple!(int, ???);

There is no alias type you could use in this case.


One can use value instead of a type, like alias.


Re: reflection over templates

2014-03-19 Thread Dicebot

As a workaround one can use set of relevant trait checks:
1) type is void
2) is not a variable or callable
3) .stringof fits NAME(ARGS) pattern


Re: reflection over templates

2014-03-19 Thread Dicebot
Wait just a bit more 
https://github.com/D-Programming-Language/dmd/pull/3380 :)


Re: reflection over templates

2014-03-19 Thread Adam D. Ruppe

On Wednesday, 19 March 2014 at 16:10:52 UTC, Dicebot wrote:
Wait just a bit more 
https://github.com/D-Programming-Language/dmd/pull/3380 :)


megarox. Make it so.


reflection over templates

2014-03-19 Thread Adam D. Ruppe

Given:

template Foo(string T) { enum Foo = to!int(T); }

(or anything else, really)

Is there anything we can do with static if to identify it as a 
template?


I tried:

static if(is(Foo == template)) {} // nope, basic type expected, 
not template


Note that is(typeof(Foo) == function) {} is how we check for 
regular functions.



static if(is(typeof(Foo) == template)) {} // nope


In fact, typeof(Foo) == void... is that something we can use?


I know we can break down a template instantiation with one of the 
arcane is expressions, but I don't have that here, I just want to 
identify the template Foo as a template.


This is in the context of doing __traits(allMembers) over a 
module and trying to categorize every member.



Checking for a void type seems to be the closest I've gotten, but 
that seems awfully strange. I guess other variables can't be 
declared with type void, so maybe that is a unique 
differentiator, but still, idk about it.



And after we determine it is a template, can we extract the 
required arguments list like we can with a regular function at 
all?


Re: reflection over templates

2014-03-19 Thread Andrej Mitrovic
On 3/19/14, Adam D. Ruppe destructiona...@gmail.com wrote:
 Is there anything we can do with static if to identify it as a
 template?

https://github.com/D-Programming-Language/dmd/pull/3380

 And after we determine it is a template, can we extract the
 required arguments list like we can with a regular function at
 all?

Well there's TemplateArgsOf for *instantiations*, but I'm not sure how
one would do it with non-instantiations. In particular how would we
create a tuple of template parameter types where one of the parameters
was an alias?

E.g.:

template Foo(int, alias X);

alias Args = TypeTuple!(int, ???);

There is no alias type you could use in this case.


Re: reflection over templates

2014-03-19 Thread simendsjo

On 03/19/2014 05:34 PM, Adam D. Ruppe wrote:

On Wednesday, 19 March 2014 at 16:10:52 UTC, Dicebot wrote:

Wait just a bit more
https://github.com/D-Programming-Language/dmd/pull/3380 :)


megarox. Make it so.


Nice. I have some ugly hacks that's probably full of bugs for this (look 
at the bottom):


template isLValue(T)
{
enum isLValue = false;
}
/// ditto
template isLValue(alias T)
{
enum isLValue = !isType!T  isAddressable!T  __traits(compiles, 
{ Unqual!(TypeOf!T) t = TypeOf!(T).init; });

}
/// ditto
template isRValue(T)
{
enum isRValue = false;
}
/// ditto
template isRValue(alias T)
{
static if(isType!T)
enum isRValue = false;
else
enum isRValue = __traits(compiles, { typeof(T) t = T; })  
!isAddressable!T;

}

template isValue(T)
{
enum isValue = false;
}
/// ditto
template isValue(alias T)
{
enum isValue = isLValue!T || isRValue!T;
}
/// ditto
template isType(T)
{
enum isType = is(T);
}
/// ditto
template isType(alias T)
{
enum isType = is(T) || isCallable!T;
}
template isTemplate(T)
{
enum isTemplate = !(isValue!T || isType!T);
}
template isTemplate(alias T)
{
enum isTemplate = !(isValue!T || isType!T);
}



Ada-Style Range Types with Value Range Propagation in Arithmetic

2014-03-19 Thread Nordlöw
I'm trying to extend my wrapper class Bound to support CTFE Value 
Range Propagation in primary in opUnary and opBinary similar to 
what Ada's Range Types.


My current try so far for binary arithmetic is

auto opBinary(string op, U,
  U lower_rhs = U.min,
  U upper_rhs = U.max,
  string file = __FILE__,
  int line = __LINE__)(Bound!(U, lower_rhs, 
upper_rhs) rhs)

{
Bound!(CommonType!(T, U),
   min(T.min, U.min),
   max(T.max + U.max)) tmp = void; // TODO: Needs fix
mixin(tmp = _value  ~ op ~ rhs;);
mixin(check());
return tmp;
}

but this errors as

bound.d(120,19): Error: undefined identifier U and I don't 
understand why I can't parameterize opBinary in this way.


Ideas anyone?

For reference, this older version

https://github.com/nordlow/justd/blob/master/bound.d

compiles but do not do value range propagation in arithmetic.


Re: Ada-Style Range Types with Value Range Propagation in Arithmetic

2014-03-19 Thread Nordlöw

Ideas anyone?


I cracked it:


auto opBinary(string op, U,
  string file = __FILE__,
  int line = __LINE__)(U rhs)
{
static if (is(U == Bound))
{
alias C = CommonType!(T, U.type);
Bound!(C,
   cast(C)min + cast(C)U.min,
   cast(C)max + cast(C)U.max) tmp = void; // 
TODO: Needs fix

}
else
{
CommonType!(T, U) tmp = void;
}
mixin(tmp = _value  ~ op ~ rhs;);
mixin(check());
return tmp;
}