From 72363ada846c1510925ec66358e764aaf35ccfbf Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 31 Aug 2019 02:35:05 +0300 Subject: [PATCH] array: make .set() private + format --- compiler/main.v | 2 +- vlib/builtin/array.v | 44 ++++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index 251402ee74..2e8fd65aaf 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -311,7 +311,7 @@ fn (v mut V) compile() { d.writeln(v.prof_counters()) } dd := d.str() - cgen.lines.set(defs_pos, dd)// TODO `def.str()` doesn't compile + cgen.lines[defs_pos] = dd// TODO `def.str()` doesn't compile v.generate_main() diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index e71e4d1cf7..080f996434 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -4,7 +4,7 @@ module builtin -import strings +import strings struct array { pub: @@ -28,10 +28,10 @@ fn new_array(mylen, cap, elm_size int) array { } -// TODO +// TODO pub fn _make(len, cap, elm_size int) array { - return new_array(len, cap, elm_size) -} + return new_array(len, cap, elm_size) +} // Private function, used by V (`nums := [1, 2, 3]`) fn new_array_from_c_array(len, cap, elm_size int, c_array voidptr) array { @@ -137,10 +137,10 @@ pub fn (s array) slice(start, _end int) array { panic('invalid slice index: $start > $end') } if end > s.len { - panic('runtime error: slice bounds out of range ($end >= $s.len)') + panic('runtime error: slice bounds out of range ($end >= $s.len)') } - if start < 0 { - panic('runtime error: slice bounds out of range ($start < 0)') + if start < 0 { + panic('runtime error: slice bounds out of range ($start < 0)') } l := end - start res := array { @@ -148,12 +148,12 @@ pub fn (s array) slice(start, _end int) array { data: s.data + start * s.element_size len: l cap: l - //is_slice: true + //is_slice: true } return res } -pub fn (a mut array) set(idx int, val voidptr) { +fn (a mut array) set(idx int, val voidptr) { if idx < 0 || idx >= a.len { panic('array index out of range: $idx / $a.len') } @@ -176,8 +176,8 @@ fn (arr mut array) _push(val voidptr) { arr.len++ } -// `val` is array.data -// TODO make private, right now it's used by strings.Builder +// `val` is array.data +// TODO make private, right now it's used by strings.Builder pub fn (arr mut array) _push_many(val voidptr, size int) { if arr.len >= arr.cap - size { cap := (arr.len + size) * 2 @@ -214,31 +214,31 @@ pub fn (a array) clone() array { element_size: a.element_size data: malloc(a.cap * a.element_size) } - C.memcpy(arr.data, a.data, a.cap * a.element_size) - return arr -} + C.memcpy(arr.data, a.data, a.cap * a.element_size) + return arr +} //pub fn (a []int) free() { pub fn (a array) free() { //if a.is_slice { - //return - //} + //return + //} C.free(a.data) } // "[ 'a', 'b', 'c' ]" pub fn (a []string) str() string { - mut sb := strings.new_builder(a.len * 3) - sb.write('[') + mut sb := strings.new_builder(a.len * 3) + sb.write('[') for i := 0; i < a.len; i++ { val := a[i] - sb.write('"$val"') + sb.write('"$val"') if i < a.len - 1 { - sb.write(', ') + sb.write(', ') } } - sb.write(']') - return sb.str() + sb.write(']') + return sb.str() } pub fn (b []byte) hex() string {