diff --git a/cmd/puffs-c/internal/cgen/statement.go b/cmd/puffs-c/internal/cgen/statement.go index 07c47bb2..18188847 100644 --- a/cmd/puffs-c/internal/cgen/statement.go +++ b/cmd/puffs-c/internal/cgen/statement.go @@ -459,6 +459,15 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error { } b.printf(" = *%srptr_src++;\n", bPrefix) + } else if isInSrc(g.tm, n, t.KeyUnreadU8, 0) { + if !n.ProvenNotToSuspend() { + b.printf("if (%srptr_src == %srstart_src) { status = %sERROR_INVALID_I_O_OPERATION;", + bPrefix, bPrefix, g.PKGPREFIX) + b.writes("goto exit;") + b.writes("}\n") + } + b.printf("%srptr_src--;\n", bPrefix) + } else if isInSrc(g.tm, n, t.KeyReadU16BE, 0) { return g.writeReadUXX(b, n, "src", 16, "be") diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index b2b2a5bb..fec01c28 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -2349,6 +2349,12 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast( label_0_break:; while (v_n_bits >= 8) { v_n_bits -= 8; + PUFFS_BASE__COROUTINE_SUSPENSION_POINT(11); + if (b_rptr_src == b_rstart_src) { + status = PUFFS_FLATE__ERROR_INVALID_I_O_OPERATION; + goto exit; + } + b_rptr_src--; } self->private_impl.f_bits = v_bits; self->private_impl.f_n_bits = v_n_bits; diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 0c48ec00..4ecdff39 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -734,7 +734,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int, } // TODO: delete this hack that only matches "in.src.read_u8?()" etc. - if isInSrc(q.tm, n, t.KeyReadU8, 0) || + if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeyUnreadU8, 0) || isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) || isInSrc(q.tm, n, t.KeySkip32, 1) || isInSrc(q.tm, n, t.KeySinceMark, 0) || @@ -1170,7 +1170,8 @@ func (q *checker) bcheckIOMethods(n *a.Expr, depth uint32) error { return nil } - // Figure out the "receiver" in "receiver.read_u8?()". + // Figure out the "receiver" in "receiver.read_xxx?()", for some I/O method + // "read_xxx". if n.ID0().Key() != t.KeyOpenParen { return nil } @@ -1179,7 +1180,10 @@ func (q *checker) bcheckIOMethods(n *a.Expr, depth uint32) error { return nil } advance := (*big.Int)(nil) - if key := receiver.ID1().Key(); key < t.Key(len(ioMethodAdvances)) { + if key := receiver.ID1().Key(); key == t.KeyUnreadU8 { + // TODO: call SetProvenNotToSuspend, since unread_u8 can never suspend, + // only succeed or fail. + } else if key < t.Key(len(ioMethodAdvances)) { advance = ioMethodAdvances[key] } if advance == nil { diff --git a/lang/check/type.go b/lang/check/type.go index d15e644e..8293fef4 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -407,7 +407,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { // require a TypeExpr being able to express function and method types. // TODO: delete this hack that only matches "in.src.read_u8?()" etc. - if isInSrc(q.tm, n, t.KeyReadU8, 0) || + if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeyUnreadU8, 0) || isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) || isInSrc(q.tm, n, t.KeySkip32, 1) || isInSrc(q.tm, n, t.KeySinceMark, 0) || diff --git a/lang/token/list.go b/lang/token/list.go index 3b6eec73..8447cff3 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -150,6 +150,8 @@ func (t Token) IsXAssociativeOp() bool { return t.ID.Key().isXOp() && t.ID.IsAss // // "Squiggly" means a sequence of non-alpha-numeric characters, such as "+" and // "&=". Their Keys range in [0x01, 0x7F]. +// +// TODO: re-pack the keys. const nBuiltInKeys = Key(256) const ( @@ -301,6 +303,7 @@ const ( KeyPrefix = Key(IDPrefix >> KeyShift) KeySuffix = Key(IDSuffix >> KeyShift) KeyLimit = Key(IDLimit >> KeyShift) + KeyUnreadU8 = Key(IDUnreadU8 >> KeyShift) KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift) KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift) @@ -488,6 +491,7 @@ const ( IDPrefix = ID(0xCB<= 8 { n_bits -= 8 - // TODO: in.src.unread_u8?() + in.src.unread_u8?() } this.bits = bits diff --git a/test/c/std/flate.c b/test/c/std/flate.c index daebc644..4cc547d9 100644 --- a/test/c/std/flate.c +++ b/test/c/std/flate.c @@ -877,18 +877,17 @@ proc tests[] = { test_puffs_flate_decode_flate_backref_crosses_blocks, // test_puffs_flate_decode_midsummer, // test_puffs_flate_decode_pi, // - // TODO: uncomment. - //test_puffs_flate_decode_pi_many_big_reads, // - //test_puffs_flate_decode_pi_many_medium_reads, // - //test_puffs_flate_decode_pi_many_small_writes_reads, // - //test_puffs_flate_decode_romeo, // - //test_puffs_flate_decode_romeo_fixed, // + test_puffs_flate_decode_pi_many_big_reads, // + test_puffs_flate_decode_pi_many_medium_reads, // + test_puffs_flate_decode_pi_many_small_writes_reads, // + test_puffs_flate_decode_romeo, // + test_puffs_flate_decode_romeo_fixed, // test_puffs_flate_decode_split_src, // test_puffs_flate_history_full, // test_puffs_flate_history_partial, // test_puffs_flate_table_redirect, // - //test_puffs_zlib_checksum_mismatch, // - //test_puffs_zlib_decode_midsummer, // + test_puffs_zlib_checksum_mismatch, // + test_puffs_zlib_decode_midsummer, // test_puffs_zlib_decode_pi, // #ifdef PUFFS_MIMIC @@ -915,11 +914,10 @@ proc benches[] = { // Flate Benches bench_puffs_adler32_10k, // bench_puffs_adler32_100k, // - // TODO: uncomment. - //bench_puffs_flate_decode_1k, // + bench_puffs_flate_decode_1k, // bench_puffs_flate_decode_10k, // bench_puffs_flate_decode_100k, // - //bench_puffs_zlib_decode_10k, // + bench_puffs_zlib_decode_10k, // bench_puffs_zlib_decode_100k, // #ifdef PUFFS_MIMIC