mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
compiler: allow larger-than-int values to be sent across a channel
Instead of storing the value to send/receive in the coroutine promise, store only a pointer in the promise. This simplifies the code a lot and allows larger value sizes to be sent across a channel. Unfortunately, this new system has a code size impact. For example, compiling testdata/channel.go for the BBC micro:bit, there is an increase in code size from 4776 bytes to 4856 bytes. However, the improved flexibility and simplicity of the code should be worth it. If this becomes an issue, we can always refactor the code at a later time.
This commit is contained in:
committed by
Ron Evans
parent
46d5ea8cf6
commit
9a54ee4241
Vendored
+9
@@ -20,6 +20,11 @@ func main() {
|
||||
n, ok = <-ch
|
||||
println("recv from closed channel:", n, ok)
|
||||
|
||||
// Test bigger values
|
||||
ch2 := make(chan complex128)
|
||||
go sendComplex(ch2)
|
||||
println("complex128:", <-ch2)
|
||||
|
||||
// Test multi-sender.
|
||||
ch = make(chan int)
|
||||
go fastsender(ch)
|
||||
@@ -62,6 +67,10 @@ func sender(ch chan int) {
|
||||
close(ch)
|
||||
}
|
||||
|
||||
func sendComplex(ch chan complex128) {
|
||||
ch <- 7+10.5i
|
||||
}
|
||||
|
||||
func fastsender(ch chan int) {
|
||||
ch <- 10
|
||||
ch <- 11
|
||||
|
||||
Vendored
+1
@@ -9,6 +9,7 @@ received num: 6
|
||||
received num: 7
|
||||
received num: 8
|
||||
recv from closed channel: 0 false
|
||||
complex128: (+7.000000e+000+1.050000e+001i)
|
||||
got n: 10
|
||||
got n: 11
|
||||
got n: 10
|
||||
|
||||
Reference in New Issue
Block a user