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

all: change f mut Foo to mut f Foo

This commit is contained in:
yuyi 2020-06-04 16:35:40 +08:00 committed by GitHub
parent 0b7fe0a9d0
commit 5ae8853648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 62 additions and 65 deletions

View File

@ -177,7 +177,7 @@ pub fn (ws &WebhookServer) reset() {
// parse flags to FlagOptions struct
fn parse_flags(fp mut flag.FlagParser) FlagOptions {
fn parse_flags(mut fp flag.FlagParser) FlagOptions {
return FlagOptions{
serve : fp.bool('serve', 0, false, 'run in webhook server mode')
work_dir : fp.string('work-dir', 0, work_dir, 'gen_vc working directory')

View File

@ -127,7 +127,7 @@ pub fn (mut m TestMessageHandler) display_message() {
}
}
fn worker_trunner(p mut sync.PoolProcessor, idx int, thread_id int) voidptr {
fn worker_trunner(mut p sync.PoolProcessor, idx int, thread_id int) voidptr {
mut ts := &TestSession(p.get_shared_context())
defer { ts.message_handler.display_message() }
tmpd := os.temp_dir()

View File

@ -142,7 +142,7 @@ pub mut:
verbose bool // should the tool be much more verbose
}
pub fn add_common_tool_options(context mut VGitOptions, fp mut flag.FlagParser) []string {
pub fn add_common_tool_options(mut context VGitOptions, mut fp flag.FlagParser) []string {
tdir := os.temp_dir()
context.workdir = os.real_path(fp.string('workdir', `w`, tdir, 'A writable base folder. Default: $tdir'))
context.v_repo_url = fp.string('vrepo', 0, vgit.remote_v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')

View File

@ -32,7 +32,7 @@ pub mut:
s []Position
}
fn advance(sys mut System, dt f64) {
fn advance(mut sys System, dt f64) {
for i in 0..c_n - 1 {
mut vx := sys.v[i].x
mut vy := sys.v[i].y
@ -68,7 +68,7 @@ fn advance(sys mut System, dt f64) {
}
}
fn offsetmomentum(sys mut System) {
fn offsetmomentum(mut sys System) {
mut px := f64(0)
mut py := f64(0)
mut pz := f64(0)

View File

@ -20,7 +20,7 @@ fn hello_response() string {
}
fn callback(req picohttpparser.Request, res mut picohttpparser.Response) {
fn callback(req picohttpparser.Request, mut res picohttpparser.Response) {
if picohttpparser.cmpn(req.method, 'GET ', 4) {
if picohttpparser.cmp(req.path, '/t') {
res.http_ok().header_server().header_date().plain().body(hello_response())

View File

@ -19,7 +19,7 @@ fn main() {
println('after quick sort whether array is sorted: ${is_sorted(arr)}')
}
fn quick_sort(arr mut []int, l int, r int) {
fn quick_sort(mut arr []int, l int, r int) {
if l>=r { return }
mut sep := l // what is sep: [...all_value<arr[sep]...sep...all_value>=arr[sep]...]
for i in l+1..r+1 {
@ -34,7 +34,7 @@ fn quick_sort(arr mut []int, l int, r int) {
}
[inline]
fn swap(arr mut []int, i int, j int) {
fn swap(mut arr []int, i int, j int) {
temp := arr[i]
arr[i] = arr[j]
arr[j] = temp

View File

@ -38,7 +38,7 @@ fn main() {
sapp.run(&desc)
}
fn init(state mut AppState) {
fn init(mut state AppState) {
// dont actually alocate this on the heap in real life
gfx.setup(&C.sg_desc{
mtl_device: sapp.metal_get_device()

View File

@ -18,7 +18,7 @@ fn evala(i, j int) int {
return ((i + j) * (i + j + 1) / 2 + i + 1)
}
fn times(v mut []f64, u []f64) {
fn times(mut v []f64, u []f64) {
for i in 0..v.len {
mut a := f64(0)
for j in 0..u.len {
@ -28,7 +28,7 @@ fn times(v mut []f64, u []f64) {
}
}
fn times_trans(v mut []f64, u []f64) {
fn times_trans(mut v []f64, u []f64) {
for i in 0..v.len {
mut a := f64(0)
for j in 0..u.len {
@ -38,7 +38,7 @@ fn times_trans(v mut []f64, u []f64) {
}
}
fn a_times_transp(v mut []f64, u []f64) {
fn a_times_transp(mut v []f64, u []f64) {
mut x := []f64{len:u.len, init:0}
times(mut x, u)
times_trans(mut v, x)
@ -69,4 +69,3 @@ fn main() {
ans := math.sqrt(vbv / vv)
println('${ans:0.9f}')
}

View File

@ -402,7 +402,7 @@ fn parse_binary_tetro(t_ int) []Block {
return res
}
fn on_event(e &sapp.Event, game mut Game) {
fn on_event(e &sapp.Event, mut game Game) {
if e.typ == .key_down {
game.key_down(e.key_code)
}

View File

@ -311,7 +311,7 @@ fn test_fixed() {
assert nums2[c_n - 1] == 0
}
fn modify(numbers mut []int) {
fn modify(mut numbers []int) {
numbers[0] = 777
}
@ -328,13 +328,13 @@ fn test_mut_slice() {
*/
}
fn double_up(a mut []int) {
fn double_up(mut a []int) {
for i := 0; i < a.len; i++ {
a[i] = a[i]*2
}
}
fn double_up_v2(a mut []int) {
fn double_up_v2(mut a []int) {
for i, _ in a {
a[i] = a[i]*2 // or val*2, doesn't matter
}

View File

@ -160,7 +160,7 @@ fn test_string_arr() {
assert m['a'][1] == 'two'
}
fn mut_map(m mut map[string]int) {
fn mut_map(mut m map[string]int) {
m['a'] = 10
}

View File

@ -112,7 +112,7 @@ fn (mut m SortedMap) set(key string, value voidptr) {
}
}
fn (mut n mapnode) split_child(child_index int, y mut mapnode) {
fn (mut n mapnode) split_child(child_index int, mut y mapnode) {
mut z := new_node()
z.size = mid_index
y.size = mid_index
@ -353,7 +353,7 @@ pub fn (mut m SortedMap) delete(key string) {
// Insert all keys of the subtree into array `keys`
// starting at `at`. Keys are inserted in order.
fn (n &mapnode) subkeys(keys mut []string, at int) int {
fn (n &mapnode) subkeys(mut keys []string, at int) int {
mut position := at
if !isnil(n.children) {
// Traverse children and insert

View File

@ -46,7 +46,7 @@ pub fn new_cbc(b AesCipher, iv []byte) AesCbc {
pub fn (x &AesCbc) block_size() int { return x.block_size }
pub fn (x &AesCbc) encrypt_blocks(dst mut []byte, src_ []byte) {
pub fn (x &AesCbc) encrypt_blocks(mut dst []byte, src_ []byte) {
mut src := src_
if src.len%x.block_size != 0 {
panic('crypto.cipher: input not full blocks')
@ -79,7 +79,7 @@ pub fn (x &AesCbc) encrypt_blocks(dst mut []byte, src_ []byte) {
copy(x.iv, iv)
}
pub fn (mut x AesCbc) decrypt_blocks(dst mut []byte, src []byte) {
pub fn (mut x AesCbc) decrypt_blocks(mut dst []byte, src []byte) {
if src.len%x.block_size != 0 {
panic('crypto.cipher: input not full blocks')
}

View File

@ -156,7 +156,7 @@ fn rotw(w u32) u32 { return (w<<8) | (w>>24) }
// Key expansion algorithm. See FIPS-197, Figure 11.
// Their rcon[i] is our powx[i-1] << 24.
fn expand_key_generic(key []byte, enc mut []u32, dec mut []u32) {
fn expand_key_generic(key []byte, mut enc []u32, mut dec []u32) {
// Encryption key setup.
mut i := 0
nk := key.len / 4

View File

@ -8,7 +8,7 @@ module cipher
// xor_bytes xors the bytes in a and b. The destination should have enough
// space, otherwise xor_bytes will panic. Returns the number of bytes xor'd.
pub fn xor_bytes(dst mut []byte, a, b []byte) int {
pub fn xor_bytes(mut dst []byte, a, b []byte) int {
mut n := a.len
if b.len < n {
n = b.len
@ -23,7 +23,7 @@ pub fn xor_bytes(dst mut []byte, a, b []byte) int {
}
// n needs to be smaller or equal than the length of a and b.
pub fn safe_xor_bytes(dst mut []byte, a, b []byte, n int) {
pub fn safe_xor_bytes(mut dst []byte, a, b []byte, n int) {
for i in 0..n {
dst[i] = a[i] ^ b[i]
}
@ -31,6 +31,6 @@ pub fn safe_xor_bytes(dst mut []byte, a, b []byte, n int) {
// fast_xor_words XORs multiples of 4 or 8 bytes (depending on architecture.)
// The slice arguments a and b are assumed to be of equal length.
pub fn xor_words(dst mut []byte, a, b []byte) {
pub fn xor_words(mut dst []byte, a, b []byte) {
safe_xor_bytes(mut dst, a, b, b.len)
}

View File

@ -133,7 +133,7 @@ pub fn sum(data []byte) []byte {
return d.checksum()
}
fn block(dig mut Digest, p []byte) {
fn block(mut dig Digest, p []byte) {
// For now just use block_generic until we have specific
// architecture optimized versions
block_generic(mut dig, p)

View File

@ -11,7 +11,7 @@ module md5
import math.bits
import encoding.binary
fn block_generic(dig mut Digest, p []byte) {
fn block_generic(mut dig Digest, p []byte) {
// load state
mut a := dig.s[0]
mut b := dig.s[1]

View File

@ -59,7 +59,7 @@ pub fn (mut c Cipher) reset() {
// xor_key_stream sets dst to the result of XORing src with the key stream.
// Dst and src must overlap entirely or not at all.
pub fn (mut c Cipher) xor_key_stream(dst mut []byte, src []byte) {
pub fn (mut c Cipher) xor_key_stream(mut dst []byte, src []byte) {
if src.len == 0 {
return
}

View File

@ -17,7 +17,7 @@ const (
_k3 = 0xCA62C1D6
)
fn block_generic(dig mut Digest, p_ []byte) {
fn block_generic(mut dig Digest, p_ []byte) {
mut p := p_
mut w := [u32(0)].repeat(16)
mut h0 := dig.h[0]
@ -113,7 +113,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
} else {
p = p[chunk..]
}
}
dig.h[0] = h0

View File

@ -199,7 +199,7 @@ pub fn sum224(data []byte) []byte {
return sum224
}
fn block(dig mut Digest, p []byte) {
fn block(mut dig Digest, p []byte) {
// For now just use block_generic until we have specific
// architecture optimized versions
block_generic(mut dig, p)

View File

@ -80,11 +80,11 @@ const (
]
)
fn block_generic(dig mut Digest, p_ []byte) {
fn block_generic(mut dig Digest, p_ []byte) {
mut p := p_
mut w := [u32(0)].repeat(64)
mut h0 := dig.h[0]
mut h1 := dig.h[1]
mut h2 := dig.h[2]

View File

@ -279,7 +279,7 @@ pub fn sum512_256(data []byte) []byte {
return sum256
}
fn block(dig mut Digest, p []byte) {
fn block(mut dig Digest, p []byte) {
// For now just use block_generic until we have specific
// architecture optimized versions
block_generic(mut dig, p)

View File

@ -93,7 +93,7 @@ const (
]
)
fn block_generic(dig mut Digest, p_ []byte) {
fn block_generic(mut dig Digest, p_ []byte) {
mut p := p_
mut w := [u64(0)].repeat(80)
mut h0 := dig.h[0]
@ -160,4 +160,3 @@ fn block_generic(dig mut Digest, p_ []byte) {
dig.h[6] = h6
dig.h[7] = h7
}

View File

@ -10,7 +10,7 @@ pub fn little_endian_u16(b []byte) u16 {
}
[inline]
pub fn little_endian_put_u16(b mut []byte, v u16) {
pub fn little_endian_put_u16(mut b []byte, v u16) {
_ = b[1] // bounds check
b[0] = byte(v)
b[1] = byte(v>>u16(8))
@ -23,7 +23,7 @@ pub fn little_endian_u32(b []byte) u32 {
}
[inline]
pub fn little_endian_put_u32(b mut []byte, v u32) {
pub fn little_endian_put_u32(mut b []byte, v u32) {
_ = b[3] // bounds check
b[0] = byte(v)
b[1] = byte(v>>u32(8))
@ -38,7 +38,7 @@ pub fn little_endian_u64(b []byte) u64 {
}
[inline]
pub fn little_endian_put_u64(b mut []byte, v u64) {
pub fn little_endian_put_u64(mut b []byte, v u64) {
_ = b[7] // bounds check
b[0] = byte(v)
b[1] = byte(v>>u64(8))
@ -58,7 +58,7 @@ pub fn big_endian_u16(b []byte) u16 {
}
[inline]
pub fn big_endian_put_u16(b mut []byte, v u16) {
pub fn big_endian_put_u16(mut b []byte, v u16) {
_ = b[1] // bounds check
b[0] = byte(v>>u16(8))
b[1] = byte(v)
@ -71,7 +71,7 @@ pub fn big_endian_u32(b []byte) u32 {
}
[inline]
pub fn big_endian_put_u32(b mut []byte, v u32) {
pub fn big_endian_put_u32(mut b []byte, v u32) {
_ = b[3] // bounds check
b[0] = byte(v>>u32(24))
b[1] = byte(v>>u32(16))
@ -86,7 +86,7 @@ pub fn big_endian_u64(b []byte) u64 {
}
[inline]
pub fn big_endian_put_u64(b mut []byte, v u64) {
pub fn big_endian_put_u64(mut b []byte, v u64) {
_ = b[7] // bounds check
b[0] = byte(v>>u64(56))
b[1] = byte(v>>u64(48))
@ -97,4 +97,3 @@ pub fn big_endian_put_u64(b mut []byte, v u64) {
b[6] = byte(v>>u64(8))
b[7] = byte(v)
}

View File

@ -315,7 +315,7 @@ pub fn rotate(angle f32, axis Vec3, src Mat4) Mat4 {
dest[10] = data[2] * f20 + data[6] * f21 + data[10] * f22
dest[11] = data[3] * f20 + data[7] * f21 + data[11] * f22
dest[0] = t00 dest[1] = t01 dest[2] = t02 dest[3] = t03
dest[0] = t00 dest[1] = t01 dest[2] = t02 dest[3] = t03
dest[4] = t10 dest[5] = t11 dest[6] = t12 dest[7] = t13
return mat4(dest)
@ -370,7 +370,7 @@ pub fn identity() Mat4 {
}
// returns *f32 without allocation
pub fn identity2(res mut &f32) {
pub fn identity2(mut res &f32) {
res[0] = 1
res[5] = 1
res[10] = 1

View File

@ -31,7 +31,7 @@ pub fn new_live_reload_info(original string, vexe string, vopts string, live_fn_
// NB: start_reloader will be called by generated code inside main(), to start
// the hot code reloader thread. start_reloader is executed in the context of
// the original main thread.
pub fn start_reloader(r mut live.LiveReloadInfo) {
pub fn start_reloader(mut r live.LiveReloadInfo) {
// The shared library should be loaded once in the main thread
// If that fails, the program would crash anyway, just provide
// an error message to the user and exit:
@ -48,7 +48,7 @@ fn elog(r &live.LiveReloadInfo, s string){
eprintln(s)
}
fn compile_and_reload_shared_lib(r mut live.LiveReloadInfo) ?bool {
fn compile_and_reload_shared_lib(mut r live.LiveReloadInfo) ?bool {
sw := time.new_stopwatch({})
new_lib_path := compile_lib(mut r) or {
return error('errors while compiling $r.original')
@ -59,7 +59,7 @@ fn compile_and_reload_shared_lib(r mut live.LiveReloadInfo) ?bool {
return true
}
fn compile_lib(r mut live.LiveReloadInfo) ?string {
fn compile_lib(mut r live.LiveReloadInfo) ?string {
new_lib_path, new_lib_path_with_extension := current_shared_library_path(mut r)
cmd := '$r.vexe $r.vopts -o $new_lib_path $r.original'
elog(r,'> compilation cmd: $cmd')
@ -81,13 +81,13 @@ fn compile_lib(r mut live.LiveReloadInfo) ?string {
return new_lib_path_with_extension
}
fn current_shared_library_path(r mut live.LiveReloadInfo) (string, string) {
fn current_shared_library_path(mut r live.LiveReloadInfo) (string, string) {
lib_path := strconv.v_sprintf(r.so_name_template.replace('\\', '\\\\'), r.reloads)
lib_path_with_extension := lib_path + r.so_extension
return lib_path, lib_path_with_extension
}
fn load_lib(r mut live.LiveReloadInfo, new_lib_path string) {
fn load_lib(mut r live.LiveReloadInfo, new_lib_path string) {
elog(r,'live mutex locking...')
C.pthread_mutex_lock(r.live_fn_mutex)
elog(r,'live mutex locked')
@ -108,7 +108,7 @@ fn load_lib(r mut live.LiveReloadInfo, new_lib_path string) {
elog(r,'live mutex unlocked')
}
fn protected_load_lib(r mut live.LiveReloadInfo, new_lib_path string) {
fn protected_load_lib(mut r live.LiveReloadInfo, new_lib_path string) {
if r.live_lib != 0 {
dl.close( r.live_lib )
r.live_lib = 0
@ -126,7 +126,7 @@ fn protected_load_lib(r mut live.LiveReloadInfo, new_lib_path string) {
}
// NB: r.reloader() is executed in a new, independent thread
fn reloader(r mut live.LiveReloadInfo) {
fn reloader(mut r live.LiveReloadInfo) {
// elog(r,'reloader, r: $r')
mut last_ts := os.file_last_mod_unix( r.original )
for {

View File

@ -836,7 +836,7 @@ fn parse_query_silent(query string) Values {
return m
}
fn parse_query_values(m mut Values, query string) ?bool {
fn parse_query_values(mut m Values, query string) ?bool {
mut had_error := false
mut q := query
for q != '' {

View File

@ -95,7 +95,7 @@ fn on_message(sender voidptr, mut ws websocket.Client, msg websocket.Message) {
}
}
fn start_tests(ws mut websocket.Client, num int) {
fn start_tests(mut ws websocket.Client, num int) {
for i := 1; i < num; i++ {
println('Running test: ' + i.str())
ws.uri = 'ws://localhost:9001/runCase?case=${i.str()}&agent=vws/1.0a'

View File

@ -64,7 +64,7 @@ struct C.picoev_loop {}
struct Picoev {
loop &C.picoev_loop
cb fn(req picohttpparser.Request, res mut picohttpparser.Response)
cb fn(req picohttpparser.Request, mut res picohttpparser.Response)
mut:
date byteptr
buf byteptr
@ -229,7 +229,7 @@ pub fn (p Picoev) serve() {
}
}
fn update_date(p mut Picoev) {
fn update_date(mut p Picoev) {
for {
p.date = C.get_date()
C.usleep(1000000)

View File

@ -360,7 +360,7 @@ fn parser(s string) (int,PrepNumber) {
**********************************************************************/
// converter return a u64 with the bit image of the f64 number
fn converter(pn mut PrepNumber) u64 {
fn converter(mut pn PrepNumber) u64 {
mut binexp := 92
mut s2 := u32(0) // 96-bit precision integer
mut s1 := u32(0)

View File

@ -124,7 +124,7 @@ pub fn (mut pool PoolProcessor) work_on_pointers(items []voidptr) {
// process_in_thread does the actual work of worker thread.
// It is a workaround for the current inability to pass a
// method in a callback.
fn process_in_thread(pool mut PoolProcessor, task_id int) {
fn process_in_thread(mut pool PoolProcessor, task_id int) {
cb := ThreadCB(pool.thread_cb)
mut idx := 0
ilen := pool.items.len

View File

@ -64,7 +64,7 @@ pub fn fmt(file ast.File, table &table.Table, is_debug bool) string {
}
/*
fn (f mut Fmt) find_comment(line_nr int) {
fn (mut f Fmt) find_comment(line_nr int) {
for comment in f.file.comments {
if comment.line_nr == line_nr {
f.writeln('// FFF $comment.line_nr $comment.text')

View File

@ -327,7 +327,7 @@ pub fn backend_from_string(s string) ?Backend {
}
}
fn parse_define(prefs mut Preferences, define string) {
fn parse_define(mut prefs Preferences, define string) {
define_parts := define.split('=')
if define_parts.len == 1 {
prefs.compile_defines << define

View File

@ -19,7 +19,7 @@ fn test_defer() {
assert foo2() == 'foo'
}
fn set_num(i int, n mut Num) {
fn set_num(i int, mut n Num) {
defer {
println('exiting')
n.val++
@ -33,7 +33,7 @@ fn set_num(i int, n mut Num) {
}
}
fn set_num_opt(n mut Num) ?int {
fn set_num_opt(mut n Num) ?int {
defer {
n.val = 1
}

View File

@ -8,7 +8,7 @@ pub mut:
a []Aaa
}
fn foo(b int, a mut []int) {
fn foo(b int, mut a []int) {
a[0] = 7
// a << 4
}

View File

@ -53,7 +53,7 @@ fn test_all_v_repl_files() {
println(session.bmark.total_message('total time spent running REPL files'))
}
fn worker_repl(p mut sync.PoolProcessor, idx int, thread_id int) voidptr {
fn worker_repl(mut p sync.PoolProcessor, idx int, thread_id int) voidptr {
cdir := os.cache_dir()
mut session := &Session(p.get_shared_context())
mut tls_bench := &benchmark.Benchmark(p.get_thread_context(idx))