Skip to content

Commit

Permalink
base: rename min/max arg to no_more/less_than
Browse files Browse the repository at this point in the history
  • Loading branch information
nigeltao committed Apr 16, 2023
1 parent 95630b6 commit bc86394
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The dot points below probably aren't of interest unless you're _writing_ Wuffs
code (instead of writing C/C++ code that _uses_ Wuffs' standard library).

- Added read-only type decorators: `roarray`, `roslice` and `rotable`.
- Renamed `base` `min/max` argument from `a` to `no_more/less_than`.
- Wuffs struct private data now needs a "+" between the "()" pairs.
- `wuffsfmt` double-indents hanging lines and each indent is now 4 spaces (not
a tab).
Expand Down
16 changes: 8 additions & 8 deletions lang/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,23 +347,23 @@ var Funcs = [][]string{
var funcsOther = [...]string{
"u8.high_bits(n: u32[..= 7]) u8",
"u8.low_bits(n: u32[..= 7]) u8",
"u8.max(a: u8) u8",
"u8.min(a: u8) u8",
"u8.max(no_less_than: u8) u8",
"u8.min(no_more_than: u8) u8",

"u16.high_bits(n: u32[..= 15]) u16",
"u16.low_bits(n: u32[..= 15]) u16",
"u16.max(a: u16) u16",
"u16.min(a: u16) u16",
"u16.max(no_less_than: u16) u16",
"u16.min(no_more_than: u16) u16",

"u32.high_bits(n: u32[..= 31]) u32",
"u32.low_bits(n: u32[..= 31]) u32",
"u32.max(a: u32) u32",
"u32.min(a: u32) u32",
"u32.max(no_less_than: u32) u32",
"u32.min(no_more_than: u32) u32",

"u64.high_bits(n: u32[..= 63]) u64",
"u64.low_bits(n: u32[..= 63]) u64",
"u64.max(a: u64) u64",
"u64.min(a: u64) u64",
"u64.max(no_less_than: u64) u64",
"u64.min(no_more_than: u64) u64",

// ---- utility

Expand Down
20 changes: 10 additions & 10 deletions std/bmp/decode_bmp.wuffs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
return "#unsupported BMP file"
}
n = args.src.length() / (src_bytes_per_pixel as base.u64)
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64)
n = n.min(no_more_than: (this.width ~mod- this.dst_x) as base.u64)
j = n
while j >= 8 {
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
Expand Down Expand Up @@ -770,7 +770,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
p0 = (p0 & 255) + 0x04
chunk_count -= 1
} endwhile
p0 = p0.min(a: this.rle_length)
p0 = p0.min(no_more_than: this.rle_length)
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst,
dst_palette: dst_palette,
Expand Down Expand Up @@ -930,7 +930,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea

// -------- BEGIN convert to PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE.
p1_temp = this.width ~mod- this.dst_x
p1 = p1_temp.min(a: 256)
p1 = p1_temp.min(no_more_than: 256)
p0 = 0
while p0 < p1 {
assert p0 < 256 via "a < b: a < c; c <= b"(c: p1)
Expand Down Expand Up @@ -1057,20 +1057,20 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
}
while (chunk_count >= 64) and (args.src.length() >= 256) {
args.src.skip_u32_fast!(actual: 256, worst_case: 256)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 64))
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 64))
chunk_count -= 64
} endwhile
while (chunk_count >= 8) and (args.src.length() >= 32) {
args.src.skip_u32_fast!(actual: 32, worst_case: 32)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 8))
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 8))
chunk_count -= 8
} endwhile
while chunk_count > 0 {
if args.src.length() < 4 {
return "@internal note: short read"
}
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 1))
this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 1))
chunk_count -= 1
} endwhile
continue.loop
Expand All @@ -1082,7 +1082,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
// Calculate the remaining number of 32-bit chunks. At 1 bit per
// pixel there are 32 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32
chunk_count = chunk_count.min(a: 16) // Keep p0 <= 512.
chunk_count = chunk_count.min(no_more_than: 16) // Keep p0 <= 512.
while (chunk_count > 0) and (args.src.length() >= 4) {
chunk_bits = args.src.peek_u32be()
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
Expand Down Expand Up @@ -1126,7 +1126,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
// Calculate the remaining number of 32-bit chunks. At 2 bits per
// pixel there are 16 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 15) / 16
chunk_count = chunk_count.min(a: 32) // Keep p0 <= 512.
chunk_count = chunk_count.min(no_more_than: 32) // Keep p0 <= 512.
while (chunk_count > 0) and (args.src.length() >= 4) {
chunk_bits = args.src.peek_u32be()
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
Expand Down Expand Up @@ -1154,7 +1154,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
// Calculate the remaining number of 32-bit chunks. At 4 bits per
// pixel there are 8 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 7) / 8
chunk_count = chunk_count.min(a: 64) // Keep p0 <= 512.
chunk_count = chunk_count.min(no_more_than: 64) // Keep p0 <= 512.
while (chunk_count > 0) and (args.src.length() >= 4) {
chunk_bits = args.src.peek_u32be()
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
Expand All @@ -1171,7 +1171,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
} endwhile
}

p0 = p0.min(a: this.width ~sat- this.dst_x)
p0 = p0.min(no_more_than: this.width ~sat- this.dst_x)
n = this.swizzler.swizzle_interleaved_from_slice!(
dst: dst,
dst_palette: dst_palette,
Expand Down
4 changes: 2 additions & 2 deletions std/cbor/decode_cbor.wuffs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
yield? base."$short write"
continue
}
n64 = string_length.min(a: args.src.length())
n64 = string_length.min(no_more_than: args.src.length())
token_length = (n64 & 0xFFFF) as base.u32
if n64 > 0xFFFF {
token_length = 0xFFFF
Expand Down Expand Up @@ -413,7 +413,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
yield? base."$short write"
continue
}
n64 = string_length.min(a: 0xFFFF)
n64 = string_length.min(no_more_than: 0xFFFF)
n64 = args.src.valid_utf_8_length(up_to: n64)
token_length = (n64 & 0xFFFF) as base.u32
if token_length <= 0 {
Expand Down
38 changes: 19 additions & 19 deletions std/gif/decode_gif.wuffs
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ pub func decoder.num_decoded_frames() base.u64 {
}

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.
// The "foo.min(no_more_than: 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(no_more_than: this.width),
min_incl_y: this.frame_rect_y0.min(no_more_than: this.height),
max_excl_x: this.frame_rect_x1.min(no_more_than: this.width),
max_excl_y: this.dirty_max_excl_y.min(no_more_than: this.height))
}

