ci: fix some of `v test-cleancode` 3
parent
c0e2b9b1e2
commit
d11fb8497a
|
@ -18,6 +18,8 @@ const (
|
||||||
]
|
]
|
||||||
verify_known_failing_exceptions = [
|
verify_known_failing_exceptions = [
|
||||||
'vlib/builtin/int_test.v' /* special number formatting that should be tested */,
|
'vlib/builtin/int_test.v' /* special number formatting that should be tested */,
|
||||||
|
'vlib/builtin/int.v' /* vfmt converts `pub fn (nn byteptr) str() string {` to `nn &byte` and that conflicts with `nn byte` */,
|
||||||
|
'vlib/builtin/string_charptr_byteptr_helpers.v' /* a temporary shim to ease the byteptr=>&byte transition */,
|
||||||
'vlib/gg/m4/graphic.v' /* has hand crafted meaningful formatting of matrices */,
|
'vlib/gg/m4/graphic.v' /* has hand crafted meaningful formatting of matrices */,
|
||||||
'vlib/gg/m4/m4_test.v' /* has hand crafted meaningful formatting of matrices */,
|
'vlib/gg/m4/m4_test.v' /* has hand crafted meaningful formatting of matrices */,
|
||||||
'vlib/gg/m4/matrix.v' /* has hand crafted meaningful formatting of matrices */,
|
'vlib/gg/m4/matrix.v' /* has hand crafted meaningful formatting of matrices */,
|
||||||
|
|
|
@ -337,16 +337,16 @@ fn split_int_errno(rc_in u64) (i64, Errno) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0 sys_read unsigned int fd char *buf size_t count
|
// 0 sys_read unsigned int fd char *buf size_t count
|
||||||
pub fn sys_read(fd i64, buf byteptr, count u64) (i64, Errno) {
|
pub fn sys_read(fd i64, buf &byte, count u64) (i64, Errno) {
|
||||||
return split_int_errno(sys_call3(0, u64(fd), u64(buf), count))
|
return split_int_errno(sys_call3(0, u64(fd), u64(buf), count))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 sys_write unsigned int fd, const char *buf, size_t count
|
// 1 sys_write unsigned int fd, const char *buf, size_t count
|
||||||
pub fn sys_write(fd i64, buf byteptr, count u64) (i64, Errno) {
|
pub fn sys_write(fd i64, buf &byte, count u64) (i64, Errno) {
|
||||||
return split_int_errno(sys_call3(1, u64(fd), u64(buf), count))
|
return split_int_errno(sys_call3(1, u64(fd), u64(buf), count))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_open(filename byteptr, flags i64, mode int) (i64, Errno) {
|
pub fn sys_open(filename &byte, flags i64, mode int) (i64, Errno) {
|
||||||
// 2 sys_open const char *filename int flags int mode
|
// 2 sys_open const char *filename int flags int mode
|
||||||
return split_int_errno(sys_call3(2, u64(filename), u64(flags), u64(mode)))
|
return split_int_errno(sys_call3(2, u64(filename), u64(flags), u64(mode)))
|
||||||
}
|
}
|
||||||
|
@ -357,10 +357,10 @@ pub fn sys_close(fd i64) Errno {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9 sys_mmap unsigned long addr unsigned long len unsigned long prot unsigned long flags unsigned long fd unsigned long off
|
// 9 sys_mmap unsigned long addr unsigned long len unsigned long prot unsigned long flags unsigned long fd unsigned long off
|
||||||
pub fn sys_mmap(addr byteptr, len u64, prot Mm_prot, flags Map_flags, fildes u64, off u64) (byteptr, 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 byteptr(a), e
|
return &byte(a), e
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_munmap(addr voidptr, len u64) Errno {
|
pub fn sys_munmap(addr voidptr, len u64) Errno {
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub fn mm_pages(size u64) u32 {
|
||||||
return u32(pages)
|
return u32(pages)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mm_alloc(size u64) (byteptr, Errno) {
|
pub fn mm_alloc(size u64) (&byte, Errno) {
|
||||||
pages := mm_pages(size)
|
pages := mm_pages(size)
|
||||||
n_bytes := u64(pages * u32(Linux_mem.page_size))
|
n_bytes := u64(pages * u32(Linux_mem.page_size))
|
||||||
|
|
||||||
|
@ -19,12 +19,12 @@ pub fn mm_alloc(size u64) (byteptr, Errno) {
|
||||||
if e == .enoerror {
|
if e == .enoerror {
|
||||||
mut ap := &int(a)
|
mut ap := &int(a)
|
||||||
*ap = pages
|
*ap = pages
|
||||||
return byteptr(a + 4), e
|
return &byte(a + 4), e
|
||||||
}
|
}
|
||||||
return byteptr(0), e
|
return &byte(0), e
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mm_free(addr byteptr) Errno {
|
pub fn mm_free(addr &byte) Errno {
|
||||||
ap := &int(addr - 4)
|
ap := &int(addr - 4)
|
||||||
size := u64(*ap) * u64(Linux_mem.page_size)
|
size := u64(*ap) * u64(Linux_mem.page_size)
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ pub fn mm_free(addr byteptr) 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 := byteptr(dest0)
|
mut dest := &byte(dest0)
|
||||||
src := byteptr(src0)
|
src := &byte(src0)
|
||||||
for i in 0 .. n {
|
for i in 0 .. n {
|
||||||
dest[i] = src[i]
|
dest[i] = src[i]
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ pub fn mem_copy(dest0 voidptr, src0 voidptr, n int) voidptr {
|
||||||
}
|
}
|
||||||
|
|
||||||
[unsafe]
|
[unsafe]
|
||||||
pub fn malloc(n int) byteptr {
|
pub fn malloc(n int) &byte {
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
panic('malloc(<0)')
|
panic('malloc(<0)')
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,17 @@ module builtin
|
||||||
|
|
||||||
pub struct string {
|
pub struct string {
|
||||||
pub:
|
pub:
|
||||||
str byteptr
|
str &byte
|
||||||
len int
|
len int
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn strlen(s byteptr) int {
|
pub fn strlen(s &byte) int {
|
||||||
mut i := 0
|
mut i := 0
|
||||||
for ; s[i] != 0; i++ {}
|
for ; s[i] != 0; i++ {}
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tos(s byteptr, len int) string {
|
pub fn tos(s &byte, len int) string {
|
||||||
if s == 0 {
|
if s == 0 {
|
||||||
panic('tos(): nil string')
|
panic('tos(): nil string')
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ pub fn tos_clone(s byteptr) string {
|
||||||
|
|
||||||
// Same as `tos`, but calculates the length. Called by `string(bytes)` casts.
|
// Same as `tos`, but calculates the length. Called by `string(bytes)` casts.
|
||||||
// Used only internally.
|
// Used only internally.
|
||||||
pub fn tos2(s byteptr) string {
|
pub fn tos2(s &byte) string {
|
||||||
if s == 0 {
|
if s == 0 {
|
||||||
panic('tos2: nil string')
|
panic('tos2: nil string')
|
||||||
}
|
}
|
||||||
|
@ -59,13 +59,13 @@ pub fn tos2(s byteptr) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tos3(s charptr) string {
|
pub fn tos3(s &char) string {
|
||||||
if s == 0 {
|
if s == 0 {
|
||||||
panic('tos3: nil string')
|
panic('tos3: nil string')
|
||||||
}
|
}
|
||||||
return string{
|
return string{
|
||||||
str: byteptr(s)
|
str: &byte(s)
|
||||||
len: strlen(byteptr(s))
|
len: strlen(&byte(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ pub fn string_ne(s1 string, s2 string) bool {
|
||||||
return !string_eq(s1, s2)
|
return !string_eq(s1, s2)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn i64_tos(buf byteptr, len int, n0 i64, base int) string {
|
pub fn i64_tos(buf &byte, len int, n0 i64, base int) string {
|
||||||
if base < 2 {
|
if base < 2 {
|
||||||
panic('base must be >= 2')
|
panic('base must be >= 2')
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,8 +349,8 @@ fn new_map_2(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqF
|
||||||
fn new_map_init_2(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 {
|
fn new_map_init_2(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_2(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn)
|
mut out := new_map_2(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn)
|
||||||
// TODO pre-allocate n slots
|
// TODO pre-allocate n slots
|
||||||
mut pkey := byteptr(keys)
|
mut pkey := &byte(keys)
|
||||||
mut pval := byteptr(values)
|
mut pval := &byte(values)
|
||||||
for _ in 0 .. n {
|
for _ in 0 .. n {
|
||||||
unsafe {
|
unsafe {
|
||||||
out.set_1(pkey, pval)
|
out.set_1(pkey, pval)
|
||||||
|
@ -688,7 +688,7 @@ pub fn (mut m map) delete_1(key voidptr) {
|
||||||
// delete this
|
// delete this
|
||||||
pub fn (m &map) keys() []string {
|
pub fn (m &map) keys() []string {
|
||||||
mut keys := []string{len: m.len}
|
mut keys := []string{len: m.len}
|
||||||
mut item := unsafe { byteptr(keys.data) }
|
mut item := unsafe { &byte(keys.data) }
|
||||||
for i := 0; i < m.key_values.len; i++ {
|
for i := 0; i < m.key_values.len; i++ {
|
||||||
if !m.key_values.has_index(i) {
|
if !m.key_values.has_index(i) {
|
||||||
continue
|
continue
|
||||||
|
@ -705,7 +705,7 @@ pub fn (m &map) keys() []string {
|
||||||
// Returns all keys in the map.
|
// Returns all keys in the map.
|
||||||
fn (m &map) keys_1() array {
|
fn (m &map) keys_1() array {
|
||||||
mut keys := __new_array(m.len, 0, m.key_bytes)
|
mut keys := __new_array(m.len, 0, m.key_bytes)
|
||||||
mut item := unsafe { byteptr(keys.data) }
|
mut item := unsafe { &byte(keys.data) }
|
||||||
if m.key_values.deletes == 0 {
|
if m.key_values.deletes == 0 {
|
||||||
for i := 0; i < m.key_values.len; i++ {
|
for i := 0; i < m.key_values.len; i++ {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -196,9 +196,9 @@ fn test_various_map_value() {
|
||||||
mut m14 := map[string]voidptr{}
|
mut m14 := map[string]voidptr{}
|
||||||
m14['test'] = voidptr(0)
|
m14['test'] = voidptr(0)
|
||||||
assert m14['test'] == voidptr(0)
|
assert m14['test'] == voidptr(0)
|
||||||
mut m15 := map[string]byteptr{}
|
mut m15 := map[string]&byte{}
|
||||||
m15['test'] = byteptr(0)
|
m15['test'] = &byte(0)
|
||||||
assert m15['test'] == byteptr(0)
|
assert m15['test'] == &byte(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)
|
||||||
|
|
|
@ -67,7 +67,7 @@ fn opt_ok(data voidptr, mut option Option, size int) {
|
||||||
unsafe {
|
unsafe {
|
||||||
*option = Option{}
|
*option = Option{}
|
||||||
// use err to get the end of OptionBase and then memcpy into it
|
// use err to get the end of OptionBase and then memcpy into it
|
||||||
C.memcpy(byteptr(&option.err) + sizeof(IError), data, size)
|
C.memcpy(&byte(&option.err) + sizeof(IError), data, size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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], byteptr(values) + i * value_bytes)
|
out.set(keys[i], &byte(values) + i * value_bytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
|
@ -3126,9 +3126,13 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
||||||
&& left_sym.kind != .interface_ {
|
&& left_sym.kind != .interface_ {
|
||||||
// Dual sides check (compatibility check)
|
// Dual sides check (compatibility check)
|
||||||
c.check_expected(right_type_unwrapped, left_type_unwrapped) or {
|
c.check_expected(right_type_unwrapped, left_type_unwrapped) or {
|
||||||
|
// allow for ptr += 2
|
||||||
|
if !left_type_unwrapped.is_ptr() && !right_type_unwrapped.is_int()
|
||||||
|
&& assign_stmt.op !in [.plus_assign, .minus_assign] {
|
||||||
c.error('cannot assign to `$left`: $err.msg', right.position())
|
c.error('cannot assign to `$left`: $err.msg', right.position())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if left_sym.kind == .interface_ {
|
if left_sym.kind == .interface_ {
|
||||||
c.type_implements(right_type, left_type, right.position())
|
c.type_implements(right_type, left_type, right.position())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue