[svn r77] Fixed foreach on slice.

Fixed some nested function problems when accessing outer function parameters.
Major changes to handling of structs.
Initial support for unions.
Probably more...
This commit is contained in:
Tomas Lindquist Olsen
2007-10-31 03:11:32 +01:00
parent 4230f2ef11
commit 9804fe0fa3
23 changed files with 562 additions and 283 deletions

10
test/bug41.d Normal file
View File

@@ -0,0 +1,10 @@
module bug41;
void main()
{
char[] a = "hello world";
char* ap = a.ptr;
size_t i = 5;
char[] b = ap[0..i];
assert(b == "hello");
}

View File

@@ -1,9 +1,8 @@
module d;
/*
void main()
{
int delegate() dg;
int i = dg();
struct S
{
@@ -19,17 +18,19 @@ void main()
S s;
auto dg2 = &s.func;
i = dg2();
int i = dg2();
assert(i == 42);
i = f(dg2, 1);
assert(i == 43);
}
int f(int delegate() dg, int i)
{
return dg() + i;
}
*/
/*
struct S
{
int i;
@@ -46,3 +47,4 @@ void main()
{
auto dg = &s.square;
}
*/

12
test/foreach7.d Normal file
View File

@@ -0,0 +1,12 @@
module foreach7;
void main()
{
int[4] a = [1,2,3,4];
int i;
foreach(v; a[0..3])
{
i += v;
}
assert(i == 6);
}

12
test/nested4.d Normal file
View File

@@ -0,0 +1,12 @@
module nested4;
void func(void delegate() dg) {
auto v = (){
dg();
};
}
void main()
{
func({});
}

View File

@@ -22,5 +22,5 @@ void main()
s.t.b = 4;
s.t.u = U.init;
s.t.u.c = 5;
{assert(s.t.u.c == 5);}
//{assert(s.t.u.c == 5);}
}

15
test/union1.d Normal file
View File

@@ -0,0 +1,15 @@
module union1;
pragma(LLVM_internal, "notypeinfo")
union U
{
float f;
int i;
}
void main()
{
float f = 2;
U u = U(f);
assert(u.i == *cast(int*)&f);
}

17
test/union2.d Normal file
View File

@@ -0,0 +1,17 @@
module union2;
pragma(LLVM_internal, "notypeinfo")
union U
{
float f;
long l;
}
U u;
void main()
{
assert(u.f !<>= 0);
uint* p = 1 + cast(uint*)&u.l;
assert(*p == 0);
}

14
test/union3.d Normal file
View File

@@ -0,0 +1,14 @@
module union3;
pragma(LLVM_internal, "notypeinfo")
union vec3
{
struct { float x,y,z; }
float[3] xyz;
}
void main()
{
vec3 v;
assert(&v.y is &v.xyz[1]);
}