pub func decoder.workbuf_len() base.range_ii_u64 {
Expand Down Expand Up @@ -390,13 +390,13 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
}

if args.dst <> nullptr {
// The "foo.min(a:this.width_or_height)" calls clip the nominal
// frame_rect to the image_rect.
// The "foo.min(no_more_than: this.width_or_height)" calls clip the
// nominal frame_rect to the image_rect.
args.dst.set!(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)),
min_incl_x: this.frame_rect_x0.min(no_more_than: this.width),
min_incl_y: this.frame_rect_y0.min(no_more_than: this.height),
max_excl_x: this.frame_rect_x1.min(no_more_than: this.width),
max_excl_y: this.frame_rect_y1.min(no_more_than: this.height)),
duration: this.gc_duration,
index: this.num_decoded_frame_configs_value,
io_position: this.frame_config_io_position,
Expand Down Expand Up @@ -804,8 +804,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.num_decoded_frame_configs_value == 0) and (not this.quirks[QUIRK_IMAGE_BOUNDS_ARE_STRICT - QUIRKS_BASE]) {
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(no_less_than: this.frame_rect_x1)
this.height = this.height.max(no_less_than: this.frame_rect_y1)
}
}

Expand Down Expand Up @@ -936,7 +936,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
this.compressed_wi = 0
}
while this.compressed_wi <= (4096 - 255) {
n_compressed = block_size.min(a: args.src.length())
n_compressed = block_size.min(no_more_than: args.src.length())
if n_compressed <= 0 {
break
}
Expand Down Expand Up @@ -1078,7 +1078,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
src_ri ~sat+= n
this.dst_x ~sat+= (n & 0xFFFF_FFFF) 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(no_less_than: this.dst_y ~sat+ 1)
}

if this.frame_rect_x1 <= this.dst_x {
Expand All @@ -1102,14 +1102,14 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
replicate_src = tab.row_u32(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(no_more_than: this.frame_rect_y1)
while replicate_y0 < replicate_y1 {
assert replicate_y0 < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: replicate_y1)
replicate_dst = tab.row_u32(y: replicate_y0)
replicate_dst.copy_from_slice!(s: replicate_src)
replicate_y0 += 1
} endwhile
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(no_less_than: replicate_y1)
}

this.dst_y ~sat+= INTERLACE_DELTA[this.interlace] as base.u32
Expand All @@ -1131,7 +1131,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas

// 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(no_more_than: args.src.length() - src_ri)

src_ri ~sat+= n
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
Expand Down
2 changes: 1 addition & 1 deletion std/nie/decode_nie.wuffs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
assert src_bytes_per_pixel > 0
}
n = args.src.length() / (src_bytes_per_pixel as base.u64)
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64)
n = n.min(no_more_than: (this.width ~mod- this.dst_x) as base.u64)
j = n
while j >= 8 {
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
Expand Down
6 changes: 3 additions & 3 deletions std/png/decode_filter_fallback.wuffs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pri func decoder.filter_2!(curr: slice base.u8, prev: slice base.u8) {
var n : base.u64
var i : base.u64

n = args.curr.length().min(a: args.prev.length())
n = args.curr.length().min(no_more_than: args.prev.length())
i = 0
while i < n,
inv n <= args.curr.length(),
Expand Down Expand Up @@ -122,7 +122,7 @@ pri func decoder.filter_3!(curr: slice base.u8, prev: slice base.u8),
} endwhile

} else {
n = args.curr.length().min(a: args.prev.length())
n = args.curr.length().min(no_more_than: args.prev.length())
i = 0
while (i < n) and (i < filter_distance),
inv n <= args.curr.length(),
Expand Down Expand Up @@ -238,7 +238,7 @@ pri func decoder.filter_4!(curr: slice base.u8, prev: slice base.u8),
var pc : base.u32

filter_distance = this.filter_distance as base.u64
n = args.curr.length().min(a: args.prev.length())
n = args.curr.length().min(no_more_than: args.prev.length())
i = 0
while (i < n) and (i < filter_distance),
inv n <= args.curr.length(),
Expand Down
2 changes: 1 addition & 1 deletion std/tga/decode_tga.wuffs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
if lit_length > 0 {
mark = args.src.mark()
num_pixels64 = args.src.length() / (this.src_bytes_per_pixel as base.u64)
num_pixels32 = num_pixels64.min(a: lit_length as base.u64) as base.u32
num_pixels32 = num_pixels64.min(no_more_than: lit_length as base.u64) as base.u32
num_dst_bytes = (num_pixels32 as base.u64) * dst_bytes_per_pixel
num_src_bytes = num_pixels32 * this.src_bytes_per_pixel
args.src.skip_u32?(n: num_src_bytes)
Expand Down

0 comments on commit bc86394

Please sign in to comment.