Re: is there a way to embed python 3.7 code in D program?

2019-05-12 Thread evilrat via Digitalmars-d-learn

On Monday, 13 May 2019 at 01:35:58 UTC, evilrat wrote:


I have project using pyd with python 3.7, that also using ptvsd 
(visual studio debugger for python package) to allow mixed 
debugging right inside VS Code.


I'll reduce the code and upload somewhere later.



https://github.com/Superbelko/pyd-min

Here. Super minimal example, ptvsd can be commented out as well, 
it is there entirely for debugging.


Re: is there a way to embed python 3.7 code in D program?

2019-05-12 Thread evilrat via Digitalmars-d-learn

On Sunday, 12 May 2019 at 22:36:43 UTC, torea wrote:


ok, I'll do some more tests with pyd then.
And if I cannot get it to work, I'll have a look at the package!



I have project using pyd with python 3.7, that also using ptvsd 
(visual studio debugger for python package) to allow mixed 
debugging right inside VS Code.


I'll reduce the code and upload somewhere later.




Re: Windows / redirect STDERR to see assert messages

2019-05-12 Thread Adam D. Ruppe via Digitalmars-d-learn

On Sunday, 12 May 2019 at 13:39:15 UTC, Robert M. Münch wrote:
If an assert fails, I don't see any output. Is assert using 
something else? What's wrong about this approach?


You might need to catch all the throwable exceptions and print 
your way instead...


Re: is there a way to embed python 3.7 code in D program?

2019-05-12 Thread torea via Digitalmars-d-learn

On Sunday, 12 May 2019 at 21:01:31 UTC, Nicholas Wilson wrote:

On Sunday, 12 May 2019 at 20:06:34 UTC, torea wrote:

Hi,

I'd like to use D for the "brain" of a small robot (Anki 
vector) whose API is coded in Python 3.6+.

I had a look at Pyd but it's limited to python 2.7...


It isn't. You may needs to set a dub version, or it may pick up 
the 2.7 as the default but it definitely works (I'm travelling 
ATM, can't check).


ok, I'll do some more tests with pyd then.
And if I cannot get it to work, I'll have a look at the package!

Many thanks!!


Re: is there a way to embed python 3.7 code in D program?

2019-05-12 Thread Nicholas Wilson via Digitalmars-d-learn

On Sunday, 12 May 2019 at 20:06:34 UTC, torea wrote:

Hi,

I'd like to use D for the "brain" of a small robot (Anki 
vector) whose API is coded in Python 3.6+.

I had a look at Pyd but it's limited to python 2.7...


It isn't. You may needs to set a dub version, or it may pick up 
the 2.7 as the default but it definitely works (I'm travelling 
ATM, can't check).


Re: is there a way to embed python 3.7 code in D program?

2019-05-12 Thread Andre Pany via Digitalmars-d-learn

On Sunday, 12 May 2019 at 20:06:34 UTC, torea wrote:

Hi,

I'd like to use D for the "brain" of a small robot (Anki 
vector) whose API is coded in Python 3.6+.

I had a look at Pyd but it's limited to python 2.7...
Would there be other ways to call python functions and retrieve 
the python objects (including camera image) inside a D program?


Best regards


You could try to do s.th. similar like this package

http://code.dlang.org/packages/matplotlib-d

Kind regards
Andre



is there a way to embed python 3.7 code in D program?

2019-05-12 Thread torea via Digitalmars-d-learn

Hi,

I'd like to use D for the "brain" of a small robot (Anki vector) 
whose API is coded in Python 3.6+.

I had a look at Pyd but it's limited to python 2.7...
Would there be other ways to call python functions and retrieve 
the python objects (including camera image) inside a D program?


Best regards


Re: Compile time mapping

2019-05-12 Thread Bastiaan Veelo via Digitalmars-d-learn

On Sunday, 12 May 2019 at 18:47:20 UTC, Bogdan wrote:

On Sunday, 12 May 2019 at 17:53:56 UTC, Bastiaan Veelo wrote:
If I understand your question correctly, you have two enums of 
equal length, and you want to convert members across enums 
according to their position, right?


My question was very vague, sorry about that.

In my use case I'd like to map SDL2 keyboard scan codes to my 
own game input keyboard codes. The two enums would look 
something like this:


```
enum SDL_Scancode
{
SDL_SCANCODE_UNKNOWN = 0,
SDL_SCANCODE_A = 4,
SDL_SCANCODE_B = 5,
SDL_SCANCODE_C = 6,
SDL_SCANCODE_D = 7,
}

enum MY_Scancode
{
  KEY_A,
  KEY_B,
  KEY_C,
  KEY_D,
}
```

The two enums are not of equal length, so in the end I just 
decided to create an immutable array of type My_Scancode[] 
where the index is an SDL_Scancode and the value is the 
corresponding MY_Scancode enum member. I'm ok with using some 
memory for this, as long as it's as fast as possible.


If the only difference is the extra _UNKNOWN member, you can 
still use the static foreach approach. Just make it a 
non-template function and rip out the checks, and add a +1 in the 
right place.


Re: Compile time mapping

2019-05-12 Thread Bogdan via Digitalmars-d-learn

On Sunday, 12 May 2019 at 17:53:56 UTC, Bastiaan Veelo wrote:
If I understand your question correctly, you have two enums of 
equal length, and you want to convert members across enums 
according to their position, right?


My question was very vague, sorry about that.

In my use case I'd like to map SDL2 keyboard scan codes to my own 
game input keyboard codes. The two enums would look something 
like this:


```
enum SDL_Scancode
{
SDL_SCANCODE_UNKNOWN = 0,
SDL_SCANCODE_A = 4,
SDL_SCANCODE_B = 5,
SDL_SCANCODE_C = 6,
SDL_SCANCODE_D = 7,
}

enum MY_Scancode
{
  KEY_A,
  KEY_B,
  KEY_C,
  KEY_D,
}
```

The two enums are not of equal length, so in the end I just 
decided to create an immutable array of type My_Scancode[] where 
the index is an SDL_Scancode and the value is the corresponding 
MY_Scancode enum member. I'm ok with using some memory for this, 
as long as it's as fast as possible.


Re: Compile time mapping

2019-05-12 Thread Bastiaan Veelo via Digitalmars-d-learn

On Sunday, 12 May 2019 at 17:53:56 UTC, Bastiaan Veelo wrote:

On Saturday, 11 May 2019 at 15:48:44 UTC, Bogdan wrote:
What would be the most straight-forward way of mapping the 
members of an enum to the members of another enum (one-to-one 
mapping) at compile time?


If I understand your question correctly, you have two enums of 
equal length, and you want to convert members across enums 
according to their position, right? You can do that with a 
little bit of template programming and static foreach. The 
following works irrespective of underlying value and type, the 
only requirement is that there are no duplicate values:


https://run.dlang.io/is/dNssel


There was an error in the error reporting. That should teach me 
to never copy+paste if you can static foreach :-) This one is 
better:


https://run.dlang.io/is/TVl9db


Re: Compile time mapping

2019-05-12 Thread Bastiaan Veelo via Digitalmars-d-learn

On Saturday, 11 May 2019 at 15:48:44 UTC, Bogdan wrote:
What would be the most straight-forward way of mapping the 
members of an enum to the members of another enum (one-to-one 
mapping) at compile time?


If I understand your question correctly, you have two enums of 
equal length, and you want to convert members across enums 
according to their position, right? You can do that with a little 
bit of template programming and static foreach. The following 
works irrespective of underlying value and type, the only 
requirement is that there are no duplicate values:


https://run.dlang.io/is/dNssel
```
void main()
{
enum FromEnum {F1 = 10, F2, F3}
enum ToEnum   {T1 = 20, T2, T3}
enum CharEnum : char {C1 = 'c', C2, C3}

static assert(to!ToEnum(FromEnum.F2) == ToEnum.T2);
static assert(to!ToEnum(FromEnum.F2) == 21);
static assert(to!CharEnum(FromEnum.F2) == CharEnum.C2);
static assert(to!CharEnum(FromEnum.F2) == 'd');
}

// Converts enumerations by position.
T to(T, F)(F f) if (is(F==enum) && is(T == enum))
{
import std.traits;
import std.meta;
static assert(NoDuplicates!(EnumMembers!F).length == 
EnumMembers!F.length,

  F.stringof ~ " has duplicates.");
static assert(NoDuplicates!(EnumMembers!T).length == 
EnumMembers!T.length,

  F.stringof ~ " has duplicates.");
static assert(EnumMembers!F.length == EnumMembers!T.length,
  F.stringof ~ " and " ~ T.stringof ~ " differ in 
length.");

static foreach(i, t; EnumMembers!T)
if (rank(f) == i)
return t;
assert(0, "Not an enum member");
}

// Returns i if e is the i-th enumerator of E.
static size_t rank(E)(E e) if (is(E == enum))
{
import std.traits;
static foreach (i, member; EnumMembers!E)
if (e == member)
return i;
assert(0, "Not an enum member");
}
```


