diff --git a/cmd/tools/bench/wyhash.v b/cmd/tools/bench/wyhash.v index 302ee4345f..aa24ac850f 100644 --- a/cmd/tools/bench/wyhash.v +++ b/cmd/tools/bench/wyhash.v @@ -16,7 +16,7 @@ fn main() { mut bgenerating := benchmark.start() mut bytepile := []byte{} for _ in 0 .. sample_size * max_str_len { - bytepile << byte(rand.int_in_range(40, 125) or { 40 }) + bytepile << u8(rand.int_in_range(40, 125) or { 40 }) } mut str_lens := []int{} for _ in 0 .. sample_size { @@ -30,7 +30,7 @@ fn main() { checksum = 0 for len in str_lens { end_pos := start_pos + len - checksum ^= wyhash.wyhash_c(unsafe { &byte(bytepile.data) + start_pos }, u64(len), + checksum ^= wyhash.wyhash_c(unsafe { &u8(bytepile.data) + start_pos }, u64(len), 1) start_pos = end_pos } diff --git a/cmd/tools/vast/vast.v b/cmd/tools/vast/vast.v index d6e50f1af5..3bfbc4ea60 100644 --- a/cmd/tools/vast/vast.v +++ b/cmd/tools/vast/vast.v @@ -283,7 +283,7 @@ fn (t Tree) embed_file(node ast.EmbeddedFile) &Node { obj.add('compression_type', t.string_node(node.compression_type)) obj.add('is_compressed', t.bool_node(node.is_compressed)) obj.add('len', t.number_node(node.len)) - obj.add('bytes', t.array_node_byte(node.bytes)) + obj.add('bytes', t.array_node_u8(node.bytes)) return obj } @@ -1216,7 +1216,7 @@ fn (t Tree) string_inter_literal(node ast.StringInterLiteral) &Node { obj.add_terse('pluss', t.array_node_bool(node.pluss)) obj.add_terse('fills', t.array_node_bool(node.fills)) obj.add_terse('fmt_poss', t.array_node_position(node.fmt_poss)) - obj.add_terse('fmts', t.array_node_byte(node.fmts)) + obj.add_terse('fmts', t.array_node_u8(node.fmts)) obj.add_terse('need_fmts', t.array_node_bool(node.need_fmts)) obj.add('pos', t.pos(node.pos)) return obj @@ -2209,7 +2209,7 @@ fn (t Tree) array_node_int(nodes []int) &Node { return arr } -fn (t Tree) array_node_byte(nodes []byte) &Node { +fn (t Tree) array_node_u8(nodes []byte) &Node { mut arr := new_array() for node in nodes { arr.add_item(t.number_node(node)) diff --git a/cmd/tools/vbin2v.v b/cmd/tools/vbin2v.v index ed1b776db2..975b8fe6b5 100644 --- a/cmd/tools/vbin2v.v +++ b/cmd/tools/vbin2v.v @@ -51,7 +51,7 @@ fn (context Context) file2v(bname string, fbytes []byte, bn_max int) string { bn_diff_len := bn_max - bname.len sb.write_string('\t${bname}_len' + ' '.repeat(bn_diff_len - 4) + ' = $fbytes.len\n') fbyte := fbytes[0] - bnmae_line := '\t$bname' + ' '.repeat(bn_diff_len) + ' = [byte($fbyte), ' + bnmae_line := '\t$bname' + ' '.repeat(bn_diff_len) + ' = [u8($fbyte), ' sb.write_string(bnmae_line) mut line_len := bnmae_line.len + 3 for i := 1; i < fbytes.len; i++ { diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index 588089395a..bbecb8bc13 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -370,7 +370,7 @@ fn html_highlight(code string, tb &ast.Table) string { break } } else { - buf.write_byte(code[i]) + buf.write_u8(code[i]) i++ } } diff --git a/cmd/tools/vdoc/utils.v b/cmd/tools/vdoc/utils.v index 18d6904639..50c93581ec 100644 --- a/cmd/tools/vdoc/utils.v +++ b/cmd/tools/vdoc/utils.v @@ -271,7 +271,7 @@ fn color_highlight(code string, tb &ast.Table) string { tok = next_tok next_tok = s.scan() } else { - buf.write_byte(code[i]) + buf.write_u8(code[i]) i++ } } diff --git a/cmd/tools/vdoc/vdoc.v b/cmd/tools/vdoc/vdoc.v index db1e4d39b4..862d5f433e 100644 --- a/cmd/tools/vdoc/vdoc.v +++ b/cmd/tools/vdoc/vdoc.v @@ -132,9 +132,9 @@ fn (vd VDoc) write_plaintext_content(contents []doc.DocNode, mut pw strings.Buil for ex in examples { pw.write_string(' Example: ') mut fex := ex - if ex.index_byte(`\n`) >= 0 { + if ex.index_u8(`\n`) >= 0 { // multi-line example - pw.write_byte(`\n`) + pw.write_u8(`\n`) fex = indent(ex) } if cfg.is_color { diff --git a/examples/fireworks/fireworks.v b/examples/fireworks/fireworks.v index 5a7948a9e1..0efbd8fc4b 100644 --- a/examples/fireworks/fireworks.v +++ b/examples/fireworks/fireworks.v @@ -25,7 +25,7 @@ fn on_frame(mut app App) { for mut frame in app.frames { for mut rocket in frame { if !rocket.exploded { - rocket.color.a = byte(f32_max(rocket.color.a - 8, 0)) + rocket.color.a = u8(f32_max(rocket.color.a - 8, 0)) rocket.draw(mut app.gg) } } diff --git a/examples/fireworks/modules/objects/color.v b/examples/fireworks/modules/objects/color.v index 8edbcfebd2..710f356361 100644 --- a/examples/fireworks/modules/objects/color.v +++ b/examples/fireworks/modules/objects/color.v @@ -5,8 +5,8 @@ import rand pub fn random_color() gx.Color { return gx.Color{ - r: rand.byte() - g: rand.byte() - b: rand.byte() + r: rand.u8() + g: rand.u8() + b: rand.u8() } } diff --git a/examples/fireworks/modules/objects/particle.v b/examples/fireworks/modules/objects/particle.v index 81f4d01ff6..8370e54aed 100644 --- a/examples/fireworks/modules/objects/particle.v +++ b/examples/fireworks/modules/objects/particle.v @@ -19,7 +19,7 @@ pub fn (particle Particle) draw(mut ctx gg.Context) { pub fn (mut particle Particle) tick(mut rocket Rocket, mut ctx gg.Context) { particle.lifespan -= get_params().age_rate - particle.color.a = byte(particle.lifespan) + particle.color.a = u8(particle.lifespan) if particle.lifespan <= 0 { rocket.dead = true diff --git a/examples/sokol/01_cubes/cube.v b/examples/sokol/01_cubes/cube.v index e9e3a81665..3ac68bbcfe 100644 --- a/examples/sokol/01_cubes/cube.v +++ b/examples/sokol/01_cubes/cube.v @@ -50,7 +50,7 @@ fn create_texture(w int, h int, buf &u8) gfx.Image { // usage: .dynamic wrap_u: .clamp_to_edge wrap_v: .clamp_to_edge - label: &byte(0) + label: &u8(0) d3d11_texture: 0 } // commen if .dynamic is enabled @@ -352,23 +352,23 @@ fn my_init(mut app App) { x := (i & 0xFF) >> 5 // 8 cell // upper left corner if x == 0 && y == 0 { - tmp_txt[i] = byte(0xFF) - tmp_txt[i + 1] = byte(0) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i] = u8(0xFF) + tmp_txt[i + 1] = u8(0) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } // low right corner else if x == 7 && y == 7 { - tmp_txt[i] = byte(0) - tmp_txt[i + 1] = byte(0xFF) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i] = u8(0) + tmp_txt[i + 1] = u8(0xFF) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } else { col := if ((x + y) & 1) == 1 { 0xFF } else { 0 } - tmp_txt[i] = byte(col) // red - tmp_txt[i + 1] = byte(col) // green - tmp_txt[i + 2] = byte(col) // blue - tmp_txt[i + 3] = byte(0xFF) // alpha + tmp_txt[i] = u8(col) // red + tmp_txt[i + 1] = u8(col) // green + tmp_txt[i + 2] = u8(col) // blue + tmp_txt[i + 3] = u8(0xFF) // alpha } i += 4 } diff --git a/examples/sokol/02_cubes_glsl/cube_glsl.v b/examples/sokol/02_cubes_glsl/cube_glsl.v index 842b71f24a..4cd677d580 100644 --- a/examples/sokol/02_cubes_glsl/cube_glsl.v +++ b/examples/sokol/02_cubes_glsl/cube_glsl.v @@ -66,7 +66,7 @@ fn create_texture(w int, h int, buf &byte) gfx.Image { // usage: .dynamic wrap_u: .clamp_to_edge wrap_v: .clamp_to_edge - label: &byte(0) + label: &u8(0) d3d11_texture: 0 } // comment if .dynamic is enabled @@ -524,23 +524,23 @@ fn my_init(mut app App) { x := (i & 0xFF) >> 5 // 8 cell // upper left corner if x == 0 && y == 0 { - tmp_txt[i] = byte(0xFF) - tmp_txt[i + 1] = byte(0) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i] = u8(0xFF) + tmp_txt[i + 1] = u8(0) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } // low right corner else if x == 7 && y == 7 { - tmp_txt[i + 0] = byte(0) - tmp_txt[i + 1] = byte(0xFF) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i + 0] = u8(0) + tmp_txt[i + 1] = u8(0xFF) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } else { col := if ((x + y) & 1) == 1 { 0xFF } else { 128 } - tmp_txt[i + 0] = byte(col) // red - tmp_txt[i + 1] = byte(col) // green - tmp_txt[i + 2] = byte(col) // blue - tmp_txt[i + 3] = byte(0xFF) // alpha + tmp_txt[i + 0] = u8(col) // red + tmp_txt[i + 1] = u8(col) // green + tmp_txt[i + 2] = u8(col) // blue + tmp_txt[i + 3] = u8(0xFF) // alpha } i += 4 } diff --git a/examples/sokol/03_march_tracing_glsl/rt_glsl.v b/examples/sokol/03_march_tracing_glsl/rt_glsl.v index 6138fe92fd..a85ec6ac27 100644 --- a/examples/sokol/03_march_tracing_glsl/rt_glsl.v +++ b/examples/sokol/03_march_tracing_glsl/rt_glsl.v @@ -65,7 +65,7 @@ fn create_texture(w int, h int, buf &byte) gfx.Image { // usage: .dynamic wrap_u: .clamp_to_edge wrap_v: .clamp_to_edge - label: &byte(0) + label: &u8(0) d3d11_texture: 0 } // comment if .dynamic is enabled @@ -342,23 +342,23 @@ fn my_init(mut app App) { x := (i & 0xFF) >> 5 // 8 cell // upper left corner if x == 0 && y == 0 { - tmp_txt[i + 0] = byte(0xFF) - tmp_txt[i + 1] = byte(0) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i + 0] = u8(0xFF) + tmp_txt[i + 1] = u8(0) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } // low right corner else if x == 7 && y == 7 { - tmp_txt[i + 0] = byte(0) - tmp_txt[i + 1] = byte(0xFF) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i + 0] = u8(0) + tmp_txt[i + 1] = u8(0xFF) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } else { col := if ((x + y) & 1) == 1 { 0xFF } else { 128 } - tmp_txt[i + 0] = byte(col) // red - tmp_txt[i + 1] = byte(col) // green - tmp_txt[i + 2] = byte(col) // blue - tmp_txt[i + 3] = byte(0xFF) // alpha + tmp_txt[i + 0] = u8(col) // red + tmp_txt[i + 1] = u8(col) // green + tmp_txt[i + 2] = u8(col) // blue + tmp_txt[i + 3] = u8(0xFF) // alpha } i += 4 } diff --git a/examples/sokol/04_multi_shader_glsl/rt_glsl.v b/examples/sokol/04_multi_shader_glsl/rt_glsl.v index 38db089b1d..4a0113d894 100644 --- a/examples/sokol/04_multi_shader_glsl/rt_glsl.v +++ b/examples/sokol/04_multi_shader_glsl/rt_glsl.v @@ -67,7 +67,7 @@ fn create_texture(w int, h int, buf byteptr) gfx.Image { // usage: .dynamic wrap_u: .clamp_to_edge wrap_v: .clamp_to_edge - label: &byte(0) + label: &u8(0) d3d11_texture: 0 } // comment if .dynamic is enabled @@ -530,23 +530,23 @@ fn my_init(mut app App) { x := (i & 0xFF) >> 5 // 8 cell // upper left corner if x == 0 && y == 0 { - tmp_txt[i + 0] = byte(0xFF) - tmp_txt[i + 1] = byte(0) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i + 0] = u8(0xFF) + tmp_txt[i + 1] = u8(0) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } // low right corner else if x == 7 && y == 7 { - tmp_txt[i + 0] = byte(0) - tmp_txt[i + 1] = byte(0xFF) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i + 0] = u8(0) + tmp_txt[i + 1] = u8(0xFF) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } else { col := if ((x + y) & 1) == 1 { 0xFF } else { 128 } - tmp_txt[i + 0] = byte(col) // red - tmp_txt[i + 1] = byte(col) // green - tmp_txt[i + 2] = byte(col) // blue - tmp_txt[i + 3] = byte(0xFF) // alpha + tmp_txt[i + 0] = u8(col) // red + tmp_txt[i + 1] = u8(col) // green + tmp_txt[i + 2] = u8(col) // blue + tmp_txt[i + 3] = u8(0xFF) // alpha } i += 4 } diff --git a/examples/sokol/05_instancing_glsl/rt_glsl.v b/examples/sokol/05_instancing_glsl/rt_glsl.v index 1fc740c6a3..12b52e15b2 100644 --- a/examples/sokol/05_instancing_glsl/rt_glsl.v +++ b/examples/sokol/05_instancing_glsl/rt_glsl.v @@ -80,7 +80,7 @@ fn create_texture(w int, h int, buf byteptr) gfx.Image{ //usage: .dynamic wrap_u: .clamp_to_edge wrap_v: .clamp_to_edge - label: &byte(0) + label: &u8(0) d3d11_texture: 0 } // comment if .dynamic is enabled @@ -406,23 +406,23 @@ fn my_init(mut app App) { x := (i & 0xFF) >> 5 // 8 cell // upper left corner if x == 0 && y == 0 { - tmp_txt[i + 0] = byte(0xFF) - tmp_txt[i + 1] = byte(0) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i + 0] = u8(0xFF) + tmp_txt[i + 1] = u8(0) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } // low right corner else if x == 7 && y == 7 { - tmp_txt[i + 0] = byte(0) - tmp_txt[i + 1] = byte(0xFF) - tmp_txt[i + 2] = byte(0) - tmp_txt[i + 3] = byte(0xFF) + tmp_txt[i + 0] = u8(0) + tmp_txt[i + 1] = u8(0xFF) + tmp_txt[i + 2] = u8(0) + tmp_txt[i + 3] = u8(0xFF) } else { col := if ((x + y) & 1) == 1 { 0xFF } else { 128 } - tmp_txt[i + 0] = byte(col) // red - tmp_txt[i + 1] = byte(col) // green - tmp_txt[i + 2] = byte(col) // blue - tmp_txt[i + 3] = byte(0xFF) // alpha + tmp_txt[i + 0] = u8(col) // red + tmp_txt[i + 1] = u8(col) // green + tmp_txt[i + 2] = u8(col) // blue + tmp_txt[i + 3] = u8(0xFF) // alpha } i += 4 } diff --git a/examples/sokol/06_obj_viewer/modules/obj/rend.v b/examples/sokol/06_obj_viewer/modules/obj/rend.v index 2f3c51411b..38d7607743 100644 --- a/examples/sokol/06_obj_viewer/modules/obj/rend.v +++ b/examples/sokol/06_obj_viewer/modules/obj/rend.v @@ -29,7 +29,7 @@ pub fn create_texture(w int, h int, buf &byte) gfx.Image { // usage: .dynamic wrap_u: .clamp_to_edge wrap_v: .clamp_to_edge - label: &byte(0) + label: &u8(0) d3d11_texture: 0 } // comment if .dynamic is enabled diff --git a/examples/sokol/06_obj_viewer/show_obj.v b/examples/sokol/06_obj_viewer/show_obj.v index 9859d201da..7d018a2463 100644 --- a/examples/sokol/06_obj_viewer/show_obj.v +++ b/examples/sokol/06_obj_viewer/show_obj.v @@ -220,10 +220,10 @@ fn my_init(mut app App) { // 1x1 pixel white, default texture unsafe { tmp_txt := malloc(4) - tmp_txt[0] = byte(0xFF) - tmp_txt[1] = byte(0xFF) - tmp_txt[2] = byte(0xFF) - tmp_txt[3] = byte(0xFF) + tmp_txt[0] = u8(0xFF) + tmp_txt[1] = u8(0xFF) + tmp_txt[2] = u8(0xFF) + tmp_txt[3] = u8(0xFF) app.texture = obj.create_texture(1, 1, tmp_txt) free(tmp_txt) } diff --git a/examples/sokol/particles/modules/particle/particle.v b/examples/sokol/particles/modules/particle/particle.v index ac172b90c6..5025b13087 100644 --- a/examples/sokol/particles/modules/particle/particle.v +++ b/examples/sokol/particles/modules/particle/particle.v @@ -46,10 +46,10 @@ pub fn (mut p Particle) update(dt f64) { lt := p.life_time - (1000 * dt) if lt > 0 { p.life_time = lt - p.color.r = p.color.r - 1 // byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.r)) - p.color.g = p.color.g - 1 // byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.g)) - p.color.b = p.color.b - 1 // byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.b)) - p.color.a = byte(int(remap(p.life_time, 0.0, p.life_time_init, 0, 255))) - 10 + p.color.r = p.color.r - 1 // u8(remap(p.life_time,0.0,p.life_time_init,0,p.color.r)) + p.color.g = p.color.g - 1 // u8(remap(p.life_time,0.0,p.life_time_init,0,p.color.g)) + p.color.b = p.color.b - 1 // u8(remap(p.life_time,0.0,p.life_time_init,0,p.color.b)) + p.color.a = u8(int(remap(p.life_time, 0.0, p.life_time_init, 0, 255))) - 10 } else { p.life_time = 0 } diff --git a/examples/sokol/sounds/melody.v b/examples/sokol/sounds/melody.v index aa5ebc4025..664971d654 100644 --- a/examples/sokol/sounds/melody.v +++ b/examples/sokol/sounds/melody.v @@ -22,7 +22,7 @@ fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int, mut a for ch := 0; ch < num_channels; ch++ { idx := frame * num_channels + ch unsafe { - a := f32(byte(y) - 127) / 255.0 + a := f32(u8(y) - 127) / 255.0 soundbuffer[idx] = a acontext.frames[idx & 2047] = a } @@ -62,7 +62,7 @@ fn graphics_frame(mut state AppState) { [inline] fn (mut state AppState) bsample(idx int) byte { - return byte(127 + state.frames[(state.gframe + idx) & 2047] * 128) + return u8(127 + state.frames[(state.gframe + idx) & 2047] * 128) } fn (mut state AppState) draw() { diff --git a/examples/sokol/sounds/wav_player.v b/examples/sokol/sounds/wav_player.v index a10ff21858..303553333a 100644 --- a/examples/sokol/sounds/wav_player.v +++ b/examples/sokol/sounds/wav_player.v @@ -120,14 +120,14 @@ fn read_wav_file_samples(fpath string) ?[]f32 { mut res := []f32{} // eprintln('> read_wav_file_samples: $fpath -------------------------------------------------') mut bytes := os.read_bytes(fpath) ? - mut pbytes := &byte(bytes.data) + mut pbytes := &u8(bytes.data) mut offset := u32(0) rh := unsafe { &RIFFHeader(pbytes) } // eprintln('rh: $rh') - if rh.riff != [byte(`R`), `I`, `F`, `F`]! { + if rh.riff != [u8(`R`), `I`, `F`, `F`]! { return error('WAV should start with `RIFF`') } - if rh.form_type != [byte(`W`), `A`, `V`, `E`]! { + if rh.form_type != [u8(`W`), `A`, `V`, `E`]! { return error('WAV should have `WAVE` form type') } if rh.file_size + 8 != bytes.len { @@ -145,15 +145,15 @@ fn read_wav_file_samples(fpath string) ?[]f32 { // eprintln('ch: $ch') // eprintln('p: $pbytes | offset: $offset | bytes.len: $bytes.len') // //////// - if ch.chunk_type == [byte(`L`), `I`, `S`, `T`]! { + if ch.chunk_type == [u8(`L`), `I`, `S`, `T`]! { continue } // - if ch.chunk_type == [byte(`i`), `d`, `3`, ` `]! { + if ch.chunk_type == [u8(`i`), `d`, `3`, ` `]! { continue } // - if ch.chunk_type == [byte(`f`), `m`, `t`, ` `]! { + if ch.chunk_type == [u8(`f`), `m`, `t`, ` `]! { // eprintln('`fmt ` chunk') rf = unsafe { &RIFFFormat(&ch.chunk_data) } // eprintln('fmt riff format: $rf') @@ -169,20 +169,20 @@ fn read_wav_file_samples(fpath string) ?[]f32 { continue } // - if ch.chunk_type == [byte(`d`), `a`, `t`, `a`]! { + if ch.chunk_type == [u8(`d`), `a`, `t`, `a`]! { if rf == 0 { return error('`data` chunk should be after `fmt ` chunk') } // eprintln('`fmt ` chunk: $rf\n`data` chunk: $ch') mut doffset := 0 - mut dp := unsafe { &byte(&ch.chunk_data) } + mut dp := unsafe { &u8(&ch.chunk_data) } for doffset < ch.chunk_size { for c := 0; c < rf.nchannels; c++ { mut x := f32(0.0) mut step := 0 ppos := unsafe { dp + doffset } if rf.bits_per_sample == 8 { - d8 := unsafe { &byte(ppos) } + d8 := unsafe { &u8(ppos) } x = (f32(*d8) - 128) / 128.0 step = 1 doffset++ diff --git a/examples/term.ui/rectangles.v b/examples/term.ui/rectangles.v index 82a1f4d557..f71be145c2 100644 --- a/examples/term.ui/rectangles.v +++ b/examples/term.ui/rectangles.v @@ -21,9 +21,9 @@ mut: fn random_color() tui.Color { return tui.Color{ - r: rand.byte() - g: rand.byte() - b: rand.byte() + r: rand.u8() + g: rand.u8() + b: rand.u8() } } diff --git a/examples/viewer/view.v b/examples/viewer/view.v index faa87c5368..5b322cc894 100644 --- a/examples/viewer/view.v +++ b/examples/viewer/view.v @@ -126,7 +126,7 @@ fn create_texture(w int, h int, buf &u8) gfx.Image { // usage: .dynamic wrap_u: .clamp_to_edge wrap_v: .clamp_to_edge - label: &byte(0) + label: &u8(0) d3d11_texture: 0 } // comment if .dynamic is enabled @@ -428,7 +428,7 @@ fn frame(mut app App) { // println("$w,$h") // white multiplicator for now - mut c := [byte(255), 255, 255]! + mut c := [u8(255), 255, 255]! sgl.begin_quads() sgl.v2f_t2f_c3b(-w, -h, 0, 0, c[0], c[1], c[2]) sgl.v2f_t2f_c3b(w, -h, 1, 0, c[0], c[1], c[2]) @@ -478,7 +478,7 @@ fn frame(mut app App) { bx += (bw_old - bw) / 2 - (tr_x / 8) / app.scale by += (bh_old - bh) / 2 - ((tr_y / 8) / app.scale) * ratio - c = [byte(255),255,0]! // yellow + c = [u8(255),255,0]! // yellow sgl.begin_line_strip() sgl.v2f_c3b(bx , by , c[0], c[1], c[2]) sgl.v2f_c3b(bx + bw, by , c[0], c[1], c[2]) diff --git a/examples/vpwgen.v b/examples/vpwgen.v index a5854bab28..c12e75d87b 100644 --- a/examples/vpwgen.v +++ b/examples/vpwgen.v @@ -13,7 +13,7 @@ fn main() { x := rand.read(blocksize) ? for c in x { if c >= `0` && c <= `~` { - sb.write_byte(c) + sb.write_u8(c) } } if sb.len > size { diff --git a/vlib/arrays/arrays_test.v b/vlib/arrays/arrays_test.v index ee05cfac1f..c979dbd84c 100644 --- a/vlib/arrays/arrays_test.v +++ b/vlib/arrays/arrays_test.v @@ -11,11 +11,11 @@ fn test_min() ? { assert rf == f32(1.1) rf = min(b[..2]) ? assert rf == f32(3.1) - c := [byte(4), 9, 3, 1] + c := [u8(4), 9, 3, 1] mut rb := min(c) ? - assert rb == byte(1) + assert rb == u8(1) rb = min(c[..3]) ? - assert rb == byte(3) + assert rb == u8(3) } fn test_max() ? { @@ -29,11 +29,11 @@ fn test_max() ? { assert rf == f32(9.1) rf = max(b[..3]) ? assert rf == f32(5.1) - c := [byte(4), 9, 3, 1] + c := [u8(4), 9, 3, 1] mut rb := max(c) ? - assert rb == byte(9) + assert rb == u8(9) rb = max(c[2..]) ? - assert rb == byte(3) + assert rb == u8(3) } fn test_idx_min() ? { @@ -43,7 +43,7 @@ fn test_idx_min() ? { b := [f32(5.1), 3.1, 1.1, 9.1] rf := idx_min(b) ? assert rf == 2 - c := [byte(4), 9, 3, 1] + c := [u8(4), 9, 3, 1] rb := idx_min(c) ? assert rb == 3 } @@ -55,7 +55,7 @@ fn test_idx_max() ? { b := [f32(5.1), 3.1, 1.1, 9.1] rf := idx_max(b) ? assert rf == 3 - c := [byte(4), 9, 3, 1] + c := [u8(4), 9, 3, 1] rb := idx_max(c) ? assert rb == 1 } diff --git a/vlib/bitfield/bitfield.v b/vlib/bitfield/bitfield.v index fdabdc3e81..07cc913a81 100644 --- a/vlib/bitfield/bitfield.v +++ b/vlib/bitfield/bitfield.v @@ -29,7 +29,7 @@ const ( pub fn from_bytes(input []byte) BitField { mut output := new(input.len * 8) for i, b in input { - mut ob := byte(0) + mut ob := u8(0) if b & 0b10000000 > 0 { ob |= 0b00000001 } diff --git a/vlib/bitfield/bitfield_test.v b/vlib/bitfield/bitfield_test.v index 365e583b27..c186daed08 100644 --- a/vlib/bitfield/bitfield_test.v +++ b/vlib/bitfield/bitfield_test.v @@ -133,7 +133,7 @@ fn test_hamming() { } fn test_bf_from_bytes() { - input := [byte(0x01), 0xF0, 0x0F, 0xF0, 0xFF] + input := [u8(0x01), 0xF0, 0x0F, 0xF0, 0xFF] output := bitfield.from_bytes(input).str() assert output == '00000001' + '11110000' + '00001111' + '11110000' + '11111111' newoutput := bitfield.from_str(output).str() @@ -141,7 +141,7 @@ fn test_bf_from_bytes() { } fn test_bf_from_bytes_lowest_bits_first() { - input := [byte(0x01), 0xF0] + input := [u8(0x01), 0xF0] output := bitfield.from_bytes_lowest_bits_first(input).str() assert output == '10000000' + '00001111' newoutput := bitfield.from_str(output).str() @@ -161,7 +161,7 @@ fn test_bf_from_str() { output := bitfield.from_str(input) mut result := 1 for i in 0 .. len { - if input[i] != byte(output.get_bit(i)) + 48 { + if input[i] != u8(output.get_bit(i)) + 48 { result = 0 } } diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index a7e85b34db..1a914a8b0c 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -821,17 +821,17 @@ pub fn (a []string) str() string { } sb_len += 2 // 1x[ + 1x] mut sb := strings.new_builder(sb_len) - sb.write_byte(`[`) + sb.write_u8(`[`) for i in 0 .. a.len { val := a[i] - sb.write_byte(`'`) + sb.write_u8(`'`) sb.write_string(val) - sb.write_byte(`'`) + sb.write_u8(`'`) if i < a.len - 1 { sb.write_string(', ') } } - sb.write_byte(`]`) + sb.write_u8(`]`) res := sb.str() unsafe { sb.free() } return res diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index e81e1fe0aa..5202b5f810 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -669,7 +669,7 @@ fn test_map() { assert nums.map(it + strs.map(it.len)[0]) == [2, 3, 4, 5, 6, 7] assert strs.map(it.len + strs.map(it.len)[0]) == [2, 3, 8] // nested (different it types) - assert strs.map(it[nums.map(it - it)[0]]) == [byte(`v`), `i`, `a`] + assert strs.map(it[nums.map(it - it)[0]]) == [u8(`v`), `i`, `a`] assert nums[0..3].map('$it' + strs.map(it)[it - 1]) == ['1v', '2is', '3awesome'] assert nums.map(map_test_helper_1) == [1, 4, 9, 16, 25, 36] assert [1, 5, 10].map(map_test_helper_1) == [1, 25, 100] @@ -1082,10 +1082,10 @@ fn test_drop() { fn test_hex() { // array hex - st := [byte(`V`), `L`, `A`, `N`, `G`] + st := [u8(`V`), `L`, `A`, `N`, `G`] assert st.hex() == '564c414e47' assert st.hex().len == 10 - st1 := [byte(0x41)].repeat(100) + st1 := [u8(0x41)].repeat(100) assert st1.hex() == '41'.repeat(100) } diff --git a/vlib/builtin/byte_test.v b/vlib/builtin/byte_test.v index 8b38eb8cbc..aac1ace119 100644 --- a/vlib/builtin/byte_test.v +++ b/vlib/builtin/byte_test.v @@ -1,12 +1,12 @@ fn test_clone() { - a := [byte(0), 1, 2] + a := [u8(0), 1, 2] b := a.clone() assert b.len == 3 assert b[0] == 0 assert b[1] == 1 assert b[2] == 2 assert b[1].str() == '1' - xx := byte(35) + xx := u8(35) assert xx.str() == '35' assert xx.ascii_str() == '#' println(typeof(`A`).name) diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 146276d5bd..aaffbc916a 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -294,9 +294,9 @@ fn u64_to_hex_no_leading_zeros(nn u64, len u8) string { // hex returns the value of the `byte` as a hexadecimal `string`. // Note that the output is zero padded for values below 16. -// Example: assert byte(2).hex() == '02' -// Example: assert byte(15).hex() == '0f' -// Example: assert byte(255).hex() == 'ff' +// Example: assert u8(2).hex() == '02' +// Example: assert u8(15).hex() == '0f' +// Example: assert u8(255).hex() == 'ff' pub fn (nn u8) hex() string { if nn == 0 { return '00' @@ -451,13 +451,13 @@ pub fn (nn u64) hex_full() string { // str returns the contents of `byte` as a zero terminated `string`. // See also: [`byte.ascii_str`](#byte.ascii_str) -// Example: assert byte(111).str() == '111' +// Example: assert u8(111).str() == '111' pub fn (b u8) str() string { return int(b).str_l(7) } // ascii_str returns the contents of `byte` as a zero terminated ASCII `string` character. -// Example: assert byte(97).ascii_str() == 'a' +// Example: assert u8(97).ascii_str() == 'a' pub fn (b u8) ascii_str() string { mut str := string{ str: unsafe { malloc_noscan(2) } @@ -472,7 +472,7 @@ pub fn (b u8) ascii_str() string { } // str_escaped returns the contents of `byte` as an escaped `string`. -// Example: assert byte(0).str_escaped() == r'`\0`' +// Example: assert u8(0).str_escaped() == r'`\0`' [manualfree] pub fn (b u8) str_escaped() string { str := match b { @@ -538,7 +538,7 @@ pub fn (b []u8) clone() []byte { // Note: the returned string will have .len equal to the array.len, // even when some of the array bytes were `0`. // If you want to get a V string, that contains only the bytes till -// the first `0` byte, use `tos_clone(&byte(array.data))` instead. +// the first `0` byte, use `tos_clone(&u8(array.data))` instead. pub fn (b []u8) bytestr() string { unsafe { buf := malloc_noscan(b.len + 1) diff --git a/vlib/builtin/int_test.v b/vlib/builtin/int_test.v index bfb8a4286b..5602d07a8f 100644 --- a/vlib/builtin/int_test.v +++ b/vlib/builtin/int_test.v @@ -31,8 +31,8 @@ fn test_str_methods() { assert u64(-1).str() == '18446744073709551615' assert voidptr(-1).str() == '0xffffffffffffffff' assert voidptr(1).str() == '0x1' - assert (&byte(-1)).str() == 'ffffffffffffffff' - assert (&byte(1)).str() == '1' + assert (&u8(-1)).str() == 'ffffffffffffffff' + assert (&u8(1)).str() == '1' assert byteptr(-1).str() == '0xffffffffffffffff' assert byteptr(1).str() == '0x1' assert charptr(-1).str() == '0xffffffffffffffff' @@ -130,7 +130,7 @@ fn test_bin() { assert x3 == -1 x4 := 0b11111111 assert x4 == 255 - x5 := byte(0b11111111) + x5 := u8(0b11111111) assert x5 == 255 x6 := char(0b11111111) // C.char is unsigned on arm64, but signed on amd64, by default @@ -206,21 +206,21 @@ fn test_int_decl() { fn test_int_to_hex() { // array hex - st := [byte(`V`), `L`, `A`, `N`, `G`] + st := [u8(`V`), `L`, `A`, `N`, `G`] assert st.hex() == '564c414e47' assert st.hex().len == 10 - st1 := [byte(0x41)].repeat(100) + st1 := [u8(0x41)].repeat(100) assert st1.hex() == '41'.repeat(100) // --- int to hex tests c0 := 12 // 8Bit - assert byte(0).hex() == '00' - assert byte(c0).hex() == '0c' + assert u8(0).hex() == '00' + assert u8(c0).hex() == '0c' assert i8(c0).hex() == '0c' - assert byte(127).hex() == '7f' + assert u8(127).hex() == '7f' assert i8(127).hex() == '7f' - assert byte(255).hex() == 'ff' - assert byte(-1).hex() == 'ff' + assert u8(255).hex() == 'ff' + assert u8(-1).hex() == 'ff' // 16bit assert u16(0).hex() == '0' assert i16(c0).hex() == 'c' @@ -248,7 +248,7 @@ fn test_int_to_hex() { } fn test_repeat() { - b := byte(`V`) + b := u8(`V`) assert b.repeat(5) == 'VVVVV' assert b.repeat(1) == b.ascii_str() assert b.repeat(0) == '' diff --git a/vlib/builtin/isnil_test.v b/vlib/builtin/isnil_test.v index 15df9f0b79..764d59272c 100644 --- a/vlib/builtin/isnil_test.v +++ b/vlib/builtin/isnil_test.v @@ -1,5 +1,5 @@ fn test_isnil_byteptr() { - pb := &byte(0) + pb := &u8(0) assert isnil(pb) } diff --git a/vlib/builtin/js/array_test.js.v b/vlib/builtin/js/array_test.js.v index ea603d0558..d8520f0041 100644 --- a/vlib/builtin/js/array_test.js.v +++ b/vlib/builtin/js/array_test.js.v @@ -678,7 +678,7 @@ fn test_map() { assert nums.map(it + strs.map(it.len)[0]) == [2, 3, 4, 5, 6, 7] assert strs.map(it.len + strs.map(it.len)[0]) == [2, 3, 8] // nested (different it types) - assert strs.map(it[nums.map(it - it)[0]]) == [byte(`v`), `i`, `a`] + assert strs.map(it[nums.map(it - it)[0]]) == [u8(`v`), `i`, `a`] assert nums[0..3].map('$it' + strs.map(it)[it - 1]) == ['1v', '2is', '3awesome'] assert nums.map(map_test_helper_1) == [1, 4, 9, 16, 25, 36] assert [1, 5, 10].map(map_test_helper_1) == [1, 25, 100] @@ -1045,10 +1045,10 @@ fn test_trim() { /* fn test_hex() { // array hex - st := [byte(`V`), `L`, `A`, `N`, `G`] + st := [u8(`V`), `L`, `A`, `N`, `G`] assert st.hex() == '564c414e47' assert st.hex().len == 10 - st1 := [byte(0x41)].repeat(100) + st1 := [u8(0x41)].repeat(100) assert st1.hex() == '41'.repeat(100) }*/ diff --git a/vlib/builtin/js/byte.js.v b/vlib/builtin/js/byte.js.v index 0cd420d497..22ae9d7d80 100644 --- a/vlib/builtin/js/byte.js.v +++ b/vlib/builtin/js/byte.js.v @@ -36,35 +36,35 @@ pub fn (c u8) is_digit() bool { } // is_hex_digit returns `true` if the byte is either in range 0-9, a-f or A-F and `false` otherwise. -// Example: assert byte(`F`) == true +// Example: assert u8(`F`) == true [inline] pub fn (c u8) is_hex_digit() bool { return (c >= `0` && c <= `9`) || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`) } // is_oct_digit returns `true` if the byte is in range 0-7 and `false` otherwise. -// Example: assert byte(`7`) == true +// Example: assert u8(`7`) == true [inline] pub fn (c u8) is_oct_digit() bool { return c >= `0` && c <= `7` } // is_bin_digit returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise. -// Example: assert byte(`0`) == true +// Example: assert u8(`0`) == true [inline] pub fn (c u8) is_bin_digit() bool { return c == `0` || c == `1` } // is_letter returns `true` if the byte is in range a-z or A-Z and `false` otherwise. -// Example: assert byte(`V`) == true +// Example: assert u8(`V`) == true [inline] pub fn (c u8) is_letter() bool { return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) } // is_alnum returns `true` if the byte is in range a-z, A-Z, 0-9 and `false` otherwise. -// Example: assert byte(`V`) == true +// Example: assert u8(`V`) == true [inline] pub fn (c u8) is_alnum() bool { return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`) @@ -79,7 +79,7 @@ pub fn (c u8) is_capital() bool { } // str_escaped returns the contents of `byte` as an escaped `string`. -// Example: assert byte(0).str_escaped() == r'`\0`' +// Example: assert u8(0).str_escaped() == r'`\0`' pub fn (b u8) str_escaped() string { mut str := '' diff --git a/vlib/builtin/js/int_test.js.v b/vlib/builtin/js/int_test.js.v index 311bcadc13..7d4218fc1d 100644 --- a/vlib/builtin/js/int_test.js.v +++ b/vlib/builtin/js/int_test.js.v @@ -124,7 +124,7 @@ fn test_bin() { assert x3 == -1 x4 := 0b11111111 assert x4 == 255 - x5 := byte(0b11111111) + x5 := u8(0b11111111) assert x5 == 255 x6 := char(0b11111111) assert int(x6) == -1 @@ -196,21 +196,21 @@ fn test_int_decl() { fn test_int_to_hex() { // array hex /* - st := [byte(`V`), `L`, `A`, `N`, `G`] + st := [u8(`V`), `L`, `A`, `N`, `G`] assert st.hex() == '564c414e47' assert st.hex().len == 10 - st1 := [byte(0x41)].repeat(100) + st1 := [u8(0x41)].repeat(100) assert st1.hex() == '41'.repeat(100)*/ // --- int to hex tests c0 := 12 // 8Bit - assert byte(0).hex() == '0' - assert byte(c0).hex() == 'c' + assert u8(0).hex() == '0' + assert u8(c0).hex() == 'c' assert i8(c0).hex() == 'c' - assert byte(127).hex() == '7f' + assert u8(127).hex() == '7f' assert i8(127).hex() == '7f' - assert byte(255).hex() == 'ff' - // assert byte(-1).hex() == 'ff' + assert u8(255).hex() == 'ff' + // assert u8(-1).hex() == 'ff' // 16bit assert u16(0).hex() == '0' assert i16(c0).hex() == 'c' @@ -238,7 +238,7 @@ fn test_int_to_hex() { } fn test_repeat() { - b := byte(`V`) + b := u8(`V`) assert b.repeat(5) == 'VVVVV' assert b.repeat(1) == b.ascii_str() assert b.repeat(0) == '' diff --git a/vlib/builtin/js/map_test.js.v b/vlib/builtin/js/map_test.js.v index ef6e013893..5d5c6db251 100644 --- a/vlib/builtin/js/map_test.js.v +++ b/vlib/builtin/js/map_test.js.v @@ -182,8 +182,8 @@ fn test_various_map_value() { m9['test'] = true assert m9['test'] == true mut m10 := map[string]byte{} - m10['test'] = byte(0) - assert m10['test'] == byte(0) + m10['test'] = u8(0) + assert m10['test'] == u8(0) mut m11 := map[string]f32{} m11['test'] = f32(0.0) assert m11['test'] == f32(0.0) @@ -199,8 +199,8 @@ fn test_various_map_value() { m14['test'] = voidptr(0) assert m14['test'] == voidptr(0) mut m15 := map[string]&byte{} - m15['test'] = &byte(0) - assert m15['test'] == &byte(0) + m15['test'] = &u8(0) + assert m15['test'] == &u8(0) mut m16 := map[string]i64{} m16['test'] = i64(0) assert m16['test'] == i64(0) @@ -763,24 +763,24 @@ fn test_in_map_literal() { fn test_byte_keys() { mut m := map[byte]byte{} - byte_max := byte(255) - for i in byte(0) .. byte_max { + byte_max := u8(255) + for i in u8(0) .. byte_max { m[i] = i assert m[i] == i } for k, v in m { assert k == v } - for i in byte(0) .. 100 { + for i in u8(0) .. 100 { m[i]++ assert m[i] == i + 1 } assert m.len == int(byte_max) keys := m.keys() - for i in byte(0) .. byte_max { + for i in u8(0) .. byte_max { assert keys[i] == i } - for i in byte(0) .. byte_max { + for i in u8(0) .. byte_max { m.delete(i) assert m[i] == 0 } diff --git a/vlib/builtin/js/string.js.v b/vlib/builtin/js/string.js.v index 09b740cffa..bc457be743 100644 --- a/vlib/builtin/js/string.js.v +++ b/vlib/builtin/js/string.js.v @@ -88,7 +88,7 @@ pub fn (s string) split(dot string) []string { pub fn (s string) bytes() []byte { sep := '' tmparr := s.str.split(sep.str).map(fn (it JS.Any) JS.Any { - return JS.Any(byte(JS.String(it).charCodeAt(JS.Number(0)))) + return JS.Any(u8(JS.String(it).charCodeAt(JS.Number(0)))) }) _ := tmparr mut arr := []byte{} @@ -249,9 +249,9 @@ pub fn (s string) u64() u64 { return u64(JS.parseInt(s.str)) } -pub fn (s string) byte() u64 { - res := byte(0) - #res.val = byte(JS.parseInt(s.str)) +pub fn (s string) u8() u64 { + res := u8(0) + #res.val = u8(JS.parseInt(s.str)) return res } @@ -384,10 +384,10 @@ fn compare_lower_strings(a &string, b &string) int { } // at returns the byte at index `idx`. -// Example: assert 'ABC'.at(1) == byte(`B`) +// Example: assert 'ABC'.at(1) == u8(`B`) fn (s string) at(idx int) byte { - mut result := byte(0) - #result = new byte(s.str.charCodeAt(result)) + mut result := u8(0) + #result = new u8(s.str.charCodeAt(result)) return result } @@ -443,7 +443,7 @@ pub fn (s string) repeat(count int) string { return result } -// TODO(playX): Use this iterator instead of using .split('').map(c => byte(c)) +// TODO(playX): Use this iterator instead of using .split('').map(c => u8(c)) #function string_iterator(string) { this.stringIteratorFieldIndex = 0; this.stringIteratorIteratedString = string.str; } #string_iterator.prototype.next = function next() { #var done = true; @@ -458,9 +458,9 @@ pub fn (s string) repeat(count int) string { #done = false; #var first = string.charCodeAt(position); #if (first < 0xD800 || first > 0xDBFF || position + 1 === length) -#value = new byte(string[position]); +#value = new u8(string[position]); #else { -#value = new byte(string[position]+string[position+1]) +#value = new u8(string[position]+string[position+1]) #} #this.stringIteratorFieldIndex = position + value.length; #} diff --git a/vlib/builtin/js/string_test.js.v b/vlib/builtin/js/string_test.js.v index 7228ada8a3..3433278ee4 100644 --- a/vlib/builtin/js/string_test.js.v +++ b/vlib/builtin/js/string_test.js.v @@ -422,7 +422,7 @@ fn test_arr_contains() { fn test_to_num() { s := '7' assert s.int() == 7 - assert s.byte() == 7 + assert s.u8() == 7 assert s.u64() == 7 f := '71.5 hasdf' // QTODO diff --git a/vlib/builtin/linux_bare/libc_impl.v b/vlib/builtin/linux_bare/libc_impl.v index b5724b7351..6ce11d6127 100644 --- a/vlib/builtin/linux_bare/libc_impl.v +++ b/vlib/builtin/linux_bare/libc_impl.v @@ -6,8 +6,8 @@ __global global_allocator dlmalloc.Dlmalloc [unsafe] pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void { - dest_ := unsafe { &byte(dest) } - src_ := unsafe { &byte(src) } + dest_ := unsafe { &u8(dest) } + src_ := unsafe { &u8(src) } unsafe { for i in 0 .. int(n) { dest_[i] = src_[i] @@ -24,7 +24,7 @@ fn __malloc(n usize) &C.void { [unsafe] fn strlen(_s &C.void) usize { - s := unsafe { &byte(_s) } + s := unsafe { &u8(_s) } mut i := 0 for ; unsafe { s[i] } != 0; i++ {} return usize(i) @@ -63,8 +63,8 @@ fn memset(s &C.void, c int, n usize) &C.void { [unsafe] fn memmove(dest &C.void, src &C.void, n usize) &C.void { - dest_ := unsafe { &byte(dest) } - src_ := unsafe { &byte(src) } + dest_ := unsafe { &u8(dest) } + src_ := unsafe { &u8(src) } mut temp_buf := unsafe { malloc(int(n)) } for i in 0 .. int(n) { unsafe { @@ -90,14 +90,14 @@ fn __calloc(nmemb usize, size usize) &C.void { } fn getchar() int { - x := byte(0) + x := u8(0) sys_read(0, &x, 1) return int(x) } fn memcmp(a &C.void, b &C.void, n usize) int { - a_ := unsafe { &byte(a) } - b_ := unsafe { &byte(b) } + a_ := unsafe { &u8(a) } + b_ := unsafe { &u8(b) } for i in 0 .. int(n) { if unsafe { a_[i] != b_[i] } { unsafe { diff --git a/vlib/builtin/linux_bare/linux_syscalls.v b/vlib/builtin/linux_bare/linux_syscalls.v index 09c74b2d6e..440b4e7794 100644 --- a/vlib/builtin/linux_bare/linux_syscalls.v +++ b/vlib/builtin/linux_bare/linux_syscalls.v @@ -254,7 +254,7 @@ fn sys_close(fd i64) Errno { fn sys_mmap(addr &byte, len u64, prot MemProt, flags MapFlags, fildes u64, off u64) (&byte, Errno) { rc := sys_call6(9, u64(addr), len, u64(prot), u64(flags), fildes, off) a, e := split_int_errno(rc) - return &byte(a), e + return &u8(a), e } // 11 sys_munmap @@ -266,7 +266,7 @@ fn sys_munmap(addr voidptr, len u64) Errno { fn sys_mremap(old_addr voidptr, old_len u64, new_len u64, flags u64) (&byte, Errno) { rc := sys_call4(25, u64(old_addr), old_len, new_len, flags) a, e := split_int_errno(rc) - return &byte(a), e + return &u8(a), e } // 22 sys_pipe diff --git a/vlib/builtin/linux_bare/memory_managment.v b/vlib/builtin/linux_bare/memory_managment.v index 5973c35a02..a21eebcd14 100644 --- a/vlib/builtin/linux_bare/memory_managment.v +++ b/vlib/builtin/linux_bare/memory_managment.v @@ -10,16 +10,16 @@ fn mm_alloc(size u64) (&byte, Errno) { map_flags := MapFlags(int(MapFlags.map_private) | int(MapFlags.map_anonymous)) // END CONSTS - a, e := sys_mmap(&byte(0), size + sizeof(u64), mem_prot, map_flags, -1, 0) + a, e := sys_mmap(&u8(0), size + sizeof(u64), mem_prot, map_flags, -1, 0) if e == .enoerror { unsafe { mut ap := &u64(a) *ap = size - x2 := &byte(a + sizeof(u64)) + x2 := &u8(a + sizeof(u64)) return x2, e } } - return &byte(0), e + return &u8(0), e } fn mm_free(addr &byte) Errno { @@ -38,7 +38,7 @@ fn system_alloc(_ voidptr, size usize) (voidptr, usize, u32) { map_flags := MapFlags(int(MapFlags.map_private) | int(MapFlags.map_anonymous)) // END CONSTS - a, e := sys_mmap(&byte(0), u64(size), mem_prot, map_flags, -1, 0) + a, e := sys_mmap(&u8(0), u64(size), mem_prot, map_flags, -1, 0) if e == .enoerror { return a, size, 0 diff --git a/vlib/builtin/linux_bare/old/linuxsys_bare.v b/vlib/builtin/linux_bare/old/linuxsys_bare.v index ddec203ddf..9588b16849 100644 --- a/vlib/builtin/linux_bare/old/linuxsys_bare.v +++ b/vlib/builtin/linux_bare/old/linuxsys_bare.v @@ -360,7 +360,7 @@ pub fn sys_close(fd i64) Errno { pub fn sys_mmap(addr &byte, len u64, prot Mm_prot, flags Map_flags, fildes u64, off u64) (&byte, Errno) { rc := sys_call6(9, u64(addr), len, u64(prot), u64(flags), fildes, off) a, e := split_int_errno(rc) - return &byte(a), e + return &u8(a), e } pub fn sys_munmap(addr voidptr, len u64) Errno { diff --git a/vlib/builtin/linux_bare/old/mm_bare.v b/vlib/builtin/linux_bare/old/mm_bare.v index cee5f99857..e17cf4f32d 100644 --- a/vlib/builtin/linux_bare/old/mm_bare.v +++ b/vlib/builtin/linux_bare/old/mm_bare.v @@ -19,9 +19,9 @@ pub fn mm_alloc(size u64) (&byte, Errno) { if e == .enoerror { mut ap := &int(a) *ap = pages - return &byte(a + 4), e + return &u8(a + 4), e } - return &byte(0), e + return &u8(0), e } pub fn mm_free(addr &byte) Errno { @@ -32,8 +32,8 @@ pub fn mm_free(addr &byte) Errno { } pub fn mem_copy(dest0 voidptr, src0 voidptr, n int) voidptr { - mut dest := &byte(dest0) - src := &byte(src0) + mut dest := &u8(dest0) + src := &u8(src0) for i in 0 .. n { dest[i] = src[i] } diff --git a/vlib/builtin/linux_bare/old/string_bare.v b/vlib/builtin/linux_bare/old/string_bare.v index 8f7edfcfb4..5be89f2474 100644 --- a/vlib/builtin/linux_bare/old/string_bare.v +++ b/vlib/builtin/linux_bare/old/string_bare.v @@ -64,8 +64,8 @@ pub fn tos3(s &char) string { panic('tos3: nil string') } return string{ - str: &byte(s) - len: strlen(&byte(s)) + str: &u8(s) + len: strlen(&u8(s)) } } diff --git a/vlib/builtin/map.c.v b/vlib/builtin/map.c.v index c0fc60cfbc..c46d77194f 100644 --- a/vlib/builtin/map.c.v +++ b/vlib/builtin/map.c.v @@ -23,7 +23,7 @@ fn map_hash_string(pkey voidptr) u64 { } fn map_hash_int_1(pkey voidptr) u64 { - return C.wyhash64(*unsafe { &byte(pkey) }, 0) + return C.wyhash64(*unsafe { &u8(pkey) }, 0) } fn map_hash_int_2(pkey voidptr) u64 { diff --git a/vlib/builtin/map_d_gcboehm_opt.v b/vlib/builtin/map_d_gcboehm_opt.v index 93049b7212..001c621eef 100644 --- a/vlib/builtin/map_d_gcboehm_opt.v +++ b/vlib/builtin/map_d_gcboehm_opt.v @@ -101,8 +101,8 @@ fn new_map_init_noscan_key(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapClo mut out := new_map_noscan_key(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn) // TODO pre-allocate n slots - mut pkey := &byte(keys) - mut pval := &byte(values) + mut pkey := &u8(keys) + mut pval := &u8(values) for _ in 0 .. n { unsafe { out.set(pkey, pval) @@ -117,8 +117,8 @@ fn new_map_init_noscan_value(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapC mut out := new_map_noscan_value(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn) // TODO pre-allocate n slots - mut pkey := &byte(keys) - mut pval := &byte(values) + mut pkey := &u8(keys) + mut pval := &u8(values) for _ in 0 .. n { unsafe { out.set(pkey, pval) @@ -133,8 +133,8 @@ fn new_map_init_noscan_key_value(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn mut out := new_map_noscan_key_value(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn) // TODO pre-allocate n slots - mut pkey := &byte(keys) - mut pval := &byte(values) + mut pkey := &u8(keys) + mut pval := &u8(values) for _ in 0 .. n { unsafe { out.set(pkey, pval) diff --git a/vlib/builtin/map_test.v b/vlib/builtin/map_test.v index a064d7f6bb..65a323412e 100644 --- a/vlib/builtin/map_test.v +++ b/vlib/builtin/map_test.v @@ -180,8 +180,8 @@ fn test_various_map_value() { m9['test'] = true assert m9['test'] == true mut m10 := map[string]byte{} - m10['test'] = byte(0) - assert m10['test'] == byte(0) + m10['test'] = u8(0) + assert m10['test'] == u8(0) mut m11 := map[string]f32{} m11['test'] = f32(0.0) assert m11['test'] == f32(0.0) @@ -195,8 +195,8 @@ fn test_various_map_value() { m14['test'] = voidptr(0) assert m14['test'] == voidptr(0) mut m15 := map[string]&byte{} - m15['test'] = &byte(0) - assert m15['test'] == &byte(0) + m15['test'] = &u8(0) + assert m15['test'] == &u8(0) mut m16 := map[string]i64{} m16['test'] = i64(0) assert m16['test'] == i64(0) @@ -751,24 +751,24 @@ fn test_in_map_literal() { fn test_byte_keys() { mut m := map[byte]byte{} - byte_max := byte(255) - for i in byte(0) .. byte_max { + byte_max := u8(255) + for i in u8(0) .. byte_max { m[i] = i assert m[i] == i } for k, v in m { assert k == v } - for i in byte(0) .. 100 { + for i in u8(0) .. 100 { m[i]++ assert m[i] == i + 1 } assert m.len == int(byte_max) keys := m.keys() - for i in byte(0) .. byte_max { + for i in u8(0) .. byte_max { assert keys[i] == i } - for i in byte(0) .. byte_max { + for i in u8(0) .. byte_max { m.delete(i) assert m[i] == 0 } diff --git a/vlib/builtin/prealloc.c.v b/vlib/builtin/prealloc.c.v index b34a4f5a86..abe901022c 100644 --- a/vlib/builtin/prealloc.c.v +++ b/vlib/builtin/prealloc.c.v @@ -50,7 +50,7 @@ fn vmemory_block_malloc(n int) &byte { if g_memory_block.remaining < n { g_memory_block = vmemory_block_new(g_memory_block, n) } - mut res := &byte(0) + mut res := &u8(0) res = g_memory_block.current g_memory_block.remaining -= n g_memory_block.mallocs++ diff --git a/vlib/builtin/rune_test.v b/vlib/builtin/rune_test.v index 8a9098f8d5..a36b464e6e 100644 --- a/vlib/builtin/rune_test.v +++ b/vlib/builtin/rune_test.v @@ -38,5 +38,5 @@ fn test_length_in_bytes() { fn test_bytes() { r1 := `★` - assert r1.bytes() == [byte(0xe2), 0x98, 0x85] + assert r1.bytes() == [u8(0xe2), 0x98, 0x85] } diff --git a/vlib/builtin/sorted_map.v b/vlib/builtin/sorted_map.v index c5bb998fe9..7893ad00c7 100644 --- a/vlib/builtin/sorted_map.v +++ b/vlib/builtin/sorted_map.v @@ -49,7 +49,7 @@ fn new_sorted_map_init(n int, value_bytes int, keys &string, values voidptr) Sor mut out := new_sorted_map(n, value_bytes) for i in 0 .. n { unsafe { - out.set(keys[i], &byte(values) + i * value_bytes) + out.set(keys[i], &u8(values) + i * value_bytes) } } return out diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 23cf264751..7078ad7506 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -180,7 +180,7 @@ pub fn tos5(s &char) string { // vstring converts a C style string to a V string. // Note: the memory block pointed by `bp` is *reused, not copied*! -// Note: instead of `&byte(arr.data).vstring()`, do use `tos_clone(&byte(arr.data))`. +// Note: instead of `&u8(arr.data).vstring()`, do use `tos_clone(&u8(arr.data))`. // Strings returned from this function will be normal V strings beside that, // (i.e. they would be freed by V's -autofree mechanism, when they are no longer used). // See also `tos_clone`. @@ -211,7 +211,7 @@ pub fn (bp &u8) vstring_with_len(len int) string { // Strings returned from this function will be normal V strings beside that, // (i.e. they would be freed by V's -autofree mechanism, when they are // no longer used). -// Note: instead of `&byte(a.data).vstring()`, use `tos_clone(&byte(a.data))`. +// Note: instead of `&u8(a.data).vstring()`, use `tos_clone(&u8(a.data))`. // See also `tos_clone`. [unsafe] pub fn (cp &char) vstring() string { @@ -520,7 +520,7 @@ pub fn (s string) f64() f64 { } // u8 returns the value of the string as u8 `'1'.u8() == u8(1)`. -pub fn (s string) byte() u8 { +pub fn (s string) u8() u8 { return u8(strconv.common_parse_uint(s, 0, 8, false, false) or { 0 }) } @@ -1039,7 +1039,7 @@ pub fn (s string) index_after(p string, start int) int { // index_byte returns the index of byte `c` if found in the string. // index_byte returns -1 if the byte can not be found. [direct_array_access] -pub fn (s string) index_byte(c u8) int { +pub fn (s string) index_u8(c u8) int { for i in 0 .. s.len { if unsafe { s.str[i] } == c { return i @@ -1051,7 +1051,7 @@ pub fn (s string) index_byte(c u8) int { // last_index_byte returns the index of the last occurence of byte `c` if found in the string. // last_index_byte returns -1 if the byte is not found. [direct_array_access] -pub fn (s string) last_index_byte(c u8) int { +pub fn (s string) last_index_u8(c u8) int { for i := s.len - 1; i >= 0; i-- { if unsafe { s.str[i] == c } { return i @@ -1476,7 +1476,7 @@ pub fn (s string) str() string { } // at returns the byte at index `idx`. -// Example: assert 'ABC'.at(1) == byte(`B`) +// Example: assert 'ABC'.at(1) == u8(`B`) fn (s string) at(idx int) byte { $if !no_bounds_checking ? { if idx < 0 || idx >= s.len { @@ -1501,7 +1501,7 @@ fn (s string) at_with_check(idx int) ?u8 { // is_space returns `true` if the byte is a white space character. // The following list is considered white space characters: ` `, `\t`, `\n`, `\v`, `\f`, `\r`, 0x85, 0xa0 -// Example: assert byte(` `).is_space() == true +// Example: assert u8(` `).is_space() == true [inline] pub fn (c u8) is_space() bool { // 0x85 is NEXT LINE (NEL) @@ -1510,42 +1510,42 @@ pub fn (c u8) is_space() bool { } // is_digit returns `true` if the byte is in range 0-9 and `false` otherwise. -// Example: assert byte(`9`) == true +// Example: assert u8(`9`) == true [inline] pub fn (c u8) is_digit() bool { return c >= `0` && c <= `9` } // is_hex_digit returns `true` if the byte is either in range 0-9, a-f or A-F and `false` otherwise. -// Example: assert byte(`F`) == true +// Example: assert u8(`F`) == true [inline] pub fn (c u8) is_hex_digit() bool { return (c >= `0` && c <= `9`) || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`) } // is_oct_digit returns `true` if the byte is in range 0-7 and `false` otherwise. -// Example: assert byte(`7`) == true +// Example: assert u8(`7`) == true [inline] pub fn (c u8) is_oct_digit() bool { return c >= `0` && c <= `7` } // is_bin_digit returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise. -// Example: assert byte(`0`) == true +// Example: assert u8(`0`) == true [inline] pub fn (c u8) is_bin_digit() bool { return c == `0` || c == `1` } // is_letter returns `true` if the byte is in range a-z or A-Z and `false` otherwise. -// Example: assert byte(`V`) == true +// Example: assert u8(`V`) == true [inline] pub fn (c u8) is_letter() bool { return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) } // is_alnum returns `true` if the byte is in range a-z, A-Z, 0-9 and `false` otherwise. -// Example: assert byte(`V`) == true +// Example: assert u8(`V`) == true [inline] pub fn (c u8) is_alnum() bool { return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`) @@ -1558,7 +1558,7 @@ pub fn (s &string) free() { return } if s.is_lit == -98761234 { - double_free_msg := unsafe { &byte(c'double string.free() detected\n') } + double_free_msg := unsafe { &u8(c'double string.free() detected\n') } double_free_msg_len := unsafe { vstrlen(double_free_msg) } $if freestanding { bare_eprint(double_free_msg, u64(double_free_msg_len)) @@ -1937,7 +1937,7 @@ pub fn (name string) match_glob(pattern string) bool { mut is_inverted := false mut inner_match := false mut inner_idx := bstart + 1 - mut inner_c := byte(0) + mut inner_c := u8(0) if inner_idx < plen { inner_c = pattern[inner_idx] if inner_c == `^` { diff --git a/vlib/builtin/string_interpolation.v b/vlib/builtin/string_interpolation.v index 299077fc63..6974d0f296 100644 --- a/vlib/builtin/string_interpolation.v +++ b/vlib/builtin/string_interpolation.v @@ -174,7 +174,7 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) { } // mange pad char, for now only 0 allowed - mut pad_ch := byte(` `) + mut pad_ch := u8(` `) if fmt_pad_ch > 0 { // pad_ch = fmt_pad_ch pad_ch = `0` @@ -263,7 +263,7 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) { tmp.free() } if write_minus { - sb.write_byte(`-`) + sb.write_u8(`-`) bf.len0-- // compensate for the `-` above } if width == 0 { diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 5ae69866e5..6f200375d6 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -457,7 +457,7 @@ fn test_arr_contains() { fn test_to_num() { s := '7' assert s.int() == 7 - assert s.byte() == 7 + assert s.u8() == 7 assert s.u64() == 7 f := '71.5 hasdf' // QTODO @@ -574,7 +574,7 @@ fn test_bytes_to_string() { } assert unsafe { buf.vstring() } == 'hello' assert unsafe { buf.vstring_with_len(2) } == 'he' - bytes := [byte(`h`), `e`, `l`, `l`, `o`] + bytes := [u8(`h`), `e`, `l`, `l`, `o`] assert bytes.bytestr() == 'hello' } @@ -982,5 +982,5 @@ fn test_string_f32() { } fn test_string_with_zero_byte_escape() { - assert '\x00'.bytes() == [byte(0)] + assert '\x00'.bytes() == [u8(0)] } diff --git a/vlib/builtin/utf8.c.v b/vlib/builtin/utf8.c.v index e7134c759c..b74f9f289d 100644 --- a/vlib/builtin/utf8.c.v +++ b/vlib/builtin/utf8.c.v @@ -12,7 +12,7 @@ pub fn (_str string) to_wide() &u16 { mut wstr := &u16(malloc_noscan((num_chars + 1) * 2)) // sizeof(wchar_t) if wstr != 0 { C.MultiByteToWideChar(cp_utf8, 0, &char(_str.str), _str.len, wstr, num_chars) - C.memset(&byte(wstr) + num_chars * 2, 0, 2) + C.memset(&u8(wstr) + num_chars * 2, 0, 2) } return wstr } diff --git a/vlib/builtin/wasm_bare/libc_impl.v b/vlib/builtin/wasm_bare/libc_impl.v index 26f17bd156..96ad8da060 100644 --- a/vlib/builtin/wasm_bare/libc_impl.v +++ b/vlib/builtin/wasm_bare/libc_impl.v @@ -11,8 +11,8 @@ pub fn __malloc(size usize) voidptr { [unsafe] pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void { - dest_ := unsafe { &byte(dest) } - src_ := unsafe { &byte(src) } + dest_ := unsafe { &u8(dest) } + src_ := unsafe { &u8(src) } unsafe { for i in 0 .. int(n) { dest_[i] = src_[i] @@ -23,7 +23,7 @@ pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void { [unsafe] fn strlen(_s &C.void) usize { - s := unsafe { &byte(_s) } + s := unsafe { &u8(_s) } mut i := 0 for ; unsafe { s[i] } != 0; i++ {} return usize(i) @@ -62,8 +62,8 @@ fn memset(s &C.void, c int, n usize) &C.void { [unsafe] fn memmove(dest &C.void, src &C.void, n usize) &C.void { - dest_ := unsafe { &byte(dest) } - src_ := unsafe { &byte(src) } + dest_ := unsafe { &u8(dest) } + src_ := unsafe { &u8(src) } mut temp_buf := unsafe { malloc(int(n)) } for i in 0 .. int(n) { unsafe { @@ -93,8 +93,8 @@ fn getchar() int { } fn memcmp(a &C.void, b &C.void, n usize) int { - a_ := unsafe { &byte(a) } - b_ := unsafe { &byte(b) } + a_ := unsafe { &u8(a) } + b_ := unsafe { &u8(b) } for i in 0 .. int(n) { if unsafe { a_[i] != b_[i] } { unsafe { diff --git a/vlib/clipboard/clipboard_darwin.c.v b/vlib/clipboard/clipboard_darwin.c.v index b8f04214ee..d2d0756d69 100644 --- a/vlib/clipboard/clipboard_darwin.c.v +++ b/vlib/clipboard/clipboard_darwin.c.v @@ -74,7 +74,7 @@ pub fn (mut cb Clipboard) get_text() string { return '' } utf8_clip := C.darwin_get_pasteboard_text(cb.pb) - return unsafe { tos_clone(&byte(utf8_clip)) } + return unsafe { tos_clone(&u8(utf8_clip)) } } // new_primary returns a new X11 `PRIMARY` type `Clipboard` instance allocated on the heap. diff --git a/vlib/clipboard/x11/clipboard.c.v b/vlib/clipboard/x11/clipboard.c.v index ff96bdf67b..d4b60be807 100644 --- a/vlib/clipboard/x11/clipboard.c.v +++ b/vlib/clipboard/x11/clipboard.c.v @@ -398,7 +398,7 @@ fn read_property(d &C.Display, w Window, p Atom) Property { actual_format := 0 nitems := u64(0) bytes_after := u64(0) - ret := &byte(0) + ret := &u8(0) mut read_bytes := 1024 for { if ret != 0 { diff --git a/vlib/crypto/aes/block_generic.v b/vlib/crypto/aes/block_generic.v index 129d7b47e6..f0a290cf8b 100644 --- a/vlib/crypto/aes/block_generic.v +++ b/vlib/crypto/aes/block_generic.v @@ -58,10 +58,10 @@ fn encrypt_block_generic(xk []u32, mut dst []byte, src []byte) { mut t2 := u32(0) mut t3 := u32(0) for _ in 0 .. nr { - t0 = xk[k + 0] ^ te0[byte(s0 >> 24)] ^ te1[byte(s1 >> 16)] ^ te2[byte(s2 >> 8)] ^ u32(te3[byte(s3)]) - t1 = xk[k + 1] ^ te0[byte(s1 >> 24)] ^ te1[byte(s2 >> 16)] ^ te2[byte(s3 >> 8)] ^ u32(te3[byte(s0)]) - t2 = xk[k + 2] ^ te0[byte(s2 >> 24)] ^ te1[byte(s3 >> 16)] ^ te2[byte(s0 >> 8)] ^ u32(te3[byte(s1)]) - t3 = xk[k + 3] ^ te0[byte(s3 >> 24)] ^ te1[byte(s0 >> 16)] ^ te2[byte(s1 >> 8)] ^ u32(te3[byte(s2)]) + t0 = xk[k + 0] ^ te0[u8(s0 >> 24)] ^ te1[u8(s1 >> 16)] ^ te2[u8(s2 >> 8)] ^ u32(te3[u8(s3)]) + t1 = xk[k + 1] ^ te0[u8(s1 >> 24)] ^ te1[u8(s2 >> 16)] ^ te2[u8(s3 >> 8)] ^ u32(te3[u8(s0)]) + t2 = xk[k + 2] ^ te0[u8(s2 >> 24)] ^ te1[u8(s3 >> 16)] ^ te2[u8(s0 >> 8)] ^ u32(te3[u8(s1)]) + t3 = xk[k + 3] ^ te0[u8(s3 >> 24)] ^ te1[u8(s0 >> 16)] ^ te2[u8(s1 >> 8)] ^ u32(te3[u8(s2)]) k += 4 s0 = t0 s1 = t1 @@ -105,10 +105,10 @@ fn decrypt_block_generic(xk []u32, mut dst []byte, src []byte) { mut t2 := u32(0) mut t3 := u32(0) for _ in 0 .. nr { - t0 = xk[k + 0] ^ td0[byte(s0 >> 24)] ^ td1[byte(s3 >> 16)] ^ td2[byte(s2 >> 8)] ^ u32(td3[byte(s1)]) - t1 = xk[k + 1] ^ td0[byte(s1 >> 24)] ^ td1[byte(s0 >> 16)] ^ td2[byte(s3 >> 8)] ^ u32(td3[byte(s2)]) - t2 = xk[k + 2] ^ td0[byte(s2 >> 24)] ^ td1[byte(s1 >> 16)] ^ td2[byte(s0 >> 8)] ^ u32(td3[byte(s3)]) - t3 = xk[k + 3] ^ td0[byte(s3 >> 24)] ^ td1[byte(s2 >> 16)] ^ td2[byte(s1 >> 8)] ^ u32(td3[byte(s0)]) + t0 = xk[k + 0] ^ td0[u8(s0 >> 24)] ^ td1[u8(s3 >> 16)] ^ td2[u8(s2 >> 8)] ^ u32(td3[u8(s1)]) + t1 = xk[k + 1] ^ td0[u8(s1 >> 24)] ^ td1[u8(s0 >> 16)] ^ td2[u8(s3 >> 8)] ^ u32(td3[u8(s2)]) + t2 = xk[k + 2] ^ td0[u8(s2 >> 24)] ^ td1[u8(s1 >> 16)] ^ td2[u8(s0 >> 8)] ^ u32(td3[u8(s3)]) + t3 = xk[k + 3] ^ td0[u8(s3 >> 24)] ^ td1[u8(s2 >> 16)] ^ td2[u8(s1 >> 8)] ^ u32(td3[u8(s0)]) k += 4 s0 = t0 s1 = t1 diff --git a/vlib/crypto/aes/const.v b/vlib/crypto/aes/const.v index 78eb88defa..1952d9a620 100644 --- a/vlib/crypto/aes/const.v +++ b/vlib/crypto/aes/const.v @@ -29,7 +29,7 @@ const ( // Powers of x mod poly in GF(2). const ( pow_x = [ - byte(0x01), + u8(0x01), 0x02, 0x04, 0x08, @@ -51,7 +51,7 @@ const ( // FIPS-197 Figure 7. S-box substitution values in hexadecimal format. const ( s_box0 = [ - byte(0x63), 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, + u8(0x63), 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, @@ -73,7 +73,7 @@ const ( // FIPS-197 Figure 14. Inverse S-box substitution values in hexadecimal format. const ( s_box1 = [ - byte(0x52), 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, + u8(0x52), 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, diff --git a/vlib/crypto/bcrypt/bcrypt.v b/vlib/crypto/bcrypt/bcrypt.v index 8f1b13389f..290b7e2e49 100644 --- a/vlib/crypto/bcrypt/bcrypt.v +++ b/vlib/crypto/bcrypt/bcrypt.v @@ -27,13 +27,13 @@ mut: minor string } -const magic_cipher_data = [byte(0x4f), 0x72, 0x70, 0x68, 0x65, 0x61, 0x6e, 0x42, 0x65, 0x68, 0x6f, +const magic_cipher_data = [u8(0x4f), 0x72, 0x70, 0x68, 0x65, 0x61, 0x6e, 0x42, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x53, 0x63, 0x72, 0x79, 0x44, 0x6f, 0x75, 0x62, 0x74] // generate_from_password return a bcrypt string from Hashed struct. pub fn generate_from_password(password []byte, cost int) ?string { mut p := new_from_password(password, cost) or { return error('Error: $err') } - x := p.hash_byte() + x := p.hash_u8() return x.bytestr() } @@ -52,7 +52,7 @@ pub fn compare_hash_and_password(password []byte, hashed_password []byte) ? { minor: p.minor } - if p.hash_byte() != other_p.hash_byte() { + if p.hash_u8() != other_p.hash_u8() { return error('mismatched hash and password') } } @@ -140,7 +140,7 @@ fn expensive_blowfish_setup(key []byte, cost u32, salt []byte) ?&blowfish.Blowfi } // hash_byte converts the hash value to a byte array. -fn (mut h Hashed) hash_byte() []byte { +fn (mut h Hashed) hash_u8() []byte { mut arr := []byte{len: 65, init: 0} arr[0] = `$` arr[1] = h.major[0] diff --git a/vlib/crypto/blowfish/block.v b/vlib/crypto/blowfish/block.v index 0250ac0568..205642208f 100644 --- a/vlib/crypto/blowfish/block.v +++ b/vlib/crypto/blowfish/block.v @@ -89,38 +89,38 @@ fn setup_tables(l u32, r u32, mut bf Blowfish) []u32 { mut xl := l mut xr := r xl ^= bf.p[0] - xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) + - (bf.s[3][byte(xl)] ^ bf.p[1]) - xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) + - (bf.s[3][byte(xr)] ^ bf.p[2]) - xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) + - (bf.s[3][byte(xl)] ^ bf.p[3]) - xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) + - (bf.s[3][byte(xr)] ^ bf.p[4]) - xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) + - (bf.s[3][byte(xl)] ^ bf.p[5]) - xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) + - (bf.s[3][byte(xr)] ^ bf.p[6]) - xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) + - (bf.s[3][byte(xl)] ^ bf.p[7]) - xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) + - (bf.s[3][byte(xr)] ^ bf.p[8]) - xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) + - (bf.s[3][byte(xl)] ^ bf.p[9]) - xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) + - (bf.s[3][byte(xr)] ^ bf.p[10]) - xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) + - (bf.s[3][byte(xl)] ^ bf.p[11]) - xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) + - (bf.s[3][byte(xr)] ^ bf.p[12]) - xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) + - (bf.s[3][byte(xl)] ^ bf.p[13]) - xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) + - (bf.s[3][byte(xr)] ^ bf.p[14]) - xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) + - (bf.s[3][byte(xl)] ^ bf.p[15]) - xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) + - (bf.s[3][byte(xr)] ^ bf.p[16]) + xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) + + (bf.s[3][u8(xl)] ^ bf.p[1]) + xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) + + (bf.s[3][u8(xr)] ^ bf.p[2]) + xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) + + (bf.s[3][u8(xl)] ^ bf.p[3]) + xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) + + (bf.s[3][u8(xr)] ^ bf.p[4]) + xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) + + (bf.s[3][u8(xl)] ^ bf.p[5]) + xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) + + (bf.s[3][u8(xr)] ^ bf.p[6]) + xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) + + (bf.s[3][u8(xl)] ^ bf.p[7]) + xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) + + (bf.s[3][u8(xr)] ^ bf.p[8]) + xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) + + (bf.s[3][u8(xl)] ^ bf.p[9]) + xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) + + (bf.s[3][u8(xr)] ^ bf.p[10]) + xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) + + (bf.s[3][u8(xl)] ^ bf.p[11]) + xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) + + (bf.s[3][u8(xr)] ^ bf.p[12]) + xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) + + (bf.s[3][u8(xl)] ^ bf.p[13]) + xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) + + (bf.s[3][u8(xr)] ^ bf.p[14]) + xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) + + (bf.s[3][u8(xl)] ^ bf.p[15]) + xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) + + (bf.s[3][u8(xr)] ^ bf.p[16]) xr ^= bf.p[17] res := [xl, xr] return res diff --git a/vlib/crypto/blowfish/blowfish.v b/vlib/crypto/blowfish/blowfish.v index 944253b6b6..2770737b33 100644 --- a/vlib/crypto/blowfish/blowfish.v +++ b/vlib/crypto/blowfish/blowfish.v @@ -40,6 +40,6 @@ pub fn (mut bf Blowfish) encrypt(mut dst []byte, src []byte) { l := u32(src[0]) << 24 | u32(src[1]) << 16 | u32(src[2]) << 8 | u32(src[3]) r := u32(src[4]) << 24 | u32(src[5]) << 16 | u32(src[6]) << 8 | u32(src[7]) arr := setup_tables(l, r, mut bf) - dst[0], dst[1], dst[2], dst[3] = byte(arr[0] >> 24), byte(arr[0] >> 16), byte(arr[0] >> 8), byte(arr[0]) - dst[4], dst[5], dst[6], dst[7] = byte(arr[1] >> 24), byte(arr[1] >> 16), byte(arr[1] >> 8), byte(arr[1]) + dst[0], dst[1], dst[2], dst[3] = u8(arr[0] >> 24), u8(arr[0] >> 16), u8(arr[0] >> 8), u8(arr[0]) + dst[4], dst[5], dst[6], dst[7] = u8(arr[1] >> 24), u8(arr[1] >> 16), u8(arr[1] >> 8), u8(arr[1]) } diff --git a/vlib/crypto/des/const.v b/vlib/crypto/des/const.v index cb103efc41..2f75f9299a 100644 --- a/vlib/crypto/des/const.v +++ b/vlib/crypto/des/const.v @@ -10,35 +10,35 @@ module des // Used to perform an initial permutation of a 64-bit input block. -// const initial_permutation = [byte(6), 14, 22, 30, 38, 46, 54, 62, 4, 12, 20, 28, 36, 44, 52, 60, +// const initial_permutation = [u8(6), 14, 22, 30, 38, 46, 54, 62, 4, 12, 20, 28, 36, 44, 52, 60, // 2, 10, 18, 26, 34, 42, 50, 58, 0, 8, 16, 24, 32, 40, 48, 56, 7, 15, 23, 31, 39, 47, 55, 63, // 5, 13, 21, 29, 37, 45, 53, 61, 3, 11, 19, 27, 35, 43, 51, 59, 1, 9, 17, 25, 33, 41, 49, 57] // // Used to perform a final permutation of a 4-bit preoutput block. This is the // // inverse of initialPermutation -// const final_permutation = [byte(24), 56, 16, 48, 8, 40, 0, 32, 25, 57, 17, 49, 9, 41, 1, 33, 26, +// const final_permutation = [u8(24), 56, 16, 48, 8, 40, 0, 32, 25, 57, 17, 49, 9, 41, 1, 33, 26, // 58, 18, 50, 10, 42, 2, 34, 27, 59, 19, 51, 11, 43, 3, 35, 28, 60, 20, 52, 12, 44, 4, 36, 29, // 61, 21, 53, 13, 45, 5, 37, 30, 62, 22, 54, 14, 46, 6, 38, 31, 63, 23, 55, 15, 47, 7, 39] // // Used to expand an input block of 32 bits, producing an output block of 48 // // bits. -// const expansion_function = [byte(0), 31, 30, 29, 28, 27, 28, 27, 26, 25, 24, 23, 24, 23, 22, 21, +// const expansion_function = [u8(0), 31, 30, 29, 28, 27, 28, 27, 26, 25, 24, 23, 24, 23, 22, 21, // 20, 19, 20, 19, 18, 17, 16, 15, 16, 15, 14, 13, 12, 11, 12, 11, 10, 9, 8, 7, 8, 7, 6, 5, 4, // 3, 4, 3, 2, 1, 0, 31] // // Yields a 32-bit output from a 32-bit input -// const permutation_function = [byte(16), 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22, +// const permutation_function = [u8(16), 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22, // 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7] // Used in the key schedule to select 56 bits // from a 64-bit input. -const permuted_choice1 = [byte(7), 15, 23, 31, 39, 47, 55, 63, 6, 14, 22, 30, 38, 46, 54, 62, 5, +const permuted_choice1 = [u8(7), 15, 23, 31, 39, 47, 55, 63, 6, 14, 22, 30, 38, 46, 54, 62, 5, 13, 21, 29, 37, 45, 53, 61, 4, 12, 20, 28, 1, 9, 17, 25, 33, 41, 49, 57, 2, 10, 18, 26, 34, 42, 50, 58, 3, 11, 19, 27, 35, 43, 51, 59, 36, 44, 52, 60] // Used in the key schedule to produce each subkey by selecting 48 bits from // the 56-bit input -const permuted_choice2 = [byte(42), 39, 45, 32, 55, 51, 53, 28, 41, 50, 35, 46, 33, 37, 44, 52, +const permuted_choice2 = [u8(42), 39, 45, 32, 55, 51, 53, 28, 41, 50, 35, 46, 33, 37, 44, 52, 30, 48, 40, 49, 29, 36, 43, 54, 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24] diff --git a/vlib/crypto/ed25519/internal/ed25519_test.v b/vlib/crypto/ed25519/internal/ed25519_test.v index af154656b0..0e0795d2b4 100644 --- a/vlib/crypto/ed25519/internal/ed25519_test.v +++ b/vlib/crypto/ed25519/internal/ed25519_test.v @@ -63,13 +63,13 @@ fn test_malleability() ? { // https://tools.ietf.org/html/rfc8032#section-5.1.7 adds an additional test // that s be in [0, order). This prevents someone from adding a multiple of // order to s and obtaining a second valid signature for the same message. - msg := [byte(0x54), 0x65, 0x73, 0x74] - sig := [byte(0x7c), 0x38, 0xe0, 0x26, 0xf2, 0x9e, 0x14, 0xaa, 0xbd, 0x05, 0x9a, 0x0f, 0x2d, + msg := [u8(0x54), 0x65, 0x73, 0x74] + sig := [u8(0x7c), 0x38, 0xe0, 0x26, 0xf2, 0x9e, 0x14, 0xaa, 0xbd, 0x05, 0x9a, 0x0f, 0x2d, 0xb8, 0xb0, 0xcd, 0x78, 0x30, 0x40, 0x60, 0x9a, 0x8b, 0xe6, 0x84, 0xdb, 0x12, 0xf8, 0x2a, 0x27, 0x77, 0x4a, 0xb0, 0x67, 0x65, 0x4b, 0xce, 0x38, 0x32, 0xc2, 0xd7, 0x6f, 0x8f, 0x6f, 0x5d, 0xaf, 0xc0, 0x8d, 0x93, 0x39, 0xd4, 0xee, 0xf6, 0x76, 0x57, 0x33, 0x36, 0xa5, 0xc5, 0x1e, 0xb6, 0xf9, 0x46, 0xb3, 0x1d] - publickey := [byte(0x7d), 0x4d, 0x0e, 0x7f, 0x61, 0x53, 0xa6, 0x9b, 0x62, 0x42, 0xb5, 0x22, + publickey := [u8(0x7d), 0x4d, 0x0e, 0x7f, 0x61, 0x53, 0xa6, 0x9b, 0x62, 0x42, 0xb5, 0x22, 0xab, 0xbe, 0xe6, 0x85, 0xfd, 0xa4, 0x42, 0x0f, 0x88, 0x34, 0xb1, 0x08, 0xc3, 0xbd, 0xae, 0x36, 0x9e, 0xf5, 0x49, 0xfa] // verify should fail on provided bytes diff --git a/vlib/crypto/ed25519/internal/edwards25519/element_test.v b/vlib/crypto/ed25519/internal/edwards25519/element_test.v index 3036a4fa88..845f886d39 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/element_test.v +++ b/vlib/crypto/ed25519/internal/edwards25519/element_test.v @@ -237,12 +237,12 @@ fn test_set_bytes_from_dalek_test_vectors() ? { mut tests := [ FeRTTest{ fe: Element{358744748052810, 1691584618240980, 977650209285361, 1429865912637724, 560044844278676} - b: [byte(74), 209, 69, 197, 70, 70, 161, 222, 56, 226, 229, 19, 112, 60, 25, 92, 187, + b: [u8(74), 209, 69, 197, 70, 70, 161, 222, 56, 226, 229, 19, 112, 60, 25, 92, 187, 74, 222, 56, 50, 153, 51, 233, 40, 74, 57, 6, 160, 185, 213, 31] }, FeRTTest{ fe: Element{84926274344903, 473620666599931, 365590438845504, 1028470286882429, 2146499180330972} - b: [byte(199), 23, 106, 112, 61, 77, 216, 79, 186, 60, 11, 118, 13, 16, 103, 15, 42, + b: [u8(199), 23, 106, 112, 61, 77, 216, 79, 186, 60, 11, 118, 13, 16, 103, 15, 42, 32, 83, 250, 44, 57, 204, 198, 78, 199, 253, 119, 146, 172, 3, 122] }, ] diff --git a/vlib/crypto/ed25519/internal/edwards25519/extra_test.v b/vlib/crypto/ed25519/internal/edwards25519/extra_test.v index f6548f3c10..61ae54ab54 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/extra_test.v +++ b/vlib/crypto/ed25519/internal/edwards25519/extra_test.v @@ -90,7 +90,7 @@ fn fn_cofactor(mut data []byte) bool { mut sc := Scalar{ s: [32]byte{} } - sc.s[0] = byte(0x08) + sc.s[0] = u8(0x08) s.multiply(s, sc) mut pp := Point{} pp.scalar_base_mult(mut s) diff --git a/vlib/crypto/ed25519/internal/edwards25519/point.v b/vlib/crypto/ed25519/internal/edwards25519/point.v index ba815668e2..f0bc7d35eb 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/point.v +++ b/vlib/crypto/ed25519/internal/edwards25519/point.v @@ -2,12 +2,12 @@ module edwards25519 const ( // d is a constant in the curve equation. - d_bytes = [byte(0xa3), 0x78, 0x59, 0x13, 0xca, 0x4d, 0xeb, 0x75, 0xab, 0xd8, 0x41, 0x41, + d_bytes = [u8(0xa3), 0x78, 0x59, 0x13, 0xca, 0x4d, 0xeb, 0x75, 0xab, 0xd8, 0x41, 0x41, 0x4d, 0x0a, 0x70, 0x00, 0x98, 0xe8, 0x79, 0x77, 0x79, 0x40, 0xc7, 0x8c, 0x73, 0xfe, 0x6f, 0x2b, 0xee, 0x6c, 0x03, 0x52] - id_bytes = [byte(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + id_bytes = [u8(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - gen_bytes = [byte(0x58), 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, + gen_bytes = [u8(0x58), 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66] d_const = d_const_generate() or { panic(err) } @@ -220,8 +220,8 @@ fn (mut v Point) bytes_generic(mut buf [32]byte) []byte { mut out := copy_field_element(mut buf, mut y) unsafe { - // out[31] |= byte(x.is_negative() << 7) //original one - out[31] |= byte(x.is_negative() * 128) // x << 7 == x * 2^7 + // out[31] |= u8(x.is_negative() << 7) //original one + out[31] |= u8(x.is_negative() * 128) // x << 7 == x * 2^7 } return out } diff --git a/vlib/crypto/ed25519/internal/edwards25519/scalar.v b/vlib/crypto/ed25519/internal/edwards25519/scalar.v index 500d0c2525..13d17994ea 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/scalar.v +++ b/vlib/crypto/ed25519/internal/edwards25519/scalar.v @@ -23,17 +23,17 @@ mut: pub const ( sc_zero = Scalar{ - s: [byte(0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + s: [u8(0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]! } sc_one = Scalar{ - s: [byte(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + s: [u8(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]! } sc_minus_one = Scalar{ - s: [byte(236), 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, + s: [u8(236), 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16]! } ) @@ -613,38 +613,38 @@ fn sc_mul_add(mut s [32]byte, a [32]byte, b [32]byte, c [32]byte) { s11 += carry[10] s10 -= carry[10] * 2097152 - s[0] = byte(s0 >> 0) - s[1] = byte(s0 >> 8) - s[2] = byte((s0 >> 16) | (s1 * 32)) - s[3] = byte(s1 >> 3) - s[4] = byte(s1 >> 11) - s[5] = byte((s1 >> 19) | (s2 * 4)) - s[6] = byte(s2 >> 6) - s[7] = byte((s2 >> 14) | (s3 * 128)) - s[8] = byte(s3 >> 1) - s[9] = byte(s3 >> 9) - s[10] = byte((s3 >> 17) | (s4 * 16)) - s[11] = byte(s4 >> 4) - s[12] = byte(s4 >> 12) - s[13] = byte((s4 >> 20) | (s5 * 2)) - s[14] = byte(s5 >> 7) - s[15] = byte((s5 >> 15) | (s6 * 64)) - s[16] = byte(s6 >> 2) - s[17] = byte(s6 >> 10) - s[18] = byte((s6 >> 18) | (s7 * 8)) - s[19] = byte(s7 >> 5) - s[20] = byte(s7 >> 13) - s[21] = byte(s8 >> 0) - s[22] = byte(s8 >> 8) - s[23] = byte((s8 >> 16) | (s9 * 32)) - s[24] = byte(s9 >> 3) - s[25] = byte(s9 >> 11) - s[26] = byte((s9 >> 19) | (s10 * 4)) - s[27] = byte(s10 >> 6) - s[28] = byte((s10 >> 14) | (s11 * 128)) - s[29] = byte(s11 >> 1) - s[30] = byte(s11 >> 9) - s[31] = byte(s11 >> 17) + s[0] = u8(s0 >> 0) + s[1] = u8(s0 >> 8) + s[2] = u8((s0 >> 16) | (s1 * 32)) + s[3] = u8(s1 >> 3) + s[4] = u8(s1 >> 11) + s[5] = u8((s1 >> 19) | (s2 * 4)) + s[6] = u8(s2 >> 6) + s[7] = u8((s2 >> 14) | (s3 * 128)) + s[8] = u8(s3 >> 1) + s[9] = u8(s3 >> 9) + s[10] = u8((s3 >> 17) | (s4 * 16)) + s[11] = u8(s4 >> 4) + s[12] = u8(s4 >> 12) + s[13] = u8((s4 >> 20) | (s5 * 2)) + s[14] = u8(s5 >> 7) + s[15] = u8((s5 >> 15) | (s6 * 64)) + s[16] = u8(s6 >> 2) + s[17] = u8(s6 >> 10) + s[18] = u8((s6 >> 18) | (s7 * 8)) + s[19] = u8(s7 >> 5) + s[20] = u8(s7 >> 13) + s[21] = u8(s8 >> 0) + s[22] = u8(s8 >> 8) + s[23] = u8((s8 >> 16) | (s9 * 32)) + s[24] = u8(s9 >> 3) + s[25] = u8(s9 >> 11) + s[26] = u8((s9 >> 19) | (s10 * 4)) + s[27] = u8(s10 >> 6) + s[28] = u8((s10 >> 14) | (s11 * 128)) + s[29] = u8(s11 >> 1) + s[30] = u8(s11 >> 9) + s[31] = u8(s11 >> 17) } // Input: @@ -940,38 +940,38 @@ fn sc_reduce(mut out [32]byte, mut s []byte) { s11 += carry[10] s10 -= carry[10] * 2097152 - out[0] = byte(s0 >> 0) - out[1] = byte(s0 >> 8) - out[2] = byte((s0 >> 16) | (s1 * 32)) - out[3] = byte(s1 >> 3) - out[4] = byte(s1 >> 11) - out[5] = byte((s1 >> 19) | (s2 * 4)) - out[6] = byte(s2 >> 6) - out[7] = byte((s2 >> 14) | (s3 * 128)) - out[8] = byte(s3 >> 1) - out[9] = byte(s3 >> 9) - out[10] = byte((s3 >> 17) | (s4 * 16)) - out[11] = byte(s4 >> 4) - out[12] = byte(s4 >> 12) - out[13] = byte((s4 >> 20) | (s5 * 2)) - out[14] = byte(s5 >> 7) - out[15] = byte((s5 >> 15) | (s6 * 64)) - out[16] = byte(s6 >> 2) - out[17] = byte(s6 >> 10) - out[18] = byte((s6 >> 18) | (s7 * 8)) - out[19] = byte(s7 >> 5) - out[20] = byte(s7 >> 13) - out[21] = byte(s8 >> 0) - out[22] = byte(s8 >> 8) - out[23] = byte((s8 >> 16) | (s9 * 32)) - out[24] = byte(s9 >> 3) - out[25] = byte(s9 >> 11) - out[26] = byte((s9 >> 19) | (s10 * 4)) - out[27] = byte(s10 >> 6) - out[28] = byte((s10 >> 14) | (s11 * 128)) - out[29] = byte(s11 >> 1) - out[30] = byte(s11 >> 9) - out[31] = byte(s11 >> 17) + out[0] = u8(s0 >> 0) + out[1] = u8(s0 >> 8) + out[2] = u8((s0 >> 16) | (s1 * 32)) + out[3] = u8(s1 >> 3) + out[4] = u8(s1 >> 11) + out[5] = u8((s1 >> 19) | (s2 * 4)) + out[6] = u8(s2 >> 6) + out[7] = u8((s2 >> 14) | (s3 * 128)) + out[8] = u8(s3 >> 1) + out[9] = u8(s3 >> 9) + out[10] = u8((s3 >> 17) | (s4 * 16)) + out[11] = u8(s4 >> 4) + out[12] = u8(s4 >> 12) + out[13] = u8((s4 >> 20) | (s5 * 2)) + out[14] = u8(s5 >> 7) + out[15] = u8((s5 >> 15) | (s6 * 64)) + out[16] = u8(s6 >> 2) + out[17] = u8(s6 >> 10) + out[18] = u8((s6 >> 18) | (s7 * 8)) + out[19] = u8(s7 >> 5) + out[20] = u8(s7 >> 13) + out[21] = u8(s8 >> 0) + out[22] = u8(s8 >> 8) + out[23] = u8((s8 >> 16) | (s9 * 32)) + out[24] = u8(s9 >> 3) + out[25] = u8(s9 >> 11) + out[26] = u8((s9 >> 19) | (s10 * 4)) + out[27] = u8(s10 >> 6) + out[28] = u8((s10 >> 14) | (s11 * 128)) + out[29] = u8(s11 >> 1) + out[30] = u8(s11 >> 9) + out[31] = u8(s11 >> 17) } // non_adjacent_form computes a width-w non-adjacent form for this scalar. diff --git a/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v b/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v index 9a5ab90eed..acddc2f541 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v +++ b/vlib/crypto/ed25519/internal/edwards25519/scalar_test.v @@ -22,7 +22,7 @@ fn test_scalar_equal() { fn test_scalar_non_adjacent_form() { mut s := Scalar{ - s: [byte(0x1a), 0x0e, 0x97, 0x8a, 0x90, 0xf6, 0x62, 0x2d, 0x37, 0x47, 0x02, 0x3f, 0x8a, + s: [u8(0x1a), 0x0e, 0x97, 0x8a, 0x90, 0xf6, 0x62, 0x2d, 0x37, 0x47, 0x02, 0x3f, 0x8a, 0xd8, 0x26, 0x4d, 0xa7, 0x58, 0xaa, 0x1b, 0x88, 0xe0, 0x40, 0xd1, 0x58, 0x9e, 0x7b, 0x7f, 0x23, 0x76, 0xef, 0x09]! } @@ -101,7 +101,7 @@ fn test_scalar_set_canonical_bytes_round_trip() ? { const ( sc_error = Scalar{ - s: [32]byte{init: (byte(-1))} + s: [32]byte{init: (u8(-1))} } ) diff --git a/vlib/crypto/ed25519/internal/edwards25519/scalarmult_test.v b/vlib/crypto/ed25519/internal/edwards25519/scalarmult_test.v index e976141dd7..f3b270aaf0 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/scalarmult_test.v +++ b/vlib/crypto/ed25519/internal/edwards25519/scalarmult_test.v @@ -1,9 +1,9 @@ module edwards25519 const ( - dalek_scalar = Scalar{[byte(219), 106, 114, 9, 174, 249, 155, 89, 69, 203, 201, 93, 92, 116, + dalek_scalar = Scalar{[u8(219), 106, 114, 9, 174, 249, 155, 89, 69, 203, 201, 93, 92, 116, 234, 187, 78, 115, 103, 172, 182, 98, 62, 103, 187, 136, 13, 100, 248, 110, 12, 4]!} - dsc_basepoint = [byte(0xf4), 0xef, 0x7c, 0xa, 0x34, 0x55, 0x7b, 0x9f, 0x72, 0x3b, 0xb6, 0x1e, + dsc_basepoint = [u8(0xf4), 0xef, 0x7c, 0xa, 0x34, 0x55, 0x7b, 0x9f, 0x72, 0x3b, 0xb6, 0x1e, 0xf9, 0x46, 0x9, 0x91, 0x1c, 0xb9, 0xc0, 0x6c, 0x17, 0x28, 0x2d, 0x8b, 0x43, 0x2b, 0x5, 0x18, 0x6a, 0x54, 0x3e, 0x48] ) @@ -24,7 +24,7 @@ fn test_scalar_mult_small_scalars() { assert i.equal(p) == 1 assert check_on_curve(p) == true - z = Scalar{[byte(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + z = Scalar{[u8(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]!} p.scalar_mult(mut z, b) diff --git a/vlib/crypto/ed25519/internal/edwards25519/table.v b/vlib/crypto/ed25519/internal/edwards25519/table.v index d8ae7937ba..bf160ffe4d 100644 --- a/vlib/crypto/ed25519/internal/edwards25519/table.v +++ b/vlib/crypto/ed25519/internal/edwards25519/table.v @@ -88,12 +88,12 @@ fn (mut v NafLookupTable8) from_p3(q Point) { fn (mut v ProjLookupTable) select_into(mut dest ProjectiveCached, x i8) { // Compute xabs = |x| xmask := x >> 7 - xabs := byte((x + xmask) ^ xmask) + xabs := u8((x + xmask) ^ xmask) dest.zero() for j := 1; j <= 8; j++ { // Set dest = j*Q if |x| = j - cond := subtle.constant_time_byte_eq(xabs, byte(j)) + cond := subtle.constant_time_byte_eq(xabs, u8(j)) dest.selected(&v.points[j - 1], dest, cond) } // Now dest = |x|*Q, conditionally negate to get x*Q @@ -104,12 +104,12 @@ fn (mut v ProjLookupTable) select_into(mut dest ProjectiveCached, x i8) { fn (mut v AffineLookupTable) select_into(mut dest AffineCached, x i8) { // Compute xabs = |x| xmask := x >> 7 - xabs := byte((x + xmask) ^ xmask) + xabs := u8((x + xmask) ^ xmask) dest.zero() for j := 1; j <= 8; j++ { // Set dest = j*Q if |x| = j - cond := subtle.constant_time_byte_eq(xabs, byte(j)) + cond := subtle.constant_time_byte_eq(xabs, u8(j)) dest.selected(v.points[j - 1], dest, cond) } // Now dest = |x|*Q, conditionally negate to get x*Q diff --git a/vlib/crypto/hmac/hmac_test.v b/vlib/crypto/hmac/hmac_test.v index c1b66678fb..31c31a6a8b 100644 --- a/vlib/crypto/hmac/hmac_test.v +++ b/vlib/crypto/hmac/hmac_test.v @@ -21,21 +21,21 @@ import crypto.sha512 // import crypto.blake2b_512 const ( keys = [ - [byte(0xb), 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb], + [u8(0xb), 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb], 'Jefe'.bytes(), - [byte(0xAA), 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, + [u8(0xAA), 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA], - [byte(0x01), 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + [u8(0x01), 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19], - [byte(0x0c), 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, + [u8(0x0c), 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c], - [byte(0xaa), 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + [u8(0xaa), 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa], - [byte(0xaa), 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + [u8(0xaa), 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, @@ -43,11 +43,11 @@ const ( 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa], ] data = ['Hi There'.bytes(), 'what do ya want for nothing?'.bytes(), - [byte(0xDD), 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + [u8(0xDD), 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD], - [byte(0xcd), 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, + [u8(0xcd), 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd], diff --git a/vlib/crypto/internal/subtle/comparison.v b/vlib/crypto/internal/subtle/comparison.v index e7dd1624fe..38cd09c449 100644 --- a/vlib/crypto/internal/subtle/comparison.v +++ b/vlib/crypto/internal/subtle/comparison.v @@ -23,7 +23,7 @@ pub fn constant_time_compare(x []byte, y []byte) int { if x.len != y.len { return 0 } - mut v := byte(0) + mut v := u8(0) for i in 0 .. x.len { v |= x[i] ^ y[i] } @@ -37,8 +37,8 @@ pub fn constant_time_copy(v int, mut x []byte, y []byte) { if x.len != y.len { panic('subtle: arrays have different lengths') } - xmask := byte(v - 1) - ymask := byte(~(v - 1)) + xmask := u8(v - 1) + ymask := u8(~(v - 1)) for i := 0; i < x.len; i++ { x[i] = x[i] & xmask | y[i] & ymask } diff --git a/vlib/crypto/internal/subtle/comparison_test.v b/vlib/crypto/internal/subtle/comparison_test.v index b339746bf1..8222ce5568 100644 --- a/vlib/crypto/internal/subtle/comparison_test.v +++ b/vlib/crypto/internal/subtle/comparison_test.v @@ -35,20 +35,20 @@ fn test_constant_time_select() { } fn test_constant_time_compare() { - assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3]) == 1 - assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 9]) == 0 - assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3, 4]) == 0 - assert constant_time_compare([byte(1), 2, 3], [byte(1), 2]) == 0 + assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 3]) == 1 + assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 9]) == 0 + assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 3, 4]) == 0 + assert constant_time_compare([u8(1), 2, 3], [u8(1), 2]) == 0 } fn test_constant_time_copy() { - y := [byte(3), 4, 5] - mut x := [byte(0), 0, 0] + y := [u8(3), 4, 5] + mut x := [u8(0), 0, 0] constant_time_copy(0, mut x, y) - assert x == [byte(0), 0, 0] + assert x == [u8(0), 0, 0] constant_time_copy(1, mut x, y) assert x == y - assert x == [byte(3), 4, 5] + assert x == [u8(3), 4, 5] } fn test_constant_time_less_or_eq() { diff --git a/vlib/crypto/rand/utils.v b/vlib/crypto/rand/utils.v index 45a2ca5404..9ce01e26b9 100644 --- a/vlib/crypto/rand/utils.v +++ b/vlib/crypto/rand/utils.v @@ -21,7 +21,7 @@ pub fn int_u64(max u64) ?u64 { mut n := u64(0) for { mut bytes := read(k) ? - bytes[0] &= byte(int(u64(1) << b) - 1) + bytes[0] &= u8(int(u64(1) << b) - 1) x := bytes_to_u64(bytes) n = x[0] // NOTE: maybe until we have bigint could do it another way? diff --git a/vlib/crypto/rc4/rc4.v b/vlib/crypto/rc4/rc4.v index 7c28fd2825..0bcaff30f3 100644 --- a/vlib/crypto/rc4/rc4.v +++ b/vlib/crypto/rc4/rc4.v @@ -32,9 +32,9 @@ pub fn new_cipher(key []byte) ?Cipher { for i in 0 .. 256 { c.s[i] = u32(i) } - mut j := byte(0) + mut j := u8(0) for i in 0 .. 256 { - j += byte(c.s[i]) + key[i % key.len] + j += u8(c.s[i]) + key[i % key.len] tmp := c.s[i] c.s[i] = c.s[j] c.s[j] = tmp @@ -66,13 +66,13 @@ pub fn (mut c Cipher) xor_key_stream(mut dst []byte, mut src []byte) { mut i := c.i mut j := c.j for k, v in src { - i += byte(1) + i += u8(1) x := c.s[i] - j += byte(x) + j += u8(x) y := c.s[j] c.s[i] = y c.s[j] = x - dst[k] = v ^ byte(c.s[byte(x + y)]) + dst[k] = v ^ u8(c.s[u8(x + y)]) } c.i = i c.j = j diff --git a/vlib/encoding/base58/base58.v b/vlib/encoding/base58/base58.v index fb2ff72027..d1a7bfd715 100644 --- a/vlib/encoding/base58/base58.v +++ b/vlib/encoding/base58/base58.v @@ -65,7 +65,7 @@ pub fn encode_walpha(input string, alphabet Alphabet) string { i = sz - 1 for carry = u32(b); i > high || carry != 0; i-- { carry = carry + 256 * u32(out[i]) - out[i] = byte(carry % 58) + out[i] = u8(carry % 58) carry /= 58 } high = 1 @@ -94,7 +94,7 @@ pub fn decode_int_walpha(input string, alphabet Alphabet) ?int { mut total := 0 // to hold the results b58 := input.reverse() for i, ch in b58 { - ch_i := alphabet.encode.bytestr().index_byte(ch) + ch_i := alphabet.encode.bytestr().index_u8(ch) if ch_i == -1 { return error(@MOD + '.' + @FN + ': input string contains values not found in the provided alphabet') @@ -162,7 +162,7 @@ pub fn decode_walpha(str string, alphabet Alphabet) ?string { mut out_len := 0 for j := 0; j < outi.len; j++ { for mask < 32 { - binu[out_len] = byte(outi[j] >> mask) + binu[out_len] = u8(outi[j] >> mask) mask -= 8 out_len++ } diff --git a/vlib/encoding/base64/base64.c.v b/vlib/encoding/base64/base64.c.v index 02053cda3e..ba1bd6c116 100644 --- a/vlib/encoding/base64/base64.c.v +++ b/vlib/encoding/base64/base64.c.v @@ -57,11 +57,11 @@ fn encode_from_buffer(dest &byte, src &byte, src_len int) int { match remain { 2 { b[di + 2] = etable[val >> 6 & 0x3F] - b[di + 3] = byte(`=`) + b[di + 3] = u8(`=`) } 1 { - b[di + 2] = byte(`=`) - b[di + 3] = byte(`=`) + b[di + 2] = u8(`=`) + b[di + 3] = u8(`=`) } else { panic('base64: This case should never occur.') @@ -125,9 +125,9 @@ fn decode_from_buffer(dest &byte, src &byte, src_len int) int { for src_len - si >= 8 { // Converting 8 bytes of input into 6 bytes of output. Storing these in the upper bytes of an u64. - datablock_64.data = assemble64(byte(index[d[si + 0]]), byte(index[d[si + 1]]), - byte(index[d[si + 2]]), byte(index[d[si + 3]]), byte(index[d[si + 4]]), - byte(index[d[si + 5]]), byte(index[d[si + 6]]), byte(index[d[si + 7]])) + datablock_64.data = assemble64(u8(index[d[si + 0]]), u8(index[d[si + 1]]), + u8(index[d[si + 2]]), u8(index[d[si + 3]]), u8(index[d[si + 4]]), + u8(index[d[si + 5]]), u8(index[d[si + 6]]), u8(index[d[si + 7]])) // Reading out the individual bytes from the u64. Watch out with endianess. $if little_endian { @@ -151,8 +151,8 @@ fn decode_from_buffer(dest &byte, src &byte, src_len int) int { } for src_len - si >= 4 { - datablock_32.data = assemble32(byte(index[d[si + 0]]), byte(index[d[si + 1]]), - byte(index[d[si + 2]]), byte(index[d[si + 3]])) + datablock_32.data = assemble32(u8(index[d[si + 0]]), u8(index[d[si + 1]]), + u8(index[d[si + 2]]), u8(index[d[si + 3]])) $if little_endian { b[n_decoded_bytes + 0] = datablock_32.data_byte[3] b[n_decoded_bytes + 1] = datablock_32.data_byte[2] diff --git a/vlib/encoding/base64/base64_test.v b/vlib/encoding/base64/base64_test.v index 8d08de24ad..95e557cf94 100644 --- a/vlib/encoding/base64/base64_test.v +++ b/vlib/encoding/base64/base64_test.v @@ -111,23 +111,23 @@ fn test_url_decode_str() { assert test == 'Hello Base64Url encoding!' } -fn test_encode_null_byte() { - assert base64.encode([byte(`A`), 0, `C`]) == 'QQBD' +fn test_encode_null_u8() { + assert base64.encode([u8(`A`), 0, `C`]) == 'QQBD' } fn test_encode_null_byte_str() { // While this works, bytestr() does a memcpy - s := [byte(`A`), 0, `C`].bytestr() + s := [u8(`A`), 0, `C`].bytestr() assert base64.encode_str(s) == 'QQBD' } -fn test_decode_null_byte() { - assert base64.decode('QQBD') == [byte(`A`), 0, `C`] +fn test_decode_null_u8() { + assert base64.decode('QQBD') == [u8(`A`), 0, `C`] } fn test_decode_null_byte_str() { // While this works, bytestr() does a memcpy - s := [byte(`A`), 0, `C`].bytestr() + s := [u8(`A`), 0, `C`].bytestr() assert base64.decode_str('QQBD') == s } diff --git a/vlib/encoding/binary/binary.v b/vlib/encoding/binary/binary.v index 48ac434b0b..3a6753f9b5 100644 --- a/vlib/encoding/binary/binary.v +++ b/vlib/encoding/binary/binary.v @@ -13,8 +13,8 @@ pub fn little_endian_u16(b []byte) u16 { [inline] pub fn little_endian_put_u16(mut b []byte, v u16) { _ = b[1] // bounds check - b[0] = byte(v) - b[1] = byte(v >> u16(8)) + b[0] = u8(v) + b[1] = u8(v >> u16(8)) } [inline] @@ -26,10 +26,10 @@ pub fn little_endian_u32(b []byte) u32 { [inline] pub fn little_endian_put_u32(mut b []byte, v u32) { _ = b[3] // bounds check - b[0] = byte(v) - b[1] = byte(v >> u32(8)) - b[2] = byte(v >> u32(16)) - b[3] = byte(v >> u32(24)) + b[0] = u8(v) + b[1] = u8(v >> u32(8)) + b[2] = u8(v >> u32(16)) + b[3] = u8(v >> u32(24)) } [inline] @@ -41,14 +41,14 @@ pub fn little_endian_u64(b []byte) u64 { [inline] pub fn little_endian_put_u64(mut b []byte, v u64) { _ = b[7] // bounds check - b[0] = byte(v) - b[1] = byte(v >> u64(8)) - b[2] = byte(v >> u64(16)) - b[3] = byte(v >> u64(24)) - b[4] = byte(v >> u64(32)) - b[5] = byte(v >> u64(40)) - b[6] = byte(v >> u64(48)) - b[7] = byte(v >> u64(56)) + b[0] = u8(v) + b[1] = u8(v >> u64(8)) + b[2] = u8(v >> u64(16)) + b[3] = u8(v >> u64(24)) + b[4] = u8(v >> u64(32)) + b[5] = u8(v >> u64(40)) + b[6] = u8(v >> u64(48)) + b[7] = u8(v >> u64(56)) } // Big Endian @@ -61,8 +61,8 @@ pub fn big_endian_u16(b []byte) u16 { [inline] pub fn big_endian_put_u16(mut b []byte, v u16) { _ = b[1] // bounds check - b[0] = byte(v >> u16(8)) - b[1] = byte(v) + b[0] = u8(v >> u16(8)) + b[1] = u8(v) } [inline] @@ -74,10 +74,10 @@ pub fn big_endian_u32(b []byte) u32 { [inline] pub fn big_endian_put_u32(mut b []byte, v u32) { _ = b[3] // bounds check - b[0] = byte(v >> u32(24)) - b[1] = byte(v >> u32(16)) - b[2] = byte(v >> u32(8)) - b[3] = byte(v) + b[0] = u8(v >> u32(24)) + b[1] = u8(v >> u32(16)) + b[2] = u8(v >> u32(8)) + b[3] = u8(v) } [inline] @@ -89,12 +89,12 @@ pub fn big_endian_u64(b []byte) u64 { [inline] pub fn big_endian_put_u64(mut b []byte, v u64) { _ = b[7] // bounds check - b[0] = byte(v >> u64(56)) - b[1] = byte(v >> u64(48)) - b[2] = byte(v >> u64(40)) - b[3] = byte(v >> u64(32)) - b[4] = byte(v >> u64(24)) - b[5] = byte(v >> u64(16)) - b[6] = byte(v >> u64(8)) - b[7] = byte(v) + b[0] = u8(v >> u64(56)) + b[1] = u8(v >> u64(48)) + b[2] = u8(v >> u64(40)) + b[3] = u8(v >> u64(32)) + b[4] = u8(v >> u64(24)) + b[5] = u8(v >> u64(16)) + b[6] = u8(v >> u64(8)) + b[7] = u8(v) } diff --git a/vlib/encoding/hex/hex.v b/vlib/encoding/hex/hex.v index 7698f4acf0..4dcc8a3fc2 100644 --- a/vlib/encoding/hex/hex.v +++ b/vlib/encoding/hex/hex.v @@ -54,9 +54,9 @@ pub fn encode(bytes []byte) string { // char2nibble converts an ASCII hex character to it's hex value fn char2nibble(b byte) ?byte { match b { - `0`...`9` { return b - byte(`0`) } - `A`...`F` { return b - byte(`A`) + 10 } - `a`...`f` { return b - byte(`a`) + 10 } + `0`...`9` { return b - u8(`0`) } + `A`...`F` { return b - u8(`A`) + 10 } + `a`...`f` { return b - u8(`a`) + 10 } else { return error('invalid hex char $b.ascii_str()') } } } diff --git a/vlib/encoding/hex/hex_test.v b/vlib/encoding/hex/hex_test.v index 62501e9ded..81ffb045a7 100644 --- a/vlib/encoding/hex/hex_test.v +++ b/vlib/encoding/hex/hex_test.v @@ -2,15 +2,15 @@ module hex fn test_decode() ? { assert decode('') ? == [] - assert decode('0') ? == [byte(0x0)] - assert decode('f') ? == [byte(0xf)] - assert decode('0f') ? == [byte(0x0f)] - assert decode('ff') ? == [byte(0xff)] - assert decode('123') ? == [byte(0x1), 0x23] - assert decode('1234') ? == [byte(0x12), 0x34] - assert decode('12345') ? == [byte(0x1), 0x23, 0x45] - assert decode('0123456789abcdef') ? == [byte(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] - assert decode('123456789ABCDEF') ? == [byte(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] + assert decode('0') ? == [u8(0x0)] + assert decode('f') ? == [u8(0xf)] + assert decode('0f') ? == [u8(0x0f)] + assert decode('ff') ? == [u8(0xff)] + assert decode('123') ? == [u8(0x1), 0x23] + assert decode('1234') ? == [u8(0x12), 0x34] + assert decode('12345') ? == [u8(0x1), 0x23, 0x45] + assert decode('0123456789abcdef') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] + assert decode('123456789ABCDEF') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] } fn test_decode_fails() ? { @@ -46,9 +46,9 @@ fn test_encode() ? { fn test_decode_0x() ? { assert decode('0x') ? == [] - assert decode('0x0') ? == [byte(0x0)] - assert decode('0X1234') ? == [byte(0x12), 0x34] - assert decode('0x12345') ? == [byte(0x1), 0x23, 0x45] - assert decode('0x0123456789abcdef') ? == [byte(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] - assert decode('0X123456789ABCDEF') ? == [byte(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] + assert decode('0x0') ? == [u8(0x0)] + assert decode('0X1234') ? == [u8(0x12), 0x34] + assert decode('0x12345') ? == [u8(0x1), 0x23, 0x45] + assert decode('0x0123456789abcdef') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] + assert decode('0X123456789ABCDEF') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] } diff --git a/vlib/encoding/utf8/utf8_util.v b/vlib/encoding/utf8/utf8_util.v index e406f37224..85853dc71c 100644 --- a/vlib/encoding/utf8/utf8_util.v +++ b/vlib/encoding/utf8/utf8_util.v @@ -147,7 +147,7 @@ pub fn is_control(r rune) bool { if r > max_latin_1 { return false } - return props[byte(r)] == 1 + return props[u8(r)] == 1 } // is_letter returns true if the rune is unicode letter or in unicode category L @@ -155,7 +155,7 @@ pub fn is_letter(r rune) bool { if (r >= `a` && r <= `z`) || (r >= `A` && r <= `Z`) { return true } else if r <= max_latin_1 { - return props[byte(r)] & p_l_mask != 0 + return props[u8(r)] & p_l_mask != 0 } return is_excluding_latin(letter_table, r) } @@ -405,11 +405,11 @@ fn up_low(s string, upper_flag bool) string { if ch_len == 1 { if upper_flag == true { unsafe { - str_res[index] = byte(C.toupper(s.str[index])) + str_res[index] = u8(C.toupper(s.str[index])) } } else { unsafe { - str_res[index] = byte(C.tolower(s.str[index])) + str_res[index] = u8(C.tolower(s.str[index])) } } } else if ch_len > 1 && ch_len < 5 { @@ -451,8 +451,8 @@ fn up_low(s string, upper_flag bool) string { } if ch_len == 2 { - ch0 := byte((tab_char >> 6) & 0x1f) | 0xc0 // 110x xxxx - ch1 := byte((tab_char >> 0) & 0x3f) | 0x80 // 10xx xxxx + ch0 := u8((tab_char >> 6) & 0x1f) | 0xc0 // 110x xxxx + ch1 := u8((tab_char >> 0) & 0x3f) | 0x80 // 10xx xxxx // C.printf("[%02x%02x] \n",ch0,ch1) unsafe { @@ -462,11 +462,11 @@ fn up_low(s string, upper_flag bool) string { //**************************************************************** // BUG: doesn't compile, workaround use shitf to right of 0 bit //**************************************************************** - // str_res[index + 1 ] = byte( tab_char & 0xbf ) // 1011 1111 + // str_res[index + 1 ] = u8( tab_char & 0xbf ) // 1011 1111 } else if ch_len == 3 { - ch0 := byte((tab_char >> 12) & 0x0f) | 0xe0 // 1110 xxxx - ch1 := byte((tab_char >> 6) & 0x3f) | 0x80 // 10xx xxxx - ch2 := byte((tab_char >> 0) & 0x3f) | 0x80 // 10xx xxxx + ch0 := u8((tab_char >> 12) & 0x0f) | 0xe0 // 1110 xxxx + ch1 := u8((tab_char >> 6) & 0x3f) | 0x80 // 10xx xxxx + ch2 := u8((tab_char >> 0) & 0x3f) | 0x80 // 10xx xxxx // C.printf("[%02x%02x%02x] \n",ch0,ch1,ch2) unsafe { diff --git a/vlib/flag/flag.v b/vlib/flag/flag.v index 9ef26b5a6a..116c126890 100644 --- a/vlib/flag/flag.v +++ b/vlib/flag/flag.v @@ -305,7 +305,7 @@ fn (mut fs FlagParser) parse_bool_value(longhand string, shorthand byte) ?string fs.args.delete(i) return val } - if arg.len > 1 && arg[0] == `-` && arg[1] != `-` && arg.index_byte(shorthand) != -1 { + if arg.len > 1 && arg[0] == `-` && arg[1] != `-` && arg.index_u8(shorthand) != -1 { // -abc is equivalent to -a -b -c return 'true' } diff --git a/vlib/fontstash/fontstash.c.v b/vlib/fontstash/fontstash.c.v index c59d03451c..cdc19c881a 100644 --- a/vlib/fontstash/fontstash.c.v +++ b/vlib/fontstash/fontstash.c.v @@ -252,7 +252,7 @@ pub fn (s &Context) text_iter_next(iter &C.FONStextIter, quad &C.FONSquad) int { // `width` and `height` is assigned the size of the texture dimensions. [inline] pub fn (s &Context) get_texture_data(width &int, height &int) &byte { - return &byte(C.fonsGetTextureData(s, width, height)) + return &u8(C.fonsGetTextureData(s, width, height)) } // validate_texture fills the `dirty` argument with the pixel dimensions diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index ae62ca0098..e19ea24b29 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -268,12 +268,12 @@ fn gg_event_fn(ce voidptr, user_data voidptr) { } if e.typ == .mouse_down { bitplace := int(e.mouse_button) - ctx.mbtn_mask |= byte(1 << bitplace) + ctx.mbtn_mask |= u8(1 << bitplace) ctx.mouse_buttons = MouseButtons(ctx.mbtn_mask) } if e.typ == .mouse_up { bitplace := int(e.mouse_button) - ctx.mbtn_mask &= ~(byte(1 << bitplace)) + ctx.mbtn_mask &= ~(u8(1 << bitplace)) ctx.mouse_buttons = MouseButtons(ctx.mbtn_mask) } if e.typ == .mouse_move && e.mouse_button == .invalid { diff --git a/vlib/gg/gg.js.v b/vlib/gg/gg.js.v index ade590466a..e71b7bc30a 100644 --- a/vlib/gg/gg.js.v +++ b/vlib/gg/gg.js.v @@ -524,7 +524,7 @@ fn (mut g Context) handle_mouse_event(event JS.MouseEvent, typ DOMEventType) Eve e.mouse_dx = int(event.movementX) e.mouse_dy = int(event.movementY) bitplace := int(event.button) - g.mbtn_mask |= byte(1 << bitplace) + g.mbtn_mask |= u8(1 << bitplace) // g.mouse_buttons = MouseButtons(g.mbtn_mask) g.mouse_pos_x = int(event.offsetX) diff --git a/vlib/gx/color.v b/vlib/gx/color.v index 14ea53f78a..c1d38fd4d2 100644 --- a/vlib/gx/color.v +++ b/vlib/gx/color.v @@ -125,10 +125,10 @@ pub mut: // hex takes in a 32 bit integer and splits it into 4 byte values pub fn hex(color int) Color { return Color{ - r: byte((color >> 24) & 0xFF) - g: byte((color >> 16) & 0xFF) - b: byte((color >> 8) & 0xFF) - a: byte(color & 0xFF) + r: u8((color >> 24) & 0xFF) + g: u8((color >> 16) & 0xFF) + b: u8((color >> 8) & 0xFF) + a: u8(color & 0xFF) } } @@ -168,10 +168,10 @@ pub fn (a Color) + (b Color) Color { nb = 255 } return Color{ - r: byte(nr) - g: byte(ng) - b: byte(nb) - a: byte(na) + r: u8(nr) + g: u8(ng) + b: u8(nb) + a: u8(na) } } @@ -194,10 +194,10 @@ pub fn (a Color) - (b Color) Color { nb = 0 } return Color{ - r: byte(nr) - g: byte(ng) - b: byte(nb) - a: byte(na) + r: u8(nr) + g: u8(ng) + b: u8(nb) + a: u8(na) } } @@ -230,10 +230,10 @@ pub fn (a Color) over(b Color) Color { gr := (f32(a.g) * aa + f32(b.g) * ab * (1 - aa)) / ar br := (f32(a.b) * aa + f32(b.b) * ab * (1 - aa)) / ar return Color{ - r: byte(rr) - g: byte(gr) - b: byte(br) - a: byte(ar * 255) + r: u8(rr) + g: u8(gr) + b: u8(br) + a: u8(ar * 255) } } diff --git a/vlib/hash/crc32/crc32.v b/vlib/hash/crc32/crc32.v index efabed97e5..f7202829bc 100644 --- a/vlib/hash/crc32/crc32.v +++ b/vlib/hash/crc32/crc32.v @@ -40,7 +40,7 @@ fn (mut c Crc32) generate_table(poly int) { fn (c &Crc32) sum32(b []byte) u32 { mut crc := ~u32(0) for i in 0 .. b.len { - crc = c.table[byte(crc) ^ b[i]] ^ (crc >> 8) + crc = c.table[u8(crc) ^ b[i]] ^ (crc >> 8) } return ~crc } diff --git a/vlib/hash/fnv1a/fnv1a.v b/vlib/hash/fnv1a/fnv1a.v index ffe1384350..f4e6f08d44 100644 --- a/vlib/hash/fnv1a/fnv1a.v +++ b/vlib/hash/fnv1a/fnv1a.v @@ -34,7 +34,7 @@ pub fn sum32(data []byte) u32 { // sum32_bytes returns a fnv1a hash of the struct `s`. [direct_array_access; inline] pub fn sum32_struct(s &T) u32 { - bp := unsafe { &byte(s) } + bp := unsafe { &u8(s) } sz := int(sizeof(T)) mut hash := fnv1a.fnv32_offset_basis for i in 0 .. sz { @@ -89,7 +89,7 @@ pub fn sum64_bytes(data &byte, data_len int) u64 { // sum64_bytes returns a fnv1a hash of the struct `s`. [direct_array_access; inline] pub fn sum64_struct(s &T) u64 { - bp := unsafe { &byte(s) } + bp := unsafe { &u8(s) } sz := int(sizeof(T)) mut hash := fnv1a.fnv64_offset_basis for i in 0 .. sz { diff --git a/vlib/hash/wyhash.c.v b/vlib/hash/wyhash.c.v index 9fc4b06c5e..98cad20206 100644 --- a/vlib/hash/wyhash.c.v +++ b/vlib/hash/wyhash.c.v @@ -23,5 +23,5 @@ pub fn sum64_string(key string, seed u64) u64 { [inline] pub fn sum64(key []byte, seed u64) u64 { - return wyhash_c(&byte(key.data), u64(key.len), seed) + return wyhash_c(&u8(key.data), u64(key.len), seed) } diff --git a/vlib/io/custom_string_reading_test.v b/vlib/io/custom_string_reading_test.v index 432fcf3b30..008ecc0c61 100644 --- a/vlib/io/custom_string_reading_test.v +++ b/vlib/io/custom_string_reading_test.v @@ -46,10 +46,10 @@ fn read_from_string(text string, capacity int) []byte { pub fn test_reading_from_a_string() { for capacity in 1 .. 1000 { - assert read_from_string('a', capacity) == [byte(`a`)] - assert read_from_string('ab', capacity) == [byte(`a`), `b`] - assert read_from_string('abc', capacity) == [byte(`a`), `b`, `c`] - assert read_from_string('abcde', capacity) == [byte(`a`), `b`, `c`, `d`, `e`] + assert read_from_string('a', capacity) == [u8(`a`)] + assert read_from_string('ab', capacity) == [u8(`a`), `b`] + assert read_from_string('abc', capacity) == [u8(`a`), `b`, `c`] + assert read_from_string('abcde', capacity) == [u8(`a`), `b`, `c`, `d`, `e`] large_string_bytes := []byte{len: 1000, init: `x`} large_string := large_string_bytes.bytestr() assert read_from_string(large_string, capacity) == large_string_bytes diff --git a/vlib/json/json_primitives.v b/vlib/json/json_primitives.v index 4e886e2fe1..05689d6304 100644 --- a/vlib/json/json_primitives.v +++ b/vlib/json/json_primitives.v @@ -71,18 +71,18 @@ fn decode_i64(root &C.cJSON) i64 { return i64(root.valuedouble) // i64 is double in C } -fn decode_byte(root &C.cJSON) byte { +fn decode_u8(root &C.cJSON) byte { if isnil(root) { - return byte(0) + return u8(0) } - return byte(root.valueint) + return u8(root.valueint) } fn decode_u8(root &C.cJSON) u8 { if isnil(root) { - return byte(0) + return u8(0) } - return byte(root.valueint) + return u8(root.valueint) } fn decode_u16(root &C.cJSON) u16 { @@ -129,7 +129,7 @@ fn decode_rune(root &C.cJSON) rune { } // TODO: Parse as runes, bypassing string casting...? - return unsafe { tos_clone(&byte(root.valuestring)).runes().first() } + return unsafe { tos_clone(&u8(root.valuestring)).runes().first() } } fn decode_string(root &C.cJSON) string { @@ -141,7 +141,7 @@ fn decode_string(root &C.cJSON) string { } // println('decode string valuestring="$root.valuestring"') // return tos(root.valuestring, _strlen(root.valuestring)) - return unsafe { tos_clone(&byte(root.valuestring)) } // , _strlen(root.valuestring)) + return unsafe { tos_clone(&u8(root.valuestring)) } // , _strlen(root.valuestring)) } fn decode_bool(root &C.cJSON) bool { @@ -168,7 +168,7 @@ fn encode_i64(val i64) &C.cJSON { return C.cJSON_CreateNumber(val) } -fn encode_byte(val byte) &C.cJSON { +fn encode_u8(val byte) &C.cJSON { return C.cJSON_CreateNumber(val) } @@ -217,12 +217,12 @@ fn json_parse(s string) &C.cJSON { // json_string := json_print(encode_User(user)) fn json_print(json &C.cJSON) string { s := C.cJSON_PrintUnformatted(json) - return unsafe { tos(&byte(s), C.strlen(&char(s))) } + return unsafe { tos(&u8(s), C.strlen(&char(s))) } } fn json_print_pretty(json &C.cJSON) string { s := C.cJSON_Print(json) - return unsafe { tos(&byte(s), C.strlen(&char(s))) } + return unsafe { tos(&u8(s), C.strlen(&char(s))) } } // / cjson wrappers diff --git a/vlib/math/big/big_test.v b/vlib/math/big/big_test.v index 32d681a7b3..7edc4589dc 100644 --- a/vlib/math/big/big_test.v +++ b/vlib/math/big/big_test.v @@ -24,32 +24,32 @@ fn test_integer_from_u64() { fn test_integer_from_bytes() { assert big.integer_from_bytes([]).hex() == '0' - assert big.integer_from_bytes([byte(0)]).hex() == '0' - assert big.integer_from_bytes([byte(0x13), 0x37]).hex() == '1337' - assert big.integer_from_bytes([byte(0x13), 0x37, 0xca]).hex() == '1337ca' - assert big.integer_from_bytes([byte(0x13), 0x37, 0xca, 0xfe]).hex() == '1337cafe' - assert big.integer_from_bytes([byte(0x13), 0x37, 0xca, 0xfe, 0xba]).hex() == '1337cafeba' - assert big.integer_from_bytes([byte(0x13), 0x37, 0xca, 0xfe, 0xba, 0xbe]).hex() == '1337cafebabe' + assert big.integer_from_bytes([u8(0)]).hex() == '0' + assert big.integer_from_bytes([u8(0x13), 0x37]).hex() == '1337' + assert big.integer_from_bytes([u8(0x13), 0x37, 0xca]).hex() == '1337ca' + assert big.integer_from_bytes([u8(0x13), 0x37, 0xca, 0xfe]).hex() == '1337cafe' + assert big.integer_from_bytes([u8(0x13), 0x37, 0xca, 0xfe, 0xba]).hex() == '1337cafeba' + assert big.integer_from_bytes([u8(0x13), 0x37, 0xca, 0xfe, 0xba, 0xbe]).hex() == '1337cafebabe' mut bytes := []byte{cap: 1024} mut expected := '' for i := 0; i < bytes.cap; i++ { - bytes << byte(i) - expected = expected + byte(i).hex() + bytes << u8(i) + expected = expected + u8(i).hex() } assert big.integer_from_bytes(bytes).hex() == expected.trim_left('0') } fn test_bytes() { result1, sign1 := big.integer_from_u64(0x1337cafebabe).bytes() - assert result1 == [byte(0x13), 0x37, 0xca, 0xfe, 0xba, 0xbe] + assert result1 == [u8(0x13), 0x37, 0xca, 0xfe, 0xba, 0xbe] assert sign1 == 1 mut bytes := []byte{cap: 1024} mut expected := '' for i := 0; i < bytes.cap; i++ { - bytes << byte(i | 1) - expected = expected + byte(i).hex() + bytes << u8(i | 1) + expected = expected + u8(i).hex() } result2, sign2 := big.integer_from_bytes(bytes).bytes() assert result2 == bytes @@ -334,8 +334,8 @@ fn test_lshift() { assert big.integer_from_int(45).lshift(4) == big.integer_from_int(45 * 16) assert big.integer_from_int(45).lshift(5) == big.integer_from_int(45 * 32) assert big.integer_from_u64(0xabcedabcde).lshift(20) == big.integer_from_u64(0xabcedabcde00000) - assert big.integer_from_bytes([byte(1), 1, 1]).lshift(56) == big.integer_from_bytes([ - byte(1), + assert big.integer_from_bytes([u8(1), 1, 1]).lshift(56) == big.integer_from_bytes([ + u8(1), 1, 1, 0, @@ -352,7 +352,7 @@ fn test_rshift() { assert big.integer_from_int(45).rshift(3) == big.integer_from_int(5) assert big.integer_from_int(0x13374956).rshift(16) == big.integer_from_int(0x1337) assert big.integer_from_bytes([ - byte(1), + u8(1), 1, 1, 0, @@ -362,7 +362,7 @@ fn test_rshift() { 0, 0, 0, - ]).rshift(56) == big.integer_from_bytes([byte(1), 1, 1]) + ]).rshift(56) == big.integer_from_bytes([u8(1), 1, 1]) } fn test_isqrt() { diff --git a/vlib/math/big/integer.v b/vlib/math/big/integer.v index 49184b9e7f..e26fef1341 100644 --- a/vlib/math/big/integer.v +++ b/vlib/math/big/integer.v @@ -787,7 +787,7 @@ pub fn (a Integer) bytes() ([]byte, int) { mut offset := 24 mut non_zero_found := false for index := a.digits.len - 1; index >= 0; { - value := byte((a.digits[index] & mask) >> offset) + value := u8((a.digits[index] & mask) >> offset) non_zero_found = non_zero_found || value != 0 if non_zero_found { result << value diff --git a/vlib/math/big/special_array_ops.v b/vlib/math/big/special_array_ops.v index 30010c9283..e7f4f180a0 100644 --- a/vlib/math/big/special_array_ops.v +++ b/vlib/math/big/special_array_ops.v @@ -149,7 +149,7 @@ fn pow2(k int) Integer { } } -// optimized left shift of full byte(s) in place. byte_nb must be positive +// optimized left shift of full u8(s) in place. byte_nb must be positive fn lshift_byte_in_place(mut a []u32, byte_nb int) { a_len := a.len // control or allocate capacity diff --git a/vlib/math/bits/bits.v b/vlib/math/bits/bits.v index 11abc89b29..29614a2651 100644 --- a/vlib/math/bits/bits.v +++ b/vlib/math/bits/bits.v @@ -6,10 +6,10 @@ module bits const ( // See http://supertech.csail.mit.edu/papers/debruijn.pdf de_bruijn32 = u32(0x077CB531) - de_bruijn32tab = [byte(0), 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, + de_bruijn32tab = [u8(0), 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9] de_bruijn64 = u64(0x03f79d71b4ca8b09) - de_bruijn64tab = [byte(0), 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4, 62, 47, + de_bruijn64tab = [u8(0), 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4, 62, 47, 59, 36, 45, 43, 51, 22, 53, 39, 33, 30, 24, 18, 12, 5, 63, 55, 48, 27, 60, 41, 37, 16, 46, 35, 44, 21, 52, 32, 23, 11, 54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7, 6] @@ -147,7 +147,7 @@ pub fn ones_count_64(x u64) int { // This function's execution time does not depend on the inputs. [inline] pub fn rotate_left_8(x byte, k int) byte { - n := byte(8) + n := u8(8) s := u8(k) & (n - u8(1)) return (x << s) | (x >> (n - s)) } diff --git a/vlib/math/bits/bits_tables.v b/vlib/math/bits/bits_tables.v index bfa457b07f..d765867318 100644 --- a/vlib/math/bits/bits_tables.v +++ b/vlib/math/bits/bits_tables.v @@ -4,7 +4,7 @@ module bits const ( - ntz_8_tab = [byte(0x08), 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, + ntz_8_tab = [u8(0x08), 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, @@ -22,7 +22,7 @@ const ( 0x01, 0x00, 0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00] - pop_8_tab = [byte(0x00), 0x01, 0x01, 0x02, 0x01, 0x02, 0x02, 0x03, 0x01, 0x02, 0x02, 0x03, + pop_8_tab = [u8(0x00), 0x01, 0x01, 0x02, 0x01, 0x02, 0x02, 0x03, 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04, 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04, 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05, 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04, 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05, 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05, 0x03, @@ -40,7 +40,7 @@ const ( 0x06, 0x07, 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06, 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06, 0x07, 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06, 0x07, 0x05, 0x06, 0x06, 0x07, 0x06, 0x07, 0x07, 0x08] - rev_8_tab = [byte(0x00), 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, + rev_8_tab = [u8(0x00), 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, @@ -58,7 +58,7 @@ const ( 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff] - len_8_tab = [byte(0x00), 0x01, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, + len_8_tab = [u8(0x00), 0x01, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, diff --git a/vlib/math/bits/bits_test.v b/vlib/math/bits/bits_test.v index 7b2cc5d00a..1dfe81a1f1 100644 --- a/vlib/math/bits/bits_test.v +++ b/vlib/math/bits/bits_test.v @@ -15,7 +15,7 @@ fn test_bits() { i = 1 for x in 0 .. 8 { // C.printf("x:%02x lz: %d cmp: %d\n", i << x, leading_zeros_8(i << x), 7-x) - assert leading_zeros_8(byte(i << x)) == 7 - x + assert leading_zeros_8(u8(i << x)) == 7 - x } // 16 bit @@ -46,8 +46,8 @@ fn test_bits() { // 8 bit i = 0 for x in 0 .. 9 { - // C.printf("x:%02x lz: %llu cmp: %d\n", byte(i), ones_count_8(byte(i)), x) - assert ones_count_8(byte(i)) == x + // C.printf("x:%02x lz: %llu cmp: %d\n", u8(i), ones_count_8(u8(i)), x) + assert ones_count_8(u8(i)) == x i = (i << 1) + 1 } @@ -90,16 +90,16 @@ fn test_bits() { // 8 bit i = 0 for _ in 0 .. 9 { - mut rv := byte(0) + mut rv := u8(0) mut bc := 0 mut n := i for bc < 8 { - rv = (rv << 1) | (byte(n) & 0x01) + rv = (rv << 1) | (u8(n) & 0x01) bc++ n = n >> 1 } - // C.printf("x:%02x lz: %llu cmp: %d\n", byte(i), reverse_8(byte(i)), rv) - assert reverse_8(byte(i)) == rv + // C.printf("x:%02x lz: %llu cmp: %d\n", u8(i), reverse_8(u8(i)), rv) + assert reverse_8(u8(i)) == rv i = (i << 1) + 1 } diff --git a/vlib/math/unsigned/uint128.v b/vlib/math/unsigned/uint128.v index 4bae3c4f15..7e36235229 100644 --- a/vlib/math/unsigned/uint128.v +++ b/vlib/math/unsigned/uint128.v @@ -391,7 +391,7 @@ pub fn (u_ Uint128) str() string { mut n := int(0) for ; r != 0; r /= 10 { n++ - buf[i - n] += byte(r % 10) + buf[i - n] += u8(r % 10) } if q.is_zero() { return buf[i - n..].bytestr() diff --git a/vlib/math/unsigned/uint256.v b/vlib/math/unsigned/uint256.v index 69f7e086a6..8b1d6dc0ad 100644 --- a/vlib/math/unsigned/uint256.v +++ b/vlib/math/unsigned/uint256.v @@ -329,7 +329,7 @@ pub fn (u_ Uint256) str() string { mut n := 0 for ; r != 0; r /= 10 { n++ - buf[i - n] += byte(r % 10) + buf[i - n] += u8(r % 10) } if q.is_zero() { return buf[i - n..].bytestr() diff --git a/vlib/mysql/orm.v b/vlib/mysql/orm.v index 5f999c3b49..6fc08b2aee 100644 --- a/vlib/mysql/orm.v +++ b/vlib/mysql/orm.v @@ -30,7 +30,7 @@ pub fn (db Connection) @select(config orm.SelectConfig, data orm.QueryData, wher f := unsafe { fields[i] } match FieldType(f.@type) { .type_tiny { - dataptr << byte(0) + dataptr << u8(0) } .type_short { dataptr << u16(0) @@ -51,7 +51,7 @@ pub fn (db Connection) @select(config orm.SelectConfig, data orm.QueryData, wher dataptr << '' } else { - dataptr << byte(0) + dataptr << u8(0) } } } @@ -163,7 +163,7 @@ fn stmt_binder_match(mut stmt Stmt, data orm.Primitive) { stmt.bind_i64(&data) } byte { - stmt.bind_byte(&data) + stmt.bind_u8(&data) } u16 { stmt.bind_u16(&data) @@ -211,7 +211,7 @@ fn buffer_to_primitive(data_list []&char, types []int) ?[]orm.Primitive { primitive = *(&i64(data)) } 9 { - primitive = *(&byte(data)) + primitive = *(&u8(data)) } 10 { primitive = *(&u16(data)) diff --git a/vlib/mysql/result.v b/vlib/mysql/result.v index e9e1909d84..a3652592e4 100644 --- a/vlib/mysql/result.v +++ b/vlib/mysql/result.v @@ -58,7 +58,7 @@ pub fn (r Result) rows() []Row { if unsafe { rr[i] == 0 } { row.vals << '' } else { - row.vals << mystring(unsafe { &byte(rr[i]) }) + row.vals << mystring(unsafe { &u8(rr[i]) }) } } rows << row diff --git a/vlib/mysql/stmt.c.v b/vlib/mysql/stmt.c.v index ee91746d42..d374408012 100644 --- a/vlib/mysql/stmt.c.v +++ b/vlib/mysql/stmt.c.v @@ -153,7 +153,7 @@ pub fn (mut stmt Stmt) bind_bool(b &bool) { stmt.bind(mysql.mysql_type_tiny, b, 0) } -pub fn (mut stmt Stmt) bind_byte(b &byte) { +pub fn (mut stmt Stmt) bind_u8(b &byte) { stmt.bind(mysql.mysql_type_tiny, b, 0) } diff --git a/vlib/net/address.v b/vlib/net/address.v index 6656b21610..1513fd38d5 100644 --- a/vlib/net/address.v +++ b/vlib/net/address.v @@ -10,8 +10,8 @@ union AddrData { } const ( - addr_ip6_any = [16]byte{init: byte(0)} - addr_ip_any = [4]byte{init: byte(0)} + addr_ip6_any = [16]byte{init: u8(0)} + addr_ip_any = [4]byte{init: u8(0)} ) fn new_ip6(port u16, addr [16]byte) Addr { diff --git a/vlib/net/address_test.v b/vlib/net/address_test.v index cbd0ce5dfa..deb5c06d79 100644 --- a/vlib/net/address_test.v +++ b/vlib/net/address_test.v @@ -90,7 +90,7 @@ fn test_ip_str() { assert ip1.len == expected1.len assert ip1 == expected1 - addr := [byte(2), 0, 2, 2]! + addr := [u8(2), 0, 2, 2]! ip2 := new_ip(2202, addr).str() expected2 := '2.0.2.2:2202' assert ip2.len == expected2.len @@ -103,7 +103,7 @@ fn test_ip6_str() { assert ip1.len == expected1.len assert ip1 == expected1 - addr := [byte(2), 0, 2, 2, 2, 0, 1, 1, 2, 3, 2, 1, 2, 3, 5, 2]! + addr := [u8(2), 0, 2, 2, 2, 0, 1, 1, 2, 3, 2, 1, 2, 3, 5, 2]! ip2 := new_ip6(2022, addr).str() println(ip2) expected2 := '[200:202:200:101:203:201:203:502]:2022' diff --git a/vlib/net/html/parser.v b/vlib/net/html/parser.v index ef48af39bb..066527781b 100644 --- a/vlib/net/html/parser.v +++ b/vlib/net/html/parser.v @@ -118,7 +118,7 @@ pub fn (mut parser Parser) split_parse(data string) { else { 0 } } if parser.lexical_attributes.open_code { // here will verify all needed to know if open_code finishes and string in code - parser.lexical_attributes.lexeme_builder.write_byte(chr) + parser.lexical_attributes.lexeme_builder.write_u8(chr) if parser.lexical_attributes.open_string > 0 && parser.lexical_attributes.open_string == string_code { parser.lexical_attributes.open_string = 0 @@ -141,12 +141,12 @@ pub fn (mut parser Parser) split_parse(data string) { parser.lexical_attributes.open_comment = false parser.lexical_attributes.open_tag = false } else { - parser.lexical_attributes.lexeme_builder.write_byte(chr) + parser.lexical_attributes.lexeme_builder.write_u8(chr) } } else if parser.lexical_attributes.open_string > 0 { if parser.lexical_attributes.open_string == string_code { parser.lexical_attributes.open_string = 0 - parser.lexical_attributes.lexeme_builder.write_byte(chr) + parser.lexical_attributes.lexeme_builder.write_u8(chr) temp_lexeme := parser.builder_str() if parser.lexical_attributes.current_tag.last_attribute != '' { lattr := parser.lexical_attributes.current_tag.last_attribute @@ -159,12 +159,12 @@ pub fn (mut parser Parser) split_parse(data string) { } parser.lexical_attributes.lexeme_builder.go_back_to(0) } else { - parser.lexical_attributes.lexeme_builder.write_byte(chr) + parser.lexical_attributes.lexeme_builder.write_u8(chr) } } else if parser.lexical_attributes.open_tag { if parser.lexical_attributes.lexeme_builder.len == 0 && is_quote { parser.lexical_attributes.open_string = string_code - parser.lexical_attributes.lexeme_builder.write_byte(chr) + parser.lexical_attributes.lexeme_builder.write_u8(chr) } else if chr == `>` { // close tag > complete_lexeme := parser.builder_str().to_lower() parser.lexical_attributes.current_tag.closed = (complete_lexeme.len > 0 @@ -189,8 +189,8 @@ pub fn (mut parser Parser) split_parse(data string) { parser.lexical_attributes.opened_code_type = parser.lexical_attributes.current_tag.name } // parser.print_debug(parser.lexical_attributes.current_tag.name) - } else if chr !in [byte(9), ` `, `=`, `\n`] { // Tab, space, = and \n - parser.lexical_attributes.lexeme_builder.write_byte(chr) + } else if chr !in [u8(9), ` `, `=`, `\n`] { // Tab, space, = and \n + parser.lexical_attributes.lexeme_builder.write_u8(chr) } else if chr != 10 { complete_lexeme := parser.builder_str().to_lower() if parser.lexical_attributes.current_tag.name == '' { @@ -226,7 +226,7 @@ pub fn (mut parser Parser) split_parse(data string) { parser.generate_tag() parser.lexical_attributes.open_tag = true } else { - parser.lexical_attributes.lexeme_builder.write_byte(chr) + parser.lexical_attributes.lexeme_builder.write_u8(chr) } } } diff --git a/vlib/net/http/cookie.v b/vlib/net/http/cookie.v index d647b3daf6..a0569c5579 100644 --- a/vlib/net/http/cookie.v +++ b/vlib/net/http/cookie.v @@ -222,11 +222,11 @@ fn sanitize_cookie_path(v string) string { return sanitize(valid_cookie_path_byte, v) } -fn valid_cookie_value_byte(b byte) bool { +fn valid_cookie_value_u8(b byte) bool { return 0x20 <= b && b < 0x7f && b != `"` && b != `;` && b != `\\` } -fn valid_cookie_path_byte(b byte) bool { +fn valid_cookie_path_u8(b byte) bool { return 0x20 <= b && b < 0x7f && b != `!` } @@ -300,7 +300,7 @@ fn parse_cookie_value(_raw string, allow_double_quote bool) ?string { raw = raw.substr(1, raw.len - 1) } for i in 0 .. raw.len { - if !valid_cookie_value_byte(raw[i]) { + if !valid_cookie_value_u8(raw[i]) { return error('http.cookie: invalid cookie value') } } diff --git a/vlib/net/openssl/ssl_connection.v b/vlib/net/openssl/ssl_connection.v index a92e58d849..f5c821a301 100644 --- a/vlib/net/openssl/ssl_connection.v +++ b/vlib/net/openssl/ssl_connection.v @@ -180,14 +180,14 @@ pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr &byte, len int) ?int { } pub fn (mut s SSLConn) read(mut buffer []byte) ?int { - res := s.socket_read_into_ptr(&byte(buffer.data), buffer.len) ? + res := s.socket_read_into_ptr(&u8(buffer.data), buffer.len) ? return res } // write number of bytes to SSL connection pub fn (mut s SSLConn) write(bytes []byte) ?int { unsafe { - mut ptr_base := &byte(bytes.data) + mut ptr_base := &u8(bytes.data) mut total_sent := 0 for total_sent < bytes.len { ptr := ptr_base + total_sent diff --git a/vlib/net/smtp/smtp.v b/vlib/net/smtp/smtp.v index 9b3d7a8a28..faf1b85468 100644 --- a/vlib/net/smtp/smtp.v +++ b/vlib/net/smtp/smtp.v @@ -200,9 +200,9 @@ fn (mut c Client) send_auth() ? { return } mut sb := strings.new_builder(100) - sb.write_byte(0) + sb.write_u8(0) sb.write_string(c.username) - sb.write_byte(0) + sb.write_u8(0) sb.write_string(c.password) a := sb.str() auth := 'AUTH PLAIN ${base64.encode_str(a)}\r\n' diff --git a/vlib/net/tcp.v b/vlib/net/tcp.v index bbe30b353b..3f36641d05 100644 --- a/vlib/net/tcp.v +++ b/vlib/net/tcp.v @@ -107,7 +107,7 @@ pub fn (mut c TcpConn) write_ptr(b &byte, len int) ?int { unsafe { b.vstring_with_len(len) }) } unsafe { - mut ptr_base := &byte(b) + mut ptr_base := &u8(b) mut total_sent := 0 for total_sent < len { ptr := ptr_base + total_sent diff --git a/vlib/net/unix/stream_nix.v b/vlib/net/unix/stream_nix.v index 4dba85d7cc..5ceddcefcb 100644 --- a/vlib/net/unix/stream_nix.v +++ b/vlib/net/unix/stream_nix.v @@ -62,7 +62,7 @@ fn (mut s StreamSocket) connect(a string) ? { } mut addr := C.sockaddr_un{} unsafe { C.memset(&addr, 0, sizeof(C.sockaddr_un)) } - addr.sun_family = byte(C.AF_UNIX) + addr.sun_family = u8(C.AF_UNIX) unsafe { C.strncpy(&addr.sun_path[0], &char(a.str), max_sun_path) } size := C.SUN_LEN(&addr) res := C.connect(s.handle, voidptr(&addr), size) @@ -94,7 +94,7 @@ pub fn listen_stream(sock string) ?&StreamListener { s.path = sock mut addr := C.sockaddr_un{} unsafe { C.memset(&addr, 0, sizeof(C.sockaddr_un)) } - addr.sun_family = byte(C.AF_UNIX) + addr.sun_family = u8(C.AF_UNIX) unsafe { C.strncpy(&addr.sun_path[0], &char(sock.str), max_sun_path) } size := C.SUN_LEN(&addr) if os.exists(sock) { @@ -177,7 +177,7 @@ pub fn (mut c StreamConn) write_ptr(b &byte, len int) ?int { unsafe { b.vstring_with_len(len) }) } unsafe { - mut ptr_base := &byte(b) + mut ptr_base := &u8(b) mut total_sent := 0 for total_sent < len { ptr := ptr_base + total_sent diff --git a/vlib/net/urllib/urllib.v b/vlib/net/urllib/urllib.v index dc632f254f..7b8adb5cbe 100644 --- a/vlib/net/urllib/urllib.v +++ b/vlib/net/urllib/urllib.v @@ -190,7 +190,7 @@ fn unescape(s_ string, mode EncodingMode) ?string { if i + 3 >= s.len { return error(error_msg('unescape: invalid escape sequence', '')) } - v := ((unhex(s[i + 1]) << byte(4)) | unhex(s[i + 2])) + v := ((unhex(s[i + 1]) << u8(4)) | unhex(s[i + 2])) if s[i..i + 3] != '%25' && v != ` ` && should_escape(v, .encode_host) { error(error_msg(urllib.err_msg_escape, s[i..i + 3])) } @@ -224,7 +224,7 @@ fn unescape(s_ string, mode EncodingMode) ?string { if i + 2 >= s.len { return error(error_msg('unescape: invalid escape sequence', '')) } - t.write_string(((unhex(s[i + 1]) << byte(4)) | unhex(s[i + 2])).ascii_str()) + t.write_string(((unhex(s[i + 1]) << u8(4)) | unhex(s[i + 2])).ascii_str()) i += 2 } `+` { @@ -257,7 +257,7 @@ pub fn path_escape(s string) string { fn escape(s string, mode EncodingMode) string { mut space_count := 0 mut hex_count := 0 - mut c := byte(0) + mut c := u8(0) for i in 0 .. s.len { c = s[i] if should_escape(c, mode) { @@ -418,7 +418,7 @@ fn get_scheme(rawurl string) ?string { // sep. If cutc is true then sep is included with the second substring. // If sep does not occur in s then s and the empty string is returned. fn split(s string, sep byte, cutc bool) (string, string) { - i := s.index_byte(sep) + i := s.index_u8(sep) if i < 0 { return s, '' } @@ -462,7 +462,7 @@ fn parse_request_uri(rawurl string) ?URL { // If via_request is false, all forms of relative URLs are allowed. [manualfree] fn parse_url(rawurl string, via_request bool) ?URL { - if string_contains_ctl_byte(rawurl) { + if string_contains_ctl_u8(rawurl) { return error(error_msg('parse_url: invalid control character in URL', rawurl)) } if rawurl == '' && via_request { @@ -746,11 +746,11 @@ pub fn (u URL) str() string { // it would be mistaken for a scheme name. Such a segment must be // preceded by a dot-segment (e.g., './this:that') to make a relative- // path reference. - i := path.index_byte(`:`) + i := path.index_u8(`:`) if i > -1 { // TODO remove this when autofree handles tmp // expressions like this - if i > -1 && path[..i].index_byte(`/`) == -1 { + if i > -1 && path[..i].index_u8(`/`) == -1 { buf.write_string('./') } } @@ -1006,7 +1006,7 @@ pub fn (u &URL) port() string { fn split_host_port(hostport string) (string, string) { mut host := hostport mut port := '' - colon := host.last_index_byte(`:`) + colon := host.last_index_u8(`:`) if colon != -1 { if valid_optional_port(host[colon..]) { port = host[colon + 1..] @@ -1052,7 +1052,7 @@ pub fn valid_userinfo(s string) bool { } // string_contains_ctl_byte reports whether s contains any ASCII control character. -fn string_contains_ctl_byte(s string) bool { +fn string_contains_ctl_u8(s string) bool { for i in 0 .. s.len { b := s[i] if b < ` ` || b == 0x7f { diff --git a/vlib/net/websocket/utils.v b/vlib/net/websocket/utils.v index 2131fb8e24..a7edaa148d 100644 --- a/vlib/net/websocket/utils.v +++ b/vlib/net/websocket/utils.v @@ -7,20 +7,20 @@ import encoding.base64 // htonl64 converts payload length to header bits fn htonl64(payload_len u64) []byte { mut ret := []byte{len: 8} - ret[0] = byte(((payload_len & (u64(0xff) << 56)) >> 56) & 0xff) - ret[1] = byte(((payload_len & (u64(0xff) << 48)) >> 48) & 0xff) - ret[2] = byte(((payload_len & (u64(0xff) << 40)) >> 40) & 0xff) - ret[3] = byte(((payload_len & (u64(0xff) << 32)) >> 32) & 0xff) - ret[4] = byte(((payload_len & (u64(0xff) << 24)) >> 24) & 0xff) - ret[5] = byte(((payload_len & (u64(0xff) << 16)) >> 16) & 0xff) - ret[6] = byte(((payload_len & (u64(0xff) << 8)) >> 8) & 0xff) - ret[7] = byte(((payload_len & (u64(0xff) << 0)) >> 0) & 0xff) + ret[0] = u8(((payload_len & (u64(0xff) << 56)) >> 56) & 0xff) + ret[1] = u8(((payload_len & (u64(0xff) << 48)) >> 48) & 0xff) + ret[2] = u8(((payload_len & (u64(0xff) << 40)) >> 40) & 0xff) + ret[3] = u8(((payload_len & (u64(0xff) << 32)) >> 32) & 0xff) + ret[4] = u8(((payload_len & (u64(0xff) << 24)) >> 24) & 0xff) + ret[5] = u8(((payload_len & (u64(0xff) << 16)) >> 16) & 0xff) + ret[6] = u8(((payload_len & (u64(0xff) << 8)) >> 8) & 0xff) + ret[7] = u8(((payload_len & (u64(0xff) << 0)) >> 0) & 0xff) return ret } // create_masking_key returs a new masking key to use when masking websocket messages fn create_masking_key() []byte { - mask_bit := rand.byte() + mask_bit := rand.u8() buf := []byte{len: 4, init: `0`} unsafe { C.memcpy(buf.data, &mask_bit, 4) } return buf diff --git a/vlib/net/websocket/websocket_client.v b/vlib/net/websocket/websocket_client.v index 4671175edb..ceee88b01d 100644 --- a/vlib/net/websocket/websocket_client.v +++ b/vlib/net/websocket/websocket_client.v @@ -241,11 +241,11 @@ pub fn (mut ws Client) write_ptr(bytes &byte, payload_len int, code OPCode) ?int header_len += 4 } mut header := []byte{len: header_len, init: `0`} // [`0`].repeat(header_len) - header[0] = byte(int(code)) | 0x80 + header[0] = u8(int(code)) | 0x80 masking_key := create_masking_key() if ws.is_server { if payload_len <= 125 { - header[1] = byte(payload_len) + header[1] = u8(payload_len) } else if payload_len > 125 && payload_len <= 0xffff { len16 := C.htons(payload_len) header[1] = 126 @@ -257,7 +257,7 @@ pub fn (mut ws Client) write_ptr(bytes &byte, payload_len int, code OPCode) ?int } } else { if payload_len <= 125 { - header[1] = byte(payload_len | 0x80) + header[1] = u8(payload_len | 0x80) header[2] = masking_key[0] header[3] = masking_key[1] header[4] = masking_key[2] @@ -286,7 +286,7 @@ pub fn (mut ws Client) write_ptr(bytes &byte, payload_len int, code OPCode) ?int len := header.len + payload_len mut frame_buf := []byte{len: len} unsafe { - C.memcpy(&frame_buf[0], &byte(header.data), header.len) + C.memcpy(&frame_buf[0], &u8(header.data), header.len) if payload_len > 0 { C.memcpy(&frame_buf[header.len], bytes, payload_len) } @@ -307,7 +307,7 @@ pub fn (mut ws Client) write_ptr(bytes &byte, payload_len int, code OPCode) ?int // write writes a byte array with a websocket messagetype to socket pub fn (mut ws Client) write(bytes []byte, code OPCode) ?int { - return ws.write_ptr(&byte(bytes.data), bytes.len, code) + return ws.write_ptr(&u8(bytes.data), bytes.len, code) } // write_str, writes a string with a websocket texttype to socket @@ -333,8 +333,8 @@ pub fn (mut ws Client) close(code int, message string) ? { code_ := C.htons(code) message_len := message.len + 2 mut close_frame := []byte{len: message_len} - close_frame[0] = byte(code_ & 0xFF) - close_frame[1] = byte(code_ >> 8) + close_frame[0] = u8(code_ & 0xFF) + close_frame[1] = u8(code_ >> 8) // code32 = (close_frame[0] << 8) + close_frame[1] for i in 0 .. message.len { close_frame[i + 2] = message[i] @@ -365,15 +365,15 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b } } } - control_frame[0] = byte(int(code) | 0x80) + control_frame[0] = u8(int(code) | 0x80) if !ws.is_server { - control_frame[1] = byte(payload.len | 0x80) + control_frame[1] = u8(payload.len | 0x80) control_frame[2] = masking_key[0] control_frame[3] = masking_key[1] control_frame[4] = masking_key[2] control_frame[5] = masking_key[3] } else { - control_frame[1] = byte(payload.len) + control_frame[1] = u8(payload.len) } if code == .close { if payload.len >= 2 { diff --git a/vlib/os/environment.c.v b/vlib/os/environment.c.v index ed74681145..a27c9d578c 100644 --- a/vlib/os/environment.c.v +++ b/vlib/os/environment.c.v @@ -91,7 +91,7 @@ pub fn environ() map[string]string { mut eline := '' for c := estrings; *c != 0; { eline = unsafe { string_from_wide(c) } - eq_index := eline.index_byte(`=`) + eq_index := eline.index_u8(`=`) if eq_index > 0 { res[eline[0..eq_index]] = eline[eq_index + 1..] } @@ -109,7 +109,7 @@ pub fn environ() map[string]string { break } eline := unsafe { cstring_to_vstring(x) } - eq_index := eline.index_byte(`=`) + eq_index := eline.index_u8(`=`) if eq_index > 0 { res[eline[0..eq_index]] = eline[eq_index + 1..] } diff --git a/vlib/os/file_test.v b/vlib/os/file_test.v index 7937056664..9663778710 100644 --- a/vlib/os/file_test.v +++ b/vlib/os/file_test.v @@ -35,7 +35,7 @@ const ( unit_point = Point{1.0, 1.0, 1.0} another_point = Point{0.25, 2.25, 6.25} extended_point = Extended_Point{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0} - another_byte = byte(123) + another_byte = u8(123) another_color = Color.red another_permission = Permissions.read | .write ) @@ -191,7 +191,7 @@ fn test_write_struct() ? { f.write_struct(another_point) ? f.close() x := os.read_file(tfile) ? - pcopy := unsafe { &byte(memdup(&another_point, size_of_point)) } + pcopy := unsafe { &u8(memdup(&another_point, size_of_point)) } y := unsafe { pcopy.vstring_with_len(size_of_point) } assert x == y $if debug { @@ -228,7 +228,7 @@ fn test_read_struct() ? { fn test_read_struct_at() ? { mut f := os.open_file(tfile, 'w') ? - f.write([byte(1), 2, 3]) ? + f.write([u8(1), 2, 3]) ? f.write_struct(another_point) ? f.close() f = os.open_file(tfile, 'r') ? @@ -246,7 +246,7 @@ fn test_write_raw() ? { f.write_raw(another_point) ? f.close() x := os.read_file(tfile) ? - pcopy := unsafe { &byte(memdup(&another_point, size_of_point)) } + pcopy := unsafe { &u8(memdup(&another_point, size_of_point)) } y := unsafe { pcopy.vstring_with_len(size_of_point) } assert x == y $if debug { @@ -299,7 +299,7 @@ fn test_read_raw() ? { fn test_read_raw_at() ? { mut f := os.open_file(tfile, 'w') ? - f.write([byte(1), 2, 3]) ? + f.write([u8(1), 2, 3]) ? f.write_raw(another_point) ? f.write_raw(another_byte) ? f.write_raw(another_color) ? diff --git a/vlib/os/os.c.v b/vlib/os/os.c.v index ff26209ab2..74b86e9ef7 100644 --- a/vlib/os/os.c.v +++ b/vlib/os/os.c.v @@ -39,7 +39,7 @@ fn C._chsize_s(voidptr, u64) int // read_bytes returns all bytes read from file in `path`. [manualfree] -pub fn read_bytes(path string) ?[]byte { +pub fn read_bytes(path string) ?[]u8 { mut fp := vfopen(path, 'rb') ? defer { C.fclose(fp) @@ -59,7 +59,7 @@ pub fn read_bytes(path string) ?[]byte { return error('$fsize cast to int results in ${int(fsize)})') } C.rewind(fp) - mut res := []byte{len: len} + mut res := []u8{len: len} nr_read_elements := int(C.fread(res.data, len, 1, fp)) if nr_read_elements == 0 && fsize > 0 { return error('fread failed') @@ -356,7 +356,7 @@ pub fn system(cmd string) int { } $else { $if ios { unsafe { - arg := [c'/bin/sh', c'-c', &byte(cmd.str), 0] + arg := [c'/bin/sh', c'-c', &u8(cmd.str), 0] pid := 0 ret = C.posix_spawn(&pid, c'/bin/sh', 0, 0, arg.data, 0) status := 0 @@ -481,7 +481,7 @@ pub fn rmdir(path string) ? { // print_c_errno will print the current value of `C.errno`. fn print_c_errno() { e := C.errno - se := unsafe { tos_clone(&byte(C.strerror(e))) } + se := unsafe { tos_clone(&u8(C.strerror(e))) } println('errno=$e err=$se') } @@ -522,12 +522,12 @@ pub fn get_raw_line() string { max := usize(0) buf := &char(0) nr_chars := unsafe { C.getline(&buf, &max, C.stdin) } - return unsafe { tos(&byte(buf), if nr_chars < 0 { 0 } else { nr_chars }) } + return unsafe { tos(&u8(buf), if nr_chars < 0 { 0 } else { nr_chars }) } } } // get_raw_stdin will get the raw input from stdin. -pub fn get_raw_stdin() []byte { +pub fn get_raw_stdin() []u8 { $if windows { unsafe { block_bytes := 512 diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index ee5dfc6fb4..ff62ae1a9c 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -148,7 +148,7 @@ fn test_write_and_read_string_to_file() { // read_bytes, read_bytes_at and write_bytes. fn test_write_and_read_bytes() { file_name := './byte_reader_writer.tst' - payload := [byte(`I`), `D`, `D`, `Q`, `D`] + payload := [u8(`I`), `D`, `D`, `Q`, `D`] mut file_write := os.create(os.real_path(file_name)) or { eprintln('failed to create file $file_name') return @@ -683,7 +683,7 @@ fn test_write_file_array_bytes() { fpath := './abytes.bin' mut arr := []byte{len: maxn} for i in 0 .. maxn { - arr[i] = 65 + byte(i) + arr[i] = 65 + u8(i) } os.write_file_array(fpath, arr) or { panic(err) } rarr := os.read_bytes(fpath) or { panic(err) } diff --git a/vlib/pg/orm.v b/vlib/pg/orm.v index b08992f115..681e0025c7 100644 --- a/vlib/pg/orm.v +++ b/vlib/pg/orm.v @@ -234,7 +234,7 @@ fn str_to_primitive(str string, typ int) ?orm.Primitive { // byte 9 { data := str.i8() - return orm.Primitive(*unsafe { &byte(&data) }) + return orm.Primitive(*unsafe { &u8(&data) }) } // u16 10 { diff --git a/vlib/pg/pg.v b/vlib/pg/pg.v index 0956932e6a..f0f016443e 100644 --- a/vlib/pg/pg.v +++ b/vlib/pg/pg.v @@ -254,11 +254,11 @@ pub fn (db DB) copy_expert(query string, mut file io.ReaderWriter) ?int { } } else if status == C.PGRES_COPY_OUT { for { - address := &byte(0) + address := &u8(0) n_bytes := C.PQgetCopyData(db.conn, &address, 0) if n_bytes > 0 { mut local_buf := []byte{len: n_bytes} - unsafe { C.memcpy(&byte(local_buf.data), address, n_bytes) } + unsafe { C.memcpy(&u8(local_buf.data), address, n_bytes) } file.write(local_buf) or { C.PQfreemem(address) return err diff --git a/vlib/picoev/picoev.v b/vlib/picoev/picoev.v index feb587552a..ad4a27b8cf 100644 --- a/vlib/picoev/picoev.v +++ b/vlib/picoev/picoev.v @@ -211,7 +211,7 @@ pub fn new(config Config) &Picoev { // Setting addr mut addr := C.sockaddr_in{ - sin_family: byte(C.AF_INET) + sin_family: u8(C.AF_INET) sin_port: C.htons(config.port) sin_addr: C.htonl(C.INADDR_ANY) } @@ -234,7 +234,7 @@ pub fn new(config Config) &Picoev { user_data: config.user_data timeout_secs: config.timeout_secs max_headers: config.max_headers - date: &byte(C.get_date()) + date: &u8(C.get_date()) buf: unsafe { malloc_noscan(picoev.max_fds * picoev.max_read + 1) } out: unsafe { malloc_noscan(picoev.max_fds * picoev.max_write + 1) } } @@ -252,7 +252,7 @@ pub fn (p Picoev) serve() { fn update_date(mut p Picoev) { for { - p.date = &byte(C.get_date()) + p.date = &u8(C.get_date()) C.usleep(1000000) } } diff --git a/vlib/rand/mt19937/mt19937.v b/vlib/rand/mt19937/mt19937.v index 3bdfcb1468..5577328dc1 100644 --- a/vlib/rand/mt19937/mt19937.v +++ b/vlib/rand/mt19937/mt19937.v @@ -99,16 +99,16 @@ pub fn (mut rng MT19937RNG) seed(seed_data []u32) { // byte returns a uniformly distributed pseudorandom 8-bit unsigned positive `byte`. [inline] -pub fn (mut rng MT19937RNG) byte() byte { +pub fn (mut rng MT19937RNG) u8() byte { if rng.bytes_left >= 1 { rng.bytes_left -= 1 - value := byte(rng.buffer) + value := u8(rng.buffer) rng.buffer >>= 8 return value } rng.buffer = rng.u64() rng.bytes_left = 7 - value := byte(rng.buffer) + value := u8(rng.buffer) rng.buffer >>= 8 return value } diff --git a/vlib/rand/musl/musl_rng.v b/vlib/rand/musl/musl_rng.v index c03f45a919..96d437ddff 100644 --- a/vlib/rand/musl/musl_rng.v +++ b/vlib/rand/musl/musl_rng.v @@ -29,16 +29,16 @@ pub fn (mut rng MuslRNG) seed(seed_data []u32) { // byte returns a uniformly distributed pseudorandom 8-bit unsigned positive `byte`. [inline] -pub fn (mut rng MuslRNG) byte() byte { +pub fn (mut rng MuslRNG) u8() byte { if rng.bytes_left >= 1 { rng.bytes_left -= 1 - value := byte(rng.buffer) + value := u8(rng.buffer) rng.buffer >>= 8 return value } rng.buffer = rng.u32() rng.bytes_left = 3 - value := byte(rng.buffer) + value := u8(rng.buffer) rng.buffer >>= 8 return value } diff --git a/vlib/rand/pcg32/pcg32.v b/vlib/rand/pcg32/pcg32.v index fa1ff41984..e0b54d99a1 100644 --- a/vlib/rand/pcg32/pcg32.v +++ b/vlib/rand/pcg32/pcg32.v @@ -39,16 +39,16 @@ pub fn (mut rng PCG32RNG) seed(seed_data []u32) { // byte returns a uniformly distributed pseudorandom 8-bit unsigned positive `byte`. [inline] -pub fn (mut rng PCG32RNG) byte() byte { +pub fn (mut rng PCG32RNG) u8() byte { if rng.bytes_left >= 1 { rng.bytes_left -= 1 - value := byte(rng.buffer) + value := u8(rng.buffer) rng.buffer >>= 8 return value } rng.buffer = rng.u32() rng.bytes_left = 3 - value := byte(rng.buffer) + value := u8(rng.buffer) rng.buffer >>= 8 return value } diff --git a/vlib/rand/rand.c.v b/vlib/rand/rand.c.v index b7b7dd83cc..572ad90f89 100644 --- a/vlib/rand/rand.c.v +++ b/vlib/rand/rand.c.v @@ -13,7 +13,7 @@ fn internal_uuid_v4(mut rng PRNG) string { mut buf := unsafe { malloc_noscan(37) } mut i_buf := 0 mut x := u64(0) - mut d := byte(0) + mut d := u8(0) for i_buf < buflen { mut c := 0 x = rng.u64() @@ -131,7 +131,7 @@ fn read_32(mut rng PRNG, mut buf []byte) { } } for i in u32s * 4 .. buf.len { - buf[i] = rng.byte() + buf[i] = rng.u8() } } @@ -144,7 +144,7 @@ fn read_64(mut rng PRNG, mut buf []byte) { } } for i in u64s * 8 .. buf.len { - buf[i] = rng.byte() + buf[i] = rng.u8() } } @@ -158,7 +158,7 @@ fn read_internal(mut rng PRNG, mut buf []byte) { } else { for i in 0 .. buf.len { - buf[i] = rng.byte() + buf[i] = rng.u8() } } } diff --git a/vlib/rand/rand.js.v b/vlib/rand/rand.js.v index bd9ece82fc..c54d3d02dc 100644 --- a/vlib/rand/rand.js.v +++ b/vlib/rand/rand.js.v @@ -55,6 +55,6 @@ fn internal_ulid_at_millisecond(mut rng PRNG, unix_time_milli u64) string { fn read_internal(mut rng PRNG, mut buf []byte) { for i in 0 .. buf.len { - buf[i] = rng.byte() + buf[i] = rng.u8() } } diff --git a/vlib/rand/rand.v b/vlib/rand/rand.v index 183fdbeb47..6fd36d17b1 100644 --- a/vlib/rand/rand.v +++ b/vlib/rand/rand.v @@ -16,7 +16,7 @@ import time pub interface PRNG { mut: seed(seed_data []u32) - byte() byte + u8() byte u16() u16 u32() u32 u64() u64 @@ -121,7 +121,7 @@ pub fn (mut rng PRNG) u64_in_range(min u64, max u64) ?u64 { // i8 returns a (possibly negative) pseudorandom 8-bit `i8`. [inline] pub fn (mut rng PRNG) i8() i8 { - return i8(rng.byte()) + return i8(rng.u8()) } // i16 returns a (possibly negative) pseudorandom 16-bit `i16`. @@ -424,8 +424,8 @@ pub fn intn(max int) ?int { } // byte returns a uniformly distributed pseudorandom 8-bit unsigned positive `byte`. -pub fn byte() byte { - return default_rng.byte() +pub fn u8() byte { + return default_rng.u8() } // int_in_range returns a uniformly distributed pseudorandom 32-bit signed int in range `[min, max)`. diff --git a/vlib/rand/random_numbers_test.v b/vlib/rand/random_numbers_test.v index b7f5ba7c1e..3f0ce1d791 100644 --- a/vlib/rand/random_numbers_test.v +++ b/vlib/rand/random_numbers_test.v @@ -179,10 +179,10 @@ fn test_rand_f64_in_range() { } } -fn test_rand_byte() { +fn test_rand_u8() { mut all := []byte{} for _ in 0 .. 256 { - x := rand.byte() + x := rand.u8() assert x >= 0 assert x <= 255 all << x diff --git a/vlib/rand/splitmix64/splitmix64.v b/vlib/rand/splitmix64/splitmix64.v index e38716e4c6..44efeac19b 100644 --- a/vlib/rand/splitmix64/splitmix64.v +++ b/vlib/rand/splitmix64/splitmix64.v @@ -29,16 +29,16 @@ pub fn (mut rng SplitMix64RNG) seed(seed_data []u32) { // byte returns a uniformly distributed pseudorandom 8-bit unsigned positive `byte`. [inline] -pub fn (mut rng SplitMix64RNG) byte() byte { +pub fn (mut rng SplitMix64RNG) u8() byte { if rng.bytes_left >= 1 { rng.bytes_left -= 1 - value := byte(rng.buffer) + value := u8(rng.buffer) rng.buffer >>= 8 return value } rng.buffer = rng.u64() rng.bytes_left = 7 - value := byte(rng.buffer) + value := u8(rng.buffer) rng.buffer >>= 8 return value } diff --git a/vlib/rand/sys/system_rng.c.v b/vlib/rand/sys/system_rng.c.v index b431d58fbb..4c84bf8e4a 100644 --- a/vlib/rand/sys/system_rng.c.v +++ b/vlib/rand/sys/system_rng.c.v @@ -64,16 +64,16 @@ pub fn (r SysRNG) default_rand() int { // byte returns a uniformly distributed pseudorandom 8-bit unsigned positive `byte`. [inline] -pub fn (mut r SysRNG) byte() byte { +pub fn (mut r SysRNG) u8() byte { if r.bytes_left >= 1 { r.bytes_left -= 1 - value := byte(r.buffer) + value := u8(r.buffer) r.buffer >>= 8 return value } r.buffer = r.default_rand() r.bytes_left = sys.rand_bytesize - 1 - value := byte(r.buffer) + value := u8(r.buffer) r.buffer >>= 8 return value } diff --git a/vlib/rand/wyrand/wyrand.v b/vlib/rand/wyrand/wyrand.v index 05500ebe37..23989df8d9 100644 --- a/vlib/rand/wyrand/wyrand.v +++ b/vlib/rand/wyrand/wyrand.v @@ -35,7 +35,7 @@ pub fn (mut rng WyRandRNG) seed(seed_data []u32) { // byte returns a uniformly distributed pseudorandom 8-bit unsigned positive `byte`. [inline] -pub fn (mut rng WyRandRNG) byte() byte { +pub fn (mut rng WyRandRNG) u8() byte { // Can we extract a value from the buffer? if rng.bytes_left >= 1 { rng.bytes_left -= 1 diff --git a/vlib/readline/readline_linux.c.v b/vlib/readline/readline_linux.c.v index 2bd562391a..d5d4d4f71f 100644 --- a/vlib/readline/readline_linux.c.v +++ b/vlib/readline/readline_linux.c.v @@ -82,8 +82,8 @@ pub fn (mut r Readline) enable_raw_mode() { raw.c_iflag &= ~(C.BRKINT | C.ICRNL | C.INPCK | C.ISTRIP | C.IXON) raw.c_cflag |= C.CS8 raw.c_lflag &= ~(C.ECHO | C.ICANON | C.IEXTEN | C.ISIG) - raw.c_cc[C.VMIN] = byte(1) - raw.c_cc[C.VTIME] = byte(0) + raw.c_cc[C.VMIN] = u8(1) + raw.c_cc[C.VTIME] = u8(0) unsafe { C.tcsetattr(0, C.TCSADRAIN, &raw) } // println('> after raw: $raw') r.is_raw = true @@ -105,8 +105,8 @@ pub fn (mut r Readline) enable_raw_mode_nosig() { raw.c_iflag &= ~(C.BRKINT | C.ICRNL | C.INPCK | C.ISTRIP | C.IXON) raw.c_cflag |= C.CS8 raw.c_lflag &= ~(C.ECHO | C.ICANON | C.IEXTEN) - raw.c_cc[C.VMIN] = byte(1) - raw.c_cc[C.VTIME] = byte(0) + raw.c_cc[C.VMIN] = u8(1) + raw.c_cc[C.VTIME] = u8(0) unsafe { C.tcsetattr(0, C.TCSADRAIN, &raw) } r.is_raw = true r.is_tty = true @@ -203,7 +203,7 @@ fn (r Readline) analyse(c int) Action { if c > 255 { return Action.insert_character } - match byte(c) { + match u8(c) { `\0`, 0x3, 0x4, 255 { return .eof } // NUL, End of Text, End of Transmission @@ -240,16 +240,16 @@ fn (r Readline) analyse(c int) Action { // analyse_control returns an `Action` based on the type of input read by `read_char`. fn (r Readline) analyse_control() Action { c := r.read_char() - match byte(c) { + match u8(c) { `[` { sequence := r.read_char() - match byte(sequence) { + match u8(sequence) { `C` { return .move_cursor_right } `D` { return .move_cursor_left } `B` { return .history_next } `A` { return .history_previous } `1` { return r.analyse_extended_control() } - `2`, `3` { return r.analyse_extended_control_no_eat(byte(sequence)) } + `2`, `3` { return r.analyse_extended_control_no_eat(u8(sequence)) } else {} } } @@ -284,10 +284,10 @@ match c { fn (r Readline) analyse_extended_control() Action { r.read_char() // Removes ; c := r.read_char() - match byte(c) { + match u8(c) { `5` { direction := r.read_char() - match byte(direction) { + match u8(direction) { `C` { return .move_cursor_word_right } `D` { return .move_cursor_word_left } else {} @@ -302,7 +302,7 @@ fn (r Readline) analyse_extended_control() Action { // analyse_extended_control_no_eat specialises in detection of delete and insert keys. fn (r Readline) analyse_extended_control_no_eat(last_c byte) Action { c := r.read_char() - match byte(c) { + match u8(c) { `~` { match last_c { `3` { return .delete_right } // Suppr key diff --git a/vlib/regex/regex.v b/vlib/regex/regex.v index dd31b9b67a..4bc73fd3a9 100644 --- a/vlib/regex/regex.v +++ b/vlib/regex/regex.v @@ -212,7 +212,7 @@ fn utf8_str(ch rune) string { mut i := 4 mut res := '' for i > 0 { - v := byte((ch >> ((i - 1) * 8)) & 0xFF) + v := u8((ch >> ((i - 1) * 8)) & 0xFF) if v != 0 { res += '${v:1c}' } @@ -410,7 +410,7 @@ fn (re RE) parse_bsls(in_txt string, in_i int) (int, int) { for i < in_txt.len { // get our char char_tmp, char_len := re.get_char(in_txt, i) - ch := byte(char_tmp) + ch := u8(char_tmp) if status == .start && ch == `\\` { status = .bsls_found @@ -475,7 +475,7 @@ enum CharClass_parse_state { fn (re RE) get_char_class(pc int) string { buf := []byte{len: (re.cc.len)} - mut buf_ptr := unsafe { &byte(&buf) } + mut buf_ptr := unsafe { &u8(&buf) } mut cc_i := re.prog[pc].cc_index mut i := 0 @@ -485,13 +485,13 @@ fn (re RE) get_char_class(pc int) string { unsafe { buf_ptr[i] = `\\` i++ - buf_ptr[i] = byte(re.cc[cc_i].ch0) + buf_ptr[i] = u8(re.cc[cc_i].ch0) i++ } } else if re.cc[cc_i].ch0 == re.cc[cc_i].ch1 { tmp = 3 for tmp >= 0 { - x := byte((re.cc[cc_i].ch0 >> (tmp * 8)) & 0xFF) + x := u8((re.cc[cc_i].ch0 >> (tmp * 8)) & 0xFF) if x != 0 { unsafe { buf_ptr[i] = x @@ -503,7 +503,7 @@ fn (re RE) get_char_class(pc int) string { } else { tmp = 3 for tmp >= 0 { - x := byte((re.cc[cc_i].ch0 >> (tmp * 8)) & 0xFF) + x := u8((re.cc[cc_i].ch0 >> (tmp * 8)) & 0xFF) if x != 0 { unsafe { buf_ptr[i] = x @@ -518,7 +518,7 @@ fn (re RE) get_char_class(pc int) string { } tmp = 3 for tmp >= 0 { - x := byte((re.cc[cc_i].ch1 >> (tmp * 8)) & 0xFF) + x := u8((re.cc[cc_i].ch1 >> (tmp * 8)) & 0xFF) if x != 0 { unsafe { buf_ptr[i] = x @@ -531,7 +531,7 @@ fn (re RE) get_char_class(pc int) string { cc_i++ } unsafe { - buf_ptr[i] = byte(0) + buf_ptr[i] = u8(0) } return unsafe { tos_clone(buf_ptr) } } @@ -540,7 +540,7 @@ fn (re RE) check_char_class(pc int, ch rune) bool { mut cc_i := re.prog[pc].cc_index for cc_i >= 0 && cc_i < re.cc.len && re.cc[cc_i].cc_type != regex.cc_end { if re.cc[cc_i].cc_type == regex.cc_bsls { - if re.cc[cc_i].validator(byte(ch)) { + if re.cc[cc_i].validator(u8(ch)) { return true } } else if ch >= re.cc[cc_i].ch0 && ch <= re.cc[cc_i].ch1 { @@ -569,7 +569,7 @@ fn (mut re RE) parse_char_class(in_txt string, in_i int) (int, int, rune) { // get our char char_tmp, char_len := re.get_char(in_txt, i) - ch := byte(char_tmp) + ch := u8(char_tmp) // println("CC #${i:3d} ch: ${ch:c}") @@ -698,7 +698,7 @@ fn (re RE) parse_quantifier(in_txt string, in_i int) (int, int, int, bool) { mut q_min := 0 // default min in a {} quantifier is 1 mut q_max := 0 // deafult max in a {} quantifier is max_quantifier - mut ch := byte(0) + mut ch := u8(0) for i < in_txt.len { unsafe { @@ -829,7 +829,7 @@ fn (re RE) parse_groups(in_txt string, in_i int) (int, bool, bool, string, int) for i < in_txt.len && status != .finish { // get our char char_tmp, char_len := re.get_char(in_txt, i) - ch := byte(char_tmp) + ch := u8(char_tmp) // start if status == .start && ch == `(` { @@ -940,19 +940,19 @@ fn (mut re RE) impl_compile(in_txt string) (int, int) { // // check special cases: $ ^ // - if char_len == 1 && i == 0 && byte(char_tmp) == `^` { + if char_len == 1 && i == 0 && u8(char_tmp) == `^` { re.flag = regex.f_ms i = i + char_len continue } - if char_len == 1 && i == (in_txt.len - 1) && byte(char_tmp) == `$` { + if char_len == 1 && i == (in_txt.len - 1) && u8(char_tmp) == `$` { re.flag = regex.f_me i = i + char_len continue } // ist_group_start - if char_len == 1 && pc >= 0 && byte(char_tmp) == `(` { + if char_len == 1 && pc >= 0 && u8(char_tmp) == `(` { // check max groups allowed if group_count > re.group_max { return regex.err_groups_overflow, i + 1 @@ -1019,7 +1019,7 @@ fn (mut re RE) impl_compile(in_txt string) (int, int) { } // ist_group_end - if char_len == 1 && pc > 0 && byte(char_tmp) == `)` { + if char_len == 1 && pc > 0 && u8(char_tmp) == `)` { if group_stack_index < 0 { return regex.err_group_not_balanced, i + 1 } @@ -1049,7 +1049,7 @@ fn (mut re RE) impl_compile(in_txt string) (int, int) { } // ist_dot_char match any char except the following token - if char_len == 1 && pc >= 0 && byte(char_tmp) == `.` { + if char_len == 1 && pc >= 0 && u8(char_tmp) == `.` { // consecutive ist_dot_char is a syntax error if pc > 0 && re.prog[pc - 1].ist == regex.ist_dot_char { return regex.err_consecutive_dots, i @@ -1064,7 +1064,7 @@ fn (mut re RE) impl_compile(in_txt string) (int, int) { } // OR branch - if char_len == 1 && pc > 0 && byte(char_tmp) == `|` { + if char_len == 1 && pc > 0 && u8(char_tmp) == `|` { if pc > 0 && re.prog[pc - 1].ist == regex.ist_or_branch { return regex.err_syntax_error, i } @@ -1089,7 +1089,7 @@ fn (mut re RE) impl_compile(in_txt string) (int, int) { return regex.err_neg_group_quantifier, i } - match byte(char_tmp) { + match u8(char_tmp) { `?` { // println("q: ${char_tmp:c}") // check illegal quantifier sequences @@ -1159,7 +1159,7 @@ fn (mut re RE) impl_compile(in_txt string) (int, int) { // IST_CHAR_CLASS_* if char_len == 1 && pc >= 0 { - if byte(char_tmp) == `[` { + if u8(char_tmp) == `[` { cc_index, tmp, cc_type := re.parse_char_class(in_txt, i + 1) if cc_index >= 0 { // println("index: $cc_index str:${in_txt[i..i+tmp]}") @@ -1180,7 +1180,7 @@ fn (mut re RE) impl_compile(in_txt string) (int, int) { // ist_bsls_char if char_len == 1 && pc >= 0 { - if byte(char_tmp) == `\\` { + if u8(char_tmp) == `\\` { bsls_index, tmp := re.parse_bsls(in_txt, i) // println("index: $bsls_index str:${in_txt[i..i+tmp]}") if bsls_index >= 0 { @@ -1209,7 +1209,7 @@ fn (mut re RE) impl_compile(in_txt string) (int, int) { // ist_simple_char re.prog[pc].ist = regex.ist_simple_char re.prog[pc].ch = char_tmp - re.prog[pc].ch_len = byte(char_len) + re.prog[pc].ch_len = u8(char_len) re.prog[pc].rep_min = 1 re.prog[pc].rep_max = 1 // println("char: ${char_tmp:c}") @@ -1547,7 +1547,7 @@ pub fn (re RE) get_query() string { // char alone if ch == regex.ist_simple_char { - if byte(ch) in regex.bsls_escape_list { + if u8(ch) in regex.bsls_escape_list { res.write_string('\\') } res.write_string('${tk.ch:c}') @@ -1912,7 +1912,7 @@ pub fn (mut re RE) match_base(in_txt &byte, in_txt_len int) (int, int) { ch, char_len = re.get_charb(in_txt, state.i) // check new line if flag f_nl enabled - if (re.flag & regex.f_nl) != 0 && char_len == 1 && byte(ch) in regex.new_line_list { + if (re.flag & regex.f_nl) != 0 && char_len == 1 && u8(ch) in regex.new_line_list { m_state = .new_line continue } @@ -2094,7 +2094,7 @@ pub fn (mut re RE) match_base(in_txt &byte, in_txt_len int) (int, int) { } // check bsls else if re.prog[chk_pc].ist == regex.ist_bsls_char { - next_check_flag = re.prog[chk_pc].validator(byte(ch_t)) + next_check_flag = re.prog[chk_pc].validator(u8(ch_t)) // println("Check [ist_bsls_char] => $next_check_flag") } } @@ -2214,7 +2214,7 @@ pub fn (mut re RE) match_base(in_txt &byte, in_txt_len int) (int, int) { } // check bsls else if re.prog[chk_pc].ist == regex.ist_bsls_char { - next_check_flag = re.prog[chk_pc].validator(byte(ch_t)) + next_check_flag = re.prog[chk_pc].validator(u8(ch_t)) // println("Check [ist_bsls_char] => $next_check_flag") } } @@ -2244,7 +2244,7 @@ pub fn (mut re RE) match_base(in_txt &byte, in_txt_len int) (int, int) { continue } - tmp_res := re.prog[state.pc].validator(byte(ch)) + tmp_res := re.prog[state.pc].validator(u8(ch)) if tmp_res == false { m_state = .ist_quant_n continue diff --git a/vlib/regex/regex_test.v b/vlib/regex/regex_test.v index a31e354e41..6b9e514c26 100644 --- a/vlib/regex/regex_test.v +++ b/vlib/regex/regex_test.v @@ -767,9 +767,9 @@ fn test_long_query() { base_string := rand.string(test_len) for c in base_string { - buf.write_byte(`(`) - buf.write_byte(c) - buf.write_byte(`)`) + buf.write_u8(`(`) + buf.write_u8(c) + buf.write_u8(`)`) } mut query := buf.str() @@ -786,11 +786,11 @@ fn test_long_query() { // test 2 buf.clear() for c in base_string { - buf.write_byte(`(`) - buf.write_byte(c) + buf.write_u8(`(`) + buf.write_u8(c) } for _ in 0..base_string.len { - buf.write_byte(`)`) + buf.write_u8(`)`) } query = buf.str() re = regex.regex_opt(query) or { panic(err) } diff --git a/vlib/sokol/sapp/screenshot.c.v b/vlib/sokol/sapp/screenshot.c.v index fd3dcbf336..8aaba15f01 100644 --- a/vlib/sokol/sapp/screenshot.c.v +++ b/vlib/sokol/sapp/screenshot.c.v @@ -14,7 +14,7 @@ pub fn screenshot_window() &Screenshot { img_width := width() img_height := height() img_size := img_width * img_height * 4 - img_pixels := unsafe { &byte(malloc(img_size)) } + img_pixels := unsafe { &u8(malloc(img_size)) } C.v_sapp_gl_read_rgba_pixels(0, 0, img_width, img_height, img_pixels) return &Screenshot{ width: img_width @@ -29,7 +29,7 @@ pub fn screenshot_window() &Screenshot { pub fn (mut ss Screenshot) free() { unsafe { free(ss.pixels) - ss.pixels = &byte(0) + ss.pixels = &u8(0) } } diff --git a/vlib/sqlite/sqlite.v b/vlib/sqlite/sqlite.v index 0f8d590c68..5a188cafc2 100644 --- a/vlib/sqlite/sqlite.v +++ b/vlib/sqlite/sqlite.v @@ -159,8 +159,8 @@ pub fn (db DB) q_string(query string) string { C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0) C.sqlite3_step(stmt) - val := unsafe { &byte(C.sqlite3_column_text(stmt, 0)) } - return if val != &byte(0) { unsafe { tos_clone(val) } } else { '' } + val := unsafe { &u8(C.sqlite3_column_text(stmt, 0)) } + return if val != &u8(0) { unsafe { tos_clone(val) } } else { '' } } // Execute the query on db, return an array of all the results, alongside any result code. @@ -180,8 +180,8 @@ pub fn (db DB) exec(query string) ([]Row, int) { } mut row := Row{} for i in 0 .. nr_cols { - val := unsafe { &byte(C.sqlite3_column_text(stmt, i)) } - if val == &byte(0) { + val := unsafe { &u8(C.sqlite3_column_text(stmt, i)) } + if val == &u8(0) { row.vals << '' } else { row.vals << unsafe { tos_clone(val) } diff --git a/vlib/strconv/atoi.v b/vlib/strconv/atoi.v index 04bd2fce82..fcc0191c81 100644 --- a/vlib/strconv/atoi.v +++ b/vlib/strconv/atoi.v @@ -87,7 +87,7 @@ pub fn common_parse_uint2(s string, _base int, _bit_size int) (u64, int) { c := s[i] cl := byte_to_lower(c) - mut d := byte(0) + mut d := u8(0) if c == `_` && base0 { // underscore_ok already called continue diff --git a/vlib/strconv/f64_str.js.v b/vlib/strconv/f64_str.js.v index 4bc62ef88d..538d9ba95c 100644 --- a/vlib/strconv/f64_str.js.v +++ b/vlib/strconv/f64_str.js.v @@ -228,7 +228,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 { // Step 4: Find the shortest decimal representation // in the interval of valid representations. mut removed := 0 - mut last_removed_digit := byte(0) + mut last_removed_digit := u8(0) mut out := u64(0) // On average, we remove ~2 digits. if vm_is_trailing_zeros || vr_is_trailing_zeros { @@ -244,7 +244,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 { vr_mod_10 := vr % 10 vm_is_trailing_zeros = vm_is_trailing_zeros && vm_mod_10 == 0 vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0) - last_removed_digit = byte(vr_mod_10) + last_removed_digit = u8(vr_mod_10) vr = vr_div_10 vp = vp_div_10 vm = vm_div_10 @@ -261,7 +261,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 { vr_div_10 := vr / 10 vr_mod_10 := vr % 10 vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0) - last_removed_digit = byte(vr_mod_10) + last_removed_digit = u8(vr_mod_10) vr = vr_div_10 vp = vp_div_10 vm = vm_div_10 diff --git a/vlib/strconv/format.v b/vlib/strconv/format.v index 0f8459d9b0..47b10db405 100644 --- a/vlib/strconv/format.v +++ b/vlib/strconv/format.v @@ -80,7 +80,7 @@ Single format functions */ pub struct BF_param { pub mut: - pad_ch byte = byte(` `) // padding char + pad_ch byte = u8(` `) // padding char len0 int = -1 // default len for whole the number or string len1 int = 6 // number of decimal digits, if needed positive bool = true // mandatory: the sign of the number passed @@ -104,13 +104,13 @@ pub fn format_str(s string, p BF_param) string { } if p.allign == .right { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } res.write_string(s) if p.allign == .left { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } return res.str() diff --git a/vlib/strconv/format_mem.c.v b/vlib/strconv/format_mem.c.v index d0d1b166e2..e08b7f4ad5 100644 --- a/vlib/strconv/format_mem.c.v +++ b/vlib/strconv/format_mem.c.v @@ -23,13 +23,13 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) { if p.allign == .right { for i1 := 0; i1 < dif; i1++ { - sb.write_byte(p.pad_ch) + sb.write_u8(p.pad_ch) } } sb.write_string(s) if p.allign == .left { for i1 := 0; i1 < dif; i1++ { - sb.write_byte(p.pad_ch) + sb.write_u8(p.pad_ch) } } } @@ -53,17 +53,17 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { if p.pad_ch == `0` { if p.positive { if p.sign_flag { - res.write_byte(`+`) + res.write_u8(`+`) sign_written = true } } else { - res.write_byte(`-`) + res.write_u8(`-`) sign_written = true } } // write the pad chars for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } @@ -71,10 +71,10 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { // no pad char, write the sign before the number if p.positive { if p.sign_flag { - res.write_byte(`+`) + res.write_u8(`+`) } } else { - res.write_byte(`-`) + res.write_u8(`-`) } } @@ -85,7 +85,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { mut i := 20 mut d1 := d for i >= (21 - n_char) { - buf[i] = byte(d1 % 10) + `0` + buf[i] = u8(d1 % 10) + `0` d1 = d1 / 10 i-- } @@ -123,13 +123,13 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { unsafe { res.write_ptr(&buf[i], n_char) } } else { // we have a zero no need of more code! - res.write_byte(`0`) + res.write_u8(`0`) } //=========================================== if p.allign == .left { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } return diff --git a/vlib/strconv/format_mem.js.v b/vlib/strconv/format_mem.js.v index c73c2575af..36a673286f 100644 --- a/vlib/strconv/format_mem.js.v +++ b/vlib/strconv/format_mem.js.v @@ -17,7 +17,7 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) { if p.allign == .right { for i1 := 0; i1 < dif; i1++ { - sb.write_byte(p.pad_ch) + sb.write_u8(p.pad_ch) } } @@ -25,7 +25,7 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) { if p.allign == .left { for i1 := 0; i1 < dif; i1++ { - sb.write_byte(p.pad_ch) + sb.write_u8(p.pad_ch) } } } @@ -49,17 +49,17 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { if p.pad_ch == `0` { if p.positive { if p.sign_flag { - res.write_byte(`+`) + res.write_u8(`+`) sign_written = true } } else { - res.write_byte(`-`) + res.write_u8(`-`) sign_written = true } } // write the pad chars for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } @@ -67,10 +67,10 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { // no pad char, write the sign before the number if p.positive { if p.sign_flag { - res.write_byte(`+`) + res.write_u8(`+`) } } else { - res.write_byte(`-`) + res.write_u8(`-`) } } @@ -80,7 +80,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { mut i := 20 mut d1 := d for i >= (21 - n_char) { - buf[i] = byte(d1 % 10) + `0` + buf[i] = u8(d1 % 10) + `0` d1 = d1 / 10 i-- @@ -88,7 +88,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { for _ in 0 .. n_char { i++ - res.write_byte(buf[i]) + res.write_u8(buf[i]) } i++ @@ -96,7 +96,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) { if p.allign == .left { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } return diff --git a/vlib/strconv/format_test.v b/vlib/strconv/format_test.v index 92e76ec6d1..150a6d8973 100644 --- a/vlib/strconv/format_test.v +++ b/vlib/strconv/format_test.v @@ -5,7 +5,7 @@ fn test_format() { mut tmp_str := '' a0 := u32(10) b0 := 200 - c0 := byte(12) + c0 := u8(12) s0 := 'ciAo' ch0 := `B` f0 := 0.312345 @@ -20,7 +20,7 @@ fn test_format() { // println("\n$temp_s") assert tmp_str == temp_s - a := byte(12) + a := u8(12) b := i16(13) c := 14 d := i64(15) @@ -31,7 +31,7 @@ fn test_format() { // println("\n$temp_s") assert tmp_str == temp_s - a1 := byte(0xff) + a1 := u8(0xff) b1 := i16(0xffff) c1 := u32(0xffff_ffff) d1 := u64(-1) diff --git a/vlib/strconv/vprintf.c.v b/vlib/strconv/vprintf.c.v index 6325f3d437..073dc8ee8d 100644 --- a/vlib/strconv/vprintf.c.v +++ b/vlib/strconv/vprintf.c.v @@ -40,7 +40,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string { mut len0 := -1 // forced length, if -1 free length mut len1 := -1 // decimal part for floats def_len1 := 6 // default value for len1 - mut pad_ch := byte(` `) // pad char + mut pad_ch := u8(` `) // pad char // prefix chars for Length field mut ch1 := `0` // +1 char if present else `0` @@ -62,7 +62,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string { ch := str[i] if ch != `%` && status == .norm_char { - res.write_byte(ch) + res.write_u8(ch) i++ continue } @@ -75,8 +75,8 @@ pub fn v_sprintf(str string, pt ...voidptr) string { // single char, manage it here if ch == `c` && status == .field_char { v_sprintf_panic(p_index, pt.len) - d1 := unsafe { *(&byte(pt[p_index])) } - res.write_byte(d1) + d1 := unsafe { *(&u8(pt[p_index])) } + res.write_u8(d1) status = .reset_params p_index++ i++ @@ -297,7 +297,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string { // hh fot 8 bit unsigned int `h` { if ch2 == `h` { - d1 = u64(unsafe { *(&byte(pt[p_index])) }) + d1 = u64(unsafe { *(&u8(pt[p_index])) }) } else { d1 = u64(unsafe { *(&u16(pt[p_index])) }) } @@ -579,11 +579,11 @@ pub fn format_fl_old(f f64, p BF_param) string { if p.pad_ch == `0` { if p.positive { if p.sign_flag { - res.write_byte(`+`) + res.write_u8(`+`) sign_len_diff = -1 } } else { - res.write_byte(`-`) + res.write_u8(`-`) sign_len_diff = -1 } tmp := s @@ -611,13 +611,13 @@ pub fn format_fl_old(f f64, p BF_param) string { if p.allign == .right { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } res.write_string(s) if p.allign == .left { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } @@ -648,11 +648,11 @@ pub fn format_es_old(f f64, p BF_param) string { if p.pad_ch == `0` { if p.positive { if p.sign_flag { - res.write_byte(`+`) + res.write_u8(`+`) sign_len_diff = -1 } } else { - res.write_byte(`-`) + res.write_u8(`-`) sign_len_diff = -1 } tmp := s @@ -679,13 +679,13 @@ pub fn format_es_old(f f64, p BF_param) string { dif := p.len0 - s.len + sign_len_diff if p.allign == .right { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } res.write_string(s) if p.allign == .left { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } return res.str() @@ -697,7 +697,7 @@ pub fn remove_tail_zeros_old(s string) string { mut last_zero_start := -1 mut dot_pos := -1 mut in_decimal := false - mut prev_ch := byte(0) + mut prev_ch := u8(0) for i < s.len { ch := unsafe { s.str[i] } if ch == `.` { @@ -745,11 +745,11 @@ pub fn format_dec_old(d u64, p BF_param) string { if p.pad_ch == `0` { if p.positive { if p.sign_flag { - res.write_byte(`+`) + res.write_u8(`+`) sign_len_diff = -1 } } else { - res.write_byte(`-`) + res.write_u8(`-`) sign_len_diff = -1 } tmp := s @@ -776,13 +776,13 @@ pub fn format_dec_old(d u64, p BF_param) string { if p.allign == .right { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } res.write_string(s) if p.allign == .left { for i1 := 0; i1 < dif; i1++ { - res.write_byte(p.pad_ch) + res.write_u8(p.pad_ch) } } return res.str() diff --git a/vlib/strings/builder.c.v b/vlib/strings/builder.c.v index b4745e7705..1224728c2e 100644 --- a/vlib/strings/builder.c.v +++ b/vlib/strings/builder.c.v @@ -49,14 +49,14 @@ pub fn (mut b Builder) write_runes(runes []rune) { } // write_b appends a single `data` byte to the accumulated buffer -[deprecated: 'Use write_byte() instead'] +[deprecated: 'Use write_u8() instead'] [deprecated_after: '2022-02-11'] pub fn (mut b Builder) write_b(data byte) { b << data } // write_byte appends a single `data` byte to the accumulated buffer -pub fn (mut b Builder) write_byte(data byte) { +pub fn (mut b Builder) write_u8(data byte) { b << data } @@ -82,7 +82,7 @@ pub fn (mut b Builder) drain_builder(mut other Builder, other_new_cap int) { // Note: it can panic, if there are not enough bytes in the strings builder yet. [inline] pub fn (b &Builder) byte_at(n int) byte { - return unsafe { (&[]byte(b))[n] } + return unsafe { (&[]u8(b))[n] } } // write appends the string `s` to the buffer @@ -95,7 +95,7 @@ pub fn (mut b Builder) write_string(s string) { // for c in s { // b.buf << c // } - // b.buf << []byte(s) // TODO + // b.buf << []u8(s) // TODO } // go_back discards the last `n` bytes from the buffer @@ -146,8 +146,8 @@ pub fn (mut b Builder) writeln(s string) { if s.len > 0 { unsafe { b.push_many(s.str, s.len) } } - // b.buf << []byte(s) // TODO - b << byte(`\n`) + // b.buf << []u8(s) // TODO + b << u8(`\n`) } // last_n(5) returns 'world' @@ -176,8 +176,8 @@ pub fn (b &Builder) after(n int) string { // accumulated data that was in the string builder, before the // .str() call. pub fn (mut b Builder) str() string { - b << byte(0) - bcopy := unsafe { &byte(memdup_noscan(b.data, b.len)) } + b << u8(0) + bcopy := unsafe { &u8(memdup_noscan(b.data, b.len)) } s := unsafe { bcopy.vstring_with_len(b.len - 1) } b.trim(0) return s diff --git a/vlib/strings/builder.js.v b/vlib/strings/builder.js.v index 22909bb782..e1d48a4f97 100644 --- a/vlib/strings/builder.js.v +++ b/vlib/strings/builder.js.v @@ -18,12 +18,12 @@ pub fn new_builder(initial_size int) Builder { return []u8{cap: initial_size} } -[deprecated: 'Use write_byte() instead'] +[deprecated: 'Use write_u8() instead'] pub fn (mut b Builder) write_b(data u8) { b << data } -pub fn (mut b Builder) write_byte(data u8) { +pub fn (mut b Builder) write_u8(data u8) { b << data } diff --git a/vlib/strings/builder_test.js.v b/vlib/strings/builder_test.js.v index ef75e9a11c..70701a7f86 100644 --- a/vlib/strings/builder_test.js.v +++ b/vlib/strings/builder_test.js.v @@ -65,7 +65,7 @@ fn test_byte_write() { temp_str := 'byte testing' mut count := 0 for word in temp_str { - sb.write_byte(word) + sb.write_u8(word) count++ assert count == sb.len } diff --git a/vlib/strings/builder_test.v b/vlib/strings/builder_test.v index 151e1b989a..69d86b188f 100644 --- a/vlib/strings/builder_test.v +++ b/vlib/strings/builder_test.v @@ -65,7 +65,7 @@ fn test_byte_write() { temp_str := 'byte testing' mut count := 0 for word in temp_str { - sb.write_byte(word) + sb.write_u8(word) count++ assert count == sb.len } diff --git a/vlib/strings/strings.v b/vlib/strings/strings.v index 172c3c3dc2..2e43095f44 100644 --- a/vlib/strings/strings.v +++ b/vlib/strings/strings.v @@ -22,9 +22,9 @@ pub fn random(n int) string { // amount of `end` marks in the `input`. An empty string is returned otherwise. // Using two identical marks as `start` and `end` results in undefined output behavior. // find_between_pair_byte is the fastest in the find_between_pair_* family of functions. -// Example: assert strings.find_between_pair_byte('(V) (NOT V)',`(`,`)`) == 'V' -// Example: assert strings.find_between_pair_byte('s {X{Y}} s',`{`,`}`) == 'X{Y}' -pub fn find_between_pair_byte(input string, start byte, end byte) string { +// Example: assert strings.find_between_pair_u8('(V) (NOT V)',`(`,`)`) == 'V' +// Example: assert strings.find_between_pair_u8('s {X{Y}} s',`{`,`}`) == 'X{Y}' +pub fn find_between_pair_u8(input string, start byte, end byte) string { mut marks := 0 mut start_index := -1 for i, b in input { diff --git a/vlib/strings/strings_test.v b/vlib/strings/strings_test.v index eac5bf05b8..0475b6aad4 100644 --- a/vlib/strings/strings_test.v +++ b/vlib/strings/strings_test.v @@ -71,9 +71,9 @@ const expected_string_outputs = [ fn test_find_between_pair_family() { assert strings.find_between_pair_rune('xx♡ok❦yy', `♡`, `❦`) == 'ok' - assert strings.find_between_pair_byte('xx{ok}yy', `{`, `}`) == 'ok' + assert strings.find_between_pair_u8('xx{ok}yy', `{`, `}`) == 'ok' assert strings.find_between_pair_string('xx/*ok*/yy', '/*', '*/') == 'ok' - assert strings.find_between_pair_byte('xx{ok}yy', `{`, `}`) == 'ok' + assert strings.find_between_pair_u8('xx{ok}yy', `{`, `}`) == 'ok' assert strings.find_between_pair_string('xxxxokyyyy', 'xxx', 'yyy') == 'xok' for i, tstr in test_rune_and_byte { @@ -83,7 +83,7 @@ fn test_find_between_pair_family() { } for i, tstr in test_rune_and_byte { - e1 := strings.find_between_pair_byte(tstr, `[`, `]`) + e1 := strings.find_between_pair_u8(tstr, `[`, `]`) e2 := expected_rune_and_byte_outputs[i] assert '$e1' == '$e2' } diff --git a/vlib/sync/channel_select_2_test.v b/vlib/sync/channel_select_2_test.v index 189aaf6be2..f1e571adbd 100644 --- a/vlib/sync/channel_select_2_test.v +++ b/vlib/sync/channel_select_2_test.v @@ -14,9 +14,9 @@ fn do_send_int(ch chan int) { } } -fn do_send_byte(ch chan byte) { +fn do_send_u8(ch chan byte) { for i in 0 .. 300 { - ch <- byte(i) + ch <- u8(i) } } @@ -33,7 +33,7 @@ fn test_select() { recch := chan i64{cap: 0} go do_rec_i64(recch) go do_send_int(chi) - go do_send_byte(chb) + go do_send_u8(chb) go do_send_i64(chl) mut sum := i64(0) mut rl := i64(0) diff --git a/vlib/sync/channel_select_test.v b/vlib/sync/channel_select_test.v index 26ed641f52..9ef64d4036 100644 --- a/vlib/sync/channel_select_test.v +++ b/vlib/sync/channel_select_test.v @@ -26,9 +26,9 @@ fn do_send_int(mut ch Channel) { } } -fn do_send_byte(mut ch Channel) { +fn do_send_u8(mut ch Channel) { for i in 0 .. 300 { - ii := byte(i) + ii := u8(i) ch.push(&ii) } } @@ -47,14 +47,14 @@ fn test_select() { mut recch := new_channel(0) go do_rec_i64(mut recch) go do_send_int(mut chi) - go do_send_byte(mut chb) + go do_send_u8(mut chb) go do_send_i64(mut chl) mut channels := [chi, recch, chl, chb] directions := [Direction.pop, .push, .pop, .pop] mut sum := i64(0) mut rl := i64(0) mut ri := int(0) - mut rb := byte(0) + mut rb := u8(0) mut sl := i64(0) mut objs := [voidptr(&ri), &sl, &rl, &rb] for _ in 0 .. 1200 { diff --git a/vlib/sync/select_close_test.v b/vlib/sync/select_close_test.v index 3a40e2d4ef..b733b8d7b8 100644 --- a/vlib/sync/select_close_test.v +++ b/vlib/sync/select_close_test.v @@ -23,9 +23,9 @@ fn do_send_int(mut ch Channel) { ch.close() } -fn do_send_byte(mut ch Channel) { +fn do_send_u8(mut ch Channel) { for i in 0 .. 300 { - ii := byte(i) + ii := u8(i) ch.push(&ii) } ch.close() @@ -46,14 +46,14 @@ fn test_select() { mut recch := new_channel(0) go do_rec_i64(mut recch) go do_send_int(mut chi) - go do_send_byte(mut chb) + go do_send_u8(mut chb) go do_send_i64(mut chl) mut channels := [chi, recch, chl, chb] directions := [Direction.pop, .push, .pop, .pop] mut sum := i64(0) mut rl := i64(0) mut ri := int(0) - mut rb := byte(0) + mut rb := u8(0) mut sl := i64(0) mut objs := [voidptr(&ri), &sl, &rl, &rb] for j in 0 .. 1101 { diff --git a/vlib/sync/sync_darwin.c.v b/vlib/sync/sync_darwin.c.v index b46ec05903..afb754006b 100644 --- a/vlib/sync/sync_darwin.c.v +++ b/vlib/sync/sync_darwin.c.v @@ -228,5 +228,5 @@ pub fn (mut sem Semaphore) destroy() { return } } - panic(unsafe { tos_clone(&byte(C.strerror(res))) }) + panic(unsafe { tos_clone(&u8(C.strerror(res))) }) } diff --git a/vlib/sync/sync_default.c.v b/vlib/sync/sync_default.c.v index 5a1680b209..f42d0dd9b1 100644 --- a/vlib/sync/sync_default.c.v +++ b/vlib/sync/sync_default.c.v @@ -147,7 +147,7 @@ pub fn (mut sem Semaphore) wait() { continue // interrupted by signal } else { - panic(unsafe { tos_clone(&byte(C.strerror(C.errno))) }) + panic(unsafe { tos_clone(&u8(C.strerror(C.errno))) }) } } } @@ -166,7 +166,7 @@ pub fn (mut sem Semaphore) try_wait() bool { return false } else { - panic(unsafe { tos_clone(&byte(C.strerror(C.errno))) }) + panic(unsafe { tos_clone(&u8(C.strerror(C.errno))) }) } } } @@ -195,7 +195,7 @@ pub fn (mut sem Semaphore) timed_wait(timeout time.Duration) bool { break } else { - panic(unsafe { tos_clone(&byte(C.strerror(e))) }) + panic(unsafe { tos_clone(&u8(C.strerror(e))) }) } } } @@ -207,5 +207,5 @@ pub fn (sem Semaphore) destroy() { if res == 0 { return } - panic(unsafe { tos_clone(&byte(C.strerror(res))) }) + panic(unsafe { tos_clone(&u8(C.strerror(res))) }) } diff --git a/vlib/szip/szip.v b/vlib/szip/szip.v index 0e96c0242c..39b556b5cf 100644 --- a/vlib/szip/szip.v +++ b/vlib/szip/szip.v @@ -66,7 +66,7 @@ pub enum OpenMode { } [inline] -fn (om OpenMode) to_byte() byte { +fn (om OpenMode) to_u8() byte { return match om { .write { `w` @@ -88,7 +88,7 @@ pub fn open(name string, level CompressionLevel, mode OpenMode) ?&Zip { if name.len == 0 { return error('szip: name of file empty') } - p_zip := unsafe { &Zip(C.zip_open(&char(name.str), int(level), char(mode.to_byte()))) } + p_zip := unsafe { &Zip(C.zip_open(&char(name.str), int(level), char(mode.to_u8()))) } if isnil(p_zip) { return error('szip: cannot open/create/append new zip archive') } @@ -134,7 +134,7 @@ pub fn (mut zentry Zip) close_entry() { // All slashes MUST be forward slashes '/' as opposed to backwards slashes '\' // for compatibility with Amiga and UNIX file systems etc. pub fn (mut zentry Zip) name() string { - name := unsafe { &byte(C.zip_entry_name(zentry)) } + name := unsafe { &u8(C.zip_entry_name(zentry)) } if name == 0 { return '' } @@ -195,7 +195,7 @@ pub fn (mut zentry Zip) create_entry(name string) ? { // NOTE: remember to release the memory allocated for an output buffer. // for large entries, please take a look at zip_entry_extract function. pub fn (mut zentry Zip) read_entry() ?voidptr { - mut buf := &byte(0) + mut buf := &u8(0) mut bsize := usize(0) res := C.zip_entry_read(zentry, unsafe { &voidptr(&buf) }, &bsize) if res == -1 { diff --git a/vlib/term/term_nix.c.v b/vlib/term/term_nix.c.v index c0c37c8b5a..9008e5248a 100644 --- a/vlib/term/term_nix.c.v +++ b/vlib/term/term_nix.c.v @@ -55,7 +55,7 @@ pub fn get_cursor_position() ?Coord { mut x := 0 mut y := 0 - mut stage := byte(0) + mut stage := u8(0) // ESC [ YYY `;` XXX `R` diff --git a/vlib/term/ui/input_nix.c.v b/vlib/term/ui/input_nix.c.v index c83d02eadd..5628c202c8 100644 --- a/vlib/term/ui/input_nix.c.v +++ b/vlib/term/ui/input_nix.c.v @@ -55,7 +55,7 @@ pub fn (mut ctx Context) run() ? { [inline] fn (mut ctx Context) shift(len int) { unsafe { - C.memmove(ctx.read_buf.data, &byte(ctx.read_buf.data) + len, ctx.read_buf.cap - len) + C.memmove(ctx.read_buf.data, &u8(ctx.read_buf.data) + len, ctx.read_buf.cap - len) ctx.resize_arr(ctx.read_buf.len - len) } } diff --git a/vlib/term/ui/termios_nix.c.v b/vlib/term/ui/termios_nix.c.v index 60355fd1ea..37c08169aa 100644 --- a/vlib/term/ui/termios_nix.c.v +++ b/vlib/term/ui/termios_nix.c.v @@ -226,7 +226,7 @@ fn (mut ctx Context) termios_loop() { sw.restart() if ctx.cfg.event_fn != voidptr(0) { unsafe { - len := C.read(C.STDIN_FILENO, &byte(ctx.read_buf.data) + ctx.read_buf.len, + len := C.read(C.STDIN_FILENO, &u8(ctx.read_buf.data) + ctx.read_buf.len, ctx.read_buf.cap - ctx.read_buf.len) ctx.resize_arr(ctx.read_buf.len + len) } diff --git a/vlib/time/parse.c.v b/vlib/time/parse.c.v index 2554a22617..593e83b1fc 100644 --- a/vlib/time/parse.c.v +++ b/vlib/time/parse.c.v @@ -172,7 +172,7 @@ pub fn parse_rfc2822(s string) ?Time { // ----- iso8601 ----- fn parse_iso8601_date(s string) ?(int, int, int) { - year, month, day, dummy := 0, 0, 0, byte(0) + year, month, day, dummy := 0, 0, 0, u8(0) count := unsafe { C.sscanf(&char(s.str), c'%4d-%2d-%2d%c', &year, &month, &day, &dummy) } if count != 3 { return error_invalid_time(10) diff --git a/vlib/toml/checker/checker.v b/vlib/toml/checker/checker.v index f23e0a8f03..25636e55d4 100644 --- a/vlib/toml/checker/checker.v +++ b/vlib/toml/checker/checker.v @@ -104,20 +104,20 @@ fn (c Checker) check_number(num ast.Number) ? { is_float := lit_lower_case.all_before('e').contains('.') has_exponent_notation := lit_lower_case.contains('e') float_decimal_index := lit.index('.') or { -1 } - // mut is_first_digit := byte(lit[0]).is_digit() - mut ascii := byte(lit[0]).ascii_str() + // mut is_first_digit := u8(lit[0]).is_digit() + mut ascii := u8(lit[0]).ascii_str() is_sign_prefixed := lit[0] in [`+`, `-`] mut lit_sans_sign := lit if is_sign_prefixed { // +/- ... lit_sans_sign = lit[1..] hex_bin_oct = is_hex_bin_oct_prefixed(lit_sans_sign) if hex_bin_oct { - ascii = byte(lit[0]).ascii_str() + ascii = u8(lit[0]).ascii_str() return error(@MOD + '.' + @STRUCT + '.' + @FN + ' numbers like "$lit" (hex, octal and binary) can not start with `$ascii` in ...${c.excerpt(num.pos)}...') } if lit.len > 1 && lit_sans_sign.starts_with('0') && !lit_sans_sign.starts_with('0.') { - ascii = byte(lit_sans_sign[0]).ascii_str() + ascii = u8(lit_sans_sign[0]).ascii_str() return error(@MOD + '.' + @STRUCT + '.' + @FN + ' numbers like "$lit" can not start with `$ascii` in ...${c.excerpt(num.pos)}...') } @@ -198,7 +198,7 @@ fn (c Checker) check_number(num ast.Number) ? { } last := lit[lit.len - 1] if last in scanner.digit_extras { - ascii = byte(last).ascii_str() + ascii = u8(last).ascii_str() return error(@MOD + '.' + @STRUCT + '.' + @FN + ' numbers like "$lit" (float) can not end with `$ascii` in ...${c.excerpt(num.pos)}...') } @@ -215,12 +215,12 @@ fn (c Checker) check_number(num ast.Number) ? { if r !in [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `.`, `e`, `E`, `-`, `+`, `_`] { return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' numbers like "$lit" (float) can not contain `${byte(r).ascii_str()}` in ...${c.excerpt(num.pos)}...') + ' numbers like "$lit" (float) can not contain `${u8(r).ascii_str()}` in ...${c.excerpt(num.pos)}...') } } } else { if lit.len > 1 && lit.starts_with('0') && lit[1] !in [`b`, `o`, `x`] { - ascii = byte(lit[0]).ascii_str() + ascii = u8(lit[0]).ascii_str() return error(@MOD + '.' + @STRUCT + '.' + @FN + ' numbers like "$lit" can not start with `$ascii` in ...${c.excerpt(num.pos)}...') } @@ -425,9 +425,9 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ? { if ch == scanner.end_of_text { break } - ch_byte := byte(ch) + ch_byte := u8(ch) if ch == `\\` { - next_ch := byte(s.at()) + next_ch := u8(s.at()) if next_ch == `\\` { s.next() @@ -452,7 +452,7 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ? { if !(ch_ == ` ` || ch_ == `\t`) { st := s.state() return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' invalid character `${byte(ch_).ascii_str()}` after `$escape` at ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...') + ' invalid character `${u8(ch_).ascii_str()}` after `$escape` at ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...') } } } @@ -558,7 +558,7 @@ pub fn (c Checker) check_comment(comment ast.Comment) ? { if ch == scanner.end_of_text { break } - ch_byte := byte(ch) + ch_byte := u8(ch) // Check for carrige return if ch_byte == 0x0D { st := s.state() @@ -569,7 +569,7 @@ pub fn (c Checker) check_comment(comment ast.Comment) ? { if util.is_illegal_ascii_control_character(ch_byte) { st := s.state() return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' control character `$ch_byte.hex()` is not allowed ($st.line_nr,$st.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(st.pos, 10)}...') + ' control character `$ch_byte.hex()` is not allowed ($st.line_nr,$st.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(st.pos, 10)}...') } } diff --git a/vlib/toml/decoder/decoder.v b/vlib/toml/decoder/decoder.v index 2a5e47b166..fef1fa0a93 100644 --- a/vlib/toml/decoder/decoder.v +++ b/vlib/toml/decoder/decoder.v @@ -92,7 +92,7 @@ pub fn decode_quoted_escapes(mut q ast.Quoted) ? { if ch == scanner.end_of_text { break } - ch_byte := byte(ch) + ch_byte := u8(ch) if eat_whitespace && ch_byte.is_space() { continue @@ -101,7 +101,7 @@ pub fn decode_quoted_escapes(mut q ast.Quoted) ? { if ch == `\\` { ch_next := s.at() - ch_next_byte := byte(ch_next) + ch_next_byte := u8(ch_next) if ch_next == `\\` { decoded_s += ch_next_byte.ascii_str() @@ -155,13 +155,13 @@ pub fn decode_quoted_escapes(mut q ast.Quoted) ? { escape := ch_byte.ascii_str() + ch_next_byte.ascii_str() // Decode unicode escapes if escape.to_lower() == '\\u' { - is_valid_short := byte(s.peek(1)).is_hex_digit() && byte(s.peek(2)).is_hex_digit() - && byte(s.peek(3)).is_hex_digit() && byte(s.peek(4)).is_hex_digit() + is_valid_short := u8(s.peek(1)).is_hex_digit() && u8(s.peek(2)).is_hex_digit() + && u8(s.peek(3)).is_hex_digit() && u8(s.peek(4)).is_hex_digit() if is_valid_short { - is_valid_long := byte(s.peek(5)).is_hex_digit() - && byte(s.peek(6)).is_hex_digit() && byte(s.peek(7)).is_hex_digit() - && byte(s.peek(8)).is_hex_digit() + is_valid_long := u8(s.peek(5)).is_hex_digit() + && u8(s.peek(6)).is_hex_digit() && u8(s.peek(7)).is_hex_digit() + && u8(s.peek(8)).is_hex_digit() // If it's a long type Unicode (\UXXXXXXXX) with a maximum of 10 chars: '\' + 'U' + 8 hex characters // we pass in 10 characters from the `u`/`U` which is the longest possible sequence // of 9 chars plus one extra. diff --git a/vlib/toml/scanner/scanner.v b/vlib/toml/scanner/scanner.v index 1c61fa8bfe..e117825265 100644 --- a/vlib/toml/scanner/scanner.v +++ b/vlib/toml/scanner/scanner.v @@ -100,7 +100,7 @@ pub fn (mut s Scanner) scan() ?token.Token { for { c := s.next() - byte_c := byte(c) + byte_c := u8(c) if c == scanner.end_of_text { s.inc_line_number() util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'reached EOF') @@ -110,7 +110,7 @@ pub fn (mut s Scanner) scan() ?token.Token { ascii := byte_c.ascii_str() util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'current char "$ascii"') - if byte_c == byte(0x0) { + if byte_c == u8(0x0) { s.reset() return error(@MOD + '.' + @STRUCT + '.' + @FN + ' NULL control character `$c.hex()` is not allowed at ($s.line_nr,$s.col) "$ascii" near ...${s.excerpt(s.pos, 5)}...') @@ -132,7 +132,7 @@ pub fn (mut s Scanner) scan() ?token.Token { return s.new_token(.number, num, num.len) } - is_signed_number := is_sign && byte(s.at()).is_digit() && !byte(s.peek(-1)).is_digit() + is_signed_number := is_sign && u8(s.at()).is_digit() && !u8(s.peek(-1)).is_digit() is_digit := byte_c.is_digit() if is_digit || is_signed_number { num := s.extract_number() ? @@ -158,8 +158,8 @@ pub fn (mut s Scanner) scan() ?token.Token { } // Date-Time in RFC 3339 is allowed to have a space between the date and time in supplement to the 'T' // so we allow space characters to slip through to the parser if the space is between two digits... - // util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, '"'+byte(s.peek(-1)).ascii_str()+'" < "$ascii" > "'+byte(s.at()).ascii_str()+'"') - if c == ` ` && byte(s.peek(-1)).is_digit() && byte(s.at()).is_digit() { + // util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, '"'+u8(s.peek(-1)).ascii_str()+'" < "$ascii" > "'+u8(s.at()).ascii_str()+'"') + if c == ` ` && u8(s.peek(-1)).is_digit() && u8(s.at()).is_digit() { util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'identified, what could be, a space between a RFC 3339 date and time ("$ascii") ($ascii.len)') return s.new_token(token.Kind.whitespace, ascii, ascii.len) } @@ -358,7 +358,7 @@ fn (mut s Scanner) ignore_line() ?string { util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, ' ignoring until EOL...') start := s.pos for c := s.at(); c != scanner.end_of_text && c != `\n`; c = s.at() { - util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'skipping "${byte(c).ascii_str()} / $c"') + util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'skipping "${u8(c).ascii_str()} / $c"') if s.at_crlf() { util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'letting `\\r\\n` slip through') break @@ -383,7 +383,7 @@ fn (mut s Scanner) extract_key() string { s.col-- start := s.pos for s.pos < s.text.len { - c := byte(s.at()) + c := u8(s.at()) if !(util.is_key_char(c) || c.is_digit() || c in [`_`, `-`]) { break } @@ -403,7 +403,7 @@ fn (mut s Scanner) extract_string() ?string { // a byte that is the start of a string so we rewind it to start at the correct s.pos-- s.col-- - quote := byte(s.at()) + quote := u8(s.at()) start := s.pos mut lit := quote.ascii_str() @@ -420,14 +420,14 @@ fn (mut s Scanner) extract_string() ?string { if s.pos >= s.text.len { return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' unfinished single-line string literal `$quote.ascii_str()` started at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') + ' unfinished single-line string literal `$quote.ascii_str()` started at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') } - c := byte(s.at()) + c := u8(s.at()) util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'c: `$c.ascii_str()` / $c (quote type: $quote/$quote.ascii_str())') // Check for escaped chars - if c == byte(92) { + if c == u8(92) { esc, skip := s.handle_escapes(quote, is_multiline) lit += esc if skip > 0 { @@ -439,7 +439,7 @@ fn (mut s Scanner) extract_string() ?string { // Check for control characters (allow TAB) if util.is_illegal_ascii_control_character(c) { return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' control character `$c.hex()` is not allowed at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') + ' control character `$c.hex()` is not allowed at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') } if c == quote { @@ -453,7 +453,7 @@ fn (mut s Scanner) extract_string() ?string { // Don't eat multiple lines in single-line mode if lit.contains('\n') { return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' unfinished single-line string literal `$quote.ascii_str()` started at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') + ' unfinished single-line string literal `$quote.ascii_str()` started at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') } } return lit @@ -466,7 +466,7 @@ fn (mut s Scanner) extract_string() ?string { fn (mut s Scanner) extract_multiline_string() ?string { // extract_multiline_string is called from extract_string so we know the 3 first // characters is the quotes - quote := byte(s.at()) + quote := u8(s.at()) start := s.pos mut lit := quote.ascii_str() + quote.ascii_str() + quote.ascii_str() @@ -482,10 +482,10 @@ fn (mut s Scanner) extract_multiline_string() ?string { if s.pos >= s.text.len { return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' unfinished multi-line string literal ($quote.ascii_str()$quote.ascii_str()$quote.ascii_str()) started at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') + ' unfinished multi-line string literal ($quote.ascii_str()$quote.ascii_str()$quote.ascii_str()) started at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') } - c := byte(s.at()) + c := u8(s.at()) util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'c: `$c.ascii_str()` / $c (quote type: $quote/$quote.ascii_str())') if c == `\n` { @@ -495,7 +495,7 @@ fn (mut s Scanner) extract_multiline_string() ?string { continue } // Check for escaped chars - if c == byte(92) { + if c == u8(92) { esc, skip := s.handle_escapes(quote, true) lit += esc if skip > 0 { @@ -507,7 +507,7 @@ fn (mut s Scanner) extract_multiline_string() ?string { // Check for control characters (allow TAB) if util.is_illegal_ascii_control_character(c) { return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' control character `$c.hex()` is not allowed at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') + ' control character `$c.hex()` is not allowed at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...') } if c == quote { @@ -537,12 +537,12 @@ fn (mut s Scanner) extract_multiline_string() ?string { // handle_escapes returns any escape character sequence. // For escape sequence validation see `Checker.check_quoted_escapes`. fn (mut s Scanner) handle_escapes(quote byte, is_multiline bool) (string, int) { - c := byte(s.at()) + c := u8(s.at()) mut lit := c.ascii_str() is_literal_string := quote == `'` if !is_literal_string { - if s.peek(1) == `u` && byte(s.peek(2)).is_hex_digit() && byte(s.peek(3)).is_hex_digit() - && byte(s.peek(4)).is_hex_digit() && byte(s.peek(5)).is_hex_digit() { + if s.peek(1) == `u` && u8(s.peek(2)).is_hex_digit() && u8(s.peek(3)).is_hex_digit() + && u8(s.peek(4)).is_hex_digit() && u8(s.peek(5)).is_hex_digit() { lit += s.text[s.pos + 1..s.pos + 6] //.ascii_str() util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'gulp escaped unicode `$lit`') return lit, 5 @@ -559,12 +559,12 @@ fn (mut s Scanner) handle_escapes(quote byte, is_multiline bool) (string, int) { } if is_literal_string { if s.peek(1) == quote { - util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'ignore escape `$lit${byte(s.peek(1)).ascii_str()}` in literal string') + util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'ignore escape `$lit${u8(s.peek(1)).ascii_str()}` in literal string') return '', 0 } } - lit += byte(s.peek(1)).ascii_str() + lit += u8(s.peek(1)).ascii_str() util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'gulp escaped `$lit`') return lit, 1 } @@ -582,22 +582,22 @@ fn (mut s Scanner) extract_number() ?string { start := s.pos mut c := s.at() - is_digit := byte(c).is_digit() + is_digit := u8(c).is_digit() if !(is_digit || c in [`+`, `-`]) { return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' ${byte(c).ascii_str()} is not a number at ${s.excerpt(s.pos, 10)}') + ' ${u8(c).ascii_str()} is not a number at ${s.excerpt(s.pos, 10)}') } s.pos++ s.col++ for s.pos < s.text.len { c = s.at() // Handle signed exponent notation. I.e.: 3e2, 3E2, 3e-2, 3E+2, 3e0, 3.1e2, 3.1E2, -1E-1 - if c in [`e`, `E`] && s.peek(1) in [`+`, `-`] && byte(s.peek(2)).is_digit() { + if c in [`e`, `E`] && s.peek(1) in [`+`, `-`] && u8(s.peek(2)).is_digit() { s.pos += 2 s.col += 2 } c = s.at() - if !(byte(c).is_hex_digit() || c in scanner.digit_extras) + if !(u8(c).is_hex_digit() || c in scanner.digit_extras) || (c == `.` && s.is_left_of_assign) { break } @@ -622,7 +622,7 @@ fn (mut s Scanner) extract_nan_or_inf_number() ?string { mut c := s.at() if c !in [`+`, `-`, `n`, `i`] { return error(@MOD + '.' + @STRUCT + '.' + @FN + - ' ${byte(c).ascii_str()} is not a number at ${s.excerpt(s.pos, 10)}') + ' ${u8(c).ascii_str()} is not a number at ${s.excerpt(s.pos, 10)}') } s.pos++ s.col++ diff --git a/vlib/toml/toml.v b/vlib/toml/toml.v index 43cd4eb4f5..e85ddb27e6 100644 --- a/vlib/toml/toml.v +++ b/vlib/toml/toml.v @@ -131,7 +131,7 @@ pub fn parse_dotted_key(key string) ?[]string { mut out := []string{} mut buf := '' mut in_string := false - mut delim := byte(` `) + mut delim := u8(` `) for ch in key { if ch in [`"`, `'`] { if !in_string { diff --git a/vlib/v/builder/rebuilding.v b/vlib/v/builder/rebuilding.v index 40dd90265f..ee8aac0c1f 100644 --- a/vlib/v/builder/rebuilding.v +++ b/vlib/v/builder/rebuilding.v @@ -37,9 +37,9 @@ pub fn (mut b Builder) rebuild_modules() { chash := hash.sum64_string(ccontent, 7).hex_full() new_hashes[cpath] = chash sb_new_hashes.write_string(chash) - sb_new_hashes.write_byte(` `) + sb_new_hashes.write_u8(` `) sb_new_hashes.write_string(cpath) - sb_new_hashes.write_byte(`\n`) + sb_new_hashes.write_u8(`\n`) } snew_hashes := sb_new_hashes.str() // eprintln('new_hashes: $new_hashes') diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index d0b032c45d..419ed5a038 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2621,7 +2621,7 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type { c.error('dump expression can not be void', node.expr.pos()) return ast.void_type } else if etidx == ast.char_type_idx && node.expr_type.nr_muls() == 0 { - c.error('`char` values cannot be dumped directly, use dump(byte(x)) or dump(int(x)) instead', + c.error('`char` values cannot be dumped directly, use dump(u8(x)) or dump(int(x)) instead', node.expr.pos()) return ast.void_type } @@ -2937,7 +2937,7 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { } else if from_type.is_real_pointer() { snexpr := node.expr.str() ft := c.table.type_to_str(from_type) - c.error('cannot cast pointer type `$ft` to string, use `&byte($snexpr).vstring()` or `cstring_to_vstring($snexpr)` instead.', + c.error('cannot cast pointer type `$ft` to string, use `&u8($snexpr).vstring()` or `cstring_to_vstring($snexpr)` instead.', node.pos) } else if from_type.is_number() { snexpr := node.expr.str() diff --git a/vlib/v/embed_file/embed_file.v b/vlib/v/embed_file/embed_file.v index 730cc31807..fb4401d3e9 100644 --- a/vlib/v/embed_file/embed_file.v +++ b/vlib/v/embed_file/embed_file.v @@ -33,11 +33,11 @@ pub fn (mut ed EmbedFileData) free() { ed.compression_type.free() if ed.free_compressed { free(ed.compressed) - ed.compressed = &byte(0) + ed.compressed = &u8(0) } if ed.free_uncompressed { free(ed.uncompressed) - ed.uncompressed = &byte(0) + ed.uncompressed = &u8(0) } } } @@ -45,7 +45,7 @@ pub fn (mut ed EmbedFileData) free() { pub fn (original &EmbedFileData) to_string() string { unsafe { mut ed := &EmbedFileData(original) - the_copy := &byte(memdup(ed.data(), ed.len)) + the_copy := &u8(memdup(ed.data(), ed.len)) return the_copy.vstring_with_len(ed.len) } } @@ -71,7 +71,7 @@ pub fn (mut ed EmbedFileData) data() &byte { panic('EmbedFileData error: decompression of "$ed.path" failed: $err') } unsafe { - ed.uncompressed = &byte(memdup(decompressed.data, ed.len)) + ed.uncompressed = &u8(memdup(decompressed.data, ed.len)) } } else { mut path := os.resource_abs_path(ed.path) diff --git a/vlib/v/embed_file/tests/embed_file_test.v b/vlib/v/embed_file/tests/embed_file_test.v index 4608512c54..dad2f1ddeb 100644 --- a/vlib/v/embed_file/tests/embed_file_test.v +++ b/vlib/v/embed_file/tests/embed_file_test.v @@ -17,7 +17,7 @@ fn test_const_embed_file() { assert file.path == 'v.png' assert file.len == 603 unsafe { - assert fdata.vbytes(4) == [byte(0x89), `P`, `N`, `G`] + assert fdata.vbytes(4) == [u8(0x89), `P`, `N`, `G`] } } @@ -29,6 +29,6 @@ fn test_embed_file() { eprintln('file after .data() call: $file') assert file.len == 603 unsafe { - assert fdata.vbytes(4) == [byte(0x89), `P`, `N`, `G`] + assert fdata.vbytes(4) == [u8(0x89), `P`, `N`, `G`] } } diff --git a/vlib/v/embed_file/tests/embed_file_test_with_import.v b/vlib/v/embed_file/tests/embed_file_test_with_import.v index 1db2ff6f18..be0c20a826 100644 --- a/vlib/v/embed_file/tests/embed_file_test_with_import.v +++ b/vlib/v/embed_file/tests/embed_file_test_with_import.v @@ -8,7 +8,7 @@ fn test_embed_file_with_import() { eprintln('file after .data() call: $file') assert file.len == 603 unsafe { - assert fdata.vbytes(4) == [byte(0x89), `P`, `N`, `G`] + assert fdata.vbytes(4) == [u8(0x89), `P`, `N`, `G`] } assert check_file(file) } diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 1f1c19d4bc..4a0880a1d7 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -87,7 +87,7 @@ mut: is_assign_lhs bool // inside left part of assign expr (for array_set(), etc) is_void_expr_stmt bool // ExprStmt whos result is discarded is_arraymap_set bool // map or array set value state - is_amp bool // for `&Foo{}` to merge PrefixExpr `&` and StructInit `Foo{}`; also for `&byte(0)` etc + is_amp bool // for `&Foo{}` to merge PrefixExpr `&` and StructInit `Foo{}`; also for `&u8(0)` etc is_sql bool // Inside `sql db{}` statement, generating sql instead of C (e.g. `and` instead of `&&` etc) is_shared bool // for initialization of hidden mutex in `[rw]shared` literals is_vlines_enabled bool // is it safe to generate #line directives when -g is passed @@ -2229,7 +2229,7 @@ fn cescape_nonascii(original string) string { write_octal_escape(mut b, c) continue } - b.write_byte(c) + b.write_u8(c) } res := b.str() return res diff --git a/vlib/v/gen/c/cheaders.v b/vlib/v/gen/c/cheaders.v index 4c630f9726..cb596e2305 100644 --- a/vlib/v/gen/c/cheaders.v +++ b/vlib/v/gen/c/cheaders.v @@ -106,7 +106,7 @@ fn amd64_bytes(nargs int) string { sb.write_string('0x48, 0x83, 0xec, 0x$s, ') // sub rsp,0x8 sub rsp,0x10 sb.write_string('0xff, 0x35, 0xe6, 0xff, 0xff, 0xff, ') // push QWORD PTR [rip+0xffffffffffffffe6] - rsp_offset := byte(0x18 + ((u8(nargs - 7) >> 1) << 4)).hex() + rsp_offset := u8(0x18 + ((u8(nargs - 7) >> 1) << 4)).hex() for _ in 0 .. nargs - 7 { sb.write_string('0xff, 0xb4, 0x24, 0x$rsp_offset, 0x00, 0x00, 0x00, ') // push QWORD PTR [rsp+$rsp_offset] } diff --git a/vlib/v/gen/js/fn.v b/vlib/v/gen/js/fn.v index d583111314..e82724ebb7 100644 --- a/vlib/v/gen/js/fn.v +++ b/vlib/v/gen/js/fn.v @@ -121,7 +121,7 @@ fn (mut g JsGen) js_call(node ast.CallExpr) { if g.file.mod.name == 'main' && g.fn_decl.name == 'main.main' { g.writeln('return builtin__panic($panicstr)') } else { - g.writeln('throw new Option({ state: new byte(2), err: error(new string($panicstr)) });') + g.writeln('throw new Option({ state: new u8(2), err: error(new string($panicstr)) });') } } else {} @@ -181,7 +181,7 @@ fn (mut g JsGen) js_method_call(node ast.CallExpr) { if g.file.mod.name == 'main' && g.fn_decl.name == 'main.main' { g.writeln('return builtin__panic($panicstr)') } else { - g.writeln('throw new Option({ state: new byte(2), err: error(new string($panicstr)) });') + g.writeln('throw new Option({ state: new u8(2), err: error(new string($panicstr)) });') } } else {} diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 33dc2d3e6b..26821b9f99 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -902,7 +902,7 @@ fn (mut g JsGen) expr(node_ ast.Expr) { if utf8_str_len(node.val) < node.val.len { g.write("new rune('$node.val'.charCodeAt())") } else { - g.write("new byte('$node.val')") + g.write("new u8('$node.val')") } } ast.Comment {} @@ -1689,7 +1689,7 @@ fn (mut g JsGen) gen_for_in_stmt(it ast.ForInStmt) { g.write('new ') - g.write('byte($val)])') + g.write('u8($val)])') } else { g.expr(it.cond) if it.cond_type.is_ptr() { @@ -1712,7 +1712,7 @@ fn (mut g JsGen) gen_for_in_stmt(it ast.ForInStmt) { g.write('new ') - g.write('byte(c))') + g.write('u8(c))') } } g.writeln(') {') @@ -1841,7 +1841,7 @@ fn (mut g JsGen) gen_interface_decl(it ast.InterfaceDecl) { } fn (mut g JsGen) gen_optional_error(expr ast.Expr) { - g.write('new Option({ state: new byte(2),err: ') + g.write('new Option({ state: new u8(2),err: ') g.expr(expr) g.write('})') } @@ -1896,7 +1896,7 @@ fn (mut g JsGen) gen_return_stmt(it ast.Return) { g.write('const $tmp = new ') g.writeln('Option({});') - g.write('${tmp}.state = new byte(0);') + g.write('${tmp}.state = new u8(0);') g.write('${tmp}.data = ') if it.exprs.len == 1 { g.expr(it.exprs[0]) @@ -2942,7 +2942,7 @@ fn (mut g JsGen) gen_index_expr(expr ast.IndexExpr) { // 'string'[3] = `o` } else { // TODO: Maybe use u16 there? JS String returns values up to 2^16-1 - g.write('new byte(') + g.write('new u8(') g.expr(expr.left) if expr.left_type.is_ptr() { g.write('.valueOf()') @@ -3796,7 +3796,7 @@ fn (mut g JsGen) gen_postfix_index_expr(expr ast.IndexExpr, op token.Kind) { // 'string'[3] = `o` } else { // TODO: Maybe use u16 there? JS String returns values up to 2^16-1 - g.write('new byte(') + g.write('new u8(') g.expr(expr.left) if expr.left_type.is_ptr() { g.write('.valueOf()') diff --git a/vlib/v/gen/js/sourcemap/vlq/vlq.v b/vlib/v/gen/js/sourcemap/vlq/vlq.v index 7dfef05e09..2d20e4a931 100644 --- a/vlib/v/gen/js/sourcemap/vlq/vlq.v +++ b/vlib/v/gen/js/sourcemap/vlq/vlq.v @@ -3,9 +3,9 @@ module vlq import io const ( - shift = byte(5) - mask = byte((1 << shift) - 1) - continued = byte(1 << shift) + shift = u8(5) + mask = u8((1 << shift) - 1) + continued = u8(1 << shift) max_i64 = u64(9223372036854775807) // index start is: byte - vlq.enc_char_special_plus @@ -38,7 +38,7 @@ fn decode64(input byte) byte { assert input >= vlq.enc_char_special_plus assert input <= vlq.enc_char_end_zl } - return byte(vlq.enc_index[input - vlq.enc_char_special_plus]) + return u8(vlq.enc_index[input - vlq.enc_char_special_plus]) } // Decode a single VLQ value from the input stream, returning the value. @@ -55,7 +55,7 @@ pub fn decode(mut input io.Reader) ?i64 { mut accum := u64(0) mut shifter := 0 - mut digit := byte(0) + mut digit := u8(0) mut keep_going := true for keep_going { @@ -101,7 +101,7 @@ pub fn encode(value i64, mut output io.Writer) ? { value_u64 |= 1 } for { - mut digit := byte(value_u64) & vlq.mask + mut digit := u8(value_u64) & vlq.mask value_u64 >>= vlq.shift if value_u64 > 0 { digit |= vlq.continued diff --git a/vlib/v/gen/js/tests/interp.v b/vlib/v/gen/js/tests/interp.v index 5b00aa8d8b..54f911cf54 100644 --- a/vlib/v/gen/js/tests/interp.v +++ b/vlib/v/gen/js/tests/interp.v @@ -98,8 +98,8 @@ fn interpolation_string_prefix_expr() { inttypes_string_interpolation() fn inttypes_string_interpolation() { c := i8(-103) - uc := byte(217) - uc2 := byte(13) + uc := u8(217) + uc2 := u8(13) s := i16(-23456) us := u16(54321) i := -1622999040 diff --git a/vlib/v/gen/native/amd64.v b/vlib/v/gen/native/amd64.v index 00133d930a..faab705151 100644 --- a/vlib/v/gen/native/amd64.v +++ b/vlib/v/gen/native/amd64.v @@ -55,7 +55,7 @@ fn (mut g Gen) dec(reg Register) { [inline] fn byt(n int, s int) byte { - return byte((n >> (s * 8)) & 0xff) + return u8((n >> (s * 8)) & 0xff) } fn (mut g Gen) inc(reg Register) { @@ -111,7 +111,7 @@ fn (mut g Gen) cmp_reg(reg Register, reg2 Register) { .rax { match reg2 { .rbx { - g.write([byte(0x48), 0x39, 0xd8]) + g.write([u8(0x48), 0x39, 0xd8]) } else { g.n_error('Cannot compare $reg and $reg2') @@ -121,7 +121,7 @@ fn (mut g Gen) cmp_reg(reg Register, reg2 Register) { .rbx { match reg2 { .rax { - g.write([byte(0x48), 0x39, 0xc3]) + g.write([u8(0x48), 0x39, 0xc3]) } else { g.n_error('Cannot compare $reg and $reg2') @@ -559,8 +559,8 @@ pub fn (mut g Gen) gen_print(s string, fd int) { // g.mov64(.rdx, g.allocate_string(s, 3)) g.lea(.rdx, g.allocate_string(s, 3, .abs64)) g.mov(.r8, s.len) // string length - g.write([byte(0x4c), 0x8d, 0x4c, 0x24, 0x20]) // lea r9, [rsp+0x20] - g.write([byte(0x48), 0xc7, 0x44, 0x24, 0x20]) + g.write([u8(0x4c), 0x8d, 0x4c, 0x24, 0x20]) // lea r9, [rsp+0x20] + g.write([u8(0x48), 0xc7, 0x44, 0x24, 0x20]) g.write32(0) // mov qword[rsp+0x20], 0 // g.mov(.r9, rsp+0x20) g.apicall('WriteFile') @@ -648,12 +648,12 @@ fn (mut g Gen) relpc(dst Register, src Register) { .rax { match src { .rsi { - g.write([byte(0x48), 0x8d, 0x35, 0x00, 0x00, 0x00, 0x00]) // lea rsi, rip - g.write([byte(0x48), 0x01, 0xf0]) // add rax, rsi + g.write([u8(0x48), 0x8d, 0x35, 0x00, 0x00, 0x00, 0x00]) // lea rsi, rip + g.write([u8(0x48), 0x01, 0xf0]) // add rax, rsi } .rbx { - g.write([byte(0x48), 0x8d, 0x1d, 0x00, 0x00, 0x00, 0x00]) - g.write([byte(0x48), 0x01, 0xd8]) + g.write([u8(0x48), 0x8d, 0x1d, 0x00, 0x00, 0x00, 0x00]) + g.write([u8(0x48), 0x01, 0xd8]) } else { panic('relpc requires .rax, {.rsi,.rbx}') @@ -874,7 +874,7 @@ fn (mut g Gen) add_reg(a Register, b Register) { fn (mut g Gen) mov_reg(a Register, b Register) { if a == .rax && b == .rsi { - g.write([byte(0x48), 0x89, 0xf0]) + g.write([u8(0x48), 0x89, 0xf0]) } else if a == .rbp && b == .rsp { g.write8(0x48) g.write8(0x89) @@ -1342,43 +1342,43 @@ fn (mut g Gen) gen_asm_stmt_amd64(asm_node ast.AsmStmt) { g.println(': $line') match t.name { 'nop' { - g.write8(byte(0x90)) + g.write8(u8(0x90)) g.println('nop') } 'syscall' { - g.write8(byte(0x0f)) - g.write8(byte(0x05)) + g.write8(u8(0x0f)) + g.write8(u8(0x05)) g.println('syscall') } 'ret' { - g.write8(byte(0xc3)) + g.write8(u8(0xc3)) g.println('ret') } 'int3' { - g.write8(byte(0xcc)) - g.write8(byte(imm)) + g.write8(u8(0xcc)) + g.write8(u8(imm)) g.println('int3') } 'sti' { - g.write8(byte(0xfb)) + g.write8(u8(0xfb)) g.println('sti') } 'cli' { - g.write8(byte(0xfa)) + g.write8(u8(0xfa)) g.println('cli') } 'int' { - g.write8(byte(0xcd)) - g.write8(byte(imm)) + g.write8(u8(0xcd)) + g.write8(u8(imm)) g.println('int') } 'cpuid' { - g.write8(byte(0x0f)) - g.write8(byte(0xa2)) + g.write8(u8(0x0f)) + g.write8(u8(0xa2)) g.println('cpuid') } 'mov' { - g.write8(byte(0xb8 + reg)) + g.write8(u8(0xb8 + reg)) g.write8(byt(imm, 0)) g.write8(byt(imm, 1)) g.write8(byt(imm, 2)) @@ -1532,10 +1532,10 @@ fn (mut g Gen) if_expr(node ast.IfExpr) { fn (mut g Gen) infloop() { if g.pref.arch == .arm64 { - g.write32(byte(0x14)) + g.write32(u8(0x14)) } else { - g.write8(byte(0xeb)) - g.write8(byte(0xfe)) + g.write8(u8(0xeb)) + g.write8(u8(0xfe)) } g.println('jmp $$') } diff --git a/vlib/v/gen/native/gen.v b/vlib/v/gen/native/gen.v index bd3ae37e54..dcfa999219 100644 --- a/vlib/v/gen/native/gen.v +++ b/vlib/v/gen/native/gen.v @@ -201,13 +201,13 @@ fn (mut g Gen) write(bytes []byte) { fn (mut g Gen) write8(n int) { // write 1 byte - g.buf << byte(n) + g.buf << u8(n) } fn (mut g Gen) write16(n int) { // write 2 bytes - g.buf << byte(n) - g.buf << byte(n >> 8) + g.buf << u8(n) + g.buf << u8(n >> 8) } fn (mut g Gen) read32_at(at int) int { @@ -217,48 +217,48 @@ fn (mut g Gen) read32_at(at int) int { fn (mut g Gen) write32(n int) { // write 4 bytes - g.buf << byte(n) - g.buf << byte(n >> 8) - g.buf << byte(n >> 16) - g.buf << byte(n >> 24) + g.buf << u8(n) + g.buf << u8(n >> 8) + g.buf << u8(n >> 16) + g.buf << u8(n >> 24) } fn (mut g Gen) write64(n i64) { // write 8 bytes - g.buf << byte(n) - g.buf << byte(n >> 8) - g.buf << byte(n >> 16) - g.buf << byte(n >> 24) - g.buf << byte(n >> 32) - g.buf << byte(n >> 40) - g.buf << byte(n >> 48) - g.buf << byte(n >> 56) + g.buf << u8(n) + g.buf << u8(n >> 8) + g.buf << u8(n >> 16) + g.buf << u8(n >> 24) + g.buf << u8(n >> 32) + g.buf << u8(n >> 40) + g.buf << u8(n >> 48) + g.buf << u8(n >> 56) } fn (mut g Gen) write64_at(at i64, n i64) { // write 8 bytes - g.buf[at] = byte(n) - g.buf[at + 1] = byte(n >> 8) - g.buf[at + 2] = byte(n >> 16) - g.buf[at + 3] = byte(n >> 24) - g.buf[at + 4] = byte(n >> 32) - g.buf[at + 5] = byte(n >> 40) - g.buf[at + 6] = byte(n >> 48) - g.buf[at + 7] = byte(n >> 56) + g.buf[at] = u8(n) + g.buf[at + 1] = u8(n >> 8) + g.buf[at + 2] = u8(n >> 16) + g.buf[at + 3] = u8(n >> 24) + g.buf[at + 4] = u8(n >> 32) + g.buf[at + 5] = u8(n >> 40) + g.buf[at + 6] = u8(n >> 48) + g.buf[at + 7] = u8(n >> 56) } fn (mut g Gen) write32_at(at i64, n int) { // write 4 bytes - g.buf[at] = byte(n) - g.buf[at + 1] = byte(n >> 8) - g.buf[at + 2] = byte(n >> 16) - g.buf[at + 3] = byte(n >> 24) + g.buf[at] = u8(n) + g.buf[at + 1] = u8(n >> 8) + g.buf[at + 2] = u8(n >> 16) + g.buf[at + 3] = u8(n >> 24) } fn (mut g Gen) write16_at(at i64, n int) { // write 2 bytes - g.buf[at] = byte(n) - g.buf[at + 1] = byte(n >> 8) + g.buf[at] = u8(n) + g.buf[at + 1] = u8(n >> 8) } fn (mut g Gen) write_string(s string) { @@ -611,7 +611,7 @@ fn (mut g Gen) stmt(node ast.Stmt) { g.n_error('opcodes format: xx xx xx xx') } b := unsafe { C.strtol(&char(word.str), 0, 16) } - // b := word.byte() + // b := word.u8() // println('"$word" $b') g.write8(b) } diff --git a/vlib/v/gen/native/pe.v b/vlib/v/gen/native/pe.v index ed42685d09..9488d8f7c3 100644 --- a/vlib/v/gen/native/pe.v +++ b/vlib/v/gen/native/pe.v @@ -96,16 +96,16 @@ fn (mut g Gen) write_pe_sections() { g.write32(0) g.write32(0) g.write32(0x20000000) // 0, 0, 0, 32, - g.write([byte(0), 0, 96]) + g.write([u8(0), 0, 96]) g.zeroes(52) - g.write([byte(72), 16, 0, 0]) - g.write([byte(40), 16, 0, 0]) + g.write([u8(72), 16, 0, 0]) + g.write([u8(40), 16, 0, 0]) g.zeroes(20) - g.write([byte(96), 16, 0, 0]) + g.write([u8(96), 16, 0, 0]) g.write32(0) - g.write([byte(110), 16, 0, 0]) + g.write([u8(110), 16, 0, 0]) g.write32(0) - g.write([byte(125), 16, 0, 0]) + g.write([u8(125), 16, 0, 0]) g.zeroes(12) g.write_string_with_padding('KERNEL32.DLL', 13) g.write_string_with_padding('USER32.DLL', 13) @@ -215,7 +215,7 @@ pub fn (mut g Gen) generate_pe_header() { fn pad_to(mut buf []byte, len int) { for buf.len < len { - buf << byte(0) + buf << u8(0) } } diff --git a/vlib/v/parser/tmpl.v b/vlib/v/parser/tmpl.v index e0aa85eebd..fe70bef9af 100644 --- a/vlib/v/parser/tmpl.v +++ b/vlib/v/parser/tmpl.v @@ -76,7 +76,7 @@ fn is_html_open_tag(name string, s string) bool { fn insert_template_code(fn_name string, tmpl_str_start string, line string) string { // HTML, may include `@var` // escaped by cgen, unless it's a `vweb.RawHtml` string - trailing_bs := parser.tmpl_str_end + 'sb_${fn_name}.write_byte(92)\n' + tmpl_str_start + trailing_bs := parser.tmpl_str_end + 'sb_${fn_name}.write_u8(92)\n' + tmpl_str_start round1 := ['\\', '\\\\', r"'", "\\'", r'@', r'$'] round2 := [r'$$', r'\@', r'.$', r'.@'] mut rline := line.replace_each(round1).replace_each(round2) diff --git a/vlib/v/scanner/scanner_test.v b/vlib/v/scanner/scanner_test.v index b4076e7a43..62a7f5cdb0 100644 --- a/vlib/v/scanner/scanner_test.v +++ b/vlib/v/scanner/scanner_test.v @@ -244,7 +244,7 @@ fn test_escape_string() { // (should not be converted to unicode) result = scan_tokens(r"'\xe29885'") assert result[0].kind == .string - assert result[0].lit.bytes() == [byte(0xe2), `9`, `8`, `8`, `5`] + assert result[0].lit.bytes() == [u8(0xe2), `9`, `8`, `8`, `5`] // SHOULD RESULT IN ERRORS // result = scan_tokens(r'`\x61\x61`') // should always result in an error @@ -255,7 +255,7 @@ fn test_escape_string() { fn test_comment_string() { mut result := scan_tokens('// single line comment will get an \\x01 prepended') assert result[0].kind == .comment - assert result[0].lit[0] == byte(1) // \x01 + assert result[0].lit[0] == u8(1) // \x01 // result = scan_tokens('/// doc comment will keep third / at beginning') // result = scan_tokens('/* block comment will be stripped of whitespace */') // result = scan_tokens('a := 0 // line end comment also gets \\x01 prepended') diff --git a/vlib/v/tests/alias_basic_types_test.v b/vlib/v/tests/alias_basic_types_test.v index 8cdb58d372..71efa4a6f9 100644 --- a/vlib/v/tests/alias_basic_types_test.v +++ b/vlib/v/tests/alias_basic_types_test.v @@ -10,17 +10,17 @@ fn ok() { // bytes fn test_byte_aliasing() { - dump(byte(123)) - dump(MyByte(byte(123))) - dump(byte(MyByte(byte(123)))) + dump(u8(123)) + dump(MyByte(u8(123))) + dump(u8(MyByte(u8(123)))) ok() } fn test_pbyte_aliasing() { unsafe { - dump(voidptr(&byte(123))) - dump(voidptr(&MyByte(&byte(123)))) - dump(voidptr(&byte(&MyByte(&byte(123))))) + dump(voidptr(&u8(123))) + dump(voidptr(&MyByte(&u8(123)))) + dump(voidptr(&u8(&MyByte(&u8(123))))) } ok() } diff --git a/vlib/v/tests/array_to_string_test.v b/vlib/v/tests/array_to_string_test.v index 92f68be124..90261c2ca9 100644 --- a/vlib/v/tests/array_to_string_test.v +++ b/vlib/v/tests/array_to_string_test.v @@ -18,7 +18,7 @@ fn test_array_to_string_conversion() { e := [i64(1), 2, 3] assert e.str() == '[1, 2, 3]' - f := [byte(66), 32, 126, 10, 13, 5, 18, 127, 255] + f := [u8(66), 32, 126, 10, 13, 5, 18, 127, 255] assert f.str() == '[B, , ~, `\\n`, `\\r`, 0x05, 0x12, 0x7f, 0xff]' // https://github.com/vlang/v/issues/8036 diff --git a/vlib/v/tests/assembly/asm_test.amd64.v b/vlib/v/tests/assembly/asm_test.amd64.v index 38a378a905..93017b4d98 100644 --- a/vlib/v/tests/assembly/asm_test.amd64.v +++ b/vlib/v/tests/assembly/asm_test.amd64.v @@ -122,7 +122,7 @@ mut: fn (m Manu) str() string { return unsafe { string{ - str: &byte(&m) + str: &u8(&m) len: 24 is_lit: 1 } @@ -154,7 +154,7 @@ $if !macos { // this test does not appear in i386 test since rip relative addressing was introduced in 64-bit mode // doesn't actually work [if !macos] -fn test_rip_relative_label_byte() { +fn test_rip_relative_label_u8() { $if !macos { mut a := int(4) asm amd64 { diff --git a/vlib/v/tests/assembly/asm_test.i386.v b/vlib/v/tests/assembly/asm_test.i386.v index d285407253..d4e395b524 100644 --- a/vlib/v/tests/assembly/asm_test.i386.v +++ b/vlib/v/tests/assembly/asm_test.i386.v @@ -118,7 +118,7 @@ mut: fn (m Manu) str() string { return unsafe { string{ - str: &byte(&m) + str: &u8(&m) len: 24 is_lit: 1 } diff --git a/vlib/v/tests/c_function_mut_param/code_test.v b/vlib/v/tests/c_function_mut_param/code_test.v index c95fbc29b6..91189df854 100644 --- a/vlib/v/tests/c_function_mut_param/code_test.v +++ b/vlib/v/tests/c_function_mut_param/code_test.v @@ -5,7 +5,7 @@ module main fn C.mut_arg(key &byte, mut val usize) fn test_c_function_mut_param() { - key := &byte(1) + key := &u8(1) mut val := usize(1) C.mut_arg(key, mut &val) assert val == usize(5) diff --git a/vlib/v/tests/cast_in_comptime_if_test.v b/vlib/v/tests/cast_in_comptime_if_test.v index bd3f8d45ea..7214d3691a 100644 --- a/vlib/v/tests/cast_in_comptime_if_test.v +++ b/vlib/v/tests/cast_in_comptime_if_test.v @@ -4,8 +4,8 @@ fn test_cast_in_comptime_if() { fn generic_bool(val T) { $if T is bool { - println(byte(val)) - assert byte(val) == 1 + println(u8(val)) + assert u8(val) == 1 println(i8(val)) assert i8(val) == 1 diff --git a/vlib/v/tests/cast_to_byte_test.v b/vlib/v/tests/cast_to_byte_test.v index e5b1b3f878..3aa6231390 100644 --- a/vlib/v/tests/cast_to_byte_test.v +++ b/vlib/v/tests/cast_to_byte_test.v @@ -7,10 +7,10 @@ enum WireType { } fn pack_wire_type(w WireType) byte { - return byte(w) + return u8(w) } -fn test_casting_an_enum_to_byte() { +fn test_casting_an_enum_to_u8() { x := WireType.length_prefixed y := pack_wire_type(x) assert 'x: $x' == 'x: length_prefixed' @@ -19,23 +19,23 @@ fn test_casting_an_enum_to_byte() { // -fn test_casting_a_float_to_byte() { +fn test_casting_a_float_to_u8() { x := 1.23 - b := byte(x) + b := u8(x) assert 'x: $x | b: $b.hex()' == 'x: 1.23 | b: 01' } -fn test_casting_an_int_to_byte() { +fn test_casting_an_int_to_u8() { x := 12 - b := byte(x) + b := u8(x) assert 'x: $x | b: $b.hex()' == 'x: 12 | b: 0c' } -fn test_casting_a_bool_to_byte() { +fn test_casting_a_bool_to_u8() { x := true - b1 := byte(x) + b1 := u8(x) assert 'x: $x | b: $b1.hex()' == 'x: true | b: 01' y := false - b2 := byte(y) + b2 := u8(y) assert 'y: $y | b: $b2.hex()' == 'y: false | b: 00' } diff --git a/vlib/v/tests/cast_to_u8_test.v b/vlib/v/tests/cast_to_u8_test.v index babf9638d7..e5bad9ff35 100644 --- a/vlib/v/tests/cast_to_u8_test.v +++ b/vlib/v/tests/cast_to_u8_test.v @@ -1,11 +1,11 @@ module main fn test_cast_to_alias() { - r1 := u8(byte(1)) + r1 := u8(u8(1)) println(r1) assert '$r1' == '1' - r2 := u8(byte(true)) + r2 := u8(u8(true)) println(r2) assert '$r2' == '1' diff --git a/vlib/v/tests/char_literal_bytes_test.v b/vlib/v/tests/char_literal_bytes_test.v index 2647a3a2b3..d3c6ac85ef 100644 --- a/vlib/v/tests/char_literal_bytes_test.v +++ b/vlib/v/tests/char_literal_bytes_test.v @@ -1,515 +1,515 @@ fn test_all_byte_char_literals() { mut a := ` ` a = `\x00` - assert byte(a) == byte(0) + assert u8(a) == u8(0) a = `\x01` - assert byte(a) == byte(1) + assert u8(a) == u8(1) a = `\x02` - assert byte(a) == byte(2) + assert u8(a) == u8(2) a = `\x03` - assert byte(a) == byte(3) + assert u8(a) == u8(3) a = `\x04` - assert byte(a) == byte(4) + assert u8(a) == u8(4) a = `\x05` - assert byte(a) == byte(5) + assert u8(a) == u8(5) a = `\x06` - assert byte(a) == byte(6) + assert u8(a) == u8(6) a = `\x07` - assert byte(a) == byte(7) + assert u8(a) == u8(7) a = `\x08` - assert byte(a) == byte(8) + assert u8(a) == u8(8) a = `\x09` - assert byte(a) == byte(9) + assert u8(a) == u8(9) a = `\x0a` - assert byte(a) == byte(10) + assert u8(a) == u8(10) a = `\x0b` - assert byte(a) == byte(11) + assert u8(a) == u8(11) a = `\x0c` - assert byte(a) == byte(12) + assert u8(a) == u8(12) a = `\x0d` - assert byte(a) == byte(13) + assert u8(a) == u8(13) a = `\x0e` - assert byte(a) == byte(14) + assert u8(a) == u8(14) a = `\x0f` - assert byte(a) == byte(15) + assert u8(a) == u8(15) a = `\x10` - assert byte(a) == byte(16) + assert u8(a) == u8(16) a = `\x11` - assert byte(a) == byte(17) + assert u8(a) == u8(17) a = `\x12` - assert byte(a) == byte(18) + assert u8(a) == u8(18) a = `\x13` - assert byte(a) == byte(19) + assert u8(a) == u8(19) a = `\x14` - assert byte(a) == byte(20) + assert u8(a) == u8(20) a = `\x15` - assert byte(a) == byte(21) + assert u8(a) == u8(21) a = `\x16` - assert byte(a) == byte(22) + assert u8(a) == u8(22) a = `\x17` - assert byte(a) == byte(23) + assert u8(a) == u8(23) a = `\x18` - assert byte(a) == byte(24) + assert u8(a) == u8(24) a = `\x19` - assert byte(a) == byte(25) + assert u8(a) == u8(25) a = `\x1a` - assert byte(a) == byte(26) + assert u8(a) == u8(26) a = `\x1b` - assert byte(a) == byte(27) + assert u8(a) == u8(27) a = `\x1c` - assert byte(a) == byte(28) + assert u8(a) == u8(28) a = `\x1d` - assert byte(a) == byte(29) + assert u8(a) == u8(29) a = `\x1e` - assert byte(a) == byte(30) + assert u8(a) == u8(30) a = `\x1f` - assert byte(a) == byte(31) + assert u8(a) == u8(31) a = `\x20` - assert byte(a) == byte(32) + assert u8(a) == u8(32) a = `\x21` - assert byte(a) == byte(33) + assert u8(a) == u8(33) a = `\x22` - assert byte(a) == byte(34) + assert u8(a) == u8(34) a = `\x23` - assert byte(a) == byte(35) + assert u8(a) == u8(35) a = `\x24` - assert byte(a) == byte(36) + assert u8(a) == u8(36) a = `\x25` - assert byte(a) == byte(37) + assert u8(a) == u8(37) a = `\x26` - assert byte(a) == byte(38) + assert u8(a) == u8(38) a = `\x27` - assert byte(a) == byte(39) + assert u8(a) == u8(39) a = `\x28` - assert byte(a) == byte(40) + assert u8(a) == u8(40) a = `\x29` - assert byte(a) == byte(41) + assert u8(a) == u8(41) a = `\x2a` - assert byte(a) == byte(42) + assert u8(a) == u8(42) a = `\x2b` - assert byte(a) == byte(43) + assert u8(a) == u8(43) a = `\x2c` - assert byte(a) == byte(44) + assert u8(a) == u8(44) a = `\x2d` - assert byte(a) == byte(45) + assert u8(a) == u8(45) a = `\x2e` - assert byte(a) == byte(46) + assert u8(a) == u8(46) a = `\x2f` - assert byte(a) == byte(47) + assert u8(a) == u8(47) a = `\x30` - assert byte(a) == byte(48) + assert u8(a) == u8(48) a = `\x31` - assert byte(a) == byte(49) + assert u8(a) == u8(49) a = `\x32` - assert byte(a) == byte(50) + assert u8(a) == u8(50) a = `\x33` - assert byte(a) == byte(51) + assert u8(a) == u8(51) a = `\x34` - assert byte(a) == byte(52) + assert u8(a) == u8(52) a = `\x35` - assert byte(a) == byte(53) + assert u8(a) == u8(53) a = `\x36` - assert byte(a) == byte(54) + assert u8(a) == u8(54) a = `\x37` - assert byte(a) == byte(55) + assert u8(a) == u8(55) a = `\x38` - assert byte(a) == byte(56) + assert u8(a) == u8(56) a = `\x39` - assert byte(a) == byte(57) + assert u8(a) == u8(57) a = `\x3a` - assert byte(a) == byte(58) + assert u8(a) == u8(58) a = `\x3b` - assert byte(a) == byte(59) + assert u8(a) == u8(59) a = `\x3c` - assert byte(a) == byte(60) + assert u8(a) == u8(60) a = `\x3d` - assert byte(a) == byte(61) + assert u8(a) == u8(61) a = `\x3e` - assert byte(a) == byte(62) + assert u8(a) == u8(62) a = `\x3f` - assert byte(a) == byte(63) + assert u8(a) == u8(63) a = `\x40` - assert byte(a) == byte(64) + assert u8(a) == u8(64) a = `\x41` - assert byte(a) == byte(65) + assert u8(a) == u8(65) a = `\x42` - assert byte(a) == byte(66) + assert u8(a) == u8(66) a = `\x43` - assert byte(a) == byte(67) + assert u8(a) == u8(67) a = `\x44` - assert byte(a) == byte(68) + assert u8(a) == u8(68) a = `\x45` - assert byte(a) == byte(69) + assert u8(a) == u8(69) a = `\x46` - assert byte(a) == byte(70) + assert u8(a) == u8(70) a = `\x47` - assert byte(a) == byte(71) + assert u8(a) == u8(71) a = `\x48` - assert byte(a) == byte(72) + assert u8(a) == u8(72) a = `\x49` - assert byte(a) == byte(73) + assert u8(a) == u8(73) a = `\x4a` - assert byte(a) == byte(74) + assert u8(a) == u8(74) a = `\x4b` - assert byte(a) == byte(75) + assert u8(a) == u8(75) a = `\x4c` - assert byte(a) == byte(76) + assert u8(a) == u8(76) a = `\x4d` - assert byte(a) == byte(77) + assert u8(a) == u8(77) a = `\x4e` - assert byte(a) == byte(78) + assert u8(a) == u8(78) a = `\x4f` - assert byte(a) == byte(79) + assert u8(a) == u8(79) a = `\x50` - assert byte(a) == byte(80) + assert u8(a) == u8(80) a = `\x51` - assert byte(a) == byte(81) + assert u8(a) == u8(81) a = `\x52` - assert byte(a) == byte(82) + assert u8(a) == u8(82) a = `\x53` - assert byte(a) == byte(83) + assert u8(a) == u8(83) a = `\x54` - assert byte(a) == byte(84) + assert u8(a) == u8(84) a = `\x55` - assert byte(a) == byte(85) + assert u8(a) == u8(85) a = `\x56` - assert byte(a) == byte(86) + assert u8(a) == u8(86) a = `\x57` - assert byte(a) == byte(87) + assert u8(a) == u8(87) a = `\x58` - assert byte(a) == byte(88) + assert u8(a) == u8(88) a = `\x59` - assert byte(a) == byte(89) + assert u8(a) == u8(89) a = `\x5a` - assert byte(a) == byte(90) + assert u8(a) == u8(90) a = `\x5b` - assert byte(a) == byte(91) + assert u8(a) == u8(91) a = `\x5c` - assert byte(a) == byte(92) + assert u8(a) == u8(92) a = `\x5d` - assert byte(a) == byte(93) + assert u8(a) == u8(93) a = `\x5e` - assert byte(a) == byte(94) + assert u8(a) == u8(94) a = `\x5f` - assert byte(a) == byte(95) + assert u8(a) == u8(95) a = `\x60` - assert byte(a) == byte(96) + assert u8(a) == u8(96) a = `\x61` - assert byte(a) == byte(97) + assert u8(a) == u8(97) a = `\x62` - assert byte(a) == byte(98) + assert u8(a) == u8(98) a = `\x63` - assert byte(a) == byte(99) + assert u8(a) == u8(99) a = `\x64` - assert byte(a) == byte(100) + assert u8(a) == u8(100) a = `\x65` - assert byte(a) == byte(101) + assert u8(a) == u8(101) a = `\x66` - assert byte(a) == byte(102) + assert u8(a) == u8(102) a = `\x67` - assert byte(a) == byte(103) + assert u8(a) == u8(103) a = `\x68` - assert byte(a) == byte(104) + assert u8(a) == u8(104) a = `\x69` - assert byte(a) == byte(105) + assert u8(a) == u8(105) a = `\x6a` - assert byte(a) == byte(106) + assert u8(a) == u8(106) a = `\x6b` - assert byte(a) == byte(107) + assert u8(a) == u8(107) a = `\x6c` - assert byte(a) == byte(108) + assert u8(a) == u8(108) a = `\x6d` - assert byte(a) == byte(109) + assert u8(a) == u8(109) a = `\x6e` - assert byte(a) == byte(110) + assert u8(a) == u8(110) a = `\x6f` - assert byte(a) == byte(111) + assert u8(a) == u8(111) a = `\x70` - assert byte(a) == byte(112) + assert u8(a) == u8(112) a = `\x71` - assert byte(a) == byte(113) + assert u8(a) == u8(113) a = `\x72` - assert byte(a) == byte(114) + assert u8(a) == u8(114) a = `\x73` - assert byte(a) == byte(115) + assert u8(a) == u8(115) a = `\x74` - assert byte(a) == byte(116) + assert u8(a) == u8(116) a = `\x75` - assert byte(a) == byte(117) + assert u8(a) == u8(117) a = `\x76` - assert byte(a) == byte(118) + assert u8(a) == u8(118) a = `\x77` - assert byte(a) == byte(119) + assert u8(a) == u8(119) a = `\x78` - assert byte(a) == byte(120) + assert u8(a) == u8(120) a = `\x79` - assert byte(a) == byte(121) + assert u8(a) == u8(121) a = `\x7a` - assert byte(a) == byte(122) + assert u8(a) == u8(122) a = `\x7b` - assert byte(a) == byte(123) + assert u8(a) == u8(123) a = `\x7c` - assert byte(a) == byte(124) + assert u8(a) == u8(124) a = `\x7d` - assert byte(a) == byte(125) + assert u8(a) == u8(125) a = `\x7e` - assert byte(a) == byte(126) + assert u8(a) == u8(126) a = `\x7f` - assert byte(a) == byte(127) + assert u8(a) == u8(127) a = `\x80` - assert byte(a) == byte(128) + assert u8(a) == u8(128) a = `\x81` - assert byte(a) == byte(129) + assert u8(a) == u8(129) a = `\x82` - assert byte(a) == byte(130) + assert u8(a) == u8(130) a = `\x83` - assert byte(a) == byte(131) + assert u8(a) == u8(131) a = `\x84` - assert byte(a) == byte(132) + assert u8(a) == u8(132) a = `\x85` - assert byte(a) == byte(133) + assert u8(a) == u8(133) a = `\x86` - assert byte(a) == byte(134) + assert u8(a) == u8(134) a = `\x87` - assert byte(a) == byte(135) + assert u8(a) == u8(135) a = `\x88` - assert byte(a) == byte(136) + assert u8(a) == u8(136) a = `\x89` - assert byte(a) == byte(137) + assert u8(a) == u8(137) a = `\x8a` - assert byte(a) == byte(138) + assert u8(a) == u8(138) a = `\x8b` - assert byte(a) == byte(139) + assert u8(a) == u8(139) a = `\x8c` - assert byte(a) == byte(140) + assert u8(a) == u8(140) a = `\x8d` - assert byte(a) == byte(141) + assert u8(a) == u8(141) a = `\x8e` - assert byte(a) == byte(142) + assert u8(a) == u8(142) a = `\x8f` - assert byte(a) == byte(143) + assert u8(a) == u8(143) a = `\x90` - assert byte(a) == byte(144) + assert u8(a) == u8(144) a = `\x91` - assert byte(a) == byte(145) + assert u8(a) == u8(145) a = `\x92` - assert byte(a) == byte(146) + assert u8(a) == u8(146) a = `\x93` - assert byte(a) == byte(147) + assert u8(a) == u8(147) a = `\x94` - assert byte(a) == byte(148) + assert u8(a) == u8(148) a = `\x95` - assert byte(a) == byte(149) + assert u8(a) == u8(149) a = `\x96` - assert byte(a) == byte(150) + assert u8(a) == u8(150) a = `\x97` - assert byte(a) == byte(151) + assert u8(a) == u8(151) a = `\x98` - assert byte(a) == byte(152) + assert u8(a) == u8(152) a = `\x99` - assert byte(a) == byte(153) + assert u8(a) == u8(153) a = `\x9a` - assert byte(a) == byte(154) + assert u8(a) == u8(154) a = `\x9b` - assert byte(a) == byte(155) + assert u8(a) == u8(155) a = `\x9c` - assert byte(a) == byte(156) + assert u8(a) == u8(156) a = `\x9d` - assert byte(a) == byte(157) + assert u8(a) == u8(157) a = `\x9e` - assert byte(a) == byte(158) + assert u8(a) == u8(158) a = `\x9f` - assert byte(a) == byte(159) + assert u8(a) == u8(159) a = `\xa0` - assert byte(a) == byte(160) + assert u8(a) == u8(160) a = `\xa1` - assert byte(a) == byte(161) + assert u8(a) == u8(161) a = `\xa2` - assert byte(a) == byte(162) + assert u8(a) == u8(162) a = `\xa3` - assert byte(a) == byte(163) + assert u8(a) == u8(163) a = `\xa4` - assert byte(a) == byte(164) + assert u8(a) == u8(164) a = `\xa5` - assert byte(a) == byte(165) + assert u8(a) == u8(165) a = `\xa6` - assert byte(a) == byte(166) + assert u8(a) == u8(166) a = `\xa7` - assert byte(a) == byte(167) + assert u8(a) == u8(167) a = `\xa8` - assert byte(a) == byte(168) + assert u8(a) == u8(168) a = `\xa9` - assert byte(a) == byte(169) + assert u8(a) == u8(169) a = `\xaa` - assert byte(a) == byte(170) + assert u8(a) == u8(170) a = `\xab` - assert byte(a) == byte(171) + assert u8(a) == u8(171) a = `\xac` - assert byte(a) == byte(172) + assert u8(a) == u8(172) a = `\xad` - assert byte(a) == byte(173) + assert u8(a) == u8(173) a = `\xae` - assert byte(a) == byte(174) + assert u8(a) == u8(174) a = `\xaf` - assert byte(a) == byte(175) + assert u8(a) == u8(175) a = `\xb0` - assert byte(a) == byte(176) + assert u8(a) == u8(176) a = `\xb1` - assert byte(a) == byte(177) + assert u8(a) == u8(177) a = `\xb2` - assert byte(a) == byte(178) + assert u8(a) == u8(178) a = `\xb3` - assert byte(a) == byte(179) + assert u8(a) == u8(179) a = `\xb4` - assert byte(a) == byte(180) + assert u8(a) == u8(180) a = `\xb5` - assert byte(a) == byte(181) + assert u8(a) == u8(181) a = `\xb6` - assert byte(a) == byte(182) + assert u8(a) == u8(182) a = `\xb7` - assert byte(a) == byte(183) + assert u8(a) == u8(183) a = `\xb8` - assert byte(a) == byte(184) + assert u8(a) == u8(184) a = `\xb9` - assert byte(a) == byte(185) + assert u8(a) == u8(185) a = `\xba` - assert byte(a) == byte(186) + assert u8(a) == u8(186) a = `\xbb` - assert byte(a) == byte(187) + assert u8(a) == u8(187) a = `\xbc` - assert byte(a) == byte(188) + assert u8(a) == u8(188) a = `\xbd` - assert byte(a) == byte(189) + assert u8(a) == u8(189) a = `\xbe` - assert byte(a) == byte(190) + assert u8(a) == u8(190) a = `\xbf` - assert byte(a) == byte(191) + assert u8(a) == u8(191) a = `\xc0` - assert byte(a) == byte(192) + assert u8(a) == u8(192) a = `\xc1` - assert byte(a) == byte(193) + assert u8(a) == u8(193) a = `\xc2` - assert byte(a) == byte(194) + assert u8(a) == u8(194) a = `\xc3` - assert byte(a) == byte(195) + assert u8(a) == u8(195) a = `\xc4` - assert byte(a) == byte(196) + assert u8(a) == u8(196) a = `\xc5` - assert byte(a) == byte(197) + assert u8(a) == u8(197) a = `\xc6` - assert byte(a) == byte(198) + assert u8(a) == u8(198) a = `\xc7` - assert byte(a) == byte(199) + assert u8(a) == u8(199) a = `\xc8` - assert byte(a) == byte(200) + assert u8(a) == u8(200) a = `\xc9` - assert byte(a) == byte(201) + assert u8(a) == u8(201) a = `\xca` - assert byte(a) == byte(202) + assert u8(a) == u8(202) a = `\xcb` - assert byte(a) == byte(203) + assert u8(a) == u8(203) a = `\xcc` - assert byte(a) == byte(204) + assert u8(a) == u8(204) a = `\xcd` - assert byte(a) == byte(205) + assert u8(a) == u8(205) a = `\xce` - assert byte(a) == byte(206) + assert u8(a) == u8(206) a = `\xcf` - assert byte(a) == byte(207) + assert u8(a) == u8(207) a = `\xd0` - assert byte(a) == byte(208) + assert u8(a) == u8(208) a = `\xd1` - assert byte(a) == byte(209) + assert u8(a) == u8(209) a = `\xd2` - assert byte(a) == byte(210) + assert u8(a) == u8(210) a = `\xd3` - assert byte(a) == byte(211) + assert u8(a) == u8(211) a = `\xd4` - assert byte(a) == byte(212) + assert u8(a) == u8(212) a = `\xd5` - assert byte(a) == byte(213) + assert u8(a) == u8(213) a = `\xd6` - assert byte(a) == byte(214) + assert u8(a) == u8(214) a = `\xd7` - assert byte(a) == byte(215) + assert u8(a) == u8(215) a = `\xd8` - assert byte(a) == byte(216) + assert u8(a) == u8(216) a = `\xd9` - assert byte(a) == byte(217) + assert u8(a) == u8(217) a = `\xda` - assert byte(a) == byte(218) + assert u8(a) == u8(218) a = `\xdb` - assert byte(a) == byte(219) + assert u8(a) == u8(219) a = `\xdc` - assert byte(a) == byte(220) + assert u8(a) == u8(220) a = `\xdd` - assert byte(a) == byte(221) + assert u8(a) == u8(221) a = `\xde` - assert byte(a) == byte(222) + assert u8(a) == u8(222) a = `\xdf` - assert byte(a) == byte(223) + assert u8(a) == u8(223) a = `\xe0` - assert byte(a) == byte(224) + assert u8(a) == u8(224) a = `\xe1` - assert byte(a) == byte(225) + assert u8(a) == u8(225) a = `\xe2` - assert byte(a) == byte(226) + assert u8(a) == u8(226) a = `\xe3` - assert byte(a) == byte(227) + assert u8(a) == u8(227) a = `\xe4` - assert byte(a) == byte(228) + assert u8(a) == u8(228) a = `\xe5` - assert byte(a) == byte(229) + assert u8(a) == u8(229) a = `\xe6` - assert byte(a) == byte(230) + assert u8(a) == u8(230) a = `\xe7` - assert byte(a) == byte(231) + assert u8(a) == u8(231) a = `\xe8` - assert byte(a) == byte(232) + assert u8(a) == u8(232) a = `\xe9` - assert byte(a) == byte(233) + assert u8(a) == u8(233) a = `\xea` - assert byte(a) == byte(234) + assert u8(a) == u8(234) a = `\xeb` - assert byte(a) == byte(235) + assert u8(a) == u8(235) a = `\xec` - assert byte(a) == byte(236) + assert u8(a) == u8(236) a = `\xed` - assert byte(a) == byte(237) + assert u8(a) == u8(237) a = `\xee` - assert byte(a) == byte(238) + assert u8(a) == u8(238) a = `\xef` - assert byte(a) == byte(239) + assert u8(a) == u8(239) a = `\xf0` - assert byte(a) == byte(240) + assert u8(a) == u8(240) a = `\xf1` - assert byte(a) == byte(241) + assert u8(a) == u8(241) a = `\xf2` - assert byte(a) == byte(242) + assert u8(a) == u8(242) a = `\xf3` - assert byte(a) == byte(243) + assert u8(a) == u8(243) a = `\xf4` - assert byte(a) == byte(244) + assert u8(a) == u8(244) a = `\xf5` - assert byte(a) == byte(245) + assert u8(a) == u8(245) a = `\xf6` - assert byte(a) == byte(246) + assert u8(a) == u8(246) a = `\xf7` - assert byte(a) == byte(247) + assert u8(a) == u8(247) a = `\xf8` - assert byte(a) == byte(248) + assert u8(a) == u8(248) a = `\xf9` - assert byte(a) == byte(249) + assert u8(a) == u8(249) a = `\xfa` - assert byte(a) == byte(250) + assert u8(a) == u8(250) a = `\xfb` - assert byte(a) == byte(251) + assert u8(a) == u8(251) a = `\xfc` - assert byte(a) == byte(252) + assert u8(a) == u8(252) a = `\xfd` - assert byte(a) == byte(253) + assert u8(a) == u8(253) a = `\xfe` - assert byte(a) == byte(254) + assert u8(a) == u8(254) a = `\xff` - assert byte(a) == byte(255) + assert u8(a) == u8(255) } diff --git a/vlib/v/tests/comptime_if_is_test.v b/vlib/v/tests/comptime_if_is_test.v index bba4936db2..c8fbabc913 100644 --- a/vlib/v/tests/comptime_if_is_test.v +++ b/vlib/v/tests/comptime_if_is_test.v @@ -22,7 +22,7 @@ fn g(t T) int { } fn test_is_or() { - assert g(byte(1)) == 1 + assert g(u8(1)) == 1 assert g(i8(1)) == 1 assert g(1) == 2 } diff --git a/vlib/v/tests/const_comptime_eval_before_vinit_test.v b/vlib/v/tests/const_comptime_eval_before_vinit_test.v index 08bd30c0f3..c9bff8efcb 100644 --- a/vlib/v/tests/const_comptime_eval_before_vinit_test.v +++ b/vlib/v/tests/const_comptime_eval_before_vinit_test.v @@ -9,7 +9,7 @@ const zzz_an_int_const = int(89) const zzz_an_i64_const = i64(123) // -const zzz_an_byte_const = byte(0x4b) +const zzz_an_byte_const = u8(0x4b) const zzz_an_u16_const = u16(0x53) @@ -31,7 +31,7 @@ const zzz_an_int_const_1 = zzz_an_int_const + int(1) const zzz_an_i64_const_1 = zzz_an_i64_const + i64(1) // -const zzz_an_byte_const_1 = zzz_an_byte_const + byte(1) +const zzz_an_byte_const_1 = zzz_an_byte_const + u8(1) const zzz_an_u16_const_1 = zzz_an_u16_const + u16(1) @@ -64,7 +64,7 @@ fn static_storage(idx int, value int) byte { return storage[idx] } prev := storage[idx] - storage[idx] = byte(value) + storage[idx] = u8(value) return prev } @@ -104,34 +104,34 @@ fn pre_main() { fn do_check() { unsafe { - assert static_storage(0, -1) == byte(zzz_an_i8_const) - assert static_storage(1, -1) == byte(zzz_an_i16_const) - assert static_storage(2, -1) == byte(zzz_an_int_const) + assert static_storage(0, -1) == u8(zzz_an_i8_const) + assert static_storage(1, -1) == u8(zzz_an_i16_const) + assert static_storage(2, -1) == u8(zzz_an_int_const) // TODO: this should also be initialised, but is not for now, // since V has problems with `-9223372036854775808.str()`, // The generating code for i64 consts is present, but is disabled // for now, so they are still computed/assigned in the _vinit // function at runtime. - // assert static_storage(3, -1) == byte(zzz_an_i64_const) + // assert static_storage(3, -1) == u8(zzz_an_i64_const) // - assert static_storage(4, -1) == byte(zzz_an_byte_const) - assert static_storage(5, -1) == byte(zzz_an_u16_const) - assert static_storage(6, -1) == byte(zzz_an_u32_const) - assert static_storage(7, -1) == byte(zzz_an_u64_const) + assert static_storage(4, -1) == u8(zzz_an_byte_const) + assert static_storage(5, -1) == u8(zzz_an_u16_const) + assert static_storage(6, -1) == u8(zzz_an_u32_const) + assert static_storage(7, -1) == u8(zzz_an_u64_const) // TODO: ensure these work too: - // assert static_storage(8, -1) == byte(zzz_an_f32_const) - // assert static_storage(9, -1) == byte(zzz_an_f64_const) + // assert static_storage(8, -1) == u8(zzz_an_f32_const) + // assert static_storage(9, -1) == u8(zzz_an_f64_const) // - // assert static_storage(20, -1) == byte(zzz_an_i8_const_1) - // assert static_storage(21, -1) == byte(zzz_an_i16_const_1) - // assert static_storage(22, -1) == byte(zzz_an_int_const_1) - // assert static_storage(23, -1) == byte(zzz_an_i64_const_1) - assert static_storage(24, -1) == byte(zzz_an_byte_const_1) - // assert static_storage(25, -1) == byte(zzz_an_u16_const_1) - // assert static_storage(26, -1) == byte(zzz_an_u32_const_1) - assert static_storage(27, -1) == byte(zzz_an_u64_const_1) - // assert static_storage(28, -1) == byte(zzz_an_f32_const_1) - // assert static_storage(29, -1) == byte(zzz_an_f64_const_1) + // assert static_storage(20, -1) == u8(zzz_an_i8_const_1) + // assert static_storage(21, -1) == u8(zzz_an_i16_const_1) + // assert static_storage(22, -1) == u8(zzz_an_int_const_1) + // assert static_storage(23, -1) == u8(zzz_an_i64_const_1) + assert static_storage(24, -1) == u8(zzz_an_byte_const_1) + // assert static_storage(25, -1) == u8(zzz_an_u16_const_1) + // assert static_storage(26, -1) == u8(zzz_an_u32_const_1) + assert static_storage(27, -1) == u8(zzz_an_u64_const_1) + // assert static_storage(28, -1) == u8(zzz_an_f32_const_1) + // assert static_storage(29, -1) == u8(zzz_an_f64_const_1) } } diff --git a/vlib/v/tests/const_init_order_test.v b/vlib/v/tests/const_init_order_test.v index f0e47cfbc3..9449680d69 100644 --- a/vlib/v/tests/const_init_order_test.v +++ b/vlib/v/tests/const_init_order_test.v @@ -1,7 +1,7 @@ import rand const ( - my_random_letter_const = byte(65) + (rand.byte() % 26) + my_random_letter_const = u8(65) + (rand.u8() % 26) ) fn test_rand_is_initialized_before_main() { diff --git a/vlib/v/tests/const_representation_test.v b/vlib/v/tests/const_representation_test.v index d1f8435e03..e055191b7a 100644 --- a/vlib/v/tests/const_representation_test.v +++ b/vlib/v/tests/const_representation_test.v @@ -1,4 +1,4 @@ -const zzz_byte_a = byte(`A`) +const zzz_byte_a = u8(`A`) const zzz_u16_a = u16(999) + 5 diff --git a/vlib/v/tests/fixed_array_const_size_test.v b/vlib/v/tests/fixed_array_const_size_test.v index 36e16a7095..b2c37a414b 100644 --- a/vlib/v/tests/fixed_array_const_size_test.v +++ b/vlib/v/tests/fixed_array_const_size_test.v @@ -11,7 +11,7 @@ fn test_fixed_array_const_size() { a := Foo{} println(a) assert a == Foo{ - bar: [byte(0), 0, 0, 0, 0]! + bar: [u8(0), 0, 0, 0, 0]! } } diff --git a/vlib/v/tests/fixed_array_init_test.v b/vlib/v/tests/fixed_array_init_test.v index 2cb27106a2..2f28fec47a 100644 --- a/vlib/v/tests/fixed_array_init_test.v +++ b/vlib/v/tests/fixed_array_init_test.v @@ -39,7 +39,7 @@ fn test_fixed_type_init() { fn test_fixed_custom_init() { a := [2]byte{init: 7} - assert a == [byte(7), 7]! + assert a == [u8(7), 7]! mut b := [3]int{} assert b == [0, 0, 0]! // assign diff --git a/vlib/v/tests/for_t_fields_with_comptime_if_test.v b/vlib/v/tests/for_t_fields_with_comptime_if_test.v index dead6c474b..79c7bd6d83 100644 --- a/vlib/v/tests/for_t_fields_with_comptime_if_test.v +++ b/vlib/v/tests/for_t_fields_with_comptime_if_test.v @@ -36,7 +36,7 @@ fn decode2() T { mut x := T{} $for field in T.fields { $if field.typ is byte { - x.$(field.name) = byte(-1) + x.$(field.name) = u8(-1) } $else $if field.typ is int { x.$(field.name) = int(-1) } $else $if field.typ is string { diff --git a/vlib/v/tests/generics_struct_parent_has_str_to_string_test.v b/vlib/v/tests/generics_struct_parent_has_str_to_string_test.v index c7ec228670..c815a769a5 100644 --- a/vlib/v/tests/generics_struct_parent_has_str_to_string_test.v +++ b/vlib/v/tests/generics_struct_parent_has_str_to_string_test.v @@ -24,7 +24,7 @@ struct Pattern { } fn new_pattern(pattern string, handler fn (mut m Vm)) Pattern { - return Pattern{pattern.runes().map(byte('0x$it'.int())), handler} + return Pattern{pattern.runes().map(u8('0x$it'.int())), handler} } fn test_generics_struct_parent_has_str_to_string() { diff --git a/vlib/v/tests/generics_test.v b/vlib/v/tests/generics_test.v index f738de3e92..bf07dfd1df 100644 --- a/vlib/v/tests/generics_test.v +++ b/vlib/v/tests/generics_test.v @@ -51,7 +51,7 @@ fn minus_one(a T) T { fn test_postfix_expr() { assert plus_one(-1) == 0 - assert plus_one(byte(0)) == 1 + assert plus_one(u8(0)) == 1 assert plus_one(u16(1)) == 2 assert plus_one(u32(2)) == 3 assert plus_one(u64(3)) == 4 @@ -60,7 +60,7 @@ fn test_postfix_expr() { assert plus_one(int(-8)) == -7 assert plus_one(i64(-7)) == -6 assert minus_one(0) == -1 - assert minus_one(byte(1)) == 0 + assert minus_one(u8(1)) == 0 assert minus_one(u16(2)) == 1 assert minus_one(u32(3)) == 2 assert minus_one(u64(4)) == 3 @@ -108,7 +108,7 @@ fn test_generic_variadic() { assert max('krkr', 1, 2, 3, 4) == 4 a := [f64(1.2), 3.2, 0.1, 2.2] assert max('krkr', ...a) == 3.2 - assert max('krkr', ...[byte(4), 3, 2, 1]) == 4 + assert max('krkr', ...[u8(4), 3, 2, 1]) == 4 } fn create() { diff --git a/vlib/v/tests/generics_with_nested_generics_fn_inst_call_test.v b/vlib/v/tests/generics_with_nested_generics_fn_inst_call_test.v index 16f66e4b75..728987e44d 100644 --- a/vlib/v/tests/generics_with_nested_generics_fn_inst_call_test.v +++ b/vlib/v/tests/generics_with_nested_generics_fn_inst_call_test.v @@ -1,5 +1,5 @@ fn test_generics_with_nested_generic_fn_inst_call() { - value := [byte(105), 116, 32, 119, 111, 114, 107, 115, 33, 33] + value := [u8(105), 116, 32, 119, 111, 114, 107, 115, 33, 33] decoded := decode_arr(value) dump(decoded) assert decoded.len == 4 diff --git a/vlib/v/tests/in_expression_test.v b/vlib/v/tests/in_expression_test.v index 23a54b3ec7..34a9a5c37f 100644 --- a/vlib/v/tests/in_expression_test.v +++ b/vlib/v/tests/in_expression_test.v @@ -233,7 +233,7 @@ fn test_in_array_init() { } fn test_in_expression_numeric() { - b := [byte(2), 4, 7] + b := [u8(2), 4, 7] b2 := [i8(3), -4, 9] s := [u16(6), 1, 0] s2 := [i16(34), -17, 45] @@ -243,7 +243,7 @@ fn test_in_expression_numeric() { l2 := [i64(-45), 8, 2] f := [f32(12.5), 0, -17.25] f2 := [1.0625, 3, 17.125] - assert byte(4) in b + assert u8(4) in b assert 3 !in b assert -4 in b2 assert i8(5) !in b2 diff --git a/vlib/v/tests/int_cmp_test.v b/vlib/v/tests/int_cmp_test.v index 3032f43bd7..0da94f6e4c 100644 --- a/vlib/v/tests/int_cmp_test.v +++ b/vlib/v/tests/int_cmp_test.v @@ -6,14 +6,14 @@ fn test_cmp_signed() { } fn test_cmp_unsigned() { - assert byte(3) < u16(10) + assert u8(3) < u16(10) assert u16(40000) > u32(200) - assert u64(18161419857654944321) >= byte(12) + assert u64(18161419857654944321) >= u8(12) assert u64(40000) < u16(40001) } fn test_cmp_unsigned_signed() { - assert byte(12) > i8(-12) + assert u8(12) > i8(-12) assert i16(-27) < u32(65463356) assert u32(8543) > int(-7523) assert i64(-89) <= u64(567) diff --git a/vlib/v/tests/multiret_with_ptrtype_test.v b/vlib/v/tests/multiret_with_ptrtype_test.v index e1699970e1..06129cd6fb 100644 --- a/vlib/v/tests/multiret_with_ptrtype_test.v +++ b/vlib/v/tests/multiret_with_ptrtype_test.v @@ -3,7 +3,7 @@ fn multi_voidptr_ret() (voidptr, bool) { } fn multi_byteptr_ret() (&byte, bool) { - return &byte(0), true + return &u8(0), true } fn test_multi_ptrtype_ret() { diff --git a/vlib/v/tests/offsetof_test.v b/vlib/v/tests/offsetof_test.v index f03aa2eefa..555c6cb2a8 100644 --- a/vlib/v/tests/offsetof_test.v +++ b/vlib/v/tests/offsetof_test.v @@ -15,17 +15,17 @@ fn test_offsetof() { age: 2147483647 } unsafe { - assert *(&string(&byte(&cat) + __offsetof(Cat, name))) == 'Cthulhu' - assert *(&string(&byte(&cat) + __offsetof(Cat, breed))) == 'Great Old One' - assert *(&int(&byte(&cat) + __offsetof(Cat, age))) == 2147483647 + assert *(&string(&u8(&cat) + __offsetof(Cat, name))) == 'Cthulhu' + assert *(&string(&u8(&cat) + __offsetof(Cat, breed))) == 'Great Old One' + assert *(&int(&u8(&cat) + __offsetof(Cat, age))) == 2147483647 } } fn test_offsetof_struct_from_another_module() { num := complex.Complex{1.0, 1.0} unsafe { - assert *(&f64(&byte(&num) + __offsetof(complex.Complex, re))) == 1.0 - assert *(&f64(&byte(&num) + __offsetof(complex.Complex, im))) == 1.0 + assert *(&f64(&u8(&num) + __offsetof(complex.Complex, re))) == 1.0 + assert *(&f64(&u8(&num) + __offsetof(complex.Complex, im))) == 1.0 } } @@ -36,8 +36,8 @@ fn test_offsetof_alias() { age: 2147483647 } unsafe { - assert *(&string(&byte(&fel) + __offsetof(Feline, name))) == 'Cthulhu' - assert *(&string(&byte(&fel) + __offsetof(Feline, breed))) == 'Great Old One' - assert *(&int(&byte(&fel) + __offsetof(Feline, age))) == 2147483647 + assert *(&string(&u8(&fel) + __offsetof(Feline, name))) == 'Cthulhu' + assert *(&string(&u8(&fel) + __offsetof(Feline, breed))) == 'Great Old One' + assert *(&int(&u8(&fel) + __offsetof(Feline, age))) == 2147483647 } } diff --git a/vlib/v/tests/pointers_multilevel_casts_test.v b/vlib/v/tests/pointers_multilevel_casts_test.v index e7a658053e..aff9ef32f3 100644 --- a/vlib/v/tests/pointers_multilevel_casts_test.v +++ b/vlib/v/tests/pointers_multilevel_casts_test.v @@ -5,10 +5,10 @@ struct Struct { fn test_byte_pointer_casts() { unsafe { - pb := &byte(1) - ppb := &&byte(2) - pppb := &&&byte(3) - ppppb := &&&&byte(4) + pb := &u8(1) + ppb := &&u8(2) + pppb := &&&u8(3) + ppppb := &&&&u8(4) assert voidptr(pb).str() == '0x1' assert voidptr(ppb).str() == '0x2' assert voidptr(pppb).str() == '0x3' diff --git a/vlib/v/tests/ptr_arithmetic_test.v b/vlib/v/tests/ptr_arithmetic_test.v index dcb681b5c6..92072c561c 100644 --- a/vlib/v/tests/ptr_arithmetic_test.v +++ b/vlib/v/tests/ptr_arithmetic_test.v @@ -20,20 +20,20 @@ fn test_ptr_arithmetic() { fn test_ptr_arithmetic_over_byteptr() { // byteptr, voidptr, charptr are handled differently - mut q := &byte(10) + mut q := &u8(10) unsafe { q -= 2 q = q + 1 } - assert u64(q) == u64(&byte(9)) + assert u64(q) == u64(&u8(9)) s := unsafe { q - 1 } - assert u64(s) == u64(&byte(8)) + assert u64(s) == u64(&u8(8)) unsafe { q++ q++ q-- } - assert u64(q) == u64(&byte(10)) + assert u64(q) == u64(&u8(10)) } struct Abc { diff --git a/vlib/v/tests/shift_test.v b/vlib/v/tests/shift_test.v index 0a8997d46b..e3480bd5fc 100644 --- a/vlib/v/tests/shift_test.v +++ b/vlib/v/tests/shift_test.v @@ -7,7 +7,7 @@ fn test_shift_operators() { b := 1024 i := 10 assert b == a << i8(i) - assert b == a << byte(i) + assert b == a << u8(i) assert b == a << i16(i) assert b == a << u16(i) assert b == a << int(i) @@ -15,7 +15,7 @@ fn test_shift_operators() { assert b == a << i64(i) assert b == a << u64(i) assert a == b >> i8(i) - assert a == b >> byte(i) + assert a == b >> u8(i) assert a == b >> i16(i) assert a == b >> u16(i) assert a == b >> int(i) @@ -48,9 +48,9 @@ fn test_shift_operators() { assert e2 == b e2 >>= i64(i) assert e2 == a - e <<= byte(i) + e <<= u8(i) assert e == b - e >>= byte(i) + e >>= u8(i) assert e == a e <<= u16(i) assert e == b diff --git a/vlib/v/tests/string_interpolation_test.v b/vlib/v/tests/string_interpolation_test.v index 528b15b204..d68d8bc05e 100644 --- a/vlib/v/tests/string_interpolation_test.v +++ b/vlib/v/tests/string_interpolation_test.v @@ -87,18 +87,18 @@ fn test_interpolation_string_prefix_expr() { fn test_inttypes_string_interpolation() { c := i8(-103) // -0x67 - uc := byte(217) // 0xD9 - uc2 := byte(13) // 0x0D + uc := u8(217) // 0xD9 + uc2 := u8(13) // 0x0D s := i16(-23456) // -0x5BA0 us := u16(54321) // 0xD431 i := -1622999040 // -0x60BD 0000 ui := u32(3421958087) // 0xCBF6 EFC7 vp := voidptr(ui) - mut bp := &byte(0) + mut bp := &u8(0) $if x64 { - bp = &byte(15541149836) // 0x3 9E53 208C + bp = &u8(15541149836) // 0x3 9E53 208C } $else { - bp = &byte(3541149836) // 0xD311 A88C + bp = &u8(3541149836) // 0xD311 A88C } l := i64(-7694555558525237396) ul := u64(17234006112912956370) diff --git a/vlib/v/tests/strings_unicode_test.v b/vlib/v/tests/strings_unicode_test.v index 2333069e57..c3b4b31ff3 100644 --- a/vlib/v/tests/strings_unicode_test.v +++ b/vlib/v/tests/strings_unicode_test.v @@ -6,5 +6,5 @@ fn test_escape() { assert '\x20' == ' ' assert '\u0020' == ' ' assert '\u00c4' == 'Ä' - assert '\r\n'.bytes() == [byte(0x0d), 0x0a] + assert '\r\n'.bytes() == [u8(0x0d), 0x0a] } diff --git a/vlib/v/tests/struct_fields_storing_functions_test.v b/vlib/v/tests/struct_fields_storing_functions_test.v index 5687bad582..d4f03a52e9 100644 --- a/vlib/v/tests/struct_fields_storing_functions_test.v +++ b/vlib/v/tests/struct_fields_storing_functions_test.v @@ -14,7 +14,7 @@ mut: } fn test_struct_fn_field_can_be_used_directly() { - buf := [byte(1), 2, 3] + buf := [u8(1), 2, 3] mut res := []byte{} res << 0x88 async_cb(buf[0..2], mut res) @@ -25,5 +25,5 @@ fn test_struct_fn_field_can_be_used_directly() { data.cb(buf[1..2], mut res) res << 0x99 eprintln(res) - assert res == [byte(0x88), 0x01, 0x02, 0x02, 0x99] + assert res == [u8(0x88), 0x01, 0x02, 0x02, 0x99] } diff --git a/vlib/v/tests/type_voidptr_test.v b/vlib/v/tests/type_voidptr_test.v index 8fc8254cae..e15c6c9721 100644 --- a/vlib/v/tests/type_voidptr_test.v +++ b/vlib/v/tests/type_voidptr_test.v @@ -1,7 +1,7 @@ [unsafe] fn memcpy(mut dest voidptr, src voidptr, len u32) voidptr { - mut d := unsafe { &byte(dest) } - s := unsafe { &byte(src) } + mut d := unsafe { &u8(dest) } + s := unsafe { &u8(src) } mut l := len for l > 0 { l-- diff --git a/vlib/v/tests/typeof_simple_types_test.v b/vlib/v/tests/typeof_simple_types_test.v index 1c0cc6e659..000daf9f1f 100644 --- a/vlib/v/tests/typeof_simple_types_test.v +++ b/vlib/v/tests/typeof_simple_types_test.v @@ -22,7 +22,7 @@ fn test_typeof_for_builtin_int_types() { assert typeof(int(1)).name == 'int' // assert typeof(1).name == 'int_literal' assert typeof(i64(1)).name == 'i64' - assert typeof(byte(1)).name == 'byte' + assert typeof(u8(1)).name == 'byte' assert typeof(u16(1)).name == 'u16' assert typeof(u32(1)).name == 'u32' assert typeof(u64(1)).name == 'u64' diff --git a/vlib/v/tests/typeof_test.v b/vlib/v/tests/typeof_test.v index 98fc8de52b..e717110ef9 100644 --- a/vlib/v/tests/typeof_test.v +++ b/vlib/v/tests/typeof_test.v @@ -128,7 +128,7 @@ fn myfn2() { } fn myfn3(i int, s string) byte { - return byte(0) + return u8(0) } fn myfn4() i8 { diff --git a/vlib/v/util/errors.v b/vlib/v/util/errors.v index 2f25e3de48..32b9401f99 100644 --- a/vlib/v/util/errors.v +++ b/vlib/v/util/errors.v @@ -150,7 +150,7 @@ pub fn source_file_context(kind string, filepath string, pos token.Pos) []string mut pointerline_builder := strings.new_builder(sline.len) for i := 0; i < start_column; { if sline[i].is_space() { - pointerline_builder.write_byte(sline[i]) + pointerline_builder.write_u8(sline[i]) i++ } else { char_len := utf8_char_len(sline[i]) diff --git a/vlib/v/util/quote.v b/vlib/v/util/quote.v index 3c0b4cb4c4..c77eaddea6 100644 --- a/vlib/v/util/quote.v +++ b/vlib/v/util/quote.v @@ -23,7 +23,7 @@ pub fn smart_quote(str string, raw bool) string { if len < 256 { mut is_pure := true for i := 0; i < len; i++ { - ch := byte(str[i]) + ch := u8(str[i]) if (ch >= 37 && ch <= 90) || (ch >= 95 && ch <= 126) || (ch in [` `, `!`, `#`, `[`, `]`]) { // safe punctuation + digits + big latin letters, @@ -43,9 +43,9 @@ pub fn smart_quote(str string, raw bool) string { // ensure there is enough space for the potential expansion of several \\ or \n mut result := strings.new_builder(len + 10) mut pos := -1 - mut last := byte(0) - mut current := byte(0) - mut next := byte(0) + mut last := u8(0) + mut current := u8(0) + mut next := u8(0) mut skip_next := false for { pos++ @@ -65,8 +65,8 @@ pub fn smart_quote(str string, raw bool) string { } if current == util.double_quote { current = 0 - result.write_byte(util.backslash) - result.write_byte(util.double_quote) + result.write_u8(util.backslash) + result.write_u8(util.double_quote) continue } if current == util.backslash { @@ -88,26 +88,26 @@ pub fn smart_quote(str string, raw bool) string { } if next in util.invalid_escapes { skip_next = true - result.write_byte(next) + result.write_u8(next) continue } // keep all valid escape sequences skip_next = true - result.write_byte(current) - result.write_byte(next) + result.write_u8(current) + result.write_u8(next) continue } } if current == util.backslash_n { // keep newlines in string current = 0 - result.write_byte(util.backslash) - result.write_byte(`n`) + result.write_u8(util.backslash) + result.write_u8(`n`) continue } if current == util.backslash_r && next == util.backslash_n { - result.write_byte(current) - result.write_byte(next) + result.write_u8(current) + result.write_u8(next) current = 0 skip_next = true continue @@ -115,20 +115,20 @@ pub fn smart_quote(str string, raw bool) string { if !raw { if current == `$` { if last == util.backslash { - result.write_byte(last) - result.write_byte(current) + result.write_u8(last) + result.write_u8(current) continue } } if current == util.backslash_r && next == util.backslash_n { // Windows style new line \r\n skip_next = true - result.write_byte(util.backslash) - result.write_byte(`n`) + result.write_u8(util.backslash) + result.write_u8(`n`) continue } } - result.write_byte(current) + result.write_u8(current) } return result.str() } diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 67a17f286e..cb9e42be7f 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -80,10 +80,10 @@ pub fn resolve_env_value(str string, check_for_presence bool) ?string { at := str.index(env_ident) or { return error('no "$env_ident' + '...\')" could be found in "$str".') } - mut ch := byte(`.`) + mut ch := u8(`.`) mut env_lit := '' for i := at + env_ident.len; i < str.len && ch != `)`; i++ { - ch = byte(str[i]) + ch = u8(str[i]) if ch.is_letter() || ch.is_digit() || ch == `_` { env_lit += ch.ascii_str() } else { diff --git a/vlib/x/json2/encoder.v b/vlib/x/json2/encoder.v index 20ae67ea6b..a1684822c6 100644 --- a/vlib/x/json2/encoder.v +++ b/vlib/x/json2/encoder.v @@ -22,17 +22,17 @@ const true_in_bytes = 'true'.bytes() const false_in_bytes = 'false'.bytes() -const zero_in_bytes = [byte(`0`)] +const zero_in_bytes = [u8(`0`)] -const comma_bytes = [byte(`,`)] +const comma_bytes = [u8(`,`)] -const colon_bytes = [byte(`:`)] +const colon_bytes = [u8(`:`)] -const space_bytes = [byte(` `)] +const space_bytes = [u8(` `)] -const unicode_escape_chars = [byte(`\\`), `u`] +const unicode_escape_chars = [u8(`\\`), `u`] -const quote_bytes = [byte(`"`)] +const quote_bytes = [u8(`"`)] const escaped_chars = [(r'\b').bytes(), (r'\f').bytes(), (r'\n').bytes(), (r'\r').bytes(), (r'\t').bytes()] @@ -78,7 +78,7 @@ fn (e &Encoder) encode_value_with_level(f Any, level int, mut wr io.Writer) ? { wr.write(json2.zero_in_bytes) ? } map[string]Any { - wr.write([byte(`{`)]) ? + wr.write([u8(`{`)]) ? mut i := 0 for k, v in f { e.encode_newline(level, mut wr) ? @@ -94,10 +94,10 @@ fn (e &Encoder) encode_value_with_level(f Any, level int, mut wr io.Writer) ? { i++ } e.encode_newline(level - 1, mut wr) ? - wr.write([byte(`}`)]) ? + wr.write([u8(`}`)]) ? } []Any { - wr.write([byte(`[`)]) ? + wr.write([u8(`[`)]) ? for i, v in f { e.encode_newline(level, mut wr) ? e.encode_value_with_level(v, level + 1, mut wr) ? @@ -106,7 +106,7 @@ fn (e &Encoder) encode_value_with_level(f Any, level int, mut wr io.Writer) ? { } } e.encode_newline(level - 1, mut wr) ? - wr.write([byte(`]`)]) ? + wr.write([u8(`]`)]) ? } Null { wr.write(json2.null_in_bytes) ? @@ -180,7 +180,7 @@ fn (mut iter CharLengthIterator) next() ?int { mut len := 1 c := iter.text[iter.idx] if (c & (1 << 7)) != 0 { - for t := byte(1 << 6); (c & t) != 0; t >>= 1 { + for t := u8(1 << 6); (c & t) != 0; t >>= 1 { len++ iter.idx++ } @@ -207,7 +207,7 @@ fn (e &Encoder) encode_string(s string, mut wr io.Writer) ? { } } } else if chr == `"` || chr == `/` || chr == `\\` { - wr.write([byte(`\\`), chr]) ? + wr.write([u8(`\\`), chr]) ? } else if int(chr) < 0x20 { hex_code := chr.hex().bytes() wr.write(json2.unicode_escape_chars) ? // \u @@ -215,7 +215,7 @@ fn (e &Encoder) encode_string(s string, mut wr io.Writer) ? { wr.write(json2.zero_in_bytes) ? // \u00 wr.write(hex_code) ? // \u00xxxx } else { - wr.write([byte(chr)]) ? + wr.write([u8(chr)]) ? } } else { slice := s[i..i + char_len] diff --git a/vlib/x/json2/scanner.v b/vlib/x/json2/scanner.v index 8840fbf844..57d112db59 100644 --- a/vlib/x/json2/scanner.v +++ b/vlib/x/json2/scanner.v @@ -65,7 +65,7 @@ const ( 34: `"` 47: `/` } - exp_signs = [byte(`-`), `+`] + exp_signs = [u8(`-`), `+`] ) // move_pos proceeds to the next position. @@ -135,7 +135,7 @@ fn (mut s Scanner) text_scan() Token { } else if (s.pos - 1 >= 0 && s.text[s.pos - 1] != `\\`) && ch in json2.important_escapable_chars { return s.error('character must be escaped with a backslash') - } else if (s.pos == s.text.len - 1 && ch == `\\`) || ch == byte(0) { + } else if (s.pos == s.text.len - 1 && ch == `\\`) || ch == u8(0) { return s.error('invalid backslash escape') } else if s.pos + 1 < s.text.len && ch == `\\` { peek := s.text[s.pos + 1] @@ -179,7 +179,7 @@ fn (mut s Scanner) text_scan() Token { } } else if peek == `U` { return s.error('unicode endpoints must be in lowercase `u`') - } else if peek == byte(229) { + } else if peek == u8(229) { return s.error('unicode endpoint not allowed') } else { return s.error('invalid backslash escape') diff --git a/vlib/x/json2/scanner_test.v b/vlib/x/json2/scanner_test.v index 73f4d797d7..2ec512efff 100644 --- a/vlib/x/json2/scanner_test.v +++ b/vlib/x/json2/scanner_test.v @@ -42,7 +42,7 @@ fn test_str_invalid_escape() { fn test_str_invalid_must_be_escape() { for char in important_escapable_chars { mut sc := Scanner{ - text: [byte(`"`), `t`, char, `"`] + text: [u8(`"`), `t`, char, `"`] } tok := sc.scan() assert tok.kind == .error diff --git a/vlib/x/ttf/common.v b/vlib/x/ttf/common.v index d83ac6dccf..aa0a5b0ec1 100644 --- a/vlib/x/ttf/common.v +++ b/vlib/x/ttf/common.v @@ -51,15 +51,15 @@ fn dprintln(txt string) { ******************************************************************************/ // transform the bitmap from one layer to color layers fn (mut bmp BitMap) format_texture() { - r := byte(bmp.color >> 24) - g := byte((bmp.color >> 16) & 0xFF) - b := byte((bmp.color >> 8) & 0xFF) - a := byte(bmp.color & 0xFF) + r := u8(bmp.color >> 24) + g := u8((bmp.color >> 16) & 0xFF) + b := u8((bmp.color >> 8) & 0xFF) + a := u8(bmp.color & 0xFF) - b_r := byte(bmp.bg_color >> 24) - b_g := byte((bmp.bg_color >> 16) & 0xFF) - b_b := byte((bmp.bg_color >> 8) & 0xFF) - b_a := byte(bmp.bg_color & 0xFF) + b_r := u8(bmp.bg_color >> 24) + b_g := u8((bmp.bg_color >> 16) & 0xFF) + b_b := u8((bmp.bg_color >> 8) & 0xFF) + b_a := u8(bmp.bg_color & 0xFF) // trasform buffer in a texture x := bmp.buf @@ -72,7 +72,7 @@ fn (mut bmp BitMap) format_texture() { x[i + 1] = g x[i + 2] = b // alpha - x[i + 3] = byte(u16(a * data) >> 8) + x[i + 3] = u8(u16(a * data) >> 8) } else { x[i + 0] = b_r x[i + 1] = b_g diff --git a/vlib/x/ttf/render_bmp.v b/vlib/x/ttf/render_bmp.v index 4539617ca2..7c2fabf702 100644 --- a/vlib/x/ttf/render_bmp.v +++ b/vlib/x/ttf/render_bmp.v @@ -195,12 +195,12 @@ pub fn (mut bmp BitMap) plot(x int, y int, c u32) bool { mut index := (x + y * bmp.width) * bmp.bp unsafe { // bmp.buf[index]=0xFF - bmp.buf[index] = byte(c & 0xFF) // write only the alpha + bmp.buf[index] = u8(c & 0xFF) // write only the alpha } /* for count in 0..(bmp.bp) { unsafe{ - bmp.buf[index + count] = byte((c >> (bmp.bp - count - 1) * 8) & 0x0000_00FF) + bmp.buf[index + count] = u8((c >> (bmp.bp - count - 1) * 8) & 0x0000_00FF) } } */ diff --git a/vlib/x/ttf/ttf.v b/vlib/x/ttf/ttf.v index 7f6e3fa177..4c6b69b77b 100644 --- a/vlib/x/ttf/ttf.v +++ b/vlib/x/ttf/ttf.v @@ -493,7 +493,7 @@ fn (mut tf TTF_File) read_compound_glyph(mut in_glyph Glyph) { fn (mut tf TTF_File) get_u8() byte { x := tf.buf[tf.pos] tf.pos++ - return byte(x) + return u8(x) } fn (mut tf TTF_File) get_i8() i8 { @@ -540,7 +540,7 @@ fn (mut tf TTF_File) get_fixed() f32 { fn (mut tf TTF_File) get_string(length int) string { tmp_pos := u64(tf.pos) tf.pos += u32(length) - return unsafe { tos(&byte(u64(tf.buf.data) + tmp_pos), length) } + return unsafe { tos(&u8(u64(tf.buf.data) + tmp_pos), length) } } fn (mut tf TTF_File) get_unicode_string(length int) string { @@ -552,12 +552,12 @@ fn (mut tf TTF_File) get_unicode_string(length int) string { c_len := ((0xe5000000 >> ((c >> 3) & 0x1e)) & 3) + 1 real_len += c_len if c_len == 1 { - tmp_txt.write_byte(byte(c & 0xff)) + tmp_txt.write_u8(u8(c & 0xff)) } else { - tmp_txt.write_byte(byte((c >> 8) & 0xff)) - tmp_txt.write_byte(byte(c & 0xff)) + tmp_txt.write_u8(u8((c >> 8) & 0xff)) + tmp_txt.write_u8(u8(c & 0xff)) } - // dprintln("c: ${c:c}|${ byte(c &0xff) :c} c_len: ${c_len} str_len: ${real_len} in_len: ${length}") + // dprintln("c: ${c:c}|${ u8(c &0xff) :c} c_len: ${c_len} str_len: ${real_len} in_len: ${length}") } tf.pos += u32(real_len) res_txt := tmp_txt.str() @@ -1056,7 +1056,7 @@ fn tst() { mut tf := TTF_File{} tf.buf = [ - byte(0xFF), /* 8 bit */ + u8(0xFF), /* 8 bit */ 0xF1, 0xF2, /* 16 bit */ 0x81, diff --git a/vlib/x/ttf/ttf_test.v b/vlib/x/ttf/ttf_test.v index e7fc003a2e..dc6be65bd2 100644 --- a/vlib/x/ttf/ttf_test.v +++ b/vlib/x/ttf/ttf_test.v @@ -228,7 +228,7 @@ fn get_raw_data(data string) []byte { } if c == 2 { - buf << byte(b) + buf << u8(b) b = 0 c = 0 }