2024-09-15 20:21:16 +08:00
package main
2024-09-14 18:46:44 +08:00
2024-09-15 12:05:27 +08:00
import "errors"
type Base struct {
name string
2024-09-14 18:46:44 +08:00
}
2024-09-15 12:05:27 +08:00
type E struct {
2024-09-15 20:21:16 +08:00
// Base
2024-09-15 12:05:27 +08:00
i int
}
type StructWithAllTypeFields struct {
2024-09-18 18:10:45 +08:00
i8 int8
i16 int16
i32 int32
i64 int64
i int
u8 uint8
u16 uint16
u32 uint32
u64 uint64
u uint
f32 float32
f64 float64
b bool
c64 complex64
c128 complex128
slice [ ] int
arr [ 3 ] int
arr2 [ 3 ] E
s string
e E
pf * StructWithAllTypeFields // resursive
pi * int
2024-09-18 18:26:36 +08:00
intr Interface
2024-09-18 19:45:11 +08:00
m map [ string ] uint64
2024-09-18 19:52:01 +08:00
c chan int
err error
2024-09-18 20:31:45 +08:00
fn func ( string ) ( int , error )
pad1 int
pad2 int
2024-09-14 18:46:44 +08:00
}
2024-09-15 12:05:27 +08:00
type Interface interface {
Foo ( a [ ] int , b string ) int
2024-09-14 18:46:44 +08:00
}
2024-09-15 12:05:27 +08:00
type Struct struct { }
func ( s * Struct ) Foo ( a [ ] int , b string ) int {
2024-09-14 18:46:44 +08:00
return 1
}
2024-09-15 12:05:27 +08:00
func FuncWithAllTypeStructParam ( s StructWithAllTypeFields ) {
println ( & s )
2024-09-18 16:42:47 +08:00
println ( len ( s . s ) )
2024-09-14 18:46:44 +08:00
}
2024-09-15 12:05:27 +08:00
// Params is a function with all types of parameters.
func FuncWithAllTypeParams (
i8 int8 ,
i16 int16 ,
i32 int32 ,
i64 int64 ,
i int ,
u8 uint8 ,
u16 uint16 ,
u32 uint32 ,
u64 uint64 ,
u uint ,
f32 float32 ,
f64 float64 ,
b bool ,
2024-09-15 20:54:10 +08:00
c64 complex64 ,
c128 complex128 ,
2024-09-18 18:10:45 +08:00
slice [ ] int ,
arr [ 3 ] int ,
arr2 [ 3 ] E ,
2024-09-18 16:42:47 +08:00
s string ,
2024-09-15 12:05:27 +08:00
e E ,
f StructWithAllTypeFields ,
2024-09-18 16:42:47 +08:00
pf * StructWithAllTypeFields ,
pi * int ,
2024-09-18 18:26:36 +08:00
intr Interface ,
2024-09-18 19:45:11 +08:00
m map [ string ] uint64 ,
2024-09-18 19:52:01 +08:00
c chan int ,
2024-09-18 18:26:36 +08:00
err error ,
2024-09-18 20:31:45 +08:00
fn func ( string ) ( int , error ) ,
2024-09-15 12:05:27 +08:00
) ( int , error ) {
println (
2024-09-15 20:21:16 +08:00
i8 , i16 , i32 , i64 , i , u8 , u16 , u32 , u64 , u ,
f32 , f64 , b ,
2024-09-15 20:54:10 +08:00
c64 , c128 ,
2024-09-18 18:10:45 +08:00
slice , arr [ 0 : ] ,
2024-09-18 16:42:47 +08:00
s ,
2024-09-18 18:26:36 +08:00
& e ,
2024-09-18 19:45:11 +08:00
& f , pf , pi , intr , m ,
2024-09-18 19:52:01 +08:00
c ,
2024-09-18 18:26:36 +08:00
err ,
2024-09-18 20:31:45 +08:00
fn ,
2024-09-15 12:05:27 +08:00
)
2024-09-19 14:26:18 +08:00
// Expected:
// all variables: i8 i16 i32 i64 i u8 u16 u32 u64 u f32 f64 b c64 c128 slice arr arr2 s e f pf pi intr m c err fn globalInt globalStruct globalStructPtr
// i8: '\x01'
// i16: 2
// i32: 3
// i64: 4
// i: 5
// u8: '\x06'
// u16: 7
// u32: 8
// u64: 9
// u: 10
// f32: 11
// f64: 12
// b: true
// c64: complex64(real = 13, imag = 14)
// c128: complex128(real = 15, imag = 16)
// slice: []int[21, 22, 23]
2024-09-19 21:06:45 +08:00
// arr: [3]int[24, 25, 26]
// arr2: [3]github.com/goplus/llgo/cl/_testdata/debug.E[github.com/goplus/llgo/cl/_testdata/debug.E(i = 27), github.com/goplus/llgo/cl/_testdata/debug.E(i = 28), github.com/goplus/llgo/cl/_testdata/debug.E(i = 29)]
2024-09-19 14:26:18 +08:00
// s: hello
2024-09-19 21:06:45 +08:00
// e: github.com/goplus/llgo/cl/_testdata/debug.E(i = 30)
2024-09-19 14:26:18 +08:00
return 1 , errors . New ( "some error" )
2024-09-14 18:46:44 +08:00
}
2024-09-15 20:21:16 +08:00
func main ( ) {
i := 100
s := StructWithAllTypeFields {
2024-09-18 18:10:45 +08:00
i8 : 1 ,
i16 : 2 ,
i32 : 3 ,
i64 : 4 ,
i : 5 ,
u8 : 6 ,
u16 : 7 ,
u32 : 8 ,
u64 : 9 ,
u : 10 ,
f32 : 11 ,
f64 : 12 ,
b : true ,
c64 : 13 + 14i ,
c128 : 15 + 16i ,
slice : [ ] int { 21 , 22 , 23 } ,
arr : [ 3 ] int { 24 , 25 , 26 } ,
arr2 : [ 3 ] E { { i : 27 } , { i : 28 } , { i : 29 } } ,
s : "hello" ,
e : E { i : 30 } ,
pf : & StructWithAllTypeFields { } ,
pi : & i ,
2024-09-18 18:26:36 +08:00
intr : & Struct { } ,
2024-09-18 19:45:11 +08:00
m : map [ string ] uint64 { "a" : 31 , "b" : 32 } ,
2024-09-18 19:52:01 +08:00
c : make ( chan int ) ,
err : errors . New ( "Test error" ) ,
2024-09-18 20:31:45 +08:00
fn : func ( s string ) ( int , error ) {
println ( "fn:" , s )
i = 201
return 1 , errors . New ( "fn error" )
} ,
pad1 : 100 ,
pad2 : 200 ,
2024-09-15 20:21:16 +08:00
}
2024-09-18 22:05:41 +08:00
globalStructPtr = & s
globalStruct = s
println ( "globalInt:" , globalInt )
2024-09-15 20:21:16 +08:00
println ( "s:" , & s )
FuncWithAllTypeStructParam ( s )
println ( "called function with struct" )
i , err := FuncWithAllTypeParams (
s . i8 , s . i16 , s . i32 , s . i64 , s . i , s . u8 , s . u16 , s . u32 , s . u64 , s . u ,
s . f32 , s . f64 , s . b ,
2024-09-15 20:54:10 +08:00
s . c64 , s . c128 ,
2024-09-18 18:10:45 +08:00
s . slice , s . arr , s . arr2 ,
2024-09-18 16:42:47 +08:00
s . s ,
2024-09-15 20:21:16 +08:00
s . e , s ,
2024-09-18 16:42:47 +08:00
s . pf , s . pi ,
2024-09-18 18:26:36 +08:00
s . intr ,
2024-09-18 19:45:11 +08:00
s . m ,
2024-09-18 19:52:01 +08:00
s . c ,
2024-09-18 18:26:36 +08:00
s . err ,
2024-09-18 20:31:45 +08:00
s . fn ,
2024-09-15 20:21:16 +08:00
)
println ( i , err )
println ( "called function with types" )
2024-09-18 22:05:41 +08:00
println ( globalStructPtr )
println ( & globalStruct )
2024-09-19 14:26:18 +08:00
// Expected:
// all variables: globalInt globalStruct globalStructPtr s i err
// s.i8: '\x01'
// s.i16: 2
2024-09-15 20:21:16 +08:00
println ( "done" )
2024-09-19 14:26:18 +08:00
println ( "" )
2024-09-15 20:21:16 +08:00
}
2024-09-18 22:05:41 +08:00
var globalInt int = 301
var globalStruct StructWithAllTypeFields
var globalStructPtr * StructWithAllTypeFields