all: byte => u8
parent
51c65e41fd
commit
7ecbca345f
|
@ -16,7 +16,7 @@ fn main() {
|
||||||
mut bgenerating := benchmark.start()
|
mut bgenerating := benchmark.start()
|
||||||
mut bytepile := []byte{}
|
mut bytepile := []byte{}
|
||||||
for _ in 0 .. sample_size * max_str_len {
|
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{}
|
mut str_lens := []int{}
|
||||||
for _ in 0 .. sample_size {
|
for _ in 0 .. sample_size {
|
||||||
|
@ -30,7 +30,7 @@ fn main() {
|
||||||
checksum = 0
|
checksum = 0
|
||||||
for len in str_lens {
|
for len in str_lens {
|
||||||
end_pos := start_pos + len
|
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)
|
1)
|
||||||
start_pos = end_pos
|
start_pos = end_pos
|
||||||
}
|
}
|
||||||
|
|
|
@ -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('compression_type', t.string_node(node.compression_type))
|
||||||
obj.add('is_compressed', t.bool_node(node.is_compressed))
|
obj.add('is_compressed', t.bool_node(node.is_compressed))
|
||||||
obj.add('len', t.number_node(node.len))
|
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
|
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('pluss', t.array_node_bool(node.pluss))
|
||||||
obj.add_terse('fills', t.array_node_bool(node.fills))
|
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('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_terse('need_fmts', t.array_node_bool(node.need_fmts))
|
||||||
obj.add('pos', t.pos(node.pos))
|
obj.add('pos', t.pos(node.pos))
|
||||||
return obj
|
return obj
|
||||||
|
@ -2209,7 +2209,7 @@ fn (t Tree) array_node_int(nodes []int) &Node {
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (t Tree) array_node_byte(nodes []byte) &Node {
|
fn (t Tree) array_node_u8(nodes []byte) &Node {
|
||||||
mut arr := new_array()
|
mut arr := new_array()
|
||||||
for node in nodes {
|
for node in nodes {
|
||||||
arr.add_item(t.number_node(node))
|
arr.add_item(t.number_node(node))
|
||||||
|
|
|
@ -51,7 +51,7 @@ fn (context Context) file2v(bname string, fbytes []byte, bn_max int) string {
|
||||||
bn_diff_len := bn_max - bname.len
|
bn_diff_len := bn_max - bname.len
|
||||||
sb.write_string('\t${bname}_len' + ' '.repeat(bn_diff_len - 4) + ' = $fbytes.len\n')
|
sb.write_string('\t${bname}_len' + ' '.repeat(bn_diff_len - 4) + ' = $fbytes.len\n')
|
||||||
fbyte := fbytes[0]
|
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)
|
sb.write_string(bnmae_line)
|
||||||
mut line_len := bnmae_line.len + 3
|
mut line_len := bnmae_line.len + 3
|
||||||
for i := 1; i < fbytes.len; i++ {
|
for i := 1; i < fbytes.len; i++ {
|
||||||
|
|
|
@ -370,7 +370,7 @@ fn html_highlight(code string, tb &ast.Table) string {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buf.write_byte(code[i])
|
buf.write_u8(code[i])
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ fn color_highlight(code string, tb &ast.Table) string {
|
||||||
tok = next_tok
|
tok = next_tok
|
||||||
next_tok = s.scan()
|
next_tok = s.scan()
|
||||||
} else {
|
} else {
|
||||||
buf.write_byte(code[i])
|
buf.write_u8(code[i])
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,9 +132,9 @@ fn (vd VDoc) write_plaintext_content(contents []doc.DocNode, mut pw strings.Buil
|
||||||
for ex in examples {
|
for ex in examples {
|
||||||
pw.write_string(' Example: ')
|
pw.write_string(' Example: ')
|
||||||
mut fex := ex
|
mut fex := ex
|
||||||
if ex.index_byte(`\n`) >= 0 {
|
if ex.index_u8(`\n`) >= 0 {
|
||||||
// multi-line example
|
// multi-line example
|
||||||
pw.write_byte(`\n`)
|
pw.write_u8(`\n`)
|
||||||
fex = indent(ex)
|
fex = indent(ex)
|
||||||
}
|
}
|
||||||
if cfg.is_color {
|
if cfg.is_color {
|
||||||
|
|
|
@ -25,7 +25,7 @@ fn on_frame(mut app App) {
|
||||||
for mut frame in app.frames {
|
for mut frame in app.frames {
|
||||||
for mut rocket in frame {
|
for mut rocket in frame {
|
||||||
if !rocket.exploded {
|
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)
|
rocket.draw(mut app.gg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import rand
|
||||||
|
|
||||||
pub fn random_color() gx.Color {
|
pub fn random_color() gx.Color {
|
||||||
return gx.Color{
|
return gx.Color{
|
||||||
r: rand.byte()
|
r: rand.u8()
|
||||||
g: rand.byte()
|
g: rand.u8()
|
||||||
b: rand.byte()
|
b: rand.u8()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
pub fn (mut particle Particle) tick(mut rocket Rocket, mut ctx gg.Context) {
|
||||||
particle.lifespan -= get_params().age_rate
|
particle.lifespan -= get_params().age_rate
|
||||||
particle.color.a = byte(particle.lifespan)
|
particle.color.a = u8(particle.lifespan)
|
||||||
|
|
||||||
if particle.lifespan <= 0 {
|
if particle.lifespan <= 0 {
|
||||||
rocket.dead = true
|
rocket.dead = true
|
||||||
|
|
|
@ -50,7 +50,7 @@ fn create_texture(w int, h int, buf &u8) gfx.Image {
|
||||||
// usage: .dynamic
|
// usage: .dynamic
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
label: &byte(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// commen if .dynamic is enabled
|
// commen if .dynamic is enabled
|
||||||
|
@ -352,23 +352,23 @@ fn my_init(mut app App) {
|
||||||
x := (i & 0xFF) >> 5 // 8 cell
|
x := (i & 0xFF) >> 5 // 8 cell
|
||||||
// upper left corner
|
// upper left corner
|
||||||
if x == 0 && y == 0 {
|
if x == 0 && y == 0 {
|
||||||
tmp_txt[i] = byte(0xFF)
|
tmp_txt[i] = u8(0xFF)
|
||||||
tmp_txt[i + 1] = byte(0)
|
tmp_txt[i + 1] = u8(0)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
}
|
}
|
||||||
// low right corner
|
// low right corner
|
||||||
else if x == 7 && y == 7 {
|
else if x == 7 && y == 7 {
|
||||||
tmp_txt[i] = byte(0)
|
tmp_txt[i] = u8(0)
|
||||||
tmp_txt[i + 1] = byte(0xFF)
|
tmp_txt[i + 1] = u8(0xFF)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
} else {
|
} else {
|
||||||
col := if ((x + y) & 1) == 1 { 0xFF } else { 0 }
|
col := if ((x + y) & 1) == 1 { 0xFF } else { 0 }
|
||||||
tmp_txt[i] = byte(col) // red
|
tmp_txt[i] = u8(col) // red
|
||||||
tmp_txt[i + 1] = byte(col) // green
|
tmp_txt[i + 1] = u8(col) // green
|
||||||
tmp_txt[i + 2] = byte(col) // blue
|
tmp_txt[i + 2] = u8(col) // blue
|
||||||
tmp_txt[i + 3] = byte(0xFF) // alpha
|
tmp_txt[i + 3] = u8(0xFF) // alpha
|
||||||
}
|
}
|
||||||
i += 4
|
i += 4
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ fn create_texture(w int, h int, buf &byte) gfx.Image {
|
||||||
// usage: .dynamic
|
// usage: .dynamic
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
label: &byte(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// comment if .dynamic is enabled
|
// comment if .dynamic is enabled
|
||||||
|
@ -524,23 +524,23 @@ fn my_init(mut app App) {
|
||||||
x := (i & 0xFF) >> 5 // 8 cell
|
x := (i & 0xFF) >> 5 // 8 cell
|
||||||
// upper left corner
|
// upper left corner
|
||||||
if x == 0 && y == 0 {
|
if x == 0 && y == 0 {
|
||||||
tmp_txt[i] = byte(0xFF)
|
tmp_txt[i] = u8(0xFF)
|
||||||
tmp_txt[i + 1] = byte(0)
|
tmp_txt[i + 1] = u8(0)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
}
|
}
|
||||||
// low right corner
|
// low right corner
|
||||||
else if x == 7 && y == 7 {
|
else if x == 7 && y == 7 {
|
||||||
tmp_txt[i + 0] = byte(0)
|
tmp_txt[i + 0] = u8(0)
|
||||||
tmp_txt[i + 1] = byte(0xFF)
|
tmp_txt[i + 1] = u8(0xFF)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
} else {
|
} else {
|
||||||
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
||||||
tmp_txt[i + 0] = byte(col) // red
|
tmp_txt[i + 0] = u8(col) // red
|
||||||
tmp_txt[i + 1] = byte(col) // green
|
tmp_txt[i + 1] = u8(col) // green
|
||||||
tmp_txt[i + 2] = byte(col) // blue
|
tmp_txt[i + 2] = u8(col) // blue
|
||||||
tmp_txt[i + 3] = byte(0xFF) // alpha
|
tmp_txt[i + 3] = u8(0xFF) // alpha
|
||||||
}
|
}
|
||||||
i += 4
|
i += 4
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ fn create_texture(w int, h int, buf &byte) gfx.Image {
|
||||||
// usage: .dynamic
|
// usage: .dynamic
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
label: &byte(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// comment if .dynamic is enabled
|
// comment if .dynamic is enabled
|
||||||
|
@ -342,23 +342,23 @@ fn my_init(mut app App) {
|
||||||
x := (i & 0xFF) >> 5 // 8 cell
|
x := (i & 0xFF) >> 5 // 8 cell
|
||||||
// upper left corner
|
// upper left corner
|
||||||
if x == 0 && y == 0 {
|
if x == 0 && y == 0 {
|
||||||
tmp_txt[i + 0] = byte(0xFF)
|
tmp_txt[i + 0] = u8(0xFF)
|
||||||
tmp_txt[i + 1] = byte(0)
|
tmp_txt[i + 1] = u8(0)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
}
|
}
|
||||||
// low right corner
|
// low right corner
|
||||||
else if x == 7 && y == 7 {
|
else if x == 7 && y == 7 {
|
||||||
tmp_txt[i + 0] = byte(0)
|
tmp_txt[i + 0] = u8(0)
|
||||||
tmp_txt[i + 1] = byte(0xFF)
|
tmp_txt[i + 1] = u8(0xFF)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
} else {
|
} else {
|
||||||
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
||||||
tmp_txt[i + 0] = byte(col) // red
|
tmp_txt[i + 0] = u8(col) // red
|
||||||
tmp_txt[i + 1] = byte(col) // green
|
tmp_txt[i + 1] = u8(col) // green
|
||||||
tmp_txt[i + 2] = byte(col) // blue
|
tmp_txt[i + 2] = u8(col) // blue
|
||||||
tmp_txt[i + 3] = byte(0xFF) // alpha
|
tmp_txt[i + 3] = u8(0xFF) // alpha
|
||||||
}
|
}
|
||||||
i += 4
|
i += 4
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ fn create_texture(w int, h int, buf byteptr) gfx.Image {
|
||||||
// usage: .dynamic
|
// usage: .dynamic
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
label: &byte(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// comment if .dynamic is enabled
|
// comment if .dynamic is enabled
|
||||||
|
@ -530,23 +530,23 @@ fn my_init(mut app App) {
|
||||||
x := (i & 0xFF) >> 5 // 8 cell
|
x := (i & 0xFF) >> 5 // 8 cell
|
||||||
// upper left corner
|
// upper left corner
|
||||||
if x == 0 && y == 0 {
|
if x == 0 && y == 0 {
|
||||||
tmp_txt[i + 0] = byte(0xFF)
|
tmp_txt[i + 0] = u8(0xFF)
|
||||||
tmp_txt[i + 1] = byte(0)
|
tmp_txt[i + 1] = u8(0)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
}
|
}
|
||||||
// low right corner
|
// low right corner
|
||||||
else if x == 7 && y == 7 {
|
else if x == 7 && y == 7 {
|
||||||
tmp_txt[i + 0] = byte(0)
|
tmp_txt[i + 0] = u8(0)
|
||||||
tmp_txt[i + 1] = byte(0xFF)
|
tmp_txt[i + 1] = u8(0xFF)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
} else {
|
} else {
|
||||||
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
||||||
tmp_txt[i + 0] = byte(col) // red
|
tmp_txt[i + 0] = u8(col) // red
|
||||||
tmp_txt[i + 1] = byte(col) // green
|
tmp_txt[i + 1] = u8(col) // green
|
||||||
tmp_txt[i + 2] = byte(col) // blue
|
tmp_txt[i + 2] = u8(col) // blue
|
||||||
tmp_txt[i + 3] = byte(0xFF) // alpha
|
tmp_txt[i + 3] = u8(0xFF) // alpha
|
||||||
}
|
}
|
||||||
i += 4
|
i += 4
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ fn create_texture(w int, h int, buf byteptr) gfx.Image{
|
||||||
//usage: .dynamic
|
//usage: .dynamic
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
label: &byte(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// comment if .dynamic is enabled
|
// comment if .dynamic is enabled
|
||||||
|
@ -406,23 +406,23 @@ fn my_init(mut app App) {
|
||||||
x := (i & 0xFF) >> 5 // 8 cell
|
x := (i & 0xFF) >> 5 // 8 cell
|
||||||
// upper left corner
|
// upper left corner
|
||||||
if x == 0 && y == 0 {
|
if x == 0 && y == 0 {
|
||||||
tmp_txt[i + 0] = byte(0xFF)
|
tmp_txt[i + 0] = u8(0xFF)
|
||||||
tmp_txt[i + 1] = byte(0)
|
tmp_txt[i + 1] = u8(0)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
}
|
}
|
||||||
// low right corner
|
// low right corner
|
||||||
else if x == 7 && y == 7 {
|
else if x == 7 && y == 7 {
|
||||||
tmp_txt[i + 0] = byte(0)
|
tmp_txt[i + 0] = u8(0)
|
||||||
tmp_txt[i + 1] = byte(0xFF)
|
tmp_txt[i + 1] = u8(0xFF)
|
||||||
tmp_txt[i + 2] = byte(0)
|
tmp_txt[i + 2] = u8(0)
|
||||||
tmp_txt[i + 3] = byte(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
} else {
|
} else {
|
||||||
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
||||||
tmp_txt[i + 0] = byte(col) // red
|
tmp_txt[i + 0] = u8(col) // red
|
||||||
tmp_txt[i + 1] = byte(col) // green
|
tmp_txt[i + 1] = u8(col) // green
|
||||||
tmp_txt[i + 2] = byte(col) // blue
|
tmp_txt[i + 2] = u8(col) // blue
|
||||||
tmp_txt[i + 3] = byte(0xFF) // alpha
|
tmp_txt[i + 3] = u8(0xFF) // alpha
|
||||||
}
|
}
|
||||||
i += 4
|
i += 4
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub fn create_texture(w int, h int, buf &byte) gfx.Image {
|
||||||
// usage: .dynamic
|
// usage: .dynamic
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
label: &byte(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// comment if .dynamic is enabled
|
// comment if .dynamic is enabled
|
||||||
|
|
|
@ -220,10 +220,10 @@ fn my_init(mut app App) {
|
||||||
// 1x1 pixel white, default texture
|
// 1x1 pixel white, default texture
|
||||||
unsafe {
|
unsafe {
|
||||||
tmp_txt := malloc(4)
|
tmp_txt := malloc(4)
|
||||||
tmp_txt[0] = byte(0xFF)
|
tmp_txt[0] = u8(0xFF)
|
||||||
tmp_txt[1] = byte(0xFF)
|
tmp_txt[1] = u8(0xFF)
|
||||||
tmp_txt[2] = byte(0xFF)
|
tmp_txt[2] = u8(0xFF)
|
||||||
tmp_txt[3] = byte(0xFF)
|
tmp_txt[3] = u8(0xFF)
|
||||||
app.texture = obj.create_texture(1, 1, tmp_txt)
|
app.texture = obj.create_texture(1, 1, tmp_txt)
|
||||||
free(tmp_txt)
|
free(tmp_txt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,10 +46,10 @@ pub fn (mut p Particle) update(dt f64) {
|
||||||
lt := p.life_time - (1000 * dt)
|
lt := p.life_time - (1000 * dt)
|
||||||
if lt > 0 {
|
if lt > 0 {
|
||||||
p.life_time = lt
|
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.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 // byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.g))
|
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 // byte(remap(p.life_time,0.0,p.life_time_init,0,p.color.b))
|
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 = byte(int(remap(p.life_time, 0.0, p.life_time_init, 0, 255))) - 10
|
p.color.a = u8(int(remap(p.life_time, 0.0, p.life_time_init, 0, 255))) - 10
|
||||||
} else {
|
} else {
|
||||||
p.life_time = 0
|
p.life_time = 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -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++ {
|
for ch := 0; ch < num_channels; ch++ {
|
||||||
idx := frame * num_channels + ch
|
idx := frame * num_channels + ch
|
||||||
unsafe {
|
unsafe {
|
||||||
a := f32(byte(y) - 127) / 255.0
|
a := f32(u8(y) - 127) / 255.0
|
||||||
soundbuffer[idx] = a
|
soundbuffer[idx] = a
|
||||||
acontext.frames[idx & 2047] = a
|
acontext.frames[idx & 2047] = a
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ fn graphics_frame(mut state AppState) {
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
fn (mut state AppState) bsample(idx int) byte {
|
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() {
|
fn (mut state AppState) draw() {
|
||||||
|
|
|
@ -120,14 +120,14 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
|
||||||
mut res := []f32{}
|
mut res := []f32{}
|
||||||
// eprintln('> read_wav_file_samples: $fpath -------------------------------------------------')
|
// eprintln('> read_wav_file_samples: $fpath -------------------------------------------------')
|
||||||
mut bytes := os.read_bytes(fpath) ?
|
mut bytes := os.read_bytes(fpath) ?
|
||||||
mut pbytes := &byte(bytes.data)
|
mut pbytes := &u8(bytes.data)
|
||||||
mut offset := u32(0)
|
mut offset := u32(0)
|
||||||
rh := unsafe { &RIFFHeader(pbytes) }
|
rh := unsafe { &RIFFHeader(pbytes) }
|
||||||
// eprintln('rh: $rh')
|
// 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`')
|
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')
|
return error('WAV should have `WAVE` form type')
|
||||||
}
|
}
|
||||||
if rh.file_size + 8 != bytes.len {
|
if rh.file_size + 8 != bytes.len {
|
||||||
|
@ -145,15 +145,15 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
|
||||||
// eprintln('ch: $ch')
|
// eprintln('ch: $ch')
|
||||||
// eprintln('p: $pbytes | offset: $offset | bytes.len: $bytes.len')
|
// 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
|
continue
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
if ch.chunk_type == [byte(`i`), `d`, `3`, ` `]! {
|
if ch.chunk_type == [u8(`i`), `d`, `3`, ` `]! {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
if ch.chunk_type == [byte(`f`), `m`, `t`, ` `]! {
|
if ch.chunk_type == [u8(`f`), `m`, `t`, ` `]! {
|
||||||
// eprintln('`fmt ` chunk')
|
// eprintln('`fmt ` chunk')
|
||||||
rf = unsafe { &RIFFFormat(&ch.chunk_data) }
|
rf = unsafe { &RIFFFormat(&ch.chunk_data) }
|
||||||
// eprintln('fmt riff format: $rf')
|
// eprintln('fmt riff format: $rf')
|
||||||
|
@ -169,20 +169,20 @@ fn read_wav_file_samples(fpath string) ?[]f32 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
if ch.chunk_type == [byte(`d`), `a`, `t`, `a`]! {
|
if ch.chunk_type == [u8(`d`), `a`, `t`, `a`]! {
|
||||||
if rf == 0 {
|
if rf == 0 {
|
||||||
return error('`data` chunk should be after `fmt ` chunk')
|
return error('`data` chunk should be after `fmt ` chunk')
|
||||||
}
|
}
|
||||||
// eprintln('`fmt ` chunk: $rf\n`data` chunk: $ch')
|
// eprintln('`fmt ` chunk: $rf\n`data` chunk: $ch')
|
||||||
mut doffset := 0
|
mut doffset := 0
|
||||||
mut dp := unsafe { &byte(&ch.chunk_data) }
|
mut dp := unsafe { &u8(&ch.chunk_data) }
|
||||||
for doffset < ch.chunk_size {
|
for doffset < ch.chunk_size {
|
||||||
for c := 0; c < rf.nchannels; c++ {
|
for c := 0; c < rf.nchannels; c++ {
|
||||||
mut x := f32(0.0)
|
mut x := f32(0.0)
|
||||||
mut step := 0
|
mut step := 0
|
||||||
ppos := unsafe { dp + doffset }
|
ppos := unsafe { dp + doffset }
|
||||||
if rf.bits_per_sample == 8 {
|
if rf.bits_per_sample == 8 {
|
||||||
d8 := unsafe { &byte(ppos) }
|
d8 := unsafe { &u8(ppos) }
|
||||||
x = (f32(*d8) - 128) / 128.0
|
x = (f32(*d8) - 128) / 128.0
|
||||||
step = 1
|
step = 1
|
||||||
doffset++
|
doffset++
|
||||||
|
|
|
@ -21,9 +21,9 @@ mut:
|
||||||
|
|
||||||
fn random_color() tui.Color {
|
fn random_color() tui.Color {
|
||||||
return tui.Color{
|
return tui.Color{
|
||||||
r: rand.byte()
|
r: rand.u8()
|
||||||
g: rand.byte()
|
g: rand.u8()
|
||||||
b: rand.byte()
|
b: rand.u8()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ fn create_texture(w int, h int, buf &u8) gfx.Image {
|
||||||
// usage: .dynamic
|
// usage: .dynamic
|
||||||
wrap_u: .clamp_to_edge
|
wrap_u: .clamp_to_edge
|
||||||
wrap_v: .clamp_to_edge
|
wrap_v: .clamp_to_edge
|
||||||
label: &byte(0)
|
label: &u8(0)
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
// comment if .dynamic is enabled
|
// comment if .dynamic is enabled
|
||||||
|
@ -428,7 +428,7 @@ fn frame(mut app App) {
|
||||||
|
|
||||||
// println("$w,$h")
|
// println("$w,$h")
|
||||||
// white multiplicator for now
|
// white multiplicator for now
|
||||||
mut c := [byte(255), 255, 255]!
|
mut c := [u8(255), 255, 255]!
|
||||||
sgl.begin_quads()
|
sgl.begin_quads()
|
||||||
sgl.v2f_t2f_c3b(-w, -h, 0, 0, c[0], c[1], c[2])
|
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])
|
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
|
bx += (bw_old - bw) / 2 - (tr_x / 8) / app.scale
|
||||||
by += (bh_old - bh) / 2 - ((tr_y / 8) / app.scale) * ratio
|
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.begin_line_strip()
|
||||||
sgl.v2f_c3b(bx , by , c[0], c[1], c[2])
|
sgl.v2f_c3b(bx , by , c[0], c[1], c[2])
|
||||||
sgl.v2f_c3b(bx + bw, by , c[0], c[1], c[2])
|
sgl.v2f_c3b(bx + bw, by , c[0], c[1], c[2])
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
||||||
x := rand.read(blocksize) ?
|
x := rand.read(blocksize) ?
|
||||||
for c in x {
|
for c in x {
|
||||||
if c >= `0` && c <= `~` {
|
if c >= `0` && c <= `~` {
|
||||||
sb.write_byte(c)
|
sb.write_u8(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sb.len > size {
|
if sb.len > size {
|
||||||
|
|
|
@ -11,11 +11,11 @@ fn test_min() ? {
|
||||||
assert rf == f32(1.1)
|
assert rf == f32(1.1)
|
||||||
rf = min(b[..2]) ?
|
rf = min(b[..2]) ?
|
||||||
assert rf == f32(3.1)
|
assert rf == f32(3.1)
|
||||||
c := [byte(4), 9, 3, 1]
|
c := [u8(4), 9, 3, 1]
|
||||||
mut rb := min(c) ?
|
mut rb := min(c) ?
|
||||||
assert rb == byte(1)
|
assert rb == u8(1)
|
||||||
rb = min(c[..3]) ?
|
rb = min(c[..3]) ?
|
||||||
assert rb == byte(3)
|
assert rb == u8(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_max() ? {
|
fn test_max() ? {
|
||||||
|
@ -29,11 +29,11 @@ fn test_max() ? {
|
||||||
assert rf == f32(9.1)
|
assert rf == f32(9.1)
|
||||||
rf = max(b[..3]) ?
|
rf = max(b[..3]) ?
|
||||||
assert rf == f32(5.1)
|
assert rf == f32(5.1)
|
||||||
c := [byte(4), 9, 3, 1]
|
c := [u8(4), 9, 3, 1]
|
||||||
mut rb := max(c) ?
|
mut rb := max(c) ?
|
||||||
assert rb == byte(9)
|
assert rb == u8(9)
|
||||||
rb = max(c[2..]) ?
|
rb = max(c[2..]) ?
|
||||||
assert rb == byte(3)
|
assert rb == u8(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_idx_min() ? {
|
fn test_idx_min() ? {
|
||||||
|
@ -43,7 +43,7 @@ fn test_idx_min() ? {
|
||||||
b := [f32(5.1), 3.1, 1.1, 9.1]
|
b := [f32(5.1), 3.1, 1.1, 9.1]
|
||||||
rf := idx_min(b) ?
|
rf := idx_min(b) ?
|
||||||
assert rf == 2
|
assert rf == 2
|
||||||
c := [byte(4), 9, 3, 1]
|
c := [u8(4), 9, 3, 1]
|
||||||
rb := idx_min(c) ?
|
rb := idx_min(c) ?
|
||||||
assert rb == 3
|
assert rb == 3
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ fn test_idx_max() ? {
|
||||||
b := [f32(5.1), 3.1, 1.1, 9.1]
|
b := [f32(5.1), 3.1, 1.1, 9.1]
|
||||||
rf := idx_max(b) ?
|
rf := idx_max(b) ?
|
||||||
assert rf == 3
|
assert rf == 3
|
||||||
c := [byte(4), 9, 3, 1]
|
c := [u8(4), 9, 3, 1]
|
||||||
rb := idx_max(c) ?
|
rb := idx_max(c) ?
|
||||||
assert rb == 1
|
assert rb == 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ const (
|
||||||
pub fn from_bytes(input []byte) BitField {
|
pub fn from_bytes(input []byte) BitField {
|
||||||
mut output := new(input.len * 8)
|
mut output := new(input.len * 8)
|
||||||
for i, b in input {
|
for i, b in input {
|
||||||
mut ob := byte(0)
|
mut ob := u8(0)
|
||||||
if b & 0b10000000 > 0 {
|
if b & 0b10000000 > 0 {
|
||||||
ob |= 0b00000001
|
ob |= 0b00000001
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ fn test_hamming() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_bf_from_bytes() {
|
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()
|
output := bitfield.from_bytes(input).str()
|
||||||
assert output == '00000001' + '11110000' + '00001111' + '11110000' + '11111111'
|
assert output == '00000001' + '11110000' + '00001111' + '11110000' + '11111111'
|
||||||
newoutput := bitfield.from_str(output).str()
|
newoutput := bitfield.from_str(output).str()
|
||||||
|
@ -141,7 +141,7 @@ fn test_bf_from_bytes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_bf_from_bytes_lowest_bits_first() {
|
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()
|
output := bitfield.from_bytes_lowest_bits_first(input).str()
|
||||||
assert output == '10000000' + '00001111'
|
assert output == '10000000' + '00001111'
|
||||||
newoutput := bitfield.from_str(output).str()
|
newoutput := bitfield.from_str(output).str()
|
||||||
|
@ -161,7 +161,7 @@ fn test_bf_from_str() {
|
||||||
output := bitfield.from_str(input)
|
output := bitfield.from_str(input)
|
||||||
mut result := 1
|
mut result := 1
|
||||||
for i in 0 .. len {
|
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
|
result = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -821,17 +821,17 @@ pub fn (a []string) str() string {
|
||||||
}
|
}
|
||||||
sb_len += 2 // 1x[ + 1x]
|
sb_len += 2 // 1x[ + 1x]
|
||||||
mut sb := strings.new_builder(sb_len)
|
mut sb := strings.new_builder(sb_len)
|
||||||
sb.write_byte(`[`)
|
sb.write_u8(`[`)
|
||||||
for i in 0 .. a.len {
|
for i in 0 .. a.len {
|
||||||
val := a[i]
|
val := a[i]
|
||||||
sb.write_byte(`'`)
|
sb.write_u8(`'`)
|
||||||
sb.write_string(val)
|
sb.write_string(val)
|
||||||
sb.write_byte(`'`)
|
sb.write_u8(`'`)
|
||||||
if i < a.len - 1 {
|
if i < a.len - 1 {
|
||||||
sb.write_string(', ')
|
sb.write_string(', ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.write_byte(`]`)
|
sb.write_u8(`]`)
|
||||||
res := sb.str()
|
res := sb.str()
|
||||||
unsafe { sb.free() }
|
unsafe { sb.free() }
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -669,7 +669,7 @@ fn test_map() {
|
||||||
assert nums.map(it + strs.map(it.len)[0]) == [2, 3, 4, 5, 6, 7]
|
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]
|
assert strs.map(it.len + strs.map(it.len)[0]) == [2, 3, 8]
|
||||||
// nested (different it types)
|
// 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[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 nums.map(map_test_helper_1) == [1, 4, 9, 16, 25, 36]
|
||||||
assert [1, 5, 10].map(map_test_helper_1) == [1, 25, 100]
|
assert [1, 5, 10].map(map_test_helper_1) == [1, 25, 100]
|
||||||
|
@ -1082,10 +1082,10 @@ fn test_drop() {
|
||||||
|
|
||||||
fn test_hex() {
|
fn test_hex() {
|
||||||
// array hex
|
// array hex
|
||||||
st := [byte(`V`), `L`, `A`, `N`, `G`]
|
st := [u8(`V`), `L`, `A`, `N`, `G`]
|
||||||
assert st.hex() == '564c414e47'
|
assert st.hex() == '564c414e47'
|
||||||
assert st.hex().len == 10
|
assert st.hex().len == 10
|
||||||
st1 := [byte(0x41)].repeat(100)
|
st1 := [u8(0x41)].repeat(100)
|
||||||
assert st1.hex() == '41'.repeat(100)
|
assert st1.hex() == '41'.repeat(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
fn test_clone() {
|
fn test_clone() {
|
||||||
a := [byte(0), 1, 2]
|
a := [u8(0), 1, 2]
|
||||||
b := a.clone()
|
b := a.clone()
|
||||||
assert b.len == 3
|
assert b.len == 3
|
||||||
assert b[0] == 0
|
assert b[0] == 0
|
||||||
assert b[1] == 1
|
assert b[1] == 1
|
||||||
assert b[2] == 2
|
assert b[2] == 2
|
||||||
assert b[1].str() == '1'
|
assert b[1].str() == '1'
|
||||||
xx := byte(35)
|
xx := u8(35)
|
||||||
assert xx.str() == '35'
|
assert xx.str() == '35'
|
||||||
assert xx.ascii_str() == '#'
|
assert xx.ascii_str() == '#'
|
||||||
println(typeof(`A`).name)
|
println(typeof(`A`).name)
|
||||||
|
|
|
@ -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`.
|
// hex returns the value of the `byte` as a hexadecimal `string`.
|
||||||
// Note that the output is zero padded for values below 16.
|
// Note that the output is zero padded for values below 16.
|
||||||
// Example: assert byte(2).hex() == '02'
|
// Example: assert u8(2).hex() == '02'
|
||||||
// Example: assert byte(15).hex() == '0f'
|
// Example: assert u8(15).hex() == '0f'
|
||||||
// Example: assert byte(255).hex() == 'ff'
|
// Example: assert u8(255).hex() == 'ff'
|
||||||
pub fn (nn u8) hex() string {
|
pub fn (nn u8) hex() string {
|
||||||
if nn == 0 {
|
if nn == 0 {
|
||||||
return '00'
|
return '00'
|
||||||
|
@ -451,13 +451,13 @@ pub fn (nn u64) hex_full() string {
|
||||||
|
|
||||||
// str returns the contents of `byte` as a zero terminated `string`.
|
// str returns the contents of `byte` as a zero terminated `string`.
|
||||||
// See also: [`byte.ascii_str`](#byte.ascii_str)
|
// 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 {
|
pub fn (b u8) str() string {
|
||||||
return int(b).str_l(7)
|
return int(b).str_l(7)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ascii_str returns the contents of `byte` as a zero terminated ASCII `string` character.
|
// 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 {
|
pub fn (b u8) ascii_str() string {
|
||||||
mut str := string{
|
mut str := string{
|
||||||
str: unsafe { malloc_noscan(2) }
|
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`.
|
// 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]
|
[manualfree]
|
||||||
pub fn (b u8) str_escaped() string {
|
pub fn (b u8) str_escaped() string {
|
||||||
str := match b {
|
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,
|
// Note: the returned string will have .len equal to the array.len,
|
||||||
// even when some of the array bytes were `0`.
|
// even when some of the array bytes were `0`.
|
||||||
// If you want to get a V string, that contains only the bytes till
|
// 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 {
|
pub fn (b []u8) bytestr() string {
|
||||||
unsafe {
|
unsafe {
|
||||||
buf := malloc_noscan(b.len + 1)
|
buf := malloc_noscan(b.len + 1)
|
||||||
|
|
|
@ -31,8 +31,8 @@ fn test_str_methods() {
|
||||||
assert u64(-1).str() == '18446744073709551615'
|
assert u64(-1).str() == '18446744073709551615'
|
||||||
assert voidptr(-1).str() == '0xffffffffffffffff'
|
assert voidptr(-1).str() == '0xffffffffffffffff'
|
||||||
assert voidptr(1).str() == '0x1'
|
assert voidptr(1).str() == '0x1'
|
||||||
assert (&byte(-1)).str() == 'ffffffffffffffff'
|
assert (&u8(-1)).str() == 'ffffffffffffffff'
|
||||||
assert (&byte(1)).str() == '1'
|
assert (&u8(1)).str() == '1'
|
||||||
assert byteptr(-1).str() == '0xffffffffffffffff'
|
assert byteptr(-1).str() == '0xffffffffffffffff'
|
||||||
assert byteptr(1).str() == '0x1'
|
assert byteptr(1).str() == '0x1'
|
||||||
assert charptr(-1).str() == '0xffffffffffffffff'
|
assert charptr(-1).str() == '0xffffffffffffffff'
|
||||||
|
@ -130,7 +130,7 @@ fn test_bin() {
|
||||||
assert x3 == -1
|
assert x3 == -1
|
||||||
x4 := 0b11111111
|
x4 := 0b11111111
|
||||||
assert x4 == 255
|
assert x4 == 255
|
||||||
x5 := byte(0b11111111)
|
x5 := u8(0b11111111)
|
||||||
assert x5 == 255
|
assert x5 == 255
|
||||||
x6 := char(0b11111111)
|
x6 := char(0b11111111)
|
||||||
// C.char is unsigned on arm64, but signed on amd64, by default
|
// 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() {
|
fn test_int_to_hex() {
|
||||||
// array hex
|
// array hex
|
||||||
st := [byte(`V`), `L`, `A`, `N`, `G`]
|
st := [u8(`V`), `L`, `A`, `N`, `G`]
|
||||||
assert st.hex() == '564c414e47'
|
assert st.hex() == '564c414e47'
|
||||||
assert st.hex().len == 10
|
assert st.hex().len == 10
|
||||||
st1 := [byte(0x41)].repeat(100)
|
st1 := [u8(0x41)].repeat(100)
|
||||||
assert st1.hex() == '41'.repeat(100)
|
assert st1.hex() == '41'.repeat(100)
|
||||||
// --- int to hex tests
|
// --- int to hex tests
|
||||||
c0 := 12
|
c0 := 12
|
||||||
// 8Bit
|
// 8Bit
|
||||||
assert byte(0).hex() == '00'
|
assert u8(0).hex() == '00'
|
||||||
assert byte(c0).hex() == '0c'
|
assert u8(c0).hex() == '0c'
|
||||||
assert i8(c0).hex() == '0c'
|
assert i8(c0).hex() == '0c'
|
||||||
assert byte(127).hex() == '7f'
|
assert u8(127).hex() == '7f'
|
||||||
assert i8(127).hex() == '7f'
|
assert i8(127).hex() == '7f'
|
||||||
assert byte(255).hex() == 'ff'
|
assert u8(255).hex() == 'ff'
|
||||||
assert byte(-1).hex() == 'ff'
|
assert u8(-1).hex() == 'ff'
|
||||||
// 16bit
|
// 16bit
|
||||||
assert u16(0).hex() == '0'
|
assert u16(0).hex() == '0'
|
||||||
assert i16(c0).hex() == 'c'
|
assert i16(c0).hex() == 'c'
|
||||||
|
@ -248,7 +248,7 @@ fn test_int_to_hex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_repeat() {
|
fn test_repeat() {
|
||||||
b := byte(`V`)
|
b := u8(`V`)
|
||||||
assert b.repeat(5) == 'VVVVV'
|
assert b.repeat(5) == 'VVVVV'
|
||||||
assert b.repeat(1) == b.ascii_str()
|
assert b.repeat(1) == b.ascii_str()
|
||||||
assert b.repeat(0) == ''
|
assert b.repeat(0) == ''
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fn test_isnil_byteptr() {
|
fn test_isnil_byteptr() {
|
||||||
pb := &byte(0)
|
pb := &u8(0)
|
||||||
assert isnil(pb)
|
assert isnil(pb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -678,7 +678,7 @@ fn test_map() {
|
||||||
assert nums.map(it + strs.map(it.len)[0]) == [2, 3, 4, 5, 6, 7]
|
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]
|
assert strs.map(it.len + strs.map(it.len)[0]) == [2, 3, 8]
|
||||||
// nested (different it types)
|
// 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[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 nums.map(map_test_helper_1) == [1, 4, 9, 16, 25, 36]
|
||||||
assert [1, 5, 10].map(map_test_helper_1) == [1, 25, 100]
|
assert [1, 5, 10].map(map_test_helper_1) == [1, 25, 100]
|
||||||
|
@ -1045,10 +1045,10 @@ fn test_trim() {
|
||||||
/*
|
/*
|
||||||
fn test_hex() {
|
fn test_hex() {
|
||||||
// array hex
|
// array hex
|
||||||
st := [byte(`V`), `L`, `A`, `N`, `G`]
|
st := [u8(`V`), `L`, `A`, `N`, `G`]
|
||||||
assert st.hex() == '564c414e47'
|
assert st.hex() == '564c414e47'
|
||||||
assert st.hex().len == 10
|
assert st.hex().len == 10
|
||||||
st1 := [byte(0x41)].repeat(100)
|
st1 := [u8(0x41)].repeat(100)
|
||||||
assert st1.hex() == '41'.repeat(100)
|
assert st1.hex() == '41'.repeat(100)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
|
@ -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.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_hex_digit() bool {
|
pub fn (c u8) is_hex_digit() bool {
|
||||||
return (c >= `0` && c <= `9`) || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`)
|
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.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_oct_digit() bool {
|
pub fn (c u8) is_oct_digit() bool {
|
||||||
return c >= `0` && c <= `7`
|
return c >= `0` && c <= `7`
|
||||||
}
|
}
|
||||||
|
|
||||||
// is_bin_digit returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_bin_digit() bool {
|
pub fn (c u8) is_bin_digit() bool {
|
||||||
return c == `0` || c == `1`
|
return c == `0` || c == `1`
|
||||||
}
|
}
|
||||||
|
|
||||||
// is_letter returns `true` if the byte is in range a-z or A-Z and `false` otherwise.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_letter() bool {
|
pub fn (c u8) is_letter() bool {
|
||||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`)
|
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.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_alnum() bool {
|
pub fn (c u8) is_alnum() bool {
|
||||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`)
|
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`.
|
// 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 {
|
pub fn (b u8) str_escaped() string {
|
||||||
mut str := ''
|
mut str := ''
|
||||||
|
|
|
@ -124,7 +124,7 @@ fn test_bin() {
|
||||||
assert x3 == -1
|
assert x3 == -1
|
||||||
x4 := 0b11111111
|
x4 := 0b11111111
|
||||||
assert x4 == 255
|
assert x4 == 255
|
||||||
x5 := byte(0b11111111)
|
x5 := u8(0b11111111)
|
||||||
assert x5 == 255
|
assert x5 == 255
|
||||||
x6 := char(0b11111111)
|
x6 := char(0b11111111)
|
||||||
assert int(x6) == -1
|
assert int(x6) == -1
|
||||||
|
@ -196,21 +196,21 @@ fn test_int_decl() {
|
||||||
fn test_int_to_hex() {
|
fn test_int_to_hex() {
|
||||||
// array hex
|
// array hex
|
||||||
/*
|
/*
|
||||||
st := [byte(`V`), `L`, `A`, `N`, `G`]
|
st := [u8(`V`), `L`, `A`, `N`, `G`]
|
||||||
assert st.hex() == '564c414e47'
|
assert st.hex() == '564c414e47'
|
||||||
assert st.hex().len == 10
|
assert st.hex().len == 10
|
||||||
st1 := [byte(0x41)].repeat(100)
|
st1 := [u8(0x41)].repeat(100)
|
||||||
assert st1.hex() == '41'.repeat(100)*/
|
assert st1.hex() == '41'.repeat(100)*/
|
||||||
// --- int to hex tests
|
// --- int to hex tests
|
||||||
c0 := 12
|
c0 := 12
|
||||||
// 8Bit
|
// 8Bit
|
||||||
assert byte(0).hex() == '0'
|
assert u8(0).hex() == '0'
|
||||||
assert byte(c0).hex() == 'c'
|
assert u8(c0).hex() == 'c'
|
||||||
assert i8(c0).hex() == 'c'
|
assert i8(c0).hex() == 'c'
|
||||||
assert byte(127).hex() == '7f'
|
assert u8(127).hex() == '7f'
|
||||||
assert i8(127).hex() == '7f'
|
assert i8(127).hex() == '7f'
|
||||||
assert byte(255).hex() == 'ff'
|
assert u8(255).hex() == 'ff'
|
||||||
// assert byte(-1).hex() == 'ff'
|
// assert u8(-1).hex() == 'ff'
|
||||||
// 16bit
|
// 16bit
|
||||||
assert u16(0).hex() == '0'
|
assert u16(0).hex() == '0'
|
||||||
assert i16(c0).hex() == 'c'
|
assert i16(c0).hex() == 'c'
|
||||||
|
@ -238,7 +238,7 @@ fn test_int_to_hex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_repeat() {
|
fn test_repeat() {
|
||||||
b := byte(`V`)
|
b := u8(`V`)
|
||||||
assert b.repeat(5) == 'VVVVV'
|
assert b.repeat(5) == 'VVVVV'
|
||||||
assert b.repeat(1) == b.ascii_str()
|
assert b.repeat(1) == b.ascii_str()
|
||||||
assert b.repeat(0) == ''
|
assert b.repeat(0) == ''
|
||||||
|
|
|
@ -182,8 +182,8 @@ fn test_various_map_value() {
|
||||||
m9['test'] = true
|
m9['test'] = true
|
||||||
assert m9['test'] == true
|
assert m9['test'] == true
|
||||||
mut m10 := map[string]byte{}
|
mut m10 := map[string]byte{}
|
||||||
m10['test'] = byte(0)
|
m10['test'] = u8(0)
|
||||||
assert m10['test'] == byte(0)
|
assert m10['test'] == u8(0)
|
||||||
mut m11 := map[string]f32{}
|
mut m11 := map[string]f32{}
|
||||||
m11['test'] = f32(0.0)
|
m11['test'] = f32(0.0)
|
||||||
assert m11['test'] == f32(0.0)
|
assert m11['test'] == f32(0.0)
|
||||||
|
@ -199,8 +199,8 @@ fn test_various_map_value() {
|
||||||
m14['test'] = voidptr(0)
|
m14['test'] = voidptr(0)
|
||||||
assert m14['test'] == voidptr(0)
|
assert m14['test'] == voidptr(0)
|
||||||
mut m15 := map[string]&byte{}
|
mut m15 := map[string]&byte{}
|
||||||
m15['test'] = &byte(0)
|
m15['test'] = &u8(0)
|
||||||
assert m15['test'] == &byte(0)
|
assert m15['test'] == &u8(0)
|
||||||
mut m16 := map[string]i64{}
|
mut m16 := map[string]i64{}
|
||||||
m16['test'] = i64(0)
|
m16['test'] = i64(0)
|
||||||
assert m16['test'] == i64(0)
|
assert m16['test'] == i64(0)
|
||||||
|
@ -763,24 +763,24 @@ fn test_in_map_literal() {
|
||||||
|
|
||||||
fn test_byte_keys() {
|
fn test_byte_keys() {
|
||||||
mut m := map[byte]byte{}
|
mut m := map[byte]byte{}
|
||||||
byte_max := byte(255)
|
byte_max := u8(255)
|
||||||
for i in byte(0) .. byte_max {
|
for i in u8(0) .. byte_max {
|
||||||
m[i] = i
|
m[i] = i
|
||||||
assert m[i] == i
|
assert m[i] == i
|
||||||
}
|
}
|
||||||
for k, v in m {
|
for k, v in m {
|
||||||
assert k == v
|
assert k == v
|
||||||
}
|
}
|
||||||
for i in byte(0) .. 100 {
|
for i in u8(0) .. 100 {
|
||||||
m[i]++
|
m[i]++
|
||||||
assert m[i] == i + 1
|
assert m[i] == i + 1
|
||||||
}
|
}
|
||||||
assert m.len == int(byte_max)
|
assert m.len == int(byte_max)
|
||||||
keys := m.keys()
|
keys := m.keys()
|
||||||
for i in byte(0) .. byte_max {
|
for i in u8(0) .. byte_max {
|
||||||
assert keys[i] == i
|
assert keys[i] == i
|
||||||
}
|
}
|
||||||
for i in byte(0) .. byte_max {
|
for i in u8(0) .. byte_max {
|
||||||
m.delete(i)
|
m.delete(i)
|
||||||
assert m[i] == 0
|
assert m[i] == 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ pub fn (s string) split(dot string) []string {
|
||||||
pub fn (s string) bytes() []byte {
|
pub fn (s string) bytes() []byte {
|
||||||
sep := ''
|
sep := ''
|
||||||
tmparr := s.str.split(sep.str).map(fn (it JS.Any) JS.Any {
|
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
|
_ := tmparr
|
||||||
mut arr := []byte{}
|
mut arr := []byte{}
|
||||||
|
@ -249,9 +249,9 @@ pub fn (s string) u64() u64 {
|
||||||
return u64(JS.parseInt(s.str))
|
return u64(JS.parseInt(s.str))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s string) byte() u64 {
|
pub fn (s string) u8() u64 {
|
||||||
res := byte(0)
|
res := u8(0)
|
||||||
#res.val = byte(JS.parseInt(s.str))
|
#res.val = u8(JS.parseInt(s.str))
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
@ -384,10 +384,10 @@ fn compare_lower_strings(a &string, b &string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// at returns the byte at index `idx`.
|
// 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 {
|
fn (s string) at(idx int) byte {
|
||||||
mut result := byte(0)
|
mut result := u8(0)
|
||||||
#result = new byte(s.str.charCodeAt(result))
|
#result = new u8(s.str.charCodeAt(result))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -443,7 +443,7 @@ pub fn (s string) repeat(count int) string {
|
||||||
return result
|
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; }
|
#function string_iterator(string) { this.stringIteratorFieldIndex = 0; this.stringIteratorIteratedString = string.str; }
|
||||||
#string_iterator.prototype.next = function next() {
|
#string_iterator.prototype.next = function next() {
|
||||||
#var done = true;
|
#var done = true;
|
||||||
|
@ -458,9 +458,9 @@ pub fn (s string) repeat(count int) string {
|
||||||
#done = false;
|
#done = false;
|
||||||
#var first = string.charCodeAt(position);
|
#var first = string.charCodeAt(position);
|
||||||
#if (first < 0xD800 || first > 0xDBFF || position + 1 === length)
|
#if (first < 0xD800 || first > 0xDBFF || position + 1 === length)
|
||||||
#value = new byte(string[position]);
|
#value = new u8(string[position]);
|
||||||
#else {
|
#else {
|
||||||
#value = new byte(string[position]+string[position+1])
|
#value = new u8(string[position]+string[position+1])
|
||||||
#}
|
#}
|
||||||
#this.stringIteratorFieldIndex = position + value.length;
|
#this.stringIteratorFieldIndex = position + value.length;
|
||||||
#}
|
#}
|
||||||
|
|
|
@ -422,7 +422,7 @@ fn test_arr_contains() {
|
||||||
fn test_to_num() {
|
fn test_to_num() {
|
||||||
s := '7'
|
s := '7'
|
||||||
assert s.int() == 7
|
assert s.int() == 7
|
||||||
assert s.byte() == 7
|
assert s.u8() == 7
|
||||||
assert s.u64() == 7
|
assert s.u64() == 7
|
||||||
f := '71.5 hasdf'
|
f := '71.5 hasdf'
|
||||||
// QTODO
|
// QTODO
|
||||||
|
|
|
@ -6,8 +6,8 @@ __global global_allocator dlmalloc.Dlmalloc
|
||||||
|
|
||||||
[unsafe]
|
[unsafe]
|
||||||
pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void {
|
pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void {
|
||||||
dest_ := unsafe { &byte(dest) }
|
dest_ := unsafe { &u8(dest) }
|
||||||
src_ := unsafe { &byte(src) }
|
src_ := unsafe { &u8(src) }
|
||||||
unsafe {
|
unsafe {
|
||||||
for i in 0 .. int(n) {
|
for i in 0 .. int(n) {
|
||||||
dest_[i] = src_[i]
|
dest_[i] = src_[i]
|
||||||
|
@ -24,7 +24,7 @@ fn __malloc(n usize) &C.void {
|
||||||
|
|
||||||
[unsafe]
|
[unsafe]
|
||||||
fn strlen(_s &C.void) usize {
|
fn strlen(_s &C.void) usize {
|
||||||
s := unsafe { &byte(_s) }
|
s := unsafe { &u8(_s) }
|
||||||
mut i := 0
|
mut i := 0
|
||||||
for ; unsafe { s[i] } != 0; i++ {}
|
for ; unsafe { s[i] } != 0; i++ {}
|
||||||
return usize(i)
|
return usize(i)
|
||||||
|
@ -63,8 +63,8 @@ fn memset(s &C.void, c int, n usize) &C.void {
|
||||||
|
|
||||||
[unsafe]
|
[unsafe]
|
||||||
fn memmove(dest &C.void, src &C.void, n usize) &C.void {
|
fn memmove(dest &C.void, src &C.void, n usize) &C.void {
|
||||||
dest_ := unsafe { &byte(dest) }
|
dest_ := unsafe { &u8(dest) }
|
||||||
src_ := unsafe { &byte(src) }
|
src_ := unsafe { &u8(src) }
|
||||||
mut temp_buf := unsafe { malloc(int(n)) }
|
mut temp_buf := unsafe { malloc(int(n)) }
|
||||||
for i in 0 .. int(n) {
|
for i in 0 .. int(n) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -90,14 +90,14 @@ fn __calloc(nmemb usize, size usize) &C.void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getchar() int {
|
fn getchar() int {
|
||||||
x := byte(0)
|
x := u8(0)
|
||||||
sys_read(0, &x, 1)
|
sys_read(0, &x, 1)
|
||||||
return int(x)
|
return int(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn memcmp(a &C.void, b &C.void, n usize) int {
|
fn memcmp(a &C.void, b &C.void, n usize) int {
|
||||||
a_ := unsafe { &byte(a) }
|
a_ := unsafe { &u8(a) }
|
||||||
b_ := unsafe { &byte(b) }
|
b_ := unsafe { &u8(b) }
|
||||||
for i in 0 .. int(n) {
|
for i in 0 .. int(n) {
|
||||||
if unsafe { a_[i] != b_[i] } {
|
if unsafe { a_[i] != b_[i] } {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -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) {
|
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)
|
rc := sys_call6(9, u64(addr), len, u64(prot), u64(flags), fildes, off)
|
||||||
a, e := split_int_errno(rc)
|
a, e := split_int_errno(rc)
|
||||||
return &byte(a), e
|
return &u8(a), e
|
||||||
}
|
}
|
||||||
|
|
||||||
// 11 sys_munmap
|
// 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) {
|
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)
|
rc := sys_call4(25, u64(old_addr), old_len, new_len, flags)
|
||||||
a, e := split_int_errno(rc)
|
a, e := split_int_errno(rc)
|
||||||
return &byte(a), e
|
return &u8(a), e
|
||||||
}
|
}
|
||||||
|
|
||||||
// 22 sys_pipe
|
// 22 sys_pipe
|
||||||
|
|
|
@ -10,16 +10,16 @@ fn mm_alloc(size u64) (&byte, Errno) {
|
||||||
map_flags := MapFlags(int(MapFlags.map_private) | int(MapFlags.map_anonymous))
|
map_flags := MapFlags(int(MapFlags.map_private) | int(MapFlags.map_anonymous))
|
||||||
// END CONSTS
|
// 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 {
|
if e == .enoerror {
|
||||||
unsafe {
|
unsafe {
|
||||||
mut ap := &u64(a)
|
mut ap := &u64(a)
|
||||||
*ap = size
|
*ap = size
|
||||||
x2 := &byte(a + sizeof(u64))
|
x2 := &u8(a + sizeof(u64))
|
||||||
return x2, e
|
return x2, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &byte(0), e
|
return &u8(0), e
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mm_free(addr &byte) Errno {
|
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))
|
map_flags := MapFlags(int(MapFlags.map_private) | int(MapFlags.map_anonymous))
|
||||||
// END CONSTS
|
// 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 {
|
if e == .enoerror {
|
||||||
return a, size, 0
|
return a, size, 0
|
||||||
|
|
|
@ -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) {
|
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)
|
rc := sys_call6(9, u64(addr), len, u64(prot), u64(flags), fildes, off)
|
||||||
a, e := split_int_errno(rc)
|
a, e := split_int_errno(rc)
|
||||||
return &byte(a), e
|
return &u8(a), e
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_munmap(addr voidptr, len u64) Errno {
|
pub fn sys_munmap(addr voidptr, len u64) Errno {
|
||||||
|
|
|
@ -19,9 +19,9 @@ pub fn mm_alloc(size u64) (&byte, Errno) {
|
||||||
if e == .enoerror {
|
if e == .enoerror {
|
||||||
mut ap := &int(a)
|
mut ap := &int(a)
|
||||||
*ap = pages
|
*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 {
|
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 {
|
pub fn mem_copy(dest0 voidptr, src0 voidptr, n int) voidptr {
|
||||||
mut dest := &byte(dest0)
|
mut dest := &u8(dest0)
|
||||||
src := &byte(src0)
|
src := &u8(src0)
|
||||||
for i in 0 .. n {
|
for i in 0 .. n {
|
||||||
dest[i] = src[i]
|
dest[i] = src[i]
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,8 @@ pub fn tos3(s &char) string {
|
||||||
panic('tos3: nil string')
|
panic('tos3: nil string')
|
||||||
}
|
}
|
||||||
return string{
|
return string{
|
||||||
str: &byte(s)
|
str: &u8(s)
|
||||||
len: strlen(&byte(s))
|
len: strlen(&u8(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ fn map_hash_string(pkey voidptr) u64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_hash_int_1(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 {
|
fn map_hash_int_2(pkey voidptr) u64 {
|
||||||
|
|
|
@ -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,
|
mut out := new_map_noscan_key(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn,
|
||||||
free_fn)
|
free_fn)
|
||||||
// TODO pre-allocate n slots
|
// TODO pre-allocate n slots
|
||||||
mut pkey := &byte(keys)
|
mut pkey := &u8(keys)
|
||||||
mut pval := &byte(values)
|
mut pval := &u8(values)
|
||||||
for _ in 0 .. n {
|
for _ in 0 .. n {
|
||||||
unsafe {
|
unsafe {
|
||||||
out.set(pkey, pval)
|
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,
|
mut out := new_map_noscan_value(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn,
|
||||||
free_fn)
|
free_fn)
|
||||||
// TODO pre-allocate n slots
|
// TODO pre-allocate n slots
|
||||||
mut pkey := &byte(keys)
|
mut pkey := &u8(keys)
|
||||||
mut pval := &byte(values)
|
mut pval := &u8(values)
|
||||||
for _ in 0 .. n {
|
for _ in 0 .. n {
|
||||||
unsafe {
|
unsafe {
|
||||||
out.set(pkey, pval)
|
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,
|
mut out := new_map_noscan_key_value(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn,
|
||||||
free_fn)
|
free_fn)
|
||||||
// TODO pre-allocate n slots
|
// TODO pre-allocate n slots
|
||||||
mut pkey := &byte(keys)
|
mut pkey := &u8(keys)
|
||||||
mut pval := &byte(values)
|
mut pval := &u8(values)
|
||||||
for _ in 0 .. n {
|
for _ in 0 .. n {
|
||||||
unsafe {
|
unsafe {
|
||||||
out.set(pkey, pval)
|
out.set(pkey, pval)
|
||||||
|
|
|
@ -180,8 +180,8 @@ fn test_various_map_value() {
|
||||||
m9['test'] = true
|
m9['test'] = true
|
||||||
assert m9['test'] == true
|
assert m9['test'] == true
|
||||||
mut m10 := map[string]byte{}
|
mut m10 := map[string]byte{}
|
||||||
m10['test'] = byte(0)
|
m10['test'] = u8(0)
|
||||||
assert m10['test'] == byte(0)
|
assert m10['test'] == u8(0)
|
||||||
mut m11 := map[string]f32{}
|
mut m11 := map[string]f32{}
|
||||||
m11['test'] = f32(0.0)
|
m11['test'] = f32(0.0)
|
||||||
assert m11['test'] == f32(0.0)
|
assert m11['test'] == f32(0.0)
|
||||||
|
@ -195,8 +195,8 @@ fn test_various_map_value() {
|
||||||
m14['test'] = voidptr(0)
|
m14['test'] = voidptr(0)
|
||||||
assert m14['test'] == voidptr(0)
|
assert m14['test'] == voidptr(0)
|
||||||
mut m15 := map[string]&byte{}
|
mut m15 := map[string]&byte{}
|
||||||
m15['test'] = &byte(0)
|
m15['test'] = &u8(0)
|
||||||
assert m15['test'] == &byte(0)
|
assert m15['test'] == &u8(0)
|
||||||
mut m16 := map[string]i64{}
|
mut m16 := map[string]i64{}
|
||||||
m16['test'] = i64(0)
|
m16['test'] = i64(0)
|
||||||
assert m16['test'] == i64(0)
|
assert m16['test'] == i64(0)
|
||||||
|
@ -751,24 +751,24 @@ fn test_in_map_literal() {
|
||||||
|
|
||||||
fn test_byte_keys() {
|
fn test_byte_keys() {
|
||||||
mut m := map[byte]byte{}
|
mut m := map[byte]byte{}
|
||||||
byte_max := byte(255)
|
byte_max := u8(255)
|
||||||
for i in byte(0) .. byte_max {
|
for i in u8(0) .. byte_max {
|
||||||
m[i] = i
|
m[i] = i
|
||||||
assert m[i] == i
|
assert m[i] == i
|
||||||
}
|
}
|
||||||
for k, v in m {
|
for k, v in m {
|
||||||
assert k == v
|
assert k == v
|
||||||
}
|
}
|
||||||
for i in byte(0) .. 100 {
|
for i in u8(0) .. 100 {
|
||||||
m[i]++
|
m[i]++
|
||||||
assert m[i] == i + 1
|
assert m[i] == i + 1
|
||||||
}
|
}
|
||||||
assert m.len == int(byte_max)
|
assert m.len == int(byte_max)
|
||||||
keys := m.keys()
|
keys := m.keys()
|
||||||
for i in byte(0) .. byte_max {
|
for i in u8(0) .. byte_max {
|
||||||
assert keys[i] == i
|
assert keys[i] == i
|
||||||
}
|
}
|
||||||
for i in byte(0) .. byte_max {
|
for i in u8(0) .. byte_max {
|
||||||
m.delete(i)
|
m.delete(i)
|
||||||
assert m[i] == 0
|
assert m[i] == 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ fn vmemory_block_malloc(n int) &byte {
|
||||||
if g_memory_block.remaining < n {
|
if g_memory_block.remaining < n {
|
||||||
g_memory_block = vmemory_block_new(g_memory_block, n)
|
g_memory_block = vmemory_block_new(g_memory_block, n)
|
||||||
}
|
}
|
||||||
mut res := &byte(0)
|
mut res := &u8(0)
|
||||||
res = g_memory_block.current
|
res = g_memory_block.current
|
||||||
g_memory_block.remaining -= n
|
g_memory_block.remaining -= n
|
||||||
g_memory_block.mallocs++
|
g_memory_block.mallocs++
|
||||||
|
|
|
@ -38,5 +38,5 @@ fn test_length_in_bytes() {
|
||||||
|
|
||||||
fn test_bytes() {
|
fn test_bytes() {
|
||||||
r1 := `★`
|
r1 := `★`
|
||||||
assert r1.bytes() == [byte(0xe2), 0x98, 0x85]
|
assert r1.bytes() == [u8(0xe2), 0x98, 0x85]
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
mut out := new_sorted_map(n, value_bytes)
|
||||||
for i in 0 .. n {
|
for i in 0 .. n {
|
||||||
unsafe {
|
unsafe {
|
||||||
out.set(keys[i], &byte(values) + i * value_bytes)
|
out.set(keys[i], &u8(values) + i * value_bytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
|
@ -180,7 +180,7 @@ pub fn tos5(s &char) string {
|
||||||
|
|
||||||
// vstring converts a C style string to a V string.
|
// vstring converts a C style string to a V string.
|
||||||
// Note: the memory block pointed by `bp` is *reused, not copied*!
|
// 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,
|
// 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).
|
// (i.e. they would be freed by V's -autofree mechanism, when they are no longer used).
|
||||||
// See also `tos_clone`.
|
// 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,
|
// 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
|
// (i.e. they would be freed by V's -autofree mechanism, when they are
|
||||||
// no longer used).
|
// 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`.
|
// See also `tos_clone`.
|
||||||
[unsafe]
|
[unsafe]
|
||||||
pub fn (cp &char) vstring() string {
|
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)`.
|
// 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 })
|
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 the index of byte `c` if found in the string.
|
||||||
// index_byte returns -1 if the byte can not be found.
|
// index_byte returns -1 if the byte can not be found.
|
||||||
[direct_array_access]
|
[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 {
|
for i in 0 .. s.len {
|
||||||
if unsafe { s.str[i] } == c {
|
if unsafe { s.str[i] } == c {
|
||||||
return i
|
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 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.
|
// last_index_byte returns -1 if the byte is not found.
|
||||||
[direct_array_access]
|
[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-- {
|
for i := s.len - 1; i >= 0; i-- {
|
||||||
if unsafe { s.str[i] == c } {
|
if unsafe { s.str[i] == c } {
|
||||||
return i
|
return i
|
||||||
|
@ -1476,7 +1476,7 @@ pub fn (s string) str() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// at returns the byte at index `idx`.
|
// 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 {
|
fn (s string) at(idx int) byte {
|
||||||
$if !no_bounds_checking ? {
|
$if !no_bounds_checking ? {
|
||||||
if idx < 0 || idx >= s.len {
|
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.
|
// 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
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_space() bool {
|
pub fn (c u8) is_space() bool {
|
||||||
// 0x85 is NEXT LINE (NEL)
|
// 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.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_digit() bool {
|
pub fn (c u8) is_digit() bool {
|
||||||
return c >= `0` && c <= `9`
|
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.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_hex_digit() bool {
|
pub fn (c u8) is_hex_digit() bool {
|
||||||
return (c >= `0` && c <= `9`) || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`)
|
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.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_oct_digit() bool {
|
pub fn (c u8) is_oct_digit() bool {
|
||||||
return c >= `0` && c <= `7`
|
return c >= `0` && c <= `7`
|
||||||
}
|
}
|
||||||
|
|
||||||
// is_bin_digit returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_bin_digit() bool {
|
pub fn (c u8) is_bin_digit() bool {
|
||||||
return c == `0` || c == `1`
|
return c == `0` || c == `1`
|
||||||
}
|
}
|
||||||
|
|
||||||
// is_letter returns `true` if the byte is in range a-z or A-Z and `false` otherwise.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_letter() bool {
|
pub fn (c u8) is_letter() bool {
|
||||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`)
|
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.
|
// 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]
|
[inline]
|
||||||
pub fn (c u8) is_alnum() bool {
|
pub fn (c u8) is_alnum() bool {
|
||||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`)
|
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`)
|
||||||
|
@ -1558,7 +1558,7 @@ pub fn (s &string) free() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.is_lit == -98761234 {
|
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) }
|
double_free_msg_len := unsafe { vstrlen(double_free_msg) }
|
||||||
$if freestanding {
|
$if freestanding {
|
||||||
bare_eprint(double_free_msg, u64(double_free_msg_len))
|
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 is_inverted := false
|
||||||
mut inner_match := false
|
mut inner_match := false
|
||||||
mut inner_idx := bstart + 1
|
mut inner_idx := bstart + 1
|
||||||
mut inner_c := byte(0)
|
mut inner_c := u8(0)
|
||||||
if inner_idx < plen {
|
if inner_idx < plen {
|
||||||
inner_c = pattern[inner_idx]
|
inner_c = pattern[inner_idx]
|
||||||
if inner_c == `^` {
|
if inner_c == `^` {
|
||||||
|
|
|
@ -174,7 +174,7 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// mange pad char, for now only 0 allowed
|
// mange pad char, for now only 0 allowed
|
||||||
mut pad_ch := byte(` `)
|
mut pad_ch := u8(` `)
|
||||||
if fmt_pad_ch > 0 {
|
if fmt_pad_ch > 0 {
|
||||||
// pad_ch = fmt_pad_ch
|
// pad_ch = fmt_pad_ch
|
||||||
pad_ch = `0`
|
pad_ch = `0`
|
||||||
|
@ -263,7 +263,7 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) {
|
||||||
tmp.free()
|
tmp.free()
|
||||||
}
|
}
|
||||||
if write_minus {
|
if write_minus {
|
||||||
sb.write_byte(`-`)
|
sb.write_u8(`-`)
|
||||||
bf.len0-- // compensate for the `-` above
|
bf.len0-- // compensate for the `-` above
|
||||||
}
|
}
|
||||||
if width == 0 {
|
if width == 0 {
|
||||||
|
|
|
@ -457,7 +457,7 @@ fn test_arr_contains() {
|
||||||
fn test_to_num() {
|
fn test_to_num() {
|
||||||
s := '7'
|
s := '7'
|
||||||
assert s.int() == 7
|
assert s.int() == 7
|
||||||
assert s.byte() == 7
|
assert s.u8() == 7
|
||||||
assert s.u64() == 7
|
assert s.u64() == 7
|
||||||
f := '71.5 hasdf'
|
f := '71.5 hasdf'
|
||||||
// QTODO
|
// QTODO
|
||||||
|
@ -574,7 +574,7 @@ fn test_bytes_to_string() {
|
||||||
}
|
}
|
||||||
assert unsafe { buf.vstring() } == 'hello'
|
assert unsafe { buf.vstring() } == 'hello'
|
||||||
assert unsafe { buf.vstring_with_len(2) } == 'he'
|
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'
|
assert bytes.bytestr() == 'hello'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -982,5 +982,5 @@ fn test_string_f32() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_string_with_zero_byte_escape() {
|
fn test_string_with_zero_byte_escape() {
|
||||||
assert '\x00'.bytes() == [byte(0)]
|
assert '\x00'.bytes() == [u8(0)]
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub fn (_str string) to_wide() &u16 {
|
||||||
mut wstr := &u16(malloc_noscan((num_chars + 1) * 2)) // sizeof(wchar_t)
|
mut wstr := &u16(malloc_noscan((num_chars + 1) * 2)) // sizeof(wchar_t)
|
||||||
if wstr != 0 {
|
if wstr != 0 {
|
||||||
C.MultiByteToWideChar(cp_utf8, 0, &char(_str.str), _str.len, wstr, num_chars)
|
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
|
return wstr
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ pub fn __malloc(size usize) voidptr {
|
||||||
|
|
||||||
[unsafe]
|
[unsafe]
|
||||||
pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void {
|
pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void {
|
||||||
dest_ := unsafe { &byte(dest) }
|
dest_ := unsafe { &u8(dest) }
|
||||||
src_ := unsafe { &byte(src) }
|
src_ := unsafe { &u8(src) }
|
||||||
unsafe {
|
unsafe {
|
||||||
for i in 0 .. int(n) {
|
for i in 0 .. int(n) {
|
||||||
dest_[i] = src_[i]
|
dest_[i] = src_[i]
|
||||||
|
@ -23,7 +23,7 @@ pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void {
|
||||||
|
|
||||||
[unsafe]
|
[unsafe]
|
||||||
fn strlen(_s &C.void) usize {
|
fn strlen(_s &C.void) usize {
|
||||||
s := unsafe { &byte(_s) }
|
s := unsafe { &u8(_s) }
|
||||||
mut i := 0
|
mut i := 0
|
||||||
for ; unsafe { s[i] } != 0; i++ {}
|
for ; unsafe { s[i] } != 0; i++ {}
|
||||||
return usize(i)
|
return usize(i)
|
||||||
|
@ -62,8 +62,8 @@ fn memset(s &C.void, c int, n usize) &C.void {
|
||||||
|
|
||||||
[unsafe]
|
[unsafe]
|
||||||
fn memmove(dest &C.void, src &C.void, n usize) &C.void {
|
fn memmove(dest &C.void, src &C.void, n usize) &C.void {
|
||||||
dest_ := unsafe { &byte(dest) }
|
dest_ := unsafe { &u8(dest) }
|
||||||
src_ := unsafe { &byte(src) }
|
src_ := unsafe { &u8(src) }
|
||||||
mut temp_buf := unsafe { malloc(int(n)) }
|
mut temp_buf := unsafe { malloc(int(n)) }
|
||||||
for i in 0 .. int(n) {
|
for i in 0 .. int(n) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -93,8 +93,8 @@ fn getchar() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn memcmp(a &C.void, b &C.void, n usize) int {
|
fn memcmp(a &C.void, b &C.void, n usize) int {
|
||||||
a_ := unsafe { &byte(a) }
|
a_ := unsafe { &u8(a) }
|
||||||
b_ := unsafe { &byte(b) }
|
b_ := unsafe { &u8(b) }
|
||||||
for i in 0 .. int(n) {
|
for i in 0 .. int(n) {
|
||||||
if unsafe { a_[i] != b_[i] } {
|
if unsafe { a_[i] != b_[i] } {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub fn (mut cb Clipboard) get_text() string {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
utf8_clip := C.darwin_get_pasteboard_text(cb.pb)
|
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.
|
// new_primary returns a new X11 `PRIMARY` type `Clipboard` instance allocated on the heap.
|
||||||
|
|
|
@ -398,7 +398,7 @@ fn read_property(d &C.Display, w Window, p Atom) Property {
|
||||||
actual_format := 0
|
actual_format := 0
|
||||||
nitems := u64(0)
|
nitems := u64(0)
|
||||||
bytes_after := u64(0)
|
bytes_after := u64(0)
|
||||||
ret := &byte(0)
|
ret := &u8(0)
|
||||||
mut read_bytes := 1024
|
mut read_bytes := 1024
|
||||||
for {
|
for {
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
|
|
|
@ -58,10 +58,10 @@ fn encrypt_block_generic(xk []u32, mut dst []byte, src []byte) {
|
||||||
mut t2 := u32(0)
|
mut t2 := u32(0)
|
||||||
mut t3 := u32(0)
|
mut t3 := u32(0)
|
||||||
for _ in 0 .. nr {
|
for _ in 0 .. nr {
|
||||||
t0 = xk[k + 0] ^ te0[byte(s0 >> 24)] ^ te1[byte(s1 >> 16)] ^ te2[byte(s2 >> 8)] ^ u32(te3[byte(s3)])
|
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[byte(s1 >> 24)] ^ te1[byte(s2 >> 16)] ^ te2[byte(s3 >> 8)] ^ u32(te3[byte(s0)])
|
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[byte(s2 >> 24)] ^ te1[byte(s3 >> 16)] ^ te2[byte(s0 >> 8)] ^ u32(te3[byte(s1)])
|
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[byte(s3 >> 24)] ^ te1[byte(s0 >> 16)] ^ te2[byte(s1 >> 8)] ^ u32(te3[byte(s2)])
|
t3 = xk[k + 3] ^ te0[u8(s3 >> 24)] ^ te1[u8(s0 >> 16)] ^ te2[u8(s1 >> 8)] ^ u32(te3[u8(s2)])
|
||||||
k += 4
|
k += 4
|
||||||
s0 = t0
|
s0 = t0
|
||||||
s1 = t1
|
s1 = t1
|
||||||
|
@ -105,10 +105,10 @@ fn decrypt_block_generic(xk []u32, mut dst []byte, src []byte) {
|
||||||
mut t2 := u32(0)
|
mut t2 := u32(0)
|
||||||
mut t3 := u32(0)
|
mut t3 := u32(0)
|
||||||
for _ in 0 .. nr {
|
for _ in 0 .. nr {
|
||||||
t0 = xk[k + 0] ^ td0[byte(s0 >> 24)] ^ td1[byte(s3 >> 16)] ^ td2[byte(s2 >> 8)] ^ u32(td3[byte(s1)])
|
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[byte(s1 >> 24)] ^ td1[byte(s0 >> 16)] ^ td2[byte(s3 >> 8)] ^ u32(td3[byte(s2)])
|
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[byte(s2 >> 24)] ^ td1[byte(s1 >> 16)] ^ td2[byte(s0 >> 8)] ^ u32(td3[byte(s3)])
|
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[byte(s3 >> 24)] ^ td1[byte(s2 >> 16)] ^ td2[byte(s1 >> 8)] ^ u32(td3[byte(s0)])
|
t3 = xk[k + 3] ^ td0[u8(s3 >> 24)] ^ td1[u8(s2 >> 16)] ^ td2[u8(s1 >> 8)] ^ u32(td3[u8(s0)])
|
||||||
k += 4
|
k += 4
|
||||||
s0 = t0
|
s0 = t0
|
||||||
s1 = t1
|
s1 = t1
|
||||||
|
|
|
@ -29,7 +29,7 @@ const (
|
||||||
// Powers of x mod poly in GF(2).
|
// Powers of x mod poly in GF(2).
|
||||||
const (
|
const (
|
||||||
pow_x = [
|
pow_x = [
|
||||||
byte(0x01),
|
u8(0x01),
|
||||||
0x02,
|
0x02,
|
||||||
0x04,
|
0x04,
|
||||||
0x08,
|
0x08,
|
||||||
|
@ -51,7 +51,7 @@ const (
|
||||||
// FIPS-197 Figure 7. S-box substitution values in hexadecimal format.
|
// FIPS-197 Figure 7. S-box substitution values in hexadecimal format.
|
||||||
const (
|
const (
|
||||||
s_box0 = [
|
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,
|
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,
|
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,
|
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.
|
// FIPS-197 Figure 14. Inverse S-box substitution values in hexadecimal format.
|
||||||
const (
|
const (
|
||||||
s_box1 = [
|
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,
|
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,
|
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,
|
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
|
||||||
|
|
|
@ -27,13 +27,13 @@ mut:
|
||||||
minor string
|
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]
|
0x6c, 0x64, 0x65, 0x72, 0x53, 0x63, 0x72, 0x79, 0x44, 0x6f, 0x75, 0x62, 0x74]
|
||||||
|
|
||||||
// generate_from_password return a bcrypt string from Hashed struct.
|
// generate_from_password return a bcrypt string from Hashed struct.
|
||||||
pub fn generate_from_password(password []byte, cost int) ?string {
|
pub fn generate_from_password(password []byte, cost int) ?string {
|
||||||
mut p := new_from_password(password, cost) or { return error('Error: $err') }
|
mut p := new_from_password(password, cost) or { return error('Error: $err') }
|
||||||
x := p.hash_byte()
|
x := p.hash_u8()
|
||||||
return x.bytestr()
|
return x.bytestr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ pub fn compare_hash_and_password(password []byte, hashed_password []byte) ? {
|
||||||
minor: p.minor
|
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')
|
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.
|
// 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}
|
mut arr := []byte{len: 65, init: 0}
|
||||||
arr[0] = `$`
|
arr[0] = `$`
|
||||||
arr[1] = h.major[0]
|
arr[1] = h.major[0]
|
||||||
|
|
|
@ -89,38 +89,38 @@ fn setup_tables(l u32, r u32, mut bf Blowfish) []u32 {
|
||||||
mut xl := l
|
mut xl := l
|
||||||
mut xr := r
|
mut xr := r
|
||||||
xl ^= bf.p[0]
|
xl ^= bf.p[0]
|
||||||
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
|
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
|
||||||
(bf.s[3][byte(xl)] ^ bf.p[1])
|
(bf.s[3][u8(xl)] ^ bf.p[1])
|
||||||
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
|
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
|
||||||
(bf.s[3][byte(xr)] ^ bf.p[2])
|
(bf.s[3][u8(xr)] ^ bf.p[2])
|
||||||
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
|
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
|
||||||
(bf.s[3][byte(xl)] ^ bf.p[3])
|
(bf.s[3][u8(xl)] ^ bf.p[3])
|
||||||
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
|
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
|
||||||
(bf.s[3][byte(xr)] ^ bf.p[4])
|
(bf.s[3][u8(xr)] ^ bf.p[4])
|
||||||
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
|
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
|
||||||
(bf.s[3][byte(xl)] ^ bf.p[5])
|
(bf.s[3][u8(xl)] ^ bf.p[5])
|
||||||
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
|
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
|
||||||
(bf.s[3][byte(xr)] ^ bf.p[6])
|
(bf.s[3][u8(xr)] ^ bf.p[6])
|
||||||
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
|
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
|
||||||
(bf.s[3][byte(xl)] ^ bf.p[7])
|
(bf.s[3][u8(xl)] ^ bf.p[7])
|
||||||
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
|
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
|
||||||
(bf.s[3][byte(xr)] ^ bf.p[8])
|
(bf.s[3][u8(xr)] ^ bf.p[8])
|
||||||
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
|
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
|
||||||
(bf.s[3][byte(xl)] ^ bf.p[9])
|
(bf.s[3][u8(xl)] ^ bf.p[9])
|
||||||
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
|
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
|
||||||
(bf.s[3][byte(xr)] ^ bf.p[10])
|
(bf.s[3][u8(xr)] ^ bf.p[10])
|
||||||
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
|
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
|
||||||
(bf.s[3][byte(xl)] ^ bf.p[11])
|
(bf.s[3][u8(xl)] ^ bf.p[11])
|
||||||
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
|
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
|
||||||
(bf.s[3][byte(xr)] ^ bf.p[12])
|
(bf.s[3][u8(xr)] ^ bf.p[12])
|
||||||
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
|
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
|
||||||
(bf.s[3][byte(xl)] ^ bf.p[13])
|
(bf.s[3][u8(xl)] ^ bf.p[13])
|
||||||
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
|
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
|
||||||
(bf.s[3][byte(xr)] ^ bf.p[14])
|
(bf.s[3][u8(xr)] ^ bf.p[14])
|
||||||
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
|
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
|
||||||
(bf.s[3][byte(xl)] ^ bf.p[15])
|
(bf.s[3][u8(xl)] ^ bf.p[15])
|
||||||
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
|
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
|
||||||
(bf.s[3][byte(xr)] ^ bf.p[16])
|
(bf.s[3][u8(xr)] ^ bf.p[16])
|
||||||
xr ^= bf.p[17]
|
xr ^= bf.p[17]
|
||||||
res := [xl, xr]
|
res := [xl, xr]
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -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])
|
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])
|
r := u32(src[4]) << 24 | u32(src[5]) << 16 | u32(src[6]) << 8 | u32(src[7])
|
||||||
arr := setup_tables(l, r, mut bf)
|
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[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] = byte(arr[1] >> 24), byte(arr[1] >> 16), byte(arr[1] >> 8), byte(arr[1])
|
dst[4], dst[5], dst[6], dst[7] = u8(arr[1] >> 24), u8(arr[1] >> 16), u8(arr[1] >> 8), u8(arr[1])
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,35 +10,35 @@
|
||||||
module des
|
module des
|
||||||
|
|
||||||
// Used to perform an initial permutation of a 64-bit input block.
|
// 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,
|
// 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]
|
// 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
|
// // Used to perform a final permutation of a 4-bit preoutput block. This is the
|
||||||
// // inverse of initialPermutation
|
// // 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,
|
// 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]
|
// 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
|
// // Used to expand an input block of 32 bits, producing an output block of 48
|
||||||
// // bits.
|
// // 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,
|
// 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]
|
// 3, 4, 3, 2, 1, 0, 31]
|
||||||
|
|
||||||
// // Yields a 32-bit output from a 32-bit input
|
// // 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]
|
// 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
|
// Used in the key schedule to select 56 bits
|
||||||
// from a 64-bit input.
|
// 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,
|
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]
|
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
|
// Used in the key schedule to produce each subkey by selecting 48 bits from
|
||||||
// the 56-bit input
|
// 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,
|
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]
|
3, 10, 14, 6, 20, 27, 24]
|
||||||
|
|
||||||
|
|
|
@ -63,13 +63,13 @@ fn test_malleability() ? {
|
||||||
// https://tools.ietf.org/html/rfc8032#section-5.1.7 adds an additional test
|
// 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
|
// 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.
|
// order to s and obtaining a second valid signature for the same message.
|
||||||
msg := [byte(0x54), 0x65, 0x73, 0x74]
|
msg := [u8(0x54), 0x65, 0x73, 0x74]
|
||||||
sig := [byte(0x7c), 0x38, 0xe0, 0x26, 0xf2, 0x9e, 0x14, 0xaa, 0xbd, 0x05, 0x9a, 0x0f, 0x2d,
|
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,
|
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,
|
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,
|
0x5d, 0xaf, 0xc0, 0x8d, 0x93, 0x39, 0xd4, 0xee, 0xf6, 0x76, 0x57, 0x33, 0x36, 0xa5, 0xc5,
|
||||||
0x1e, 0xb6, 0xf9, 0x46, 0xb3, 0x1d]
|
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,
|
0xab, 0xbe, 0xe6, 0x85, 0xfd, 0xa4, 0x42, 0x0f, 0x88, 0x34, 0xb1, 0x08, 0xc3, 0xbd, 0xae,
|
||||||
0x36, 0x9e, 0xf5, 0x49, 0xfa]
|
0x36, 0x9e, 0xf5, 0x49, 0xfa]
|
||||||
// verify should fail on provided bytes
|
// verify should fail on provided bytes
|
||||||
|
|
|
@ -237,12 +237,12 @@ fn test_set_bytes_from_dalek_test_vectors() ? {
|
||||||
mut tests := [
|
mut tests := [
|
||||||
FeRTTest{
|
FeRTTest{
|
||||||
fe: Element{358744748052810, 1691584618240980, 977650209285361, 1429865912637724, 560044844278676}
|
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]
|
74, 222, 56, 50, 153, 51, 233, 40, 74, 57, 6, 160, 185, 213, 31]
|
||||||
},
|
},
|
||||||
FeRTTest{
|
FeRTTest{
|
||||||
fe: Element{84926274344903, 473620666599931, 365590438845504, 1028470286882429, 2146499180330972}
|
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]
|
32, 83, 250, 44, 57, 204, 198, 78, 199, 253, 119, 146, 172, 3, 122]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
|
@ -90,7 +90,7 @@ fn fn_cofactor(mut data []byte) bool {
|
||||||
mut sc := Scalar{
|
mut sc := Scalar{
|
||||||
s: [32]byte{}
|
s: [32]byte{}
|
||||||
}
|
}
|
||||||
sc.s[0] = byte(0x08)
|
sc.s[0] = u8(0x08)
|
||||||
s.multiply(s, sc)
|
s.multiply(s, sc)
|
||||||
mut pp := Point{}
|
mut pp := Point{}
|
||||||
pp.scalar_base_mult(mut s)
|
pp.scalar_base_mult(mut s)
|
||||||
|
|
|
@ -2,12 +2,12 @@ module edwards25519
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// d is a constant in the curve equation.
|
// 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,
|
0x4d, 0x0a, 0x70, 0x00, 0x98, 0xe8, 0x79, 0x77, 0x79, 0x40, 0xc7, 0x8c, 0x73, 0xfe, 0x6f,
|
||||||
0x2b, 0xee, 0x6c, 0x03, 0x52]
|
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]
|
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, 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) }
|
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)
|
mut out := copy_field_element(mut buf, mut y)
|
||||||
unsafe {
|
unsafe {
|
||||||
// out[31] |= byte(x.is_negative() << 7) //original one
|
// out[31] |= u8(x.is_negative() << 7) //original one
|
||||||
out[31] |= byte(x.is_negative() * 128) // x << 7 == x * 2^7
|
out[31] |= u8(x.is_negative() * 128) // x << 7 == x * 2^7
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,17 +23,17 @@ mut:
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
sc_zero = Scalar{
|
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]!
|
0, 0, 0, 0, 0, 0]!
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_one = Scalar{
|
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]!
|
0, 0, 0, 0, 0, 0]!
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_minus_one = Scalar{
|
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]!
|
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]
|
s11 += carry[10]
|
||||||
s10 -= carry[10] * 2097152
|
s10 -= carry[10] * 2097152
|
||||||
|
|
||||||
s[0] = byte(s0 >> 0)
|
s[0] = u8(s0 >> 0)
|
||||||
s[1] = byte(s0 >> 8)
|
s[1] = u8(s0 >> 8)
|
||||||
s[2] = byte((s0 >> 16) | (s1 * 32))
|
s[2] = u8((s0 >> 16) | (s1 * 32))
|
||||||
s[3] = byte(s1 >> 3)
|
s[3] = u8(s1 >> 3)
|
||||||
s[4] = byte(s1 >> 11)
|
s[4] = u8(s1 >> 11)
|
||||||
s[5] = byte((s1 >> 19) | (s2 * 4))
|
s[5] = u8((s1 >> 19) | (s2 * 4))
|
||||||
s[6] = byte(s2 >> 6)
|
s[6] = u8(s2 >> 6)
|
||||||
s[7] = byte((s2 >> 14) | (s3 * 128))
|
s[7] = u8((s2 >> 14) | (s3 * 128))
|
||||||
s[8] = byte(s3 >> 1)
|
s[8] = u8(s3 >> 1)
|
||||||
s[9] = byte(s3 >> 9)
|
s[9] = u8(s3 >> 9)
|
||||||
s[10] = byte((s3 >> 17) | (s4 * 16))
|
s[10] = u8((s3 >> 17) | (s4 * 16))
|
||||||
s[11] = byte(s4 >> 4)
|
s[11] = u8(s4 >> 4)
|
||||||
s[12] = byte(s4 >> 12)
|
s[12] = u8(s4 >> 12)
|
||||||
s[13] = byte((s4 >> 20) | (s5 * 2))
|
s[13] = u8((s4 >> 20) | (s5 * 2))
|
||||||
s[14] = byte(s5 >> 7)
|
s[14] = u8(s5 >> 7)
|
||||||
s[15] = byte((s5 >> 15) | (s6 * 64))
|
s[15] = u8((s5 >> 15) | (s6 * 64))
|
||||||
s[16] = byte(s6 >> 2)
|
s[16] = u8(s6 >> 2)
|
||||||
s[17] = byte(s6 >> 10)
|
s[17] = u8(s6 >> 10)
|
||||||
s[18] = byte((s6 >> 18) | (s7 * 8))
|
s[18] = u8((s6 >> 18) | (s7 * 8))
|
||||||
s[19] = byte(s7 >> 5)
|
s[19] = u8(s7 >> 5)
|
||||||
s[20] = byte(s7 >> 13)
|
s[20] = u8(s7 >> 13)
|
||||||
s[21] = byte(s8 >> 0)
|
s[21] = u8(s8 >> 0)
|
||||||
s[22] = byte(s8 >> 8)
|
s[22] = u8(s8 >> 8)
|
||||||
s[23] = byte((s8 >> 16) | (s9 * 32))
|
s[23] = u8((s8 >> 16) | (s9 * 32))
|
||||||
s[24] = byte(s9 >> 3)
|
s[24] = u8(s9 >> 3)
|
||||||
s[25] = byte(s9 >> 11)
|
s[25] = u8(s9 >> 11)
|
||||||
s[26] = byte((s9 >> 19) | (s10 * 4))
|
s[26] = u8((s9 >> 19) | (s10 * 4))
|
||||||
s[27] = byte(s10 >> 6)
|
s[27] = u8(s10 >> 6)
|
||||||
s[28] = byte((s10 >> 14) | (s11 * 128))
|
s[28] = u8((s10 >> 14) | (s11 * 128))
|
||||||
s[29] = byte(s11 >> 1)
|
s[29] = u8(s11 >> 1)
|
||||||
s[30] = byte(s11 >> 9)
|
s[30] = u8(s11 >> 9)
|
||||||
s[31] = byte(s11 >> 17)
|
s[31] = u8(s11 >> 17)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input:
|
// Input:
|
||||||
|
@ -940,38 +940,38 @@ fn sc_reduce(mut out [32]byte, mut s []byte) {
|
||||||
s11 += carry[10]
|
s11 += carry[10]
|
||||||
s10 -= carry[10] * 2097152
|
s10 -= carry[10] * 2097152
|
||||||
|
|
||||||
out[0] = byte(s0 >> 0)
|
out[0] = u8(s0 >> 0)
|
||||||
out[1] = byte(s0 >> 8)
|
out[1] = u8(s0 >> 8)
|
||||||
out[2] = byte((s0 >> 16) | (s1 * 32))
|
out[2] = u8((s0 >> 16) | (s1 * 32))
|
||||||
out[3] = byte(s1 >> 3)
|
out[3] = u8(s1 >> 3)
|
||||||
out[4] = byte(s1 >> 11)
|
out[4] = u8(s1 >> 11)
|
||||||
out[5] = byte((s1 >> 19) | (s2 * 4))
|
out[5] = u8((s1 >> 19) | (s2 * 4))
|
||||||
out[6] = byte(s2 >> 6)
|
out[6] = u8(s2 >> 6)
|
||||||
out[7] = byte((s2 >> 14) | (s3 * 128))
|
out[7] = u8((s2 >> 14) | (s3 * 128))
|
||||||
out[8] = byte(s3 >> 1)
|
out[8] = u8(s3 >> 1)
|
||||||
out[9] = byte(s3 >> 9)
|
out[9] = u8(s3 >> 9)
|
||||||
out[10] = byte((s3 >> 17) | (s4 * 16))
|
out[10] = u8((s3 >> 17) | (s4 * 16))
|
||||||
out[11] = byte(s4 >> 4)
|
out[11] = u8(s4 >> 4)
|
||||||
out[12] = byte(s4 >> 12)
|
out[12] = u8(s4 >> 12)
|
||||||
out[13] = byte((s4 >> 20) | (s5 * 2))
|
out[13] = u8((s4 >> 20) | (s5 * 2))
|
||||||
out[14] = byte(s5 >> 7)
|
out[14] = u8(s5 >> 7)
|
||||||
out[15] = byte((s5 >> 15) | (s6 * 64))
|
out[15] = u8((s5 >> 15) | (s6 * 64))
|
||||||
out[16] = byte(s6 >> 2)
|
out[16] = u8(s6 >> 2)
|
||||||
out[17] = byte(s6 >> 10)
|
out[17] = u8(s6 >> 10)
|
||||||
out[18] = byte((s6 >> 18) | (s7 * 8))
|
out[18] = u8((s6 >> 18) | (s7 * 8))
|
||||||
out[19] = byte(s7 >> 5)
|
out[19] = u8(s7 >> 5)
|
||||||
out[20] = byte(s7 >> 13)
|
out[20] = u8(s7 >> 13)
|
||||||
out[21] = byte(s8 >> 0)
|
out[21] = u8(s8 >> 0)
|
||||||
out[22] = byte(s8 >> 8)
|
out[22] = u8(s8 >> 8)
|
||||||
out[23] = byte((s8 >> 16) | (s9 * 32))
|
out[23] = u8((s8 >> 16) | (s9 * 32))
|
||||||
out[24] = byte(s9 >> 3)
|
out[24] = u8(s9 >> 3)
|
||||||
out[25] = byte(s9 >> 11)
|
out[25] = u8(s9 >> 11)
|
||||||
out[26] = byte((s9 >> 19) | (s10 * 4))
|
out[26] = u8((s9 >> 19) | (s10 * 4))
|
||||||
out[27] = byte(s10 >> 6)
|
out[27] = u8(s10 >> 6)
|
||||||
out[28] = byte((s10 >> 14) | (s11 * 128))
|
out[28] = u8((s10 >> 14) | (s11 * 128))
|
||||||
out[29] = byte(s11 >> 1)
|
out[29] = u8(s11 >> 1)
|
||||||
out[30] = byte(s11 >> 9)
|
out[30] = u8(s11 >> 9)
|
||||||
out[31] = byte(s11 >> 17)
|
out[31] = u8(s11 >> 17)
|
||||||
}
|
}
|
||||||
|
|
||||||
// non_adjacent_form computes a width-w non-adjacent form for this scalar.
|
// non_adjacent_form computes a width-w non-adjacent form for this scalar.
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn test_scalar_equal() {
|
||||||
|
|
||||||
fn test_scalar_non_adjacent_form() {
|
fn test_scalar_non_adjacent_form() {
|
||||||
mut s := Scalar{
|
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,
|
0xd8, 0x26, 0x4d, 0xa7, 0x58, 0xaa, 0x1b, 0x88, 0xe0, 0x40, 0xd1, 0x58, 0x9e, 0x7b,
|
||||||
0x7f, 0x23, 0x76, 0xef, 0x09]!
|
0x7f, 0x23, 0x76, 0xef, 0x09]!
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ fn test_scalar_set_canonical_bytes_round_trip() ? {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sc_error = Scalar{
|
sc_error = Scalar{
|
||||||
s: [32]byte{init: (byte(-1))}
|
s: [32]byte{init: (u8(-1))}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
module edwards25519
|
module edwards25519
|
||||||
|
|
||||||
const (
|
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]!}
|
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,
|
0xf9, 0x46, 0x9, 0x91, 0x1c, 0xb9, 0xc0, 0x6c, 0x17, 0x28, 0x2d, 0x8b, 0x43, 0x2b, 0x5,
|
||||||
0x18, 0x6a, 0x54, 0x3e, 0x48]
|
0x18, 0x6a, 0x54, 0x3e, 0x48]
|
||||||
)
|
)
|
||||||
|
@ -24,7 +24,7 @@ fn test_scalar_mult_small_scalars() {
|
||||||
assert i.equal(p) == 1
|
assert i.equal(p) == 1
|
||||||
assert check_on_curve(p) == true
|
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]!}
|
0, 0, 0, 0, 0, 0, 0]!}
|
||||||
p.scalar_mult(mut z, b)
|
p.scalar_mult(mut z, b)
|
||||||
|
|
||||||
|
|
|
@ -88,12 +88,12 @@ fn (mut v NafLookupTable8) from_p3(q Point) {
|
||||||
fn (mut v ProjLookupTable) select_into(mut dest ProjectiveCached, x i8) {
|
fn (mut v ProjLookupTable) select_into(mut dest ProjectiveCached, x i8) {
|
||||||
// Compute xabs = |x|
|
// Compute xabs = |x|
|
||||||
xmask := x >> 7
|
xmask := x >> 7
|
||||||
xabs := byte((x + xmask) ^ xmask)
|
xabs := u8((x + xmask) ^ xmask)
|
||||||
|
|
||||||
dest.zero()
|
dest.zero()
|
||||||
for j := 1; j <= 8; j++ {
|
for j := 1; j <= 8; j++ {
|
||||||
// Set dest = j*Q if |x| = 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)
|
dest.selected(&v.points[j - 1], dest, cond)
|
||||||
}
|
}
|
||||||
// Now dest = |x|*Q, conditionally negate to get x*Q
|
// 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) {
|
fn (mut v AffineLookupTable) select_into(mut dest AffineCached, x i8) {
|
||||||
// Compute xabs = |x|
|
// Compute xabs = |x|
|
||||||
xmask := x >> 7
|
xmask := x >> 7
|
||||||
xabs := byte((x + xmask) ^ xmask)
|
xabs := u8((x + xmask) ^ xmask)
|
||||||
|
|
||||||
dest.zero()
|
dest.zero()
|
||||||
for j := 1; j <= 8; j++ {
|
for j := 1; j <= 8; j++ {
|
||||||
// Set dest = j*Q if |x| = 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)
|
dest.selected(v.points[j - 1], dest, cond)
|
||||||
}
|
}
|
||||||
// Now dest = |x|*Q, conditionally negate to get x*Q
|
// Now dest = |x|*Q, conditionally negate to get x*Q
|
||||||
|
|
|
@ -21,21 +21,21 @@ import crypto.sha512
|
||||||
// import crypto.blake2b_512
|
// import crypto.blake2b_512
|
||||||
const (
|
const (
|
||||||
keys = [
|
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(),
|
'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],
|
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],
|
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],
|
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, 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,
|
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],
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa],
|
||||||
]
|
]
|
||||||
data = ['Hi There'.bytes(), 'what do ya want for nothing?'.bytes(),
|
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, 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, 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],
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub fn constant_time_compare(x []byte, y []byte) int {
|
||||||
if x.len != y.len {
|
if x.len != y.len {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
mut v := byte(0)
|
mut v := u8(0)
|
||||||
for i in 0 .. x.len {
|
for i in 0 .. x.len {
|
||||||
v |= x[i] ^ y[i]
|
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 {
|
if x.len != y.len {
|
||||||
panic('subtle: arrays have different lengths')
|
panic('subtle: arrays have different lengths')
|
||||||
}
|
}
|
||||||
xmask := byte(v - 1)
|
xmask := u8(v - 1)
|
||||||
ymask := byte(~(v - 1))
|
ymask := u8(~(v - 1))
|
||||||
for i := 0; i < x.len; i++ {
|
for i := 0; i < x.len; i++ {
|
||||||
x[i] = x[i] & xmask | y[i] & ymask
|
x[i] = x[i] & xmask | y[i] & ymask
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,20 +35,20 @@ fn test_constant_time_select() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_constant_time_compare() {
|
fn test_constant_time_compare() {
|
||||||
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3]) == 1
|
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 3]) == 1
|
||||||
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 9]) == 0
|
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 9]) == 0
|
||||||
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3, 4]) == 0
|
assert constant_time_compare([u8(1), 2, 3], [u8(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]) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_constant_time_copy() {
|
fn test_constant_time_copy() {
|
||||||
y := [byte(3), 4, 5]
|
y := [u8(3), 4, 5]
|
||||||
mut x := [byte(0), 0, 0]
|
mut x := [u8(0), 0, 0]
|
||||||
constant_time_copy(0, mut x, y)
|
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)
|
constant_time_copy(1, mut x, y)
|
||||||
assert x == y
|
assert x == y
|
||||||
assert x == [byte(3), 4, 5]
|
assert x == [u8(3), 4, 5]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_constant_time_less_or_eq() {
|
fn test_constant_time_less_or_eq() {
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub fn int_u64(max u64) ?u64 {
|
||||||
mut n := u64(0)
|
mut n := u64(0)
|
||||||
for {
|
for {
|
||||||
mut bytes := read(k) ?
|
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)
|
x := bytes_to_u64(bytes)
|
||||||
n = x[0]
|
n = x[0]
|
||||||
// NOTE: maybe until we have bigint could do it another way?
|
// NOTE: maybe until we have bigint could do it another way?
|
||||||
|
|
|
@ -32,9 +32,9 @@ pub fn new_cipher(key []byte) ?Cipher {
|
||||||
for i in 0 .. 256 {
|
for i in 0 .. 256 {
|
||||||
c.s[i] = u32(i)
|
c.s[i] = u32(i)
|
||||||
}
|
}
|
||||||
mut j := byte(0)
|
mut j := u8(0)
|
||||||
for i in 0 .. 256 {
|
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]
|
tmp := c.s[i]
|
||||||
c.s[i] = c.s[j]
|
c.s[i] = c.s[j]
|
||||||
c.s[j] = tmp
|
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 i := c.i
|
||||||
mut j := c.j
|
mut j := c.j
|
||||||
for k, v in src {
|
for k, v in src {
|
||||||
i += byte(1)
|
i += u8(1)
|
||||||
x := c.s[i]
|
x := c.s[i]
|
||||||
j += byte(x)
|
j += u8(x)
|
||||||
y := c.s[j]
|
y := c.s[j]
|
||||||
c.s[i] = y
|
c.s[i] = y
|
||||||
c.s[j] = x
|
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.i = i
|
||||||
c.j = j
|
c.j = j
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub fn encode_walpha(input string, alphabet Alphabet) string {
|
||||||
i = sz - 1
|
i = sz - 1
|
||||||
for carry = u32(b); i > high || carry != 0; i-- {
|
for carry = u32(b); i > high || carry != 0; i-- {
|
||||||
carry = carry + 256 * u32(out[i])
|
carry = carry + 256 * u32(out[i])
|
||||||
out[i] = byte(carry % 58)
|
out[i] = u8(carry % 58)
|
||||||
carry /= 58
|
carry /= 58
|
||||||
}
|
}
|
||||||
high = 1
|
high = 1
|
||||||
|
@ -94,7 +94,7 @@ pub fn decode_int_walpha(input string, alphabet Alphabet) ?int {
|
||||||
mut total := 0 // to hold the results
|
mut total := 0 // to hold the results
|
||||||
b58 := input.reverse()
|
b58 := input.reverse()
|
||||||
for i, ch in b58 {
|
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 {
|
if ch_i == -1 {
|
||||||
return error(@MOD + '.' + @FN +
|
return error(@MOD + '.' + @FN +
|
||||||
': input string contains values not found in the provided alphabet')
|
': 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
|
mut out_len := 0
|
||||||
for j := 0; j < outi.len; j++ {
|
for j := 0; j < outi.len; j++ {
|
||||||
for mask < 32 {
|
for mask < 32 {
|
||||||
binu[out_len] = byte(outi[j] >> mask)
|
binu[out_len] = u8(outi[j] >> mask)
|
||||||
mask -= 8
|
mask -= 8
|
||||||
out_len++
|
out_len++
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,11 +57,11 @@ fn encode_from_buffer(dest &byte, src &byte, src_len int) int {
|
||||||
match remain {
|
match remain {
|
||||||
2 {
|
2 {
|
||||||
b[di + 2] = etable[val >> 6 & 0x3F]
|
b[di + 2] = etable[val >> 6 & 0x3F]
|
||||||
b[di + 3] = byte(`=`)
|
b[di + 3] = u8(`=`)
|
||||||
}
|
}
|
||||||
1 {
|
1 {
|
||||||
b[di + 2] = byte(`=`)
|
b[di + 2] = u8(`=`)
|
||||||
b[di + 3] = byte(`=`)
|
b[di + 3] = u8(`=`)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
panic('base64: This case should never occur.')
|
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 {
|
for src_len - si >= 8 {
|
||||||
// Converting 8 bytes of input into 6 bytes of output. Storing these in the upper bytes of an u64.
|
// 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]]),
|
datablock_64.data = assemble64(u8(index[d[si + 0]]), u8(index[d[si + 1]]),
|
||||||
byte(index[d[si + 2]]), byte(index[d[si + 3]]), byte(index[d[si + 4]]),
|
u8(index[d[si + 2]]), u8(index[d[si + 3]]), u8(index[d[si + 4]]),
|
||||||
byte(index[d[si + 5]]), byte(index[d[si + 6]]), byte(index[d[si + 7]]))
|
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.
|
// Reading out the individual bytes from the u64. Watch out with endianess.
|
||||||
$if little_endian {
|
$if little_endian {
|
||||||
|
@ -151,8 +151,8 @@ fn decode_from_buffer(dest &byte, src &byte, src_len int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
for src_len - si >= 4 {
|
for src_len - si >= 4 {
|
||||||
datablock_32.data = assemble32(byte(index[d[si + 0]]), byte(index[d[si + 1]]),
|
datablock_32.data = assemble32(u8(index[d[si + 0]]), u8(index[d[si + 1]]),
|
||||||
byte(index[d[si + 2]]), byte(index[d[si + 3]]))
|
u8(index[d[si + 2]]), u8(index[d[si + 3]]))
|
||||||
$if little_endian {
|
$if little_endian {
|
||||||
b[n_decoded_bytes + 0] = datablock_32.data_byte[3]
|
b[n_decoded_bytes + 0] = datablock_32.data_byte[3]
|
||||||
b[n_decoded_bytes + 1] = datablock_32.data_byte[2]
|
b[n_decoded_bytes + 1] = datablock_32.data_byte[2]
|
||||||
|
|
|
@ -111,23 +111,23 @@ fn test_url_decode_str() {
|
||||||
assert test == 'Hello Base64Url encoding!'
|
assert test == 'Hello Base64Url encoding!'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_encode_null_byte() {
|
fn test_encode_null_u8() {
|
||||||
assert base64.encode([byte(`A`), 0, `C`]) == 'QQBD'
|
assert base64.encode([u8(`A`), 0, `C`]) == 'QQBD'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_encode_null_byte_str() {
|
fn test_encode_null_byte_str() {
|
||||||
// While this works, bytestr() does a memcpy
|
// 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'
|
assert base64.encode_str(s) == 'QQBD'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_decode_null_byte() {
|
fn test_decode_null_u8() {
|
||||||
assert base64.decode('QQBD') == [byte(`A`), 0, `C`]
|
assert base64.decode('QQBD') == [u8(`A`), 0, `C`]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_decode_null_byte_str() {
|
fn test_decode_null_byte_str() {
|
||||||
// While this works, bytestr() does a memcpy
|
// 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
|
assert base64.decode_str('QQBD') == s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ pub fn little_endian_u16(b []byte) u16 {
|
||||||
[inline]
|
[inline]
|
||||||
pub fn little_endian_put_u16(mut b []byte, v u16) {
|
pub fn little_endian_put_u16(mut b []byte, v u16) {
|
||||||
_ = b[1] // bounds check
|
_ = b[1] // bounds check
|
||||||
b[0] = byte(v)
|
b[0] = u8(v)
|
||||||
b[1] = byte(v >> u16(8))
|
b[1] = u8(v >> u16(8))
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
@ -26,10 +26,10 @@ pub fn little_endian_u32(b []byte) u32 {
|
||||||
[inline]
|
[inline]
|
||||||
pub fn little_endian_put_u32(mut b []byte, v u32) {
|
pub fn little_endian_put_u32(mut b []byte, v u32) {
|
||||||
_ = b[3] // bounds check
|
_ = b[3] // bounds check
|
||||||
b[0] = byte(v)
|
b[0] = u8(v)
|
||||||
b[1] = byte(v >> u32(8))
|
b[1] = u8(v >> u32(8))
|
||||||
b[2] = byte(v >> u32(16))
|
b[2] = u8(v >> u32(16))
|
||||||
b[3] = byte(v >> u32(24))
|
b[3] = u8(v >> u32(24))
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
@ -41,14 +41,14 @@ pub fn little_endian_u64(b []byte) u64 {
|
||||||
[inline]
|
[inline]
|
||||||
pub fn little_endian_put_u64(mut b []byte, v u64) {
|
pub fn little_endian_put_u64(mut b []byte, v u64) {
|
||||||
_ = b[7] // bounds check
|
_ = b[7] // bounds check
|
||||||
b[0] = byte(v)
|
b[0] = u8(v)
|
||||||
b[1] = byte(v >> u64(8))
|
b[1] = u8(v >> u64(8))
|
||||||
b[2] = byte(v >> u64(16))
|
b[2] = u8(v >> u64(16))
|
||||||
b[3] = byte(v >> u64(24))
|
b[3] = u8(v >> u64(24))
|
||||||
b[4] = byte(v >> u64(32))
|
b[4] = u8(v >> u64(32))
|
||||||
b[5] = byte(v >> u64(40))
|
b[5] = u8(v >> u64(40))
|
||||||
b[6] = byte(v >> u64(48))
|
b[6] = u8(v >> u64(48))
|
||||||
b[7] = byte(v >> u64(56))
|
b[7] = u8(v >> u64(56))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Big Endian
|
// Big Endian
|
||||||
|
@ -61,8 +61,8 @@ pub fn big_endian_u16(b []byte) u16 {
|
||||||
[inline]
|
[inline]
|
||||||
pub fn big_endian_put_u16(mut b []byte, v u16) {
|
pub fn big_endian_put_u16(mut b []byte, v u16) {
|
||||||
_ = b[1] // bounds check
|
_ = b[1] // bounds check
|
||||||
b[0] = byte(v >> u16(8))
|
b[0] = u8(v >> u16(8))
|
||||||
b[1] = byte(v)
|
b[1] = u8(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
@ -74,10 +74,10 @@ pub fn big_endian_u32(b []byte) u32 {
|
||||||
[inline]
|
[inline]
|
||||||
pub fn big_endian_put_u32(mut b []byte, v u32) {
|
pub fn big_endian_put_u32(mut b []byte, v u32) {
|
||||||
_ = b[3] // bounds check
|
_ = b[3] // bounds check
|
||||||
b[0] = byte(v >> u32(24))
|
b[0] = u8(v >> u32(24))
|
||||||
b[1] = byte(v >> u32(16))
|
b[1] = u8(v >> u32(16))
|
||||||
b[2] = byte(v >> u32(8))
|
b[2] = u8(v >> u32(8))
|
||||||
b[3] = byte(v)
|
b[3] = u8(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
@ -89,12 +89,12 @@ pub fn big_endian_u64(b []byte) u64 {
|
||||||
[inline]
|
[inline]
|
||||||
pub fn big_endian_put_u64(mut b []byte, v u64) {
|
pub fn big_endian_put_u64(mut b []byte, v u64) {
|
||||||
_ = b[7] // bounds check
|
_ = b[7] // bounds check
|
||||||
b[0] = byte(v >> u64(56))
|
b[0] = u8(v >> u64(56))
|
||||||
b[1] = byte(v >> u64(48))
|
b[1] = u8(v >> u64(48))
|
||||||
b[2] = byte(v >> u64(40))
|
b[2] = u8(v >> u64(40))
|
||||||
b[3] = byte(v >> u64(32))
|
b[3] = u8(v >> u64(32))
|
||||||
b[4] = byte(v >> u64(24))
|
b[4] = u8(v >> u64(24))
|
||||||
b[5] = byte(v >> u64(16))
|
b[5] = u8(v >> u64(16))
|
||||||
b[6] = byte(v >> u64(8))
|
b[6] = u8(v >> u64(8))
|
||||||
b[7] = byte(v)
|
b[7] = u8(v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,9 @@ pub fn encode(bytes []byte) string {
|
||||||
// char2nibble converts an ASCII hex character to it's hex value
|
// char2nibble converts an ASCII hex character to it's hex value
|
||||||
fn char2nibble(b byte) ?byte {
|
fn char2nibble(b byte) ?byte {
|
||||||
match b {
|
match b {
|
||||||
`0`...`9` { return b - byte(`0`) }
|
`0`...`9` { return b - u8(`0`) }
|
||||||
`A`...`F` { return b - byte(`A`) + 10 }
|
`A`...`F` { return b - u8(`A`) + 10 }
|
||||||
`a`...`f` { return b - byte(`a`) + 10 }
|
`a`...`f` { return b - u8(`a`) + 10 }
|
||||||
else { return error('invalid hex char $b.ascii_str()') }
|
else { return error('invalid hex char $b.ascii_str()') }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,15 @@ module hex
|
||||||
|
|
||||||
fn test_decode() ? {
|
fn test_decode() ? {
|
||||||
assert decode('') ? == []
|
assert decode('') ? == []
|
||||||
assert decode('0') ? == [byte(0x0)]
|
assert decode('0') ? == [u8(0x0)]
|
||||||
assert decode('f') ? == [byte(0xf)]
|
assert decode('f') ? == [u8(0xf)]
|
||||||
assert decode('0f') ? == [byte(0x0f)]
|
assert decode('0f') ? == [u8(0x0f)]
|
||||||
assert decode('ff') ? == [byte(0xff)]
|
assert decode('ff') ? == [u8(0xff)]
|
||||||
assert decode('123') ? == [byte(0x1), 0x23]
|
assert decode('123') ? == [u8(0x1), 0x23]
|
||||||
assert decode('1234') ? == [byte(0x12), 0x34]
|
assert decode('1234') ? == [u8(0x12), 0x34]
|
||||||
assert decode('12345') ? == [byte(0x1), 0x23, 0x45]
|
assert decode('12345') ? == [u8(0x1), 0x23, 0x45]
|
||||||
assert decode('0123456789abcdef') ? == [byte(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
assert decode('0123456789abcdef') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||||
assert decode('123456789ABCDEF') ? == [byte(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
assert decode('123456789ABCDEF') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_decode_fails() ? {
|
fn test_decode_fails() ? {
|
||||||
|
@ -46,9 +46,9 @@ fn test_encode() ? {
|
||||||
|
|
||||||
fn test_decode_0x() ? {
|
fn test_decode_0x() ? {
|
||||||
assert decode('0x') ? == []
|
assert decode('0x') ? == []
|
||||||
assert decode('0x0') ? == [byte(0x0)]
|
assert decode('0x0') ? == [u8(0x0)]
|
||||||
assert decode('0X1234') ? == [byte(0x12), 0x34]
|
assert decode('0X1234') ? == [u8(0x12), 0x34]
|
||||||
assert decode('0x12345') ? == [byte(0x1), 0x23, 0x45]
|
assert decode('0x12345') ? == [u8(0x1), 0x23, 0x45]
|
||||||
assert decode('0x0123456789abcdef') ? == [byte(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
assert decode('0x0123456789abcdef') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||||
assert decode('0X123456789ABCDEF') ? == [byte(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
assert decode('0X123456789ABCDEF') ? == [u8(0x01), 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ pub fn is_control(r rune) bool {
|
||||||
if r > max_latin_1 {
|
if r > max_latin_1 {
|
||||||
return false
|
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
|
// 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`) {
|
if (r >= `a` && r <= `z`) || (r >= `A` && r <= `Z`) {
|
||||||
return true
|
return true
|
||||||
} else if r <= max_latin_1 {
|
} 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)
|
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 ch_len == 1 {
|
||||||
if upper_flag == true {
|
if upper_flag == true {
|
||||||
unsafe {
|
unsafe {
|
||||||
str_res[index] = byte(C.toupper(s.str[index]))
|
str_res[index] = u8(C.toupper(s.str[index]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsafe {
|
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 {
|
} 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 {
|
if ch_len == 2 {
|
||||||
ch0 := byte((tab_char >> 6) & 0x1f) | 0xc0 // 110x xxxx
|
ch0 := u8((tab_char >> 6) & 0x1f) | 0xc0 // 110x xxxx
|
||||||
ch1 := byte((tab_char >> 0) & 0x3f) | 0x80 // 10xx xxxx
|
ch1 := u8((tab_char >> 0) & 0x3f) | 0x80 // 10xx xxxx
|
||||||
// C.printf("[%02x%02x] \n",ch0,ch1)
|
// C.printf("[%02x%02x] \n",ch0,ch1)
|
||||||
|
|
||||||
unsafe {
|
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
|
// 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 {
|
} else if ch_len == 3 {
|
||||||
ch0 := byte((tab_char >> 12) & 0x0f) | 0xe0 // 1110 xxxx
|
ch0 := u8((tab_char >> 12) & 0x0f) | 0xe0 // 1110 xxxx
|
||||||
ch1 := byte((tab_char >> 6) & 0x3f) | 0x80 // 10xx xxxx
|
ch1 := u8((tab_char >> 6) & 0x3f) | 0x80 // 10xx xxxx
|
||||||
ch2 := byte((tab_char >> 0) & 0x3f) | 0x80 // 10xx xxxx
|
ch2 := u8((tab_char >> 0) & 0x3f) | 0x80 // 10xx xxxx
|
||||||
// C.printf("[%02x%02x%02x] \n",ch0,ch1,ch2)
|
// C.printf("[%02x%02x%02x] \n",ch0,ch1,ch2)
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -305,7 +305,7 @@ fn (mut fs FlagParser) parse_bool_value(longhand string, shorthand byte) ?string
|
||||||
fs.args.delete(i)
|
fs.args.delete(i)
|
||||||
return val
|
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
|
// -abc is equivalent to -a -b -c
|
||||||
return 'true'
|
return 'true'
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// `width` and `height` is assigned the size of the texture dimensions.
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (s &Context) get_texture_data(width &int, height &int) &byte {
|
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
|
// validate_texture fills the `dirty` argument with the pixel dimensions
|
||||||
|
|
|
@ -268,12 +268,12 @@ fn gg_event_fn(ce voidptr, user_data voidptr) {
|
||||||
}
|
}
|
||||||
if e.typ == .mouse_down {
|
if e.typ == .mouse_down {
|
||||||
bitplace := int(e.mouse_button)
|
bitplace := int(e.mouse_button)
|
||||||
ctx.mbtn_mask |= byte(1 << bitplace)
|
ctx.mbtn_mask |= u8(1 << bitplace)
|
||||||
ctx.mouse_buttons = MouseButtons(ctx.mbtn_mask)
|
ctx.mouse_buttons = MouseButtons(ctx.mbtn_mask)
|
||||||
}
|
}
|
||||||
if e.typ == .mouse_up {
|
if e.typ == .mouse_up {
|
||||||
bitplace := int(e.mouse_button)
|
bitplace := int(e.mouse_button)
|
||||||
ctx.mbtn_mask &= ~(byte(1 << bitplace))
|
ctx.mbtn_mask &= ~(u8(1 << bitplace))
|
||||||
ctx.mouse_buttons = MouseButtons(ctx.mbtn_mask)
|
ctx.mouse_buttons = MouseButtons(ctx.mbtn_mask)
|
||||||
}
|
}
|
||||||
if e.typ == .mouse_move && e.mouse_button == .invalid {
|
if e.typ == .mouse_move && e.mouse_button == .invalid {
|
||||||
|
|
|
@ -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_dx = int(event.movementX)
|
||||||
e.mouse_dy = int(event.movementY)
|
e.mouse_dy = int(event.movementY)
|
||||||
bitplace := int(event.button)
|
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_buttons = MouseButtons(g.mbtn_mask)
|
||||||
|
|
||||||
g.mouse_pos_x = int(event.offsetX)
|
g.mouse_pos_x = int(event.offsetX)
|
||||||
|
|
|
@ -125,10 +125,10 @@ pub mut:
|
||||||
// hex takes in a 32 bit integer and splits it into 4 byte values
|
// hex takes in a 32 bit integer and splits it into 4 byte values
|
||||||
pub fn hex(color int) Color {
|
pub fn hex(color int) Color {
|
||||||
return Color{
|
return Color{
|
||||||
r: byte((color >> 24) & 0xFF)
|
r: u8((color >> 24) & 0xFF)
|
||||||
g: byte((color >> 16) & 0xFF)
|
g: u8((color >> 16) & 0xFF)
|
||||||
b: byte((color >> 8) & 0xFF)
|
b: u8((color >> 8) & 0xFF)
|
||||||
a: byte(color & 0xFF)
|
a: u8(color & 0xFF)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,10 +168,10 @@ pub fn (a Color) + (b Color) Color {
|
||||||
nb = 255
|
nb = 255
|
||||||
}
|
}
|
||||||
return Color{
|
return Color{
|
||||||
r: byte(nr)
|
r: u8(nr)
|
||||||
g: byte(ng)
|
g: u8(ng)
|
||||||
b: byte(nb)
|
b: u8(nb)
|
||||||
a: byte(na)
|
a: u8(na)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,10 +194,10 @@ pub fn (a Color) - (b Color) Color {
|
||||||
nb = 0
|
nb = 0
|
||||||
}
|
}
|
||||||
return Color{
|
return Color{
|
||||||
r: byte(nr)
|
r: u8(nr)
|
||||||
g: byte(ng)
|
g: u8(ng)
|
||||||
b: byte(nb)
|
b: u8(nb)
|
||||||
a: byte(na)
|
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
|
gr := (f32(a.g) * aa + f32(b.g) * ab * (1 - aa)) / ar
|
||||||
br := (f32(a.b) * aa + f32(b.b) * ab * (1 - aa)) / ar
|
br := (f32(a.b) * aa + f32(b.b) * ab * (1 - aa)) / ar
|
||||||
return Color{
|
return Color{
|
||||||
r: byte(rr)
|
r: u8(rr)
|
||||||
g: byte(gr)
|
g: u8(gr)
|
||||||
b: byte(br)
|
b: u8(br)
|
||||||
a: byte(ar * 255)
|
a: u8(ar * 255)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ fn (mut c Crc32) generate_table(poly int) {
|
||||||
fn (c &Crc32) sum32(b []byte) u32 {
|
fn (c &Crc32) sum32(b []byte) u32 {
|
||||||
mut crc := ~u32(0)
|
mut crc := ~u32(0)
|
||||||
for i in 0 .. b.len {
|
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
|
return ~crc
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub fn sum32(data []byte) u32 {
|
||||||
// sum32_bytes returns a fnv1a hash of the struct `s`.
|
// sum32_bytes returns a fnv1a hash of the struct `s`.
|
||||||
[direct_array_access; inline]
|
[direct_array_access; inline]
|
||||||
pub fn sum32_struct<T>(s &T) u32 {
|
pub fn sum32_struct<T>(s &T) u32 {
|
||||||
bp := unsafe { &byte(s) }
|
bp := unsafe { &u8(s) }
|
||||||
sz := int(sizeof(T))
|
sz := int(sizeof(T))
|
||||||
mut hash := fnv1a.fnv32_offset_basis
|
mut hash := fnv1a.fnv32_offset_basis
|
||||||
for i in 0 .. sz {
|
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`.
|
// sum64_bytes returns a fnv1a hash of the struct `s`.
|
||||||
[direct_array_access; inline]
|
[direct_array_access; inline]
|
||||||
pub fn sum64_struct<T>(s &T) u64 {
|
pub fn sum64_struct<T>(s &T) u64 {
|
||||||
bp := unsafe { &byte(s) }
|
bp := unsafe { &u8(s) }
|
||||||
sz := int(sizeof(T))
|
sz := int(sizeof(T))
|
||||||
mut hash := fnv1a.fnv64_offset_basis
|
mut hash := fnv1a.fnv64_offset_basis
|
||||||
for i in 0 .. sz {
|
for i in 0 .. sz {
|
||||||
|
|
|
@ -23,5 +23,5 @@ pub fn sum64_string(key string, seed u64) u64 {
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn sum64(key []byte, seed u64) u64 {
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,10 +46,10 @@ fn read_from_string(text string, capacity int) []byte {
|
||||||
|
|
||||||
pub fn test_reading_from_a_string() {
|
pub fn test_reading_from_a_string() {
|
||||||
for capacity in 1 .. 1000 {
|
for capacity in 1 .. 1000 {
|
||||||
assert read_from_string('a', capacity) == [byte(`a`)]
|
assert read_from_string('a', capacity) == [u8(`a`)]
|
||||||
assert read_from_string('ab', capacity) == [byte(`a`), `b`]
|
assert read_from_string('ab', capacity) == [u8(`a`), `b`]
|
||||||
assert read_from_string('abc', capacity) == [byte(`a`), `b`, `c`]
|
assert read_from_string('abc', capacity) == [u8(`a`), `b`, `c`]
|
||||||
assert read_from_string('abcde', capacity) == [byte(`a`), `b`, `c`, `d`, `e`]
|
assert read_from_string('abcde', capacity) == [u8(`a`), `b`, `c`, `d`, `e`]
|
||||||
large_string_bytes := []byte{len: 1000, init: `x`}
|
large_string_bytes := []byte{len: 1000, init: `x`}
|
||||||
large_string := large_string_bytes.bytestr()
|
large_string := large_string_bytes.bytestr()
|
||||||
assert read_from_string(large_string, capacity) == large_string_bytes
|
assert read_from_string(large_string, capacity) == large_string_bytes
|
||||||
|
|
|
@ -71,18 +71,18 @@ fn decode_i64(root &C.cJSON) i64 {
|
||||||
return i64(root.valuedouble) // i64 is double in C
|
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) {
|
if isnil(root) {
|
||||||
return byte(0)
|
return u8(0)
|
||||||
}
|
}
|
||||||
return byte(root.valueint)
|
return u8(root.valueint)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode_u8(root &C.cJSON) u8 {
|
fn decode_u8(root &C.cJSON) u8 {
|
||||||
if isnil(root) {
|
if isnil(root) {
|
||||||
return byte(0)
|
return u8(0)
|
||||||
}
|
}
|
||||||
return byte(root.valueint)
|
return u8(root.valueint)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode_u16(root &C.cJSON) u16 {
|
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...?
|
// 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 {
|
fn decode_string(root &C.cJSON) string {
|
||||||
|
@ -141,7 +141,7 @@ fn decode_string(root &C.cJSON) string {
|
||||||
}
|
}
|
||||||
// println('decode string valuestring="$root.valuestring"')
|
// println('decode string valuestring="$root.valuestring"')
|
||||||
// return tos(root.valuestring, _strlen(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 {
|
fn decode_bool(root &C.cJSON) bool {
|
||||||
|
@ -168,7 +168,7 @@ fn encode_i64(val i64) &C.cJSON {
|
||||||
return C.cJSON_CreateNumber(val)
|
return C.cJSON_CreateNumber(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_byte(val byte) &C.cJSON {
|
fn encode_u8(val byte) &C.cJSON {
|
||||||
return C.cJSON_CreateNumber(val)
|
return C.cJSON_CreateNumber(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,12 +217,12 @@ fn json_parse(s string) &C.cJSON {
|
||||||
// json_string := json_print(encode_User(user))
|
// json_string := json_print(encode_User(user))
|
||||||
fn json_print(json &C.cJSON) string {
|
fn json_print(json &C.cJSON) string {
|
||||||
s := C.cJSON_PrintUnformatted(json)
|
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 {
|
fn json_print_pretty(json &C.cJSON) string {
|
||||||
s := C.cJSON_Print(json)
|
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
|
// / cjson wrappers
|
||||||
|
|
|
@ -24,32 +24,32 @@ fn test_integer_from_u64() {
|
||||||
|
|
||||||
fn test_integer_from_bytes() {
|
fn test_integer_from_bytes() {
|
||||||
assert big.integer_from_bytes([]).hex() == '0'
|
assert big.integer_from_bytes([]).hex() == '0'
|
||||||
assert big.integer_from_bytes([byte(0)]).hex() == '0'
|
assert big.integer_from_bytes([u8(0)]).hex() == '0'
|
||||||
assert big.integer_from_bytes([byte(0x13), 0x37]).hex() == '1337'
|
assert big.integer_from_bytes([u8(0x13), 0x37]).hex() == '1337'
|
||||||
assert big.integer_from_bytes([byte(0x13), 0x37, 0xca]).hex() == '1337ca'
|
assert big.integer_from_bytes([u8(0x13), 0x37, 0xca]).hex() == '1337ca'
|
||||||
assert big.integer_from_bytes([byte(0x13), 0x37, 0xca, 0xfe]).hex() == '1337cafe'
|
assert big.integer_from_bytes([u8(0x13), 0x37, 0xca, 0xfe]).hex() == '1337cafe'
|
||||||
assert big.integer_from_bytes([byte(0x13), 0x37, 0xca, 0xfe, 0xba]).hex() == '1337cafeba'
|
assert big.integer_from_bytes([u8(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(0x13), 0x37, 0xca, 0xfe, 0xba, 0xbe]).hex() == '1337cafebabe'
|
||||||
|
|
||||||
mut bytes := []byte{cap: 1024}
|
mut bytes := []byte{cap: 1024}
|
||||||
mut expected := ''
|
mut expected := ''
|
||||||
for i := 0; i < bytes.cap; i++ {
|
for i := 0; i < bytes.cap; i++ {
|
||||||
bytes << byte(i)
|
bytes << u8(i)
|
||||||
expected = expected + byte(i).hex()
|
expected = expected + u8(i).hex()
|
||||||
}
|
}
|
||||||
assert big.integer_from_bytes(bytes).hex() == expected.trim_left('0')
|
assert big.integer_from_bytes(bytes).hex() == expected.trim_left('0')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_bytes() {
|
fn test_bytes() {
|
||||||
result1, sign1 := big.integer_from_u64(0x1337cafebabe).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
|
assert sign1 == 1
|
||||||
|
|
||||||
mut bytes := []byte{cap: 1024}
|
mut bytes := []byte{cap: 1024}
|
||||||
mut expected := ''
|
mut expected := ''
|
||||||
for i := 0; i < bytes.cap; i++ {
|
for i := 0; i < bytes.cap; i++ {
|
||||||
bytes << byte(i | 1)
|
bytes << u8(i | 1)
|
||||||
expected = expected + byte(i).hex()
|
expected = expected + u8(i).hex()
|
||||||
}
|
}
|
||||||
result2, sign2 := big.integer_from_bytes(bytes).bytes()
|
result2, sign2 := big.integer_from_bytes(bytes).bytes()
|
||||||
assert result2 == 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(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_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_u64(0xabcedabcde).lshift(20) == big.integer_from_u64(0xabcedabcde00000)
|
||||||
assert big.integer_from_bytes([byte(1), 1, 1]).lshift(56) == big.integer_from_bytes([
|
assert big.integer_from_bytes([u8(1), 1, 1]).lshift(56) == big.integer_from_bytes([
|
||||||
byte(1),
|
u8(1),
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
0,
|
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(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_int(0x13374956).rshift(16) == big.integer_from_int(0x1337)
|
||||||
assert big.integer_from_bytes([
|
assert big.integer_from_bytes([
|
||||||
byte(1),
|
u8(1),
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
|
@ -362,7 +362,7 @@ fn test_rshift() {
|
||||||
0,
|
0,
|
||||||
0,
|
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() {
|
fn test_isqrt() {
|
||||||
|
|
|
@ -787,7 +787,7 @@ pub fn (a Integer) bytes() ([]byte, int) {
|
||||||
mut offset := 24
|
mut offset := 24
|
||||||
mut non_zero_found := false
|
mut non_zero_found := false
|
||||||
for index := a.digits.len - 1; index >= 0; {
|
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
|
non_zero_found = non_zero_found || value != 0
|
||||||
if non_zero_found {
|
if non_zero_found {
|
||||||
result << value
|
result << value
|
||||||
|
|
|
@ -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) {
|
fn lshift_byte_in_place(mut a []u32, byte_nb int) {
|
||||||
a_len := a.len
|
a_len := a.len
|
||||||
// control or allocate capacity
|
// control or allocate capacity
|
||||||
|
|
|
@ -6,10 +6,10 @@ module bits
|
||||||
const (
|
const (
|
||||||
// See http://supertech.csail.mit.edu/papers/debruijn.pdf
|
// See http://supertech.csail.mit.edu/papers/debruijn.pdf
|
||||||
de_bruijn32 = u32(0x077CB531)
|
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]
|
23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9]
|
||||||
de_bruijn64 = u64(0x03f79d71b4ca8b09)
|
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,
|
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,
|
46, 35, 44, 21, 52, 32, 23, 11, 54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7,
|
||||||
6]
|
6]
|
||||||
|
@ -147,7 +147,7 @@ pub fn ones_count_64(x u64) int {
|
||||||
// This function's execution time does not depend on the inputs.
|
// This function's execution time does not depend on the inputs.
|
||||||
[inline]
|
[inline]
|
||||||
pub fn rotate_left_8(x byte, k int) byte {
|
pub fn rotate_left_8(x byte, k int) byte {
|
||||||
n := byte(8)
|
n := u8(8)
|
||||||
s := u8(k) & (n - u8(1))
|
s := u8(k) & (n - u8(1))
|
||||||
return (x << s) | (x >> (n - s))
|
return (x << s) | (x >> (n - s))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
module bits
|
module bits
|
||||||
|
|
||||||
const (
|
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,
|
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,
|
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,
|
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,
|
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,
|
0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00,
|
||||||
0x02, 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,
|
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,
|
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,
|
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, 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, 0x06, 0x07, 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06, 0x07, 0x05, 0x06, 0x06, 0x07,
|
||||||
0x06, 0x07, 0x07, 0x08]
|
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,
|
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,
|
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,
|
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,
|
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,
|
0xb7, 0x77, 0xf7, 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf,
|
||||||
0x3f, 0xbf, 0x7f, 0xff]
|
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,
|
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,
|
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,
|
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
|
||||||
|
|
|
@ -15,7 +15,7 @@ fn test_bits() {
|
||||||
i = 1
|
i = 1
|
||||||
for x in 0 .. 8 {
|
for x in 0 .. 8 {
|
||||||
// C.printf("x:%02x lz: %d cmp: %d\n", i << x, leading_zeros_8(i << x), 7-x)
|
// 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
|
// 16 bit
|
||||||
|
@ -46,8 +46,8 @@ fn test_bits() {
|
||||||
// 8 bit
|
// 8 bit
|
||||||
i = 0
|
i = 0
|
||||||
for x in 0 .. 9 {
|
for x in 0 .. 9 {
|
||||||
// C.printf("x:%02x lz: %llu cmp: %d\n", byte(i), 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(byte(i)) == x
|
assert ones_count_8(u8(i)) == x
|
||||||
i = (i << 1) + 1
|
i = (i << 1) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,16 +90,16 @@ fn test_bits() {
|
||||||
// 8 bit
|
// 8 bit
|
||||||
i = 0
|
i = 0
|
||||||
for _ in 0 .. 9 {
|
for _ in 0 .. 9 {
|
||||||
mut rv := byte(0)
|
mut rv := u8(0)
|
||||||
mut bc := 0
|
mut bc := 0
|
||||||
mut n := i
|
mut n := i
|
||||||
for bc < 8 {
|
for bc < 8 {
|
||||||
rv = (rv << 1) | (byte(n) & 0x01)
|
rv = (rv << 1) | (u8(n) & 0x01)
|
||||||
bc++
|
bc++
|
||||||
n = n >> 1
|
n = n >> 1
|
||||||
}
|
}
|
||||||
// C.printf("x:%02x lz: %llu cmp: %d\n", byte(i), reverse_8(byte(i)), rv)
|
// C.printf("x:%02x lz: %llu cmp: %d\n", u8(i), reverse_8(u8(i)), rv)
|
||||||
assert reverse_8(byte(i)) == rv
|
assert reverse_8(u8(i)) == rv
|
||||||
i = (i << 1) + 1
|
i = (i << 1) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -391,7 +391,7 @@ pub fn (u_ Uint128) str() string {
|
||||||
mut n := int(0)
|
mut n := int(0)
|
||||||
for ; r != 0; r /= 10 {
|
for ; r != 0; r /= 10 {
|
||||||
n++
|
n++
|
||||||
buf[i - n] += byte(r % 10)
|
buf[i - n] += u8(r % 10)
|
||||||
}
|
}
|
||||||
if q.is_zero() {
|
if q.is_zero() {
|
||||||
return buf[i - n..].bytestr()
|
return buf[i - n..].bytestr()
|
||||||
|
|
|
@ -329,7 +329,7 @@ pub fn (u_ Uint256) str() string {
|
||||||
mut n := 0
|
mut n := 0
|
||||||
for ; r != 0; r /= 10 {
|
for ; r != 0; r /= 10 {
|
||||||
n++
|
n++
|
||||||
buf[i - n] += byte(r % 10)
|
buf[i - n] += u8(r % 10)
|
||||||
}
|
}
|
||||||
if q.is_zero() {
|
if q.is_zero() {
|
||||||
return buf[i - n..].bytestr()
|
return buf[i - n..].bytestr()
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue