aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-02-08 19:56:43 +0100
committerRon Evans <[email protected]>2019-02-18 17:17:56 +0100
commitda345e8723eac7956a4895d6f13890d9bd0b2aeb (patch)
treeb03230df3959be5480c230830de68de57558ffd3 /testdata
parentfab38a07493bd4f4030cdef2356afc316d73f509 (diff)
downloadtinygo-da345e8723eac7956a4895d6f13890d9bd0b2aeb.tar.gz
tinygo-da345e8723eac7956a4895d6f13890d9bd0b2aeb.zip
cgo: implement bool/float/complex types
Diffstat (limited to 'testdata')
-rw-r--r--testdata/cgo/main.c7
-rw-r--r--testdata/cgo/main.go8
-rw-r--r--testdata/cgo/main.h11
-rw-r--r--testdata/cgo/out.txt6
4 files changed, 31 insertions, 1 deletions
diff --git a/testdata/cgo/main.c b/testdata/cgo/main.c
index 2f3269ea0..b4ac14115 100644
--- a/testdata/cgo/main.c
+++ b/testdata/cgo/main.c
@@ -1,6 +1,13 @@
#include "main.h"
int global = 3;
+_Bool globalBool = 1;
+_Bool globalBool2 = 10; // test narrowing
+float globalFloat = 3.1;
+double globalDouble = 3.2;
+_Complex float globalComplexFloat = 4.1+3.3i;
+_Complex double globalComplexDouble = 4.2+3.4i;
+_Complex double globalComplexLongDouble = 4.3+3.5i;
int fortytwo() {
return 42;
diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go
index 0733d226e..261f1b5fe 100644
--- a/testdata/cgo/main.go
+++ b/testdata/cgo/main.go
@@ -28,6 +28,14 @@ func main() {
println("callback 1:", C.doCallback(20, 30, cb))
cb = C.binop_t(C.mul)
println("callback 2:", C.doCallback(20, 30, cb))
+
+ // more globals
+ println("bool:", C.globalBool, C.globalBool2 == true)
+ println("float:", C.globalFloat)
+ println("double:", C.globalDouble)
+ println("complex float:", C.globalComplexFloat)
+ println("complex double:", C.globalComplexDouble)
+ println("complex long double:", C.globalComplexLongDouble)
}
//export mul
diff --git a/testdata/cgo/main.h b/testdata/cgo/main.h
index be529d4fb..39a76f4f8 100644
--- a/testdata/cgo/main.h
+++ b/testdata/cgo/main.h
@@ -3,9 +3,18 @@ int add(int a, int b);
typedef int (*binop_t) (int, int);
int doCallback(int a, int b, binop_t cb);
typedef int * intPointer;
-extern int global;
void store(int value, int *ptr);
+// test globals
+extern int global;
+extern _Bool globalBool;
+extern _Bool globalBool2;
+extern float globalFloat;
+extern double globalDouble;
+extern _Complex float globalComplexFloat;
+extern _Complex double globalComplexDouble;
+extern _Complex double globalComplexLongDouble;
+
// test duplicate definitions
int add(int a, int b);
extern int global;
diff --git a/testdata/cgo/out.txt b/testdata/cgo/out.txt
index 8d6845ee7..79f8cc63f 100644
--- a/testdata/cgo/out.txt
+++ b/testdata/cgo/out.txt
@@ -8,3 +8,9 @@ global: 3
25: 25
callback 1: 50
callback 2: 600
+bool: true true
+float: +3.100000e+000
+double: +3.200000e+000
+complex float: (+4.100000e+000+3.300000e+000i)
+complex double: (+4.200000e+000+3.400000e+000i)
+complex long double: (+4.300000e+000+3.500000e+000i)