Re: Windows 64

2013-10-07 Thread Rainer Schuetze



On 07.10.2013 03:31, "Casper Færgemand" " wrote:

Hey, I've been trying for a while to compile 64 bit programs on a
Windows 7 platform. The setup is the following:

Version: 2.063.2
OS: Windows 7 64
Linked: VS 11 64 bit linker

sc.ini:

[Version]
version=7.51 Build 020

[Environment]
LIB="%@P%\..\lib";\dm\lib
DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import"
LINKCMD=%@P%\link.exe
LINKCMD64=%VCINSTALLDIR%\bin\amd64\link.exe
VCINSTALLDIR=%VCINSTALLDIR%
WindowsSdkDir=%WindowsSdkDir%


Environment variables are as follows:

VCINSTALLDIR: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\
WindowsSdkDir: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\

(I had initially forgot a \ at the end of the environment variables)

On compiling the program "void main() {}" with -m64 -v in Eclipse with
DDT (same result for command line), I get this thrown back:


  Build Commands:  
-od"bin"
-of"bin\temp.exe"

-I"src"

"src\temp.d"

-m64 -v

binaryC:\D\Tools\dmd2\windows\bin\dmd.exe
version   v2.063.2
configC:\D\Tools\dmd2\windows\bin\sc.ini
parse temp
importall temp
import object
(C:\D\Tools\dmd2\windows\bin\..\..\src\druntime\import\object.di)
semantic  temp
entry main  src\temp.d
semantic2 temp
semantic3 temp
code  temp
function  D main
C:\Program Files (x86)\Microsoft Visual Studio
11.0\VC\bin\amd64\link.exe /NOLOGO "bin\temp" /OUT:"bin\temp.exe"
  "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio
11.0\VC\lib\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\lib\x64"
C:\D\Tools\dmd2\windows\bin\..\lib\shell32.lib : warning LNK4003:
invalid library format; library ignored
C:\D\Tools\dmd2\windows\bin\..\lib\kernel32.lib : warning LNK4003:
invalid library format; library ignored
C:\D\Tools\dmd2\windows\bin\..\lib\shell32.lib : warning LNK4003:
invalid library format; library ignored
C:\D\Tools\dmd2\windows\bin\..\lib\kernel32.lib : warning LNK4003:
invalid library format; library ignored
phobos64.lib(dmain2_480_47b.obj) : error LNK2019: unresolved external
symbol IsDebuggerPresent referenced in function _d_run_main
LIBCMT.lib(a_map.obj) : error LNK2001: unresolved external symbol
__imp_WideCharToMultiByte

...

bin\temp.exe : fatal error LNK1120: 103 unresolved externals
--- errorlevel 1120


I took the liberty of removing the mid section, since everything was
LIBCMT.lib and phobos64.lib things that were unresolved. Any heads up on
what I need to tinker with?


The linker does not find the import libraries from the Windows SDK, so 
it hits the 32-bit libraries that come with dmd.


The released sc.ini does not work with VS2012+ or a Windows SDK 8, you 
should add the following lines to it:


[Environment64]
LIB=%@P%\..\lib;%VCINSTALLDIR%\lib\amd64;%WindowsSdkDir%\Lib\win8\um\x64
;; for some additional improvements
PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\..\Common7\IDE
DFLAGS=%DFLAGS% -L/OPT:NOICF



Re: A few questions about safe concurrent programming assumptions

2013-10-07 Thread John Colvin

On Monday, 7 October 2013 at 05:26:10 UTC, Nicholas Smith wrote:
Thanks Jonathon, these are the kinds of warnings I was looking 
for.


There are _no_ guarantees of atomicity with shared. Yes, on 
some
architectures, writing a word size might be atomic, but the 
language

guarantees no such thing.


I was looking narrowly at x86, which I *think* such a statement 
is safe to say for. But you're absolutely right that I should 
probably safeguard against the possibility that something could 
go wrong there.



either that or
you have to mess around with core.atomic, which is the kind of 
code that is
_very_ easy to screw up, so it's generally advised not to 
bother with

core.atomic unless you actually _need_ to.


It will at least ensure sequential consistency, atomic 
load/store, and atomic operations (via atomicOp), will it not?


It will ensure whatever you tell it to. It's a set of convenience 
wrappers around some assembly instructions.


Re: Windows 64

2013-10-07 Thread Casper Færgemand

On Monday, 7 October 2013 at 07:03:39 UTC, Rainer Schuetze wrote:
The linker does not find the import libraries from the Windows 
SDK, so it hits the 32-bit libraries that come with dmd.


The released sc.ini does not work with VS2012+ or a Windows SDK 
8, you should add the following lines to it:


[Environment64]
LIB=%@P%\..\lib;%VCINSTALLDIR%\lib\amd64;%WindowsSdkDir%\Lib\win8\um\x64
;; for some additional improvements
PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\..\Common7\IDE
DFLAGS=%DFLAGS% -L/OPT:NOICF


Thank you. I added the lines and I'm still getting the same 103 
unresolved externals. Commenting out stuff in the file makes dmd 
throws other errors, so I'm sure I'm editing the correct sc.ini.

Where are the correct libraries supposed to be exactly?


Re: How to add time to Clock.currTime

2013-10-07 Thread JohnnyK
On Saturday, 5 October 2013 at 02:42:49 UTC, Jonathan M Davis 
wrote:

