Error when downloading with +

2014-11-26 Thread RuZzz via Digitalmars-d-learn

Hi ppl!
When dub builds the project, he tries to load the 
http://code.dlang.org/packages/libevent/2.0.1+2.0.16.zip file, 
and dub gives out this error:

  Running DUB build  
dub build
@ /mnt/hdd2_3/ftp/workspace_eclipse/axt-d-base-application
The following changes will be performed:
Fetch dunit ~master, userWide
Fetch libevent =2.0.1+2.0.16 2.1.0, userWide
Fetch ddbc =0.2.9, userWide
Fetch mysql-d =0.3.0, userWide
Fetch hibernated =0.2.11, userWide
Fetch openssl =1.0.0+1.0.0e, userWide
Fetch libev =4.0.0+4.04 4.1.0, userWide
Fetch mysql-native 0.0.10, userWide
Package dunit ~master (/home/ruzzz/.dub/packages/) is already 
present with the latest version, skipping upgrade.

Fetching libevent 2.0.1+2.0.16..
Error executing command build: Failed to download 
http://code.dlang.org/packages/libevent/2.0.1%252B2.0.16.zip: 404 
Not Found


How to fix it?

dub.json:
{
name : axt-d-base-application,
description : A minimal D bundle.,
homepage: https://axi.su;,
license: GPL-2.0,
targetType: executable,
targetPath: bin,
dependencies : {
hibernated: =0.2.11,
toml-d: =0.3.0,
vibe-d: 0.7.21-beta.4,
ax-static-d: {
version: 0.0.1,
path: ../ax-static-d/
}
},
configurations: [
{
name: MySQL,
versions: [USE_MYSQL],
subConfigurations:
{
hibernated: MySQL
}
},
{
name: SQLite,
versions: [USE_SQLITE],
libs-posix: [sqlite3],
libs-windows: [sqlite3],
subConfigurations:
{
hibernated: SQLite
}
}
],
buildTypes: {
debug: {
buildOptions: [debugMode, debugInfo, optimize]
},
release: {
buildOptions: [releaseMode, optimize]
}
},
versions: [VibeCustomMain, USE_MYSQL]
}


Re: Reducing Pegged ASTs

2014-11-26 Thread Nordlöw
On Wednesday, 26 November 2014 at 06:09:12 UTC, Philippe Sigaud 
via Digitalmars-d-learn wrote:

IIRC there is a free function in Pegged that does it.


What's the name of this function?

I did not automate it, because every time I cut down severely a 
parse

tree, I later regret it because I lost information that way.

Cutting while still retaining original info (who is this node's
ancestor) is more difficult: you would have to store it 
somewhere
anyhow. You cannot create node classes to represent the 
hierarchy,
because of loops in the grammar: an Identifier can have many 
different

ancestors.

Note also that Pegged produces parse trees (complete parsing
information), not ASTs. ASTs would indeed be much smaller, but 
we

would have to define what are the master nodes in the D grammar.


What do you mean with master nodes?


If you want to remember the intermediate nodes you cut down, not
really, since you still need to store them somehow.


I don't quite understand your formulation in English here. Could 
you elaborate?


I think what's consuming memory right now is that I duplicate 
the matched strings at each level


What do you mean with duplicate? Doesn't Pegged use string slices 
that reference the original source?


If this problem is related to (im)mutability and If I understand 
you correctly you could use something like


static if (isImmutable!Source)
node.text = source_text[i..j];
else
node.text = source_text[i..j].idup;

right? Where in Pegged could this logic be injected?


Re: Uninitialized object hangs without warning.

2014-11-26 Thread bearophile via Digitalmars-d-learn

Bear Cherian:


Class MyClass{

this(){}

void someFunction(){
//body
}

}

And in my app I had something like

MyClass classObject;
classObject.someFunction();

When I compile, no warnings or errors.


If you compile that code (with lowercase Class) with -O the 
compiler finds the bug:




