mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Have write_{u8,token} save args across suspension
This commit is contained in:
1 parent
4c7c296015
commit
8e7efa67b9
3 files changed
+43
-22
No files matched your search
+27
-13
@@ -634,29 +634,36 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
case t.IDIOWriter:
|
||||
switch method.Ident() {
|
||||
case t.IDWriteU8:
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("if (iop_a_dst == io2_a_dst) {\n" +
|
||||
"status = wuffs_base__make_status(wuffs_base__suspension__short_write); goto suspend; }\n" +
|
||||
"*iop_a_dst++ = ")
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("%s = ", scratchName)
|
||||
x := n.Args()[0].AsArg().Value()
|
||||
if err := g.writeExpr(b, x, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(";\n")
|
||||
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf("if (iop_a_dst == io2_a_dst) {\n"+
|
||||
"status = wuffs_base__make_status(wuffs_base__suspension__short_write); goto suspend; }\n"+
|
||||
"*iop_a_dst++ = ((uint8_t)(%s));\n", scratchName)
|
||||
return nil
|
||||
}
|
||||
|
||||
case t.IDTokenWriter:
|
||||
switch method.Ident() {
|
||||
case t.IDWriteToken:
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("if (iop_a_dst == io2_a_dst) {\n" +
|
||||
"status = wuffs_base__make_status(wuffs_base__suspension__short_write); goto suspend; }\n" +
|
||||
"*iop_a_dst++ = wuffs_base__make_token(((")
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("%s = ((", scratchName)
|
||||
if err := g.writeExpr(b, n.Args()[0].AsArg().Value(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -664,7 +671,14 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
if err := g.writeExpr(b, n.Args()[1].AsArg().Value(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(") << WUFFS_BASE__TOKEN__LENGTH_SHIFT));\n")
|
||||
b.writes(") << WUFFS_BASE__TOKEN__LENGTH_SHIFT);\n")
|
||||
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf("if (iop_a_dst == io2_a_dst) {\n"+
|
||||
"status = wuffs_base__make_status(wuffs_base__suspension__short_write); goto suspend; }\n"+
|
||||
"*iop_a_dst++ = wuffs_base__make_token(%s);\n", scratchName)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,8 +266,8 @@ func (h *livenessHelper) doAssign(r livenesses, n *a.Assign, depth uint32) error
|
||||
func (h *livenessHelper) doExpr(r livenesses, n *a.Expr) error {
|
||||
allToStrong := false
|
||||
if n.Effect().Coroutine() {
|
||||
method := n.LHS().AsExpr().Ident()
|
||||
if (method == t.IDSkip) || (method == t.IDSkip32) {
|
||||
recv := n.LHS().AsExpr().LHS().AsExpr()
|
||||
if recv.MType().IsIOTokenType() {
|
||||
// No-op. These methods already save their args across suspensions.
|
||||
} else {
|
||||
allToStrong = true
|
||||
|
||||
Reference in new issue
Block a user