On Saturday, October 05, 2013 03:31:33 JohnnyK wrote:
Wow I appreciate the quick response. Ok I have seen this 
before.

What is the dur? Where is dur defined? Also I am confused how
300.seconds would work. How can a literal number have 
properties?


dur is in core.time as are the aliases for each of the units:

http://dlang.org/phobos/core_time.html#dur

300.seconds works thanks to UFCS (Universal Function Call 
Syntax). Any time

that the compiler sees

x.foo(args);

and foo is not a member function of x, it converts it to

foo(x, args);

So, if there's a free function with that name which will work 
with those
arguments, then it will be called (otherwise, you'll get an 
error, because
there is no matching function). The parens can be dropped on 
300.seconds,
because the parens are optional on function calls that take no 
arguments.
seconds is not actually a property function (it's an alias for 
dur!"seconds,
which is not a property function either), but the fact that the 
parens are
optional makes it so that you can use it with the same syntax 
that would be

used for a getter property.

If you want an overview of std.datetime and the time stuff in 
Phobos, I suggest

that you read

http://dlang.org/intro-to-datetime.html

- Jonathan M Davis


I appreciate everyone's responses and yes Jonathan that article 
did help.  I know I looked under the article section but I must 
have overlooked this article.


Re: Getting the missing Windows functions

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, Matt  wrote:
> I have never had to specify any Windows libs for linking under
> DMD. What is different about these?

DMD links in user32.lib and kernel32.lib by default. But if you want
to use other libs like GDI you're going to have to pass them at the
command line.


std.math.abs and shared/const/immutable BigInts

2013-10-07 Thread Joseph Rushton Wakeling

Hello all,

I recently discovered this issue with std.bigint.BigInt and std.math.abs:
http://d.puremagic.com/issues/show_bug.cgi?id=11188

In short, the following code:

  import std.bigint, std.math, std.typetuple;

  auto foo(T)()
  {
  T n = -3;
  return std.math.abs(n);
  }

  void main()
  {
  foreach (T; TypeTuple!(byte, short, int, long, BigInt))
  {
  assert(foo!T() == 3); // works
  assert(foo!(shared(T)) == 3); // fails for BigInt
  assert(foo!(const(T)) == 3);  // fails for BigInt
  assert(foo!(immutable(T)) == 3);  // fails for BigInt
  }
  }

... will fail to compile for the shared, const and immutable variants of BigInt, 
with the compiler error message being:


