Separate the coro_susp_point from the coro stack

This commit is contained in:
Nigel Tao committed 2019-02-09 11:03:50 +11:00
1 parent 2928806ab6
commit 9518af5a95
6 files changed
+292 -317

No files matched your search

+6 -6
View File
@@ -303,8 +303,8 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
func (g *gen) writeFuncImplBodyResume(b *buffer) error {
if g.currFunk.astFunc.Effect().Coroutine() {
// TODO: don't hard-code [0], and allow recursive coroutines.
b.printf("uint32_t coro_susp_point = self->private_impl.%s%s[0].coro_susp_point;\n",
cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
b.printf("uint32_t coro_susp_point = self->private_impl.%s%s[0];\n",
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
b.printf("if (coro_susp_point) {\n")
if err := g.writeResumeSuspend(b, &g.currFunk, false); err != nil {
return err
@@ -334,14 +334,14 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
// suspension point so that the next call to this function starts at
// the top.
b.writes("\ngoto ok;ok:") // The goto avoids the "unused label" warning.
b.printf("self->private_impl.%s%s[0].coro_susp_point = 0;\n",
cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
b.printf("self->private_impl.%s%s[0] = 0;\n",
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
b.writes("goto exit; }\n\n") // Close the coroutine switch.
b.writes("goto suspend;suspend:") // The goto avoids the "unused label" warning.
b.printf("self->private_impl.%s%s[0].coro_susp_point = coro_susp_point;\n",
cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
b.printf("self->private_impl.%s%s[0] = coro_susp_point;\n",
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
if g.currFunk.astFunc.Public() {
b.printf("self->private_impl.active_coroutine = %d;\n", g.currFunk.coroID)
}