Mercurial > projects > ldc
annotate tests/mini/funcptr.d @ 715:30b42a283c8e
Removed TypeOpaque from DMD.
Changed runtime functions taking opaque[] to void[].
Implemented proper type painting, to avoid "resizing" array casts in runtime calls that previously took opaque[].
Implemented dynamic arrays as first class types, this implements proper ABI for these types on x86.
Added dwarf region end after call to assert function, fixes some problems with llvm not allowing this to be missing.
Reverted change to WithStatement from rev [704] it breaks MiniD, mini/with2.d needs to be fixed some other way...
Fixed tango bug 1339 in runtime, problem with _adReverseChar on invalid UTF-8.
Disabled .bc generation in the compiler runtime part, genobj.d triggers some llvm bug when using debug info. the .o seems to work fine.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 22 Oct 2008 14:55:33 +0200 |
parents | 1bb99290e03a |
children |
rev | line source |
---|---|
270
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
102
diff
changeset
|
1 extern(C) int printf(char*, ...); |
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
102
diff
changeset
|
2 |
1 | 3 int return_six() |
4 { | |
5 return 6; | |
6 } | |
7 | |
8 int add_int(int a, int b) | |
9 { | |
10 return a+b; | |
11 } | |
12 | |
13 int sub_int(int a, int b) | |
14 { | |
15 return a-b; | |
16 } | |
17 | |
18 alias int function(int,int) binfn_t; | |
19 | |
20 int binop_int(binfn_t op, int a, int b) | |
21 { | |
22 return op(a,b); | |
23 } | |
24 | |
25 binfn_t get_binop_int(char op) | |
26 { | |
27 binfn_t fn; | |
28 if (op == '+') | |
29 fn = &add_int; | |
30 else if (op == '-') | |
31 fn = &sub_int; | |
32 return fn; | |
33 } | |
34 | |
35 extern(C) float mul_float(float a, float b) | |
36 { | |
37 return a * b; | |
38 } | |
39 | |
40 void function_pointers() | |
41 { | |
42 int function() fn = &return_six; | |
43 assert(fn() == 6); | |
44 | |
45 binfn_t binfn = &add_int; | |
46 assert(binfn(4,1045) == 1049); | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
1
diff
changeset
|
47 |
1 | 48 assert(binop_int(binfn, 10,656) == 666); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
1
diff
changeset
|
49 |
1 | 50 binfn = get_binop_int('+'); |
51 assert(binop_int(binfn, 10,100) == 110); | |
52 binfn = get_binop_int('-'); | |
53 assert(binop_int(binfn, 10,100) == -90); | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
1
diff
changeset
|
54 |
1 | 55 { |
56 auto ffn = &mul_float; | |
57 float ftmp = mul_float(2.5,5); | |
58 assert(ftmp == 12.5); | |
59 assert(ftmp > 12.49 && ftmp < 12.51); | |
60 } | |
61 } | |
62 | |
63 void main() | |
64 { | |
65 printf("Function pointer test\n"); | |
66 function_pointers(); | |
67 printf(" SUCCESS\n"); | |
68 } |