mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Introduce "array[N] T" and "slice T" type syntax
This commit is contained in:
1 parent
2b91e7861c
commit
d33db6dae0
15 files changed
+83
-68
No files matched your search
@@ -24,7 +24,7 @@ pub struct ieee?(
|
||||
// TODO: should it be ? instead of ! because it's public, and might need a way
|
||||
// to signal "initializer not called"? Should the return type, in the generated
|
||||
// C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"?
|
||||
pub func ieee.update(x[] u8)(checksum u32) {
|
||||
pub func ieee.update(x slice u8)(checksum u32) {
|
||||
var s u32 = 0xFFFFFFFF ^ this.state
|
||||
|
||||
iterate.1 (p ptr u8:in.x) {
|
||||
@@ -37,7 +37,7 @@ pub func ieee.update(x[] u8)(checksum u32) {
|
||||
|
||||
// The table below was created by script/print-crc32-magic-numbers.go.
|
||||
|
||||
pri const ieee_table[256] u32 = $(
|
||||
pri const ieee_table array[256] u32 = $(
|
||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
||||
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
|
||||
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
// limitations under the License.
|
||||
|
||||
// code_order is defined in the RFC section 3.2.7.
|
||||
pri const code_order[19] u8[..18] = $(
|
||||
pri const code_order array[19] u8[..18] = $(
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
|
||||
)
|
||||
|
||||
// reverse8 reverses the bits in a byte.
|
||||
pri const reverse8[256] u8 = $(
|
||||
pri const reverse8 array[256] u8 = $(
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, // 0x00 - 0x07
|
||||
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, // 0x08 - 0x0F
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, // 0x10 - 0x17
|
||||
|
||||
@@ -41,14 +41,14 @@ pri error "internal error: inconsistent n_bits"
|
||||
//
|
||||
// Some trailing elements are 0x08000000. Bit 27 indicates an invalid value.
|
||||
|
||||
pri const lcode_magic_numbers[32] u32 = $(
|
||||
pri const lcode_magic_numbers array[32] u32 = $(
|
||||
0x40000300, 0x40000400, 0x40000500, 0x40000600, 0x40000700, 0x40000800, 0x40000900, 0x40000A00,
|
||||
0x40000B10, 0x40000D10, 0x40000F10, 0x40001110, 0x40001320, 0x40001720, 0x40001B20, 0x40001F20,
|
||||
0x40002330, 0x40002B30, 0x40003330, 0x40003B30, 0x40004340, 0x40005340, 0x40006340, 0x40007340,
|
||||
0x40008350, 0x4000A350, 0x4000C350, 0x4000E350, 0x40010200, 0x08000000, 0x08000000, 0x08000000,
|
||||
)
|
||||
|
||||
pri const dcode_magic_numbers[32] u32 = $(
|
||||
pri const dcode_magic_numbers array[32] u32 = $(
|
||||
0x40000000, 0x40000100, 0x40000200, 0x40000300, 0x40000410, 0x40000610, 0x40000820, 0x40000C20,
|
||||
0x40001030, 0x40001830, 0x40002040, 0x40003040, 0x40004050, 0x40006050, 0x40008060, 0x4000C060,
|
||||
0x40010070, 0x40018070, 0x40020080, 0x40030080, 0x40040090, 0x40060090, 0x400800A0, 0x400C00A0,
|
||||
@@ -93,8 +93,8 @@ pub struct decoder?(
|
||||
//
|
||||
// TODO: replace the magic "big enough" 1234 with something more
|
||||
// principled, perhaps discovered via an exhaustive search.
|
||||
huffs[2][1234] u32,
|
||||
n_huffs_bits[2] u32[..9],
|
||||
huffs array[2] array[1234] u32,
|
||||
n_huffs_bits array[2] u32[..9],
|
||||
|
||||
// history holds up to the last 32KiB of decoded output, if the decoding
|
||||
// was incomplete (e.g. due to a short read or write). RFC 1951 (DEFLATE)
|
||||
@@ -107,13 +107,13 @@ pub struct decoder?(
|
||||
//
|
||||
// history[history_index & 0x7FFF] is where the next byte of decoded output
|
||||
// will be written.
|
||||
history[0x8000] u8, // 32 KiB.
|
||||
history array[0x8000] u8, // 32 KiB.
|
||||
history_index u32,
|
||||
|
||||
// code_lengths is used to pass out-of-band data to init_huff.
|
||||
//
|
||||
// code_lengths[in.n_codes0 + i] holds the number of bits in the i'th code.
|
||||
code_lengths[320] u8[..15],
|
||||
code_lengths array[320] u8[..15],
|
||||
|
||||
// end_of_block is whether decode_huffman_xxx saw an end-of-block code.
|
||||
//
|
||||
@@ -131,7 +131,7 @@ pub func decoder.decode?(dst io_writer, src io_reader)() {
|
||||
// TODO: should "since_mark" be "since_mark!", as the return value lets
|
||||
// you modify the state of in.dst, so future mutations (via the slice)
|
||||
// can change the veracity of any in.dst assertions?
|
||||
var written[] u8 = in.dst.since_mark()
|
||||
var written slice u8 = in.dst.since_mark()
|
||||
// Append written, the decoded output, to the history ringbuffer.
|
||||
if written.length() >= 0x8000 {
|
||||
// If written is longer than the ringbuffer, we can ignore the
|
||||
@@ -456,7 +456,7 @@ pri func decoder.init_huff?(which u32[..1], n_codes0 u32[..320], n_codes1 u32[..
|
||||
// - counts[4] = 1
|
||||
// - counts[5] = 2
|
||||
// - all other counts elements are 0.
|
||||
var counts[16] u16[..320]
|
||||
var counts array[16] u16[..320]
|
||||
var i u32 = in.n_codes0
|
||||
while i < in.n_codes1 {
|
||||
assert i < 320 via "a < b: a < c; c <= b"(c:in.n_codes1)
|
||||
@@ -504,7 +504,7 @@ pri func decoder.init_huff?(which u32[..1], n_codes0 u32[..320], n_codes1 u32[..
|
||||
// - offsets[6] = 10
|
||||
// - all other offsets elements are 10.
|
||||
// - n_symbols = 10
|
||||
var offsets[16] u16[..320]
|
||||
var offsets array[16] u16[..320]
|
||||
var n_symbols u32[..320]
|
||||
i = 1
|
||||
while i <= 15 {
|
||||
@@ -541,7 +541,7 @@ pri func decoder.init_huff?(which u32[..1], n_codes0 u32[..320], n_codes1 u32[..
|
||||
// - offsets[3] = 7, formerly 0
|
||||
// - offsets[4] = 8, formerly 7
|
||||
// - offsets[5] = 10, formerly 8
|
||||
var symbols[320] u16[..319]
|
||||
var symbols array[320] u16[..319]
|
||||
i = in.n_codes0
|
||||
while i < in.n_codes1,
|
||||
inv n_symbols <= 288,
|
||||
|
||||
@@ -53,8 +53,8 @@ pub struct decoder?(
|
||||
// gct and lct are the Global / Local Color Tables: 256 (R, G, B) entries.
|
||||
//
|
||||
// TODO: 4 byte per pixel RGBA or BGRA instead of 3 bpp RGB?
|
||||
gct[3 * 256] u8,
|
||||
lct[3 * 256] u8,
|
||||
gct array[3 * 256] u8,
|
||||
lct array[3 * 256] u8,
|
||||
|
||||
lzw lzw_decoder,
|
||||
)
|
||||
@@ -122,7 +122,7 @@ pub func decoder.decode_frame?(dst io_writer, src io_reader)() {
|
||||
//
|
||||
// See the spec section 17 "Header" on page 7.
|
||||
pri func decoder.decode_header?(src io_reader)() {
|
||||
var c[6] u8
|
||||
var c array[6] u8
|
||||
var i u32
|
||||
while i < 6 {
|
||||
c[i] = in.src.read_u8?()
|
||||
@@ -138,7 +138,7 @@ pri func decoder.decode_header?(src io_reader)() {
|
||||
//
|
||||
// See the spec section 18 "Logical Screen Descriptor" on page 8.
|
||||
pri func decoder.decode_lsd?(src io_reader)() {
|
||||
var c[7] u8
|
||||
var c array[7] u8
|
||||
var i u32
|
||||
while i < 7 {
|
||||
c[i] = in.src.read_u8?()
|
||||
@@ -196,12 +196,12 @@ pri func decoder.skip_blocks?(src io_reader)() {
|
||||
}
|
||||
|
||||
// animexts1dot0 is "ANIMEXTS1.0" as bytes.
|
||||
pri const animexts1dot0[11] u8 = $(
|
||||
pri const animexts1dot0 array[11] u8 = $(
|
||||
0x41, 0x4E, 0x49, 0x4D, 0x45, 0x58, 0x54, 0x53, 0x31, 0x2E, 0x30,
|
||||
)
|
||||
|
||||
// netscape2dot0 is "NETSCAPE2.0" as bytes.
|
||||
pri const netscape2dot0[11] u8 = $(
|
||||
pri const netscape2dot0 array[11] u8 = $(
|
||||
0x4E, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2E, 0x30,
|
||||
)
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ pub error "LZW prefix chain is cyclical"
|
||||
|
||||
pri struct lzw_decoder?(
|
||||
literal_width u32[2..8] = 8,
|
||||
stack[4096] u8,
|
||||
suffixes[4096] u8,
|
||||
prefixes[4096] u16[..4095],
|
||||
stack array[4096] u8,
|
||||
suffixes array[4096] u8,
|
||||
prefixes array[4096] u16[..4095],
|
||||
)
|
||||
|
||||
pri func lzw_decoder.set_literal_width!(lw u32[2..8] = 8)() {
|
||||
@@ -109,7 +109,7 @@ pri func lzw_decoder.decode?(dst io_writer, src io_reader)() {
|
||||
inv n_bits < 8,
|
||||
inv c < 256,
|
||||
{
|
||||
var expansion[] u8 = this.stack[s:]
|
||||
var expansion slice u8 = this.stack[s:]
|
||||
var n_copied u64 = in.dst.copy_from_slice(s:expansion)
|
||||
if n_copied == expansion.length() {
|
||||
break
|
||||
|
||||
@@ -73,7 +73,7 @@ pri struct adler32?(
|
||||
)
|
||||
|
||||
// TODO: add a ! as this function is impure.
|
||||
pri func adler32.update(x[] u8)(checksum u32) {
|
||||
pri func adler32.update(x slice u8)(checksum u32) {
|
||||
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
|
||||
// RFC 1950.
|
||||
|
||||
@@ -81,7 +81,7 @@ pri func adler32.update(x[] u8)(checksum u32) {
|
||||
var s2 u32 = this.state.high_bits(n:16)
|
||||
|
||||
while in.x.length() > 0 {
|
||||
var remaining[] u8
|
||||
var remaining slice u8
|
||||
if in.x.length() > 5552 {
|
||||
remaining = in.x[5552:]
|
||||
in.x = in.x[:5552]
|
||||
|
||||
Reference in new issue
Block a user