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

2011-03-20 Thread Zirneklis

On 20/03/2011 19:55, Kai Meyer wrote:

On 03/19/2011 06: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


Is there a copy of the official D grammar somewhere online? I wrote a
lexer for my Compiler class and would love to try and apply it to
another grammar.

-Kai Meyer


As far as I know the documentation /is/ the official grammar
http://digitalmars.com/d/2.0/lex.html


Re: How do I read data with ByChunk?

2011-03-18 Thread Zirneklis

On 18/03/2011 14:35, Craig Dillabaugh wrote:

Hi,
I have two binary files containing image data, and I want to go through them 
pixel by
pixel and read the image data into arrays and compare the pixel values (images 
have the
exact same dimensions but one is unsigned 1 byte per pixel, and the other 
signed 2 bytes
per pixel).

I am trying to read the data in using the following loop:

for(int i = 0; i  num_blocks; i++) {
auto resampbytes = resampFile.byChunk( resamp_buffer_size );
auto normbytes = normalFile.byChunk( normal_buffer_size );
ubyte[] resamp = cast(ubyte[]) resampbytes;
short[] normaldata = cast(short[]) normbytes;

 //Process the data ...
}

However, when I attempt to compile this I get the following errors:

Error: cannot cast from ByChunk to ubyte[]
Error: cannot cast from ByChunk to short[]

Oddly, the example for ByChunk in the documentation seems to do exactly what I 
think I
am trying here, but apparently I am missing something.

Any help would be appreciated (also if there is a better way of doing what I am 
trying
to do any pointers on that would be appreciated too!)

Regards,

Craig



File.byChunk is designed to be used with a foreach loop, you could try:

ubyte[] resamp = new ubyte[resamp_buffer_size];
short[] normaldata = new short[normal_buffer_size];
for(int i = 0; i  num_blocks; i++)
{
resampFile.rawRead(resamp);
normaldata.rawRead(normaldata);

//Process the data ...
}

--
Aku MoD.


Re: Templated nested function can't access 'this'

2011-03-17 Thread Zirneklis

A known bug http://d.puremagic.com/issues/show_bug.cgi?id=3159

Your just gonna have to make it a normal templated method

--
Aku MoD.


Re: Iterating over an enum associative array

2011-03-14 Thread zirneklis

On 14/03/2011 14:38, Peter Lundgren wrote:

== Quote from Nebster (evil.nebs...@gmail.com)'s article

Hey,
I'm having some problems iterating over an enumerated associative array.
It comes up with this error at compile time:
Internal error: e2ir.c 4835
I cut the code down to this:
import std.stdio;
  
enum int[string] assoc = [;: 0, =: 1, +: 2, -: 2, *: 3,
/: 3];
  
void main()
{
foreach(op; assoc.byKey())
writefln(op: %s, op);
}
What does this mean/how can I get this to work?
Thanks,
Nebster



That's a rather cryptic error message. Hopefully someone smarter than I can 
trace
down why this doesn't have better error reporting. I suspect the problem has
something to do with CTFE. Because you're using an enum, D assumes you want its
value to be computed at compile time. However, currently, associative arrays can
not be evaluated at compile time. Using a static this to initialize the value at
runtime, as already suggested, should solve your issue.


That's not the cryptic part, its the name of the source file and line 
number, its tripping up here:


AssocArrayLiteralExp::toElem
//...
Type *t = type-toBasetype()-mutableOf();
assert(t-ty == Taarray);//line 4835

Though to me that whole function looks like a pile of random abbreviations.