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
+2
View File
@@ -347,6 +347,8 @@ func (c *Compiler) Compile(mainPath string) []error {
c.mod.NamedFunction("runtime.chanSend").SetLinkage(llvm.ExternalLinkage)
c.mod.NamedFunction("runtime.chanRecv").SetLinkage(llvm.ExternalLinkage)
c.mod.NamedFunction("runtime.sleepTask").SetLinkage(llvm.ExternalLinkage)
c.mod.NamedFunction("runtime.setTaskData").SetLinkage(llvm.ExternalLinkage)
c.mod.NamedFunction("runtime.getTaskData").SetLinkage(llvm.ExternalLinkage)
c.mod.NamedFunction("runtime.activateTask").SetLinkage(llvm.ExternalLinkage)
c.mod.NamedFunction("runtime.scheduler").SetLinkage(llvm.ExternalLinkage)