[svn r113] Added initial support for associative arrays (AAs).

Fixed some problems with the string runtime support functions.
Fixed initialization of array of structs.
Fixed slice assignment where LHS is slice but RHS is dynamic array.
Fixed problems with result of assignment expressions.
Fixed foreach problems with key type mismatches.
This commit is contained in:
Tomas Lindquist Olsen
2007-11-21 04:13:15 +01:00
parent a807cbfc91
commit d51e392b8d
25 changed files with 756 additions and 122 deletions
+9
View File
@@ -3,4 +3,13 @@ module aa1;
void main()
{
int[int] aai;
assert(aai is null);
aai[0] = 52;
assert(aai !is null);
int i = aai[0];
assert(i == 52);
aai[32] = 123;
int j = aai[32];
assert(i == 52);
assert(j == 123);
}
+12
View File
@@ -0,0 +1,12 @@
module aa2;
void main()
{
long[float] aa;
long* p = 2.0f in aa;
assert(!p);
aa[4f] = 23;
p = 4f in aa;
assert(p);
assert(*p == 23);
}
+24
View File
@@ -0,0 +1,24 @@
module aa3;
void main()
{
int[string] aa;
{aa["hello"] = 1;}
{int* p = "" in aa;}
aa[" worl"] = 2;
aa["d"] = 3;
aa["thisisgreat"] = 10;
int sum;
string cat;
{
foreach(k,v;aa)
{
printf("int[%.*s] = %d\n", k.length, k.ptr, v);
sum += v;
cat ~= k;
}
}
assert(sum == 16);
printf("cat = %.*s\n", cat.length, cat.ptr);
assert(cat.length == 22);
}
+20
View File
@@ -0,0 +1,20 @@
module aa4;
void main()
{
int[int] aa;
aa = addkey(aa,42,12);
int* p = haskey(aa,42);
assert(p && *p == 12);
}
int[int] addkey(int[int] aa, int key, int val)
{
aa[key] = val;
return aa;
}
int* haskey(int[int] aa, int key)
{
return key in aa;
}
+9
View File
@@ -0,0 +1,9 @@
module aa5;
void main()
{
int[int] aa;
aa[42] = 1;
int i = aa[42];
assert(i == 1);
}
+7
View File
@@ -0,0 +1,7 @@
module arrays14;
void main()
{
auto s = "hello world";
auto d = s.dup;
}
+13
View File
@@ -0,0 +1,13 @@
module typeinfo13;
void main()
{
float[long] aa;
auto ti = typeid(typeof(aa));
assert(ti.toString() == "float[long]");
assert(ti.next() is typeid(float));
assert(ti.tsize() == size_t.sizeof);
auto aati = cast(TypeInfo_AssociativeArray)ti;
assert(aati.value is typeid(float));
assert(aati.key is typeid(long));
}