From c1789e0065c91f371e064395307a2d2cb73a6e5b Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 14 Oct 2017 11:24:40 +1100 Subject: [PATCH] Rename some variables for clarity. --- gen/c/std/flate.c | 68 ++++++++++++++++++------------------ gen/c/std/gif.c | 16 ++++----- gen/h/std/flate.h | 6 ++-- gen/h/std/gif.h | 2 +- std/flate/decode_flate.puffs | 45 ++++++++++++------------ std/gif/decode_lzw.puffs | 6 ++-- 6 files changed, 71 insertions(+), 72 deletions(-) diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index 3e52c156..70b7f576 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -182,7 +182,7 @@ typedef struct { struct { uint32_t coro_susp_point; puffs_flate_status v_z; - uint64_t v_n; + uint64_t v_n_copied; uint32_t v_already_full; } c_decode[1]; struct { @@ -193,7 +193,7 @@ typedef struct { struct { uint32_t coro_susp_point; uint32_t v_length; - uint32_t v_n; + uint32_t v_n_copied; uint64_t scratch; } c_decode_uncompressed[1]; struct { @@ -208,7 +208,7 @@ typedef struct { uint32_t v_redir_mask; uint32_t v_length; uint32_t v_distance; - uint32_t v_n; + uint32_t v_n_copied; uint32_t v_hlen; uint32_t v_hdist; } c_decode_huffman[1]; @@ -743,7 +743,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self, puffs_flate_status v_z; puffs_base_slice_u8 v_written; - uint64_t v_n; + uint64_t v_n_copied; uint32_t v_already_full; uint8_t* b_wptr_dst = NULL; @@ -769,7 +769,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self, if (coro_susp_point) { v_z = self->private_impl.c_decode[0].v_z; v_written = ((puffs_base_slice_u8){}); - v_n = self->private_impl.c_decode[0].v_n; + v_n_copied = self->private_impl.c_decode[0].v_n_copied; v_already_full = self->private_impl.c_decode[0].v_already_full; } switch (coro_susp_point) { @@ -820,20 +820,20 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self, v_written); self->private_impl.f_history_index = 32768; } else { - v_n = puffs_base_slice_u8_copy_from_slice( + v_n_copied = puffs_base_slice_u8_copy_from_slice( puffs_base_slice_u8_subslice_i( ((puffs_base_slice_u8){.ptr = self->private_impl.f_history, .len = 32768}), self->private_impl.f_history_index & 32767), v_written); - if (v_n < ((uint64_t)(v_written.len))) { - v_written = puffs_base_slice_u8_subslice_i(v_written, v_n); - v_n = puffs_base_slice_u8_copy_from_slice( + if (v_n_copied < ((uint64_t)(v_written.len))) { + v_written = puffs_base_slice_u8_subslice_i(v_written, v_n_copied); + v_n_copied = puffs_base_slice_u8_copy_from_slice( ((puffs_base_slice_u8){.ptr = self->private_impl.f_history, .len = 32768}), v_written); self->private_impl.f_history_index = - (((uint32_t)((v_n & 32767))) + 32768); + (((uint32_t)((v_n_copied & 32767))) + 32768); } else { v_already_full = 0; if (self->private_impl.f_history_index >= 32768) { @@ -841,7 +841,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self, } self->private_impl.f_history_index = ((self->private_impl.f_history_index & 32767) + - ((uint32_t)((v_n & 32767))) + v_already_full); + ((uint32_t)((v_n_copied & 32767))) + v_already_full); } } status = v_z; @@ -858,7 +858,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self, suspend: self->private_impl.c_decode[0].coro_susp_point = coro_susp_point; self->private_impl.c_decode[0].v_z = v_z; - self->private_impl.c_decode[0].v_n = v_n; + self->private_impl.c_decode[0].v_n_copied = v_n_copied; self->private_impl.c_decode[0].v_already_full = v_already_full; exit: @@ -1066,7 +1066,7 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed( puffs_flate_status status = PUFFS_FLATE_STATUS_OK; uint32_t v_length; - uint32_t v_n; + uint32_t v_n_copied; uint8_t* b_wptr_dst = NULL; uint8_t* b_wstart_dst = NULL; @@ -1106,7 +1106,7 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed( self->private_impl.c_decode_uncompressed[0].coro_susp_point; if (coro_susp_point) { v_length = self->private_impl.c_decode_uncompressed[0].v_length; - v_n = self->private_impl.c_decode_uncompressed[0].v_n; + v_n_copied = self->private_impl.c_decode_uncompressed[0].v_n_copied; } switch (coro_susp_point) { PUFFS_COROUTINE_SUSPENSION_POINT(0); @@ -1151,13 +1151,13 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed( } v_length = ((v_length) & ((1 << (16)) - 1)); while (true) { - v_n = puffs_base_writer1_copy_from_reader32( + v_n_copied = puffs_base_writer1_copy_from_reader32( &b_wptr_dst, b_wend_dst, &b_rptr_src, b_rend_src, v_length); - if (v_length <= v_n) { + if (v_length <= v_n_copied) { v_length = 0; goto label_0_break; } - v_length -= v_n; + v_length -= v_n_copied; if (((uint64_t)(b_wend_dst - b_wptr_dst)) == 0) { status = PUFFS_FLATE_SUSPENSION_SHORT_WRITE; PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); @@ -1178,7 +1178,7 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed( suspend: self->private_impl.c_decode_uncompressed[0].coro_susp_point = coro_susp_point; self->private_impl.c_decode_uncompressed[0].v_length = v_length; - self->private_impl.c_decode_uncompressed[0].v_n = v_n; + self->private_impl.c_decode_uncompressed[0].v_n_copied = v_n_copied; exit: if (a_dst.buf) { @@ -1233,7 +1233,7 @@ puffs_flate_status puffs_flate_decoder_decode_huffman( uint32_t v_redir_mask; uint32_t v_length; uint32_t v_distance; - uint32_t v_n; + uint32_t v_n_copied; uint32_t v_hlen; uint32_t v_hdist; @@ -1285,7 +1285,7 @@ puffs_flate_status puffs_flate_decoder_decode_huffman( v_redir_mask = self->private_impl.c_decode_huffman[0].v_redir_mask; v_length = self->private_impl.c_decode_huffman[0].v_length; v_distance = self->private_impl.c_decode_huffman[0].v_distance; - v_n = self->private_impl.c_decode_huffman[0].v_n; + v_n_copied = self->private_impl.c_decode_huffman[0].v_n_copied; v_hlen = self->private_impl.c_decode_huffman[0].v_hlen; v_hdist = self->private_impl.c_decode_huffman[0].v_hdist; } @@ -1460,9 +1460,9 @@ puffs_flate_status puffs_flate_decoder_decode_huffman( 32767); v_bits >>= v_table_entry_n_bits; v_n_bits -= v_table_entry_n_bits; + v_n_copied = 0; label_5_continue:; while (true) { - v_n = 0; if (((uint64_t)(v_distance)) > ((uint64_t)(b_wptr_dst - b_wstart_dst))) { v_hlen = 0; @@ -1481,20 +1481,20 @@ puffs_flate_status puffs_flate_decoder_decode_huffman( } v_hdist = ((self->private_impl.f_history_index - v_hdist) & 32767); while (true) { - v_n = puffs_base_writer1_copy_from_slice32( + v_n_copied = puffs_base_writer1_copy_from_slice32( &b_wptr_dst, b_wend_dst, puffs_base_slice_u8_subslice_i( ((puffs_base_slice_u8){.ptr = self->private_impl.f_history, .len = 32768}), v_hdist), v_hlen); - if (v_hlen <= v_n) { + if (v_hlen <= v_n_copied) { v_hlen = 0; goto label_6_break; } - if (v_n > 0) { - v_hlen -= v_n; - v_hdist = ((v_hdist + (v_n & 32767)) & 32767); + if (v_n_copied > 0) { + v_hlen -= v_n_copied; + v_hdist = ((v_hdist + (v_n_copied & 32767)) & 32767); if (v_hdist == 0) { goto label_6_break; } @@ -1505,19 +1505,19 @@ puffs_flate_status puffs_flate_decoder_decode_huffman( label_6_break:; if (v_hlen > 0) { while (true) { - v_n = puffs_base_writer1_copy_from_slice32( + v_n_copied = puffs_base_writer1_copy_from_slice32( &b_wptr_dst, b_wend_dst, puffs_base_slice_u8_subslice_i( ((puffs_base_slice_u8){ .ptr = self->private_impl.f_history, .len = 32768}), v_hdist), v_hlen); - if (v_hlen <= v_n) { + if (v_hlen <= v_n_copied) { v_hlen = 0; goto label_7_break; } - v_hlen -= v_n; - v_hdist = ((v_hdist + (v_n & 32767)) & 32767); + v_hlen -= v_n_copied; + v_hdist = ((v_hdist + (v_n_copied & 32767)) & 32767); status = PUFFS_FLATE_SUSPENSION_SHORT_WRITE; PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9); } @@ -1527,13 +1527,13 @@ puffs_flate_status puffs_flate_decoder_decode_huffman( goto label_5_continue; } } - v_n = puffs_base_writer1_copy_from_history32( + v_n_copied = puffs_base_writer1_copy_from_history32( &b_wptr_dst, b_wstart_dst, b_wend_dst, v_distance, v_length); - if (v_length <= v_n) { + if (v_length <= v_n_copied) { v_length = 0; goto label_5_break; } - v_length -= v_n; + v_length -= v_n_copied; status = PUFFS_FLATE_SUSPENSION_SHORT_WRITE; PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10); } @@ -1563,7 +1563,7 @@ suspend: self->private_impl.c_decode_huffman[0].v_redir_mask = v_redir_mask; self->private_impl.c_decode_huffman[0].v_length = v_length; self->private_impl.c_decode_huffman[0].v_distance = v_distance; - self->private_impl.c_decode_huffman[0].v_n = v_n; + self->private_impl.c_decode_huffman[0].v_n_copied = v_n_copied; self->private_impl.c_decode_huffman[0].v_hlen = v_hlen; self->private_impl.c_decode_huffman[0].v_hdist = v_hdist; diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index d9effb81..a277e5e7 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -165,7 +165,7 @@ typedef struct { uint32_t v_code; uint32_t v_s; uint32_t v_c; - uint64_t v_n; + uint64_t v_n_copied; } c_decode[1]; } private_impl; } puffs_gif_lzw_decoder; @@ -1338,7 +1338,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self, uint32_t v_s; uint32_t v_c; puffs_base_slice_u8 v_expansion; - uint64_t v_n; + uint64_t v_n_copied; uint8_t* b_wptr_dst = NULL; uint8_t* b_wstart_dst = NULL; @@ -1387,7 +1387,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self, v_s = self->private_impl.c_decode[0].v_s; v_c = self->private_impl.c_decode[0].v_c; v_expansion = ((puffs_base_slice_u8){}); - v_n = self->private_impl.c_decode[0].v_n; + v_n_copied = self->private_impl.c_decode[0].v_n_copied; } switch (coro_susp_point) { PUFFS_COROUTINE_SUSPENSION_POINT(0); @@ -1458,12 +1458,12 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self, ((puffs_base_slice_u8){.ptr = self->private_impl.f_stack, .len = 4096}), v_s); - v_n = puffs_base_writer1_copy_from_slice(&b_wptr_dst, b_wend_dst, - v_expansion); - if (v_n == ((uint64_t)(v_expansion.len))) { + v_n_copied = puffs_base_writer1_copy_from_slice( + &b_wptr_dst, b_wend_dst, v_expansion); + if (v_n_copied == ((uint64_t)(v_expansion.len))) { goto label_1_break; } - v_s = ((v_s + ((uint32_t)((v_n & 4095)))) & 4095); + v_s = ((v_s + ((uint32_t)((v_n_copied & 4095)))) & 4095); status = PUFFS_GIF_SUSPENSION_SHORT_WRITE; PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); } @@ -1505,7 +1505,7 @@ suspend: self->private_impl.c_decode[0].v_code = v_code; self->private_impl.c_decode[0].v_s = v_s; self->private_impl.c_decode[0].v_c = v_c; - self->private_impl.c_decode[0].v_n = v_n; + self->private_impl.c_decode[0].v_n_copied = v_n_copied; exit: if (a_dst.buf) { diff --git a/gen/h/std/flate.h b/gen/h/std/flate.h index 1322d15a..9b6448e8 100644 --- a/gen/h/std/flate.h +++ b/gen/h/std/flate.h @@ -182,7 +182,7 @@ typedef struct { struct { uint32_t coro_susp_point; puffs_flate_status v_z; - uint64_t v_n; + uint64_t v_n_copied; uint32_t v_already_full; } c_decode[1]; struct { @@ -193,7 +193,7 @@ typedef struct { struct { uint32_t coro_susp_point; uint32_t v_length; - uint32_t v_n; + uint32_t v_n_copied; uint64_t scratch; } c_decode_uncompressed[1]; struct { @@ -208,7 +208,7 @@ typedef struct { uint32_t v_redir_mask; uint32_t v_length; uint32_t v_distance; - uint32_t v_n; + uint32_t v_n_copied; uint32_t v_hlen; uint32_t v_hdist; } c_decode_huffman[1]; diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index cba4bdaa..3efc0fe1 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -165,7 +165,7 @@ typedef struct { uint32_t v_code; uint32_t v_s; uint32_t v_c; - uint64_t v_n; + uint64_t v_n_copied; } c_decode[1]; } private_impl; } puffs_gif_lzw_decoder; diff --git a/std/flate/decode_flate.puffs b/std/flate/decode_flate.puffs index 23b107d4..0194f095 100644 --- a/std/flate/decode_flate.puffs +++ b/std/flate/decode_flate.puffs @@ -137,8 +137,8 @@ pub func decoder.decode?(dst writer1, src reader1)() { } else { // Otherwise, append written to the history ringbuffer starting at // the previous history_index (modulo 0x8000). - var n u64 = this.history[this.history_index & 0x7FFF:].copy_from_slice(s:written) - if n < written.length() { + var n_copied u64 = this.history[this.history_index & 0x7FFF:].copy_from_slice(s:written) + if n_copied < written.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 not all of b_slice was copied. @@ -146,21 +146,21 @@ pub func decoder.decode?(dst writer1, src reader1)() { // In terms of the history ringbuffer, that means that we have // to wrap around and copy the remainder of written over the // start of the history ringbuffer. - written = written[n:] - n = this.history[:].copy_from_slice(s:written) + written = written[n_copied:] + n_copied = this.history[:].copy_from_slice(s:written) // 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 maintain that the history ringbuffer is full // if and only if history_index >= 0x8000. - this.history_index = ((n & 0x7FFF) as u32) + 0x8000 + this.history_index = ((n_copied & 0x7FFF) as u32) + 0x8000 } else { // We didn't need to wrap around. var already_full u32[..0x8000] if this.history_index >= 0x8000 { already_full = 0x8000 } - this.history_index = (this.history_index & 0x7FFF) + ((n & 0x7FFF) as u32) + already_full + this.history_index = (this.history_index & 0x7FFF) + ((n_copied & 0x7FFF) as u32) + already_full } } return z @@ -209,12 +209,12 @@ pri func decoder.decode_uncompressed?(dst writer1, src reader1)() { } length = length.low_bits(n:16) while true { - var n u32 = in.dst.copy_from_reader32(r:in.src, length:length) - if length <= n { + var n_copied u32 = in.dst.copy_from_reader32(r:in.src, length:length) + if length <= n_copied { length = 0 break } - length -= n + length -= n_copied if in.dst.available() == 0 { // TODO: "closed for writes" instead? return suspension "short write" @@ -358,9 +358,8 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() { bits >>= table_entry_n_bits n_bits -= table_entry_n_bits + var n_copied u32 while true { - var n u32 - // Copy from this.history. if (distance as u64) > in.dst.length() { // Set (hlen, hdist) to be the length-distance pair to copy @@ -384,15 +383,15 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() { // Copy from hdist to the end of this.history. while true { - n = in.dst.copy_from_slice32(s:this.history[hdist:], length:hlen) - if hlen <= n { + n_copied = in.dst.copy_from_slice32(s:this.history[hdist:], length:hlen) + if hlen <= n_copied { hlen = 0 break } - if n > 0 { - hlen -= n + if n_copied > 0 { + hlen -= n_copied // TODO: a "~+" tilde-operator that ignores overflow. - hdist = (hdist + (n & 0x7FFF)) & 0x7FFF + hdist = (hdist + (n_copied & 0x7FFF)) & 0x7FFF if hdist == 0 { // Wrap around the this.history ringbuffer. break @@ -410,13 +409,13 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() { // Copy from the start of this.history, if we wrapped around. if hlen > 0 { while true { - n = in.dst.copy_from_slice32(s:this.history[hdist:], length:hlen) - if hlen <= n { + n_copied = in.dst.copy_from_slice32(s:this.history[hdist:], length:hlen) + if hlen <= n_copied { hlen = 0 break } - hlen -= n - hdist = (hdist + (n & 0x7FFF)) & 0x7FFF + hlen -= n_copied + hdist = (hdist + (n_copied & 0x7FFF)) & 0x7FFF // TODO: "closed for writes" instead? return suspension "short write" } @@ -429,12 +428,12 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() { } // Copy from in.dst. - n = in.dst.copy_from_history32(distance:distance, length:length) - if length <= n { + n_copied = in.dst.copy_from_history32(distance:distance, length:length) + if length <= n_copied { length = 0 break } - length -= n + length -= n_copied // TODO: "closed for writes" instead? return suspension "short write" } diff --git a/std/gif/decode_lzw.puffs b/std/gif/decode_lzw.puffs index f1a48fc0..9ae91ada 100644 --- a/std/gif/decode_lzw.puffs +++ b/std/gif/decode_lzw.puffs @@ -111,11 +111,11 @@ pub func lzw_decoder.decode?(dst writer1, src reader1)() { { var expansion[] u8 = this.stack[s:] // TODO: "x:" instead of "s:" should be a compiler error. - var n u64 = in.dst.copy_from_slice(x:expansion) - if n == expansion.length() { + var n_copied u64 = in.dst.copy_from_slice(x:expansion) + if n_copied == expansion.length() { break } - s = (s + ((n & 4095) as u32)) & 4095 + s = (s + ((n_copied & 4095) as u32)) & 4095 // TODO: "closed for writes" instead? return suspension "short write" }