test: move cchan/cchansel into runtime/_test
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/runtime/internal/runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
eltSize = int(unsafe.Sizeof(0))
|
||||
)
|
||||
|
||||
func doChan(cap int) {
|
||||
c := runtime.NewChan(eltSize, cap)
|
||||
go func() {
|
||||
v := 100
|
||||
runtime.ChanSend(c, unsafe.Pointer(&v), eltSize)
|
||||
}()
|
||||
var ret int
|
||||
runtime.ChanRecv(c, unsafe.Pointer(&ret), eltSize)
|
||||
println(ret)
|
||||
}
|
||||
|
||||
func main() {
|
||||
doChan(10)
|
||||
doChan(0)
|
||||
|
||||
c := runtime.NewChan(eltSize, 3)
|
||||
|
||||
v := 1
|
||||
runtime.ChanSend(c, unsafe.Pointer(&v), eltSize)
|
||||
v = 2
|
||||
runtime.ChanSend(c, unsafe.Pointer(&v), eltSize)
|
||||
v = 3
|
||||
runtime.ChanSend(c, unsafe.Pointer(&v), eltSize)
|
||||
runtime.ChanClose(c)
|
||||
|
||||
v = 10
|
||||
|
||||
if runtime.ChanTrySend(c, unsafe.Pointer(&v), eltSize) {
|
||||
println("error: chan send to closed chan")
|
||||
}
|
||||
|
||||
for {
|
||||
if ok := runtime.ChanRecv(c, unsafe.Pointer(&v), eltSize); !ok {
|
||||
break
|
||||
}
|
||||
println(v)
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/runtime/internal/runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
eltSize = int(unsafe.Sizeof(0))
|
||||
)
|
||||
|
||||
func fibonacci(c, quit *runtime.Chan) {
|
||||
x, y := 0, 1
|
||||
for {
|
||||
isel, _ := runtime.Select(
|
||||
runtime.ChanOp{C: c, Send: true, Val: unsafe.Pointer(&x), Size: int32(eltSize)},
|
||||
runtime.ChanOp{C: quit},
|
||||
)
|
||||
if isel == 0 {
|
||||
x, y = y, x+y
|
||||
} else {
|
||||
println("quit")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := runtime.NewChan(eltSize, 0)
|
||||
quit := runtime.NewChan(eltSize, 0)
|
||||
go func() {
|
||||
for i := 0; i < 10; i++ {
|
||||
val := 0
|
||||
runtime.ChanRecv(c, unsafe.Pointer(&val), eltSize)
|
||||
println(val)
|
||||
}
|
||||
runtime.ChanClose(quit)
|
||||
}()
|
||||
fibonacci(c, quit)
|
||||
}
|
||||
Reference in New Issue
Block a user