Re: Framework design, initialization and framework usage

2019-05-12 Thread kdevel via Digitalmars-d-learn

On Wednesday, 8 May 2019 at 09:15:41 UTC, Ron Tarrant wrote:

On Wednesday, 8 May 2019 at 06:30:56 UTC, Robert M. Münch wrote:



Our focus is executable size (I'm an old school guy) and speed.


What about correctness?

[...]
For some simple real-time grid example see: 
https://www.dropbox.com/s/eyya0brc5sbcs09/Bildschirmaufnahme%202019-05-02%20um%2022.09.54.mov?dl=0


Very impressive.


Don't want to curb anybody's ambitions but I see massive aliasing 
in the space and in the time domain. I actually wanted to post a 
link to the antigrain website, which, however, was removed after 
its author had passed away 2013. Apparently there is no archive 
copy of that impressing website. Remains: Wikipedia [1].


[1] https://en.wikipedia.org/wiki/Anti-Grain_Geometry


Re: LDC2 and classic profiling

2019-05-12 Thread Johan Engelen via Digitalmars-d-learn

On Saturday, 11 May 2019 at 11:34:35 UTC, Denis Feklushkin wrote:

On Saturday, 11 May 2019 at 09:12:24 UTC, Johan Engelen wrote:


Those calls are to templated functions I presume?


No


Then I don't understand how you'd see instrumentation on 
functions that you did not compile with -fprofile-instr-generate 
(indirect calls to such functions may be recorded); the std lib 
is not compiled with profiling instrumentation, and so you 
shouldn't see any internal instrumentation of it. Unless those 
functions are instantiated in your object file (e.g. templates or 
explicitly inlined functions).




Also I changed flags to "dflags-ldc": 
["-fprofile-instr-generate", "-O0"] - second flag disables 
optimisation (I assumed that optimizations magically 
completely remove calls to my functions. But this is probably 
not the case.)


No, indeed, -O0 doesn't (shouldn't!) matter.


Ok.

It is strange that you don't see calls to your functions. Just 
to verify, could you compile a simple program manually 
(without dub) and verify that you see calls to your own 
functions?


Tried, and it works!


Lambdas should also be instrumented, so please test that.


Works on simple program too.


Excellent.

I think dub -v will output the exact commands that dub is 
executing.
Looks like some parts are not compiled with the compile flag, and 
some other parts are?


By the way, if you are on linux, then XRay should work like 
with clang ( -fxray-instrument )


Tried it, and xray also does not returns any info about my own 
functions...


You tried with DUB or manually? Note that XRay has a 
(configurable) threshold for not instrumenting very small 
functions.
See for example this test: 
https://github.com/ldc-developers/ldc/blob/master/tests/instrument/xray_simple_execution.d


-Johan



Re: windowsx.h

2019-05-12 Thread rikki cattermole via Digitalmars-d-learn

On 13/05/2019 5:00 AM, Robert M. Münch wrote:

On 2019-05-12 10:33:16 +, Robert M. Münch said:

Is there any reason why windowsx.h seems to be missing from 
core.sys.windows?


Using DStep I now converted windowsx.h into windowsx.d

Is creating a pull-request the correct way to submit it to druntime so 
that it can be included?


Yes.
But a generated binding may not be good enough as it is.
You may need to modify it.



Re: windowsx.h

2019-05-12 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-05-12 10:33:16 +, Robert M. Münch said:


Is there any reason why windowsx.h seems to be missing from core.sys.windows?


Using DStep I now converted windowsx.h into windowsx.d

