Running GDC

2011-03-21 Thread Caligo
I updated my gdc repo and now I can't run the new build; it can't find the
includes and the libs.
This is what I've come up with so far:
-I/../D/gdc/Bin/usr/local/include/d2/4.4.5/
-I/../D/gdc/Bin/usr/local/include/d2/4.4.5/x86_64-unknown-linux-gnu/

What's the rest?


where do bug reports for dmd2.052 go?

2011-03-21 Thread Jason E. Aten
should I send them to the newsgroup digitalmars.D.bugs, or is there a 
better, canonical place, to report dmd2 bugs?  I've managed to crash the 
compiler.

Thanks,
Jason


Re: DMD2 - compiling and linking in separate steps (64-bit)

2011-03-21 Thread Jason E. Aten
On Sat, 19 Mar 2011 13:52:05 +, Sean Eskapp wrote:

 == Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article
 On Friday 18 March 2011 20:49:58 Sean Eskapp wrote:
  incompatible /usr/lib/../lib/librt.so when searching for -lrt
  /usr/bin/ld: skipping incompatible /usr/lib/../lib/librt.a when
  searching for -lrt
  /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-
  gnu/4.4.5/../../../librt.so when searching for -lrt /usr/bin/ld:
  skipping incompatible /usr/lib/gcc/x86_64-linux-
  gnu/4.4.5/../../../librt.a when searching for -lrt /usr/bin/ld:
  skipping incompatible /usr/lib/gcc/x86_64-linux-
  gnu/4.4.5/../../../../lib/libc.so
 Look at dmd.conf. It includes several flags which are supposed to be
 passed to the linker - either that or you can use dmd to link rather
 than using gcc on its own. Personally, I wouldn't bother compiling and
 linking as separate steps, but if you do, you need to make sure that
 you either use the flags in dmd.conf or you link with dmd rather than
 gcc. For the most part, there's no reason to link with gcc, even if you
 want to link separately. - Jonathan M Davis
 
 Hmm.. after linking with all the options in dmd.conf (-L/usr/lib32
 -L/usr/lib64 --no-warn-search-mismatch --export-dynamic -lrt), I still
 get
 
 /usr/bin/ld: skipping incompatible
 /home/me/devl/sfml2/bindings/d/lib/libdsfml-system.a when searching for
 -ldsfml-system /usr/bin/ld: cannot find -ldsfml-system /usr/bin/ld:
 skipping incompatible
 /home/me/devl/sfml2/bindings/d/lib/libdsfml-graphics.a when searching
 for -ldsfml-graphics /usr/bin/ld: cannot find -ldsfml-graphics
 /usr/bin/ld: skipping incompatible
 /home/me/devl/sfml2/bindings/d/lib/libdsfml-audio.a when searching for
 -ldsfml-audio /usr/bin/ld: cannot find -ldsfml-audio /usr/bin/ld:
 skipping incompatible
 /home/me/devl/sfml2/bindings/d/lib/libdsfml-window.a when searching for
 -ldsfml-window /usr/bin/ld: cannot find -ldsfml-window collect2: ld
 returned 1 exit status
 
 Now, I compiled libdsfml-system.a myself, and I know they're 64-bit, so
 this implies ld still isn't recognizing that I want 64-bit executables.

I think the reason that ld is skipping those libraries is that secretly, 
inside the .a archives, they are really 32-bit libraries and not 64-bit 
libraries.

You can confirm this by using the ar x {somelibrary}.z to extract the 
object files (do it from a new temp directory), and then running file 
{new}.o, which in my hands reports that the dmd libraries such as phobos 
are actually 32-bit, even on x86_64 linux.

This is why I went to LDC2, which is fully 64-bit.

- Jason


Re: where do bug reports for dmd2.052 go?

2011-03-21 Thread Steven Schveighoffer
On Mon, 21 Mar 2011 10:41:56 -0400, Jason E. Aten j.e.a...@gmail.com  
wrote:



should I send them to the newsgroup digitalmars.D.bugs, or is there a
better, canonical place, to report dmd2 bugs?  I've managed to crash the
compiler.


bugzilla please.  All reports and changes to reports are also CC'd to  
D.bugs, you really shouldn't post anything directly there.


http://d.puremagic.com/issues/

