Mercurial > projects > ldc
annotate tests/mini/funcptr.d @ 1650:40bd4a0d4870
Update to work with LLVM 2.7.
Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).
Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.
Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.
author | Tomas Lindquist Olsen |
---|---|
date | Wed, 19 May 2010 12:42:32 +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 } |