lvalue - rvalue problem
The following code prints: /home/c494/c719.d(27): Error: (Vec2!(float) __ctmp1173 = _D4c71911__T4Vec2TfZ4Vec26__initZ; , __ctmp1173).this(4F, 2F) is not an lvalue [code] import std.stdio; struct Vec2(T) { public: T x; T y; this(T x, T y) { } } alias Vec2f = Vec2!(float); class Foo { public: static Foo make(float i, ref const Vec2f a) { return new Foo(); } static Foo make(float i, const Vec2f a) { return Foo.make(i, a); } } void main() { Foo f = Foo.make(42, Vec2f(4, 2)); } [/code] If I change i from float to int it works. Also if I write 42f instead of 42. That is strange. Could someone explain me that? Same with this code: http://dpaste.1azy.net/2c98fe95 But there I found no workaround.
Re: lvalue - rvalue problem
Looks like a bug in function overload selection.
Re: lvalue - rvalue problem
On Sunday, 27 January 2013 at 11:42:29 UTC, Dicebot wrote: Looks like a bug in function overload selection. I hope not! That would be really bad. That is part of my solution as long as auto ref isn't there. :D
Re: hasDataMember and mixin inconsistency
On Sunday, 27 January 2013 at 09:49:33 UTC, Philippe Sigaud wrote: Hi, If think in your code, your testing whether or a not a mixin(...) statement is valid D. Which it is. But what I'm surprised by is that the behavior of hasDataMember with my implementation works fine for all test cases except hasDataMember!(Test, init). If it was only testing whether the mixin statement was well formed or not, shouldn't my implementation of hasDataMember always return true ? What's more confusing is that it seems to work properly for all test cases except a built-in property of a structure : assert(!hasDataMember!(long, init)); // This succeeds. assert(!hasDataMember!(Test, init)); // This fails. I'd put the mixin externally: template hasDataMember( T, string M ) { mixin( enum hasDataMember = __traits( compiles, ( ref T x, ref T y ){ x. ~ M ~ = y. ~ M ~ ; } );); } I've just tried that and it unfortunately does not work, the same test case still fails. Also, I suppose the Test inner struct is not visible from the hasDataMember template. The template is instantiated where it's declared, not where it's called. You could use a mixin template, I guess. I'm not sure at all what you mean by that. I thought all symbols within a source file were visible irrespective of their order or scope? Also, the test failure is on the Test structure directly, not its inner structure A. I'd use a string mixin, but then I was converted to string mixins a few years ago :) string hasDataMember( T )(string M ) { return __traits(compiles, { Test t; auto _ = t.D; // reading t.M t. ~ M ~ = t. ~ M ~ ; // assign to t.M }); } using is a bit more noisy than your solution: mixin(hadDataMember!(Test)(M)) I've tried that as well and it still fails on the same test case again. And it works pretty well, but it gets the wrong result for the following test case which is commented out. Originally, I thought maybe you were allowed to write to the .init member of structures, but writing the same code directly without relying on a mixin actually yields the right result (all the asserts pass) You cannot write to .init, it's not a member. It's a built-in property, like .sizeof or .offsetof. Makes sense. 2) Is there a better way to check for the existence of a data member ? If by data member, you mean some symbol that can be read and written to, then I'd test just that. See the string mixin before: it tests for existence, reading and writing. Could this be a compiler bug by any chance? It seems really weird that the template would work for intrinsic types but not for structure, especially when the exact same template without the use of mixin works fine. Thanks again for your help.
Re: lvalue - rvalue problem
Same with this code: http://dpaste.1azy.net/2c98fe95 But there I found no workaround. This works: new C(cast(A) new B(), FloatRect(0, 1, 2, 3)); But that is ugly. o.O I think you are right and it is a bug in function overload selection. :(
Re: hasDataMember and mixin inconsistency
On 01/27/13 12:47, Olivier Grant wrote: On Sunday, 27 January 2013 at 09:49:33 UTC, Philippe Sigaud wrote: You cannot write to .init, it's not a member. It's a built-in property, like .sizeof or .offsetof. Makes sense. It does, but apparently the compiler disagrees. 2) Is there a better way to check for the existence of a data member ? If by data member, you mean some symbol that can be read and written to, then I'd test just that. See the string mixin before: it tests for existence, reading and writing. Could this be a compiler bug by any chance? It seems really weird Yes, it's a bug. Assignments to .init do not make sense and shouldn't be allowed. I just tried, and the old gdc version i have here doesn't flag them as errors (but did segfault after processing one ;) ). artur
Re: hasDataMember and mixin inconsistency
I'd put the mixin externally: template hasDataMember( T, string M ) { mixin( enum hasDataMember = __traits( compiles, ( ref T x, ref T y ){ x. ~ M ~ = y. ~ M ~ ; } );); } I've just tried that and it unfortunately does not work, the same test case still fails. ? I'll find the files again, for I tested before posting. Also, I suppose the Test inner struct is not visible from the hasDataMember template. The template is instantiated where it's declared, not where it's called. You could use a mixin template, I guess. I'm not sure at all what you mean by that. I thought all symbols within a source file were visible irrespective of their order or scope? Also, the test failure is on the Test structure directly, not its inner structure A. Test is inside main() { ... }. I guess it's not visible from the module inner scope. I'd use a string mixin, but then I was converted to string mixins a few years ago :) string hasDataMember( T )(string M ) { return __traits(compiles, { Test t; auto _ = t.D; // reading t.M t. ~ M ~ = t. ~ M ~ ; // assign to t.M }); } using is a bit more noisy than your solution: mixin(hadDataMember!(Test)(M)) I've tried that as well and it still fails on the same test case again. ? Here is what I used before posting: string hasDataMember( T )(string M ) { return __traits(compiles, { Test t; auto _ = t.D; // reading t.M t. ~ M ~ = t. ~ M ~ ; // assign to t.M }); } void main() { struct Test { struct A { } void B( ) { } @property A C( ) const { return F; } @property long D( ) const { return E; } @property void D( long e ) { E = e; } long E; A F; } assert(!mixin(hasDataMember!(Test)(init))); assert(!mixin(hasDataMember!(int)(init))); assert(!mixin(hasDataMember!(Test)(init))); // Passes assert(!mixin(hasDataMember!(Test)(A))); assert(!mixin(hasDataMember!(Test)(B))); assert(!mixin(hasDataMember!(Test)(C))); assert(mixin(hasDataMember!(Test)(D))); assert(mixin(hasDataMember!(Test)(E))); assert(mixin(hasDataMember!(Test)(F))); } It seems the right behaviour. Am I mistaken?
Re: lvalue - rvalue problem
Ok, I will open a bug report for this.
Re: two mains
On Saturday, 26 January 2013 at 20:42:27 UTC, Tyro[17] wrote: So why do we need to mov RBP, RSP in [2] but not in [1]? I'm thinking this is because RBP contains the address of args but not sure. The x64 calling convention passes the first few arguments via registers. I think it's most likely that the function prolog is allocating stack space to save the value of whatever registers (RDI/RDX?) which contain the string[] parameter, so that it could reuse those registers in the code of the function - but the assignment seems to have been optimized out, yet the stack allocation wasn't. FWIW, on Windows x64, DMD generates slightly different code, presumably because it's using the Microsoft x64 calling convention instead of the System V one. There is no stack allocation when compiled with -O, however without -O, DMD adds a mov [RBP+10h], RCX instruction. I assume it makes use of the 32-byte shadow space to spill ECX: http://en.wikipedia.org/wiki/X86_calling_conventions#x86-64_calling_conventions
try to compile githubs dmd-master zip with vstudio 2010
i've grabbed the dmd-master.zip from github an opended the dmd_msc_vs10.sln but i get 3 errors C:\Test\dmd-master\src\mars.c wants missing include verstr.h C:\Test\dmd-master\src\c1xx missing ph.h C:\Test\dmd-master\src\c1xx missing util.c what else is needed to build from source this way?
Re: try to compile githubs dmd-master zip with vstudio 2010
I had the same problem, few days ago. I wrote this short make script [1] which works for me. My solution is that you must clean before, call the vs buildme and then build again with the normal make file. Sounds weird but it works (for me). [1] makefile: set DM_HOME=D:\D cd dmd cd src make -fwin32.mak clean cd vcbuild call builddmd.bat cd .. make -fwin32.mak release copy *.exe %DM_HOME%\dmd2\windows\bin make -fwin32.mak clean pause cd ../.. cd druntime make -fwin32.mak pause cd .. cd phobos make -fwin32.mak copy phobos.lib %DM_HOME%\dmd2\windows\lib cd .. dmd
Re: two mains
On Saturday, 26 January 2013 at 20:42:27 UTC, Tyro[17] wrote: Trying to learn from the ground up and would appreciate some assistance making sense of the following: // void main(){} [1] [...] This might not be directly relevant here, but in general, I'd steer clear of main() for such experiments. Due to its special nature (several possible signatures, but the calling code in druntime stays the same), there is quite a bit of extra magic going on internally. For example, you wouldn't normally find xor EAX, EAX in a void-returning functions, as its purpose is to set the return value to 0, which implicitly happens to make the void main() and void main(string[]) variants conform to the full int main(string[]) signature. David
Re: try to compile githubs dmd-master zip with vstudio 2010
and if i want to use the solution file? Am 27.01.2013 14:45, schrieb Namespace: I had the same problem, few days ago. I wrote this short make script [1] which works for me. My solution is that you must clean before, call the vs buildme and then build again with the normal make file. Sounds weird but it works (for me). [1] makefile: set DM_HOME=D:\D cd dmd cd src make -fwin32.mak clean cd vcbuild call builddmd.bat cd .. make -fwin32.mak release copy *.exe %DM_HOME%\dmd2\windows\bin make -fwin32.mak clean pause cd ../.. cd druntime make -fwin32.mak pause cd .. cd phobos make -fwin32.mak copy phobos.lib %DM_HOME%\dmd2\windows\lib cd .. dmd
Re: two mains
On Saturday, 26 January 2013 at 20:57:54 UTC, Tyro[17] wrote: On 1/26/13 3:42 PM, Tyro[17] wrote: The second is the use of leave in [2]. If I understand correctly, leave is the exact same as: movRBP,RSP popRBP So why do we need to mov RBP, RSP in [2] but not in [1]? I'm thinking this is because RBP contains the address of args but not sure. Still not clear on this choice. Both functions could be replaced with --- _Dmain: xor EAX, EAX ret --- as they don't need to store anything on the stack at all. What you are seeing is just an odd result of the way the compiler generates the code internally, especially if you are compiling without optimizations on. For further information on what EBP/RBP is needed for, try searching for discussions about the (mis)use of GCC's omit-frame-pointer option, such as: http://stackoverflow.com/questions/579262/what-is-the-purpose-of-the-frame-pointer David
Re: Why is null lowercase?
DO YOU PREFER A LANGUAGE ALL IN UPPERCASE? Hahahaha! I find it ugly too. I prefer lowercaps null, as in Java.
Re: Why is null lowercase?
On Friday, 25 January 2013 at 16:11:57 UTC, Maxim Fomin wrote: On Friday, 25 January 2013 at 14:22:20 UTC, Don wrote: On Friday, 25 January 2013 at 01:17:44 UTC, Ali Çehreli wrote: On 01/24/2013 12:42 PM, Matthew Caron wrote: for not null checks if ( ptr !is null) ... And too much perl has me wanting to write: if (ptr is not null) IIRC, the !is operator is thanks to bearophile. No, it's from 2002 (well, it was !==, renamed to !is in 2005). Bearophile only joined us about the time D2 began, in late 2007. It would be nice a to have a wiki page about D history written by old-timers. I vote for that too!
Re: hasDataMember and mixin inconsistency
On Sunday, 27 January 2013 at 12:58:39 UTC, Philippe Sigaud wrote: I'd put the mixin externally: template hasDataMember( T, string M ) { mixin( enum hasDataMember = __traits( compiles, ( ref T x, ref T y ){ x. ~ M ~ = y. ~ M ~ ; } );); } I've just tried that and it unfortunately does not work, the same test case still fails. ? I'll find the files again, for I tested before posting. Also, I suppose the Test inner struct is not visible from the hasDataMember template. The template is instantiated where it's declared, not where it's called. You could use a mixin template, I guess. I'm not sure at all what you mean by that. I thought all symbols within a source file were visible irrespective of their order or scope? Also, the test failure is on the Test structure directly, not its inner structure A. Test is inside main() { ... }. I guess it's not visible from the module inner scope. I'd use a string mixin, but then I was converted to string mixins a few years ago :) string hasDataMember( T )(string M ) { return __traits(compiles, { Test t; auto _ = t.D; // reading t.M t. ~ M ~ = t. ~ M ~ ; // assign to t.M }); } using is a bit more noisy than your solution: mixin(hadDataMember!(Test)(M)) I've tried that as well and it still fails on the same test case again. ? Here is what I used before posting: string hasDataMember( T )(string M ) { return __traits(compiles, { Test t; auto _ = t.D; // reading t.M t. ~ M ~ = t. ~ M ~ ; // assign to t.M }); } What is the purpose of auto _ = t.D; ? void main() { struct Test { struct A { } void B( ) { } @property A C( ) const { return F; } @property long D( ) const { return E; } @property void D( long e ) { E = e; } long E; A F; } assert(!mixin(hasDataMember!(Test)(init))); // (1) - Fails assert(!mixin(hasDataMember!(int)(init))); // (2) - Fails assert(!mixin(hasDataMember!(Test)(A))); assert(!mixin(hasDataMember!(Test)(B))); assert(!mixin(hasDataMember!(Test)(C))); assert(mixin(hasDataMember!(Test)(D))); assert(mixin(hasDataMember!(Test)(E))); assert(mixin(hasDataMember!(Test)(F))); } It seems the right behaviour. Am I mistaken? Using dmd 2.060 and command line rdmd test.d, I get an assertion fail on both calls that check for a member init whether for int or Test.
Re: hasDataMember and mixin inconsistency
string hasDataMember( T )(string M ) { return __traits(compiles, { Test t; auto _ = t.D; // reading t.M t. ~ M ~ = t. ~ M ~ ; // assign to t.M }); } What is the purpose of auto _ = t.D; ? Just testing whether t.M can be assigned to something (ie, is it a value?) I use '_' as a variable name to indicate I don't care for it's precise name/value. It's just a placeholder. Using dmd 2.060 and command line rdmd test.d, I get an assertion fail on both calls that check for a member init whether for int or Test. Using 2.061 here.
Re: endless loop with ref and non-ref parameter
no match match with implicit conversions match with conversion to const exact match Explain me, why this code prints: Error: A() is not an lvalue [code] import std.stdio; struct A { } void foo(A a, float r) { } void foo(const A a, float r) { } void foo(ref A a, float r) { } void main() { foo(A(), 12); } [/code] Why is the ref A a functions chosen? I create already a pull request but a explanation would be nice.
Re: endless loop with ref and non-ref parameter
pull request - bug report. I'm a bit confused today.
Tutorial on how to build DMD/druntime/phobos and docs from source?
I remember there being a tutorial on how to build DMD and such from source. I've been searching for a while and can't find it. It won't show up on google searches. Does anyone have a link? Right now I'm most interested in a tutorial on how to build the docs. Thanks.
Re: Tutorial on how to build DMD/druntime/phobos and docs from source?
On Sun, Jan 27, 2013 at 04:13:08PM -0500, Chad Joan wrote: I remember there being a tutorial on how to build DMD and such from source. I've been searching for a while and can't find it. It won't show up on google searches. Does anyone have a link? http://wiki.dlang.org/Building_DMD Right now I'm most interested in a tutorial on how to build the docs. [...] For docs, checkout d-programming-language.org from github, and run make on it to generate the HTML, CSS, etc.. Then checkout phobos and run 'make html'. I forget the exact commands but there should be analogous commands for druntime (and maybe dmd). You may need to tweak the directory structure a bit to get everything to be installed in the right places; I don't remember the details off-hand (I'm usually just interested in a single .html file so I just copy that to the web server's directory). T -- Meat: euphemism for dead animal. -- Flora
Re: two mains
On 1/27/13 8:57 AM, David Nadlinger wrote: On Saturday, 26 January 2013 at 20:42:27 UTC, Tyro[17] wrote: Trying to learn from the ground up and would appreciate some assistance making sense of the following: // void main(){} [1] [...] This might not be directly relevant here, but in general, I'd steer clear of main() for such experiments. Due to its special nature (several possible signatures, but the calling code in druntime stays the same), there is quite a bit of extra magic going on internally. For example, you wouldn't normally find xor EAX, EAX in a void-returning functions, as its purpose is to set the return value to 0, which implicitly happens to make the void main() and void main(string[]) variants conform to the full int main(string[]) signature. David Thank you much. Things are starting to get a little clearer. Oh, thanks Vlad.
Re: lvalue - rvalue problem
On Sunday, January 27, 2013 12:42:28 Dicebot wrote: Looks like a bug in function overload selection. Definitely. - Jonathan M Davis
Re: lvalue - rvalue problem
On Sunday, 27 January 2013 at 23:05:16 UTC, Jonathan M Davis wrote: On Sunday, January 27, 2013 12:42:28 Dicebot wrote: Looks like a bug in function overload selection. Definitely. - Jonathan M Davis And that prevents a workaround for the missing auto ref. :o) It seems dmd 2.060 is far more useable than 2.061 (for users which use structs, of course). I will switch back.
Delegate type inferred as pure
This fails: void main() { int z; typeof((int a){return z;}) dg; dg = (int a) {return z;}; } Error: cannot implicitly convert expression (__lambda2) of type int delegate(int a) nothrow @safe to int delegate(int a) pure nothrow @safe But I can't make the delegate pure: dg = (int a) pure {return z;}; because it references z. Is the 'typeof((int a){return z;})' getting it wrong here?
Re: Tutorial on how to build DMD/druntime/phobos and docs from source?
On 01/27/2013 04:34 PM, H. S. Teoh wrote: On Sun, Jan 27, 2013 at 04:13:08PM -0500, Chad Joan wrote: I remember there being a tutorial on how to build DMD and such from source. I've been searching for a while and can't find it. It won't show up on google searches. Does anyone have a link? http://wiki.dlang.org/Building_DMD Exactly what I was thinking of. Right now I'm most interested in a tutorial on how to build the docs. [...] For docs, checkout d-programming-language.org from github, and run make on it to generate the HTML, CSS, etc.. Then checkout phobos and run 'make html'. I forget the exact commands but there should be analogous commands for druntime (and maybe dmd). You may need to tweak the directory structure a bit to get everything to be installed in the right places; I don't remember the details off-hand (I'm usually just interested in a single .html file so I just copy that to the web server's directory). T Cool, thank you!