changeset 22:a6360e68134a trunk

[svn r26] * Fixed templates defining a constant value * Fixed problem with slice-slice copy assignment if a side was a temporary slice
author lindquist
date Thu, 04 Oct 2007 07:35:02 +0200
parents 8d45266bbabe
children 77e3d1ddae3f
files gen/arrays.c gen/toobj.c lphobos/std/stdio.d test/globals2.d test/stdiotest.d
diffstat 5 files changed, 40 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/gen/arrays.c	Thu Oct 04 07:01:15 2007 +0200
+++ b/gen/arrays.c	Thu Oct 04 07:35:02 2007 +0200
@@ -308,7 +308,21 @@
     assert(e->mem);
     const llvm::Type* t = e->mem->getType()->getContainedType(0);
     llvm::Value* ret = 0;
-    if (llvm::isa<llvm::ArrayType>(t)) {
+    if (e->arg != 0) {
+        // this means it's a real slice
+        ret = e->mem;
+
+        size_t elembsz = gTargetData->getTypeSize(ret->getType());
+        llvm::ConstantInt* elemsz = llvm::ConstantInt::get(LLVM_DtoSize_t(), elembsz, false);
+
+        if (llvm::isa<llvm::ConstantInt>(e->arg)) {
+            sz = llvm::ConstantExpr::getMul(elemsz, llvm::cast<llvm::Constant>(e->arg));
+        }
+        else {
+            sz = llvm::BinaryOperator::createMul(elemsz,e->arg,"tmp",gIR->scopebb());
+        }
+    }
+    else if (llvm::isa<llvm::ArrayType>(t)) {
         ret = LLVM_DtoGEPi(e->mem, 0, 0, "tmp", gIR->scopebb());
 
         size_t elembsz = gTargetData->getTypeSize(ret->getType()->getContainedType(0));
--- a/gen/toobj.c	Thu Oct 04 07:01:15 2007 +0200
+++ b/gen/toobj.c	Thu Oct 04 07:35:02 2007 +0200
@@ -497,7 +497,7 @@
     }
 
     // global variable or magic
-    if (!parent || parent->isModule())
+    if (isDataseg())
     {
         bool _isconst = isConst();
         if (!_isconst)
--- a/lphobos/std/stdio.d	Thu Oct 04 07:01:15 2007 +0200
+++ b/lphobos/std/stdio.d	Thu Oct 04 07:35:02 2007 +0200
@@ -1,13 +1,15 @@
 module std.stdio;
 
+import std.traits;
+
 void _writef(T)(T t) {
   static if(is(T: Object)) _writef(t.toString()); else
-  static if(is(T==char)) _writef("%c", t); else
+  static if(is(T==char)) printf("%c", t); else
   static if(is(T: char[])) printf("%.*s", t.length, t.ptr); else
   static if(isArray!(T)) {
     _writef('[');
     if (t.length) _writef(t[0]);
-    for (int i=1; i<elem.length; ++i) { _writef(','); _writef(t[i]); }
+    for (int i=1; i<t.lengthi; ++i) { _writef(','); _writef(t[i]); }
     _writef(']');
   } else
   static if(is(T==int)) printf("%i", t); else
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/globals2.d	Thu Oct 04 07:35:02 2007 +0200
@@ -0,0 +1,12 @@
+module globals2;
+
+template Bool(bool b)
+{
+    const bool Bool = b;
+}
+
+void main()
+{
+    assert(Bool!(true));
+    assert(!Bool!(false));
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/stdiotest.d	Thu Oct 04 07:35:02 2007 +0200
@@ -0,0 +1,8 @@
+module stdiotest;
+
+import std.stdio;
+
+void main()
+{
+    writefln("hello world",42,'x');
+}