annotate dmd/RealExp.d @ 144:ea6325d0edd9

+ RealExp.toCBuffer
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Tue, 14 Sep 2010 22:39:29 +0100
parents 010eb8f0e18d
children fe2e1b93e88f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1 module dmd.RealExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 73
diff changeset
3 import dmd.common;
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
4 import dmd.Complex;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
5 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
6 import dmd.backend.elem;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
7 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
8 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
9 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
10 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
11 import dmd.TOK;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
12 import dmd.Scope;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.IRState;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
14 import dmd.Type;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Port;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TY;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
18
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
19 import dmd.expression.Util;
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
20
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
26 import std.stdio;
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
27
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 class RealExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 real value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 this(Loc loc, real value, Type type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 super(loc, TOK.TOKfloat64, RealExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 //printf("RealExp.RealExp(%Lg)\n", value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 this.value = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 this.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
40 override bool equals(Object o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
42 if (this is o)
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
43 return true;
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
44
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
45 Expression e = cast(Expression)o;
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
46 if (e.op == TOKfloat64) {
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
47 RealExp ne = cast(RealExp)e;
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
48 if (type.toHeadMutable().equals(ne.type.toHeadMutable())) {
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
49 if (RealEquals(value, ne.value)) {
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
50 return true;
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
51 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
52 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
53 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
54
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
55 return 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
58 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 type = Type.tfloat64;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
67 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
72 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
77 override ulong toInteger()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
82 override ulong toUInteger()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
87 override real toReal()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 return type.isreal() ? value : 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
92 override real toImaginary()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 return type.isreal() ? 0 : value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
97 override Complex!(real) toComplex()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 return Complex!(real)(toReal(), toImaginary());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
102 override Expression castTo(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 if (type != t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 if ((type.isreal() && t.isreal()) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 (type.isimaginary() && t.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 e = copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 e = Expression.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
120 override int isConst()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
125 override bool isBool(bool result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
127 return result ? (value != 0) : (value == 0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
130 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
144
ea6325d0edd9 + RealExp.toCBuffer
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
132 floatToBuffer(buf, type, value);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
135 override void toMangleBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
137 buf.writeByte('e');
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
138 realToMangleBuffer(buf, value);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
141 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 eve c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 tym_t ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 //printf("RealExp.toElem(%p) %s\n", this, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 ///memset(&c, 0, sizeof(c));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 ty = type.toBasetype().totym();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 switch (tybasic(ty))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 case TYfloat:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 case TYifloat:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 c.Vfloat = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 if (Port.isSignallingNan(value)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 std.stdio.writeln("signalling float");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 (cast(uint*)&c.Vfloat)[0] &= 0xFFBFFFFFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 case TYdouble:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 case TYidouble:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 c.Vdouble = value; // unfortunately, this converts SNAN to QNAN
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (Port.isSignallingNan(value)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 std.stdio.writeln("signalling double");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 // Put SNAN back
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 (cast(uint*)&c.Vdouble)[1] &= 0xFFF7FFFFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 case TYldouble:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 case TYildouble:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 c.Vldouble = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 ///type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 ///type.toBasetype().print();
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
179 printf("ty = %d, tym = %lx\n", type.ty, ty);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 return el_const(ty, &c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 static private char[6] zeropad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
187 override dt_t** toDt(dt_t** pdt)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 float fvalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 double dvalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 real evalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 //printf("RealExp.toDt(%Lg)\n", value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 switch (type.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 case Tfloat32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 case Timaginary32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 fvalue = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 pdt = dtnbytes(pdt,4,cast(char*)&fvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 case Tfloat64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 case Timaginary64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 dvalue = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 pdt = dtnbytes(pdt,8,cast(char*)&dvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 case Tfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 case Timaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 evalue = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 pdt = dtnbytes(pdt,REALSIZE - REALPAD,cast(char*)&evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 pdt = dtnbytes(pdt,REALPAD,zeropad.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 assert(REALPAD <= zeropad.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 writef("%s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 ///type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 return pdt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225