Skip to content

Commit

Permalink
refactor: rename vars and params to prevent module name shadowing (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Aug 12, 2023
1 parent 42908e4 commit b3521cf
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion kernel/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn kmain() {
serial.early_initialise()

// We're alive
kprint.kprint(c'Welcome to Vinix\n\n')
kprint.kwrite(c'Welcome to Vinix\n\n')

// a dummy call to avoid V warning about an unused `stubs` module
_ := stubs.toupper(0)
Expand Down
20 changes: 10 additions & 10 deletions kernel/modules/bitmap/bitmap.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ mut:
entry_cnt u64
}

pub fn (mut bitmap GenericBitmap) initialise(entry_cnt u64) {
bitmap.entry_cnt = entry_cnt
bitmap.raw_bitmap = memory.calloc(lib.div_roundup(entry_cnt, u64(8)), 1)
pub fn (mut bmp GenericBitmap) initialise(entry_cnt u64) {
bmp.entry_cnt = entry_cnt
bmp.raw_bitmap = memory.calloc(lib.div_roundup(entry_cnt, u64(8)), 1)
}

pub fn (bitmap GenericBitmap) alloc() ?u64 {
for i := u64(0); i < bitmap.entry_cnt; i++ {
if lib.bittest(bitmap.raw_bitmap, i) == false {
lib.bitset(bitmap.raw_bitmap, i)
pub fn (bmp GenericBitmap) alloc() ?u64 {
for i := u64(0); i < bmp.entry_cnt; i++ {
if lib.bittest(bmp.raw_bitmap, i) == false {
lib.bitset(bmp.raw_bitmap, i)
return i
}
}
return none
}

pub fn (bitmap GenericBitmap) free_entry(index u64) {
if index < bitmap.entry_cnt {
lib.bitreset(bitmap.raw_bitmap, index)
pub fn (bmp GenericBitmap) free_entry(index u64) {
if index < bmp.entry_cnt {
lib.bitreset(bmp.raw_bitmap, index)
}
}
4 changes: 2 additions & 2 deletions kernel/modules/errno/errno.v
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ pub fn get() u64 {
return proc.current_thread().errno
}

pub fn set(errno u64) {
proc.current_thread().errno = errno
pub fn set(err_no u64) {
proc.current_thread().errno = err_no
}
40 changes: 20 additions & 20 deletions kernel/modules/event/event.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,41 @@ fn attach_listeners(mut events []&eventstruct.Event, mut thread proc.Thread) {
thread.attached_events_i = 0

for i := u64(0); i < events.len; i++ {
mut event := events[i]
mut e := events[i]

if event.listeners_i == eventstruct.max_listeners {
if e.listeners_i == eventstruct.max_listeners {
panic('event listeners exhausted')
}

mut listener := &event.listeners[event.listeners_i]
mut listener := &e.listeners[e.listeners_i]

listener.thread = voidptr(thread)
listener.which = i

event.listeners_i++
e.listeners_i++

if thread.attached_events_i == proc.max_events {
panic('listening on too many events')
}

thread.attached_events[thread.attached_events_i] = event
thread.attached_events[thread.attached_events_i] = e
thread.attached_events_i++
}
}

fn detach_listeners(mut thread proc.Thread) {
for i := u64(0); i < thread.attached_events_i; i++ {
mut event := thread.attached_events[i]
mut e := thread.attached_events[i]

for j := u64(0); j < event.listeners_i; j++ {
mut listener := &event.listeners[j]
for j := u64(0); j < e.listeners_i; j++ {
mut listener := &e.listeners[j]

if listener.thread != voidptr(thread) {
continue
}

event.listeners[j] = event.listeners[event.listeners_i - 1]
event.listeners_i--
e.listeners[j] = e.listeners[e.listeners_i - 1]
e.listeners_i--

break
}
Expand Down Expand Up @@ -139,7 +139,7 @@ pub fn await(mut events []&eventstruct.Event, block bool) ?u64 {
return thread.which_event
}

pub fn trigger(mut event eventstruct.Event, drop bool) u64 {
pub fn trigger(mut e eventstruct.Event, drop bool) u64 {
ints := cpu.interrupt_state()

asm volatile amd64 {
Expand All @@ -153,29 +153,29 @@ pub fn trigger(mut event eventstruct.Event, drop bool) u64 {
}
}

event.@lock.acquire()
e.@lock.acquire()
defer {
event.@lock.release()
e.@lock.release()
}

if event.listeners_i == 0 {
if e.listeners_i == 0 {
if drop == false {
event.pending++
e.pending++
}
return 0
}

for i := u64(0); i < event.listeners_i; i++ {
mut thread := unsafe { &proc.Thread(event.listeners[i].thread) }
for i := u64(0); i < e.listeners_i; i++ {
mut thread := unsafe { &proc.Thread(e.listeners[i].thread) }

thread.which_event = event.listeners[i].which
thread.which_event = e.listeners[i].which

sched.enqueue_thread(thread, false)
}

ret := event.listeners_i
ret := e.listeners_i

event.listeners_i = 0
e.listeners_i = 0

return ret
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/modules/fs/vfs.v
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ pub fn mount(parent &VFSNode, source string, target string, filesystem string) ?
return none
}

mut fs := filesystems[filesystem].instantiate()
mut f_sys := filesystems[filesystem].instantiate()

mut mount_node := fs.mount(parent_of_tgt_node, basename, source_node)?
mut mount_node := f_sys.mount(parent_of_tgt_node, basename, source_node)?

target_node.mountpoint = mount_node

Expand Down
2 changes: 1 addition & 1 deletion kernel/modules/kprint/kprint.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn syscall_kprint(_ voidptr, message charptr) {
}
}

pub fn kprint(message charptr) {
pub fn kwrite(message charptr) {
msglen := unsafe { u64(C.strlen(message)) }

kprint_lock.acquire()
Expand Down
2 changes: 1 addition & 1 deletion kernel/modules/lib/stubs/file.v
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn write(fd int, buf &C.void, count u64) i64 {
lib.kpanic(voidptr(0), c'write to fd != 1 && fd != 2 is a stub')
}

kprint.kprint(charptr(buf))
kprint.kwrite(charptr(buf))

return i64(count)
}
Expand Down
6 changes: 3 additions & 3 deletions kernel/modules/pipe/pipe.v
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ pub mut:
pub fn initialise() {}

pub fn create() ?&Pipe {
mut pipe := &Pipe{
mut p := &Pipe{
data: unsafe { C.malloc(pipe.pipe_buf) }
capacity: pipe.pipe_buf
}
pipe.stat.mode = stat.ifpipe
p.stat.mode = stat.ifpipe

return pipe
return p
}

pub fn syscall_pipe(_ voidptr, pipefds &int, flags int) (u64, u64) {
Expand Down
40 changes: 20 additions & 20 deletions kernel/modules/socket/socket.v
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn syscall_socket(_ voidptr, domain int, @type int, protocol int) (u64, u64)
C.printf(c'\e[32m%s\e[m: returning\n', process.name.str)
}

mut socket := socket_create(domain, @type, protocol) or { return errno.err, errno.get() }
mut sock := socket_create(domain, @type, protocol) or { return errno.err, errno.get() }

mut flags := int(0)
if @type & sock_pub.sock_cloexec != 0 {
Expand All @@ -94,7 +94,7 @@ pub fn syscall_socket(_ voidptr, domain int, @type int, protocol int) (u64, u64)
flags |= resource.o_nonblock
}

ret := file.fdnum_create_from_resource(voidptr(0), mut socket, flags, 0, false) or {
ret := file.fdnum_create_from_resource(voidptr(0), mut sock, flags, 0, false) or {
return errno.err, errno.get()
}

Expand All @@ -117,15 +117,15 @@ pub fn syscall_accept(_ voidptr, fdnum int) (u64, u64) {

res := fd.handle.resource

mut socket := &sock_pub.Socket(voidptr(0))
mut sock := &sock_pub.Socket(voidptr(0))

if res is sock_unix.UnixSocket {
socket = res
sock = res
} else {
return errno.err, errno.einval
}

mut connection_socket := socket.accept(fd.handle) or {
mut connection_socket := sock.accept(fd.handle) or {
return errno.err, errno.get()
}

Expand All @@ -152,15 +152,15 @@ pub fn syscall_bind(_ voidptr, fdnum int, _addr voidptr, addrlen u64) (u64, u64)

res := fd.handle.resource

mut socket := &sock_pub.Socket(voidptr(0))
mut sock := &sock_pub.Socket(voidptr(0))

if res is sock_unix.UnixSocket {
socket = res
sock = res
} else {
return errno.err, errno.einval
}

socket.bind(fd.handle, _addr, addrlen) or { return errno.err, errno.get() }
sock.bind(fd.handle, _addr, addrlen) or { return errno.err, errno.get() }

return 0, 0
}
Expand All @@ -181,15 +181,15 @@ pub fn syscall_listen(_ voidptr, fdnum int, backlog int) (u64, u64) {

res := fd.handle.resource

mut socket := &sock_pub.Socket(voidptr(0))
mut sock := &sock_pub.Socket(voidptr(0))

if res is sock_unix.UnixSocket {
socket = res
sock = res
} else {
return errno.err, errno.einval
}

socket.listen(fd.handle, backlog) or { return errno.err, errno.get() }
sock.listen(fd.handle, backlog) or { return errno.err, errno.get() }

return 0, 0
}
Expand All @@ -210,15 +210,15 @@ pub fn syscall_recvmsg(_ voidptr, fdnum int, msg &sock_pub.MsgHdr, flags int) (u

res := fd.handle.resource

mut socket := &sock_pub.Socket(voidptr(0))
mut sock := &sock_pub.Socket(voidptr(0))

if res is sock_unix.UnixSocket {
socket = res
sock = res
} else {
return errno.err, errno.einval
}

ret := socket.recvmsg(fd.handle, msg, flags) or { return errno.err, errno.get() }
ret := sock.recvmsg(fd.handle, msg, flags) or { return errno.err, errno.get() }

return ret, 0
}
Expand All @@ -239,15 +239,15 @@ pub fn syscall_connect(_ voidptr, fdnum int, _addr voidptr, addrlen u64) (u64, u

res := fd.handle.resource

mut socket := &sock_pub.Socket(voidptr(0))
mut sock := &sock_pub.Socket(voidptr(0))

if res is sock_unix.UnixSocket {
socket = res
sock = res
} else {
return errno.err, errno.einval
}

socket.connect(fd.handle, _addr, addrlen) or { return errno.err, errno.get() }
sock.connect(fd.handle, _addr, addrlen) or { return errno.err, errno.get() }

return 0, 0
}
Expand All @@ -268,15 +268,15 @@ pub fn syscall_getpeername(_ voidptr, fdnum int, _addr voidptr, addrlen &u64) (u

res := fd.handle.resource

mut socket := &sock_pub.Socket(voidptr(0))
mut sock := &sock_pub.Socket(voidptr(0))

if res is sock_unix.UnixSocket {
socket = res
sock = res
} else {
return errno.err, errno.einval
}

socket.peername(fd.handle, _addr, addrlen) or { return errno.err, errno.get() }
sock.peername(fd.handle, _addr, addrlen) or { return errno.err, errno.get() }

return 0, 0
}

0 comments on commit b3521cf

Please sign in to comment.