Clean up gen.writeStatementAssign a bit more
@@ -99,17 +99,22 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
}
depth++
- if lhs != nil {
+ wbqcErr := errNoSuchBuiltin
if rhs.Effect().Coroutine() {
if op != t.IDEqQuestion {
if err := g.writeCoroSuspPoint(b, false); err != nil {
return err
}
}
- switch err := g.writeBuiltinQuestionCall(b, rhs, depth); err {
- case nil:
+ wbqcErr = g.writeBuiltinQuestionCall(b, rhs, depth)
+ if wbqcErr == nil {
// No-op.
- case errNoSuchBuiltin:
+ } else if wbqcErr != errNoSuchBuiltin {
+ return wbqcErr
+ }
+ }
+
+ if (wbqcErr != nil) && ((lhs == nil) || (rhs.Effect().Coroutine())) {
if err := g.writeSaveExprDerivedVars(b, rhs); err != nil {
return err
}
@@ -122,11 +127,12 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
g.currFunk.tempW++
b.printf("wuffs_base__status %s%d = ", tPrefix, temp)
- } else {
+ } else if rhs.Effect().Optional() {
b.writes("status = ")
}
- if err := g.writeExprUserDefinedCall(b, rhs, depth); err != nil {
+ // TODO: drop the "Other" in writeExprOther.
+ if err := g.writeExprOther(b, rhs, depth); err != nil {
return err
}
b.writes(";\n")
@@ -135,14 +141,16 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
return err
}
- if op != t.IDEqQuestion {
- b.writes("if (status) { goto suspend; }\n")
+ if op != t.IDEqQuestion && rhs.Effect().Optional() {
+ target := "exit"
+ if rhs.Effect().Coroutine() {
+ target = "suspend"
}
- default:
- return err
+ b.printf("if (status) { goto %s; }\n", target)
}
}
+ if lhs != nil {
lhsBuf := buffer(nil)
if err := g.writeExpr(&lhsBuf, lhs, depth); err != nil {
return err
@@ -182,44 +190,6 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
}
b.writes(closer)
b.writes(";\n")
-
- } else {
- if rhs.Effect().Coroutine() {
- if err := g.writeCoroSuspPoint(b, false); err != nil {
- return err
- }
- }
-
- if err := g.writeBuiltinQuestionCall(b, rhs, depth); err != errNoSuchBuiltin {
- return err
- }
-
- if err := g.writeSaveExprDerivedVars(b, rhs); err != nil {
- return err
- }
-
- if rhs.Effect().Optional() {
- b.writes("status = ")
- }
-
- // TODO: drop the "Other" in writeExprOther.
- if err := g.writeExprOther(b, rhs, depth); err != nil {
- return err
- }
-
- b.writes(";\n")
-
- if err := g.writeLoadExprDerivedVars(b, rhs); err != nil {
- return err
- }
-
- if rhs.Effect().Optional() {
- target := "exit"
- if rhs.Effect().Coroutine() {
- target = "suspend"
- }
- b.printf("if (status) { goto %s; }\n", target)
- }
}
return nil