class MyClass {
this() {}

void someFunction() {
//body
}
}

void main() {
MyClass classObject;
classObject.someFunction;
}


test.d(11,5): Error: null dereference in function _Dmain


But in more complex cases the compiler doesn't.

Bye,
bearophile


Re: Error when downloading with +

2014-11-26 Thread Suliman via Digitalmars-d-learn
This is an issue with your version of dub with a buggy url 
encoding method. Download the latest at code.dlang.org


http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/22266/


Cache Building of Pegged-Generated Parsers in a DUB Project

2014-11-26 Thread Nordlöw
I want to cache parsers generated by Pegged grammars in a DUB 
project by writing the generated parser strings to files.


Is it possible to add this build logic somewhere in DUB or do I 
have to resort to SCons for this?


Re: Error when downloading with +

2014-11-26 Thread RuZzz via Digitalmars-d-learn

On Wednesday, 26 November 2014 at 10:01:32 UTC, Suliman wrote:
This is an issue with your version of dub with a buggy url 
encoding method. Download the latest at code.dlang.org


http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/22266/


thanks, up-dating to version 0.9.22 solved the problem.


Re: Cache Building of Pegged-Generated Parsers in a DUB Project

2014-11-26 Thread Stefan Koch via Digitalmars-d-learn

On Wednesday, 26 November 2014 at 10:26:05 UTC, Nordlöw wrote:
I want to cache parsers generated by Pegged grammars in a DUB 
project by writing the generated parser strings to files.


Is it possible to add this build logic somewhere in DUB or do I 
have to resort to SCons for this?


preBuildCommand in check if the files are there
if not generate them if yes do nothing


Re: Cache Building of Pegged-Generated Parsers in a DUB Project

2014-11-26 Thread Nordlöw

On Wednesday, 26 November 2014 at 12:09:34 UTC, Stefan Koch wrote:

preBuildCommand in check if the files are there
if not generate them if yes do nothing


Thanks!

Documented here http://code.dlang.org/package-format

by searching for preBuildCommands


const class

2014-11-26 Thread Oleg via Digitalmars-d-learn

Hello. I can't find siple way to realization this behavior:

[code]
class A
{
  A parent;

  void someFunc() const { }

  void parentCall() const
  {
 const(A) cur = this;
 while( cur )
 {
   cur.someFunc();
   cur = cur.parent;
 }
  }
}
[/code]

error: cannot modify const expression cur

how create variable that store const object and can be changed to 
other const object?


Re: Cache Building of Pegged-Generated Parsers in a DUB Project

2014-11-26 Thread Nordlöw

On Wednesday, 26 November 2014 at 12:09:34 UTC, Stefan Koch wrote:

On Wednesday, 26 November 2014 at 10:26:05 UTC, Nordlöw wrote:
I want to cache parsers generated by Pegged grammars in a DUB 
project by writing the generated parser strings to files.


Is it possible to add this build logic somewhere in DUB or do 
I have to resort to SCons for this?


preBuildCommand in check if the files are there
if not generate them if yes do nothing


I guess I could right a separate d program that generates the 
files called by preBuildCommand. But it would be even greater if 
we could do CTFE-file-io to check whether the evaluation needs to 
be called at all. As we can import files  (generated parser 
module) into strings and write the generated parser strings at 
run-time the only thing need is to add some logic that generates 
a digest every time a parser is generated write that digest to a 
file and then import that digest at compile time at compare it to 
the digest of the parser string read at compile time. If they 
differ (at compile time) using static if the parser enum string 
is updated. Does my vision hold water? Destroy.


Re: const class

2014-11-26 Thread bearophile via Digitalmars-d-learn

Oleg:

how create variable that store const object and can be changed 
to other const object?


Take a look at std.typecons.Rebindable/std.typecons.rebindable.

Read all Phobos documentation, it helps.

Bye,
bearophile


Re: windows linker error

