digitalmars.D.bugs - Internal error: e2ir.c 134
- Daniel Horn (15/15) May 27 2004 version 0.90
- Daniel Horn (5/767) May 27 2004 it works using gdc release 1f
- Daniel Horn (26/35) May 27 2004 the problem functions were min and max
version 0.90 The following error occurs when I try to compile cev.d and BigRational.d $ dmd cev.d BigRational.d Internal error: e2ir.c 134 It goes away if I change at the bottom of vec.d alias vec!(BigRational.Rational,4) rat4; alias vec!(BigRational.Rational,3) rat3; alias vec!(BigRational.Rational,2) rat2; to alias vec!(int,4) rat4; alias vec!(int,3) rat3; alias vec!(int,2) rat2; it could be an error with my code, but it is challenging to find one without at least minimal compiler assistance.
May 27 2004
it works using gdc release 1f if you get it working you'll need to remove the void print () function which passes non POD to the printf so apparently this is some bug with dmd and not gdc Daniel Horn wrote:version 0.90 The following error occurs when I try to compile cev.d and BigRational.d $ dmd cev.d BigRational.d Internal error: e2ir.c 134 It goes away if I change at the bottom of vec.d alias vec!(BigRational.Rational,4) rat4; alias vec!(BigRational.Rational,3) rat3; alias vec!(BigRational.Rational,2) rat2; to alias vec!(int,4) rat4; alias vec!(int,3) rat3; alias vec!(int,2) rat2; it could be an error with my code, but it is challenging to find one without at least minimal compiler assistance. ------------------------------------------------------------------------ import std.string; template Zero (T) { T zero () { return T.init; } T one () { return zero()+1; } } template Zero(T:float) { T zero() { return 0; } T one () { return zero()+1; } } template Zero(T:double) { T zero() { return 0; } T one () { return zero()+1; } } template Zero(T:real) { T zero() { return 0; } T one () { return zero()+1; } } struct BigRational(T, int rat) { private: T n; T d; static T int_gcd_recurse (T less, T more) { T zero = Zero!(T).zero(); T amb = more%less; if (amb==zero) { return less; } return int_gcd_recurse(amb,less); } static T int_abs (T a) { T zero = Zero!(T).zero(); return a<zero?-a:a; } static T int_gcd (T aa, T bb) { T a = int_abs(aa); T b = int_abs(bb); return int_gcd_recurse(a<b?a:b,a<b?b:a); } BigRational InternalRationalize() { if (rat!=0) return Rationalize(); return *this; } public: static BigRational opCall (BigRational r) { return BigRational(r.n,r.d); } static BigRational opCall (T nn, T dd) { BigRational r; r.n=nn; r.d=dd; return r; } static BigRational opCall () { BigRational r; return r; } BigRational Rationalize() { T k = int_gcd(n,d); n=n/k; d=d/k; return *this; } BigRational opNeg() { return BigRational(-n,d).InternalRationalize(); } T IntegerPart() { return n/d; } BigRational Fraction() { return *this-BigRational(IntegerPart(),1); } T FractionalBits() { T zero = 0; assert(0); return zero; } BigRational opMulAssign(BigRational b) { n=n*b.n; d=d*b.d; InternalRationalize(); return *this; } BigRational opMul(BigRational b) { return BigRational(n*b.n,d*b.d).InternalRationalize(); } BigRational opAddAssign(BigRational b) { n=n*b.d+b.n*d; d=d*b.d; return InternalRationalize(); } BigRational opAdd(BigRational b) { return BigRational(n*b.d+d*b.n,d*b.d).InternalRationalize(); } BigRational opAdd(long b) { return *this+BigRational(b,1); } BigRational opSubAssign(BigRational b) { n=n*b.d-b.n*d; d=d*b.d; return InternalRationalize(); } BigRational opSub(BigRational b) { return BigRational(n*b.d-d*b.n,d*b.d).InternalRationalize(); } BigRational opSub_r(BigRational b) { return BigRational(d*b.n-n*b.d,d*b.d).InternalRationalize(); } BigRational opDivAssign(BigRational b) { n=n*b.d; d=d*b.n; InternalRationalize(); return *this; } BigRational opDiv(BigRational b) { return BigRational(n*b.d,d*b.n).InternalRationalize(); } BigRational opDiv_r(BigRational b) { return BigRational(d*b.n,n*b.d).InternalRationalize(); } BigRational opModAssign(BigRational b) { n = (n*b.d) % (b.n*d); d = b.d*d; InternalRationalize(); return *this; } BigRational opMod(BigRational b) { return BigRational((n*b.d) % (b.n*d),b.d*d).InternalRationalize(); } BigRational opMod_r(BigRational b) { return BigRational((b.n*d)%(n*b.d), b.d*d).InternalRationalize(); } int opEqual (BigRational r) { return (n*r.d==d*r.n)?1:0; } int opCmp (BigRational rr) { T thus = n*rr.d; T r = rr.n*d; if (thus<r) return -1; if (thus>r) return 1; return 0; } BigRational print() { //printf ("%d/%d=",cast(int)n,cast(int)d); BigRational r=*this; r.Rationalize(); char * num=std.string.toStringz(std.string.toString(r.n)); char * den=std.string.toStringz(std.string.toString(r.d)); printf ("%s/%s",num,den); //printf ("=%d/%d",cast(int)n,cast(int)d); return *this; } } alias BigRational!(long,0) Rational; ------------------------------------------------------------------------ module vec; import BigRational; private import std.math; private import std.c.math; private import std.string; alias std.math math; template VecMath(VALUE) { VALUE sqrt(VALUE x) { return math.sqrt(x); } } template VecMath(VALUE:BigRational.Rational) { VALUE sqrt(VALUE x) { VALUE ret; assert(0); return ret; } } template VecMath(VALUE:int) { int sqrt(int x) { return cast(int)(.01+math.sqrt(cast(float)x));//cast(int)floor((double)math.sqrt(cast(double)x)+.01); } } struct vec(VALUE, int tsize){ enum {nvalues=(tsize>0?tsize:1)} VALUE [nvalues]f; VALUE* getAt(uint ii) { return ii<tsize?&f[ii]:&f[tsize-1]; } VALUE x() { return f[0]; } VALUE y() { return f[1<tsize?1:0]; } VALUE z() { return f[2<tsize?2:0]; } VALUE w() { return f[3<tsize?3:0]; } VALUE x(VALUE i) { f[0]=i; return i; } VALUE y(VALUE i) { if (tsize>1) f[1]=i; return i; } VALUE z(VALUE i) { if (tsize>2) f[2]=i; return i; } VALUE w(VALUE i) { if (tsize>3) f[3]=i; return i; } VALUE i() { return f[0]; } VALUE j() { return f[1<tsize?1:0]; } VALUE k() { return f[2<tsize?2:0]; } VALUE i(VALUE i) { f[0]=i; return i; } VALUE j(VALUE i) { if (tsize>1) f[1]=i; return i; } VALUE k(VALUE i) { if (tsize>2) f[2]=i; return i; } static VALUE dot (vec t, vec oth) { VALUE ret=t.f[0]*oth.f[0]; for (int ii=1;ii<tsize;++ii) { ret+=t.f[ii]*oth.f[ii]; } return ret; } vec opNeg() { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=-f[ii]; } return ret; } vec opCmp() { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(BigRational.Zero!(VALUE).zero()==f[ii])?BigRational.Zero!(VALUE).one():BigRational.Zero!(VALUE).zero(); } return ret; } /* .vec!(int,tsize) opAnd(vec b) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]&&b[ii])?1:0; } return ret; } .vec!(int,tsize) opOr(vec b) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]||b[ii])?1:0; } return ret; } .vec!(int,tsize) opXor(vec b) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=((f[ii]||b[ii])&&!(f[ii]&&b[ii]))?1:0; } return ret; } vec opAndAssign(vec b) { for (int ii=0;ii<nvalues;++ii) { f[ii]=(f[ii]&&b[ii])?1:0; } return *this; } vec opOrAssign(vec b) { for (int ii=0;ii<nvalues;++ii) { f[ii]=(f[ii]||b[ii])?1:0; } return *this; } vec opXorAssign(vec b) { for (int ii=0;ii<nvalues;++ii) { f[ii]=((f[ii]||b[ii])&&!(f[ii]&&b[ii]))?1:0; } return *this; } */ VALUE length() { return VecMath!(VALUE).sqrt(dot(*this,*this)); } VALUE opIndex(uint ii, VALUE v) { return (*getAt(ii))=v; } VALUE opIndex(uint ii) { return ii<tsize?f[ii]:f[tsize-1]; } vec opMulAssign(vec b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]*=b.f[ii]; } return *this; } vec opMul(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]*b.f[ii]; } return ret; } vec opMulAssign(VALUE b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]*=b; } return *this; } vec opMul(VALUE b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]*b; } return ret; } vec opAddAssign(vec b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]+=b.f[ii]; } return *this; } vec opAdd(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]+b.f[ii]; } return ret; } vec opAddAssign(VALUE b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]+=b; } return *this; } vec opAdd(VALUE b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]+b; } return ret; } vec opSubAssign(vec b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]-=b.f[ii]; } return *this; } vec opSub(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]-b.f[ii]; } return ret; } vec opSubAssign(VALUE b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]-=b; } return *this; } vec opSub(VALUE b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]-b; } return ret; } vec opSub_r(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=b.f[ii]-this.f[ii]; } return ret; } vec opSub_r(VALUE b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=b-this.f[ii]; } return ret; } vec opDivAssign(vec b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]/=b.f[ii]; } return *this; } vec opDiv(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]/b.f[ii]; } return ret; } vec opDivAssign(VALUE b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]/=b; } return *this; } vec opDiv(VALUE b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]/b; } return ret; } vec opDiv_r(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=b.f[ii]/this.f[ii]; } return ret; } vec opDiv_r(VALUE b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=b/this.f[ii]; } return ret; } vec opModAssign(vec b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]%=b.f[ii]; } return *this; } vec min(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret[ii]=f[ii]<b[ii]?f[ii]:b[ii]; } return ret; } vec max(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret[ii]=f[ii]<b[ii]?b[ii]:f[ii]; } return ret; } vec opMod(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]%b.f[ii]; } return ret; } vec opModAssign(VALUE b) { for (int ii=0;ii<nvalues;++ii) { this.f[ii]%=b; } return *this; } vec opMod(VALUE b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=this.f[ii]%b; } return ret; } vec opMod_r(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=b.f[ii]%this.f[ii]; } return ret; } vec opMod_r(VALUE b) { vec ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=b%this.f[ii]; } return ret; } .vec!(int,tsize) opEq(vec inp) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]==inp.f[ii]); } return ret; } .vec!(int,tsize) opLess(vec inp) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]<inp.f[ii]); } return ret; } .vec!(int,tsize) opLess(VALUE inp) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]<inp); } return ret; } .vec!(int,tsize) opLEqual(vec inp) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]<inp.f[ii]); } return ret; } .vec!(int,tsize) opLEqual(VALUE inp) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]<inp); } return ret; } .vec!(int,tsize) opGreater(vec inp) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]>inp.f[ii]); } return ret; } .vec!(int,tsize) opGreater(VALUE inp) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]>inp); } return ret; } .vec!(int,tsize) opGEqual(vec inp) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]>=inp.f[ii]); } return ret; } .vec!(int,tsize) opGEqual(VALUE inp) { .vec!(int,tsize) ret; for (int ii=0;ii<nvalues;++ii) { ret.f[ii]=(f[ii]>=inp); } return ret; } //disallow! int opEqual(vec o){ for (int ii=0;ii<nvalues;++ii) { if (o.f[ii]!=f[ii]) return 0; } return 1; } int opCmp(vec o){ if (nvalues==1) { return this.opCmp(o.f[0]); } VALUE thus=dot(*this,*this); VALUE oth = dot(o,o); if (thus<oth) return -1; if (thus>oth) return 1; return 0; } int opEqual(VALUE o){ for (int ii=0;ii<nvalues;++ii) { if (o!=f[ii]) return 0; } return 1; } int opCmp(VALUE o){ if (nvalues==1) { if (f[0]<o) return -1; if (f[0]>o) return 1; return 0; } VALUE thus=dot(*this,*this); VALUE oth = o>=BigRational.Zero!(VALUE).zero()?o:-o; if (thus<oth) return -1; if (thus>oth) return 1; return 0; } int any() { for (int ii=1;ii<nvalues;++ii) { if (f[ii]!=BigRational.Zero!(VALUE).zero()) return 1; } return 0; } int all() { for (int ii=1;ii<nvalues;++ii) { if (f[ii]==BigRational.Zero!(VALUE).zero()) return 0; } return 1; } vec print () { printf ("[ "); for (int ii=0;ii<nvalues;++ii) { printf("%lf ",cast(double)f[ii]); } printf ("]"); return *this; } static vec opCall(VALUE a, VALUE b, VALUE c, VALUE d) { vec ret; ret[3]=d; ret[2]=c; ret[1]=b; ret[0]=a; return ret; } static vec opCall(VALUE a, VALUE b, VALUE c) { vec ret; ret[2]=c; ret[1]=b; ret[0]=a; return ret; } static vec opCall(VALUE a, VALUE b) { vec ret; ret[1]=b; ret[0]=a; return ret; } static vec opCall(vec v) { vec ret; for (int ii=nvalues-1;ii>=0;--ii) { ret[ii]=v[ii]; } return ret; } static vec opCall(VALUE []v) { vec ret; for (int ii=v.length-1;ii>=0;--ii) { ret[ii]=v[ii]; } return ret; } static vec opCall(VALUE a) { vec ret; for (int ii=0;ii<ret.nvalues;++ii) { ret[ii]=a; } return ret; } .vec!(VALUE,4) swizzle(int a, int b, int c, int d) { .vec!(VALUE,4) ret; ret.f[0]=*getAt(a); ret.f[1]=*getAt(b); ret.f[2]=*getAt(c); ret.f[3]=*getAt(d); return ret; } .vec!(VALUE,3) swizzle(int a, int b, int c) { .vec!(VALUE,3) ret; ret.f[0]=*getAt(a); ret.f[1]=*getAt(b); ret.f[2]=*getAt(c); return ret; } .vec!(VALUE,2) swizzle(int a, int b) { .vec!(VALUE,2) ret; ret.f[0]=*getAt(a); ret.f[1]=*getAt(b); return ret; } .vec!(VALUE,1) swizzle(int a) { .vec!(VALUE,1) ret; ret.f[0]=*getAt(a); return ret; } private: class Disallowed{}; } alias vec!(BigRational.Rational,4) rat4; alias vec!(BigRational.Rational,3) rat3; alias vec!(BigRational.Rational,2) rat2; /* alias vec!(int,4) rat4; alias vec!(int,3) rat3; alias vec!(int,2) rat2; */
May 27 2004
the problem functions were min and max to work around it in dmd you can replace the ?: syntax with an if () syntax as follows: the following code does not trigger said compiler error: vec min(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { if (f[ii]<b[ii]) ret[ii]=f[ii]; else ret[ii]=b[ii]; } return ret; } vec max(vec b) { vec ret; for (int ii=0;ii<nvalues;++ii) { if (f[ii]<b[ii]) ret[ii]=b[ii]; else ret[ii]=f[ii]; } return ret; } replacing the if statements with ?: statements triggers the bug Daniel Horn wrote:it works using gdc release 1f if you get it working you'll need to remove the void print () function which passes non POD to the printf so apparently this is some bug with dmd and not gdc Daniel Horn wrote:
May 27 2004