diff --git a/vlib/builtin/float.v b/vlib/builtin/float.v index f9faae9854..d990c1bb4a 100644 --- a/vlib/builtin/float.v +++ b/vlib/builtin/float.v @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT license that can be found in the LICENSE file. module builtin -import strconv.ftoa +import strconv #include // ----- f64 to string functions ----- @@ -11,9 +11,9 @@ import strconv.ftoa pub fn (x f64) str() string { abs_x := f64_abs(x) if abs_x >= 0.0001 && abs_x < 1.0e6 { - return ftoa.f64_to_str_l(x) + return strconv.f64_to_str_l(x) } else { - return ftoa.ftoa_64(x) + return strconv.ftoa_64(x) } } @@ -31,13 +31,13 @@ pub fn (x f64) strsci(digit_num int) string { } else if n_digit > 17 { n_digit = 17 } - return ftoa.f64_to_str(x, n_digit) + return strconv.f64_to_str(x, n_digit) } // return a decimal notation of the input f64 [inline] pub fn (x f64) strlong() string { - return ftoa.f64_to_str_l(x) + return strconv.f64_to_str_l(x) } // ----- f32 to string functions ----- @@ -46,9 +46,9 @@ pub fn (x f64) strlong() string { pub fn (x f32) str() string { abs_x := f32_abs(x) if abs_x >= 0.0001 && abs_x < 1.0e6 { - return ftoa.f32_to_str_l(x) + return strconv.f32_to_str_l(x) } else { - return ftoa.ftoa_32(x) + return strconv.ftoa_32(x) } } @@ -61,13 +61,13 @@ pub fn (x f32) strsci(digit_num int) string { } else if n_digit > 8 { n_digit = 8 } - return ftoa.f32_to_str(x, n_digit) + return strconv.f32_to_str(x, n_digit) } // return a decimal notation of the input f32 [inline] pub fn (x f32) strlong() string { - return ftoa.f32_to_str_l(x) + return strconv.f32_to_str_l(x) } // ----- C functions ----- diff --git a/vlib/strconv/atof_test.v b/vlib/strconv/atof_test.v index 8253d4cc07..86b069c32d 100644 --- a/vlib/strconv/atof_test.v +++ b/vlib/strconv/atof_test.v @@ -4,7 +4,6 @@ * **********************************************************************/ import strconv -import strconv.atofq fn test_atof() { // @@ -40,7 +39,7 @@ fn test_atof() { // quick atof - mut s1 := (atofq.atof_quick(src_num_str[c]).str()) + mut s1 := (atof_quick(src_num_str[c]).str()) mut s2 := (x.str()) delta := s1.f64() - s2.f64() //println("$s1 $s2 $delta") diff --git a/vlib/strconv/atofq/atofq.v b/vlib/strconv/atofq.v similarity index 98% rename from vlib/strconv/atofq/atofq.v rename to vlib/strconv/atofq.v index 438d126f5b..3517f7bdf5 100644 --- a/vlib/strconv/atofq/atofq.v +++ b/vlib/strconv/atofq.v @@ -16,15 +16,7 @@ Know limitation: */ -module atofq - -// same used in atof, here only for references -const( - double_plus_zero = u64(0x0000000000000000) - double_minus_zero = u64(0x8000000000000000) - double_plus_infinity = u64(0x7FF0000000000000) - double_minus_infinity = u64(0xFFF0000000000000) -) +module strconv union Float64u { mut: diff --git a/vlib/strconv/ftoa/f32_f64_to_string_test.v b/vlib/strconv/f32_f64_to_string_test.v similarity index 100% rename from vlib/strconv/ftoa/f32_f64_to_string_test.v rename to vlib/strconv/f32_f64_to_string_test.v diff --git a/vlib/strconv/ftoa/f32_str.v b/vlib/strconv/f32_str.v similarity index 99% rename from vlib/strconv/ftoa/f32_str.v rename to vlib/strconv/f32_str.v index 55ee20bf49..8544eca452 100644 --- a/vlib/strconv/ftoa/f32_str.v +++ b/vlib/strconv/f32_str.v @@ -17,7 +17,7 @@ inspired by the Go version here: https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea */ -module ftoa +module strconv // dec32 is a floating decimal type representing m * 10^e. struct Dec32 { diff --git a/vlib/strconv/ftoa/f64_str.v b/vlib/strconv/f64_str.v similarity index 99% rename from vlib/strconv/ftoa/f64_str.v rename to vlib/strconv/f64_str.v index 0b110ea03e..86f531b076 100644 --- a/vlib/strconv/ftoa/f64_str.v +++ b/vlib/strconv/f64_str.v @@ -17,7 +17,7 @@ inspired by the Go version here: https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea */ -module ftoa +module strconv struct Uint128 { mut: diff --git a/vlib/strconv/format.v b/vlib/strconv/format.v index ef8211930b..e8e764f4a1 100644 --- a/vlib/strconv/format.v +++ b/vlib/strconv/format.v @@ -10,7 +10,7 @@ This file contains the printf/sprintf functions */ module strconv -import strconv.ftoa + import strings enum Char_parse_state { @@ -69,7 +69,7 @@ const( pub fn f64_to_str_lnd(f f64, dec_digit int) string { // we add the rounding value - s := ftoa.f64_to_str(f + dec_round[dec_digit], 18) + s := f64_to_str(f + dec_round[dec_digit], 18) // check for +inf -inf Nan if s.len > 2 && (s[0] == `n` || s[1] == `i`) { return s @@ -77,7 +77,7 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string { m_sgn_flag := false mut sgn := 1 - mut b := [26]byte + mut b := [26]byte mut d_pos := 1 mut i := 0 mut i1 := 0 @@ -232,14 +232,14 @@ pub fn format_str(s string, p BF_param) string { return res.str() } -// max int64 9223372036854775807 +// max int64 9223372036854775807 pub fn format_dec(d u64, p BF_param) string { mut s := "" mut res := strings.new_builder(20) mut sign_len_diff := 0 if p.pad_ch == `0` { if p.positive { - if p.sign_flag { + if p.sign_flag { res.write_b(`+`) sign_len_diff = -1 } @@ -278,12 +278,12 @@ pub fn format_dec(d u64, p BF_param) string { pub fn format_fl(f f64, p BF_param) string { mut s := "" mut fs := f64_to_str_lnd(if f >= 0.0 {f} else {-f}, p.len1) - + // error!! if fs[0] == `[` { return fs } - + if p.rm_tail_zero { fs = remove_tail_zeros(fs) } @@ -292,7 +292,7 @@ pub fn format_fl(f f64, p BF_param) string { mut sign_len_diff := 0 if p.pad_ch == `0` { if p.positive { - if p.sign_flag { + if p.sign_flag { res.write_b(`+`) sign_len_diff = -1 } @@ -332,7 +332,7 @@ pub fn format_fl(f f64, p BF_param) string { pub fn format_es(f f64, p BF_param) string { mut s := "" - mut fs := ftoa.f64_to_str_pad(if f> 0 {f} else {-f},p.len1) + mut fs := f64_to_str_pad(if f> 0 {f} else {-f},p.len1) if p.rm_tail_zero { fs = remove_tail_zeros(fs) } @@ -341,7 +341,7 @@ pub fn format_es(f f64, p BF_param) string { mut sign_len_diff := 0 if p.pad_ch == `0` { if p.positive { - if p.sign_flag { + if p.sign_flag { res.write_b(`+`) sign_len_diff = -1 } @@ -441,7 +441,7 @@ pub fn v_sprintf(str string, pt ... voidptr) string{ mut pad_ch := ` ` // pad char mut th_separator := false // thousands separator flag - // prefix chars for Length field + // prefix chars for Length field mut ch1 := `0` // +1 char if present else `0` mut ch2 := `0` // +2 char if present else `0` @@ -523,7 +523,7 @@ pub fn v_sprintf(str string, pt ... voidptr) string{ status = .check_float i++ continue - } + } // manage "%.*s" precision field else if ch == `.` && fc_ch1 == `*` && fc_ch2 == `s` { len := unsafe {*(&int(pt[p_index]))} @@ -748,7 +748,7 @@ pub fn v_sprintf(str string, pt ... voidptr) string{ */ x := unsafe {*(&i64(pt[p_index]))} s = x.hex() - } + } else { x := unsafe {*(&int(pt[p_index]))} s = x.hex() diff --git a/vlib/strconv/ftoa/ftoa.v b/vlib/strconv/ftoa.v similarity index 86% rename from vlib/strconv/ftoa/ftoa.v rename to vlib/strconv/ftoa.v index 472e71a8c7..39708c931f 100644 --- a/vlib/strconv/ftoa/ftoa.v +++ b/vlib/strconv/ftoa.v @@ -9,15 +9,15 @@ that can be found in the LICENSE file. This file contains the f32/f64 ftoa functions These functions are based on the work of: -Publication:PLDI 2018: Proceedings of the 39th ACM SIGPLAN -Conference on Programming Language Design and ImplementationJune 2018 +Publication:PLDI 2018: Proceedings of the 39th ACM SIGPLAN +Conference on Programming Language Design and ImplementationJune 2018 Pages 270–282 https://doi.org/10.1145/3192366.3192369 -inspired by the Go version here: +inspired by the Go version here: https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea */ -module ftoa +module strconv [inline] pub fn ftoa_64(f f64) string { diff --git a/vlib/strconv/ftoa/tables.v b/vlib/strconv/tables.v similarity index 99% rename from vlib/strconv/ftoa/tables.v rename to vlib/strconv/tables.v index ce2d52d13b..519342e6f7 100644 --- a/vlib/strconv/ftoa/tables.v +++ b/vlib/strconv/tables.v @@ -1,4 +1,4 @@ -module ftoa +module strconv const( pow5_num_bits_32 = 61 diff --git a/vlib/strconv/ftoa/utilities.v b/vlib/strconv/utilities.v similarity index 99% rename from vlib/strconv/ftoa/utilities.v rename to vlib/strconv/utilities.v index 34bb95b32e..f1b32ec7f0 100644 --- a/vlib/strconv/ftoa/utilities.v +++ b/vlib/strconv/utilities.v @@ -17,7 +17,7 @@ inspired by the Go version here: https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea */ -module ftoa +module strconv import math.bits diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 7907fa505d..c10ed6cd38 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -141,10 +141,8 @@ fn (mut v Builder) cc() { // '-Werror', // TODO : try and remove the below workaround options when the corresponding // warnings are totally fixed/removed - mut a := [v.pref.cflags, '-std=gnu11', '-Wall', '-Wextra', '-Wno-unused-variable', - '-Wno-unused-parameter', '-Wno-unused-result', '-Wno-unused-function', '-Wno-missing-braces', - '-Wno-unused-label' - ] + mut a := [v.pref.cflags, '-std=gnu11', '-Wall', '-Wextra', '-Wno-unused-variable', '-Wno-unused-parameter', + '-Wno-unused-result', '-Wno-unused-function', '-Wno-missing-braces', '-Wno-unused-label'] mut linker_flags := []string{} // TCC on Linux by default, unless -cc was provided // TODO if -cc = cc, TCC is still used, default compiler should be @@ -357,9 +355,10 @@ fn (mut v Builder) cc() { } if v.pref.use_cache { // vexe := pref.vexe_path() - cached_modules := ['builtin', 'os', 'math', 'strconv', 'strings'] + cached_modules := ['builtin', 'os', 'math', 'strconv', 'strings', 'hash.wyhash', 'strconv.ftoa'] for cfile in cached_modules { - ofile := os.join_path(pref.default_module_path, 'cache', 'vlib', cfile + '.o') + ofile := os.join_path(pref.default_module_path, 'cache', 'vlib', cfile.replace('.', '/') + + '.o') if !os.exists(ofile) { println('${cfile}.o is missing. Building...') println('$vexe build-module vlib/$cfile') @@ -416,7 +415,7 @@ fn (mut v Builder) cc() { println('=====================') println('> C compiler cmd: $cmd') if v.pref.show_cc { - println("> C compiler response file $response_file:") + println('> C compiler response file $response_file:') println(response_file_content) } println('=====================') @@ -478,7 +477,7 @@ fn (mut v Builder) cc() { println('$ccompiler took $diff ms') println('=========\n') } - v.timing_message('C ${ccompiler:3}: ${diff}ms') + v.timing_message('C ${ccompiler:3}: ${diff}ms') // Link it if we are cross compiling and need an executable /* if v.os == .linux && !linux_host && v.pref.build_mode != .build { @@ -565,9 +564,7 @@ fn (mut b Builder) cc_linux_cross() { } linker_args := ['-L $sysroot/usr/lib/x86_64-linux-gnu/', '--sysroot=$sysroot -v -o $b.pref.out_name -m elf_x86_64', '-dynamic-linker /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2', '$sysroot/crt1.o $sysroot/crti.o x.o', - '-lc', '-lcrypto', '-lssl', '-lpthread', '$sysroot/crtn.o', - cflags.c_options_only_object_files() - ] + '-lc', '-lcrypto', '-lssl', '-lpthread', '$sysroot/crtn.o', cflags.c_options_only_object_files()] // -ldl linker_args_str := linker_args.join(' ') cmd := '$sysroot/ld.lld ' + linker_args_str diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index 8fe4cc2f0a..7449a6566f 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -167,8 +167,10 @@ Did you forget to add vlib to the path? (Use @vlib for default vlib)') } pub fn (v &Builder) get_user_files() []string { - if v.pref.path in ['vlib/builtin', 'vlib/strconv', 'vlib/strings', 'vlib/hash'] { - // get_builtin_files() has already added the builtin files: + if v.pref.path in ['vlib/builtin', 'vlib/strconv', 'vlib/strings', 'vlib/hash', 'vlib/hash/wyhash'] { + // This means we are building a builtin module with `v build-module vlib/strings` etc + // get_builtin_files() has already added the files in this module, + // do nothing here to avoid duplicate definition errors. v.log('Skipping user files.') return [] }