compiler: support returning values from async functions

This is implemented as follows:

  * The parent coroutine allocates space for the return value in its
    frame and stores a pointer to this frame in the parent coroutine
    handle.
  * The child coroutine obtains the alloca from its parent using the
    parent coroutine handle. It then stores the result value there.
  * The parent value reads the data from the alloca on resumption.
This commit is contained in:
Ayke van Laethem
2019-04-29 02:08:26 +02:00
committed by Ron Evans
parent fb952a722a
commit 46d5ea8cf6
5 changed files with 93 additions and 42 deletions
+8
View File
@@ -15,6 +15,9 @@ func main() {
wait()
println("end waiting")
value := delayedValue()
println("value produced after some time:", value)
// Run a non-blocking call in a goroutine. This should be turned into a
// regular call, so should be equivalent to calling nowait() without 'go'
// prefix.
@@ -39,6 +42,11 @@ func wait() {
println(" wait end")
}
func delayedValue() int {
time.Sleep(time.Millisecond)
return 42
}
func nowait() {
println("non-blocking goroutine")
}
+1
View File
@@ -7,6 +7,7 @@ wait:
wait start
wait end
end waiting
value produced after some time: 42
non-blocking goroutine
done with non-blocking goroutine
async interface method call