Re: PHP to D Conversion

2019-10-19 Thread Boris Carvajal via Digitalmars-d-learn

On Saturday, 19 October 2019 at 19:08:45 UTC, Vino wrote:

On Friday, 18 October 2019 at 14:56:05 UTC, Andre Pany wrote:

On Friday, 18 October 2019 at 09:21:46 UTC, Vino wrote:

On Friday, 18 October 2019 at 09:17:24 UTC, Vino wrote:

[...]


And now getting the error : Program exited with code 
-1073741819


Hi,

Maybe port 8080 is blocked, because there is an instance of 
your application running on the background. Just check by 
changing the port in the source code.


Kind regards
Andre


Hi Andre,

  Tried with different ports still no luck getting this error : 
Program exited with code -1073741819.


From,
Vino.B


Your program is crashing probably because you are dereferencing a 
null/ dangling pointer.
Build your program in debug mode and run it in a debugger, that 
way you will get a backtrace telling you the exactly line of the 
code when it happens.


Re: Help playing sounds using arsd.simpleaudio

2019-10-19 Thread Murilo via Digitalmars-d-learn

On Saturday, 19 October 2019 at 13:08:49 UTC, Adam D. Ruppe wrote:

try it now with the new version of simpleaudio.d from git


Ahh, now it works! Thank you so much man. I really appreciate 
the work you do with your library, I have been using it for 
everything, I'm now training a neural network using your library.


Re: PHP to D Conversion

2019-10-19 Thread Vino via Digitalmars-d-learn

On Friday, 18 October 2019 at 14:56:05 UTC, Andre Pany wrote:

On Friday, 18 October 2019 at 09:21:46 UTC, Vino wrote:

On Friday, 18 October 2019 at 09:17:24 UTC, Vino wrote:

[...]


And now getting the error : Program exited with code 
-1073741819


Hi,

Maybe port 8080 is blocked, because there is an instance of 
your application running on the background. Just check by 
changing the port in the source code.


Kind regards
Andre


Hi Andre,

  Tried with different ports still no luck getting this error : 
Program exited with code -1073741819.


From,
Vino.B


Re: Import sources from parent project

2019-10-19 Thread Andre Pany via Digitalmars-d-learn

On Saturday, 19 October 2019 at 18:00:12 UTC, Andrey wrote:

Hi,
I have got this structure of my project:

parentapp
dub.json
source
common.d
childapp1
dub.json
source
app.d
somefile.d
childapp2
dub.json
source
app.d


The "childapp1" and "childapp2" are standanole subprograms. I 
want to import file "common.d" in both "app.d". How to do it 
correctly?


I tried to write "import common;" but got error: " Error: 
module `common` is in file 'common.d' which cannot be read".

In "parentapp/dub.json" I also added these lines:

"dependencies": {
"parentapp:childapp1": "*",
"parentapp:childapp2": "*"
},
"subPackages": [
"./childapp1/",
"./childapp2/"
]


Hi,

In dub.json of your child apps you need to add a dependency to 
parentapp.


Kind regards
Andre


Import sources from parent project

2019-10-19 Thread Andrey via Digitalmars-d-learn

Hi,
I have got this structure of my project:

parentapp
dub.json
source
common.d
childapp1
dub.json
source
app.d
somefile.d
childapp2
dub.json
source
app.d


The "childapp1" and "childapp2" are standanole subprograms. I 
want to import file "common.d" in both "app.d". How to do it 
correctly?


I tried to write "import common;" but got error: " Error: module 
`common` is in file 'common.d' which cannot be read".

In "parentapp/dub.json" I also added these lines:

"dependencies": {
"parentapp:childapp1": "*",
"parentapp:childapp2": "*"
},
"subPackages": [
"./childapp1/",
"./childapp2/"
]


Re: Final necessary for inline optimization?

2019-10-19 Thread Johan Engelen via Digitalmars-d-learn

Just a brief answer.

On Saturday, 19 October 2019 at 15:58:08 UTC, IGotD- wrote:
Which one is it, LDC recognizes TestClass isn't derived or is 
sure that the class (c) isn't derived in particular?


It is the latter: the optimizer is able to prove that object c 
has a vtable that is known exactly. Then indexing into that 
vtable gives a definite function that can then be inlined.


Some more info:
The (suboptimal) trick that LDC employs is that after the call to 
`new`, LDC again sets the vtable of the object. It is 
superfluous, because it is already done by `new`, but `new` is 
opaque to the optimizer whereas the extra vtable write is not. So 
after the object creation, the optimizer knows exactly what 
vtable is used for that object. Now unfortunately, that only 
works for the first virtual call after `new`. Any opaque function 
that is called with `c` as parameter, e.g. calling a virtual 
function of that class will destroy knowledge about what vtable 
is stored in `c`. Per D language spec, the virtual function 
cannot overwrite the vtable pointer, but the optimizer does not 
know that so it assumes it might be overwritten and it no longers 
knows the contents of the vtable pointer.

You can see this happening here:
https://d.godbolt.org/z/8ERNhg

-Johan



Final necessary for inline optimization?

2019-10-19 Thread IGotD- via Digitalmars-d-learn
When I'm playing around with different D compilers I get 
different results regarding class method inlining. According most 
information I have seen, you must declare a class method final 
for the compiler to be able inline the method otherwise it will 
be a virtual table call.


Take this simple example.

import std.stdio;
import std.random;

class TestClass
{
static auto rnd = Random(42);
int tt = 3;

void doStuff()
{
tt = uniform(0, 15, rnd);
}
}

void main()
{
auto c = new TestClass;

c.doStuff();

writeln("TestClass is ", c.tt);
}


The random generator is used here so that CTFE doesn't kick in.

DMD certainly doesn't inline unless I use final (on class or 
doStuff) but when I use LDC, LDC seems to be able to figure out 
that the class isn't derived and inlines it regardless (-O option 
required). I see that LDC generates the method doStuff so it 
could also be that LDC knows which specific class it is (and not 
a derived one) in main and can inline for this particular case. 
Which one is it, LDC recognizes TestClass isn't derived or is 
sure that the class (c) isn't derived in particular? Would that 
mean that the vtable entry for doStuff is created regardless? Any 
other information why LDC do better?


I have previously seen a failed attempt to make final default 
(https://forum.dlang.org/thread/lfqoan$5qq$1...@digitalmars.com?page=1) but would that be necessary. Could the compiler figure out that a class method is final and manage that optimization by itself?




Re: Help playing sounds using arsd.simpleaudio

2019-10-19 Thread Adam D. Ruppe via Digitalmars-d-learn

try it now with the new version of simpleaudio.d from git