diff --git a/cmd/wuffs-c/internal/cgen/statement.go b/cmd/wuffs-c/internal/cgen/statement.go index d3d706f0..6641e5a5 100644 --- a/cmd/wuffs-c/internal/cgen/statement.go +++ b/cmd/wuffs-c/internal/cgen/statement.go @@ -155,9 +155,21 @@ func (g *gen) writeStatementAssign(b *buffer, n *a.Assign, depth uint32) error { } func (g *gen) writeStatementExpr(b *buffer, n *a.Expr, depth uint32) error { + // TODO: this same derived code-gen should happen for assignment and var + // statements. + // + // TODO: clean up how this and writeSuspendibles interact. + derived := n.Effect().RootCause() && n.Effect().Optional() && !n.Effect().Coroutine() + if derived { + if err := g.writeSaveExprDerivedVars(b, n); err != nil { + return err + } + } + if err := g.writeSuspendibles(b, n, depth); err != nil { return err } + checkStatus := false if n.Effect().RootCause() { if n.Effect().Coroutine() { @@ -171,6 +183,13 @@ func (g *gen) writeStatementExpr(b *buffer, n *a.Expr, depth uint32) error { return err } b.writes(";\n") + + if derived { + if err := g.writeLoadExprDerivedVars(b, n); err != nil { + return err + } + } + if checkStatus { b.writes("if (status) { goto exit; }\n") } diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.h index 770dcb9a..d2ebe29d 100644 --- a/release/c/wuffs-unsupported-snapshot.h +++ b/release/c/wuffs-unsupported-snapshot.h @@ -5216,7 +5216,6 @@ wuffs_deflate__decoder__decode_blocks(wuffs_deflate__decoder* self, goto exit; } self->private_impl.f_end_of_block = false; - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); if (a_src.private_impl.buf) { a_src.private_impl.buf->meta.ri = iop_a_src - a_src.private_impl.buf->data.ptr; @@ -5227,12 +5226,12 @@ wuffs_deflate__decoder__decode_blocks(wuffs_deflate__decoder* self, a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri; } if (status) { - goto suspend; + goto exit; } if (self->private_impl.f_end_of_block) { goto label_0_continue; } - WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); if (a_src.private_impl.buf) { a_src.private_impl.buf->meta.ri = iop_a_src - a_src.private_impl.buf->data.ptr; diff --git a/std/deflate/decode_deflate.wuffs b/std/deflate/decode_deflate.wuffs index 85683320..afed5f9d 100644 --- a/std/deflate/decode_deflate.wuffs +++ b/std/deflate/decode_deflate.wuffs @@ -199,7 +199,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) { } this.end_of_block = false - this.decode_huffman_fast!??(dst:args.dst, src:args.src) + this.decode_huffman_fast!?(dst:args.dst, src:args.src) if this.end_of_block { continue } diff --git a/std/deflate/decode_huffman_fast.wuffs b/std/deflate/decode_huffman_fast.wuffs index 37a82600..221e2683 100644 --- a/std/deflate/decode_huffman_fast.wuffs +++ b/std/deflate/decode_huffman_fast.wuffs @@ -14,7 +14,7 @@ // TODO: describe how the xxx_fast version differs from the xxx_slow one, the // assumptions that xxx_fast makes, and how that makes it fast. -pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader) { +pri func decoder.decode_huffman_fast!?(dst base.io_writer, src base.io_reader) { // When editing this function, consider making the equivalent change to the // decode_huffman_slow function. Keep the diff between the two // decode_huffman_*.wuffs files as small as possible, while retaining both