mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-09-24 14:20:18 +02:00
[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:
@@ -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");
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
*/
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
module nested4;
|
||||
|
||||
void func(void delegate() dg) {
|
||||
auto v = (){
|
||||
dg();
|
||||
};
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
func({});
|
||||
}
|
||||
+1
-1
@@ -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);}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
Reference in New Issue
Block a user