Skip to content

Commit a6a3c09

Browse files
committed
ssa: closure use specific struct field name { $f ftype, $data unsafe.pointer }
1 parent 070d64f commit a6a3c09

File tree

14 files changed

+238
-190
lines changed

14 files changed

+238
-190
lines changed

cl/_testgo/invoke/out.ll

+7-10
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ source_filename = "main"
5959
@_llgo_main.T6 = linkonce global ptr null, align 8
6060
@19 = private unnamed_addr constant [2 x i8] c"T6", align 1
6161
@_llgo_Pointer = linkonce global ptr null, align 8
62-
@"main.struct$ShRx0rnZQIkym8zpNxljLHWZbDzaCdzDkVBTe78YZMw" = linkonce global ptr null, align 8
63-
@20 = private unnamed_addr constant [1 x i8] c"f", align 1
64-
@21 = private unnamed_addr constant [4 x i8] c"data", align 1
62+
@"main.struct$TWlEC03isGYe2Nyy2HYnOBsOYR1lIx43oIUpIyqvm4s" = linkonce global ptr null, align 8
63+
@20 = private unnamed_addr constant [2 x i8] c"$f", align 1
64+
@21 = private unnamed_addr constant [5 x i8] c"$data", align 1
6565
@"*_llgo_main.T6" = linkonce global ptr null, align 8
6666
@"_llgo_iface$jwmSdgh1zvY_TDIgLzCkvkbiyrdwl9N806DH0JGcyMI" = linkonce global ptr null, align 8
6767
@22 = private unnamed_addr constant [5 x i8] c"world", align 1
@@ -337,7 +337,6 @@ _llgo_0:
337337
call void @main.invoke(%"github.com/goplus/llgo/internal/runtime.iface" %81)
338338
%82 = load %main.T6, ptr %11, align 8
339339
%83 = load ptr, ptr @_llgo_main.T6, align 8
340-
call void @"github.com/goplus/llgo/internal/runtime.SetClosure"(ptr %83)
341340
%84 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16)
342341
store %main.T6 %82, ptr %84, align 8
343342
%85 = load ptr, ptr @"_llgo_iface$uRUteI7wmSy7y7ODhGzk0FdDaxGKMhVSSu6HZEv9aa0", align 8
@@ -935,9 +934,9 @@ _llgo_56: ; preds = %_llgo_55, %_llgo_54
935934
%231 = insertvalue %"github.com/goplus/llgo/internal/runtime.Slice" %230, i64 1, 1
936935
%232 = insertvalue %"github.com/goplus/llgo/internal/runtime.Slice" %231, i64 1, 2
937936
%233 = call ptr @"github.com/goplus/llgo/internal/runtime.Func"(%"github.com/goplus/llgo/internal/runtime.Slice" %227, %"github.com/goplus/llgo/internal/runtime.Slice" %232, i1 false)
938-
%234 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @20, i64 1 }, ptr %233, i64 0, %"github.com/goplus/llgo/internal/runtime.String" zeroinitializer, i1 false)
937+
%234 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @20, i64 2 }, ptr %233, i64 0, %"github.com/goplus/llgo/internal/runtime.String" zeroinitializer, i1 false)
939938
%235 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 58)
940-
%236 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @21, i64 4 }, ptr %235, i64 8, %"github.com/goplus/llgo/internal/runtime.String" zeroinitializer, i1 false)
939+
%236 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @21, i64 5 }, ptr %235, i64 8, %"github.com/goplus/llgo/internal/runtime.String" zeroinitializer, i1 false)
941940
%237 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 112)
942941
%238 = getelementptr %"github.com/goplus/llgo/internal/abi.StructField", ptr %237, i64 0
943942
store %"github.com/goplus/llgo/internal/abi.StructField" %234, ptr %238, align 8
@@ -947,8 +946,8 @@ _llgo_56: ; preds = %_llgo_55, %_llgo_54
947946
%241 = insertvalue %"github.com/goplus/llgo/internal/runtime.Slice" %240, i64 2, 1
948947
%242 = insertvalue %"github.com/goplus/llgo/internal/runtime.Slice" %241, i64 2, 2
949948
%243 = call ptr @"github.com/goplus/llgo/internal/runtime.Struct"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @8, i64 4 }, i64 16, %"github.com/goplus/llgo/internal/runtime.Slice" %242)
950-
store ptr %243, ptr @"main.struct$ShRx0rnZQIkym8zpNxljLHWZbDzaCdzDkVBTe78YZMw", align 8
951-
%244 = load ptr, ptr @"main.struct$ShRx0rnZQIkym8zpNxljLHWZbDzaCdzDkVBTe78YZMw", align 8
949+
store ptr %243, ptr @"main.struct$TWlEC03isGYe2Nyy2HYnOBsOYR1lIx43oIUpIyqvm4s", align 8
950+
%244 = load ptr, ptr @"main.struct$TWlEC03isGYe2Nyy2HYnOBsOYR1lIx43oIUpIyqvm4s", align 8
952951
br i1 %217, label %_llgo_57, label %_llgo_58
953952

954953
_llgo_57: ; preds = %_llgo_56
@@ -1075,8 +1074,6 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.PointerTo"(ptr)
10751074

10761075
declare ptr @"github.com/goplus/llgo/internal/runtime.ArrayOf"(i64, ptr)
10771076

1078-
declare void @"github.com/goplus/llgo/internal/runtime.SetClosure"(ptr)
1079-
10801077
declare ptr @"github.com/goplus/llgo/internal/runtime.IfaceType"(%"github.com/goplus/llgo/internal/runtime.iface")
10811078

10821079
declare void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/goplus/llgo/internal/runtime.iface")

cl/_testgo/reflect/in.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,11 @@ func callMethod() {
9393
println("method", fn.Kind(), fn.Type().String())
9494
r := fn.Call([]reflect.Value{reflect.ValueOf(100)})
9595
println(r[0].Int())
96-
//TODO type assert
97-
// ifn, ok := fn.Interface().(func(int) int)
98-
// if !ok {
99-
// panic("error")
100-
// }
101-
// ifn(1)
96+
ifn, ok := fn.Interface().(func(int) int)
97+
if !ok {
98+
panic("error")
99+
}
100+
ifn(1)
102101
v2 := reflect.ValueOf(fn.Interface())
103102
r2 := v2.Call([]reflect.Value{reflect.ValueOf(100)})
104103
println(r2[0].Int())
@@ -111,12 +110,11 @@ func callIMethod() {
111110
println("imethod", fn.Kind(), fn.Type().String())
112111
r := fn.Call([]reflect.Value{reflect.ValueOf(100)})
113112
println(r[0].Int())
114-
//TODO type assert
115-
// ifn, ok := fn.Interface().(func(int) int)
116-
// if !ok {
117-
// panic("error")
118-
// }
119-
// ifn(1)
113+
ifn, ok := fn.Interface().(func(int) int)
114+
if !ok {
115+
panic("error")
116+
}
117+
ifn(1)
120118
v2 := reflect.ValueOf(fn.Interface())
121119
r2 := v2.Call([]reflect.Value{reflect.ValueOf(100)})
122120
println(r2[0].Int())

0 commit comments

Comments
 (0)