diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index 8ee5f0c250..2603d7edf3 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -346,39 +346,54 @@ fn C.ReleaseSRWLockShared(voidptr) fn C.ReleaseSRWLockExclusive(voidptr) // pthread.h -[trusted] fn C.pthread_mutex_init(voidptr, voidptr) int + fn C.pthread_mutex_lock(voidptr) int + fn C.pthread_mutex_unlock(voidptr) int + fn C.pthread_mutex_destroy(voidptr) int + fn C.pthread_rwlockattr_init(voidptr) int + fn C.pthread_rwlockattr_setkind_np(voidptr, int) int + fn C.pthread_rwlockattr_setpshared(voidptr, int) int + fn C.pthread_rwlock_init(voidptr, voidptr) int + fn C.pthread_rwlock_rdlock(voidptr) int + fn C.pthread_rwlock_wrlock(voidptr) int + fn C.pthread_rwlock_unlock(voidptr) int fn C.pthread_condattr_init(voidptr) int + fn C.pthread_condattr_setpshared(voidptr, int) int + fn C.pthread_condattr_destroy(voidptr) int + fn C.pthread_cond_init(voidptr, voidptr) int + fn C.pthread_cond_signal(voidptr) int + fn C.pthread_cond_wait(voidptr, voidptr) int + fn C.pthread_cond_timedwait(voidptr, voidptr, voidptr) int + fn C.pthread_cond_destroy(voidptr) int -[trusted] fn C.sem_init(voidptr, int, u32) int -[trusted] + fn C.sem_post(voidptr) int -[trusted] + fn C.sem_wait(voidptr) int -[trusted] + fn C.sem_trywait(voidptr) int -[trusted] + fn C.sem_timedwait(voidptr, voidptr) int -[trusted] + fn C.sem_destroy(voidptr) int // MacOS semaphore functions diff --git a/vlib/net/unix/aasocket.c.v b/vlib/net/unix/aasocket.c.v index 118874a4f4..a40639e54a 100644 --- a/vlib/net/unix/aasocket.c.v +++ b/vlib/net/unix/aasocket.c.v @@ -43,3 +43,60 @@ mut: struct C.sockaddr_storage { } + +fn C.socket() int + +fn C.setsockopt() int + +fn C.htonl() int + +fn C.htons() int + +fn C.bind() int + +fn C.listen() int + +fn C.accept() int + +fn C.getaddrinfo() int + +fn C.connect() int + +fn C.send() int + +fn C.sendto() int + +fn C.recv() int + +fn C.recvfrom() int + +fn C.shutdown() int + +fn C.ntohs() int + +fn C.getpeername() int + +fn C.inet_ntop(af int, src voidptr, dst charptr, dst_size int) charptr + +fn C.WSAAddressToStringA() int + +fn C.getsockname() int + +// defined in builtin +// fn C.read() int +// fn C.close() int + +fn C.ioctlsocket() int + +fn C.fcntl() int + +fn C.@select() int + +fn C.FD_ZERO() + +fn C.FD_SET() + +fn C.FD_ISSET() bool + +[typedef] +struct C.fd_set {} diff --git a/vlib/sync/channels.v b/vlib/sync/channels.v index 8b66594c3b..017a75a74e 100644 --- a/vlib/sync/channels.v +++ b/vlib/sync/channels.v @@ -24,9 +24,7 @@ fn C.atomic_store_ptr(voidptr, voidptr) fn C.atomic_compare_exchange_weak_ptr(voidptr, voidptr, voidptr) bool fn C.atomic_compare_exchange_strong_ptr(voidptr, voidptr, voidptr) bool fn C.atomic_exchange_ptr(voidptr, voidptr) voidptr -[trusted] fn C.atomic_fetch_add_ptr(voidptr, voidptr) voidptr -[trusted] fn C.atomic_fetch_sub_ptr(voidptr, voidptr) voidptr fn C.atomic_load_u16(voidptr) u16 @@ -34,9 +32,7 @@ fn C.atomic_store_u16(voidptr, u16) fn C.atomic_compare_exchange_weak_u16(voidptr, voidptr, u16) bool fn C.atomic_compare_exchange_strong_u16(voidptr, voidptr, u16) bool fn C.atomic_exchange_u16(voidptr, u16) u16 -[trusted] fn C.atomic_fetch_add_u16(voidptr, u16) u16 -[trusted] fn C.atomic_fetch_sub_u16(voidptr, u16) u16 fn C.atomic_load_u32(voidptr) u32 @@ -44,9 +40,7 @@ fn C.atomic_store_u32(voidptr, u32) fn C.atomic_compare_exchange_weak_u32(voidptr, voidptr, u32) bool fn C.atomic_compare_exchange_strong_u32(voidptr, voidptr, u32) bool fn C.atomic_exchange_u32(voidptr, u32) u32 -[trusted] fn C.atomic_fetch_add_u32(voidptr, u32) u32 -[trusted] fn C.atomic_fetch_sub_u32(voidptr, u32) u32 fn C.atomic_load_u64(voidptr) u64 @@ -54,9 +48,7 @@ fn C.atomic_store_u64(voidptr, u64) fn C.atomic_compare_exchange_weak_u64(voidptr, voidptr, u64) bool fn C.atomic_compare_exchange_strong_u64(voidptr, voidptr, u64) bool fn C.atomic_exchange_u64(voidptr, u64) u64 -[trusted] fn C.atomic_fetch_add_u64(voidptr, u64) u64 -[trusted] fn C.atomic_fetch_sub_u64(voidptr, u64) u64 const ( @@ -367,7 +359,7 @@ pub fn (mut ch Channel) try_pop(dest voidptr) ChanState { } fn (mut ch Channel) try_pop_priv(dest voidptr, no_block bool) ChanState { - spinloops_sem_, spinloops_ := if no_block { 1, 1 } else { spinloops, spinloops_sem } + spinloops_sem_, spinloops_ := if no_block { 1, 1 } else { spinloops, spinloops_sem } mut have_swapped := false mut write_in_progress := false for { @@ -521,7 +513,7 @@ fn (mut ch Channel) try_pop_priv(dest voidptr, no_block bool) ChanState { dest2 = dest } } - break + break } return .success } diff --git a/vlib/sync/pool/pool.v b/vlib/sync/pool/pool.v index 368f6564f3..090c07b283 100644 --- a/vlib/sync/pool/pool.v +++ b/vlib/sync/pool/pool.v @@ -4,6 +4,9 @@ import sync import runtime +[trusted] +fn C.atomic_fetch_add_u32(voidptr, u32) u32 + pub const ( no_result = voidptr(0) ) diff --git a/vlib/sync/sync_default.c.v b/vlib/sync/sync_default.c.v index e7d6eea59b..244d8dd367 100644 --- a/vlib/sync/sync_default.c.v +++ b/vlib/sync/sync_default.c.v @@ -8,6 +8,25 @@ import time #flag -lpthread #include +[trusted] +fn C.pthread_mutex_init(voidptr, voidptr) int +fn C.pthread_mutex_lock(voidptr) int +fn C.pthread_mutex_unlock(voidptr) int +fn C.pthread_mutex_destroy(voidptr) int +fn C.pthread_rwlockattr_init(voidptr) int +fn C.pthread_rwlockattr_setkind_np(voidptr, int) int +fn C.pthread_rwlockattr_setpshared(voidptr, int) int +fn C.pthread_rwlock_init(voidptr, voidptr) int +fn C.pthread_rwlock_rdlock(voidptr) int +fn C.pthread_rwlock_wrlock(voidptr) int +fn C.pthread_rwlock_unlock(voidptr) int +fn C.sem_init(voidptr, int, u32) int +fn C.sem_post(voidptr) int +fn C.sem_wait(voidptr) int +fn C.sem_trywait(voidptr) int +fn C.sem_timedwait(voidptr, voidptr) int +fn C.sem_destroy(voidptr) int + // [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function. [heap] pub struct Mutex { diff --git a/vlib/sync/sync_macos.c.v b/vlib/sync/sync_macos.c.v index 4b954ba12e..c62b133a85 100644 --- a/vlib/sync/sync_macos.c.v +++ b/vlib/sync/sync_macos.c.v @@ -9,6 +9,27 @@ import time #include #include +[trusted] +fn C.pthread_mutex_init(voidptr, voidptr) int +fn C.pthread_mutex_lock(voidptr) int +fn C.pthread_mutex_unlock(voidptr) int +fn C.pthread_mutex_destroy(voidptr) int +fn C.pthread_rwlockattr_init(voidptr) int +fn C.pthread_rwlockattr_setkind_np(voidptr, int) int +fn C.pthread_rwlockattr_setpshared(voidptr, int) int +fn C.pthread_rwlock_init(voidptr, voidptr) int +fn C.pthread_rwlock_rdlock(voidptr) int +fn C.pthread_rwlock_wrlock(voidptr) int +fn C.pthread_rwlock_unlock(voidptr) int +fn C.pthread_condattr_init(voidptr) int +fn C.pthread_condattr_setpshared(voidptr, int) int +fn C.pthread_condattr_destroy(voidptr) int +fn C.pthread_cond_init(voidptr, voidptr) int +fn C.pthread_cond_signal(voidptr) int +fn C.pthread_cond_wait(voidptr, voidptr) int +fn C.pthread_cond_timedwait(voidptr, voidptr, voidptr) int +fn C.pthread_cond_destroy(voidptr) int + // [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function. [heap] pub struct Mutex { diff --git a/vlib/sync/waitgroup.v b/vlib/sync/waitgroup.v index 9dd3c8c8b4..d9d4aca668 100644 --- a/vlib/sync/waitgroup.v +++ b/vlib/sync/waitgroup.v @@ -3,6 +3,9 @@ // that can be found in the LICENSE file. module sync +[trusted] +fn C.atomic_fetch_add_u32(voidptr, u32) u32 + // WaitGroup // Do not copy an instance of WaitGroup, use a ref instead. // @@ -12,7 +15,7 @@ module sync // `wg.wait()` to wait for all jobs to have finished // // in each parallel job: -// `wg.done()` when finished +// `wg.done()` when finished // // [init_with=new_waitgroup] // TODO: implement support for init_with struct attribute, and disallow WaitGroup{} from outside the sync.new_waitgroup() function. [heap] diff --git a/vlib/term/ui/consoleapi_windows.c.v b/vlib/term/ui/consoleapi_windows.c.v index c8a185eb41..19d521a0d0 100644 --- a/vlib/term/ui/consoleapi_windows.c.v +++ b/vlib/term/ui/consoleapi_windows.c.v @@ -54,6 +54,31 @@ struct C.FOCUS_EVENT_RECORD { bSetFocus int } +[typedef] +struct C.COORD { + X i16 + Y i16 +} + +[typedef] +struct C.SMALL_RECT { + Left u16 + Top u16 + Right u16 + Bottom u16 +} + +[typedef] +struct C.CONSOLE_SCREEN_BUFFER_INFO { + dwSize C.COORD + dwCursorPosition C.COORD + wAttributes u16 + srWindow C.SMALL_RECT + dwMaximumWindowSize C.COORD +} + fn C.ReadConsoleInput() bool fn C.GetNumberOfConsoleInputEvents() bool + +fn C.GetConsoleScreenBufferInfo(handle os.HANDLE, info &C.CONSOLE_SCREEN_BUFFER_INFO) bool diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 78d4aac296..f2e40e317c 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -215,13 +215,13 @@ fn (mut p Parser) fn_decl() ast.FnDecl { language = rec.language } mut name := '' - name_pos := p.tok.position() if p.tok.kind == .name { + pos := p.tok.position() // TODO high order fn name = if language == .js { p.check_js_name() } else { p.check_name() } if language == .v && !p.pref.translated && util.contains_capital(name) && !p.builtin_mod { p.error_with_pos('function names cannot contain uppercase letters, use snake_case instead', - name_pos) + pos) return ast.FnDecl{ scope: 0 } @@ -229,14 +229,14 @@ fn (mut p Parser) fn_decl() ast.FnDecl { type_sym := p.table.get_type_symbol(rec.typ) // interfaces are handled in the checker, methods can not be defined on them this way if is_method && (type_sym.has_method(name) && type_sym.kind != .interface_) { - p.error_with_pos('duplicate method `$name`', name_pos) + p.error_with_pos('duplicate method `$name`', pos) return ast.FnDecl{ scope: 0 } } // cannot redefine buildin function if !is_method && !p.builtin_mod && name in builtin_functions { - p.error_with_pos('cannot redefine builtin function `$name`', name_pos) + p.error_with_pos('cannot redefine builtin function `$name`', pos) return ast.FnDecl{ scope: 0 } @@ -252,7 +252,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl { p.error_with_pos('cannot overload `!=`, `>`, `<=` and `>=` as they are auto generated from `==` and`<`', p.tok.position()) } else { - p.error_with_pos('expecting method name', name_pos) + pos := p.tok.position() + p.error_with_pos('expecting method name', pos) return ast.FnDecl{ scope: 0 } @@ -334,8 +335,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl { } else { name = p.prepend_mod(name) } - if p.table.known_fn(name) { - p.fn_redefinition_error(name, name_pos) + if _ := p.table.find_fn(name) { + p.fn_redefinition_error(name) } // p.warn('reg functn $name ()') p.table.register_fn(table.Fn{ @@ -807,7 +808,7 @@ fn (mut p Parser) check_fn_atomic_arguments(typ table.Type, pos token.Position) } } -fn (mut p Parser) fn_redefinition_error(name string, pos token.Position) { +fn (mut p Parser) fn_redefinition_error(name string) { if p.pref.translated { return } @@ -819,7 +820,7 @@ fn (mut p Parser) fn_redefinition_error(name string, pos token.Position) { } */ p.table.redefined_fns << name - p.error_with_pos('redefinition of function `$name`', pos) + // p.error('redefinition of function `$name`') } fn have_fn_main(stmts []ast.Stmt) bool { diff --git a/vlib/v/parser/tests/fn_duplicate.out b/vlib/v/parser/tests/fn_duplicate.out deleted file mode 100644 index 21fda15e94..0000000000 --- a/vlib/v/parser/tests/fn_duplicate.out +++ /dev/null @@ -1,4 +0,0 @@ -vlib/v/parser/tests/fn_duplicate.vv:2:4: error: redefinition of function `foo` - 1 | fn foo() {} - 2 | fn foo() {} - | ~~~ diff --git a/vlib/v/parser/tests/fn_duplicate.vv b/vlib/v/parser/tests/fn_duplicate.vv deleted file mode 100644 index 1eb40d3025..0000000000 --- a/vlib/v/parser/tests/fn_duplicate.vv +++ /dev/null @@ -1,2 +0,0 @@ -fn foo() {} -fn foo() {}