diff gen/toir.cpp @ 127:facc562f5674 trunk

[svn r131] Fixed #11 All associative array properties now work as they should. Fixed problems with some cases of array.length and array.ptr. Fixed some problems with array properties. Fixed 'in' contracts.
author lindquist
date Fri, 30 Nov 2007 12:56:52 +0100
parents c42d245468ea
children 8096ba7082db
line wrap: on
line diff
--- a/gen/toir.cpp	Wed Nov 28 05:04:38 2007 +0100
+++ b/gen/toir.cpp	Fri Nov 30 12:56:52 2007 +0100
@@ -904,7 +904,7 @@
         Logger::cout() << "what are we calling? : " << *funcval << '\n';
     }
     assert(llfnty);
-    //Logger::cout() << "Function LLVM type: " << *llfnty << '\n';
+    Logger::cout() << "Function LLVM type: " << *llfnty << '\n';
 
     // argument handling
     llvm::FunctionType::param_iterator argiter = llfnty->param_begin();
@@ -2572,6 +2572,19 @@
     return DtoAAIn(type, aa, key);
 }
 
+DValue* RemoveExp::toElem(IRState* p)
+{
+    Logger::print("RemoveExp::toElem: %s\n", toChars());
+    LOG_SCOPE;
+
+    DValue* aa = e1->toElem(p);
+    DValue* key = e2->toElem(p);
+
+    DtoAARemove(aa, key);
+
+    return NULL; // does not produce anything useful
+}
+
 //////////////////////////////////////////////////////////////////////////////////////////
 
 DValue* AssocArrayLiteralExp::toElem(IRState* p)
@@ -2583,6 +2596,20 @@
     assert(values);
     assert(keys->dim == values->dim);
 
+    Type* aatype = DtoDType(type);
+    Type* vtype = aatype->next;
+
+    DValue* aa;
+    if (p->topexp() && p->topexp()->e2 == this)
+    {
+        aa = p->topexp()->v;
+    }
+    else
+    {
+        llvm::Value* tmp = new llvm::AllocaInst(DtoType(type),"aaliteral",p->topallocapoint());
+        aa = new DVarValue(type, tmp, true);
+    }
+
     const size_t n = keys->dim;
     for (size_t i=0; i<n; ++i)
     {
@@ -2590,9 +2617,17 @@
         Expression* eval = (Expression*)values->data[i];
 
         Logger::println("(%u) aa[%s] = %s", i, ekey->toChars(), eval->toChars());
+
+        // index
+        DValue* key = ekey->toElem(p);
+        DValue* mem = DtoAAIndex(vtype, aa, key);
+
+        // store
+        DValue* val = eval->toElem(p);
+        DtoAssign(mem, val);
     }
 
-    assert(0);
+    return aa;
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -2666,7 +2701,7 @@
 //STUB(CommaExp);
 //STUB(ArrayLengthExp);
 //STUB(HaltExp);
-STUB(RemoveExp);
+//STUB(RemoveExp);
 //STUB(ArrayLiteralExp);
 //STUB(AssocArrayLiteralExp);
 //STUB(StructLiteralExp);