comparison dmd2/builtin.c @ 1452:638d16625da2

LDC 2 compiles again.
author Robert Clipsham <robert@octarineparrot.com>
date Sat, 30 May 2009 17:23:32 +0100
parents f04dde6e882c
children
comparison
equal deleted inserted replaced
1423:42bd767ec5a4 1452:638d16625da2
1 1
2 // Compiler implementation of the D programming language 2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2007 by Digital Mars 3 // Copyright (c) 1999-2009 by Digital Mars
4 // All Rights Reserved 4 // All Rights Reserved
5 // written by Walter Bright 5 // written by Walter Bright
6 // http://www.digitalmars.com 6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License 7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt. 8 // in artistic.txt, or the GNU General Public License in gnu.txt.
21 #include "aggregate.h" 21 #include "aggregate.h"
22 #include "identifier.h" 22 #include "identifier.h"
23 #include "id.h" 23 #include "id.h"
24 #include "module.h" 24 #include "module.h"
25 25
26 #if DMDV2
27
26 /********************************** 28 /**********************************
27 * Determine if function is a builtin one. 29 * Determine if function is a builtin one that we can
30 * evaluate at compile time.
28 */ 31 */
29 enum BUILTIN FuncDeclaration::isBuiltin() 32 enum BUILTIN FuncDeclaration::isBuiltin()
30 { 33 {
31 static const char FeZe[] = "FeZe"; // real function(real) 34 static const char FeZe[] = "FNaNbeZe"; // pure nothrow real function(real)
32 35
33 //printf("FuncDeclaration::isBuiltin() %s\n", toChars()); 36 //printf("FuncDeclaration::isBuiltin() %s\n", toChars());
34 if (builtin == BUILTINunknown) 37 if (builtin == BUILTINunknown)
35 { 38 {
36 builtin = BUILTINnot; 39 builtin = BUILTINnot;
37 if (parent && parent->isModule()) 40 if (parent && parent->isModule())
38 { 41 {
42 // If it's in the std.math package
39 if (parent->ident == Id::math && 43 if (parent->ident == Id::math &&
40 parent->parent && parent->parent->ident == Id::std && 44 parent->parent && parent->parent->ident == Id::std &&
41 !parent->parent->parent) 45 !parent->parent->parent)
42 { 46 {
47 //printf("deco = %s\n", type->deco);
43 if (strcmp(type->deco, FeZe) == 0) 48 if (strcmp(type->deco, FeZe) == 0)
44 { 49 {
45 if (ident == Id::sin) 50 if (ident == Id::sin)
46 builtin = BUILTINsin; 51 builtin = BUILTINsin;
47 else if (ident == Id::cos) 52 else if (ident == Id::cos)
51 else if (ident == Id::_sqrt) 56 else if (ident == Id::_sqrt)
52 builtin = BUILTINsqrt; 57 builtin = BUILTINsqrt;
53 else if (ident == Id::fabs) 58 else if (ident == Id::fabs)
54 builtin = BUILTINfabs; 59 builtin = BUILTINfabs;
55 //printf("builtin = %d\n", builtin); 60 //printf("builtin = %d\n", builtin);
61 }
62 // if float or double versions
63 else if (strcmp(type->deco, "FNaNbdZd") == 0 ||
64 strcmp(type->deco, "FNaNbfZf") == 0)
65 {
66 if (ident == Id::_sqrt)
67 builtin = BUILTINsqrt;
56 } 68 }
57 } 69 }
58 } 70 }
59 } 71 }
60 return builtin; 72 return builtin;
73 Expression *e = NULL; 85 Expression *e = NULL;
74 switch (builtin) 86 switch (builtin)
75 { 87 {
76 case BUILTINsin: 88 case BUILTINsin:
77 if (arg0->op == TOKfloat64) 89 if (arg0->op == TOKfloat64)
78 e = new RealExp(0, sinl(arg0->toReal()), Type::tfloat80); 90 e = new RealExp(0, sinl(arg0->toReal()), arg0->type);
79 break; 91 break;
80 92
81 case BUILTINcos: 93 case BUILTINcos:
82 if (arg0->op == TOKfloat64) 94 if (arg0->op == TOKfloat64)
83 e = new RealExp(0, cosl(arg0->toReal()), Type::tfloat80); 95 e = new RealExp(0, cosl(arg0->toReal()), arg0->type);
84 break; 96 break;
85 97
86 case BUILTINtan: 98 case BUILTINtan:
87 if (arg0->op == TOKfloat64) 99 if (arg0->op == TOKfloat64)
88 e = new RealExp(0, tanl(arg0->toReal()), Type::tfloat80); 100 e = new RealExp(0, tanl(arg0->toReal()), arg0->type);
89 break; 101 break;
90 102
91 case BUILTINsqrt: 103 case BUILTINsqrt:
92 if (arg0->op == TOKfloat64) 104 if (arg0->op == TOKfloat64)
93 e = new RealExp(0, sqrtl(arg0->toReal()), Type::tfloat80); 105 e = new RealExp(0, sqrtl(arg0->toReal()), arg0->type);
94 break; 106 break;
95 107
96 case BUILTINfabs: 108 case BUILTINfabs:
97 if (arg0->op == TOKfloat64) 109 if (arg0->op == TOKfloat64)
98 e = new RealExp(0, fabsl(arg0->toReal()), Type::tfloat80); 110 e = new RealExp(0, fabsl(arg0->toReal()), arg0->type);
99 break; 111 break;
100 } 112 }
101 return e; 113 return e;
102 } 114 }
115
116 #endif