Mercurial > projects > ldc
view dmd2/builtin.c @ 1605:1d5721f9ae18
[WIP] Merge DMD r251: bugzilla 111 (appending a dchar to a char[])
This patch needs some work in the code generation, because of the runtime
changes (functions "_d_arrayappendcd" and "_d_arrayappendwd" are added).
This doesn't affect existing code though, it just makes with patch
a little useless, because something like this:
char [] s;
s ~= '\u6211';
That failed to compile with a nice error message previously to this
change, now fails with and ugly error message (a failed assertion).
Apparently there is a regression introduced by this patch too, when
compiling Dil I get this assertion message:
ldc: /home/luca/tesis/ldc/gen/statements.cpp:132: virtual void ReturnStatement::toIR(IRState*): Assertion `p->topfunc()->getReturnType() == llvm::Type::getVoidTy(gIR->context())' failed.
0 ldc 0x08a91628
Thank god we have bisecting capabilities in VCSs now ;)
---
dmd/expression.c | 47 +++++++++++++++++++++++++++++++++++++++++------
1 files changed, 41 insertions(+), 6 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:19 -0300 |
parents | 638d16625da2 |
children |
line wrap: on
line source
// Compiler implementation of the D programming language // Copyright (c) 1999-2009 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com // License for redistribution is by either the Artistic License // in artistic.txt, or the GNU General Public License in gnu.txt. // See the included readme.txt for details. #include <stdio.h> #include <assert.h> #include <math.h> #include "mars.h" #include "declaration.h" #include "attrib.h" #include "expression.h" #include "scope.h" #include "mtype.h" #include "aggregate.h" #include "identifier.h" #include "id.h" #include "module.h" #if DMDV2 /********************************** * Determine if function is a builtin one that we can * evaluate at compile time. */ enum BUILTIN FuncDeclaration::isBuiltin() { static const char FeZe[] = "FNaNbeZe"; // pure nothrow real function(real) //printf("FuncDeclaration::isBuiltin() %s\n", toChars()); if (builtin == BUILTINunknown) { 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) builtin = BUILTINsin; else if (ident == Id::cos) builtin = BUILTINcos; else if (ident == Id::tan) builtin = BUILTINtan; else if (ident == Id::_sqrt) builtin = BUILTINsqrt; else if (ident == Id::fabs) 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; } } } } return builtin; } /************************************** * Evaluate builtin function. * Return result; NULL if cannot evaluate it. */ Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments) { assert(arguments && arguments->dim); Expression *arg0 = (Expression *)arguments->data[0]; Expression *e = NULL; switch (builtin) { case BUILTINsin: if (arg0->op == TOKfloat64) e = new RealExp(0, sinl(arg0->toReal()), arg0->type); break; case BUILTINcos: if (arg0->op == TOKfloat64) e = new RealExp(0, cosl(arg0->toReal()), arg0->type); break; case BUILTINtan: if (arg0->op == TOKfloat64) e = new RealExp(0, tanl(arg0->toReal()), arg0->type); break; case BUILTINsqrt: if (arg0->op == TOKfloat64) e = new RealExp(0, sqrtl(arg0->toReal()), arg0->type); break; case BUILTINfabs: if (arg0->op == TOKfloat64) e = new RealExp(0, fabsl(arg0->toReal()), arg0->type); break; } return e; } #endif