remove u8 and i32 from tests and examples

pull/1822/head
Alexander Medvednikov 2019-09-02 15:02:25 +03:00
parent 0db1eaa55a
commit 1c6d51f271
12 changed files with 38 additions and 43 deletions

View File

@ -73,16 +73,13 @@ void pthread_mutex_unlock(HANDLE *m) {
//================================== TYPEDEFS ================================*/
typedef unsigned char byte;
typedef unsigned int uint;
typedef int64_t i64;
typedef int32_t i32;
typedef int16_t i16;
typedef int8_t i8;
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef uint8_t byte;
typedef uint32_t rune;
typedef float f32;
typedef double f64;
@ -94,8 +91,6 @@ typedef struct map map;
typedef array array_string;
typedef array array_int;
typedef array array_byte;
typedef array array_uint;
typedef array array_float;
typedef array array_f32;
typedef array array_f64;
typedef map map_int;

View File

@ -1619,8 +1619,8 @@ fn (p mut Parser) name_expr() string {
if orig_name == 'i32' {
println('`i32` alias was removed, use `int` instead')
}
if orig_name == 'u8' {
println('`u8` alias was removed, use `byte` instead')
if orig_name == 'byte' {
println('`byte` alias was removed, use `byte` instead')
}
p.error('undefined: `$orig_name`')
}
@ -1949,7 +1949,7 @@ fn (p mut Parser) index_expr(typ_ string, fn_ph int) string {
if is_arr {
index_pos := p.cgen.cur_line.len
T := p.table.find_type(p.expression())
// Allows only i8-64 and u8-64 to be used when accessing an array
// Allows only i8-64 and byte-64 to be used when accessing an array
if T.parent != 'int' && T.parent != 'u32' {
p.check_types(T.name, 'int')
}

View File

@ -758,7 +758,7 @@ fn (table &Table) cgen_name_type_pair(name, typ string) string {
fn is_valid_int_const(val, typ string) bool {
x := val.int()
switch typ {
case 'u8': return 0 <= x && x <= math.MaxU8
case 'byte': return 0 <= x && x <= math.MaxU8
case 'u16': return 0 <= x && x <= math.MaxU16
//case 'u32': return 0 <= x && x <= math.MaxU32
//case 'u64': return 0 <= x && x <= math.MaxU64

View File

@ -46,4 +46,4 @@ fn test_flag_parsing() {
for i, f in flags {
assert f == result[i]
}
}
}

View File

@ -81,20 +81,20 @@ pub fn (nn u32) str() string {
}
/*
pub fn (nn u8) str() string {
pub fn (nn byte) str() string {
mut n := nn
if n == u8(0) {
if n == byte(0) {
return '0'
}
max := 5
mut buf := malloc(max)
mut len := 0
// Fill the string from the end
for n > u8(0) {
d := n % u8(10)
buf[max - len - 1] = d + u8(`0`)
for n > byte(0) {
d := n % byte(10)
buf[max - len - 1] = d + byte(`0`)
len++
n = n / u8(10)
n = n / byte(10)
}
return tos(buf + max - len, len)
}

View File

@ -20,8 +20,8 @@ fn test_str_methods() {
assert i64(1).str() == '1'
assert i64(-1).str() == '-1'
assert u8(1).str() == '1'
assert u8(-1).str() == '255'
assert byte(1).str() == '1'
assert byte(-1).str() == '255'
assert u16(1).str() == '1'
assert u16(-1).str() == '65535'
assert u32(1).str() == '1'

View File

@ -417,4 +417,4 @@ fn test_for_loop_two() {
for i, c in s {
assert c == s[i]
}
}
}

View File

@ -64,10 +64,10 @@ fn encrypt_block_generic(xk []u32, dst, src []byte) {
mut t2 := u32(0)
mut t3 := u32(0)
for r := 0; r < nr; r++ {
t0 = xk[u32(k+0)] ^ u32(Te0[u8(s0>>u32(24))]) ^ u32(Te1[u8(s1>>u32(16))]) ^ u32(Te2[u8(s2>>u32(8))]) ^ u32(Te3[u8(s3)])
t1 = xk[u32(k+1)] ^ u32(Te0[u8(s1>>u32(24))]) ^ u32(Te1[u8(s2>>u32(16))]) ^ u32(Te2[u8(s3>>u32(8))]) ^ u32(Te3[u8(s0)])
t2 = xk[u32(k+2)] ^ u32(Te0[u8(s2>>u32(24))]) ^ u32(Te1[u8(s3>>u32(16))]) ^ u32(Te2[u8(s0>>u32(8))]) ^ u32(Te3[u8(s1)])
t3 = xk[u32(k+3)] ^ u32(Te0[u8(s3>>u32(24))]) ^ u32(Te1[u8(s0>>u32(16))]) ^ u32(Te2[u8(s1>>u32(8))]) ^ u32(Te3[u8(s2)])
t0 = xk[u32(k+0)] ^ u32(Te0[byte(s0>>u32(24))]) ^ u32(Te1[byte(s1>>u32(16))]) ^ u32(Te2[byte(s2>>u32(8))]) ^ u32(Te3[byte(s3)])
t1 = xk[u32(k+1)] ^ u32(Te0[byte(s1>>u32(24))]) ^ u32(Te1[byte(s2>>u32(16))]) ^ u32(Te2[byte(s3>>u32(8))]) ^ u32(Te3[byte(s0)])
t2 = xk[u32(k+2)] ^ u32(Te0[byte(s2>>u32(24))]) ^ u32(Te1[byte(s3>>u32(16))]) ^ u32(Te2[byte(s0>>u32(8))]) ^ u32(Te3[byte(s1)])
t3 = xk[u32(k+3)] ^ u32(Te0[byte(s3>>u32(24))]) ^ u32(Te1[byte(s0>>u32(16))]) ^ u32(Te2[byte(s1>>u32(8))]) ^ u32(Te3[byte(s2)])
k += 4
s0 = t0
s1 = t1
@ -117,10 +117,10 @@ fn decrypt_block_generic(xk []u32, dst, src []byte) {
mut t3 := u32(0)
for r := 0; r < nr; r++ {
// println('### 1')
t0 = xk[u32(k+0)] ^ u32(Td0[u8(s0>>u32(24))]) ^ u32(Td1[u8(s3>>u32(16))]) ^ u32(Td2[u8(s2>>u32(8))]) ^ u32(Td3[u8(s1)])
t1 = xk[u32(k+1)] ^ u32(Td0[u8(s1>>u32(24))]) ^ u32(Td1[u8(s0>>u32(16))]) ^ u32(Td2[u8(s3>>u32(8))]) ^ u32(Td3[u8(s2)])
t2 = xk[u32(k+2)] ^ u32(Td0[u8(s2>>u32(24))]) ^ u32(Td1[u8(s1>>u32(16))]) ^ u32(Td2[u8(s0>>u32(8))]) ^ u32(Td3[u8(s3)])
t3 = xk[u32(k+3)] ^ u32(Td0[u8(s3>>u32(24))]) ^ u32(Td1[u8(s2>>u32(16))]) ^ u32(Td2[u8(s1>>u32(8))]) ^ u32(Td3[u8(s0)])
t0 = xk[u32(k+0)] ^ u32(Td0[byte(s0>>u32(24))]) ^ u32(Td1[byte(s3>>u32(16))]) ^ u32(Td2[byte(s2>>u32(8))]) ^ u32(Td3[byte(s1)])
t1 = xk[u32(k+1)] ^ u32(Td0[byte(s1>>u32(24))]) ^ u32(Td1[byte(s0>>u32(16))]) ^ u32(Td2[byte(s3>>u32(8))]) ^ u32(Td3[byte(s2)])
t2 = xk[u32(k+2)] ^ u32(Td0[byte(s2>>u32(24))]) ^ u32(Td1[byte(s1>>u32(16))]) ^ u32(Td2[byte(s0>>u32(8))]) ^ u32(Td3[byte(s3)])
t3 = xk[u32(k+3)] ^ u32(Td0[byte(s3>>u32(24))]) ^ u32(Td1[byte(s2>>u32(16))]) ^ u32(Td2[byte(s1>>u32(8))]) ^ u32(Td3[byte(s0)])
// println('### 1 end')
k += 4
s0 = t0

View File

@ -19,8 +19,8 @@ import crypto.internal.subtle
struct Cipher {
mut:
s []u32
i u8
j u8
i byte
j byte
}
// new_cipher creates and returns a new Cipher. The key argument should be the
@ -35,9 +35,9 @@ pub fn new_cipher(key []byte) ?Cipher {
for i := 0; i < 256; i++ {
c.s[i] = u32(i)
}
mut j := u8(0)
mut j := byte(0)
for i := 0; i < 256; i++ {
j += u8(c.s[i]) + u8(key[i%key.len])
j += byte(c.s[i]) + byte(key[i%key.len])
tmp := c.s[i]
c.s[i] = c.s[j]
c.s[j] = tmp
@ -53,8 +53,8 @@ pub fn (c mut Cipher) reset() {
for i in c.s {
c.s[i] = u32(0)
}
c.i = u8(0)
c.j = u8(0)
c.i = byte(0)
c.j = byte(0)
}
// xor_key_stream sets dst to the result of XORing src with the key stream.
@ -71,13 +71,13 @@ pub fn (c mut Cipher) xor_key_stream(dst mut []byte, src []byte) {
_ := dst[src.len-1]
*dst = dst.left(src.len) // eliminate bounds check from loop
for k, v in src {
i += u8(1)
i += byte(1)
x := c.s[i]
j += u8(x)
j += byte(x)
y := c.s[j]
c.s[i] = y
c.s[j] = x
dst[k] = v ^ byte(c.s[u8(x+y)])
dst[k] = v ^ byte(c.s[byte(x+y)])
}
c.i = i
c.j = j

View File

@ -10,10 +10,10 @@ module bits
// To rotate x right by k bits, call rotate_left_8(x, -k).
//
// This function's execution time does not depend on the inputs.
pub fn rotate_left_8(x u8, k int) u8 {
n := u8(8)
s := u8(k) & u8(n - u8(1))
return u8((x<<s) | (x>>(n-s)))
pub fn rotate_left_8(x byte, k int) byte {
n := byte(8)
s := byte(k) & byte(n - byte(1))
return byte((x<<s) | (x>>(n-s)))
}
// rotate_left_16 returns the value of x rotated left by (k mod 16) bits.

View File

@ -200,4 +200,4 @@ pub fn yellow(msg string) string {
pub fn bright_yellow(msg string) string {
return format(msg, '93', '39')
}
}

View File

@ -10,4 +10,4 @@ pub fn format(msg, open, close string) string {
pub fn format_rgb(r, g, b int, msg, open, close string) string {
return _format_rgb(r, g, b, msg, open, close)
}
}