January 04, 2004 Re: DMD 0.77 release- Internal error e2ir.c 133 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | I cannot reproduce the error. What compiler switches did you use? "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt7cbt$1k9n$1@digitaldaemon.com... > This module causes an internal error "Internal error: e2ir.c 133": |
January 04, 2004 Re: DMD 0.77 release... templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | I understand the problem. It might be a bit difficult to correct, though. In the meantime, to workaround, make the 2 a variable instead. "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt7d5u$1lgq$1@digitaldaemon.com... > I'm running into a situation where function bodies inside templates are instantiated and checked even if that instantiation is never used. This is > causing problems, in that I can't provide, say, setters that take more parameters than the vector template was instantiated with. Those errors should happen during instantiation, but the instantiation should happen at point of call, not point of template instantiation. You probably also can't > have methods that utilize properties or methods of template parameters that > some may have and others may not (such as ++ on float) even if the method is > never actually used. > > C++ dealt with this by mandating implementations not expand and check template methods until they are used. > > Sean > > module vector; > > import std.intrinsic; > > import std.math; > > public: > > template VecTemplate(tfloat, int dim) > > { > > struct Vector > > { > > tfloat d[dim]; > > > void set(tfloat r) { foreach(inout tfloat v; d) v = r; } > > void set(tfloat a0,tfloat a1) { d[0] = a0; d[1] = a1; for(int i=2; i<dim; > ++i) d[i] = 0; } > > void set(tfloat a0,tfloat a1,tfloat a2) { d[0] = a0; d[1] = a1; d[2] = a2; > for(int i=3; i<dim; ++i) d[i] = 0; } // error... d[2] is outside allowed > range, but this function is never called! > > void set(tfloat a0,tfloat a1,tfloat a2,tfloat a3) { d[0] = a0; d[1] = a1; > d[2] = a2; d[3] = a3; for(int i=4; i<dim; ++i) d[i] = 0; } // error... d[2] > is outside allowed range > > void set(tfloat[dim] r) { for (int i=0; i<dim; ++i) d[i] = r[i]; } > > } > } > alias VecTemplate!(float,2) V2; > > alias V2.Vector Vector2; > > unittest > > { > > Vector2 b; > > b.set(0); > > b.set(0,1); > > } > > "Walter" <walter@digitalmars.com> wrote in message news:bt5esp$1o8d$1@digitaldaemon.com... > > Lots of new additions. Didn't get to most of the bug reports; I wanted to > > get D to be 'feature complete' first, the next version will be bug polishing. I'm setting sights on releasing D 1.0 by March. > > > > Lots of improvements to templates: > > |
January 04, 2004 Re: DMD 0.77 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | But it won't do what you want, probably. Won't that parse as: version(Linux) { } //// version(Windows) { } else { const unrecognised_platform = 0; static assert(unrecognised_platform); // will assert on Linux, even though it's handled above } ?? Anyway it's probably worth adding a unit test for. Also, just browsing on the D website and I found this section on pragmas at the bottom of the "Lexical" section. Should it be moved/integrated/otherwise reconciled with the new "pragmas" section? Pragmas Pragmas are special token sequences that give instructions to the compiler. Pragmas are processed by the lexical analyzer, may appear between any other tokens, and do not affect the syntax parsing. There is currently only one pragma, the #line pragma. Pragma # line Integer EndOfLine # line Integer Filespec EndOfLine Filespec " Characters " This sets the source line number to Integer, and optionally the source file name to Filespec, beginning with the next line of source text. The source file and line number is used for printing error messages and for mapping generated code back to the source for the symbolic debugging output. For example: int #line 6 "foo\bar" x; // this is now line 6 of file foo\bar Note that the backslash character is not treated specially inside Filespec strings. Sean "Walter" <walter@digitalmars.com> wrote in message news:bt8397$2lkb$1@digitaldaemon.com... > > "Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:bt7t0j$2cqr$1@digitaldaemon.com... > > Even better, would be > > > > version(Linux) > > { > > } > > version(Windows) > > { > > } > > else > > { > > const unrecognised_platform = 0; > > > > static assert(unrecognised_platform); > > } > > > > I take it that will be accepted by the compiler? > > It should work. > > |
January 04, 2004 Re: DMD 0.77 release- Internal error e2ir.c 133 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | \dmd\bin\dmd -g -debug -unittest -version=debug -c vector on vector.d You are probably missing the -unittest, which would cause the bug not to happen (I commented out the unit test and the bug went away) Sean "Walter" <walter@digitalmars.com> wrote in message news:bt8kvi$e46$1@digitaldaemon.com... > I cannot reproduce the error. What compiler switches did you use? > > "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt7cbt$1k9n$1@digitaldaemon.com... > > This module causes an internal error "Internal error: e2ir.c 133": |
January 04, 2004 Re: DMD 0.77 release - implicit templated types trough typeof - suggestion for walter | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | the current "implicit" way is to specify the type based on some parameter.. thanks to typeof, that works int x = max!(typeof(a))(a,b); not _that_ implicit, but at least, you don't have to know the type.. if the type parameters would be in !( )! braces, we could even implement a deduction method.. like this: int x = max!(int)!(a,b); for manual instantiation int x = max!(typeof(a))!(a,b); we want it to be the first passed type as first passed template type, too int x = max!!(a,b); just do the typeof(a) yourself.. so if you call a templated method with two !!, and no () in between, it just takes the argumentlist (in this case, a,b) and takes typeof till all template parameters are filled would be implicit enough for me, i guess In article <bt83f5$2lut$1@digitaldaemon.com>, Ben Hinkle says... > > >"Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt79le$1gb0$1@digitaldaemon.com... >> Most excellent! See, Walter *does* listen to us. ;) It's not implicit instantiation, but it's better than it was. It seems this syntax won't conflict with use of ! as logical not. > >What are the common use cases for implicit instantiation? Actually, the only ones I can think of off the top of my head are function templates. The example Walter gave: > >> > template Max(T) { T Max(T a, T b) { return ... ; } } >> > ... >> > x = Max!(int)(5,7); > >seems pretty compact and readable. The implicit form would be x = Max(5,7); (right? I can't even remember since the times I've used templates recently have been STL container stuff of the form vector<int> etc). > > I'm psyched about 0.77. It is definitely an improvement in the template >support. >-Ben > > |
January 04, 2004 Re: DMD 0.77 release - implicit templated types trough typeof - suggestion for walter | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | davepermen wrote:
>the current "implicit" way is to specify the type based on some parameter..
>thanks to typeof, that works
>
>int x = max!(typeof(a))(a,b);
>
>not _that_ implicit, but at least, you don't have to know the type..
>
>if the type parameters would be in !( )! braces, we could even implement a
>deduction method.. like this:
>
>int x = max!(int)!(a,b);
>
>for manual instantiation
>
>int x = max!(typeof(a))!(a,b);
>
>we want it to be the first passed type as first passed template type, too
>
>int x = max!!(a,b);
>
>just do the typeof(a) yourself..
>
>so if you call a templated method with two !!, and no () in between, it just
>takes the argumentlist (in this case, a,b) and takes typeof till all template
>parameters are filled
>
>
>would be implicit enough for me, i guess
>
>
>
I really like this idea!
|
January 04, 2004 Re: DMD 0.77 release - implicit templated types trough typeof - suggestion | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | thanks In article <bt99h5$1be7$1@digitaldaemon.com>, J Anderson says... > >davepermen wrote: > >>the current "implicit" way is to specify the type based on some parameter.. thanks to typeof, that works >> >>int x = max!(typeof(a))(a,b); >> >>not _that_ implicit, but at least, you don't have to know the type.. >> >>if the type parameters would be in !( )! braces, we could even implement a deduction method.. like this: >> >>int x = max!(int)!(a,b); >> >>for manual instantiation >> >>int x = max!(typeof(a))!(a,b); >> >>we want it to be the first passed type as first passed template type, too >> >>int x = max!!(a,b); >> >>just do the typeof(a) yourself.. >> >>so if you call a templated method with two !!, and no () in between, it just >>takes the argumentlist (in this case, a,b) and takes typeof till all template >>parameters are filled >> >> >>would be implicit enough for me, i guess >> >> >> >I really like this idea! > |
January 04, 2004 Re: DMD 0.77 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt8q7h$lhb$1@digitaldaemon.com... > But it won't do what you want, probably. > > Won't that parse as: > > version(Linux) > { > } > > //// > > version(Windows) > { > } > else > { > const unrecognised_platform = 0; > static assert(unrecognised_platform); // will assert on Linux, even though > it's handled above > } Sorry, an 'else' is needed in front of 'version(Windows)'. > Also, just browsing on the D website and I found this section on pragmas at > the bottom of the "Lexical" section. Should it be moved/integrated/otherwise reconciled with the new "pragmas" section? > > Pragmas > Pragmas are special token sequences that give instructions to the compiler. > Pragmas are processed by the lexical analyzer, may appear between any other > tokens, and do not affect the syntax parsing. > There is currently only one pragma, the #line pragma. That has nothing to do with the new pragma construct, I need to fix the documentation. |
January 04, 2004 Re: DMD 0.77 release - implicit templated types trough typeof - suggestion for walter | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | I've thought the similar idea. I think following syntax: int x = max?(a, b); ! denotes explicit and ? denotes implicit. "davepermen" <davepermen_member@pathlink.com> wrote in message news:bt992p$1b32$1@digitaldaemon.com... > the current "implicit" way is to specify the type based on some parameter.. > thanks to typeof, that works > > int x = max!(typeof(a))(a,b); > > not _that_ implicit, but at least, you don't have to know the type.. > > if the type parameters would be in !( )! braces, we could even implement a deduction method.. like this: > > int x = max!(int)!(a,b); > > for manual instantiation > > int x = max!(typeof(a))!(a,b); > > we want it to be the first passed type as first passed template type, too > > int x = max!!(a,b); > > just do the typeof(a) yourself.. > > so if you call a templated method with two !!, and no () in between, it just > takes the argumentlist (in this case, a,b) and takes typeof till all template > parameters are filled > > > would be implicit enough for me, i guess > > > In article <bt83f5$2lut$1@digitaldaemon.com>, Ben Hinkle says... > > > > > >"Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt79le$1gb0$1@digitaldaemon.com... > >> Most excellent! See, Walter *does* listen to us. ;) It's not implicit > >> instantiation, but it's better than it was. It seems this syntax won't conflict with use of ! as logical not. > > > >What are the common use cases for implicit instantiation? Actually, the only > >ones I can think of off the top of my head are function templates. The example Walter gave: > > > >> > template Max(T) { T Max(T a, T b) { return ... ; } } > >> > ... > >> > x = Max!(int)(5,7); > > > >seems pretty compact and readable. The implicit form would be x = Max(5,7); > >(right? I can't even remember since the times I've used templates recently > >have been STL container stuff of the form vector<int> etc). > > > > I'm psyched about 0.77. It is definitely an improvement in the template > >support. > >-Ben > > > > > > |
January 04, 2004 Re: DMD 0.77 release - implicit templated types trough typeof - suggestion for walter | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert | even more cool!! In article <bt9u5g$29tj$1@digitaldaemon.com>, Robert says... > >I've thought the similar idea. >I think following syntax: > >int x = max?(a, b); > >! denotes explicit and ? denotes implicit. > > >"davepermen" <davepermen_member@pathlink.com> wrote in message news:bt992p$1b32$1@digitaldaemon.com... >> the current "implicit" way is to specify the type based on some >parameter.. >> thanks to typeof, that works >> >> int x = max!(typeof(a))(a,b); >> >> not _that_ implicit, but at least, you don't have to know the type.. >> >> if the type parameters would be in !( )! braces, we could even implement a deduction method.. like this: >> >> int x = max!(int)!(a,b); >> >> for manual instantiation >> >> int x = max!(typeof(a))!(a,b); >> >> we want it to be the first passed type as first passed template type, too >> >> int x = max!!(a,b); >> >> just do the typeof(a) yourself.. >> >> so if you call a templated method with two !!, and no () in between, it >just >> takes the argumentlist (in this case, a,b) and takes typeof till all >template >> parameters are filled >> >> >> would be implicit enough for me, i guess >> >> >> In article <bt83f5$2lut$1@digitaldaemon.com>, Ben Hinkle says... >> > >> > >> >"Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt79le$1gb0$1@digitaldaemon.com... >> >> Most excellent! See, Walter *does* listen to us. ;) It's not >implicit >> >> instantiation, but it's better than it was. It seems this syntax won't conflict with use of ! as logical not. >> > >> >What are the common use cases for implicit instantiation? Actually, the >only >> >ones I can think of off the top of my head are function templates. The example Walter gave: >> > >> >> > template Max(T) { T Max(T a, T b) { return ... ; } } >> >> > ... >> >> > x = Max!(int)(5,7); >> > >> >seems pretty compact and readable. The implicit form would be x = >Max(5,7); >> >(right? I can't even remember since the times I've used templates >recently >> >have been STL container stuff of the form vector<int> etc). >> > >> > I'm psyched about 0.77. It is definitely an improvement in the template >> >support. >> >-Ben >> > >> > >> >> > |
Copyright © 1999-2021 by the D Language Foundation