diff 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
line wrap: on
line diff
--- a/dmd2/builtin.c	Thu May 28 00:07:21 2009 +0200
+++ b/dmd2/builtin.c	Sat May 30 17:23:32 2009 +0100
@@ -1,6 +1,6 @@
 
 // Compiler implementation of the D programming language
-// Copyright (c) 1999-2007 by Digital Mars
+// Copyright (c) 1999-2009 by Digital Mars
 // All Rights Reserved
 // written by Walter Bright
 // http://www.digitalmars.com
@@ -23,12 +23,15 @@
 #include "id.h"
 #include "module.h"
 
+#if DMDV2
+
 /**********************************
- * Determine if function is a builtin one.
+ * Determine if function is a builtin one that we can
+ * evaluate at compile time.
  */
 enum BUILTIN FuncDeclaration::isBuiltin()
 {
-    static const char FeZe[] = "FeZe";	// real function(real)
+    static const char FeZe[] = "FNaNbeZe";	// pure nothrow real function(real)
 
     //printf("FuncDeclaration::isBuiltin() %s\n", toChars());
     if (builtin == BUILTINunknown)
@@ -36,10 +39,12 @@
 	builtin = BUILTINnot;
 	if (parent && parent->isModule())
 	{
+	    // If it's in the std.math package
 	    if (parent->ident == Id::math &&
 		parent->parent && parent->parent->ident == Id::std &&
 		!parent->parent->parent)
 	    {
+		//printf("deco = %s\n", type->deco);
 		if (strcmp(type->deco, FeZe) == 0)
 		{
 		    if (ident == Id::sin)
@@ -54,6 +59,13 @@
 			builtin = BUILTINfabs;
 		    //printf("builtin = %d\n", builtin);
 		}
+		// if float or double versions
+		else if (strcmp(type->deco, "FNaNbdZd") == 0 ||
+			 strcmp(type->deco, "FNaNbfZf") == 0)
+		{
+		    if (ident == Id::_sqrt)
+			builtin = BUILTINsqrt;
+		}
 	    }
 	}
     }
@@ -75,28 +87,30 @@
     {
 	case BUILTINsin:
 	    if (arg0->op == TOKfloat64)
-		e = new RealExp(0, sinl(arg0->toReal()), Type::tfloat80);
+		e = new RealExp(0, sinl(arg0->toReal()), arg0->type);
 	    break;
 
 	case BUILTINcos:
 	    if (arg0->op == TOKfloat64)
-		e = new RealExp(0, cosl(arg0->toReal()), Type::tfloat80);
+		e = new RealExp(0, cosl(arg0->toReal()), arg0->type);
 	    break;
 
 	case BUILTINtan:
 	    if (arg0->op == TOKfloat64)
-		e = new RealExp(0, tanl(arg0->toReal()), Type::tfloat80);
+		e = new RealExp(0, tanl(arg0->toReal()), arg0->type);
 	    break;
 
 	case BUILTINsqrt:
 	    if (arg0->op == TOKfloat64)
-		e = new RealExp(0, sqrtl(arg0->toReal()), Type::tfloat80);
+		e = new RealExp(0, sqrtl(arg0->toReal()), arg0->type);
 	    break;
 
 	case BUILTINfabs:
 	    if (arg0->op == TOKfloat64)
-		e = new RealExp(0, fabsl(arg0->toReal()), Type::tfloat80);
+		e = new RealExp(0, fabsl(arg0->toReal()), arg0->type);
 	    break;
     }
     return e;
 }
+
+#endif