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

builtin: vfmt every .v file, except vlib/builtin/int_test.v (#9448)

This commit is contained in:
zakuro
2021-03-25 03:39:59 +09:00
committed by GitHub
parent 5d8b9b0151
commit 6bc9ef7373
19 changed files with 259 additions and 272 deletions

View File

@@ -1,31 +1,31 @@
module builtin
const (
mem_prot = Mm_prot(int(Mm_prot.prot_read) | int(Mm_prot.prot_write))
mem_prot = Mm_prot(int(Mm_prot.prot_read) | int(Mm_prot.prot_write))
mem_flags = Map_flags(int(Map_flags.map_private) | int(Map_flags.map_anonymous))
page_size = u64(Linux_mem.page_size)
)
pub fn mm_pages(size u64) u32 {
pages := (size+u64(4)+page_size)/page_size
pages := (size + u64(4) + page_size) / page_size
return u32(pages)
}
pub fn mm_alloc(size u64) (byteptr, Errno) {
pages := mm_pages(size)
n_bytes := u64(pages*u32(Linux_mem.page_size))
n_bytes := u64(pages * u32(Linux_mem.page_size))
a, e := sys_mmap(0, n_bytes, mem_prot, mem_flags, -1, 0)
if e == .enoerror {
mut ap := &int(a)
*ap = pages
return byteptr(a+4), e
return byteptr(a + 4), e
}
return byteptr(0), e
}
pub fn mm_free(addr byteptr) Errno {
ap := &int(addr-4)
ap := &int(addr - 4)
size := u64(*ap) * u64(Linux_mem.page_size)
return sys_munmap(ap, size)
@@ -34,7 +34,7 @@ pub fn mm_free(addr byteptr) Errno {
pub fn mem_copy(dest0 voidptr, src0 voidptr, n int) voidptr {
mut dest := byteptr(dest0)
src := byteptr(src0)
for i in 0..n {
for i in 0 .. n {
dest[i] = src[i]
}
return dest0