-Steve


Bug w/tuple of custom types?

2011-03-21 Thread Magnus Lie Hetland

Sample program:

import std.typecons;

typedef uint oid_t;

void main() {
   Tuple!(uint,uint) key;
   // Tuple!(oid_t,oid_t) key; // Doesn't work
}

If I use the last tuple instead of the first, I get the following 
compiler error with DMD 2.052 in OS X:


/path/to/src/phobos/std/format.d(1579): Error: function 
std.format.formatValue!(Appender!(string),oid_t,immutable(char)).formatValue 
is deprecated
/path/to/src/phobos/std/format.d(306): Error: template instance 
std.format.formatGeneric!(Appender!(string),oid_t,immutable(char)) 
error instantiating
/path/to/src/phobos/std/typecons.d(507):instantiated from here: 
formattedWrite!(Appender!(string),immutable(char),oid_t)


It seems that std.typecons is using a deprecated formatting API, which 
is triggered by my use of a custom type? And ... I guess this would be 
a bug? (I looked in the tracker, and couldn't find it there already.)


--
Magnus Lie Hetland
http://hetland.org



Re: Deducing types for function templates

2011-03-21 Thread Magnus Lie Hetland

On 2011-03-15 21:13:36 +0100, Michel Fortin said:


Oh, it's much older than that:

http://d.puremagic.com/issues/show_bug.cgi?id=2128


I'm not sure it's the same thing, but I realize it's hard to say given 
Magnus in his original post didn't mention how he attempts to 
instantiate the template.


Hm. I've gone back to it now, and, sadly (as opposed to for the other 
bugs I've encountered :) I didn't isolate and save the related code -- 
so now I'm unable to reproduce the const problem. (Who knows ... maybe 
I was just trying to pass it on as an un-const parameter or something? 
Might very well have been a bug on my part.)


Here's some sample code for the other part of my question, though 
(which might not have been as unclear in the first place?).


class Foo(T) {
   T foo;
}

template baz_t(T) {
   alias real function(T, T) baz_t;
}

Foo!T foo(T)(T[] bar, baz_t!T baz) {
   return new Foo!T;
}

real frozz(uint x, uint y) {
   return 4.2;
}

void main() {
   uint[] x = [1, 2, 3];
   auto f = foo(x, frozz);
}

The error is:

inferencebug.d(19): Error: template inferencebug.foo(T) does not match 
any function template declaration
inferencebug.d(19): Error: template inferencebug.foo(T) cannot deduce 
template function from argument types !()(uint[],real function(uint x, 
uint y))


--
Magnus Lie Hetland
http://hetland.org



Re: Bug w/tuple of custom types?

2011-03-21 Thread Steven Schveighoffer
On Mon, 21 Mar 2011 13:03:25 -0400, Magnus Lie Hetland  
mag...@hetland.org wrote:



Sample program:

import std.typecons;

typedef uint oid_t;

void main() {
Tuple!(uint,uint) key;
// Tuple!(oid_t,oid_t) key; // Doesn't work
}

If I use the last tuple instead of the first, I get the following  
compiler error with DMD 2.052 in OS X:


/path/to/src/phobos/std/format.d(1579): Error: function  
std.format.formatValue!(Appender!(string),oid_t,immutable(char)).formatValue  
is deprecated
/path/to/src/phobos/std/format.d(306): Error: template instance  
std.format.formatGeneric!(Appender!(string),oid_t,immutable(char)) error  
instantiating
/path/to/src/phobos/std/typecons.d(507):instantiated from here:  
formattedWrite!(Appender!(string),immutable(char),oid_t)


