Skip to content

Commit

Permalink
x/ssa: wrapCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Jan 6, 2025
1 parent fb2e63f commit 6c27f49
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 390 deletions.
41 changes: 15 additions & 26 deletions cl/_testrt/cabi/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ type info struct {
b c.Int
}

//llgo:type C
type infoBig struct {
a [128]c.Int
}

//go:linkname demo1 C.demo1
func demo1(info, c.Int) info

Expand All @@ -31,21 +26,22 @@ func demo2(info, *c.Int)
//go:linkname demo3 C.demo3
func demo3(info, c.Int) c.Int

//go:linkname big1 C.big1
func big1(infoBig, c.Int) infoBig

//go:linkname big2 C.big2
func big2(infoBig, *c.Int)

/*
//llgo:type C
type bigArr [128]int32

//llgo:link bigArr.scale C.big1
func (bigArr) scale(n int32) (v bigArr) {
return
}
*/

//llgo:link bigArr._sum C.big2
func (bigArr) _sum(n *int32) {
}

func (b bigArr) sum() (n int32) {
b._sum(&n)
return
}

//go:linkname callback C.callback
func callback(info, c.Int, func(info, c.Int) c.Int) c.Int
Expand Down Expand Up @@ -73,25 +69,18 @@ func Test() {
println(n)
panic("bad abi")
}
b := big1(infoBig{[128]c.Int{0: 1, 1: 2, 127: 3}}, 4)
if b.a[0] != 4 || b.a[1] != 8 || b.a[127] != 12 {
println(b.a[0], b.a[1], b.a[127])

b1 := bigArr{0: 1, 1: 2, 127: 4}
b2 := b1.scale(4)
if b2[0] != 4 || b2[1] != 8 || b2[127] != 16 {
println(b2[0], b2[1], b2[127])
panic("bad abi")
}
n = 0
big2(infoBig{[128]c.Int{0: 1, 1: 2, 127: 3}}, &n)
if n != 6 {
if n := b2.sum(); n != 28 {
println(n)
panic("bad abi")
}

// b1 := bigArr{0: 1, 1: 2, 127: 4}
// b2 := b1.scale(4)
// if b2[0] != 4 || b2[1] != 8 || b2[127] != 16 {
// println(b2[0], b2[1], b2[127])
// panic("bad abi")
// }

// callback go func
n = callback(info{[2]c.Int{1, 2}, 3}, 100, func(i info, n c.Int) c.Int {
return i.a[0] + i.a[1] + i.b + n
Expand Down
Loading

0 comments on commit 6c27f49

Please sign in to comment.