mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-20 04:19:04 +00:00
cgo: implement Go arrays (constant arrays in C)
This commit is contained in:
committed by
Ron Evans
parent
684543b7f1
commit
536086988c
@@ -268,6 +268,16 @@ func (info *fileInfo) makeASTType(typ C.CXType) ast.Expr {
|
|||||||
Star: info.importCPos,
|
Star: info.importCPos,
|
||||||
X: info.makeASTType(C.clang_getPointeeType(typ)),
|
X: info.makeASTType(C.clang_getPointeeType(typ)),
|
||||||
}
|
}
|
||||||
|
case C.CXType_ConstantArray:
|
||||||
|
return &ast.ArrayType{
|
||||||
|
Lbrack: info.importCPos,
|
||||||
|
Len: &ast.BasicLit{
|
||||||
|
ValuePos: info.importCPos,
|
||||||
|
Kind: token.INT,
|
||||||
|
Value: strconv.FormatInt(int64(C.clang_getArraySize(typ)), 10),
|
||||||
|
},
|
||||||
|
Elt: info.makeASTType(C.clang_getElementType(typ)),
|
||||||
|
}
|
||||||
case C.CXType_FunctionProto:
|
case C.CXType_FunctionProto:
|
||||||
// Be compatible with gc, which uses the *[0]byte type for function
|
// Be compatible with gc, which uses the *[0]byte type for function
|
||||||
// pointer types.
|
// pointer types.
|
||||||
|
|||||||
Vendored
+1
@@ -9,6 +9,7 @@ _Complex float globalComplexFloat = 4.1+3.3i;
|
|||||||
_Complex double globalComplexDouble = 4.2+3.4i;
|
_Complex double globalComplexDouble = 4.2+3.4i;
|
||||||
_Complex double globalComplexLongDouble = 4.3+3.5i;
|
_Complex double globalComplexLongDouble = 4.3+3.5i;
|
||||||
collection_t globalStruct = {256, -123456, 3.14};
|
collection_t globalStruct = {256, -123456, 3.14};
|
||||||
|
short globalArray[3] = {5, 6, 7};
|
||||||
|
|
||||||
int fortytwo() {
|
int fortytwo() {
|
||||||
return 42;
|
return 42;
|
||||||
|
|||||||
Vendored
+2
@@ -37,6 +37,8 @@ func main() {
|
|||||||
println("complex double:", C.globalComplexDouble)
|
println("complex double:", C.globalComplexDouble)
|
||||||
println("complex long double:", C.globalComplexLongDouble)
|
println("complex long double:", C.globalComplexLongDouble)
|
||||||
println("struct:", C.globalStruct.s, C.globalStruct.l, C.globalStruct.f)
|
println("struct:", C.globalStruct.s, C.globalStruct.l, C.globalStruct.f)
|
||||||
|
var _ [3]C.short = C.globalArray
|
||||||
|
println("array:", C.globalArray[0], C.globalArray[1], C.globalArray[2])
|
||||||
}
|
}
|
||||||
|
|
||||||
//export mul
|
//export mul
|
||||||
|
|||||||
Vendored
+1
@@ -21,6 +21,7 @@ extern _Complex float globalComplexFloat;
|
|||||||
extern _Complex double globalComplexDouble;
|
extern _Complex double globalComplexDouble;
|
||||||
extern _Complex double globalComplexLongDouble;
|
extern _Complex double globalComplexLongDouble;
|
||||||
extern collection_t globalStruct;
|
extern collection_t globalStruct;
|
||||||
|
extern short globalArray[3];
|
||||||
|
|
||||||
// test duplicate definitions
|
// test duplicate definitions
|
||||||
int add(int a, int b);
|
int add(int a, int b);
|
||||||
|
|||||||
Reference in New Issue
Block a user