mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Inline gen.writeQuestionCall
This commit is contained in:
1 parent
d26fa09d07
commit
5248d26db6
1 file changed
+38
-48
@@ -101,7 +101,44 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
|
|||||||
|
|
||||||
if lhs != nil {
|
if lhs != nil {
|
||||||
if rhs.Effect().Coroutine() {
|
if rhs.Effect().Coroutine() {
|
||||||
if err := g.writeQuestionCall(b, rhs, depth, op == t.IDEqQuestion); err != nil {
|
if op != t.IDEqQuestion {
|
||||||
|
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch err := g.writeBuiltinQuestionCall(b, rhs, depth); err {
|
||||||
|
case nil:
|
||||||
|
// No-op.
|
||||||
|
case errNoSuchBuiltin:
|
||||||
|
if err := g.writeSaveExprDerivedVars(b, rhs); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if op == t.IDEqQuestion {
|
||||||
|
if g.currFunk.tempW > maxTemp {
|
||||||
|
return fmt.Errorf("too many temporary variables required")
|
||||||
|
}
|
||||||
|
temp := g.currFunk.tempW
|
||||||
|
g.currFunk.tempW++
|
||||||
|
|
||||||
|
b.printf("wuffs_base__status %s%d = ", tPrefix, temp)
|
||||||
|
} else {
|
||||||
|
b.writes("status = ")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.writeExprUserDefinedCall(b, rhs, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.writes(";\n")
|
||||||
|
|
||||||
|
if err := g.writeLoadExprDerivedVars(b, rhs); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if op != t.IDEqQuestion {
|
||||||
|
b.writes("if (status) { goto suspend; }\n")
|
||||||
|
}
|
||||||
|
default:
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -473,53 +510,6 @@ func (g *gen) writeCoroSuspPoint(b *buffer, maybeSuspend bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) writeQuestionCall(b *buffer, n *a.Expr, depth uint32, eqQuestion bool) error {
|
|
||||||
if depth > a.MaxExprDepth {
|
|
||||||
return fmt.Errorf("expression recursion depth too large")
|
|
||||||
}
|
|
||||||
depth++
|
|
||||||
|
|
||||||
if !eqQuestion && n.Effect().Coroutine() {
|
|
||||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := g.writeBuiltinQuestionCall(b, n, depth); err != errNoSuchBuiltin {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := g.writeSaveExprDerivedVars(b, n); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if eqQuestion {
|
|
||||||
if g.currFunk.tempW > maxTemp {
|
|
||||||
return fmt.Errorf("too many temporary variables required")
|
|
||||||
}
|
|
||||||
temp := g.currFunk.tempW
|
|
||||||
g.currFunk.tempW++
|
|
||||||
|
|
||||||
b.printf("wuffs_base__status %s%d = ", tPrefix, temp)
|
|
||||||
} else {
|
|
||||||
b.writes("status = ")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := g.writeExprUserDefinedCall(b, n, depth); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
b.writes(";\n")
|
|
||||||
|
|
||||||
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !eqQuestion {
|
|
||||||
b.writes("if (status) { goto suspend; }\n")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func trimParens(b []byte) []byte {
|
func trimParens(b []byte) []byte {
|
||||||
if len(b) > 1 && b[0] == '(' && b[len(b)-1] == ')' {
|
if len(b) > 1 && b[0] == '(' && b[len(b)-1] == ')' {
|
||||||
return b[1 : len(b)-1]
|
return b[1 : len(b)-1]
|
||||||
|
|||||||
Reference in new issue
Block a user