Re: unpacking

2010-12-07 Thread Stewart Gordon
On 07/12/2010 17:29, spir wrote: Hello D people, Is there a way to unpack an array into local vars, as: auto x = [1,2,3]; a,b,c = x; import std.stdio; void unpack(A, T...)(out T vars, A data) { assert (vars.length == data.length); foreach (i, v; vars) { vars[i]

Re: C Bitfields in D

2010-12-07 Thread Simen kjaeraas
Andrej Mitrovic wrote: Cool! But, when is "ctod.exe" coming out? :p That should have been "cpptod". ;) As soon as you write it. -- Simen

Re: C Bitfields in D

2010-12-07 Thread Andrej Mitrovic
On 12/8/10, Andrej Mitrovic wrote: > On 12/8/10, Walter Bright wrote: >> Andrej Mitrovic wrote: >>> I haven't tried but maybe htod can help, try copypasting the code to a >>> header file and run it through htod. There's also some flags htod can >>> take to simplify the output, iirc. But maybe hto

Re: C Bitfields in D

2010-12-07 Thread Andrej Mitrovic
On 12/8/10, Walter Bright wrote: > Andrej Mitrovic wrote: >> I haven't tried but maybe htod can help, try copypasting the code to a >> header file and run it through htod. There's also some flags htod can >> take to simplify the output, iirc. But maybe htod isn't clever enough >> to do bitfields..

Re: C Bitfields in D

2010-12-07 Thread Walter Bright
Andrej Mitrovic wrote: I haven't tried but maybe htod can help, try copypasting the code to a header file and run it through htod. There's also some flags htod can take to simplify the output, iirc. But maybe htod isn't clever enough to do bitfields.. htod does bitfields. Give it a try!

Re: C Bitfields in D

2010-12-07 Thread Jesse Phillips
Jonathan M Davis Wrote: > Okay. I'm trying to get some C code to be properly callable from some D code, > which naturally involves some extern(C) blocks. One of the types that I have > to > deal with looks something like this: > > typedef struct > { > unsigned i:1; > } my_s

Re: C Bitfields in D

2010-12-07 Thread Ali Çehreli
Stanislav Blinov wrote: >> But bitfields in C may not use the same alignments used by >> bitfields!() on DMD so I think you have to test the sanity of the >> whole thing for each combination of D compiler, operating system and C >> compiler. > > hm... what alignments are you talking about? bitfie

Re: C Bitfields in D

2010-12-07 Thread Stanislav Blinov
bearophile wrote: Stanislav Blinov: I'm under the impression that struct my_struct { mixin(bitfields!( uint, "i", 1, uint, "", 31)); } should do the trick. But bitfields in C may not use the same alignments used by bitfields!() on DMD so I think you have to test the sanity of the whole thi

Re: inlining

2010-12-07 Thread spir
On Tue, 07 Dec 2010 16:20:45 +0100 Lutger Blijdestijn wrote: > Lutger Blijdestijn wrote: > > > spir wrote: > > > >> On Tue, 07 Dec 2010 13:44:18 +0100 > >> Lutger Blijdestijn wrote: > >> > >>> There are some other conditions that prevent inlining, it's best to > >>> check for it. iirc also fu

Re: free function on arrays & language operations

2010-12-07 Thread Jonathan M Davis
On Tuesday, December 07, 2010 10:10:31 spir wrote: > Hello again, > > I started to be found of defining types which basically are arrays with > free functions, instead of creating a struct or class with methods. Not > only we still have pseudo-method syntax (for arrays only), but this allows > cus

Re: C Bitfields in D

2010-12-07 Thread bearophile
Stanislav Blinov: > I'm under the impression that > > struct my_struct > { > mixin(bitfields!( > uint, "i", 1, > uint, "", 31)); > } > > should do the trick. But bitfields in C may not use the same alignments used by bitfields!() on DMD so I think you have to test the sanity of the whole thing

Re: free function on arrays & language operations

2010-12-07 Thread bearophile
spir: > But: is there a way to define functions corresponding to language operations > (opEquals, opIndex, toString...) without creating a true type? You may find some trick to do something like that, but it's not how D is supposed to be used. In D operators belong in a struct/class/enum. "alia

Re: unpacking

2010-12-07 Thread bearophile
spir: > Is there a way to unpack an array into local vars, as: > auto x = [1,2,3]; > a,b,c = x; Not yet, but I have asked this feature for tuples too and maybe someone has appreciated it. Bye, bearophile

free function on arrays & language operations

2010-12-07 Thread spir
Hello again, I started to be found of defining types which basically are arrays with free functions, instead of creating a struct or class with methods. Not only we still have pseudo-method syntax (for arrays only), but this allows customizing the type when needed. But: is there a way to define

Re: unpacking

2010-12-07 Thread Jonathan M Davis
On Tuesday, December 07, 2010 09:29:18 spir wrote: > Hello D people, > > Is there a way to unpack an array into local vars, as: > auto x = [1,2,3]; > a,b,c = x; No. There is no way to do multiple assignments to the left of an assignment operator. The only way that you can do multiple

unpacking

2010-12-07 Thread spir
Hello D people, Is there a way to unpack an array into local vars, as: auto x = [1,2,3]; a,b,c = x; Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com

Re: C Bitfields in D

2010-12-07 Thread Andrej Mitrovic
I haven't tried but maybe htod can help, try copypasting the code to a header file and run it through htod. There's also some flags htod can take to simplify the output, iirc. But maybe htod isn't clever enough to do bitfields.. On 12/7/10, Stanislav Blinov wrote: > 07.12.2010 11:58, Jonathan M D

Re: inlining

2010-12-07 Thread Lutger Blijdestijn
Lutger Blijdestijn wrote: > spir wrote: > >> On Tue, 07 Dec 2010 13:44:18 +0100 >> Lutger Blijdestijn wrote: >> >>> There are some other conditions that prevent inlining, it's best to >>> check for it. iirc also functions with loops, delegate and ref >>> parameters cannot be inlined for example

Re: inlining

2010-12-07 Thread Lutger Blijdestijn
spir wrote: > On Tue, 07 Dec 2010 13:44:18 +0100 > Lutger Blijdestijn wrote: > >> There are some other conditions that prevent inlining, it's best to check >> for it. iirc also functions with loops, delegate and ref parameters >> cannot be inlined for example. I'm not so sure about ref, that may

Re: How to exit a process?

2010-12-07 Thread Stanislav Blinov
06.12.2010 22:11, Adam Ruppe пишет: Is there a thing like C's exit() for a D program? Is simply using C's function good enough? Also take a look at core.runtime.Runtime.terminate()

Re: C Bitfields in D

2010-12-07 Thread Stanislav Blinov
07.12.2010 11:58, Jonathan M Davis пишет: Okay. I'm trying to get some C code to be properly callable from some D code, which naturally involves some extern(C) blocks. One of the types that I have to deal with looks something like this: typedef struct { unsigned i:1; } my

Re: inlining

2010-12-07 Thread spir
On Tue, 07 Dec 2010 13:44:18 +0100 Lutger Blijdestijn wrote: > There are some other conditions that prevent inlining, it's best to check > for it. iirc also functions with loops, delegate and ref parameters cannot > be inlined for example. I'm not so sure about ref, that may have been > improv

Re: inlining

2010-12-07 Thread Lutger Blijdestijn
Jonathan M Davis wrote: > On Tuesday 07 December 2010 03:05:28 spir wrote: >> Hello, >> >> Does dmd inline when appropriate (eg single-line func)? or is there a >> hint keyword? or what else? Eg how to have this inlined: >> >> private bool isPrecomposedHangulSylable (Code code) { >> /** whet

Re: inlining

2010-12-07 Thread Jonathan M Davis
On Tuesday 07 December 2010 03:05:28 spir wrote: > Hello, > > Does dmd inline when appropriate (eg single-line func)? or is there a hint > keyword? or what else? Eg how to have this inlined: > > private bool isPrecomposedHangulSylable (Code code) { > /** whether code is a precomposed Hangul s

Re: inlining

2010-12-07 Thread Christopher Nicholson-Sauls
On 12/07/10 05:05, spir wrote: > Hello, > > Does dmd inline when appropriate (eg single-line func)? or is there a hint > keyword? or what else? > Eg how to have this inlined: > > private bool isPrecomposedHangulSylable (Code code) { > /** whether code is a precomposed Hangul syllable ;-) */

inlining

2010-12-07 Thread spir
Hello, Does dmd inline when appropriate (eg single-line func)? or is there a hint keyword? or what else? Eg how to have this inlined: private bool isPrecomposedHangulSylable (Code code) { /** whether code is a precomposed Hangul syllable ;-) */ return (code >= FIRST_HANGUL_SYLLABLE) && (

C Bitfields in D

2010-12-07 Thread Jonathan M Davis
Okay. I'm trying to get some C code to be properly callable from some D code, which naturally involves some extern(C) blocks. One of the types that I have to deal with looks something like this: typedef struct { unsigned i:1; } my_struct; I have no idea how to do such a bitf