/opt/dmd/include/d2/std/math.d(303):std.math.abs(Num)(Num x) if 
(is(typeof(Num.init >= 0)) && is(typeof(-Num.init)) && !(is(Num* : 
const(ifloat*)) || is(Num* : const(idouble*)) || is(Num* : const(ireal*
/opt/dmd/include/d2/std/math.d(314):std.math.abs(Num)(Num z) if (is(Num* 
: const(cfloat*)) || is(Num* : const(cdouble*)) || is(Num* : const(creal*)))
/opt/dmd/include/d2/std/math.d(322):std.math.abs(Num)(Num y) if (is(Num* 
: const(ifloat*)) || is(Num* : const(idouble*)) || is(Num* : const(ireal*)))
bigabs.d(6): Error: template std.math.abs(Num)(Num x) if (is(typeof(Num.init >= 
0)) && is(typeof(-Num.init)) && !(is(Num* : const(ifloat*)) || is(Num* : 
const(idouble*)) || is(Num* : const(ireal* cannot deduce template function 
from argument types !()(shared(BigInt))


... and similarly for const and immutable.

What I can't see is why there is a failure to deduce the template function.  In 
fact some checks show that it's the very first of these conditions:


is(typeof(Num.init >= 0))

... that fails.  This is rather unintuitive.  Doesn't a BigInt -- even an 
immutable one -- default to 0?


Advice very much appreciated, as I'm feeling stumped.

Thanks & best wishes,

-- Joe


isAsciiString in Phobos?

2013-10-07 Thread Andrej Mitrovic
If I want to transfer some string to a C function that expects
ascii-only string. What can I use to verify there are no non-ascii
characters in a D string? I haven't seen anything in Phobos.

I was thinking of using:

bool isAscii = mystring.all!(a => a <= 0xFF);

Is this safe?

I'm thinking of whether a code point can consist of two code units
such as [C1][C2], where C2 may be in the range 0 - 0xFF. I don't know
if that's possible (not a unicode pro here..).


Re: isAsciiString in Phobos?

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, Andrej Mitrovic  wrote:
> If I want to transfer some string to a C function that expects
> ascii-only string.

Minus the "If".


Re: isAsciiString in Phobos?

2013-10-07 Thread Adam D. Ruppe

On Monday, 7 October 2013 at 15:18:06 UTC, Andrej Mitrovic wrote:

bool isAscii = mystring.all!(a => a <= 0xFF);


If you want strict ASCII, it should be <= 127 rather than 255 
because the high bit can be all kinds of different encodings (the 
first 255 of unicode codepoints I think match latin-1 
numerically, but that's different than windows-1252 or various 
non-English extended asciis.)


You could also convert utf-8 to ascii sort of... by just 
stripping out any byte > 127 since bytes higher than that are 
multibyte sequences in utf8.


Re: isAsciiString in Phobos?

2013-10-07 Thread Jonathan M Davis
On Monday, October 07, 2013 17:17:57 Andrej Mitrovic wrote:
> If I want to transfer some string to a C function that expects
> ascii-only string. What can I use to verify there are no non-ascii
> characters in a D string? I haven't seen anything in Phobos.
> 
> I was thinking of using:
> 
> bool isAscii = mystring.all!(a => a <= 0xFF);
> 
> Is this safe?
> 
> I'm thinking of whether a code point can consist of two code units
> such as [C1][C2], where C2 may be in the range 0 - 0xFF. I don't know
> if that's possible (not a unicode pro here..).

If you do

bool isASCII = !mystring.any!(not!isASCII)();

or

bool isASCII = !mystring.any!(a => a > 0x7F)();

then you should be good. Anything in UTF-8 127 or under is a single code unit 
and is ASCII. It has to be more than 127 to be a multi-byte character. Just 
look at the table on

https://en.wikipedia.org/wiki/Utf-8

It shows what each of the bytes have to look like in a UTF-8 code point for 
each number of bytes in the code point.

- Jonathan M Davis


Re: isAsciiString in Phobos?

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, Adam D. Ruppe  wrote:
> If you want strict ASCII, it should be <= 127 rather than 255
> because the high bit can be all kinds of different encodings (the
> first 255 of unicode codepoints I think match latin-1
> numerically, but that's different than windows-1252 or various
> non-English extended asciis.)
>
> You could also convert utf-8 to ascii sort of... by just
> stripping out any byte > 127 since bytes higher than that are
> multibyte sequences in utf8.

Thanks. I got some useful info from Jakob from IRC, and ended up with this:

bool isAsciiString(string input)
{
auto data = cast(const(ubyte)[])input;
return data.all!(a => a <= 0x7F);
}

The cast is needed to avoid decoding by the "all" function. Also
there's isASCII that works on a dchar in std.ascii, but I was looking
for something that works on entire strings at once. So the above
function does the work for me.

Should we put something like this in Phobos?


Re: isAsciiString in Phobos?

2013-10-07 Thread monarch_dodra

On Monday, 7 October 2013 at 15:57:15 UTC, Andrej Mitrovic wrote:

On 10/7/13, Adam D. Ruppe  wrote:

If you want strict ASCII, it should be <= 127 rather than 255
because the high bit can be all kinds of different encodings 
(the

first 255 of unicode codepoints I think match latin-1
numerically, but that's different than windows-1252 or various
non-English extended asciis.)

You could also convert utf-8 to ascii sort of... by just
stripping out any byte > 127 since bytes higher than that are
multibyte sequences in utf8.


Thanks. I got some useful info from Jakob from IRC, and ended 
up with this:


bool isAsciiString(string input)
{
auto data = cast(const(ubyte)[])input;
return data.all!(a => a <= 0x7F);
}

The cast is needed to avoid decoding by the "all" function. Also
there's isASCII that works on a dchar in std.ascii, but I was 
looking

for something that works on entire strings at once. So the above
function does the work for me.


You can use std.string.representation to do the cast for you, and 
you might as well just use isASCII anyways.


return data.representation().all!isASCII();

If we want even more efficiency, we could iterate on the string, 
interpreting it as a size_t[]. We mask each of its elements with 
0x80808080/0x80808080_80808080, and if one of the resulting 
masked elements is not null, then the string isn't ASCII.


Re: isAsciiString in Phobos?

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, monarch_dodra  wrote:
> If we want even more efficiency, we could iterate on the string,
> interpreting it as a size_t[]. We mask each of its elements with
> 0x80808080/0x80808080_80808080, and if one of the resulting
> masked elements is not null, then the string isn't ASCII.

Clever! So I think we should definitely try and push it to the library.


Re: Using ReadWriteMutex with synchronized{} ?

2013-10-07 Thread Sönke Ludwig

Am 06.10.2013 23:25, schrieb E.S. Quinn:

I need to share an associative array between two threads, and to that
extent I'd like to make the whole thing synchronized. And I'd like to
use the built-in synchronized{} blocks, and I'd also like to use the
ReadWriteMutex from core.sync.rwmutex, since it seems pretty much
tailor-made for this sort of thing.

Is it possible to, for example, tell D that I want the enclosing class
synchronized with a ReadWriteMutex, and then specifcy which functions
need a reader lock and which need writer locks? Or will I have to lock
and unlock the mutex manually?


Using "synchronized" should work using the reader/writer properties:

---
auto rwmutex = new ReadWriteMutex;

synchronized (rwmutex.reader) {
  // do something that reads from the protected memory area
}

synchronized (rwmutex.writer) {
  // do something that reads/writes from/to the protected memory area
}
---

You'll have to synchronize inside of class methods according to 
read/write though, AFAIK. "synchronized class" works only for the simple 
case of all public methods being synchronized the same way.


Re: Windows 64

2013-10-07 Thread Rainer Schuetze



On 07.10.2013 12:21, "Casper Færgemand" " wrote:

On Monday, 7 October 2013 at 07:03:39 UTC, Rainer Schuetze wrote:

The linker does not find the import libraries from the Windows SDK, so
it hits the 32-bit libraries that come with dmd.

The released sc.ini does not work with VS2012+ or a Windows SDK 8, you
should add the following lines to it:

[Environment64]
LIB=%@P%\..\lib;%VCINSTALLDIR%\lib\amd64;%WindowsSdkDir%\Lib\win8\um\x64
;; for some additional improvements
PATH=%PATH%;%VCINSTALLDIR%\bin\x86_amd64;%VCINSTALLDIR%\..\Common7\IDE
DFLAGS=%DFLAGS% -L/OPT:NOICF


Thank you. I added the lines and I'm still getting the same 103
unresolved externals. Commenting out stuff in the file makes dmd throws
other errors, so I'm sure I'm editing the correct sc.ini.
Where are the correct libraries supposed to be exactly?


Maybe the WindowsSdkDir environment variable is not set in your console. 
For the Windows 8 SDK, the standard location of the x64 libraries is


"c:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64"

for the Windows 7 SDK or previous (replace the version):

"c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64"

so the entry with expanded environment variables on my system using VS 
2012 and Windows SDK 8 is:


LIB=%@P%\..\lib;"c:\Program Files (x86)\Microsoft Visual Studio 
11.0\VC\lib\amd64";"c:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64"


I don't think the quotes are necessary, but the original sc.ini has 
them, too.


Re: mutable, const, immutable guidelines

2013-10-07 Thread Ali Çehreli

On 10/02/2013 10:07 AM, Ali Çehreli wrote:

> On 10/02/2013 06:09 AM, Daniel Davidson wrote:
>
>  > I'm reviewing Ali's insightful presentation from 2013 DConf. I
>  > wonder has he or anyone else followed up on the concepts or
>  > formalized some guidelines that could achieve consensus.
>
> I have not followed up on those concepts.
>
>  > 1. If a variable is never mutated, make it const, not immutable.
>  > 2. Make the parameter reference to immutable if that is how you 
will use

>  > it anyway. It is fine to ask a favor from the caller.
>  > ...

I have to report that I am not finding much time to go deeper in these 
issues. However, I spent some time this weekend, gaining a hint of 
enlightenment.


immutable is a requirement on two concepts, second of which is new to me:

1) As it is commonly known, it is a requirement that the data does not 
mutate.


2) It is also a requirement on the type that the variables of that type 
will always be usable as immutable. I have not formalized "be usable" 
yet but what I mean is that the type cannot be modified in the future in 
a way that inhibits its use in existing code.


To look at just one usage example, the following line carries two 
requirements:


auto a = T();
immutable b = a;

1) b will be an immutable copy of a.

2) T will always be usable as in that fashion.

If T appears on an API, it is the responibility of the user to ensure 
whether they are allowed to treat T in that way. Otherwise, they risk 
maintainability if the module decides to change T in any way that fits 
the module's needs. If they have not yet advertised that T can be used 
as immutable, it should not be.


So, the question is how can a module expose a type that can always be 
used as immutable? Can the module guarantee that its future needs will 
never disallow T's use as immutable (e.g. by inserting mutable 
references into the type)? Can the library always guarantee that T can 
be used as immutable by improving its definition, e.g. by adding 
necessary opCast, opEquals, 'alias this', constructors, etc?


I don't know these answers... :/ (yet! :p)

Ali



Get unique id of a class type.

2013-10-07 Thread Agustin

I'm looking a way to get the unique id of a class. I'm able to do
this in C++ using type_info::hash_code().

void function(T) {
auto id = typeid(T).getHash(); // Something like this?

// I know i could write this but seems ugly to me :/
auto id = typeid(string).getHash(typeid(T).name);

// Or maybe even better.
auto id = typeid(T).id; // ID is not a number but a class for
storing
}


std.parallelism amap not scaling?

2013-10-07 Thread safety0ff

Hello,
I tried converting a c++/go ray tracing benchmark [1] to D [2].

I tried to using std.parallelism amap to implement parallelism, 
but it does not seem to scale in the manner I expect.


By running the program with different numbers of threads in the 
thread pool, I got these results (core i7 sandy bridge, 4 core 
+HT):


Threads 1   2   3   4   5   6   7   
8
Real time 
(s)		34.14	26.894	21.293	20.184	19.998	25.977	34.15	39.404
User time 
(s)		62.84	65.182	65.895	70.851	78.521	111.012	157.448	173.074

System time (s) 0.270.562   1.276   1.596   2.178   4.008   6.588   
8.652
System 
calls		155808	224084	291634	403496	404161	360065	360065	258661
System calls error	39643	80245	99000	147487	155605	142922	142922 
108454


I got these measurements using latest DMD/druntime/phobos, 
compiled with "-O -release -inline -noboundscheck"


I used time and strace -c to measure:
e.g.:
time ./main -h=256 -w=256 -t=7 > /dev/null
strace -c ./main -h=256 -w=256 -t=7 > /dev/null

What I also noticed in the task manager is that no matter what I 
did, I could not get the utilization to go anywhere close to 99% 
(unlike the C++ program in [1].)


My interpretation of these results is that std.parallelism.amap 
does significant communication between threads which causes 
issues with scaling.


[1] https://github.com/kid0m4n/rays
[2] https://github.com/Safety0ff/rays/tree/master/drays


Re: Get unique id of a class type.

2013-10-07 Thread simendsjo

On Monday, 7 October 2013 at 18:55:58 UTC, Agustin wrote:
I'm looking a way to get the unique id of a class. I'm able to 
do

this in C++ using type_info::hash_code().

void function(T) {
auto id = typeid(T).getHash(); // Something like this?

// I know i could write this but seems ugly to me :/
auto id = typeid(string).getHash(typeid(T).name);

// Or maybe even better.
auto id = typeid(T).id; // ID is not a number but a class 
for

storing
}


Have you tried toHash()?
https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L211


Re: Get unique id of a class type.

2013-10-07 Thread Agustin

On Monday, 7 October 2013 at 19:07:19 UTC, simendsjo wrote:

On Monday, 7 October 2013 at 18:55:58 UTC, Agustin wrote:
I'm looking a way to get the unique id of a class. I'm able to 
do

this in C++ using type_info::hash_code().

void function(T) {
   auto id = typeid(T).getHash(); // Something like this?

   // I know i could write this but seems ugly to me :/
   auto id = typeid(string).getHash(typeid(T).name);

   // Or maybe even better.
   auto id = typeid(T).id; // ID is not a number but a class 
for

storing
}


Have you tried toHash()?
https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L211


I Think that would return the hash of every member of a class, 
rather than just the hash of the class name


Re: Scope variables.

2013-10-07 Thread Agustin

On Monday, 7 October 2013 at 19:58:21 UTC, Agustin wrote:

I'm having a hard time trying to use "scoped".

public T callEvent(T, A...)(auto ref A args) const
{
  T pEvent = scoped!T(forward!args);
  postEvent(pEvent, typeid(T).toHash);
  return pEvent;
}

private void postEvent(ref Event event, Event.ID type) const
{
  
}

src\event\EventManager.d(37): Error: function 
ghrum.event.EventManager.EventManager.postEvent (ref Event 
event, uint type) const is not callable using argument types 
(MyEvent,uint)
src\event\EventManager.d(37): Error: function 
ghrum.event.EventManager.EventManager.postEvent (ref Event 
event, uint type) const is not callable using argument types 
(MyEvent,uint) const
src\event\EventManager.d(37): Error: cast(Event)pEvent is not 
an lvalue



callEvent!MyEvent(); Being MyEvent a subclass of Event.


Scope variables.

2013-10-07 Thread Agustin

I'm having a hard time trying to use "scoped".

public T callEvent(T, A...)(auto ref A args) const
{
  T pEvent = scoped!T(forward!args);
  postEvent(pEvent, typeid(T).toHash);
  return pEvent;
}

private void postEvent(ref Event event, Event.ID type) const
{
  
}

src\event\EventManager.d(37): Error: function 
ghrum.event.EventManager.EventManager.postEvent (ref Event event, 
uint type) const is not callable using argument types 
(MyEvent,uint)
src\event\EventManager.d(37): Error: function 
ghrum.event.EventManager.EventManager.postEvent (ref Event event, 
uint type) const is not callable using argument types 
(MyEvent,uint) const
src\event\EventManager.d(37): Error: cast(Event)pEvent is not an 
lvalue


Re: isAsciiString in Phobos?

2013-10-07 Thread monarch_dodra

On Monday, 7 October 2013 at 16:23:12 UTC, Andrej Mitrovic wrote:

On 10/7/13, monarch_dodra  wrote:
If we want even more efficiency, we could iterate on the 
string,
interpreting it as a size_t[]. We mask each of its elements 
with

0x80808080/0x80808080_80808080, and if one of the resulting
masked elements is not null, then the string isn't ASCII.


Clever! So I think we should definitely try and push it to the 
library.


I wrote this:
Only lightly tested.

//
bool isASCII(const(char[]) str)
{
static if (size_t.sizeof == 8)
{
enum size = 8;
enum size_t mask  = 0x80808080_80808080;
enum size_t alignMask = ~cast(size_t)0b111;
}
else
{
enum size = 4;
enum size_t mask = 0x80808080;
enum size_t alignMask = ~cast(size_t)0b11;
}

if (str.length < size)
{
foreach (c; str)
if (c & 0x80)
return false;
return true;
}

immutable start = (cast(size_t)str.ptr & alignMask) + size;
immutable end = cast(size_t)(str.ptr + str.length) & 
alignMask;


//we start with block, because it is faster
//and chances the start is aligned anyways (so we check it 
later).
for ( auto p = cast(size_t*)start ; p != cast(size_t*)end ; 
++p )

if (*p & mask)
return false;

//Then the trailing chars.
for ( auto p = cast(char*)end ; p != str.ptr + str.length ; 
++p )

if (*p & 0x80)
return false;

//Finally, the first chars.
for ( auto p = str.ptr ; p != cast(char*)start ; ++p )
if (*p & 0x80)
return false;

return true;
}
//
assert( "hello".isASCII());
assert( "heellohelloellohelloellohelloellohellollohello");
assert( "hellellohelloellohelloo"[3 .. $].isASCII());

assert(!"heéppellohelloellohelloellohelloellohelloellohellollo".isASCII());

assert(!"heppellohelloellohelloellohéelloellohelloellohellollo".isASCII());

assert(!"heppellohelloellohelloellohelloellohelloellohellolléo".isASCII());

//

What do you think? I have some doubts though:
1. Does x64 require qword alignment for size_t, or is dword 
enough?
2. Isn't there some built-in that'll give me the wanted 
alignement, isntead of doing it by hand?

3. Are those casts 100% correct?


Re: Windows 64

2013-10-07 Thread Casper Færgemand

On Monday, 7 October 2013 at 17:48:13 UTC, Rainer Schuetze wrote:
Maybe the WindowsSdkDir environment variable is not set in your 
console. For the Windows 8 SDK, the standard location of the 
x64 libraries is


"c:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64"

for the Windows 7 SDK or previous (replace the version):

"c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64"

so the entry with expanded environment variables on my system 
using VS 2012 and Windows SDK 8 is:


LIB=%@P%\..\lib;"c:\Program Files (x86)\Microsoft Visual Studio 
11.0\VC\lib\amd64";"c:\Program Files (x86)\Windows 
Kits\8.0\Lib\win8\um\x64"


I don't think the quotes are necessary, but the original sc.ini 
has them, too.
When I run %WindowsSdkDir% from the start menu I end up in the 
v7.0A folder, so the path seems correct.


I have v7.0A, but there is no x64 folder in the Lib folder.
In fact, I get the same 103 unresolved dependencies even if I 
change the name of the Lib folder to Lib2, so presumably I never 
get that far in the linking that it reaches the directory?
What exactly does it need from WinSDK to link? Does it need 
anything if the program is simply void main() {}?


Re: Windows 64

2013-10-07 Thread Casper Færgemand
I have four folders in the SDK folder: v7.0A, v7.1, v8.0 and 
v8.0A. The latter three contain nothing but a few files, 
presumably installed by VS 11 or something else. I'm currently 
trying to install v7.1.


Re: Getting the missing Windows functions

2013-10-07 Thread Matt

On Monday, 7 October 2013 at 14:45:35 UTC, Andrej Mitrovic wrote:

On 10/7/13, Matt  wrote:

I have never had to specify any Windows libs for linking under
DMD. What is different about these?


DMD links in user32.lib and kernel32.lib by default. But if you 
want
to use other libs like GDI you're going to have to pass them at 
the

command line.


The missing functions (or at least the one I'm interested in at 
the moment) that I'm trying to use are supposed to be IN 
kernel32, and have been in there since Windows Vista. That's why 
I'm a little confused.


Re: Get unique id of a class type.

2013-10-07 Thread Agustin

On Monday, 7 October 2013 at 19:24:32 UTC, Agustin wrote:

On Monday, 7 October 2013 at 19:07:19 UTC, simendsjo wrote:

On Monday, 7 October 2013 at 18:55:58 UTC, Agustin wrote:
I'm looking a way to get the unique id of a class. I'm able 
to do

this in C++ using type_info::hash_code().

void function(T) {
  auto id = typeid(T).getHash(); // Something like this?

  // I know i could write this but seems ugly to me :/
  auto id = typeid(string).getHash(typeid(T).name);

  // Or maybe even better.
  auto id = typeid(T).id; // ID is not a number but a class 
for

storing
}


Have you tried toHash()?
https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L211


I Think that would return the hash of every member of a class, 
rather than just the hash of the class name


Nevermind, i just saw the link you gave me, thanks a lot!.


Re: std.parallelism amap not scaling?

2013-10-07 Thread safety0ff
Ok, well I re-wrote the parallelism amap into spawning/joining 
threads and the results are similar, except notably less system 
calls (specifically, less futex calls.)




Re: std.parallelism amap not scaling?

2013-10-07 Thread safety0ff
I think I've found the culprit: Memory managment / GC, disabling 
the GC caused the program to eat up all my memory.


I'll have to look into this later.


Re: Windows 64

2013-10-07 Thread Casper Færgemand
A lot of deleted posts and a lot of stupid later, v7.1 SDK is 
apparently installed in Program Files and not Program Files 
(x86). Kinda obvious given the names of said folders, but 
whatever. x.x


The x64 version does indeed have an x64 folder in the Lib folder. 
However, all that aside, still the same 103 unresolved externals.


Re: Getting the missing Windows functions

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, Matt  wrote:
> The missing functions (or at least the one I'm interested in at
> the moment) that I'm trying to use are supposed to be IN
> kernel32, and have been in there since Windows Vista. That's why
> I'm a little confused.

The kernel32.lib distributed with DMD is likely out of date.
See: http://d.puremagic.com/issues/show_bug.cgi?id=6625


Re: Windows 64

2013-10-07 Thread Casper Færgemand
More searching suggests all the unresolved external symbols are 
found in the lib files in v7.1\Lib\x64\
I'm guessing the linker doesn't know this. Any easy way to tell 
it where to look? Does the linker have an include folder? I tried 
with -LPATH"%WindowsSdkDir%\Lib\x64" as well as -L+"C:\Program 
Files\Microsoft SDKs\Windows\v7.1\Lib\x64\ShLwApi" (one of the 
files mentioned in a search result), however they failed since D 
doesn't recognize spaces in paths. "cannot open file 
'+C:\Program.obj"


Any clue on what I'm doing wrong? Any correct way to tell the 
linker where it can find stuff?


Re: Scope variables.

2013-10-07 Thread Agustin

On Monday, 7 October 2013 at 19:59:09 UTC, Agustin wrote:

On Monday, 7 October 2013 at 19:58:21 UTC, Agustin wrote:

I'm having a hard time trying to use "scoped".

public T callEvent(T, A...)(auto ref A args) const
{
 T pEvent = scoped!T(forward!args);
 postEvent(pEvent, typeid(T).toHash);
 return pEvent;
}

private void postEvent(ref Event event, Event.ID type) const
{
 
}

src\event\EventManager.d(37): Error: function 
ghrum.event.EventManager.EventManager.postEvent (ref Event 
event, uint type) const is not callable using argument types 
(MyEvent,uint)
src\event\EventManager.d(37): Error: function 
ghrum.event.EventManager.EventManager.postEvent (ref Event 
event, uint type) const is not callable using argument types 
(MyEvent,uint) const
src\event\EventManager.d(37): Error: cast(Event)pEvent is not 
an lvalue



callEvent!MyEvent(); Being MyEvent a subclass of Event.


So i found out that i cannot do this, may i ask why?

public class A
{
  int x = 0;
}

public class B : A
{
}

void func(ref A a)
{
}

void main()
{
  B b = new B();
  func(b);
}


Re: Scope variables.

2013-10-07 Thread Justin Whear
On Tue, 08 Oct 2013 00:52:19 +0200, Agustin wrote:
> 
> So i found out that i cannot do this, may i ask why?
> 
> public class A {
>int x = 0;
> }
> 
> public class B : A {
> }
> 
> void func(ref A a)
> {
> }
> 
> void main()
> {
>B b = new B();
>func(b);
> }

Get rid of the "ref" in func's signature--objects are already by 
reference.  With that fix, compiles just fine for me.


Re: Scope variables.

2013-10-07 Thread Ali Çehreli

On 10/07/2013 03:52 PM, Agustin wrote:

On Monday, 7 October 2013 at 19:59:09 UTC, Agustin wrote:

On Monday, 7 October 2013 at 19:58:21 UTC, Agustin wrote:

I'm having a hard time trying to use "scoped".

public T callEvent(T, A...)(auto ref A args) const
{
 T pEvent = scoped!T(forward!args);
 postEvent(pEvent, typeid(T).toHash);
 return pEvent;
}

private void postEvent(ref Event event, Event.ID type) const
{
 
}

src\event\EventManager.d(37): Error: function
ghrum.event.EventManager.EventManager.postEvent (ref Event event,
uint type) const is not callable using argument types (MyEvent,uint)
src\event\EventManager.d(37): Error: function
ghrum.event.EventManager.EventManager.postEvent (ref Event event,
uint type) const is not callable using argument types (MyEvent,uint)
const
src\event\EventManager.d(37): Error: cast(Event)pEvent is not an lvalue



callEvent!MyEvent(); Being MyEvent a subclass of Event.


So i found out that i cannot do this, may i ask why?

public class A
{
   int x = 0;
}

public class B : A
{
}

void func(ref A a)
{
}

void main()
{
   B b = new B();
   func(b);
}


Since classes are already references, you would normally pass A, not 
'ref A'.


If you really want to pass 'ref A', perhaps you want to change the 
actual object that an A is referring to:


public class C : A
{}

void func(ref A a)
{
a = new C;// <-- A reason for taking 'ref A'
}

However, that would upset the caller, which thinks it has a reference to 
a B object:


void main()
{
  B b = new B();
  func(b);// <-- Oops! Not a B anymore?
}

Ali



Re: Scope variables.

2013-10-07 Thread Agustin

On Monday, 7 October 2013 at 22:57:17 UTC, Ali Çehreli wrote:

On 10/07/2013 03:52 PM, Agustin wrote:

On Monday, 7 October 2013 at 19:59:09 UTC, Agustin wrote:

On Monday, 7 October 2013 at 19:58:21 UTC, Agustin wrote:

I'm having a hard time trying to use "scoped".

public T callEvent(T, A...)(auto ref A args) const
{
T pEvent = scoped!T(forward!args);
postEvent(pEvent, typeid(T).toHash);
return pEvent;
}

private void postEvent(ref Event event, Event.ID type) const
{

}

src\event\EventManager.d(37): Error: function
ghrum.event.EventManager.EventManager.postEvent (ref Event 
event,
uint type) const is not callable using argument types 
(MyEvent,uint)

src\event\EventManager.d(37): Error: function
ghrum.event.EventManager.EventManager.postEvent (ref Event 
event,
uint type) const is not callable using argument types 
(MyEvent,uint)

const
src\event\EventManager.d(37): Error: cast(Event)pEvent is 
not an lvalue



callEvent!MyEvent(); Being MyEvent a subclass of Event.


So i found out that i cannot do this, may i ask why?

public class A
{
  int x = 0;
}

public class B : A
{
}

void func(ref A a)
{
}

void main()
{
  B b = new B();
  func(b);
}


Since classes are already references, you would normally pass 
A, not 'ref A'.


If you really want to pass 'ref A', perhaps you want to change 
the actual object that an A is referring to:


public class C : A
{}

void func(ref A a)
{
a = new C;// <-- A reason for taking 'ref A'
}

However, that would upset the caller, which thinks it has a 
reference to a B object:


void main()
{
  B b = new B();
  func(b);// <-- Oops! Not a B anymore?
}

Ali


Doesn't ref means i'm passing the parameter by reference instead 
of by value?. Isn't "a" being copied when calling func?, or does 
D always pass by reference when using classes and structures?


Re: Windows 64

2013-10-07 Thread Casper Færgemand
Okay, it's definitely a problem with dmd passing something bad to 
link. I was able to link it manually and the program was working 
fine.


import std.stdio;

void main() {
writeln("Hello Linker!");
}

I ran "dmd -m64 test.d". The usual errors were dumped in the 
terminal. I then ran "link test.obj @lala.txt", with lala.txt 
containing the following:


C:\D\Tools\dmd2\windows\lib\phobos64.lib
"C:\Program Files (x86)\Microsoft Visual Studio 
11.0\VC\lib\amd64\LIBCMT.lib"
"C:\Program Files (x86)\Microsoft Visual Studio 
11.0\VC\lib\amd64\oldnames.lib"

"C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64\shell32.lib"
"C:\Program Files\Microsoft 
SDKs\Windows\v7.1\Lib\x64\kernel32.lib"


After adding the five lines one by one, the linking succeeded and 
test.exe outputted "Hello Linker!".



So, how do I not link it manually? It's sorta acceptable for 
small things, but I want DDT and Eclipse to do it automatically.


Re: Scope variables.

2013-10-07 Thread Justin Whear
On Tue, 08 Oct 2013 01:01:43 +0200, Agustin wrote: 
> Doesn't ref means i'm passing the parameter by reference instead of by
> value?. Isn't "a" being copied when calling func?, or does D always pass
> by reference when using classes and structures?

Class instances are by reference already, structs are by value.  For 
further comparison, please see the table here:
http://dlang.org/struct.html


Re: Scope variables.

2013-10-07 Thread Agustin

On Monday, 7 October 2013 at 23:18:13 UTC, Justin Whear wrote:

On Tue, 08 Oct 2013 01:01:43 +0200, Agustin wrote:
Doesn't ref means i'm passing the parameter by reference 
instead of by
value?. Isn't "a" being copied when calling func?, or does D 
always pass

by reference when using classes and structures?


Class instances are by reference already, structs are by value.
 For
further comparison, please see the table here:
http://dlang.org/struct.html


Thank you!.


Re: Windows 64

2013-10-07 Thread Casper Færgemand

And I'm done. The problem was this:
LIB=%@P%\..\lib;%VCINSTALLDIR%\lib\amd64;%WindowsSdkDir%\Lib\x64
The lib folder linked first contains kernel32.lib and 
shell32.lib. Removing both made -m64 possible, but killed -m32. 
Changing it to this:

LIB=%VCINSTALLDIR%\lib\amd64;%WindowsSdkDir%\Lib\x64;%@P%\..\lib
solved everything. Now the dmd lib is checked last, when the real 
kernel32 and shell32 have already been found.


Well that only took half a year. ~~ Thanks for the help.


Re: cascade operator or nearest equivalent

2013-10-07 Thread Daniel Davidson

On Thursday, 12 September 2013 at 19:41:49 UTC, bearophile wrote:

Daniel Davidson:

I am using Dart for code generation but would like to consider 
D if I can find a convenient replacement for the following 
declarative style:


Replacing Dart with D seems quite strange, such two languages 
have so much different usage niches.




   var dateRange = struct('date_range')
 ..doc = 'Basic pair of start and end dates'
 ..unitTest = true
 ..publicSection = true
 ..members = [
   member('start_date')
   ..type = 'Date',
   member('end_date')
   ..type = 'Date',
 ];


A similar syntax is not allowed in D, but there are two things 
that help for this: the C-style initialization of structs, that 
support field names too, and the with(){} statement.


Bye,
bearophile


The problem with with is the name can not hide each other, so it 
is easy to get into trouble. With C-style initialization I don't 
think you can use as expression - I think you need an lvalue for 
each and this hurts nesting.


I have a style I'm playing with and if anyone has comments or 
improvements (i.e. make more succinct/readable) it would be 
appreciated.


Here is a sample and the source for this and comparable Dart are 
in the links.


auto d = make((ref Dossier _) {
  _.family = [
   "father" : make((ref Person _) {
   _.birthDate = "2001/1/1";
   _.deathDate = "2101/1/1";
   _.retirementDate = "2100/1/1"; }),
   "mother" : make((ref Person _) {
   _.birthDate = "2005/1/1";
   _.deathDate = "2125/1/1";
   _.retirementDate = "2100/1/1"; }),
   ];
  _.assets = [
   "house" : make((ref Asset _) {
   _.name = "Home on the Hill";
   _.unitValue = 120_000; }),
   "car" : make((ref Asset _) {
   _.name = "Dodge Dart";
   _.unitValue = 500; })
  ];
});

http://pastebin.com/iLVL20Bz
http://pastebin.com/mLcWDACm

Thanks
Dan


Re: Windows 64

2013-10-07 Thread Rainer Schuetze



On 08.10.2013 01:26, "Casper Færgemand" " wrote:

And I'm done. The problem was this:
LIB=%@P%\..\lib;%VCINSTALLDIR%\lib\amd64;%WindowsSdkDir%\Lib\x64
The lib folder linked first contains kernel32.lib and shell32.lib.
Removing both made -m64 possible, but killed -m32. Changing it to this:
LIB=%VCINSTALLDIR%\lib\amd64;%WindowsSdkDir%\Lib\x64;%@P%\..\lib
solved everything. Now the dmd lib is checked last, when the real
kernel32 and shell32 have already been found.

Well that only took half a year. ~~ Thanks for the help.


Sorry to hear you had so much trouble, but good that it finally works.

I've been trying to convince Walter to put the 64-bit libraries into a 
different folder "lib64" for the dmd release for some time. I hope this 
lesson will convince him.


BTW: if you want to pass additional directories to the ms linker through 
the dmd command line, you can use "-L/LIBPATH:dir".