Reformat x:y as x: y

This commit is contained in:
Nigel Tao committed 2019-10-12 21:21:39 +11:00
1 parent a9ea63ff06
commit 5b4e3647c0
12 files changed
+195 -196

No files matched your search

+1 -1
View File
@@ -94,7 +94,7 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
buf = append(buf, ", "...)
}
buf = append(buf, tm.ByID(o.AsArg().Name())...)
buf = append(buf, ':')
buf = append(buf, ": "...)
buf = o.AsArg().Value().appendStr(buf, tm, false, depth)
}
buf = append(buf, ')')
+8 -8
View File
@@ -29,17 +29,17 @@ func TestString(tt *testing.T) {
"x",
"f()",
"f(a:i)",
"f(a:i, b:j)",
"f(a:i, b:j) + 1",
"f(a:i, b:j)(c:k)",
"f(a:i, b:j)(c:k, d:l, e:m + 2) + 3",
"f(a: i)",
"f(a: i, b: j)",
"f(a: i, b: j) + 1",
"f(a: i, b: j)(c: k)",
"f(a: i, b: j)(c: k, d: l, e: m + 2) + 3",
"x[i]",
"x[i][j]",
"x[i .. j]",
"x[i](arg:j)",
"x(arg:i)[j]",
"x[i](arg: j)",
"x(arg: i)[j]",
"x.y",
"x.y.z.a",
@@ -56,7 +56,7 @@ func TestString(tt *testing.T) {
"x * ((a / b) - (i / j))",
"x + y + z",
"x + (i * j.k[l] * (-m << 4) * (n & o(o0:p, o1:q[.. r.s + 5]))) + z",
"x + (i * j.k[l] * (-m << 4) * (n & o(o0: p, o1: q[.. r.s + 5]))) + z",
"x as base.bool",
"x as base.u32",
-1
View File
@@ -1185,5 +1185,4 @@ var isTightRight = [...]bool{
IDDot: true,
IDExclam: true,
IDQuestion: true,
IDColon: true,
}
+3 -3
View File
@@ -32,8 +32,8 @@ pub func hasher.update!(x slice base.u8) base.u32 {
this.state = 1
}
s1 = this.state.low_bits(n:16)
s2 = this.state.high_bits(n:16)
s1 = this.state.low_bits(n: 16)
s2 = this.state.high_bits(n: 16)
while args.x.length() > 0 {
remaining = args.x[.. 0]
@@ -42,7 +42,7 @@ pub func hasher.update!(x slice base.u8) base.u32 {
args.x = args.x[.. 5552]
}
iterate (p = args.x)(length:1, unroll:8) {
iterate (p = args.x)(length: 1, unroll: 8) {
s1 ~mod+= p[0] as base.u32
s2 ~mod+= s1
}
+2 -2
View File
@@ -28,7 +28,7 @@ pub func ieee_hasher.update!(x slice base.u8) base.u32 {
// See "Multi-Byte Lookup Tables" in std/crc32/README.md for more detail on
// the slicing-by-M algorithm. We use an M of 16.
iterate (p = args.x)(length:16, unroll:2) {
iterate (p = args.x)(length: 16, unroll: 2) {
s ^= ((p[0x00] as base.u32) << 0) |
((p[0x01] as base.u32) << 8) |
((p[0x02] as base.u32) << 16) |
@@ -49,7 +49,7 @@ pub func ieee_hasher.update!(x slice base.u8) base.u32 {
ieee_table[0x0D][0xFF & (s >> 16)] ^
ieee_table[0x0E][0xFF & (s >> 8)] ^
ieee_table[0x0F][0xFF & (s >> 0)]
} else (length:1, unroll:1) {
} else (length: 1, unroll: 1) {
s = ieee_table[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
}
+35 -35
View File
@@ -143,13 +143,13 @@ pub func decoder.add_history!(hist slice base.u8) {
if s.length() >= 0x8000 {
// If s is longer than the ringbuffer, we can ignore the previous value
// of history_index, as we will overwrite the whole ringbuffer.
s = s.suffix(up_to:0x8000)
this.history[..].copy_from_slice!(s:s)
s = s.suffix(up_to: 0x8000)
this.history[..].copy_from_slice!(s: s)
this.history_index = 0x8000
} else {
// Otherwise, append s to the history ringbuffer starting at the
// previous history_index (modulo 0x8000).
n_copied = this.history[this.history_index & 0x7FFF ..].copy_from_slice!(s:s)
n_copied = this.history[this.history_index & 0x7FFF ..].copy_from_slice!(s: s)
if n_copied < s.length() {
// a_slice.copy_from(s:b_slice) returns the minimum of the two
// slice lengths. If that value is less than b_slice.length(), then
@@ -159,7 +159,7 @@ pub func decoder.add_history!(hist slice base.u8) {
// wrap around and copy the remainder of s over the start of the
// history ringbuffer.
s = s[n_copied ..]
n_copied = this.history[..].copy_from_slice!(s:s)
n_copied = this.history[..].copy_from_slice!(s: s)
// Set history_index (modulo 0x8000) to the length of this
// remainder. The &0x7FFF is redundant, but proves to the compiler
// that the conversion to u32 will not overflow. The +0x8000 is to
@@ -179,8 +179,8 @@ pub func decoder.add_history!(hist slice base.u8) {
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(
min_incl:decoder_workbuf_len_max_incl_worst_case,
max_incl:decoder_workbuf_len_max_incl_worst_case)
min_incl: decoder_workbuf_len_max_incl_worst_case,
max_incl: decoder_workbuf_len_max_incl_worst_case)
}
pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workbuf slice base.u8) {
@@ -189,14 +189,14 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
while true {
mark = args.dst.mark()
status =? this.decode_blocks?(dst:args.dst, src:args.src)
status =? this.decode_blocks?(dst: args.dst, src: args.src)
if not status.is_suspension() {
return status
}
// TODO: should "since" be "since!", as the return value lets you
// modify the state of args.dst, so future mutations (via the slice)
// can change the veracity of any args.dst assertions?
this.add_history!(hist:args.dst.since(mark:mark))
this.add_history!(hist: args.dst.since(mark: mark))
yield? status
}
}
@@ -221,7 +221,7 @@ 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 {
status = this.init_fixed_huffman!()
@@ -235,21 +235,21 @@ pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader) {
return status
}
} else if type == 2 {
this.init_dynamic_huffman?(src:args.src)
this.init_dynamic_huffman?(src: args.src)
} else {
return "#bad block"
}
this.end_of_block = false
while true {
status = this.decode_huffman_fast!(dst:args.dst, src:args.src)
status = this.decode_huffman_fast!(dst: args.dst, src: args.src)
if status.is_error() {
return status
}
if this.end_of_block {
continue.outer
}
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.outer
}
@@ -273,12 +273,12 @@ pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader) {
this.bits = 0
length = args.src.read_u32le?()
if (length.low_bits(n:16) + length.high_bits(n:16)) <> 0xFFFF {
if (length.low_bits(n: 16) + length.high_bits(n: 16)) <> 0xFFFF {
return "#inconsistent stored block length"
}
length = length.low_bits(n:16)
length = length.low_bits(n: 16)
while true {
n_copied = args.dst.copy_n_from_reader!(n:length, r:args.src)
n_copied = args.dst.copy_n_from_reader!(n: length, r: args.src)
if length <= n_copied {
return ok
}
@@ -317,11 +317,11 @@ pri func decoder.init_fixed_huffman!() base.status {
i += 1
}
status = this.init_huff!(which:0, n_codes0:0, n_codes1:288, base_symbol:257)
status = this.init_huff!(which: 0, n_codes0: 0, n_codes1: 288, base_symbol: 257)
if status.is_error() {
return status
}
status = this.init_huff!(which:1, n_codes0:288, n_codes1:320, base_symbol:0)
status = this.init_huff!(which: 1, n_codes0: 288, n_codes1: 320, base_symbol: 0)
if status.is_error() {
return status
}
@@ -357,17 +357,17 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
bits |= b0 << n_bits
n_bits += 8
}
n_lit = bits.low_bits(n:5) + 257
n_lit = bits.low_bits(n: 5) + 257
if n_lit > 286 {
return "#bad literal/length code count"
}
bits >>= 5
n_dist = bits.low_bits(n:5) + 1
n_dist = bits.low_bits(n: 5) + 1
if n_dist > 30 {
return "#bad distance code count"
}
bits >>= 5
n_clen = bits.low_bits(n:4) + 4
n_clen = bits.low_bits(n: 4) + 4
bits >>= 4
n_bits -= 14
@@ -382,7 +382,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
bits |= b1 << n_bits
n_bits += 8
}
assert i < 19 via "a < b: a < c; c <= b"(c:n_clen)
assert i < 19 via "a < b: a < c; c <= b"(c: n_clen)
this.code_lengths[code_order[i]] = (bits & 0x07) as base.u8
bits >>= 3
n_bits -= 3
@@ -392,7 +392,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
this.code_lengths[code_order[i]] = 0
i += 1
}
status = this.init_huff!(which:0, n_codes0:0, n_codes1:19, base_symbol:0xFFF)
status = this.init_huff!(which: 0, n_codes0: 0, n_codes1: 19, base_symbol: 0xFFF)
if status.is_error() {
return status
}
@@ -401,7 +401,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
mask = ((1 as base.u32) << (this.n_huffs_bits[0])) - 1
i = 0
while i < (n_lit + n_dist) {
assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0:n_lit, c0:n_dist)
assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0: n_lit, c0: n_dist)
// Decode a clcode symbol from H-CL.
while true,
@@ -414,7 +414,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
n_bits -= table_entry_n_bits
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
b2 = args.src.read_u8_as_u32?()
bits |= b2 << n_bits
n_bits += 8
@@ -463,12 +463,12 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
inv rep_count <= 11,
post n_bits >= n_extra_bits,
{
assert n_bits < 7 via "a < b: a < c; c <= b"(c:n_extra_bits)
assert n_bits < 7 via "a < b: a < c; c <= b"(c: n_extra_bits)
b3 = args.src.read_u8_as_u32?()
bits |= b3 << n_bits
n_bits += 8
}
rep_count += bits.low_bits(n:n_extra_bits)
rep_count += bits.low_bits(n: n_extra_bits)
bits >>= n_extra_bits
n_bits -= n_extra_bits
@@ -477,7 +477,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
if i >= (n_lit + n_dist) {
return "#bad Huffman code length count"
}
assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0:n_lit, c0:n_dist)
assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0: n_lit, c0: n_dist)
this.code_lengths[i] = rep_symbol
i += 1
rep_count -= 1
@@ -491,11 +491,11 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) {
return "#missing end-of-block code"
}
status = this.init_huff!(which:0, n_codes0:0, n_codes1:n_lit, base_symbol:257)
status = this.init_huff!(which: 0, n_codes0: 0, n_codes1: n_lit, base_symbol: 257)
if status.is_error() {
return status
}
status = this.init_huff!(which:1, n_codes0:n_lit, n_codes1:n_lit + n_dist, base_symbol:0)
status = this.init_huff!(which: 1, n_codes0: n_lit, n_codes1: n_lit + n_dist, base_symbol: 0)
if status.is_error() {
return status
}
@@ -567,7 +567,7 @@ pri func decoder.init_huff!(which base.u32[..= 1], n_codes0 base.u32[..= 288], n
// - all other counts elements are 0.
i = args.n_codes0
while i < args.n_codes1 {
assert i < 320 via "a < b: a < c; c <= b"(c:args.n_codes1)
assert i < 320 via "a < b: a < c; c <= b"(c: args.n_codes1)
// TODO: this if should be unnecessary. Have some way to assert that,
// for all j, counts[j] <= i, and thus counts[j]++ will not overflow.
if counts[this.code_lengths[i] & 15] >= 320 {
@@ -662,7 +662,7 @@ pri func decoder.init_huff!(which base.u32[..= 1], n_codes0 base.u32[..= 288], n
while i < args.n_codes1,
inv n_symbols <= 288,
{
assert i < 320 via "a < b: a < c; c <= b"(c:args.n_codes1)
assert i < 320 via "a < b: a < c; c <= b"(c: args.n_codes1)
// TODO: this if check should be unnecessary.
if i < args.n_codes0 {
return "#internal error: inconsistent Huffman decoder state"
@@ -769,7 +769,7 @@ pri func decoder.init_huff!(which base.u32[..= 1], n_codes0 base.u32[..= 288], n
assert cl <= 9
redirect_key = (key >> cl) & 511
key = key.low_bits(n:cl)
key = key.low_bits(n: cl)
if prev_redirect_key <> redirect_key {
prev_redirect_key = redirect_key
@@ -804,7 +804,7 @@ pri func decoder.init_huff!(which base.u32[..= 1], n_codes0 base.u32[..= 288], n
if (top + ((1 as base.u32) << j)) > huffs_table_size {
return "#internal error: inconsistent Huffman decoder state"
}
assert (top + ((1 as base.u32) << j)) <= 1024 via "a <= b: a <= c; c <= b"(c:huffs_table_size)
assert (top + ((1 as base.u32) << j)) <= 1024 via "a <= b: a <= c; c <= b"(c: huffs_table_size)
next_top = top + ((1 as base.u32) << j)
redirect_key = (reverse8[redirect_key >> 1] as base.u32) | ((redirect_key & 1) << 8)
@@ -852,7 +852,7 @@ pri func decoder.init_huff!(which base.u32[..= 1], n_codes0 base.u32[..= 288], n
if (top + ((high_bits | reversed_key) & 511)) >= huffs_table_size {
return "#internal error: inconsistent Huffman decoder state"
}
assert (top + ((high_bits | reversed_key) & 511)) < 1024 via "a < b: a < c; c <= b"(c:huffs_table_size)
assert (top + ((high_bits | reversed_key) & 511)) < 1024 via "a < b: a < c; c <= b"(c: huffs_table_size)
this.huffs[args.which][top + ((high_bits | reversed_key) & 511)] = value
}
@@ -860,7 +860,7 @@ pri func decoder.init_huff!(which base.u32[..= 1], n_codes0 base.u32[..= 288], n
if i >= n_symbols {
break
}
assert i < 288 via "a < b: a < c; c <= b"(c:n_symbols)
assert i < 288 via "a < b: a < c; c <= b"(c: n_symbols)
code += 1
if code >= (1 << 15) {
return "#internal error: inconsistent Huffman decoder state"
+23 -23
View File
@@ -76,10 +76,10 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
if n_bits < 15 {
assert n_bits >= 0 // TODO: this shouldn't be necessary.
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
assert n_bits >= 15
} else {
@@ -99,7 +99,7 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
if (table_entry >> 31) <> 0 {
// Literal.
args.dst.write_fast_u8!(a:((table_entry >> 8) & 0xFF) as base.u8)
args.dst.write_fast_u8!(a: ((table_entry >> 8) & 0xFF) as base.u8)
continue.loop
} else if (table_entry >> 30) <> 0 {
// No-op; code continues past the if-else chain.
@@ -115,10 +115,10 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
if n_bits < 15 {
assert n_bits >= 0 // TODO: this shouldn't be necessary.
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
assert n_bits >= 15
} else {
@@ -137,7 +137,7 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
if (table_entry >> 31) <> 0 {
// Literal.
args.dst.write_fast_u8!(a:((table_entry >> 8) & 0xFF) as base.u8)
args.dst.write_fast_u8!(a: ((table_entry >> 8) & 0xFF) as base.u8)
continue.loop
} else if (table_entry >> 30) <> 0 {
// No-op; code continues past the if-else chain.
@@ -173,10 +173,10 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
if n_bits < 15 {
assert n_bits >= 0 // TODO: this shouldn't be necessary.
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
assert n_bits >= 15
} else {
@@ -188,7 +188,7 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
// The "+ 253" is the same as "- 3", after the "& 0xFF", but the
// plus form won't require an underflow check.
length = ((length + 253 + bits.low_bits(n:table_entry_n_bits)) & 0xFF) + 3
length = ((length + 253 + bits.low_bits(n: table_entry_n_bits)) & 0xFF) + 3
bits >>= table_entry_n_bits
n_bits -= table_entry_n_bits
@@ -200,10 +200,10 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
if n_bits < 15 {
assert n_bits >= 0 // TODO: this shouldn't be necessary.
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
assert n_bits >= 15
} else {
@@ -225,10 +225,10 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
if n_bits < 15 {
assert n_bits >= 0 // TODO: this shouldn't be necessary.
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
assert n_bits >= 15
} else {
@@ -266,21 +266,21 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
table_entry_n_bits = (table_entry >> 4) & 0x0F
// Ensure that we have at least table_entry_n_bits bits of input.
if n_bits < table_entry_n_bits {
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
assert n_bits >= 0 // TODO: this shouldn't be necessary.
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
assert table_entry_n_bits <= n_bits via "a <= b: a <= c; c <= b"(c:16)
assert table_entry_n_bits <= n_bits via "a <= b: a <= c; c <= b"(c: 16)
assert n_bits >= table_entry_n_bits via "a >= b: b <= a"()
}
// Once again, redundant but explicit assertions.
assert n_bits >= table_entry_n_bits
dist_minus_1 = (dist_minus_1 + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
dist_minus_1 = (dist_minus_1 + bits.low_bits(n: table_entry_n_bits)) & 0x7FFF
bits >>= table_entry_n_bits
n_bits -= table_entry_n_bits
@@ -300,7 +300,7 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
hdist = (((dist_minus_1 + 1) as base.u64) - args.dst.history_available()) as base.u32
if length > hdist {
assert hdist < length via "a < b: b > a"()
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c:length)
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c: length)
length -= hdist
hlen = hdist
} else {
@@ -331,12 +331,12 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
// "args.dst.available() >= 258" fact. It should certainly
// invalidate any fact that was "<=" instead of ">=".
n_copied = args.dst.copy_n_from_slice!(
n:hlen, s:this.history[hdist & 0x7FFF ..])
n: hlen, s: this.history[hdist & 0x7FFF ..])
if hlen <= n_copied {
break
}
hlen -= n_copied
args.dst.copy_n_from_slice!(n:hlen, s:this.history[..])
args.dst.copy_n_from_slice!(n: hlen, s: this.history[..])
break
}
@@ -356,10 +356,10 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba
// We can therefore prove:
assert (dist_minus_1 + 1) > 0
assert (length as base.u64) <= 258
assert (length as base.u64) <= args.dst.available() via "a <= b: a <= c; c <= b"(c:258)
assert (length as base.u64) <= args.dst.available() via "a <= b: a <= c; c <= b"(c: 258)
// Copy from args.dst.
args.dst.copy_n_from_history_fast!(n:length, distance:(dist_minus_1 + 1))
args.dst.copy_n_from_history_fast!(n: length, distance: (dist_minus_1 + 1))
break
}
}
+14 -14
View File
@@ -58,7 +58,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
n_bits -= table_entry_n_bits
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
b0 = args.src.read_u8_as_u32?()
bits |= b0 << n_bits
n_bits += 8
@@ -66,7 +66,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
if (table_entry >> 31) <> 0 {
// Literal.
args.dst.write_u8?(a:((table_entry >> 8) & 0xFF) as base.u8)
args.dst.write_u8?(a: ((table_entry >> 8) & 0xFF) as base.u8)
continue.loop
} else if (table_entry >> 30) <> 0 {
// No-op; code continues past the if-else chain.
@@ -86,7 +86,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
n_bits -= table_entry_n_bits
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
b1 = args.src.read_u8_as_u32?()
bits |= b1 << n_bits
n_bits += 8
@@ -94,7 +94,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
if (table_entry >> 31) <> 0 {
// Literal.
args.dst.write_u8?(a:((table_entry >> 8) & 0xFF) as base.u8)
args.dst.write_u8?(a: ((table_entry >> 8) & 0xFF) as base.u8)
continue.loop
} else if (table_entry >> 30) <> 0 {
// No-op; code continues past the if-else chain.
@@ -126,14 +126,14 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
while n_bits < table_entry_n_bits,
post n_bits >= table_entry_n_bits,
{
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
b2 = args.src.read_u8_as_u32?()
bits |= b2 << n_bits
n_bits += 8
}
// The "+ 253" is the same as "- 3", after the "& 0xFF", but the
// plus form won't require an underflow check.
length = ((length + 253 + bits.low_bits(n:table_entry_n_bits)) & 0xFF) + 3
length = ((length + 253 + bits.low_bits(n: table_entry_n_bits)) & 0xFF) + 3
bits >>= table_entry_n_bits
n_bits -= table_entry_n_bits
}
@@ -147,7 +147,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
n_bits -= table_entry_n_bits
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
b3 = args.src.read_u8_as_u32?()
bits |= b3 << n_bits
n_bits += 8
@@ -164,7 +164,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
n_bits -= table_entry_n_bits
break
}
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
b4 = args.src.read_u8_as_u32?()
bits |= b4 << n_bits
n_bits += 8
@@ -191,12 +191,12 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
while n_bits < table_entry_n_bits,
post n_bits >= table_entry_n_bits,
{
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
b5 = args.src.read_u8_as_u32?()
bits |= b5 << n_bits
n_bits += 8
}
dist_minus_1 = (dist_minus_1 + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
dist_minus_1 = (dist_minus_1 + bits.low_bits(n: table_entry_n_bits)) & 0x7FFF
bits >>= table_entry_n_bits
n_bits -= table_entry_n_bits
}
@@ -210,7 +210,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
hdist = (((dist_minus_1 + 1) as base.u64) - args.dst.history_available()) as base.u32
if length > hdist {
assert hdist < length via "a < b: b > a"()
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c:length)
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c: length)
length -= hdist
hlen = hdist
} else {
@@ -227,7 +227,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
// Copy from hdist to the end of this.history.
while true {
n_copied = args.dst.copy_n_from_slice!(
n:hlen, s:this.history[hdist & 0x7FFF ..])
n: hlen, s: this.history[hdist & 0x7FFF ..])
if hlen <= n_copied {
hlen = 0
break
@@ -246,7 +246,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
if hlen > 0 {
while true {
n_copied = args.dst.copy_n_from_slice!(
n:hlen, s:this.history[hdist & 0x7FFF ..])
n: hlen, s: this.history[hdist & 0x7FFF ..])
if hlen <= n_copied {
hlen = 0
break
@@ -264,7 +264,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
}
// Copy from args.dst.
n_copied = args.dst.copy_n_from_history!(n:length, distance:(dist_minus_1 + 1))
n_copied = args.dst.copy_n_from_history!(n: length, distance: (dist_minus_1 + 1))
if length <= n_copied {
length = 0
break
+80 -80
View File
@@ -255,13 +255,13 @@ pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_re
var ffio base.bool
if this.call_sequence == 0 {
this.decode_header?(src:args.src)
this.decode_lsd?(src:args.src)
this.decode_header?(src: args.src)
this.decode_lsd?(src: args.src)
} else if this.call_sequence <> 2 {
return base."#bad call sequence"
}
this.decode_up_to_id_part1?(src:args.src)
this.decode_up_to_id_part1?(src: args.src)
// TODO: if this.end_of_data, return an error and/or set dst to zero?
@@ -285,12 +285,12 @@ pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_re
// TODO: a Wuffs (not just C) name for the
// WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY magic pixfmt constant.
args.dst.set!(
pixfmt:0x47040008,
pixsub:0,
width:this.width,
height:this.height,
first_frame_io_position:this.frame_config_io_position,
first_frame_is_opaque:ffio)
pixfmt: 0x47040008,
pixsub: 0,
width: this.width,
height: this.height,
first_frame_io_position: this.frame_config_io_position,
first_frame_is_opaque: ffio)
}
this.call_sequence = 3
@@ -327,7 +327,7 @@ pub func decoder.ack_metadata_chunk?(src base.io_reader) {
// metadata passed to the caller.
this.metadata_chunk_length_value += 1
} else {
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
}
this.metadata_io_position =
args.src.position() ~sat+ this.metadata_chunk_length_value
@@ -335,7 +335,7 @@ pub func decoder.ack_metadata_chunk?(src base.io_reader) {
}
// Consume the '\x00' that means a zero-length block.
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
}
this.call_sequence = 2
@@ -371,16 +371,16 @@ pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
// The "foo.min(a:this.width_or_height)" calls clip the nominal frame_rect
// to the image_rect.
return this.util.make_rect_ie_u32(
min_incl_x:this.frame_rect_x0.min(a:this.width),
min_incl_y:this.frame_rect_y0.min(a:this.height),
max_excl_x:this.frame_rect_x1.min(a:this.width),
max_excl_y:this.dirty_max_excl_y.min(a:this.height))
min_incl_x: this.frame_rect_x0.min(a: this.width),
min_incl_y: this.frame_rect_y0.min(a: this.height),
max_excl_x: this.frame_rect_x1.min(a: this.width),
max_excl_y: this.dirty_max_excl_y.min(a: this.height))
}
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(
min_incl:decoder_workbuf_len_max_incl_worst_case,
max_incl:decoder_workbuf_len_max_incl_worst_case)
min_incl: decoder_workbuf_len_max_incl_worst_case,
max_incl: decoder_workbuf_len_max_incl_worst_case)
}
pub func decoder.restart_frame!(index base.u64, io_position base.u64) base.status {
@@ -407,12 +407,12 @@ pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_re
if not this.end_of_data {
if this.call_sequence == 0 {
this.decode_image_config?(dst:nullptr, src:args.src)
this.decode_image_config?(dst: nullptr, src: args.src)
} else if this.call_sequence <> 3 {
if this.call_sequence == 4 {
this.skip_frame?(src:args.src)
this.skip_frame?(src: args.src)
}
this.decode_up_to_id_part1?(src:args.src)
this.decode_up_to_id_part1?(src: args.src)
}
}
@@ -451,17 +451,17 @@ pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_re
// necessarily mean "the x direction". It's just that, in Wuffs, every
// function call argument needs a name, and for the min function, "x"
// is as good a name as any other.
args.dst.update!(bounds:this.util.make_rect_ie_u32(
min_incl_x:this.frame_rect_x0.min(a:this.width),
min_incl_y:this.frame_rect_y0.min(a:this.height),
max_excl_x:this.frame_rect_x1.min(a:this.width),
max_excl_y:this.frame_rect_y1.min(a:this.height)),
duration:this.gc_duration,
index:this.num_decoded_frame_configs_value,
io_position:this.frame_config_io_position,
blend:blend,
disposal:this.gc_disposal,
background_color:background_color)
args.dst.update!(bounds: this.util.make_rect_ie_u32(
min_incl_x: this.frame_rect_x0.min(a: this.width),
min_incl_y: this.frame_rect_y0.min(a: this.height),
max_excl_x: this.frame_rect_x1.min(a: this.width),
max_excl_y: this.frame_rect_y1.min(a: this.height)),
duration: this.gc_duration,
index: this.num_decoded_frame_configs_value,
io_position: this.frame_config_io_position,
blend: blend,
disposal: this.gc_disposal,
background_color: background_color)
}
this.num_decoded_frame_configs_value ~sat+= 1
@@ -475,7 +475,7 @@ pri func decoder.skip_frame?(src base.io_reader) {
// Skip the optional Local Color Table, 3 bytes (RGB) per entry.
flags = args.src.read_u8?()
if (flags & 0x80) <> 0 {
args.src.skip?(n:(3 as base.u32) << (1 + (flags & 0x07)))
args.src.skip?(n: (3 as base.u32) << (1 + (flags & 0x07)))
}
// Process the LZW literal width.
@@ -485,7 +485,7 @@ pri func decoder.skip_frame?(src base.io_reader) {
}
// Skip the blocks of LZW-compressed data.
this.skip_blocks?(src:args.src)
this.skip_blocks?(src: args.src)
if this.quirk_enabled_delay_num_decoded_frames {
this.delayed_num_decoded_frames = true
@@ -499,14 +499,14 @@ pri func decoder.skip_frame?(src base.io_reader) {
pub func decoder.decode_frame?(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8, opts nptr base.decode_frame_options) {
this.ignore_metadata = true
if this.call_sequence <> 4 {
this.decode_frame_config?(dst:nullptr, src:args.src)
this.decode_frame_config?(dst: nullptr, src: args.src)
}
if this.quirk_enabled_reject_empty_frame and
((this.frame_rect_x0 == this.frame_rect_x1) or (this.frame_rect_y0 == this.frame_rect_y1)) {
return "#bad frame size"
}
this.decode_id_part1?(dst:args.dst, src:args.src)
this.decode_id_part2?(dst:args.dst, src:args.src, workbuf:args.workbuf)
this.decode_id_part1?(dst: args.dst, src: args.src)
this.decode_id_part2?(dst: args.dst, src: args.src, workbuf: args.workbuf)
this.num_decoded_frames_value ~sat+= 1
this.reset_gc!()
@@ -538,13 +538,13 @@ pri func decoder.decode_up_to_id_part1?(src base.io_reader) {
while true {
block_type = args.src.read_u8?()
if block_type == 0x21 { // The spec calls 0x21 the "Extension Introducer".
this.decode_extension?(src:args.src)
this.decode_extension?(src: args.src)
} else if block_type == 0x2C { // The spec calls 0x2C the "Image Separator".
if this.delayed_num_decoded_frames {
this.delayed_num_decoded_frames = false
this.num_decoded_frames_value ~sat+= 1
}
this.decode_id_part0?(src:args.src)
this.decode_id_part0?(src: args.src)
break
} else if block_type == 0x3B { // The spec calls 0x3B the "Trailer".
if this.delayed_num_decoded_frames {
@@ -592,7 +592,7 @@ pri func decoder.decode_lsd?(src base.io_reader) {
flags = args.src.read_u8?()
background_color_index = args.src.read_u8?()
// Ignore the Pixel Aspect Ratio byte.
args.src.skip?(n:1)
args.src.skip?(n: 1)
// Read the optional Global Color Table.
i = 0
@@ -600,7 +600,7 @@ pri func decoder.decode_lsd?(src base.io_reader) {
if this.has_global_palette {
num_palette_entries = (1 as base.u32) << (1 + (flags & 0x07))
while i < num_palette_entries {
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
assert i < 256 via "a < b: a < c; c <= b"(c: num_palette_entries)
// Convert from RGB (in memory order) to ARGB (in native u32 order)
// to BGRA (in memory order).
argb = args.src.read_u24be_as_u32?()
@@ -655,15 +655,15 @@ pri func decoder.decode_extension?(src base.io_reader) {
label = args.src.read_u8?()
if label == 0xF9 { // The spec calls 0xF9 the "Graphic Control Label".
this.decode_gc?(src:args.src)
this.decode_gc?(src: args.src)
return ok
} else if label == 0xFF { // The spec calls 0xFF the "Application Extension Label".
this.decode_ae?(src:args.src)
this.decode_ae?(src: args.src)
return ok
}
// We skip over all other extensions, including 0x01 "Plain Text Label" and
// 0xFE "Comment Label".
this.skip_blocks?(src:args.src)
this.skip_blocks?(src: args.src)
}
pri func decoder.skip_blocks?(src base.io_reader) {
@@ -674,7 +674,7 @@ pri func decoder.skip_blocks?(src base.io_reader) {
if block_size == 0 {
return ok
}
args.src.skip?(n:block_size as base.u32)
args.src.skip?(n: block_size as base.u32)
}
}
@@ -722,7 +722,7 @@ pri func decoder.decode_ae?(src base.io_reader) {
//
// Other extensions include XMP metadata.
if block_size <> 11 {
args.src.skip?(n:block_size as base.u32)
args.src.skip?(n: block_size as base.u32)
break
}
is_animexts = true
@@ -744,12 +744,12 @@ pri func decoder.decode_ae?(src base.io_reader) {
// count.
block_size = args.src.read_u8?()
if block_size <> 3 {
args.src.skip?(n:block_size as base.u32)
args.src.skip?(n: block_size as base.u32)
break
}
c = args.src.read_u8?()
if c <> 0x01 {
args.src.skip?(n:2)
args.src.skip?(n: 2)
break
}
this.num_loops = args.src.read_u16le_as_u32?()
@@ -779,7 +779,7 @@ pri func decoder.decode_ae?(src base.io_reader) {
yield? base."$short read"
}
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
this.metadata_fourcc_value = 0x49434350 // "ICCP"
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
this.call_sequence = 1
@@ -798,7 +798,7 @@ pri func decoder.decode_ae?(src base.io_reader) {
// metadata passed to the caller.
this.metadata_chunk_length_value += 1
} else {
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
}
this.metadata_fourcc_value = 0x584D5020 // "XMP "
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
@@ -808,7 +808,7 @@ pri func decoder.decode_ae?(src base.io_reader) {
break
}
this.skip_blocks?(src:args.src)
this.skip_blocks?(src: args.src)
}
// decode_gc reads a Graphic Control.
@@ -882,8 +882,8 @@ pri func decoder.decode_id_part0?(src base.io_reader) {
// test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt for
// more discussion.
if (this.call_sequence == 0) and (not this.quirk_enabled_image_bounds_are_strict) {
this.width = this.width.max(a:this.frame_rect_x1)
this.height = this.height.max(a:this.frame_rect_y1)
this.width = this.width.max(a: this.frame_rect_x1)
this.height = this.height.max(a: this.frame_rect_y1)
}
}
@@ -910,7 +910,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
num_palette_entries = (1 as base.u32) << (1 + (flags & 0x07))
i = 0
while i < num_palette_entries {
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
assert i < 256 via "a < b: a < c; c <= b"(c: num_palette_entries)
// Convert from RGB (in memory order) to ARGB (in native u32 order)
// to BGRA (in memory order).
argb = args.src.read_u24be_as_u32?()
@@ -932,7 +932,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
} else if this.quirk_enabled_reject_empty_palette and (not this.has_global_palette) {
return "#bad palette"
} else if this.gc_has_transparent_index {
this.palettes[1][..].copy_from_slice!(s:this.palettes[0][..])
this.palettes[1][..].copy_from_slice!(s: this.palettes[0][..])
} else {
which_palette = 0
}
@@ -953,10 +953,10 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
// TODO: a Wuffs (not just C) name for the
// WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY magic pixfmt constant.
status = this.swizzler.prepare!(
dst_pixfmt:args.dst.pixel_format(),
dst_palette:dst_palette,
src_pixfmt:0x47040008,
src_palette:this.palettes[which_palette][..])
dst_pixfmt: args.dst.pixel_format(),
dst_palette: dst_palette,
src_pixfmt: 0x47040008,
src_palette: this.palettes[which_palette][..])
if not status.is_ok() {
return status
}
@@ -987,7 +987,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
if lw > 8 {
return "#bad literal width"
}
this.lzw.set_literal_width!(lw:lw as base.u32)
this.lzw.set_literal_width!(lw: lw as base.u32)
this.previous_lzw_decode_ended_abruptly = true
}
@@ -1021,12 +1021,12 @@ pri func decoder.decode_id_part2?(dst ptr base.pixel_buffer, src base.io_reader,
this.compressed_wi = 0
}
while this.compressed_wi <= (4096 - 255) {
n_compressed = block_size.min(a:args.src.available())
n_compressed = block_size.min(a: args.src.available())
if n_compressed <= 0 {
break
}
compressed = args.src.take!(n:n_compressed)
this.compressed[this.compressed_wi ..].copy_from_slice!(s:compressed)
compressed = args.src.take!(n: n_compressed)
this.compressed[this.compressed_wi ..].copy_from_slice!(s: compressed)
this.compressed_wi ~sat+= n_compressed
block_size ~sat-= n_compressed
if block_size > 0 {
@@ -1037,7 +1037,7 @@ pri func decoder.decode_id_part2?(dst ptr base.pixel_buffer, src base.io_reader,
break
}
block_size = args.src.peek_u8_as_u64()
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
}
if decoder_workbuf_len_max_incl_worst_case > args.workbuf.length() {
@@ -1048,16 +1048,16 @@ pri func decoder.decode_id_part2?(dst ptr base.pixel_buffer, src base.io_reader,
if (this.compressed_ri > this.compressed_wi) or (this.compressed_wi > 4096) {
return "#internal error: inconsistent ri/wi"
}
io_bind (io:r, data:this.compressed[this.compressed_ri .. this.compressed_wi]) {
io_bind (io: r, data: this.compressed[this.compressed_ri .. this.compressed_wi]) {
mark = r.mark()
lzw_status =? this.lzw.decode_io_writer?(
dst:this.util.empty_io_writer(), src:r, workbuf:this.util.empty_slice_u8())
this.compressed_ri ~sat+= r.count_since(mark:mark)
dst: this.util.empty_io_writer(), src: r, workbuf: this.util.empty_slice_u8())
this.compressed_ri ~sat+= r.count_since(mark: mark)
}
uncompressed = this.lzw.flush!()
if uncompressed.length() > 0 {
copy_status = this.copy_to_image_buffer!(pb:args.dst, src:uncompressed)
copy_status = this.copy_to_image_buffer!(pb: args.dst, src: uncompressed)
if copy_status.is_error() {
return copy_status
}
@@ -1068,8 +1068,8 @@ pri func decoder.decode_id_part2?(dst ptr base.pixel_buffer, src base.io_reader,
// Skip any trailing blocks.
if need_block_size or (block_size > 0) {
args.src.skip?(n:block_size as base.u32)
this.skip_blocks?(src:args.src)
args.src.skip?(n: block_size as base.u32)
this.skip_blocks?(src: args.src)
}
break.outer
@@ -1123,7 +1123,7 @@ pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base.
}
width_in_bytes = (this.width as base.u64) * (bytes_per_pixel as base.u64)
tab = args.pb.plane(p:0)
tab = args.pb.plane(p: 0)
while src_ri < args.src.length() {
src = args.src[src_ri ..]
@@ -1137,7 +1137,7 @@ pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base.
// First, copy from src to that part of the frame rect that is inside
// args.pb's bounds (clipped to the image bounds).
dst = tab.row(y:this.dst_y)
dst = tab.row(y: this.dst_y)
if this.dst_y >= this.height {
dst = dst[.. 0]
} else if width_in_bytes < dst.length() {
@@ -1153,12 +1153,12 @@ pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base.
dst = dst[i ..]
}
n = this.swizzler.swizzle_interleaved!(
dst:dst, dst_palette:this.dst_palette[..], src:src)
dst: dst, dst_palette: this.dst_palette[..], src: src)
src_ri ~sat+= n
this.dst_x ~sat+= (n & 0xFFFFFFFF) as base.u32
this.dirty_max_excl_y = this.dirty_max_excl_y.max(a:this.dst_y ~sat+ 1)
this.dirty_max_excl_y = this.dirty_max_excl_y.max(a: this.dst_y ~sat+ 1)
}
if this.frame_rect_x1 <= this.dst_x {
@@ -1179,17 +1179,17 @@ pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base.
(not this.gc_has_transparent_index) and
(this.interlace > 1) {
replicate_src = tab.row(y:this.dst_y)
replicate_src = tab.row(y: this.dst_y)
replicate_y0 = this.dst_y ~sat+ 1
replicate_y1 = this.dst_y ~sat+ (interlace_count[this.interlace] as base.u32)
replicate_y1 = replicate_y1.min(a:this.frame_rect_y1)
replicate_y1 = replicate_y1.min(a: this.frame_rect_y1)
while replicate_y0 < replicate_y1 {
assert replicate_y0 < 0xFFFFFFFF via "a < b: a < c; c <= b"(c:replicate_y1)
replicate_dst = tab.row(y:replicate_y0)
replicate_dst.copy_from_slice!(s:replicate_src)
assert replicate_y0 < 0xFFFFFFFF via "a < b: a < c; c <= b"(c: replicate_y1)
replicate_dst = tab.row(y: replicate_y0)
replicate_dst.copy_from_slice!(s: replicate_src)
replicate_y0 += 1
}
this.dirty_max_excl_y = this.dirty_max_excl_y.max(a:replicate_y1)
this.dirty_max_excl_y = this.dirty_max_excl_y.max(a: replicate_y1)
}
this.dst_y ~sat+= interlace_delta[this.interlace] as base.u32
@@ -1211,7 +1211,7 @@ pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base.
// Set n to the number of pixels (i.e. the number of bytes) to skip.
n = (this.frame_rect_x1 - this.dst_x) as base.u64
n = n.min(a:args.src.length() - src_ri)
n = n.min(a: args.src.length() - src_ri)
src_ri ~sat+= n
this.dst_x ~sat+= (n & 0xFFFFFFFF) as base.u32
+8 -8
View File
@@ -38,8 +38,8 @@ pub func decoder.set_ignore_checksum!(ic base.bool) {
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(
min_incl:decoder_workbuf_len_max_incl_worst_case,
max_incl:decoder_workbuf_len_max_incl_worst_case)
min_incl: decoder_workbuf_len_max_incl_worst_case,
max_incl: decoder_workbuf_len_max_incl_worst_case)
}
pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workbuf slice base.u8) {
@@ -68,12 +68,12 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
}
flags = args.src.read_u8?()
// TODO: API for returning the header's MTIME field.
args.src.skip?(n:6)
args.src.skip?(n: 6)
// Handle FEXTRA.
if (flags & 0x04) <> 0 {
xlen = args.src.read_u16le?()
args.src.skip?(n:xlen as base.u32)
args.src.skip?(n: xlen as base.u32)
}
// Handle FNAME.
@@ -102,7 +102,7 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
// Handle FHCRC.
if (flags & 0x02) <> 0 {
args.src.skip?(n:2)
args.src.skip?(n: 2)
}
// Reserved flags bits must be zero.
@@ -113,10 +113,10 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
// Decode and checksum the DEFLATE-encoded payload.
while true {
mark = args.dst.mark()
status =? this.flate.decode_io_writer?(dst:args.dst, src:args.src, workbuf:args.workbuf)
status =? this.flate.decode_io_writer?(dst: args.dst, src: args.src, workbuf: args.workbuf)
if not this.ignore_checksum {
checksum_got = this.checksum.update!(x:args.dst.since(mark:mark))
decoded_length_got ~mod+= ((args.dst.count_since(mark:mark) & 0xFFFFFFFF) as base.u32)
checksum_got = this.checksum.update!(x: args.dst.since(mark: mark))
decoded_length_got ~mod+= ((args.dst.count_since(mark: mark) & 0xFFFFFFFF) as base.u32)
}
if status.is_ok() {
break
+15 -15
View File
@@ -74,7 +74,7 @@ pub func decoder.set_literal_width!(lw base.u32[..= 8]) {
}
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(min_incl:0, max_incl:0)
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
}
pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workbuf slice base.u8) {
@@ -96,17 +96,17 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
this.output_wi = 0
i = 0
while i < this.clear_code {
assert i < 256 via "a < b: a < c; c <= b"(c:this.clear_code)
assert i < 256 via "a < b: a < c; c <= b"(c: this.clear_code)
this.lm1s[i] = 0
this.suffixes[i][0] = i as base.u8
i += 1
}
while true {
this.read_from!(src:args.src)
this.read_from!(src: args.src)
if this.output_wi > 0 {
this.write_to?(dst:args.dst)
this.write_to?(dst: args.dst)
}
if this.read_from_return_value == 0 {
@@ -154,21 +154,21 @@ pri func decoder.read_from!(src base.io_reader) {
while true {
if n_bits < width {
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
assert n_bits < 12 via "a < b: a < c; c <= b"(c: width)
if args.src.available() >= 4 {
// Read 4 bytes, using the "Variant 4" technique of
// https://fgiesen.wordpress.com/2018/02/20/reading-bits-in-far-too-many-ways-part-2/
bits |= args.src.peek_u32le() ~mod<< n_bits
args.src.skip_fast!(actual:(31 - n_bits) >> 3, worst_case:3)
args.src.skip_fast!(actual: (31 - n_bits) >> 3, worst_case: 3)
n_bits |= 24
assert width <= n_bits via "a <= b: a <= c; c <= b"(c:12)
assert width <= n_bits via "a <= b: a <= c; c <= b"(c: 12)
assert n_bits >= width via "a >= b: b <= a"()
} else if args.src.available() <= 0 {
this.read_from_return_value = 2
break
} else {
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
if n_bits >= width {
// No-op.
@@ -177,9 +177,9 @@ pri func decoder.read_from!(src base.io_reader) {
break
} else {
bits |= args.src.peek_u8_as_u32() << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
args.src.skip_fast!(actual: 1, worst_case: 1)
n_bits += 8
assert width <= n_bits via "a <= b: a <= c; c <= b"(c:12)
assert width <= n_bits via "a <= b: a <= c; c <= b"(c: 12)
assert n_bits >= width via "a >= b: b <= a"()
// This if condition is always false, but for some unknown
@@ -192,12 +192,12 @@ pri func decoder.read_from!(src base.io_reader) {
}
}
code = bits.low_bits(n:width)
code = bits.low_bits(n: width)
bits >>= width
n_bits -= width
if code < clear_code {
assert code < 256 via "a < b: a < c; c <= b"(c:clear_code)
assert code < 256 via "a < b: a < c; c <= b"(c: clear_code)
this.output[output_wi] = code as base.u8
output_wi = (output_wi + 1) & 8191
if save_code <= 4095 {
@@ -249,12 +249,12 @@ pri func decoder.read_from!(src base.io_reader) {
steps = (this.lm1s[c] as base.u32) >> 3
while true {
assert o <= (o + 8) via "a <= (a + b): 0 <= b"(b:8)
assert o <= (o + 8) via "a <= (a + b): 0 <= b"(b: 8)
// The final "8" is redundant semantically, but helps the
// wuffs-c code generator recognize that both slices have the
// same constant length, and hence produce efficient C code.
this.output[o .. o + 8].copy_from_slice!(s:this.suffixes[c][.. 8])
this.output[o .. o + 8].copy_from_slice!(s: this.suffixes[c][.. 8])
if steps <= 0 {
break
@@ -339,7 +339,7 @@ pri func decoder.write_to?(dst base.io_writer) {
return "#internal error: inconsistent I/O"
}
s = this.output[this.output_ri .. this.output_wi]
n = args.dst.copy_from_slice!(s:s)
n = args.dst.copy_from_slice!(s: s)
if n == s.length() {
this.output_ri = 0
this.output_wi = 0
+6 -6
View File
@@ -53,8 +53,8 @@ pub func decoder.add_dictionary!(dict slice base.u8) {
if this.header_complete {
this.bad_call_sequence = true
} else {
this.dict_id_got = this.dict_id_hasher.update!(x:args.dict)
this.flate.add_history!(hist:args.dict)
this.dict_id_got = this.dict_id_hasher.update!(x: args.dict)
this.flate.add_history!(hist: args.dict)
}
this.got_dictionary = true
}
@@ -65,8 +65,8 @@ pub func decoder.set_ignore_checksum!(ic base.bool) {
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(
min_incl:decoder_workbuf_len_max_incl_worst_case,
max_incl:decoder_workbuf_len_max_incl_worst_case)
min_incl: decoder_workbuf_len_max_incl_worst_case,
max_incl: decoder_workbuf_len_max_incl_worst_case)
}
pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workbuf slice base.u8) {
@@ -109,9 +109,9 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
// Decode and checksum the DEFLATE-encoded payload.
while true {
mark = args.dst.mark()
status =? this.flate.decode_io_writer?(dst:args.dst, src:args.src, workbuf:args.workbuf)
status =? this.flate.decode_io_writer?(dst: args.dst, src: args.src, workbuf: args.workbuf)
if not this.ignore_checksum {
checksum_got = this.checksum.update!(x:args.dst.since(mark:mark))
checksum_got = this.checksum.update!(x: args.dst.since(mark: mark))
}
if status.is_ok() {
break