November 26, 2008 Re: DMD 1.037 and 2.020 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | Kagamin Wrote:
> > - >The 'this' parameter to struct member functions is now a reference type,< I know this was discussed, but how does this change code? Does this forces to change C code when it is ported to D? How to do such porting? Few examples of situations may be useful.
>
> I'm affraid, this breaks my resource parser
>
> struct ResourceTable
> {
> ushort Shift; //alignment shift count
> ResourceType* FirstType()
> {
> return cast(ResourceType*)(this+1);
> }
> }
Try this:
return cast(ResourceType*)(&this + 1);
|
November 26, 2008 Re: DMD 1.037 and 2.020 releases | ||||
---|---|---|---|---|
| ||||
On Wed, Nov 26, 2008 at 9:20 AM, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote: > On Wed, Nov 26, 2008 at 9:06 AM, Kagamin <spam@here.lot> wrote: >>> - Added range support to foreach statement. What is this? >> Good question, because what is called foreach range statement was implemented long ago. > > It's the ability to use foreach on the new ranges (see std.range). > >> I'm affraid, this breaks my resource parser >> >> struct ResourceTable >> { >> ushort Shift; //alignment shift count >> ResourceType* FirstType() >> { >> return cast(ResourceType*)(this+1); >> } >> } > > return cast(ResourceType)(&this + 1); Erm, that's cast(ResourceType*), of course ;) |
November 26, 2008 Re: DMD 1.037 and 2.020 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 2008/11/25 Walter Bright <newshound1@digitalmars.com>:
>
> http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.037.zip
>
>
>
> http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.021.zip
>
>
I want to say thank you for taking the community's requests into account when fixing the bugs for this release. I can't tell you how happy it makes me to see some of these fixed. I hope this keeps up ;)
|
November 26, 2008 Re: DMD 1.037 and 2.020 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Wed, Nov 26, 2008 at 9:06 AM, Kagamin <spam@here.lot> wrote: >> - Added range support to foreach statement. What is this? > Good question, because what is called foreach range statement was implemented long ago. It's the ability to use foreach on the new ranges (see std.range). > I'm affraid, this breaks my resource parser > > struct ResourceTable > { > ushort Shift; //alignment shift count > ResourceType* FirstType() > { > return cast(ResourceType*)(this+1); > } > } return cast(ResourceType)(&this + 1); |
November 26, 2008 Re: Scope storage class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley: > Can you try declaring b as a nested function instead of as a delegate literal and see if that helps? I think that may lead to nonworking code. > (why are you declaring it the way you are, anyway? Here you can find explanations: http://en.wikipedia.org/wiki/Man_or_boy_test Here you can find other two versions that work, but I think the version I have shown is the more robust one (that is: able to computer up to higher N values with D1 compiler): http://www.rosettacode.org/wiki/Man_or_boy_test#D Bye, bearophile |
November 26, 2008 Re: DMD 1.037 and 2.020 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars Ivar Igesund | Lars Ivar Igesund wrote:
> But how does it work? If I have
>
> foo(scope void delegate()) { }
>
> will then
>
> foo({ ... });
>
> not allocate?
Correct.
|
November 26, 2008 Re: DMD 1.037 and 2.020 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> I can't tell you how happy it makes me to see some of these fixed.
We aim to please <g>.
|
November 26, 2008 Re: DMD 1.037 and 2.020 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Great release, thank you! |
November 26, 2008 Re: Scope storage class | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Wed, Nov 26, 2008 at 11:07 AM, bearophile <bearophileHUGS@lycos.com> wrote: >> Can you try declaring b as a nested function instead of as a delegate literal and see if that helps? > > I think that may lead to nonworking code. Uh, why? You are declaring the delegate as 'scope', yes? Meaning you don't expect the delegate to be allocated on the heap? Why don't you try it and see what happens instead of arguing? >> (why are you declaring it the way you are, anyway? > > Here you can find explanations: http://en.wikipedia.org/wiki/Man_or_boy_test > > Here you can find other two versions that work, but I think the version I have shown is the more robust one (that is: able to computer up to higher N values with D1 compiler): > http://www.rosettacode.org/wiki/Man_or_boy_test#D I don't really care about what test it is. I'm just confused why you're doing: scope int delegate() b; b = { .. }; instead of: scope int b() { .. } The reason I wonder is because I would expect that the compiler is still allocating the delegate on the heap if you use the first syntax. (the second is also shorter and clearer.) |
November 26, 2008 Re: Scope storage class [Was: DMD 1.037 and 2.020 releases] | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | bearophile wrote:
> To test the new scoping features of D 2.021 I have used a small stressing program, coming from this page, originally by Knuth:
>
> http://www.rosettacode.org/wiki/Man_or_boy_test
>
> More info:
> http://en.wikipedia.org/wiki/Man_or_boy_test
>
> My purpose is to see the D2 compiler being able to compute results up to N=25 on my PC (that has 2 GB RAM and a 32 bit operating system).
>
> ---------------------------
>
> This is the code I have used for DMD 1.037:
>
> import std.c.stdio: printf;
>
> int a(int k, lazy int x1, lazy int x2, lazy int x3, lazy int x4, lazy int x5) {
> int delegate() b;
> b = {
> k -= 1;
> return a(k, b(), x1, x2, x3, x4);
> };
> return k <= 0 ? x4 + x5 : b();
> }
>
> void main() {
> printf("%d\n", a(15, 1, -1, -1, 1, 0)); // N is 15
> }
>
> ---------------------------
>
> This is the code I have used for DMD 2.021. I was not sure how to use the scope, so if you have improvements please tell me:
>
> import std.c.stdio: printf;
>
> int a(scope int k, lazy int x1, lazy int x2, lazy int x3, lazy int x4, lazy int x5) {
> scope int delegate() b;
> b = {
> k -= 1;
> return a(k, b(), x1, x2, x3, x4);
> };
> return k <= 0 ? x4 + x5 : b();
> }
>
> void main() {
> printf("%d\n", a(15, 1, -1, -1, 1, 0)); // N is 15
> }
>
> ---------------------------
>
> The results for higher values of N are:
> k 21 22 23 24 25
> A -389695 -865609 -1922362 -4268854 -9479595
>
> In both cases I have compiled the code with:
> dmd -O -release -inline -L/STACK:1700000000 man_or_boy.d
>
> The results:
>
> DMD V.1.037 (exe: 168_476: bytes):
> N=24: 788 MB RAM, 3 seconds
> N=25: 1.57 GB RAM, 6.42 seconds
>
> DMD V.2.021 (exe: 99_356 bytes):
>
> The code was too much slow in D2, so I have stopped it. Do you know if the D2 code can be improved to have performance similar to D1 ones?
>
> Bye,
> bearophile
Try marking all the "lazy" parameters as "scope" ("lazy" creates delegates).
|
Copyright © 1999-2021 by the D Language Foundation