mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-28 09:33:27 +01:00
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
Added support for array .sort and .reverse properties. Fixed some bugs with pointer arithmetic. Disabled some DMD AST optimizations that was messing things up, destroying valuable information. Added a KDevelop project file, this is what I use for coding LLVMDC now :) Other minor stuff.
This commit is contained in:
15
test/alloca1.d
Normal file
15
test/alloca1.d
Normal file
@@ -0,0 +1,15 @@
|
||||
module alloca1;
|
||||
|
||||
pragma(LLVM_internal, "alloca")
|
||||
void* alloca(uint);
|
||||
|
||||
void main()
|
||||
{
|
||||
int n = 16;
|
||||
int* p = cast(int*)alloca(n*int.sizeof);
|
||||
int[] a = p[0..n];
|
||||
a[] = 0;
|
||||
foreach(i,v; a) {
|
||||
printf("a[%2d] = %d\n", i, v);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
module arrays5;
|
||||
//import std.stdio;
|
||||
void main()
|
||||
{
|
||||
auto arr = new float[5];
|
||||
arr[4] = 1f;
|
||||
//writefln(arr);
|
||||
assert(arr[0] !<>= 0f);
|
||||
assert(arr[1] !<>= 0f);
|
||||
assert(arr[2] !<>= 0f);
|
||||
assert(arr[3] !<>= 0f);
|
||||
assert(arr[4] == 1f);
|
||||
{arr[4] = 1f;}
|
||||
{assert(arr[0] !<>= 0f);}
|
||||
{assert(arr[1] !<>= 0f);}
|
||||
{assert(arr[2] !<>= 0f);}
|
||||
{assert(arr[3] !<>= 0f);}
|
||||
{assert(arr[4] == 1f);}
|
||||
}
|
||||
|
||||
|
||||
10
test/bug57.d
Normal file
10
test/bug57.d
Normal file
@@ -0,0 +1,10 @@
|
||||
import std.stdio;
|
||||
class Foo {}
|
||||
void func3()
|
||||
{
|
||||
Foo[1] test=[new Foo];
|
||||
writefln(test);
|
||||
}
|
||||
void main() {
|
||||
func3();
|
||||
}
|
||||
10
test/bug58.d
Normal file
10
test/bug58.d
Normal file
@@ -0,0 +1,10 @@
|
||||
module bug58;
|
||||
import std.stdio;
|
||||
void main()
|
||||
{
|
||||
int[16] arr = [1,16,2,15,3,14,4,13,5,12,6,11,7,10,8,9];
|
||||
writefln("arr = ",arr);
|
||||
arr.sort;
|
||||
writefln("arr.sort = ",arr);
|
||||
assert(arr == [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
|
||||
}
|
||||
20
test/bug59.d
Normal file
20
test/bug59.d
Normal file
@@ -0,0 +1,20 @@
|
||||
module bug59;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[2] a = 0;
|
||||
//func(a);
|
||||
a[0] = 1;
|
||||
int i = a[0];
|
||||
int* p = &a[0];
|
||||
}
|
||||
|
||||
void func(int[2] a)
|
||||
{
|
||||
int* p = cast(int*)a;
|
||||
}
|
||||
|
||||
void func2(int[4] a)
|
||||
{
|
||||
int* p = 3+cast(int*)a;
|
||||
}
|
||||
16
test/bug60.d
Normal file
16
test/bug60.d
Normal file
@@ -0,0 +1,16 @@
|
||||
module bug60;
|
||||
void func(T...)(T t)
|
||||
{
|
||||
foreach(v;t) {
|
||||
if (v.length) {
|
||||
foreach(i;v) {
|
||||
printf("%d\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void main()
|
||||
{
|
||||
auto a = [1,2,3];
|
||||
func(a);
|
||||
}
|
||||
26
test/bug61.d
Normal file
26
test/bug61.d
Normal file
@@ -0,0 +1,26 @@
|
||||
module bug61;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[3] a = [42,4,141414];
|
||||
printf("empty:\n");
|
||||
foreach(v; a[3..$]) {
|
||||
printf("int = %d\n", v);
|
||||
}
|
||||
printf("one element:\n");
|
||||
foreach(v; a[2..$]) {
|
||||
printf("int = %d\n", v);
|
||||
}
|
||||
printf("all elements:\n");
|
||||
foreach(v; a) {
|
||||
printf("int = %d\n", v);
|
||||
}
|
||||
printf("empty reversed:\n");
|
||||
foreach_reverse(v; a[3..$]) {
|
||||
printf("int = %d\n", v);
|
||||
}
|
||||
printf("all elements reversed:\n");
|
||||
foreach_reverse(v; a) {
|
||||
printf("int = %d\n", v);
|
||||
}
|
||||
}
|
||||
12
test/bug62.d
Normal file
12
test/bug62.d
Normal file
@@ -0,0 +1,12 @@
|
||||
module bug62;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[] arr = [1,2,5,7,9];
|
||||
int i = 0;
|
||||
foreach(v; arr) {
|
||||
i += v;
|
||||
}
|
||||
printf("sum = %d\n", i);
|
||||
assert(i == 24);
|
||||
}
|
||||
10
test/bug64.d
Normal file
10
test/bug64.d
Normal file
@@ -0,0 +1,10 @@
|
||||
module bug64;
|
||||
|
||||
void main()
|
||||
{
|
||||
float f;
|
||||
float* p = &f;
|
||||
float* end1 = p+1;
|
||||
float* end2 = 1+p;
|
||||
assert(end1 is end2);
|
||||
}
|
||||
27
test/fail2.d
Normal file
27
test/fail2.d
Normal file
@@ -0,0 +1,27 @@
|
||||
module fail2;
|
||||
|
||||
void a()
|
||||
{
|
||||
b();
|
||||
}
|
||||
|
||||
void b()
|
||||
{
|
||||
c();
|
||||
}
|
||||
|
||||
void c()
|
||||
{
|
||||
d();
|
||||
}
|
||||
|
||||
void d()
|
||||
{
|
||||
int* ip;
|
||||
int i = *ip;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
a();
|
||||
}
|
||||
@@ -4,7 +4,11 @@ void main()
|
||||
{
|
||||
int[16][16] a;
|
||||
a[10][13] = 42;
|
||||
assert(a[0][0] == 0);
|
||||
assert(a[10][13] == 42);
|
||||
{assert(*((cast(int*)a)+10*16+13) == 42);}
|
||||
//assert(a[0][0] == 0);
|
||||
//assert(a[10][13] == 42);
|
||||
{
|
||||
int* l = cast(int*)a;
|
||||
l += 10*16+13;
|
||||
assert(*l == 42);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,8 @@ double ray_trace(ref Vec light, ref Ray ray, Scene s) {
|
||||
Scene create(int level, ref Vec c, double r) {
|
||||
auto s = new Sphere(c, r);
|
||||
if (level == 1) return s;
|
||||
Scene[] children=[s];
|
||||
Scene[] children;
|
||||
children ~= s;
|
||||
double rn = 3*r/sqrt(12.0);
|
||||
for (int dz=-1; dz<=1; dz+=2)
|
||||
for (int dx=-1; dx<=1; dx+=2)
|
||||
|
||||
8
test/sync1.d
Normal file
8
test/sync1.d
Normal file
@@ -0,0 +1,8 @@
|
||||
module sync1;
|
||||
|
||||
void main()
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
synchronized j = i;
|
||||
}
|
||||
@@ -12,6 +12,8 @@ U u;
|
||||
void main()
|
||||
{
|
||||
assert(u.f !<>= 0);
|
||||
uint* p = 1 + cast(uint*)&u.l;
|
||||
assert(*p == 0);
|
||||
{
|
||||
uint* p = 1 + cast(uint*)&u;
|
||||
{assert(*p == 0);}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user