Use !?? to denote coroutines

This commit is contained in:
Nigel Tao committed 2018-07-29 13:57:13 +10:00
1 parent 0a47966e72
commit 2100a9f837
8 files changed
+149 -149

No files matched your search

+23 -23
View File
@@ -123,10 +123,10 @@ pub struct decoder?(
end_of_block base.bool,
)
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
while true {
args.dst.set_mark!()
var z base.status = try this.decode_blocks?(dst:args.dst, src:args.src)
var z base.status = try this.decode_blocks!??(dst:args.dst, src:args.src)
if not z.is_suspension() {
return z
}
@@ -175,13 +175,13 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
}
}
pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader) {
pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
var final base.u32
while final == 0 {
while this.n_bits < 3,
post this.n_bits >= 3,
{
this.bits |= (args.src.read_u8?() as base.u32) << this.n_bits
this.bits |= (args.src.read_u8!??() as base.u32) << this.n_bits
this.n_bits += 8
}
final = this.bits & 0x01
@@ -190,22 +190,22 @@ pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader) {
this.n_bits -= 3
if type == 0 {
this.decode_uncompressed?(dst:args.dst, src:args.src)
this.decode_uncompressed!??(dst:args.dst, src:args.src)
continue
} else if type == 1 {
this.init_fixed_huffman?()
this.init_fixed_huffman!??()
} else if type == 2 {
this.init_dynamic_huffman?(src:args.src)
this.init_dynamic_huffman!??(src:args.src)
} else {
return error "bad block"
}
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
}
this.decode_huffman_slow?(dst:args.dst, src:args.src)
this.decode_huffman_slow!??(dst:args.dst, src:args.src)
if this.end_of_block {
continue
}
@@ -215,7 +215,7 @@ pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader) {
// decode_uncompressed decodes an uncompresed block as per the RFC section
// 3.2.4.
pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader) {
pri func decoder.decode_uncompressed!??(dst base.io_writer, src base.io_reader) {
// TODO: make this "if" into a function invariant?
//
// Ditto for decode_huffman_slow and decode_huffman_fast.
@@ -225,7 +225,7 @@ pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader) {
this.n_bits = 0
this.bits = 0
var length base.u32 = args.src.read_u32le?()
var length base.u32 = args.src.read_u32le!??()
if (length.low_bits(n:16) + length.high_bits(n:16)) != 0xFFFF {
return error "inconsistent stored block length"
}
@@ -246,7 +246,7 @@ pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader) {
}
// init_fixed_huffman initializes this.huffs as per the RFC section 3.2.6.
pri func decoder.init_fixed_huffman?() {
pri func decoder.init_fixed_huffman!??() {
var i base.u32
while i < 144 {
this.code_lengths[i] = 8
@@ -268,18 +268,18 @@ pri func decoder.init_fixed_huffman?() {
this.code_lengths[i] = 5
i += 1
}
this.init_huff?(which:0, n_codes0:0, n_codes1:288, base_symbol:257)
this.init_huff?(which:1, n_codes0:288, n_codes1:320, base_symbol:0)
this.init_huff!??(which:0, n_codes0:0, n_codes1:288, base_symbol:257)
this.init_huff!??(which:1, n_codes0:288, n_codes1:320, base_symbol:0)
}
// init_dynamic_huffman initializes this.huffs as per the RFC section 3.2.7.
pri func decoder.init_dynamic_huffman?(src base.io_reader) {
pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
var bits base.u32 = this.bits
var n_bits base.u32 = this.n_bits
while n_bits < 14,
post n_bits >= 14,
{
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
var n_lit base.u32[257..288] = bits.low_bits(n:5) + 257
@@ -303,7 +303,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
inv i < n_clen,
post n_bits >= 3,
{
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
assert i < 19 via "a < b: a < c; c <= b"(c:n_clen)
@@ -316,7 +316,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
this.code_lengths[code_order[i]] = 0
i += 1
}
this.init_huff?(which:0, n_codes0:0, n_codes1:19, base_symbol:0xFFF)
this.init_huff!??(which:0, n_codes0:0, n_codes1:19, base_symbol:0xFFF)
// Decode the code lengths for the next two Huffman tables.
var mask base.u32[..511] = ((1 as base.u32) << this.n_huffs_bits[0]) - 1
@@ -337,7 +337,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
// For H-CL, there should be no redirections and all symbols should be
@@ -385,7 +385,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
post n_bits >= n_extra_bits,
{
assert n_bits < 7 via "a < b: a < c; c <= b"(c:n_extra_bits)
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
rep_count += bits.low_bits(n:n_extra_bits)
@@ -411,8 +411,8 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
return error "missing end-of-block code"
}
this.init_huff?(which:0, n_codes0:0, n_codes1:n_lit, base_symbol:257)
this.init_huff?(which:1, n_codes0:n_lit, n_codes1:n_lit + n_dist, base_symbol:0)
this.init_huff!??(which:0, n_codes0:0, n_codes1:n_lit, base_symbol:257)
this.init_huff!??(which:1, n_codes0:n_lit, n_codes1:n_lit + n_dist, base_symbol:0)
this.bits = bits
this.n_bits = n_bits
@@ -423,7 +423,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
// TODO: skip generating WUFFS_COROUTINE_SUSPENSION_POINTs for *callers* of
// this function, as it can only return errors, not suspensions.
pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_codes1 base.u32[..320], base_symbol base.u32) {
pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_codes1 base.u32[..320], base_symbol base.u32) {
// For the clcode example in this package's README.md:
// - n_codes0 = 0
// - n_codes1 = 19
+1 -1
View File
@@ -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
+9 -9
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader) {
// When editing this function, consider making the equivalent change to the
// decode_huffman_fast function. Keep the diff between the two
// decode_huffman_*.wuffs files as small as possible, while retaining both
@@ -41,13 +41,13 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
if (table_entry >> 31) != 0 {
// Literal.
args.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
args.dst.write_u8!??(x:((table_entry >> 8) & 0xFF) as base.u8)
continue:loop
} else if (table_entry >> 30) != 0 {
// No-op; code continues past the if-else chain.
@@ -71,13 +71,13 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
if (table_entry >> 31) != 0 {
// Literal.
args.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
args.dst.write_u8!??(x:((table_entry >> 8) & 0xFF) as base.u8)
continue:loop
} else if (table_entry >> 30) != 0 {
// No-op; code continues past the if-else chain.
@@ -107,7 +107,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
post n_bits >= table_entry_n_bits,
{
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
length = (length + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
@@ -125,7 +125,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
// Check for a redirect.
@@ -144,7 +144,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
}
@@ -170,7 +170,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
post n_bits >= table_entry_n_bits,
{
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
bits |= (args.src.read_u8?() as base.u32) << n_bits
bits |= (args.src.read_u8!??() as base.u32) << n_bits
n_bits += 8
}
dist_minus_1 = (dist_minus_1 + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF