From 36f5ae9bf4ba7028f08fb87034b28a7744954048 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 26 Oct 2017 11:20:42 +1100 Subject: [PATCH] Move the "mark in.dst" into the flate decode loop. --- cmd/puffs-c/internal/cgen/statement.go | 8 ++++++-- cmd/puffs-c/internal/cgen/var.go | 12 ------------ gen/c/std/flate.c | 2 +- std/flate/decode_flate.puffs | 7 ++----- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/cmd/puffs-c/internal/cgen/statement.go b/cmd/puffs-c/internal/cgen/statement.go index 76bcb3da..7b50ab88 100644 --- a/cmd/puffs-c/internal/cgen/statement.go +++ b/cmd/puffs-c/internal/cgen/statement.go @@ -69,8 +69,12 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error { return nil case a.KIO: - // TODO: the mark needs to apply on every (coroutine) call to the - // function, not just when we execute this particular statement. + // TODO: is a private_impl.mark the right representation? What if the + // function is passed a (ptr writer1) instead of a (writer1)? Do we + // still want to have that mark live outside of the function scope? + // + // TODO: remove this hard-coded hack for "mark in.dst". + b.printf("%sdst.private_impl.mark = %swptr_dst;", aPrefix, bPrefix) return nil case a.KIf: diff --git a/cmd/puffs-c/internal/cgen/var.go b/cmd/puffs-c/internal/cgen/var.go index 03a09689..4a2753e0 100644 --- a/cmd/puffs-c/internal/cgen/var.go +++ b/cmd/puffs-c/internal/cgen/var.go @@ -117,18 +117,6 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header b.printf("%swptr_%s = %s%s.buf->ptr + %s%s.buf->wi;", bPrefix, nameStr, aPrefix, nameStr, aPrefix, nameStr) - - // TODO: remove this hard-coded hack for "mark in.dst". - // - // TODO: is a private_impl.mark the right representation? What if the - // function is passed a (ptr writer1) instead of a (writer1)? Do we - // still want to have that mark live outside of the function scope? - if header && - g.currFunk.astFunc.Receiver().String(g.tm) == "flate_decoder" && - g.currFunk.astFunc.Name().String(g.tm) == "decode" { - b.printf("%s%s.private_impl.mark = %swptr_%s;", aPrefix, nameStr, bPrefix, nameStr) - } - if header { b.printf("%swstart_%s = %swptr_%s;", bPrefix, nameStr, bPrefix, nameStr) } diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index 06fd813f..7498338d 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -817,7 +817,6 @@ puffs_flate__status puffs_flate__flate_decoder__decode( uint8_t* b_wend_dst = NULL; if (a_dst.buf) { b_wptr_dst = a_dst.buf->ptr + a_dst.buf->wi; - a_dst.private_impl.mark = b_wptr_dst; b_wstart_dst = b_wptr_dst; b_wend_dst = b_wptr_dst; if (!a_dst.buf->closed) { @@ -843,6 +842,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode( PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0); while (true) { + a_dst.private_impl.mark = b_wptr_dst; PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); if (a_dst.buf) { size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi); diff --git a/std/flate/decode_flate.puffs b/std/flate/decode_flate.puffs index 427f3f53..021ff01a 100644 --- a/std/flate/decode_flate.puffs +++ b/std/flate/decode_flate.puffs @@ -116,12 +116,9 @@ pub struct flate_decoder?( ) pub func flate_decoder.decode?(dst writer1, src reader1)() { - // TODO: when is the mark undone? Explicitly or implicitly? Right now, we - // just assume that the mark is dropped at function end, since the arg is a - // writer1 not a *writer1. Should we support nested marks? Should this be - // "mark dst { etc }" that has a block and unmarks at the block end? - mark in.dst while true { + // TODO: this could be "in.dst.mark()" instead of a keyword. + mark in.dst var z status = try this.decode_blocks?(dst:in.dst, src:in.src) if not z.is_suspension() { // TODO: rename "return" to "raise"?