Rename u32, io_reader, etc to base.u32, etc

This commit is contained in:
Nigel Tao committed 2018-04-12 21:49:17 +10:00
1 parent fee97df698
commit f95239f6e0
24 files changed
+394 -392

No files matched your search

+29 -29
View File
@@ -18,33 +18,33 @@ pub error "LZW code is out of range"
pub error "LZW prefix chain is cyclical"
pri struct lzw_decoder?(
literal_width u32[2..8] = 8,
stack array[4096] u8,
suffixes array[4096] u8,
prefixes array[4096] u16[..4095],
literal_width base.u32[2..8] = 8,
stack array[4096] base.u8,
suffixes array[4096] base.u8,
prefixes array[4096] base.u16[..4095],
)
pri func lzw_decoder.set_literal_width!(lw u32[2..8] = 8)() {
pri func lzw_decoder.set_literal_width!(lw base.u32[2..8] = 8)() {
this.literal_width = in.lw
}
pri func lzw_decoder.decode?(dst io_writer, src io_reader)() {
pri func lzw_decoder.decode?(dst base.io_writer, src base.io_reader)() {
// These variables don't change over the lifetime of this func.
var clear_code u32[4..256] = (1 as u32) << this.literal_width
var end_code u32[5..257] = clear_code + 1
var clear_code base.u32[4..256] = (1 as base.u32) << this.literal_width
var end_code base.u32[5..257] = clear_code + 1
// These variables do change.
//
// save_code is the code for which, after decoding a code, we save what the
// next back-reference expands to. The README.md file also calls this value
// `max`. 4096 means do not save.
var save_code u32[..4096] = end_code
var prev_code u32[..4095]
var width u32[..12] = this.literal_width + 1
var save_code base.u32[..4096] = end_code
var prev_code base.u32[..4095]
var width base.u32[..12] = this.literal_width + 1
// These variables yield src's bits in Least Significant Bits order.
var bits u32
var n_bits u32
var bits base.u32
var n_bits base.u32
while true,
pre n_bits < 8,
@@ -55,19 +55,19 @@ pri func lzw_decoder.decode?(dst io_writer, src io_reader)() {
post n_bits >= width,
{
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
bits |= (in.src.read_u8?() as u32) << n_bits
bits |= (in.src.read_u8?() as base.u32) << n_bits
n_bits += 8
}
var code u32[..4095] = bits.low_bits(n:width)
var code base.u32[..4095] = 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)
in.dst.write_u8?(x:code as u8)
in.dst.write_u8?(x:code as base.u8)
if save_code <= 4095 {
this.suffixes[save_code] = code as u8
this.prefixes[save_code] = prev_code as u16
this.suffixes[save_code] = code as base.u8
this.prefixes[save_code] = prev_code as base.u16
}
} else if code == clear_code {
@@ -80,8 +80,8 @@ pri func lzw_decoder.decode?(dst io_writer, src io_reader)() {
return
} else if code <= save_code {
var s u32[..4095] = 4095
var c u32[..4095] = code
var s base.u32[..4095] = 4095
var c base.u32[..4095] = code
if code == save_code {
s -= 1
@@ -97,31 +97,31 @@ pri func lzw_decoder.decode?(dst io_writer, src io_reader)() {
return error "LZW prefix chain is cyclical"
}
s -= 1
c = this.prefixes[c] as u32
c = this.prefixes[c] as base.u32
}
this.stack[s] = c as u8
this.stack[s] = c as base.u8
if code == save_code {
this.stack[4095] = c as u8
this.stack[4095] = c as base.u8
}
while true,
inv n_bits < 8,
inv c < 256,
{
var expansion slice u8 = this.stack[s:]
var n_copied u64 = in.dst.copy_from_slice(s:expansion)
var expansion slice base.u8 = this.stack[s:]
var n_copied base.u64 = in.dst.copy_from_slice(s:expansion)
if n_copied == expansion.length() {
break
}
s = (s + ((n_copied & 4095) as u32)) & 4095
s = (s + ((n_copied & 4095) as base.u32)) & 4095
// TODO: "closed for writes" instead?
yield suspension "short write"
}
if save_code <= 4095 {
this.suffixes[save_code] = c as u8
this.prefixes[save_code] = prev_code as u16
this.suffixes[save_code] = c as base.u8
this.prefixes[save_code] = prev_code as base.u16
}
} else {
@@ -130,7 +130,7 @@ pri func lzw_decoder.decode?(dst io_writer, src io_reader)() {
if save_code <= 4095 {
save_code += 1
if (save_code == ((1 as u32) << width)) and (width < 12) {
if (save_code == ((1 as base.u32) << width)) and (width < 12) {
width += 1
}
}