2014-11-26 Thread Joakim via Digitalmars-d-learn
On Wednesday, 26 November 2014 at 04:10:08 UTC, Vlad Levenfeld 
wrote:


I'm compiling the latest build from github.

(I normally stay up to date with the current builds on 64bit 
Debian and everything works more or less without a hitch there, 
but now I need to get some of my tools working in a Windows 
environment)


I'm not really sure what my options are regarding the COFF or 
what they mean, 64-bit is really the only requirement (mostly 
because I can't get the 32-bit stuff to compile).


I've got Visual Studio Premium, I tried to install from the exe 
at one point and got Visual D in the process (and this did 
work, except that the code I need is built against the latest 
dmd/druntime/phobos builds).


I see, so the problem appears to be that you're trying to compile 
D from git to produce Win64 builds.  COFF is the binary format 
used by Microsoft for their MSVC runtime, and dmd only supports 
Win64 with COFF, the Microsoft linker, and MSVC.  If you're okay 
with 32-bit dmd from git, which by default uses the Digital Mars 
C runtime, the Digital Mars linker called optlink, and the OMF 
binary format, these instructions should work for you, as they 
did for me:


http://wiki.dlang.org/Building_DMD#Windows_2

Installing it from the instructions, IIRC, also worked for me, 
but again, the version.


So I used the dmd visual studio project to build dmd, then 
built druntime and phobos with Digital Mars make;


I had previously tried to use dmc to build dmd but couldn't get 
it to work.


Anyway, I manage to build successfully but then I get this 
linker error when I try to run dmd on some test.d consisting of 
void main (){}.


I've gone into sc.ini and pulled out the ;VC2012 comments to 
expose the LIB instruction (to fix a different problem) and 
this is the point that I've gotten stuck at.


If you still want to get Win64 from git working, I advise you to 
use a release build of dmd from the zip and set it up to get code 
compiling for Win64, ie make sure you understand what environment 
variables need to be set to use the MSVC runtime and linker.  
Then, compile dmd from git using dmc and the instructions linked 
above, before using the same Win64 environment variables to 
compile your code.


If you still have problems, you may want to look at the scripts 
and Win64-specific patches that Brad uses on the auto-tester to 
continuously build dmd for Win64:


https://github.com/braddr/d-tester/tree/master/client/src


Re: Uninitialized object hangs without warning.

2014-11-26 Thread Bear Cherian via Digitalmars-d-learn

On Wednesday, 26 November 2014 at 09:38:11 UTC, bearophile wrote:

Bear Cherian:


Class MyClass{

   this(){}

   void someFunction(){
   //body
   }

}

And in my app I had something like

   MyClass classObject;
   classObject.someFunction();

When I compile, no warnings or errors.


If you compile that code (with lowercase Class) with -O the 
compiler finds the bug:




class MyClass {
this() {}

void someFunction() {
//body
}
}

void main() {
MyClass classObject;
classObject.someFunction;
}


test.d(11,5): Error: null dereference in function _Dmain


But in more complex cases the compiler doesn't.

Bye,
bearophile


Yes, the capital C was a typo.

I still think this shouldn't be an optimization. Maybe I'm just
used to Java, as this would be a compile error by default.


Compile-Time Memoization of Pegged-Generated Parser

2014-11-26 Thread Nordlöw
I have working logic for automatic memoization of 
Pegged-generated parsers from Peg grammars here


https://github.com/nordlow/justd/blob/master/firstPegged/source/app.d

Now I wonder if this logic could be modularized in some way 
making it more easy to use (and not so verbose).


The key question is if it's possible to somehow replace

the module ctor at

https://github.com/nordlow/justd/blob/master/firstPegged/source/app.d#L339

that writes the grammar and parser to disk with some automatic 
registration logic.


My plan is to append these to an array of pairs of string at

https://github.com/nordlow/justd/blob/master/firstPegged/source/app.d#L52

that contain file and string to persistently memoized. But when 
uncomment the lines declaring and appending to fileWrites I get a 
compilation error


source/app.d(63): Error: no identifier for declarator fileWrites
source/app.d(63): Error: Declaration expected, not '~='
source/app.d(64): Error: no identifier for declarator fileWrites
source/app.d(64): Error: Declaration expected, not '~='

Have I missed something?

Destroy!


Re: Compile-Time Memoization of Pegged-Generated Parser

2014-11-26 Thread Nordlöw

On Wednesday, 26 November 2014 at 22:31:04 UTC, Nordlöw wrote:

source/app.d(63): Error: no identifier for declarator fileWrites
source/app.d(63): Error: Declaration expected, not '~='
source/app.d(64): Error: no identifier for declarator fileWrites
source/app.d(64): Error: Declaration expected, not '~='

Have I missed something?

Destroy!


Update: I guess this means D doesn't allow any statements in 
global scope. Can/Should I instead use some compile-time 
reflection to get list of parser strings that should be cached to 
disk? I guess if I wrap the path-parser-string-pair in a struct, 
say CachingPeggedParser, defined in global scope I could get a 
list of all the enum instances of this struct and do something 
with these in module constructor right?


Please tell me if this approach is unneccessary complicated!


Array toHash()

2014-11-26 Thread David Held via Digitalmars-d-learn
I have a class which contains an int[] and some other stuff.  I want to 
use my class as the key for an AA, so I am overriding toHash().  But the 
int[] is the only part which should produce the hash code.  I know that 
int[].toHash() is defined somehow, because I can put int[] directly into 
an AA without writing any hash functions.  But I don't know how to spell 
this explicitly or force the compiler to generate it for me so that I 
can forward to it in my toHash().  For illustration:


class Foo
{
override
size_t toHash() @trusted pure const nothrow
{
// error: no property 'toHash' for type 'int[]'
return importantStuff.toHash();
}

// override opEquals() too...

int[] importantStuff;
bool  notImportant;
int   ignoreMe;
}

Any way to avoid re-implementing this hash function?

Dave


Re: Casting in Safe D

2014-11-26 Thread David Held via Digitalmars-d-learn

On 11/23/2014 3:12 PM, anonymous wrote:

[...]
And even pointer dereferencing is @safe. Invalid ones will fail
with a segfault at run time:
void foo(int* a) @safe {*a = 13;}


Hmm...throwing an exception is a well-defined behavior, but is 
segfaulting a well-defined behavior of correct D programs?  This seems 
like a peculiar definition of safe to me...


Dave



Re: Array toHash()

2014-11-26 Thread Ali Çehreli via Digitalmars-d-learn

On 11/26/2014 04:25 PM, David Held wrote:

 class Foo
 {
  override
  size_t toHash() @trusted pure const nothrow
  {
  // error: no property 'toHash' for type 'int[]'
  return importantStuff.toHash();
  }

The getHash() member function of the particular TypeInfo can be used. 
However, it is not currently pure, so you must comment that out from 
your toHash:


override
size_t toHash() @trusted /* pure */ const nothrow
{
return typeid(importantStuff).getHash(importantStuff);

}

If a function can safely be casted to pure, you can use the following 
yet-missing-in-phobos function template:


import std.traits;

auto assumePure(T)(T t)
if (isFunctionPointer!T || isDelegate!T)
{
enum attrs = functionAttributes!T | FunctionAttribute.pure_;
return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
}

// ...

override
size_t toHash() @trusted pure const nothrow
{
auto func = assumePure((typeid(importantStuff).getHash));
return func(importantStuff);
}

Note that now your toHash can be pure.

Ali



Still not D standard yet ?

2014-11-26 Thread Ledd via Digitalmars-d-learn
I would like to know if something has changed in the plans for 
the future of D, because I really think it needs some kind of 
formalization and standardization to be a good investment, 
especially for medium/large/commercial projects .


Thanks.