It seems that std.typecons is using a deprecated formatting API, which  
is triggered by my use of a custom type? And ... I guess this would be a  
bug? (I looked in the tracker, and couldn't find it there already.)




If you looked and couldn't find it, it doesn't hurt to add it.  Worst case  
-- it gets marked as a duplicate.


Note that typedef is eventually going to be deprecated.  I'd suggest using  
alias unless you have a need to force uints not to be castable to oid_t.


-Steve


Re: Want to help DMD bugfixing? Write a simple utility.

2011-03-21 Thread Simen kjaeraas
On Mon, 21 Mar 2011 01:52:45 +0100, Ary Manzana a...@esperanto.org.ar  
wrote:



On 3/19/11 9:11 PM, Don wrote:

Here's the task:
Given a .d source file, strip out all of the unittest {} blocks,
including everything inside them.
Strip out all comments as well.
Print out the resulting file.

Motivation: Bug reports frequently come with very large test cases.
Even ones which look small often import from Phobos.
Reducing the test case is the first step in fixing the bug, and it's
frequently ~30% of the total time required. Stripping out the unit tests
is the most time-consuming and error-prone part of reducing the test  
case.


This should be a good task if you're relatively new to D but would like
to do something really useful.
-Don


Can it be done in Ruby? Or you need it in D?


Part of the idea was that someone use it to learn D. However, the important
part is that it's done. Doing it in D would be preferable, but not a
requisite.


--
Simen


Get single keystroke?

2011-03-21 Thread Sean Eskapp
Is there a way to get a single keystroke in D2? Any method I've tried requires
pushing Enter before the stroke is registered.


immutable and static this()

2011-03-21 Thread teo
I cannot initialize immutable class members inside a static this() 
constructor. Is there any reason for that?

Example:
class Test
{
public immutable(int) x;
static this()
{
x = 1; // Error: variable Test.x can only initialize const x 
inside constructor
}
}


Re: Get single keystroke?

2011-03-21 Thread Lars Holowko
On Mon, Mar 21, 2011 at 1:33 PM, Sean Eskapp eatingstap...@gmail.com wrote:
 Is there a way to get a single keystroke in D2? Any method I've tried requires
 pushing Enter before the stroke is registered.


Hi Sean,

what you want to do is OS dependent.

I needed something similar ('press key to continue')

e.g.: for Windows

import core.sys.windows.windows;

bool kbHit() {
// inspired by
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045691686id=1043284392
HANDLE stdIn = GetStdHandle(STD_INPUT_HANDLE);
DWORD saveMode;

GetConsoleMode(stdIn, saveMode);
SetConsoleMode(stdIn, ENABLE_PROCESSED_INPUT);

bool ret = false;

if (WaitForSingleObject(stdIn, INFINITE) == WAIT_OBJECT_0) {
uint num;
char ch;

ReadConsoleA(stdIn, ch, 1, num, cast(void *) 0L);
ret = true;
}

SetConsoleMode(stdIn, saveMode);
return ret;
}

void wait_for_key() {
writeln(\nPress any key to continue);
while (!kbHit())
{}
}


for Linux/Unix something like
http://www.linuxquestions.org/questions/programming-9/kbhit-34027/
should work.

Hope that helps,

Lars


Re: immutable and static this()

2011-03-21 Thread Simen kjaeraas

On Mon, 21 Mar 2011 22:27:17 +0100, teo teo.ubu...@yahoo.com wrote:


I cannot initialize immutable class members inside a static this()
constructor. Is there any reason for that?

Example:
class Test
{
public immutable(int) x;
static this()
{
x = 1; // Error: variable Test.x can only initialize const x
inside constructor
}
}


Non-static class members require a this pointer, and thus cannot be
initialized in a static constructor. However, if that is the error
message you get, it is clearly misleading.

--
Simen


Re: Get single keystroke?

2011-03-21 Thread Andrej Mitrovic
Here's something simpler:

import std.stdio : writefln;

extern(C) int kbhit();
extern(C) int getch();

void main()
{
while(!kbhit())
{
// keep polling
// might use thread.sleep here.
}

writefln(Key hit was %s., getch());
}


Re: Get single keystroke?

2011-03-21 Thread Andrej Mitrovic
Replace that writefln with this:

writefln(Key hit was %s., cast(char)getch());

You should get the right key displayed then.


Re: Get single keystroke?

2011-03-21 Thread bearophile
Lars Holowko:

 what you want to do is OS dependent.

But the need to get a keystroke is simple and not so uncommon, so I think 
Phobos needs a function to do that that works on both Windows/Linux (and Mac 
too).

Bye,
bearophile


Re: Get single keystroke?

2011-03-21 Thread Sean Eskapp
== Quote from Andrej Mitrovic (andrej.mitrov...@gmail.com)'s article
 Here's something simpler:
 import std.stdio : writefln;
 extern(C) int kbhit();
 extern(C) int getch();
 void main()
 {
 while(!kbhit())
 {
 // keep polling
 // might use thread.sleep here.
 }
 writefln(Key hit was %s., getch());
 }

What extra linker dependencies does this add?


Re: immutable and static this()

2011-03-21 Thread Jonathan M Davis
 On Mon, 21 Mar 2011 22:27:17 +0100, teo teo.ubu...@yahoo.com wrote:
  I cannot initialize immutable class members inside a static this()
  constructor. Is there any reason for that?
  
  Example:
  class Test
  {
  
  public immutable(int) x;
  static this()
  {
  
  x = 1; // Error: variable Test.x can only initialize const x
  
  inside constructor
  
  }
  
  }
 
 Non-static class members require a this pointer, and thus cannot be
 initialized in a static constructor. However, if that is the error
 message you get, it is clearly misleading.

No. Error message is essentially correct, just confusing. In this case, x is a 
member variable, _not_ a class/static variable. So, it must either be directly 
initialized

public immutable int x = 1;

or in a constructor (and in this case the constructor would have to be 
immutable).

public immutable int x;

this() immutable
{
int x = 1;
}

static this() in a class is for initializing class/static variables only, so 
if you did

public static immutable int x;

static this()
{
int x = 1;
}

that would work. The fact that it is immutable has nothing to do with whether 
it is a member variable or a class/static variable, so it has no effect on 
whether a normal or static constructor is used.

- Jonathan M Davis


Re: Get single keystroke?

2011-03-21 Thread Ali Çehreli

On 03/21/2011 02:42 PM, bearophile wrote:
 Lars Holowko:

 what you want to do is OS dependent.

 But the need to get a keystroke is simple and not so uncommon, so I 
think Phobos needs a function to do that that works on both 
Windows/Linux (and Mac too).


If D sticks to the C (and C++) heritage, there is no guarantee that 
there is a keyboard around. The interface is stdin, stdout, and stderr; 
which are just character streams.


But I agree: some subset of ncurses would be nice when a keyboard is 
available.



 Bye,
 bearophile

Ali



Re: Get single keystroke?

2011-03-21 Thread Jonathan M Davis
 Lars Holowko:
  what you want to do is OS dependent.
 
 But the need to get a keystroke is simple and not so uncommon, so I think
 Phobos needs a function to do that that works on both Windows/Linux (and
 Mac too).

Assuming that it could be done cleanly, it would be a good function to add, 
but honestly, I dispute that it's a common need in this day and age. If all 
you need is something like press any key to continue, you can easily do that 
with the current functions by having press enter to continue, and if you 
need to do something other than that, odds are you need something more 
powerful like ncurses anyway. Not to mention, I don't think that interactive 
console apps are all that common these days. They definitely exist, but most 
console apps essentially run a single command for you and then quit. Most of 
the types of applications which would have have been interactive console apps 
in the past are now GUI apps.

So, while it certainly wouldn't hurt to add a function like this to Phobos 
(assuming that it could be done cleanly), I really don't think that it's a 
common need anymore.

- Jonathan M Davis


Re: immutable and static this()

2011-03-21 Thread teo
On Mon, 21 Mar 2011 22:27:53 +0100, Simen kjaeraas wrote:

 On Mon, 21 Mar 2011 22:27:17 +0100, teo teo.ubu...@yahoo.com wrote:
 
 I cannot initialize immutable class members inside a static this()
 constructor. Is there any reason for that?

 Example:
 class Test
 {
 public immutable(int) x;
 static this()
 {
 x = 1; // Error: variable Test.x can only initialize const x
 inside constructor
 }
 }
 
 Non-static class members require a this pointer, and thus cannot be
 initialized in a static constructor. However, if that is the error
 message you get, it is clearly misleading.

Yes, that is the message. Thanks for the hint.


Re: Get single keystroke?

2011-03-21 Thread Andrej Mitrovic
On 3/21/11, Sean Eskapp eatingstap...@gmail.com wrote:
 == Quote from Andrej Mitrovic (andrej.mitrov...@gmail.com)'s article
 Here's something simpler:
 import std.stdio : writefln;
 extern(C) int kbhit();
 extern(C) int getch();
 void main()
 {
 while(!kbhit())
 {
 // keep polling
 // might use thread.sleep here.
 }
 writefln(Key hit was %s., getch());
 }

 What extra linker dependencies does this add?


snn.lib


Re: Get single keystroke?

2011-03-21 Thread Andrej Mitrovic
On 3/21/11, Sean Eskapp eatingstap...@gmail.com wrote:
 What about on Linux?


I'm not sure. Both DMD and GDC can run the example on Windows. Perhaps
they've got these functions implemented for Linux as well. But
according to this:
https://secure.wikimedia.org/wikipedia/en/wiki/Conio.h

it seems these functions are usually only available for compilers
targeting Windows. Have you tried compiling it on Linux, or does it
fail to link?


Re: Get single keystroke?

2011-03-21 Thread Andrej Mitrovic
It looks like its not available on Linux, I've just tried with DMD.


Re: Get single keystroke?

2011-03-21 Thread Sean Eskapp
== Quote from Andrej Mitrovic (andrej.mitrov...@gmail.com)'s article
 I believe I've found you a solution:
 import std.c.stdio;
 import std.c.linux.termios;
 extern(C) void cfmakeraw(termios *termios_p);
 void main() {
 termios  ostate; /* saved tty state */
 termios  nstate; /* values for editor mode */
 // Open stdin in raw mode
 /* Adjust output channel*/
 tcgetattr(1, ostate);   /* save old state */
 tcgetattr(1, nstate);   /* get base of new
state */
 cfmakeraw(nstate);
 tcsetattr(1, TCSADRAIN, nstate);  /* set mode */
// Read characters in raw mode
 writefln(The key hit is %s, cast(char)fgetc(stdin));
 // Close
 tcsetattr(1, TCSADRAIN, ostate);   // return to original mode
 }
 I've tested this under Ubuntu and DMD 2.052 and it works.

Great, thanks!


Re: Get single keystroke?

2011-03-21 Thread Andrej Mitrovic
On 3/21/11, teo teo.ubu...@yahoo.com wrote:
 On Mon, 21 Mar 2011 23:22:17 +0100, Andrej Mitrovic wrote:

 Woops forgot to add import std.stdio, here's a fixed version:

 import std.stdio : writefln;
 import std.c.stdio;
 import std.c.linux.termios;

 extern(C) void cfmakeraw(termios *termios_p);

 void main()
 {
 termios  ostate; /* saved tty state */ termios
 nstate; /* values for editor mode */

// Open stdin in raw mode
/* Adjust output channel*/
 tcgetattr(1, ostate);   /* save old state */
 tcgetattr(1, nstate);   /* get base of new
 state */ cfmakeraw(nstate);
 tcsetattr(1, TCSADRAIN, nstate);  /* set mode */

   // Read characters in raw mode
 writefln(The key hit is %s, cast(char)fgetc(stdin));

// Close
 tcsetattr(1, TCSADRAIN, ostate);   // return to original mode
 }

 It looks like this can be dangerous, because the terminal can be left in
 an unusable state. Please read this:
 http://groups.google.com/group/comp.os.linux.development.apps/
 browse_thread/thread/0667d16089e2b6fc


H mentions using tcgetattr to save old state and restoring it with
tcsetattr. This is what this code does. Btw this code is not mine,
Walter posted it and I just added the cfmakeraw prototype. So kudos
goes to him.


Eager dirEntries

2011-03-21 Thread Andrej Mitrovic
Currently we have DirEntries, which can be used in a foreach loop. We also have 
listDir, which returns a string[] with all entries found in a path. listDir is 
scheduled for deprecation, so I'm not using it.

DirEntries is definitely more flexible, but I can't eagerly construct an array 
of strings from it. For example, this won't compile:

string[] entries = array(dirEntries(directory, SpanMode.shallow));

Instead I have to expand the code to this:
string[] entries;
foreach (string name; dirEntries(directory, SpanMode.shallow))
{
entries ~= name;
}

That's just a waste of precious space. Would it be a good idea to make a 
feature request for this?


Re: Eager dirEntries

2011-03-21 Thread Andrej Mitrovic
Well anywho I've wrapped it in my code:

string[] arrayDirEntries(string path, SpanMode spanMode)
{
string[] result;
foreach (string name; dirEntries(path, spanMode))
{
result ~= name;
}
return result;
}


Re: Eager dirEntries

2011-03-21 Thread bearophile
Andrej Mitrovic:

 this won't compile:
 
 string[] entries = array(dirEntries(directory, SpanMode.shallow));

Do you know why?

Bye,
bearophile


Re: Eager dirEntries

2011-03-21 Thread Jonathan M Davis
 Andrej Mitrovic:
  this won't compile:
  
  string[] entries = array(dirEntries(directory, SpanMode.shallow));
 
 Do you know why?

Yes. With dirEntries, you have to tell it the iteration type. It could be 
either a DirEntry or a string. As such, it fails the template constraint for 
array. It would probably be possible to extend array to work with it (with you 
giving it the iteration type as a template argument), but array would have to 
be reworked a bit for that to work.

- Jonathan M Davis


Re: Eager dirEntries

2011-03-21 Thread Andrej Mitrovic
On 3/22/11, bearophile bearophileh...@lycos.com wrote:
 Andrej Mitrovic:

 this won't compile:

 string[] entries = array(dirEntries(directory, SpanMode.shallow));

 Do you know why?

 Bye,
 bearophile


build.d(164): Error: template std.array.array(Range) if
(isIterable!(Range)  !isNarrowString!(Range)) does not match any
function template declaration
build.d(164): Error: template std.array.array(Range) if
(isIterable!(Range)  !isNarrowString!(Range)) cannot deduce template
function from argument types !()(DirIterator)

I'm not sure why array() has this signature. Perhaps it needs an
update and let any iterable range through?


Re: Get single keystroke?

2011-03-21 Thread Ali Çehreli

On 03/21/2011 03:37 PM, Andrej Mitrovic wrote:
 On 3/21/11, teoteo.ubu...@yahoo.com  wrote:
 On Mon, 21 Mar 2011 23:22:17 +0100, Andrej Mitrovic wrote:

 Woops forgot to add import std.stdio, here's a fixed version:

 import std.stdio : writefln;
 import std.c.stdio;
 import std.c.linux.termios;

 extern(C) void cfmakeraw(termios *termios_p);

 void main()
 {
  termios  ostate; /* saved tty state */ termios
  nstate; /* values for editor mode */

 // Open stdin in raw mode
 /* Adjust output channel*/
  tcgetattr(1,ostate);   /* save old state */
  tcgetattr(1,nstate);   /* get base of new
  state */ cfmakeraw(nstate);
  tcsetattr(1, TCSADRAIN,nstate);  /* set mode */

// Read characters in raw mode
  writefln(The key hit is %s, cast(char)fgetc(stdin));

 // Close
  tcsetattr(1, TCSADRAIN,ostate);   // return to original mode
 }

 It looks like this can be dangerous, because the terminal can be left in
 an unusable state. Please read this:
 http://groups.google.com/group/comp.os.linux.development.apps/
 browse_thread/thread/0667d16089e2b6fc


 H mentions using tcgetattr to save old state and restoring it with
 tcsetattr. This is what this code does. Btw this code is not mine,
 Walter posted it and I just added the cfmakeraw prototype. So kudos
 goes to him.

Thanks for posting this.

It can be improved by moving the last tcsetattr to an earlier 
scope(exit) statement:


termios  ostate;
tcgetattr(1, ostate);
scope (exit) tcsetattr(1, TCSADRAIN, ostate);

Ali



Optlink switch for map location?

2011-03-21 Thread Andrej Mitrovic
I can't find any switches to set the output dir/name of the map file. Since I'm 
using -od and -of with DMD I have my binaries generated in a subdirectory. I'd 
like to put the map file there as well. 

I can use a shell script to move the map file, but isn't there a linker switch 
for this already?


Re: Eager dirEntries

2011-03-21 Thread bearophile
Jonathan M Davis:

 Yes. With dirEntries, you have to tell it the iteration type. It could be
 either a DirEntry or a string. As such, it fails the template constraint for
 array. It would probably be possible to extend array to work with it (with you
 giving it the iteration type as a template argument), but array would have to
 be reworked a bit for that to work.

Thank you for your answer and I see, you may mean to optionally give it the 
item type:

string[] entries = array!string(dirEntries(directory, SpanMode.shallow));

Bye,
bearophile