1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: byte => u8

This commit is contained in:
Alexander Medvednikov 2022-04-15 14:45:52 +03:00
parent 7f3b91e688
commit 014c3c97f0
38 changed files with 201 additions and 201 deletions

View File

@ -247,7 +247,7 @@ fn _writeln_to_fd(fd int, s string) {
}
[manualfree]
fn _write_buf_to_fd(fd int, buf &byte, buf_len int) {
fn _write_buf_to_fd(fd int, buf &u8, buf_len int) {
if buf_len <= 0 {
return
}

View File

@ -27,7 +27,7 @@ fn C.sprintf(a ...voidptr) int
fn C.strlen(s &char) int
fn C.sscanf(&byte, &byte, ...&byte) int
fn C.sscanf(&u8, &u8, ...&u8) int
[trusted]
fn C.isdigit(c int) bool
@ -247,11 +247,11 @@ fn C.CreateProcessW(lpApplicationName &u16, lpCommandLine &u16, lpProcessAttribu
fn C.ReadFile(hFile voidptr, lpBuffer voidptr, nNumberOfBytesToRead u32, lpNumberOfBytesRead C.LPDWORD, lpOverlapped voidptr) bool
fn C.GetFileAttributesW(lpFileName &byte) u32
fn C.GetFileAttributesW(lpFileName &u8) u32
fn C.RegQueryValueEx(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &byte, lpcbData &u32) voidptr
fn C.RegQueryValueEx(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &u8, lpcbData &u32) voidptr
fn C.RegQueryValueExW(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &byte, lpcbData &u32) int
fn C.RegQueryValueExW(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &u8, lpcbData &u32) int
fn C.RegOpenKeyEx(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, phkResult voidptr) voidptr
@ -259,7 +259,7 @@ fn C.RegOpenKeyExW(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, p
fn C.RegSetValueEx() voidptr
fn C.RegSetValueExW(hKey voidptr, lpValueName &u16, reserved u32, dwType u32, lpData &byte, lpcbData u32) int
fn C.RegSetValueExW(hKey voidptr, lpValueName &u16, reserved u32, dwType u32, lpData &u8, lpcbData u32) int
fn C.RegCloseKey(hKey voidptr)
@ -331,7 +331,7 @@ fn C.LocalFree()
fn C.FindFirstFileW(lpFileName &u16, lpFindFileData voidptr) voidptr
fn C.FindFirstFile(lpFileName &byte, lpFindFileData voidptr) voidptr
fn C.FindFirstFile(lpFileName &u8, lpFindFileData voidptr) voidptr
fn C.FindNextFile(hFindFile voidptr, lpFindFileData voidptr) int
@ -361,7 +361,7 @@ fn C.closesocket(int) int
fn C.vschannel_init(&C.TlsContext)
fn C.request(&C.TlsContext, int, &u16, &byte, &&byte) int
fn C.request(&C.TlsContext, int, &u16, &u8, &&u8) int
fn C.vschannel_cleanup(&C.TlsContext)
@ -370,19 +370,19 @@ fn C.URLDownloadToFile(int, &u16, &u16, int, int)
[trusted]
fn C.GetLastError() u32
fn C.CreateDirectory(&byte, int) bool
fn C.CreateDirectory(&u8, int) bool
// win crypto
fn C.BCryptGenRandom(int, voidptr, int, int) int
// win synchronization
fn C.CreateMutex(int, bool, &byte) voidptr
fn C.CreateMutex(int, bool, &u8) voidptr
fn C.WaitForSingleObject(voidptr, int) int
fn C.ReleaseMutex(voidptr) bool
fn C.CreateEvent(int, bool, bool, &byte) voidptr
fn C.CreateEvent(int, bool, bool, &u8) voidptr
fn C.SetEvent(voidptr) int
@ -480,4 +480,4 @@ fn C.dup2(oldfd int, newfd int) int
fn C.glTexImage2D()
// used by ios for println
fn C.WrappedNSLog(str &byte)
fn C.WrappedNSLog(str &u8)

View File

@ -77,7 +77,7 @@ fn (nn int) str_l(max int) string {
buf[index] = `-`
}
diff := max - index
vmemmove(buf, buf + index, diff + 1)
vmemmove(buf, voidptr(buf + index), diff + 1)
/*
// === manual memory move for bare metal ===
mut c:= 0
@ -148,7 +148,7 @@ pub fn (nn u32) str() string {
index++
}
diff := max - index
vmemmove(buf, buf + index, diff + 1)
vmemmove(buf, voidptr(buf + index), diff + 1)
return tos(buf, diff)
// return tos(memdup(&buf[0] + index, (max - index)), (max - index))
@ -202,7 +202,7 @@ pub fn (nn i64) str() string {
buf[index] = `-`
}
diff := max - index
vmemmove(buf, buf + index, diff + 1)
vmemmove(buf, voidptr(buf + index), diff + 1)
return tos(buf, diff)
// return tos(memdup(&buf[0] + index, (max - index)), (max - index))
}
@ -239,7 +239,7 @@ pub fn (nn u64) str() string {
index++
}
diff := max - index
vmemmove(buf, buf + index, diff + 1)
vmemmove(buf, voidptr(buf + index), diff + 1)
return tos(buf, diff)
// return tos(memdup(&buf[0] + index, (max - index)), (max - index))
}
@ -260,13 +260,13 @@ pub fn (b bool) str() string {
// u64_to_hex converts the number `nn` to a (zero padded if necessary) hexadecimal `string`.
[direct_array_access; inline]
fn u64_to_hex(nn u64, len byte) string {
fn u64_to_hex(nn u64, len u8) string {
mut n := nn
mut buf := [17]byte{}
mut buf := [17]u8{}
buf[len] = 0
mut i := 0
for i = len - 1; i >= 0; i-- {
d := byte(n & 0xF)
d := u8(n & 0xF)
buf[i] = if d < 10 { d + `0` } else { d + 87 }
n = n >> 4
}
@ -275,13 +275,13 @@ fn u64_to_hex(nn u64, len byte) string {
// u64_to_hex_no_leading_zeros converts the number `nn` to hexadecimal `string`.
[direct_array_access; inline]
fn u64_to_hex_no_leading_zeros(nn u64, len byte) string {
fn u64_to_hex_no_leading_zeros(nn u64, len u8) string {
mut n := nn
mut buf := [17]byte{}
mut buf := [17]u8{}
buf[len] = 0
mut i := 0
for i = len - 1; i >= 0; i-- {
d := byte(n & 0xF)
d := u8(n & 0xF)
buf[i] = if d < 10 { d + `0` } else { d + 87 }
n = n >> 4
if n == 0 {
@ -297,7 +297,7 @@ fn u64_to_hex_no_leading_zeros(nn u64, len byte) string {
// Example: assert byte(2).hex() == '02'
// Example: assert byte(15).hex() == '0f'
// Example: assert byte(255).hex() == 'ff'
pub fn (nn byte) hex() string {
pub fn (nn u8) hex() string {
if nn == 0 {
return '00'
}
@ -406,7 +406,7 @@ pub fn (nn charptr) str() string {
return '0x' + u64(nn).hex()
}
pub fn (nn byte) hex_full() string {
pub fn (nn u8) hex_full() string {
return u64_to_hex(u64(nn), 2)
}
@ -452,13 +452,13 @@ pub fn (nn u64) hex_full() string {
// str returns the contents of `byte` as a zero terminated `string`.
// See also: [`byte.ascii_str`](#byte.ascii_str)
// Example: assert byte(111).str() == '111'
pub fn (b byte) str() string {
pub fn (b u8) str() string {
return int(b).str_l(7)
}
// ascii_str returns the contents of `byte` as a zero terminated ASCII `string` character.
// Example: assert byte(97).ascii_str() == 'a'
pub fn (b byte) ascii_str() string {
pub fn (b u8) ascii_str() string {
mut str := string{
str: unsafe { malloc_noscan(2) }
len: 1
@ -474,7 +474,7 @@ pub fn (b byte) ascii_str() string {
// str_escaped returns the contents of `byte` as an escaped `string`.
// Example: assert byte(0).str_escaped() == r'`\0`'
[manualfree]
pub fn (b byte) str_escaped() string {
pub fn (b u8) str_escaped() string {
str := match b {
0 {
r'`\0`'
@ -520,12 +520,12 @@ pub fn (b byte) str_escaped() string {
// Example: assert `H`.is_capital() == true
// Example: assert `h`.is_capital() == false
[inline]
pub fn (c byte) is_capital() bool {
pub fn (c u8) is_capital() bool {
return c >= `A` && c <= `Z`
}
// clone clones the byte array, and returns the newly created copy.
pub fn (b []byte) clone() []byte {
pub fn (b []u8) clone() []byte {
mut res := []byte{len: b.len}
// mut res := make([]byte, {repeat:b.len})
for i in 0 .. b.len {
@ -539,7 +539,7 @@ pub fn (b []byte) clone() []byte {
// even when some of the array bytes were `0`.
// If you want to get a V string, that contains only the bytes till
// the first `0` byte, use `tos_clone(&byte(array.data))` instead.
pub fn (b []byte) bytestr() string {
pub fn (b []u8) bytestr() string {
unsafe {
buf := malloc_noscan(b.len + 1)
vmemcpy(buf, b.data, b.len)
@ -552,13 +552,13 @@ pub fn (b []byte) bytestr() string {
// from utf8 to utf32 and return the result as a rune
// it will produce an error if there are more than
// four bytes in the array.
pub fn (b []byte) byterune() ?rune {
pub fn (b []u8) byterune() ?rune {
r := b.utf8_to_utf32() ?
return rune(r)
}
// repeat returns a new string with `count` number of copies of the byte it was called on.
pub fn (b byte) repeat(count int) string {
pub fn (b u8) repeat(count int) string {
if count < 0 {
panic('byte.repeat: count is negative: $count')
} else if count == 0 {

View File

@ -1,27 +1,27 @@
module builtin
pub fn (b byte) is_space() bool {
pub fn (b u8) is_space() bool {
mut result := false
#result.val = /^\s*$/.test(String.fromCharCode(b))
return result
}
pub fn (c byte) str() string {
pub fn (c u8) str() string {
res := ''
#res.str = c.val.toString()
return res
}
pub fn (c byte) ascii_str() string {
pub fn (c u8) ascii_str() string {
res := ''
#res.str = String.fromCharCode(c.val)
return res
}
pub fn (c byte) repeat(count int) string {
pub fn (c u8) repeat(count int) string {
mut res := ''
for _ in 0 .. count {
res += c.ascii_str()
@ -31,42 +31,42 @@ pub fn (c byte) repeat(count int) string {
}
[inline]
pub fn (c byte) is_digit() bool {
pub fn (c u8) is_digit() bool {
return c >= `0` && c <= `9`
}
// is_hex_digit returns `true` if the byte is either in range 0-9, a-f or A-F and `false` otherwise.
// Example: assert byte(`F`) == true
[inline]
pub fn (c byte) 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`)
}
// is_oct_digit returns `true` if the byte is in range 0-7 and `false` otherwise.
// Example: assert byte(`7`) == true
[inline]
pub fn (c byte) is_oct_digit() bool {
pub fn (c u8) is_oct_digit() bool {
return c >= `0` && c <= `7`
}
// is_bin_digit returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise.
// Example: assert byte(`0`) == true
[inline]
pub fn (c byte) is_bin_digit() bool {
pub fn (c u8) is_bin_digit() bool {
return c == `0` || c == `1`
}
// is_letter returns `true` if the byte is in range a-z or A-Z and `false` otherwise.
// Example: assert byte(`V`) == true
[inline]
pub fn (c byte) is_letter() bool {
pub fn (c u8) is_letter() bool {
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`)
}
// is_alnum returns `true` if the byte is in range a-z, A-Z, 0-9 and `false` otherwise.
// Example: assert byte(`V`) == true
[inline]
pub fn (c byte) is_alnum() bool {
pub fn (c u8) is_alnum() bool {
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`)
}
@ -74,14 +74,14 @@ pub fn (c byte) is_alnum() bool {
// Example: assert `H`.is_capital() == true
// Example: assert `h`.is_capital() == false
[inline]
pub fn (c byte) is_capital() bool {
pub fn (c u8) is_capital() bool {
return c >= `A` && c <= `Z`
}
// str_escaped returns the contents of `byte` as an escaped `string`.
// Example: assert byte(0).str_escaped() == r'`\0`'
pub fn (b byte) str_escaped() string {
pub fn (b u8) str_escaped() string {
mut str := ''
match b {
0 { str = r'`\0`' }

View File

@ -85,9 +85,9 @@ mut:
deletes u32 // count
// array allocated (with `cap` bytes) on first deletion
// has non-zero element when key deleted
all_deleted &byte
values &byte
keys &byte
all_deleted &u8
values &u8
keys &u8
}
[inline]
@ -107,13 +107,13 @@ fn new_dense_array(key_bytes int, value_bytes int) DenseArray {
[inline]
fn (d &DenseArray) key(i int) voidptr {
return unsafe { d.keys + i * d.key_bytes }
return unsafe { voidptr(d.keys + i * d.key_bytes) }
}
// for cgen
[inline]
fn (d &DenseArray) value(i int) voidptr {
return unsafe { d.values + i * d.value_bytes }
return unsafe { voidptr(d.values + i * d.value_bytes) }
}
[inline]
@ -135,7 +135,7 @@ fn (mut d DenseArray) expand() int {
d.values = realloc_data(d.values, old_value_size, d.value_bytes * d.cap)
if d.deletes != 0 {
d.all_deleted = realloc_data(d.all_deleted, old_cap, d.cap)
vmemset(d.all_deleted + d.len, 0, d.cap - d.len)
vmemset(voidptr(d.all_deleted + d.len), 0, d.cap - d.len)
}
}
}
@ -167,9 +167,9 @@ mut:
// Highest even index in the hashtable
even_index u32
// Number of cached hashbits left for rehashing
cached_hashbits byte
cached_hashbits u8
// Used for right-shifting out used hashbits
shift byte
shift u8
// Array storing key-values (ordered)
key_values DenseArray
// Pointer to meta-data:
@ -194,7 +194,7 @@ fn map_eq_string(a voidptr, b voidptr) bool {
}
fn map_eq_int_1(a voidptr, b voidptr) bool {
return unsafe { *&byte(a) == *&byte(b) }
return unsafe { *&u8(a) == *&u8(b) }
}
fn map_eq_int_2(a voidptr, b voidptr) bool {
@ -218,7 +218,7 @@ fn map_clone_string(dest voidptr, pkey voidptr) {
fn map_clone_int_1(dest voidptr, pkey voidptr) {
unsafe {
*&byte(dest) = *&byte(pkey)
*&u8(dest) = *&u8(pkey)
}
}
@ -274,8 +274,8 @@ fn new_map(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqFn,
fn new_map_init(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn, n int, key_bytes int, value_bytes int, keys voidptr, values voidptr) map {
mut out := new_map(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn)
// TODO pre-allocate n slots
mut pkey := &byte(keys)
mut pval := &byte(values)
mut pkey := &u8(keys)
mut pval := &u8(values)
for _ in 0 .. n {
unsafe {
out.set(pkey, pval)
@ -348,7 +348,7 @@ fn (mut m map) ensure_extra_metas(probe_count u32) {
m.extra_metas += extra_metas_inc
mem_size := (m.even_index + 2 + m.extra_metas)
unsafe {
x := realloc_data(&byte(m.metas), int(size_of_u32 * old_mem_size), int(size_of_u32 * mem_size))
x := realloc_data(&u8(m.metas), int(size_of_u32 * old_mem_size), int(size_of_u32 * mem_size))
m.metas = &u32(x)
vmemset(m.metas + mem_size - extra_metas_inc, 0, int(sizeof(u32) * extra_metas_inc))
}
@ -388,7 +388,7 @@ fn (mut m map) set(key voidptr, value voidptr) {
pkey := m.key_values.key(kv_index)
pvalue := m.key_values.value(kv_index)
m.clone_fn(pkey, key)
vmemcpy(&byte(pvalue), value, m.value_bytes)
vmemcpy(&u8(pvalue), value, m.value_bytes)
}
m.meta_greater(index, meta, u32(kv_index))
m.len++
@ -418,7 +418,7 @@ fn (mut m map) rehash() {
meta_bytes := sizeof(u32) * (m.even_index + 2 + m.extra_metas)
unsafe {
// TODO: use realloc_data here too
x := v_realloc(&byte(m.metas), int(meta_bytes))
x := v_realloc(&u8(m.metas), int(meta_bytes))
m.metas = &u32(x)
vmemset(m.metas, 0, int(meta_bytes))
}
@ -468,7 +468,7 @@ fn (mut m map) get_and_set(key voidptr, zero voidptr) voidptr {
pkey := unsafe { m.key_values.key(kv_index) }
if m.key_eq_fn(key, pkey) {
pval := unsafe { m.key_values.value(kv_index) }
return unsafe { &byte(pval) }
return unsafe { &u8(pval) }
}
}
index += 2
@ -494,7 +494,7 @@ fn (m &map) get(key voidptr, zero voidptr) voidptr {
pkey := unsafe { m.key_values.key(kv_index) }
if m.key_eq_fn(key, pkey) {
pval := unsafe { m.key_values.value(kv_index) }
return unsafe { &byte(pval) }
return unsafe { &u8(pval) }
}
}
index += 2
@ -518,7 +518,7 @@ fn (m &map) get_check(key voidptr) voidptr {
pkey := unsafe { m.key_values.key(kv_index) }
if m.key_eq_fn(key, pkey) {
pval := unsafe { m.key_values.value(kv_index) }
return unsafe { &byte(pval) }
return unsafe { &u8(pval) }
}
}
index += 2
@ -604,7 +604,7 @@ pub fn (mut m map) delete(key voidptr) {
// Returns all keys in the map.
pub fn (m &map) keys() array {
mut keys := __new_array(m.len, 0, m.key_bytes)
mut item := unsafe { &byte(keys.data) }
mut item := unsafe { &u8(keys.data) }
if m.key_values.deletes == 0 {
for i := 0; i < m.key_values.len; i++ {
unsafe {

View File

@ -103,7 +103,7 @@ pub fn error_with_code(message string, code int) IError {
// Option is the base of V's internal optional return system.
struct Option {
state byte
state u8
err IError = none__
// Data is trailing after err
// and is not included in here but in the
@ -114,7 +114,7 @@ fn opt_ok(data voidptr, mut option Option, size int) {
unsafe {
*option = Option{}
// use err to get the end of OptionBase and then memcpy into it
vmemcpy(&byte(&option.err) + sizeof(IError), data, size)
vmemcpy(&u8(&option.err) + sizeof(IError), data, size)
}
}

View File

@ -25,7 +25,7 @@ mut:
start &byte = 0
previous &VMemoryBlock = 0
remaining int
current &byte = 0
current &u8 = 0
mallocs int
}

View File

@ -14,14 +14,14 @@ pub fn (c rune) str() string {
/*
unsafe {
fst_byte := int(c)>>8 * 3 & 0xff
len := utf8_char_len(byte(fst_byte))
len := utf8_char_len(u8(fst_byte))
println('len=$len')
mut str := string{
len: len
str: malloc_noscan(len + 1)
}
for i in 0..len {
str.str[i] = byte(int(c)>>8 * (3 - i) & 0xff)
str.str[i] = u8(int(c)>>8 * (3 - i) & 0xff)
}
str.str[len] = `\0`
println(str)
@ -49,15 +49,15 @@ pub fn (c rune) repeat(count int) string {
} else if count == 1 {
return c.str()
}
mut buffer := [5]byte{}
mut buffer := [5]u8{}
res := unsafe { utf32_to_str_no_malloc(u32(c), &buffer[0]) }
return res.repeat(count)
}
[manualfree]
pub fn (c rune) bytes() []byte {
mut res := []byte{cap: 5}
res.len = unsafe { utf32_decode_to_buffer(u32(c), &byte(res.data)) }
pub fn (c rune) bytes() []u8 {
mut res := []u8{cap: 5}
res.len = unsafe { utf32_decode_to_buffer(u32(c), &u8(res.data)) }
return res
}

View File

@ -43,7 +43,7 @@ Note: A V string should be/is immutable from the point of view of
*/
pub struct string {
pub:
str &byte = 0 // points to a C style 0 terminated string of bytes.
str &u8 = 0 // points to a C style 0 terminated string of bytes.
len int // the length of the .str field, excluding the ending 0 byte. It is always equal to strlen(.str).
// NB string.is_lit is an enumeration of the following:
// .is_lit == 0 => a fresh string, should be freed by autofree
@ -83,7 +83,7 @@ pub fn (s string) runes() []rune {
// It will panic, if the pointer `s` is 0.
[unsafe]
pub fn cstring_to_vstring(s &char) string {
return unsafe { tos2(&byte(s)) }.clone()
return unsafe { tos2(&u8(s)) }.clone()
}
// tos_clone creates a new V string copy of the C style string, pointed by `s`.
@ -91,7 +91,7 @@ pub fn cstring_to_vstring(s &char) string {
// that tos_clone expects `&byte`, while cstring_to_vstring expects &char).
// It will panic, if the pointer `s` is 0.
[unsafe]
pub fn tos_clone(s &byte) string {
pub fn tos_clone(s &u8) string {
return unsafe { tos2(s) }.clone()
}
@ -100,7 +100,7 @@ pub fn tos_clone(s &byte) string {
// It will panic, when the pointer `s` is 0.
// See also `tos_clone`.
[unsafe]
pub fn tos(s &byte, len int) string {
pub fn tos(s &u8, len int) string {
if s == 0 {
panic('tos(): nil string')
}
@ -117,7 +117,7 @@ pub fn tos(s &byte, len int) string {
// It is the same as `tos3`, but for &byte pointers, avoiding callsite casts.
// See also `tos_clone`.
[unsafe]
pub fn tos2(s &byte) string {
pub fn tos2(s &u8) string {
if s == 0 {
panic('tos2: nil string')
}
@ -139,7 +139,7 @@ pub fn tos3(s &char) string {
panic('tos3: nil string')
}
return string{
str: unsafe { &byte(s) }
str: unsafe { &u8(s) }
len: unsafe { vstrlen_char(s) }
}
}
@ -151,7 +151,7 @@ pub fn tos3(s &char) string {
// It is the same as `tos5`, but for &byte pointers, avoiding callsite casts.
// See also `tos_clone`.
[unsafe]
pub fn tos4(s &byte) string {
pub fn tos4(s &u8) string {
if s == 0 {
return ''
}
@ -173,7 +173,7 @@ pub fn tos5(s &char) string {
return ''
}
return string{
str: unsafe { &byte(s) }
str: unsafe { &u8(s) }
len: unsafe { vstrlen_char(s) }
}
}
@ -185,7 +185,7 @@ pub fn tos5(s &char) string {
// (i.e. they would be freed by V's -autofree mechanism, when they are no longer used).
// See also `tos_clone`.
[unsafe]
pub fn (bp &byte) vstring() string {
pub fn (bp &u8) vstring() string {
return string{
str: unsafe { bp }
len: unsafe { vstrlen(bp) }
@ -198,7 +198,7 @@ pub fn (bp &byte) vstring() string {
// does not need to calculate the length of the 0 terminated string.
// See also `tos_clone`.
[unsafe]
pub fn (bp &byte) vstring_with_len(len int) string {
pub fn (bp &u8) vstring_with_len(len int) string {
return string{
str: unsafe { bp }
len: len
@ -216,7 +216,7 @@ pub fn (bp &byte) vstring_with_len(len int) string {
[unsafe]
pub fn (cp &char) vstring() string {
return string{
str: &byte(cp)
str: &u8(cp)
len: unsafe { vstrlen_char(cp) }
is_lit: 0
}
@ -230,7 +230,7 @@ pub fn (cp &char) vstring() string {
[unsafe]
pub fn (cp &char) vstring_with_len(len int) string {
return string{
str: &byte(cp)
str: &u8(cp)
len: len
is_lit: 0
}
@ -245,7 +245,7 @@ pub fn (cp &char) vstring_with_len(len int) string {
// managed/freed by it, for example `os.args` is implemented using it.
// See also `tos_clone`.
[unsafe]
pub fn (bp &byte) vstring_literal() string {
pub fn (bp &u8) vstring_literal() string {
return string{
str: unsafe { bp }
len: unsafe { vstrlen(bp) }
@ -259,7 +259,7 @@ pub fn (bp &byte) vstring_literal() string {
// does not need to calculate the length of the 0 terminated string.
// See also `tos_clone`.
[unsafe]
pub fn (bp &byte) vstring_literal_with_len(len int) string {
pub fn (bp &u8) vstring_literal_with_len(len int) string {
return string{
str: unsafe { bp }
len: len
@ -274,7 +274,7 @@ pub fn (bp &byte) vstring_literal_with_len(len int) string {
[unsafe]
pub fn (cp &char) vstring_literal() string {
return string{
str: &byte(cp)
str: &u8(cp)
len: unsafe { vstrlen_char(cp) }
is_lit: 1
}
@ -289,7 +289,7 @@ pub fn (cp &char) vstring_literal() string {
[unsafe]
pub fn (cp &char) vstring_literal_with_len(len int) string {
return string{
str: &byte(cp)
str: &u8(cp)
len: len
is_lit: 1
}
@ -521,7 +521,7 @@ pub fn (s string) f64() f64 {
// u8 returns the value of the string as u8 `'1'.u8() == u8(1)`.
pub fn (s string) byte() u8 {
return byte(strconv.common_parse_uint(s, 0, 8, false, false) or { 0 })
return u8(strconv.common_parse_uint(s, 0, 8, false, false) or { 0 })
}
// u16 returns the value of the string as u16 `'1'.u16() == u16(1)`.
@ -1039,7 +1039,7 @@ pub fn (s string) index_after(p string, start int) int {
// index_byte returns the index of byte `c` if found in the string.
// index_byte returns -1 if the byte can not be found.
[direct_array_access]
pub fn (s string) index_byte(c byte) int {
pub fn (s string) index_byte(c u8) int {
for i in 0 .. s.len {
if unsafe { s.str[i] } == c {
return i
@ -1051,7 +1051,7 @@ pub fn (s string) index_byte(c byte) int {
// last_index_byte returns the index of the last occurence of byte `c` if found in the string.
// last_index_byte returns -1 if the byte is not found.
[direct_array_access]
pub fn (s string) last_index_byte(c byte) int {
pub fn (s string) last_index_byte(c u8) int {
for i := s.len - 1; i >= 0; i-- {
if unsafe { s.str[i] == c } {
return i
@ -1215,7 +1215,7 @@ pub fn (s string) to_upper() string {
pub fn (s string) is_upper() bool {
for i in 0 .. s.len {
if s[i] >= `a` && s[i] <= `z` {
return false
return false
}
}
return true
@ -1490,7 +1490,7 @@ fn (s string) at(idx int) byte {
// version of `at()` that is used in `a[i] or {`
// return an error when the index is out of range
fn (s string) at_with_check(idx int) ?byte {
fn (s string) at_with_check(idx int) ?u8 {
if idx < 0 || idx >= s.len {
return error('string index out of range')
}
@ -1503,7 +1503,7 @@ fn (s string) at_with_check(idx int) ?byte {
// The following list is considered white space characters: ` `, `\t`, `\n`, `\v`, `\f`, `\r`, 0x85, 0xa0
// Example: assert byte(` `).is_space() == true
[inline]
pub fn (c byte) is_space() bool {
pub fn (c u8) is_space() bool {
// 0x85 is NEXT LINE (NEL)
// 0xa0 is NO-BREAK SPACE
return c == 32 || (c > 8 && c < 14) || (c == 0x85) || (c == 0xa0)
@ -1512,42 +1512,42 @@ pub fn (c byte) is_space() bool {
// is_digit returns `true` if the byte is in range 0-9 and `false` otherwise.
// Example: assert byte(`9`) == true
[inline]
pub fn (c byte) is_digit() bool {
pub fn (c u8) is_digit() bool {
return c >= `0` && c <= `9`
}
// is_hex_digit returns `true` if the byte is either in range 0-9, a-f or A-F and `false` otherwise.
// Example: assert byte(`F`) == true
[inline]
pub fn (c byte) 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`)
}
// is_oct_digit returns `true` if the byte is in range 0-7 and `false` otherwise.
// Example: assert byte(`7`) == true
[inline]
pub fn (c byte) is_oct_digit() bool {
pub fn (c u8) is_oct_digit() bool {
return c >= `0` && c <= `7`
}
// is_bin_digit returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise.
// Example: assert byte(`0`) == true
[inline]
pub fn (c byte) is_bin_digit() bool {
pub fn (c u8) is_bin_digit() bool {
return c == `0` || c == `1`
}
// is_letter returns `true` if the byte is in range a-z or A-Z and `false` otherwise.
// Example: assert byte(`V`) == true
[inline]
pub fn (c byte) is_letter() bool {
pub fn (c u8) is_letter() bool {
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`)
}
// is_alnum returns `true` if the byte is in range a-z, A-Z, 0-9 and `false` otherwise.
// Example: assert byte(`V`) == true
[inline]
pub fn (c byte) is_alnum() bool {
pub fn (c u8) is_alnum() bool {
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`)
}
@ -1652,7 +1652,7 @@ pub fn (s string) after(sub string) string {
// If the substring is not found, it returns the full input string.
// Example: assert '23:34:45.234'.after_char(`:`) == '34:45.234'
// Example: assert 'abcd'.after_char(`:`) == 'abcd'
pub fn (s string) after_char(sub byte) string {
pub fn (s string) after_char(sub u8) string {
mut pos := -1
for i, c in s {
if c == sub {
@ -1685,13 +1685,13 @@ pub fn (a []string) join(sep string) string {
mut idx := 0
for i, val in a {
unsafe {
vmemcpy(res.str + idx, val.str, val.len)
vmemcpy(voidptr(res.str + idx), val.str, val.len)
idx += val.len
}
// Add sep if it's not last
if i != a.len - 1 {
unsafe {
vmemcpy(res.str + idx, sep.str, sep.len)
vmemcpy(voidptr(res.str + idx), sep.str, sep.len)
idx += sep.len
}
}
@ -1751,11 +1751,11 @@ pub fn (s string) hash() int {
}
// bytes returns the string converted to a byte array.
pub fn (s string) bytes() []byte {
pub fn (s string) bytes() []u8 {
if s.len == 0 {
return []
}
mut buf := []byte{len: s.len}
mut buf := []u8{len: s.len}
unsafe { vmemcpy(buf.data, s.str, s.len) }
return buf
}
@ -1839,7 +1839,7 @@ pub fn (s string) strip_margin() string {
// strip_margin_custom does the same as `strip_margin` but will use `del` as delimiter instead of `|`
[direct_array_access]
pub fn (s string) strip_margin_custom(del byte) string {
pub fn (s string) strip_margin_custom(del u8) string {
mut sep := del
if sep.is_space() {
println('Warning: `strip_margin` cannot use white-space as a delimiter')

View File

@ -159,7 +159,7 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) {
tail_zeros := ((x >> 16) & 0x01) > 0
width := int(i16((x >> 17) & 0x3FF))
mut base := int(x >> 27) & 0xF
fmt_pad_ch := byte((x >> 31) & 0xFF)
fmt_pad_ch := u8((x >> 31) & 0xFF)
// no string interpolation is needed, return empty string
if typ == .si_no_str {

View File

@ -61,7 +61,7 @@ pub fn string_from_wide2(_wstr &u16, len int) string {
// Reads an utf8 character from standard input
pub fn utf8_getchar() int {
c := C.getchar()
len := utf8_len(byte(~c))
len := utf8_len(u8(~c))
if c < 0 {
return 0
} else if len == 0 {

View File

@ -37,29 +37,29 @@ pub fn utf32_to_str_no_malloc(code u32, buf &byte) string {
pub fn utf32_decode_to_buffer(code u32, buf &byte) int {
unsafe {
icode := int(code) // Prevents doing casts everywhere
mut buffer := &byte(buf)
mut buffer := &u8(buf)
if icode <= 127 {
// 0x7F
buffer[0] = byte(icode)
buffer[0] = u8(icode)
return 1
} else if icode <= 2047 {
// 0x7FF
buffer[0] = 192 | byte(icode >> 6) // 0xC0 - 110xxxxx
buffer[1] = 128 | byte(icode & 63) // 0x80 - 0x3F - 10xxxxxx
buffer[0] = 192 | u8(icode >> 6) // 0xC0 - 110xxxxx
buffer[1] = 128 | u8(icode & 63) // 0x80 - 0x3F - 10xxxxxx
return 2
} else if icode <= 65535 {
// 0xFFFF
buffer[0] = 224 | byte(icode >> 12) // 0xE0 - 1110xxxx
buffer[1] = 128 | (byte(icode >> 6) & 63) // 0x80 - 0x3F - 10xxxxxx
buffer[2] = 128 | byte(icode & 63) // 0x80 - 0x3F - 10xxxxxx
buffer[0] = 224 | u8(icode >> 12) // 0xE0 - 1110xxxx
buffer[1] = 128 | (u8(icode >> 6) & 63) // 0x80 - 0x3F - 10xxxxxx
buffer[2] = 128 | u8(icode & 63) // 0x80 - 0x3F - 10xxxxxx
return 3
}
// 0x10FFFF
else if icode <= 1114111 {
buffer[0] = 240 | byte(icode >> 18) // 0xF0 - 11110xxx
buffer[1] = 128 | (byte(icode >> 12) & 63) // 0x80 - 0x3F - 10xxxxxx
buffer[2] = 128 | (byte(icode >> 6) & 63) // 0x80 - 0x3F - 10xxxxxx
buffer[3] = 128 | byte(icode & 63) // 0x80 - 0x3F - 10xxxxxx
buffer[0] = 240 | u8(icode >> 18) // 0xF0 - 11110xxx
buffer[1] = 128 | (u8(icode >> 12) & 63) // 0x80 - 0x3F - 10xxxxxx
buffer[2] = 128 | (u8(icode >> 6) & 63) // 0x80 - 0x3F - 10xxxxxx
buffer[3] = 128 | u8(icode & 63) // 0x80 - 0x3F - 10xxxxxx
return 4
}
}
@ -85,7 +85,7 @@ pub fn (_rune string) utf32_code() int {
// convert array of utf8 bytes to single utf32 value
// will error if more than 4 bytes are submitted
pub fn (_bytes []byte) utf8_to_utf32() ?rune {
pub fn (_bytes []u8) utf8_to_utf32() ?rune {
if _bytes.len == 0 {
return 0
}
@ -97,7 +97,7 @@ pub fn (_bytes []byte) utf8_to_utf32() ?rune {
return error('attempted to decode too many bytes, utf-8 is limited to four bytes maximum')
}
mut b := byte(int(_bytes[0]))
mut b := u8(int(_bytes[0]))
b = b << _bytes.len
mut res := rune(b)

View File

@ -52,7 +52,7 @@ pub fn leading_zeros_64(x u64) int {
// --- TrailingZeros ---
// trailing_zeros_8 returns the number of trailing zero bits in x; the result is 8 for x == 0.
pub fn trailing_zeros_8(x byte) int {
pub fn trailing_zeros_8(x u8) int {
return int(ntz_8_tab[x])
}
@ -95,7 +95,7 @@ pub fn trailing_zeros_64(x u64) int {
// --- OnesCount ---
// ones_count_8 returns the number of one bits ("population count") in x.
pub fn ones_count_8(x byte) int {
pub fn ones_count_8(x u8) int {
return int(pop_8_tab[x])
}
@ -148,7 +148,7 @@ pub fn ones_count_64(x u64) int {
[inline]
pub fn rotate_left_8(x byte, k int) byte {
n := byte(8)
s := byte(k) & (n - byte(1))
s := u8(k) & (n - u8(1))
return (x << s) | (x >> (n - s))
}
@ -188,7 +188,7 @@ pub fn rotate_left_64(x u64, k int) u64 {
// --- Reverse ---
// reverse_8 returns the value of x with its bits in reversed order.
[inline]
pub fn reverse_8(x byte) byte {
pub fn reverse_8(x u8) u8 {
return rev_8_tab[x]
}
@ -246,7 +246,7 @@ pub fn reverse_bytes_64(x u64) u64 {
// --- Len ---
// len_8 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
pub fn len_8(x byte) int {
pub fn len_8(x u8) int {
return int(len_8_tab[x])
}

View File

@ -114,8 +114,8 @@ fn (mut s Server) parse_client_handshake(client_handshake string, mut c Client)
// read_handshake_str returns the handshake response
fn (mut ws Client) read_handshake_str() ?string {
mut total_bytes_read := 0
mut msg := [1024]byte{}
mut buffer := [1]byte{}
mut msg := [1024]u8{}
mut buffer := [1]u8{}
for total_bytes_read < 1024 {
bytes_read := ws.socket_read_ptr(&buffer[0], 1) ?
if bytes_read == 0 {

View File

@ -22,7 +22,7 @@ pub fn fd_write(fd int, s string) {
return
}
remaining = remaining - written
sp = unsafe { sp + written }
sp = unsafe { voidptr(sp + written)}
}
}

View File

@ -281,7 +281,7 @@ pub fn (mut f File) write_full_buffer(buffer voidptr, buffer_len usize) ? {
if !f.is_opened {
return error_file_not_opened()
}
mut ptr := &byte(buffer)
mut ptr := &u8(buffer)
mut remaining_bytes := i64(buffer_len)
for remaining_bytes > 0 {
unsafe {
@ -390,12 +390,12 @@ pub fn (f &File) read_bytes_into_newline(mut buf []byte) ?int {
}
}
newline {
buf[buf_ptr] = byte(c)
buf[buf_ptr] = u8(c)
nbytes++
return nbytes
}
else {
buf[buf_ptr] = byte(c)
buf[buf_ptr] = u8(c)
buf_ptr++
nbytes++
}

View File

@ -230,7 +230,7 @@ pub fn cp(src string, dst string) ? {
}
// TODO use defer{} to close files in case of error or return.
// Currently there is a C-Error when building.
mut buf := [1024]byte{}
mut buf := [1024]u8{}
mut count := 0
for {
count = C.read(fp_from, &buf[0], sizeof(buf))

View File

@ -242,7 +242,7 @@ pub fn loginname() string {
return ''
}
fn init_os_args(argc int, argv &&byte) []string {
fn init_os_args(argc int, argv &&u8) []string {
mut args_ := []string{len: argc}
for i in 0 .. argc {
args_[i] = unsafe { tos_clone(argv[i]) }
@ -267,7 +267,7 @@ pub fn ls(path string) ?[]string {
break
}
unsafe {
bptr := &byte(&ent.d_name[0])
bptr := &u8(&ent.d_name[0])
if bptr[0] == 0 || (bptr[0] == `.` && bptr[1] == 0)
|| (bptr[0] == `.` && bptr[1] == `.` && bptr[2] == 0) {
continue
@ -348,7 +348,7 @@ pub fn execute(cmd string) Result {
defer {
unsafe { res.free() }
}
buf := [4096]byte{}
buf := [4096]u8{}
unsafe {
pbuf := &buf[0]
for {
@ -381,7 +381,7 @@ pub fn (mut c Command) start() ? {
[manualfree]
pub fn (mut c Command) read_line() string {
buf := [4096]byte{}
buf := [4096]u8{}
mut res := strings.new_builder(1024)
defer {
unsafe { res.free() }
@ -462,7 +462,7 @@ pub fn debugger_present() bool {
return false
}
fn C.mkstemp(stemplate &byte) int
fn C.mkstemp(stemplate &u8) int
// `is_writable_folder` - `folder` exists and is writable to the process
[manualfree]

View File

@ -22,7 +22,7 @@ fn internal_uuid_v4(mut rng PRNG) string {
x += 0x3030303030303030
// write the ASCII codes to the buffer:
for c < 8 && i_buf < buflen {
d = byte(x)
d = u8(x)
unsafe {
buf[i_buf] = if d > 0x39 { d + 0x27 } else { d }
}
@ -33,7 +33,7 @@ fn internal_uuid_v4(mut rng PRNG) string {
}
// there are still some random bits in x:
x = x >> 8
d = byte(x)
d = u8(x)
unsafe {
// From https://www.ietf.org/rfc/rfc4122.txt :
// >> Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved

View File

@ -39,14 +39,14 @@ pub fn (mut rng WyRandRNG) byte() byte {
// Can we extract a value from the buffer?
if rng.bytes_left >= 1 {
rng.bytes_left -= 1
value := byte(rng.buffer)
value := u8(rng.buffer)
rng.buffer >>= 8
return value
}
// Add a new value to the buffer
rng.buffer = rng.u64()
rng.bytes_left = 7
value := byte(rng.buffer)
value := u8(rng.buffer)
rng.buffer >>= 8
return value
}

View File

@ -98,7 +98,7 @@ pub fn common_parse_uint2(s string, _base int, _bit_size int) (u64, int) {
} else {
return n, i + 1
}
if d >= byte(base) {
if d >= u8(base) {
return n, i + 1
}
if n >= cutoff {

View File

@ -64,7 +64,7 @@ pub fn (d Dec32) get_string_32(neg bool, i_n_digit int, i_pad_digit int) string
fw_zeros = pad_digit - out_len
}
mut buf := []byte{len: int(out_len + 5 + 1 + 1)} // sign + mant_len + . + e + e_sign + exp_len(2) + \0}
mut buf := []u8{len: int(out_len + 5 + 1 + 1)} // sign + mant_len + . + e + e_sign + exp_len(2) + \0}
mut i := 0
if neg {
@ -92,7 +92,7 @@ pub fn (d Dec32) get_string_32(neg bool, i_n_digit int, i_pad_digit int) string
y := i + out_len
mut x := 0
for x < (out_len - disp - 1) {
buf[y - x] = `0` + byte(out % 10)
buf[y - x] = `0` + u8(out % 10)
out /= 10
i++
x++
@ -102,7 +102,7 @@ pub fn (d Dec32) get_string_32(neg bool, i_n_digit int, i_pad_digit int) string
if i_n_digit == 0 {
unsafe {
buf[i] = 0
return tos(&byte(&buf[0]), i)
return tos(&u8(&buf[0]), i)
}
}
@ -113,7 +113,7 @@ pub fn (d Dec32) get_string_32(neg bool, i_n_digit int, i_pad_digit int) string
}
if y - x >= 0 {
buf[y - x] = `0` + byte(out % 10)
buf[y - x] = `0` + u8(out % 10)
i++
}
@ -139,14 +139,14 @@ pub fn (d Dec32) get_string_32(neg bool, i_n_digit int, i_pad_digit int) string
// Always print two digits to match strconv's formatting.
d1 := exp % 10
d0 := exp / 10
buf[i] = `0` + byte(d0)
buf[i] = `0` + u8(d0)
i++
buf[i] = `0` + byte(d1)
buf[i] = `0` + u8(d1)
i++
buf[i] = 0
return unsafe {
tos(&byte(&buf[0]), i)
tos(&u8(&buf[0]), i)
}
}
@ -197,7 +197,7 @@ fn f32_to_decimal(mant u32, exp u32) Dec32 {
mut e10 := 0
mut vm_is_trailing_zeros := false
mut vr_is_trailing_zeros := false
mut last_removed_digit := byte(0)
mut last_removed_digit := u8(0)
if e2 >= 0 {
q := log10_pow2(e2)
@ -215,7 +215,7 @@ fn f32_to_decimal(mant u32, exp u32) Dec32 {
// we've found that 32-bit arithmetic is faster even on
// 64-bit machines.
l := pow5_inv_num_bits_32 + pow5_bits(int(q - 1)) - 1
last_removed_digit = byte(mul_pow5_invdiv_pow2(mv, q - 1, -e2 + int(q - 1) + l) % 10)
last_removed_digit = u8(mul_pow5_invdiv_pow2(mv, q - 1, -e2 + int(q - 1) + l) % 10)
}
if q <= 9 {
// The largest power of 5 that fits in 24 bits is 5^10,
@ -240,7 +240,7 @@ fn f32_to_decimal(mant u32, exp u32) Dec32 {
vm = mul_pow5_div_pow2(mm, u32(i), j)
if q != 0 && ((vp - 1) / 10) <= vm / 10 {
j = int(q) - 1 - (pow5_bits(i + 1) - pow5_num_bits_32)
last_removed_digit = byte(mul_pow5_div_pow2(mv, u32(i + 1), j) % 10)
last_removed_digit = u8(mul_pow5_div_pow2(mv, u32(i + 1), j) % 10)
}
if q <= 1 {
// {vr,vp,vm} is trailing zeros if {mv,mp,mm} has at
@ -270,7 +270,7 @@ fn f32_to_decimal(mant u32, exp u32) Dec32 {
for vp / 10 > vm / 10 {
vm_is_trailing_zeros = vm_is_trailing_zeros && (vm % 10) == 0
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
last_removed_digit = byte(vr % 10)
last_removed_digit = u8(vr % 10)
vr /= 10
vp /= 10
vm /= 10
@ -279,7 +279,7 @@ fn f32_to_decimal(mant u32, exp u32) Dec32 {
if vm_is_trailing_zeros {
for vm % 10 == 0 {
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
last_removed_digit = byte(vr % 10)
last_removed_digit = u8(vr % 10)
vr /= 10
vp /= 10
vm /= 10
@ -301,7 +301,7 @@ fn f32_to_decimal(mant u32, exp u32) Dec32 {
// are relative to this. Loop iterations below (approximately):
// 0: 13.6%, 1: 70.7%, 2: 14.1%, 3: 1.39%, 4: 0.14%, 5+: 0.01%
for vp / 10 > vm / 10 {
last_removed_digit = byte(vr % 10)
last_removed_digit = u8(vr % 10)
vr /= 10
vp /= 10
vm /= 10

View File

@ -35,7 +35,7 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string {
fw_zeros = pad_digit - out_len
}
mut buf := []byte{len: (out_len + 6 + 1 + 1 + fw_zeros)} // sign + mant_len + . + e + e_sign + exp_len(2) + \0}
mut buf := []u8{len: (out_len + 6 + 1 + 1 + fw_zeros)} // sign + mant_len + . + e + e_sign + exp_len(2) + \0}
mut i := 0
if neg {
@ -68,7 +68,7 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string {
y := i + out_len
mut x := 0
for x < (out_len - disp - 1) {
buf[y - x] = `0` + byte(out % 10)
buf[y - x] = `0` + u8(out % 10)
out /= 10
i++
x++
@ -78,7 +78,7 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string {
if i_n_digit == 0 {
unsafe {
buf[i] = 0
return tos(&byte(&buf[0]), i)
return tos(&u8(&buf[0]), i)
}
}
@ -89,7 +89,7 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string {
}
if y - x >= 0 {
buf[y - x] = `0` + byte(out % 10)
buf[y - x] = `0` + u8(out % 10)
i++
}
@ -118,17 +118,17 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string {
d1 := exp % 10
d0 := exp / 10
if d0 > 0 {
buf[i] = `0` + byte(d0)
buf[i] = `0` + u8(d0)
i++
}
buf[i] = `0` + byte(d1)
buf[i] = `0` + u8(d1)
i++
buf[i] = `0` + byte(d2)
buf[i] = `0` + u8(d2)
i++
buf[i] = 0
return unsafe {
tos(&byte(&buf[0]), i)
tos(&u8(&buf[0]), i)
}
}
@ -243,7 +243,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
// Step 4: Find the shortest decimal representation
// in the interval of valid representations.
mut removed := 0
mut last_removed_digit := byte(0)
mut last_removed_digit := u8(0)
mut out := u64(0)
// On average, we remove ~2 digits.
if vm_is_trailing_zeros || vr_is_trailing_zeros {
@ -259,7 +259,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
vr_mod_10 := vr % 10
vm_is_trailing_zeros = vm_is_trailing_zeros && vm_mod_10 == 0
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
last_removed_digit = byte(vr_mod_10)
last_removed_digit = u8(vr_mod_10)
vr = vr_div_10
vp = vp_div_10
vm = vm_div_10
@ -276,7 +276,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
vr_div_10 := vr / 10
vr_mod_10 := vr % 10
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
last_removed_digit = byte(vr_mod_10)
last_removed_digit = u8(vr_mod_10)
vr = vr_div_10
vp = vp_div_10
vm = vm_div_10

View File

@ -95,7 +95,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
//===========================================
// Speed version
// max u64 18446744073709551615 => 20 byte
mut buf := [32]byte{}
mut buf := [32]u8{}
mut i := 20
mut n := d
mut d_i := u64(0)
@ -147,7 +147,7 @@ pub fn f64_to_str_lnd1(f f64, dec_digit int) string {
m_sgn_flag := false
mut sgn := 1
mut b := [26]byte{}
mut b := [26]u8{}
mut d_pos := 1
mut i := 0
mut i1 := 0
@ -209,7 +209,7 @@ pub fn f64_to_str_lnd1(f f64, dec_digit int) string {
// allocate exp+32 chars for the return string
// mut res := []byte{len:exp+32,init:`0`}
mut res := []byte{len: exp + 32, init: 0}
mut res := []u8{len: exp + 32, init: 0}
mut r_i := 0 // result string buffer index
// println("s:${sgn} b:${b[0]} es:${exp_sgn} exp:${exp}")
@ -490,7 +490,7 @@ pub fn remove_tail_zeros(s string) string {
mut i_s1 := i_s + 1
mut sum := 0
for i_s1 < s.len && s[i_s1] >= `0` && s[i_s1] <= `9` {
sum += s[i_s1] - byte(`0`)
sum += s[i_s1] - u8(`0`)
i_s1++
}
// decimal part must be copied

View File

@ -68,7 +68,7 @@ pub fn fxx_to_str_l_parse(s string) string {
m_sgn_flag := false
mut sgn := 1
mut b := [26]byte{}
mut b := [26]u8{}
mut d_pos := 1
mut i := 0
mut i1 := 0
@ -119,7 +119,7 @@ pub fn fxx_to_str_l_parse(s string) string {
}
// allocate exp+32 chars for the return string
mut res := []byte{len: exp + 32, init: 0}
mut res := []u8{len: exp + 32, init: 0}
mut r_i := 0 // result string buffer index
// println("s:${sgn} b:${b[0]} es:${exp_sgn} exp:${exp}")
@ -191,7 +191,7 @@ pub fn fxx_to_str_l_parse_no_dot(s string) string {
m_sgn_flag := false
mut sgn := 1
mut b := [26]byte{}
mut b := [26]u8{}
mut d_pos := 1
mut i := 0
mut i1 := 0
@ -242,7 +242,7 @@ pub fn fxx_to_str_l_parse_no_dot(s string) string {
}
// allocate exp+32 chars for the return string
mut res := []byte{len: exp + 32, init: 0}
mut res := []u8{len: exp + 32, init: 0}
mut r_i := 0 // result string buffer index
// println("s:${sgn} b:${b[0]} es:${exp_sgn} exp:${exp}")

View File

@ -28,7 +28,7 @@ pub fn (mut b Builder) write_ptr(ptr &byte, len int) {
// write_rune appends a single rune to the accumulated buffer
[manualfree]
pub fn (mut b Builder) write_rune(r rune) {
mut buffer := [5]byte{}
mut buffer := [5]u8{}
res := unsafe { utf32_to_str_no_malloc(u32(r), &buffer[0]) }
if res.len == 0 {
return
@ -38,7 +38,7 @@ pub fn (mut b Builder) write_rune(r rune) {
// write_runes appends all the given runes to the accumulated buffer
pub fn (mut b Builder) write_runes(runes []rune) {
mut buffer := [5]byte{}
mut buffer := [5]u8{}
for r in runes {
res := unsafe { utf32_to_str_no_malloc(u32(r), &buffer[0]) }
if res.len == 0 {
@ -107,7 +107,7 @@ pub fn (mut b Builder) go_back(n int) {
fn (b &Builder) spart(start_pos int, n int) string {
unsafe {
mut x := malloc_noscan(n + 1)
vmemcpy(x, &byte(b.data) + start_pos, n)
vmemcpy(x, &u8(b.data) + start_pos, n)
x[n] = 0
return tos(x, n)
}

View File

@ -32,8 +32,8 @@ enum Direction {
}
struct Channel {
ringbuf &byte // queue for buffered channels
statusbuf &byte // flags to synchronize write/read in ringbuf
ringbuf &u8 // queue for buffered channels
statusbuf &u8 // flags to synchronize write/read in ringbuf
objsize u32
mut: // atomic
writesem Semaphore // to wake thread that wanted to write, but buffer was full
@ -70,8 +70,8 @@ pub fn new_channel<T>(n u32) &Channel {
fn new_channel_st(n u32, st u32) &Channel {
wsem := if n > 0 { n } else { 1 }
rsem := if n > 0 { u32(0) } else { 1 }
rbuf := if n > 0 { unsafe { malloc(int(n * st)) } } else { &byte(0) }
sbuf := if n > 0 { vcalloc_noscan(int(n * 2)) } else { &byte(0) }
rbuf := if n > 0 { unsafe { malloc(int(n * st)) } } else { &u8(0) }
sbuf := if n > 0 { vcalloc_noscan(int(n * 2)) } else { &u8(0) }
mut ch := Channel{
objsize: st
cap: n
@ -93,8 +93,8 @@ fn new_channel_st_noscan(n u32, st u32) &Channel {
$if gcboehm_opt ? {
wsem := if n > 0 { n } else { 1 }
rsem := if n > 0 { u32(0) } else { 1 }
rbuf := if n > 0 { unsafe { malloc_noscan(int(n * st)) } } else { &byte(0) }
sbuf := if n > 0 { vcalloc_noscan(int(n * 2)) } else { &byte(0) }
rbuf := if n > 0 { unsafe { malloc_noscan(int(n * st)) } } else { &u8(0) }
sbuf := if n > 0 { vcalloc_noscan(int(n * 2)) } else { &u8(0) }
mut ch := Channel{
objsize: st
cap: n
@ -322,7 +322,7 @@ fn (mut ch Channel) try_push_priv(src voidptr, no_block bool) ChanState {
mut wr_ptr := ch.ringbuf
mut status_adr := ch.statusbuf
unsafe {
wr_ptr += wr_idx * ch.objsize
wr_ptr += (wr_idx * ch.objsize)
status_adr += wr_idx * sizeof(u16)
}
mut expected_status := u16(BufferElemStat.unused)

View File

@ -6,5 +6,5 @@ mut:
c_oflag int
c_cflag int
c_lflag int
c_cc [20]byte
c_cc [20]u8
}

View File

@ -85,7 +85,7 @@ pub fn strip_ansi(text string) string {
// This is a port of https://github.com/kilobyte/colorized-logs/blob/master/ansi2txt.c
// \e, [, 1, m, a, b, c, \e, [, 2, 2, m => abc
mut input := textscanner.new(text)
mut output := []byte{cap: text.len}
mut output := []u8{cap: text.len}
mut ch := 0
for ch != -1 {
ch = input.next()
@ -117,7 +117,7 @@ pub fn strip_ansi(text string) string {
ch = input.next()
}
} else if ch != -1 {
output << byte(ch)
output << u8(ch)
}
}
return output.bytestr()

View File

@ -6,5 +6,5 @@ mut:
c_oflag int
c_cflag int
c_lflag int
c_cc [20]byte
c_cc [20]u8
}

View File

@ -286,7 +286,7 @@ fn (mut c Checker) eval_comptime_const_expr(expr ast.Expr, nlevel int) ?ast.Comp
.unsigned_right_shift { return i64(u64(left) >>> right) }
else { return none }
}
} else if left is byte && right is byte {
} else if left is u8 && right is u8 {
match expr.op {
.plus { return left + right }
.minus { return left - right }

View File

@ -4304,7 +4304,7 @@ fn (mut g Gen) const_decl_precomputed(mod string, name string, ct_value ast.Comp
if rune_code in [`"`, `\\`, `'`] {
return false
}
escval := util.smart_quote(byte(rune_code).ascii_str(), false)
escval := util.smart_quote(u8(rune_code).ascii_str(), false)
g.const_decl_write_precomputed(styp, cname, "'$escval'")
} else {
g.const_decl_write_precomputed(styp, cname, u32(ct_value).str())

View File

@ -102,15 +102,15 @@ fn amd64_bytes(nargs int) string {
else {
// see https://godbolt.org/z/64e5TEf5n for similar assembly
mut sb := strings.new_builder(256)
s := (((byte(nargs) & 1) + 1) << 3).hex()
s := (((u8(nargs) & 1) + 1) << 3).hex()
sb.write_string('0x48, 0x83, 0xec, 0x$s, ') // sub rsp,0x8 <OR> sub rsp,0x10
sb.write_string('0xff, 0x35, 0xe6, 0xff, 0xff, 0xff, ') // push QWORD PTR [rip+0xffffffffffffffe6]
rsp_offset := byte(0x18 + ((byte(nargs - 7) >> 1) << 4)).hex()
rsp_offset := byte(0x18 + ((u8(nargs - 7) >> 1) << 4)).hex()
for _ in 0 .. nargs - 7 {
sb.write_string('0xff, 0xb4, 0x24, 0x$rsp_offset, 0x00, 0x00, 0x00, ') // push QWORD PTR [rsp+$rsp_offset]
}
sb.write_string('0xff, 0x15, 0x${byte(256 - sb.len / 6 - 6 - 8).hex()}, 0xff, 0xff, 0xff, ') // call QWORD PTR [rip+OFFSET]
sb.write_string('0xff, 0x15, 0x${u8(256 - sb.len / 6 - 6 - 8).hex()}, 0xff, 0xff, 0xff, ') // call QWORD PTR [rip+OFFSET]
sb.write_string('0x48, 0x81, 0xc4, 0x$rsp_offset, 0x00, 0x00, 0x00, ') // add rsp,$rsp_offset
sb.write_string('0xc3') // ret

View File

@ -1074,7 +1074,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
// g.write('&')
} else if diff > 0 {
g.write('/*diff=$diff*/')
g.write([]byte{len: diff, init: `*`}.bytestr())
g.write([]u8{len: diff, init: `*`}.bytestr())
}
}

View File

@ -116,7 +116,7 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int) (u64, string) {
pad_ch = 1
}
res := get_str_intp_u32_format(fmt_type, node.fwidths[i], node.precisions[i], remove_tail_zeros,
node.pluss[i], byte(pad_ch), base, upper_case)
node.pluss[i], u8(pad_ch), base, upper_case)
//
return res, fmt_type.str()
}

View File

@ -560,7 +560,7 @@ pub fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_d
'i64' {
ret = ast.i64_type
}
'byte' {
'u8' {
ret = ast.byte_type
}
'u16' {

View File

@ -1279,7 +1279,7 @@ fn decode_h_escapes(s string, start int, escapes_pos []int) string {
idx := pos - start
end_idx := idx + 4 // "\xXX".len == 4
// notice this function doesn't do any decoding... it just replaces '\xc0' with the byte 0xc0
ss << [byte(strconv.parse_uint(s[idx + 2..end_idx], 16, 8) or { 0 })].bytestr()
ss << [u8(strconv.parse_uint(s[idx + 2..end_idx], 16, 8) or { 0 })].bytestr()
if i + 1 < escapes_pos.len {
ss << s[end_idx..escapes_pos[i + 1] - start]
} else {
@ -1300,7 +1300,7 @@ fn decode_o_escapes(s string, start int, escapes_pos []int) string {
idx := pos - start
end_idx := idx + 4 // "\XXX".len == 4
// notice this function doesn't do any decoding... it just replaces '\141' with the byte 0o141
ss << [byte(strconv.parse_uint(s[idx + 1..end_idx], 8, 8) or { 0 })].bytestr()
ss << [u8(strconv.parse_uint(s[idx + 1..end_idx], 8, 8) or { 0 })].bytestr()
if i + 1 < escapes_pos.len {
ss << s[end_idx..escapes_pos[i + 1] - start]
} else {

View File

@ -6,7 +6,7 @@ pub const v_version = '0.2.4'
// vhash() returns the build string C.V_COMMIT_HASH . See cmd/tools/gen_vc.v .
pub fn vhash() string {
mut buf := [50]byte{}
mut buf := [50]u8{}
buf[0] = 0
unsafe {
bp := &buf[0]
@ -75,7 +75,7 @@ pub fn githash(should_get_from_filesystem bool) string {
}
break
}
mut buf := [50]byte{}
mut buf := [50]u8{}
buf[0] = 0
unsafe {
bp := &buf[0]