struct vs built-in type

2014-12-17 Thread Jack Applegame via Digitalmars-d-learn
Code: import std.stdio; struct Bar { int payload; alias payload this; } struct Foo { private { Bar m_bar; int m_baz; } @property { Bar bar() { return m_bar; } void bar(Bar v) { m_bar = v; }

Re: struct vs built-in type

2014-12-17 Thread Daniel Kozák via Digitalmars-d-learn
V Wed, 17 Dec 2014 07:57:24 + Jack Applegame via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: Code: import std.stdio; struct Bar { int payload; alias payload this; } struct Foo { private { Bar m_bar; int m_baz;

Re: struct vs built-in type

2014-12-17 Thread Rikki Cattermole via Digitalmars-d-learn
On 17/12/2014 8:57 p.m., Jack Applegame wrote: Code: import std.stdio; struct Bar { int payload; alias payload this; } struct Foo { private { Bar m_bar; int m_baz; } @property { Bar bar() { return m_bar; } void bar(Bar v) { m_bar =

Non-blocking UDP calls using std.socket

2014-12-17 Thread Andre Artus via Digitalmars-d-learn
I've written a small program that uses UdpSocket (std.socket) to query a DNS server for selected records. It works as expected, but I would like to try a non-blocking approach. The last time I wrote socket code (without a supporting library) was over a decade ago, and even then it was not

Re: Non-blocking UDP calls using std.socket

2014-12-17 Thread Rikki Cattermole via Digitalmars-d-learn
On 17/12/2014 9:20 p.m., Andre Artus wrote: I've written a small program that uses UdpSocket (std.socket) to query a DNS server for selected records. It works as expected, but I would like to try a non-blocking approach. The last time I wrote socket code (without a supporting library) was over

Re: struct vs built-in type

2014-12-17 Thread Jack Applegame via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 08:09:44 UTC, Daniel Kozák via Digitalmars-d-learn wrote: This should work only with ref by spec I totally agree.

Re: Non-blocking UDP calls using std.socket

2014-12-17 Thread Daniel Kozák via Digitalmars-d-learn
V Wed, 17 Dec 2014 08:20:42 + Andre Artus via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: I've written a small program that uses UdpSocket (std.socket) to query a DNS server for selected records. It works as expected, but I would like to try a non-blocking approach.

Re: Non-blocking UDP calls using std.socket

2014-12-17 Thread Andre Artus via Digitalmars-d-learn
-- snip -- Have you looked at vibe.d? https://github.com/rejectedsoftware/vibe.d/blob/master/examples/udp/source/app.d Thanks Rikki, I saw that before, but I was left with the impression that its doing blocking calls in a thread (which could very well be the simplest answer). I'll give it

Re: Non-blocking UDP calls using std.socket

2014-12-17 Thread Andre Artus via Digitalmars-d-learn
-- snip -- https://github.com/etcimon/libasync http://code.dlang.org/packages/libevent http://code.dlang.org/packages/libev http://code.dlang.org/packages/libuv Thanks Daniel, These links look interesting. Perhaps libasync could do the trick.

Re: Referring to alias parameters in a mixin template

2014-12-17 Thread ketmar via Digitalmars-d-learn
On Wed, 17 Dec 2014 02:34:15 + aldanor via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wednesday, 17 December 2014 at 02:12:52 UTC, anonymous wrote: Sure, straight forward: mixin template makeProperty(T, string name, alias func) { mixin(T %s()

VLA in Assembler

2014-12-17 Thread Foo via Digitalmars-d-learn
Hi, Could someone explain me, if and how it is possible to allocate a variable length array with inline assembly? Somewhat like int[] arr; int n = 42; asm { // allocate n stack space for arr } I know it is dangerous and all that, but I just want it know. ;)

Re: VLA in Assembler

2014-12-17 Thread bearophile via Digitalmars-d-learn
Foo: Hi, Could someone explain me, if and how it is possible to allocate a variable length array with inline assembly? Somewhat like int[] arr; int n = 42; asm { // allocate n stack space for arr } I know it is dangerous and all that, but I just want it know. ;) Doing it with

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-17 Thread zeljkog via Digitalmars-d-learn
On 15.12.14 01:00, Nordlöw wrote: Isn't this algorithm already encoded somewhere in Phobos? void append(T, Args...)(ref T[] arr, auto ref Args args){ { static if (args.length == 1) arr ~= args[0]; // inlined else{ arr.length += args.length; foreach(i, e; args)

Re: VLA in Assembler

2014-12-17 Thread Foo via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 10:59:09 UTC, bearophile wrote: Foo: Hi, Could someone explain me, if and how it is possible to allocate a variable length array with inline assembly? Somewhat like int[] arr; int n = 42; asm { // allocate n stack space for arr } I know it is

Re: VLA in Assembler

2014-12-17 Thread uri via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 11:39:43 UTC, Foo wrote: On Wednesday, 17 December 2014 at 10:59:09 UTC, bearophile wrote: Foo: Hi, Could someone explain me, if and how it is possible to allocate a variable length array with inline assembly? Somewhat like int[] arr; int n = 42; asm {

Re: VLA in Assembler

2014-12-17 Thread Foo via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 12:15:23 UTC, uri wrote: On Wednesday, 17 December 2014 at 11:39:43 UTC, Foo wrote: On Wednesday, 17 December 2014 at 10:59:09 UTC, bearophile wrote: Foo: Hi, Could someone explain me, if and how it is possible to allocate a variable length array with

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-17 Thread Tobias Pankrath via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 11:15:30 UTC, zeljkog wrote: On 15.12.14 01:00, Nordlöw wrote: Isn't this algorithm already encoded somewhere in Phobos? void append(T, Args...)(ref T[] arr, auto ref Args args){ { static if (args.length == 1) arr ~= args[0]; // inlined else{

Re: Referring to alias parameters in a mixin template

2014-12-17 Thread anonymous via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 02:34:16 UTC, aldanor wrote: On Wednesday, 17 December 2014 at 02:12:52 UTC, anonymous wrote: Sure, straight forward: mixin template makeProperty(T, string name, alias func) { mixin(T %s() @property { return func(); }.format(name)); }

Re: VLA in Assembler

2014-12-17 Thread btdc via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 10:35:39 UTC, Foo wrote: Hi, Could someone explain me, if and how it is possible to allocate a variable length array with inline assembly? Somewhat like int[] arr; int n = 42; asm { // allocate n stack space for arr } I know it is dangerous and

Re: VLA in Assembler

2014-12-17 Thread btdc via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 12:54:44 UTC, btdc wrote: On Wednesday, 17 December 2014 at 10:35:39 UTC, Foo wrote: Hi, Could someone explain me, if and how it is possible to allocate a variable length array with inline assembly? Somewhat like int[] arr; int n = 42; asm { //

Re: Non-blocking UDP calls using std.socket

2014-12-17 Thread via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 09:37:47 UTC, Andre Artus wrote: -- snip -- Have you looked at vibe.d? https://github.com/rejectedsoftware/vibe.d/blob/master/examples/udp/source/app.d Thanks Rikki, I saw that before, but I was left with the impression that its doing blocking calls in a

Re: Fastest Way to Append Multiple Elements to an Array

2014-12-17 Thread zeljkog via Digitalmars-d-learn
On 17.12.14 13:30, Tobias Pankrath wrote: void append(T, Args...)(ref T[] data, Args args) { static size_t estimateLength(Args args) { size_t result; foreach(e; args) static if(hasLength!(typeof(e))) result += e.length; else

Re: VLA in Assembler

2014-12-17 Thread Foo via Digitalmars-d-learn
And it is using malloc... ;) I wanted something that increases the stack pointer ESP. e.g. void main() { int[] arr; int n = 42; writeln(arr.length); writeln(arr.ptr); asm { mov EAX, n; mov [arr + 8],

core.bitop.bt not faster than ?

2014-12-17 Thread Trollgeir via Digitalmars-d-learn
I've been doing some benchmarking the bt function (http://dlang.org/phobos/core_bitop.html) up against a regular bit -operator, and I'm a bit confused over the timings. I'd expect the bt function to be up to 32 times faster as I thought it only compared two bits, and not the entire length of

Re: VLA in Assembler

2014-12-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 12:29:53 UTC, Foo wrote: And how? I'm on Windows. Digital Mars sells an obj2asm function that will disassemble dmd generated code. I think it is in the $15 basic utility package. But VLA/alloca is more complex than a regular function - the compiler needs

Re: core.bitop.bt not faster than ?

2014-12-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 14:12:16 UTC, Trollgeir wrote: I'd expect the bt function to be up to 32 times faster as I thought it only compared two bits, and not the entire length of bits in the uint. The processor doesn't work in terms of bits like that - it still needs to look at the

Problem with compilation( DMD compile run failed with exit code -6 )

2014-12-17 Thread Akzwar via Digitalmars-d-learn
We write new signal/slot system? like in QT. https://github.com/dexset/descore/tree/de9ccae7a9907e5098f244a8683e42fb660d0b35/import/des/util/signal https://github.com/dexset/descore/tree/de9ccae7a9907e5098f244a8683e42fb660d0b35/import/des/util/object Unittests works fine, but after trying using

Re: VLA in Assembler

2014-12-17 Thread btdc via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 14:11:32 UTC, Foo wrote: And it is using malloc... ;) I wanted something that increases the stack pointer ESP. e.g. void main() { int[] arr; int n = 42; writeln(arr.length); writeln(arr.ptr); asm {

Re: Binding non-trivial C++ structs

2014-12-17 Thread Paul O'Neil via Digitalmars-d-learn
On 12/17/2014 03:01 AM, Kagamin wrote: previous thread: http://forum.dlang.org/post/mailman.1464.1415039051.9932.digitalmar...@puremagic.com I read that thread. I don't understand if / how it answers this question. -- Paul O'Neil Github / IRC: todayman

Re: Referring to alias parameters in a mixin template

2014-12-17 Thread aldanor via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 12:49:10 UTC, anonymous wrote: As far as I understand, the string mixin is resolved first, and then the template mixin takes place. So the progression is somewhat like this (pseudo code): mixin makeProperty!(int, foo, f); /* Replace makeProperty with its

Re: Problem with compilation( DMD compile run failed with exit code -6 )

2014-12-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 17, 2014 at 03:13:27PM +, Akzwar via Digitalmars-d-learn wrote: [...] Finally compilation crashes with exit code -6: dmd: class.c:859: virtual void ClassDeclaration::semantic(Scope*): Assertion `type-ty != Tclass || ((TypeClass *)type)-sym == this' failed. [...] This is an ICE

Re: core.bitop.bt not faster than ?

2014-12-17 Thread Trollgeir via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 14:58:13 UTC, Adam D. Ruppe wrote: On Wednesday, 17 December 2014 at 14:12:16 UTC, Trollgeir wrote: I'd expect the bt function to be up to 32 times faster as I thought it only compared two bits, and not the entire length of bits in the uint. The processor

Re: VLA in Assembler

2014-12-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 14:11:32 UTC, Foo wrote: asm { mov EAX, n; mov [arr + 8], ESP; sub [ESP], EAX; mov [arr + 0], EAX; } but that does not work... That wouldn't work even with malloc remember, an

Re: VLA in Assembler

2014-12-17 Thread Namespaces via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 15:20:28 UTC, btdc wrote: On Wednesday, 17 December 2014 at 14:11:32 UTC, Foo wrote: And it is using malloc... ;) I wanted something that increases the stack pointer ESP. e.g. void main() { int[] arr; int n = 42;

Re: core.bitop.bt not faster than ?

2014-12-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 17, 2014 at 04:08:40PM +, Trollgeir via Digitalmars-d-learn wrote: On Wednesday, 17 December 2014 at 14:58:13 UTC, Adam D. Ruppe wrote: On Wednesday, 17 December 2014 at 14:12:16 UTC, Trollgeir wrote: I'd expect the bt function to be up to 32 times faster as I thought it only

Re: VLA in Assembler

2014-12-17 Thread Foo via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 16:10:40 UTC, Adam D. Ruppe wrote: On Wednesday, 17 December 2014 at 14:11:32 UTC, Foo wrote: asm { mov EAX, n; mov [arr + 8], ESP; sub [ESP], EAX; mov [arr + 0], EAX; } but that

Re: Referring to alias parameters in a mixin template

2014-12-17 Thread anonymous via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 15:40:25 UTC, aldanor wrote: On Wednesday, 17 December 2014 at 12:49:10 UTC, anonymous wrote: [...] As to if there were `T` or `func` in the target scope, they'd be shadowed by the template parameters, no matter if there's a string mixin or not. That makes

Contract programming

2014-12-17 Thread Oleg via Digitalmars-d-learn
Is this behavior normal or it's bug? [code] import std.stdio; class A { float func( float x ) in { assert( x 0 ); stderr.writeln( A.func in block ); } body { stderr.writeln( A.func body block ); return x / 3; } } class B : A {

Re: Contract programming

2014-12-17 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 21:07:12 UTC, Oleg wrote: Is this behavior normal or it's bug? [code] import std.stdio; class A { float func( float x ) in { assert( x 0 ); stderr.writeln( A.func in block ); } body { stderr.writeln( A.func

Re: Contract programming

2014-12-17 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 17 December 2014 at 21:17:57 UTC, John Colvin wrote: On Wednesday, 17 December 2014 at 21:07:12 UTC, Oleg wrote: Is this behavior normal or it's bug? [code] import std.stdio; class A { float func( float x ) in { assert( x 0 ); stderr.writeln( A.func in

A mixin template for automatic property generation (criticize my code?)

2014-12-17 Thread aldanor via Digitalmars-d-learn
I'm trying (hard) to learn D templating, and (thanks to the great help on this forum) I've been able to solve one of the recent tasks I've been struggling about for a while. Wonder if anyone would take a moment to criticize the code so we rookies could learn? Could this be done more

Re: A mixin template for automatic property generation (criticize my code?)

2014-12-17 Thread aldanor via Digitalmars-d-learn
I've no idea why the forum decided to wrap all code; anyway: https://gist.github.com/aldanor/ddc45b2710a2deb9ee2b

Re: threading issues with D - C - Python

2014-12-17 Thread Ellery Newcomer via Digitalmars-d-learn
On 12/07/2014 03:12 PM, Michael wrote: now to figure out how to use them in the general case. This is great.. Thank you. I'm looking forward to being able to try the finished result. My build servers are broken at the moment, but I think I have this fixed, on linux at least.

Weird UFC and opCall issues

2014-12-17 Thread Jay Pinkman via Digitalmars-d-learn
void main () { struct X { string x; void opCall (string y) { import std.stdio; writeln(%s %s!, x, y); } } auto x = X(hello); world.x; } source/main.d(12): Error: need 'this' for 'opCall' of type 'void(string y)'

Re: Weird UFC and opCall issues

2014-12-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 December 2014 at 02:42:32 UTC, Jay Pinkman wrote: source/main.d(12): Error: need 'this' for 'opCall' of type 'void(string y)' D doesn't have a really clean separation between static and non-static methods. It sees an opCall and thinks you're trying to call it, but since it

Re: Weird UFC and opCall issues

2014-12-17 Thread Jay Pinkman via Digitalmars-d-learn
On Thursday, 18 December 2014 at 02:45:01 UTC, Adam D. Ruppe wrote: D doesn't have a really clean separation between static and non-static methods. hmm.. i thought that's what 'static' is for. It sees an opCall and thinks you're trying to call it, but since it isn't static, it complains you

Derelict SDL2 library not loading on OS X

2014-12-17 Thread Joel via Digitalmars-d-learn
I've installed SDL2. Joels-MacBook-Pro:DerelictTest joelcnz$ cat test.d import derelict.sdl2.sdl; int main() { DerelictSDL2.load(); } Joels-MacBook-Pro:DerelictTest joelcnz$ dmd test libDerelictSDL2.a libDerelictUtil.a Joels-MacBook-Pro:DerelictTest joelcnz$ ./test

Re: Derelict SDL2 library not loading on OS X

2014-12-17 Thread Jack via Digitalmars-d-learn
On Thursday, 18 December 2014 at 06:29:34 UTC, Joel wrote: I've installed SDL2. Joels-MacBook-Pro:DerelictTest joelcnz$ cat test.d import derelict.sdl2.sdl; int main() { DerelictSDL2.load(); } Joels-MacBook-Pro:DerelictTest joelcnz$ dmd test libDerelictSDL2.a libDerelictUtil.a

Re: Derelict SDL2 library not loading on OS X

2014-12-17 Thread Joel via Digitalmars-d-learn
Did you check if you installed SDL already on your machine? I followed the SDL2 instructions (on the SDL web site) for OS X before using Derelict. It had about copying to a curtain folder, which I did.

Re: Derelict SDL2 library not loading on OS X

2014-12-17 Thread Jack via Digitalmars-d-learn
On Thursday, 18 December 2014 at 07:10:43 UTC, Joel wrote: Did you check if you installed SDL already on your machine? I followed the SDL2 instructions (on the SDL web site) for OS X before using Derelict. It had about copying to a curtain folder, which I did. Just noticed that you used