Is creating a pull-request the correct way to submit it to druntime so 
that it can be included?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: dub / debug build / missing symbols

2019-05-12 Thread Robert M. Münch via Digitalmars-d-learn

On 2019-05-12 16:46:10 +, Ron Tarrant said:

Not really familiar with this, but at a guess... Have you tried it 
without the 32-bit references?


There are not 32bit references, but 64bit libs. MS was so smart to name 
the API Win32, doesn't has to do anything with 32 or 64 bit...


If I'm removing the buildType and only use my debug lib, it works and I 
get the symbols.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: dub / debug build / missing symbols

2019-05-12 Thread Ron Tarrant via Digitalmars-d-learn

On Saturday, 11 May 2019 at 16:12:34 UTC, Robert M. Münch wrote:
I somehow managed to get debug symbols into my dub project in 
the past.


Now I'm trying to extend my dub configuration to use different 
libs for debug and release versions.


 "buildTypes"  : {
   "debug" : {
 "libs-windows-x86_64"   : ["user32", "gdi32", 
"mylib1_d_x64", "mylib2_d_x64"],

   },

   "release" : {
 "libs-windows-x86_64"   : ["user32", "gdi32", 
"mylib1_x64", "mylib2_x64"],

   }
 },

And now, the debug build doesn't contain any symbols anymore... 
what am I missing?


Not really familiar with this, but at a guess...

Have you tried it without the 32-bit references?


Re: Compile time mapping

2019-05-12 Thread Patrick Schluter via Digitalmars-d-learn

On Saturday, 11 May 2019 at 15:48:44 UTC, Bogdan wrote:
What would be the most straight-forward way of mapping the 
members of an enum to the members of another enum (one-to-one 
mapping) at compile time?


An example of a Initial enum that creates a derived enum using 
the same element names but applying a transformation via a 
function foo() pus adding some other enum elements in the Derived 
one not present in the Initial.

It's a little bit clumsy but works very well.
I use this at module level. This allows to have the Derived enum 
at compile time so that it can be used to declare variables or 
functions at compile time.




mixin({
  string code = "enum Derived : ulong { "~
"init = 0,";  /* We set the dummy 
init value to 0 */

  static foreach(i; __traits(allMembers, Initial)) {
code ~= i~"= foo(Initial."~i~"),";
  }
  code ~= "
ALL=  Whatever,
THING  =  42,
  return code ~ "}";
}());




Windows / redirect STDERR to see assert messages

2019-05-12 Thread Robert M. Münch via Digitalmars-d-learn

When developing Windows GUI applications I use:

 // detach from console and attach to a new one, works for x86 and x86_64
 FreeConsole();
 AllocConsole();

 freopen("CONIN$", "r", stdin);
 freopen("CONOUT$", "w", stdout);
 freopen("CONOUT$", "w", stderr);

so that the GUI app opens a console for writeln() output etc. I assumed 
this should work for assert() messages as well. But it seems it 
doesn't. If an assert fails, I don't see any output. Is assert using 
something else? What's wrong about this approach?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: LDC2 and classic profiling

2019-05-12 Thread Denis Feklushkin via Digitalmars-d-learn

On Saturday, 11 May 2019 at 11:38:17 UTC, Denis Feklushkin wrote:



Maybe DUB caches binaries and linker links previous 
non-instrumented object files?
I tried "dub clean" and "dub clean-caches" but maybe it is need 
remove someting else?


Checked with "dub -f" and nothing changed.


windowsx.h

2019-05-12 Thread Robert M. Münch via Digitalmars-d-learn

Is there any reason why windowsx.h seems to be missing from core.sys.windows?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Dub fetch

2019-05-12 Thread Marco de Wild via Digitalmars-d-learn

On Saturday, 11 May 2019 at 14:27:50 UTC, Russel Winder wrote:

Hi,

Is there a way of asking which version of package XXX  "dub 
fetch XXX"
will actually fetch. I would like to avoid checking the 
contents of

~/.dub/packages before and after.


Use the `--annotate` option:

$ dub fetch dlangide --annotate
Fetching dlangide 0.8.17...
Please note that you need to use `dub run ` or add it to 
dependencies of your package to actually use/run it. dub does not 
do actual installation of packages outside of its own ecosystem.