cc: build-module/module cache fixes; strconv: move all code in one module

pull/5853/head
Alexander Medvednikov 2020-07-16 19:01:22 +02:00
parent f66967a88c
commit dc89a914ea
12 changed files with 44 additions and 54 deletions

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license that can be found in the LICENSE file. // Use of this source code is governed by an MIT license that can be found in the LICENSE file.
module builtin module builtin
import strconv.ftoa import strconv
#include <float.h> #include <float.h>
// ----- f64 to string functions ----- // ----- f64 to string functions -----
@ -11,9 +11,9 @@ import strconv.ftoa
pub fn (x f64) str() string { pub fn (x f64) str() string {
abs_x := f64_abs(x) abs_x := f64_abs(x)
if abs_x >= 0.0001 && abs_x < 1.0e6 { if abs_x >= 0.0001 && abs_x < 1.0e6 {
return ftoa.f64_to_str_l(x) return strconv.f64_to_str_l(x)
} else { } 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 { } else if n_digit > 17 {
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 // return a decimal notation of the input f64
[inline] [inline]
pub fn (x f64) strlong() string { pub fn (x f64) strlong() string {
return ftoa.f64_to_str_l(x) return strconv.f64_to_str_l(x)
} }
// ----- f32 to string functions ----- // ----- f32 to string functions -----
@ -46,9 +46,9 @@ pub fn (x f64) strlong() string {
pub fn (x f32) str() string { pub fn (x f32) str() string {
abs_x := f32_abs(x) abs_x := f32_abs(x)
if abs_x >= 0.0001 && abs_x < 1.0e6 { if abs_x >= 0.0001 && abs_x < 1.0e6 {
return ftoa.f32_to_str_l(x) return strconv.f32_to_str_l(x)
} else { } 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 { } else if n_digit > 8 {
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 // return a decimal notation of the input f32
[inline] [inline]
pub fn (x f32) strlong() string { pub fn (x f32) strlong() string {
return ftoa.f32_to_str_l(x) return strconv.f32_to_str_l(x)
} }
// ----- C functions ----- // ----- C functions -----

View File

@ -4,7 +4,6 @@
* *
**********************************************************************/ **********************************************************************/
import strconv import strconv
import strconv.atofq
fn test_atof() { fn test_atof() {
// //
@ -40,7 +39,7 @@ fn test_atof() {
// quick 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()) mut s2 := (x.str())
delta := s1.f64() - s2.f64() delta := s1.f64() - s2.f64()
//println("$s1 $s2 $delta") //println("$s1 $s2 $delta")

View File

@ -16,15 +16,7 @@ Know limitation:
*/ */
module atofq module strconv
// 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)
)
union Float64u { union Float64u {
mut: mut:

View File

@ -17,7 +17,7 @@ inspired by the Go version here:
https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea
*/ */
module ftoa module strconv
// dec32 is a floating decimal type representing m * 10^e. // dec32 is a floating decimal type representing m * 10^e.
struct Dec32 { struct Dec32 {

View File

@ -17,7 +17,7 @@ inspired by the Go version here:
https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea
*/ */
module ftoa module strconv
struct Uint128 { struct Uint128 {
mut: mut:

View File

@ -10,7 +10,7 @@ This file contains the printf/sprintf functions
*/ */
module strconv module strconv
import strconv.ftoa
import strings import strings
enum Char_parse_state { enum Char_parse_state {
@ -69,7 +69,7 @@ const(
pub fn f64_to_str_lnd(f f64, dec_digit int) string { pub fn f64_to_str_lnd(f f64, dec_digit int) string {
// we add the rounding value // 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 // check for +inf -inf Nan
if s.len > 2 && (s[0] == `n` || s[1] == `i`) { if s.len > 2 && (s[0] == `n` || s[1] == `i`) {
return s return s
@ -332,7 +332,7 @@ pub fn format_fl(f f64, p BF_param) string {
pub fn format_es(f f64, p BF_param) string { pub fn format_es(f f64, p BF_param) string {
mut s := "" 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 { if p.rm_tail_zero {
fs = remove_tail_zeros(fs) fs = remove_tail_zeros(fs)
} }

View File

@ -17,7 +17,7 @@ inspired by the Go version here:
https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea
*/ */
module ftoa module strconv
[inline] [inline]
pub fn ftoa_64(f f64) string { pub fn ftoa_64(f f64) string {

View File

@ -1,4 +1,4 @@
module ftoa module strconv
const( const(
pow5_num_bits_32 = 61 pow5_num_bits_32 = 61

View File

@ -17,7 +17,7 @@ inspired by the Go version here:
https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea
*/ */
module ftoa module strconv
import math.bits import math.bits

View File

@ -141,10 +141,8 @@ fn (mut v Builder) cc() {
// '-Werror', // '-Werror',
// TODO : try and remove the below workaround options when the corresponding // TODO : try and remove the below workaround options when the corresponding
// warnings are totally fixed/removed // warnings are totally fixed/removed
mut a := [v.pref.cflags, '-std=gnu11', '-Wall', '-Wextra', '-Wno-unused-variable', mut a := [v.pref.cflags, '-std=gnu11', '-Wall', '-Wextra', '-Wno-unused-variable', '-Wno-unused-parameter',
'-Wno-unused-parameter', '-Wno-unused-result', '-Wno-unused-function', '-Wno-missing-braces', '-Wno-unused-result', '-Wno-unused-function', '-Wno-missing-braces', '-Wno-unused-label']
'-Wno-unused-label'
]
mut linker_flags := []string{} mut linker_flags := []string{}
// TCC on Linux by default, unless -cc was provided // TCC on Linux by default, unless -cc was provided
// TODO if -cc = cc, TCC is still used, default compiler should be // 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 { if v.pref.use_cache {
// vexe := pref.vexe_path() // 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 { 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) { if !os.exists(ofile) {
println('${cfile}.o is missing. Building...') println('${cfile}.o is missing. Building...')
println('$vexe build-module vlib/$cfile') println('$vexe build-module vlib/$cfile')
@ -416,7 +415,7 @@ fn (mut v Builder) cc() {
println('=====================') println('=====================')
println('> C compiler cmd: $cmd') println('> C compiler cmd: $cmd')
if v.pref.show_cc { if v.pref.show_cc {
println("> C compiler response file $response_file:") println('> C compiler response file $response_file:')
println(response_file_content) println(response_file_content)
} }
println('=====================') println('=====================')
@ -478,7 +477,7 @@ fn (mut v Builder) cc() {
println('$ccompiler took $diff ms') println('$ccompiler took $diff ms')
println('=========\n') 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 // Link it if we are cross compiling and need an executable
/* /*
if v.os == .linux && !linux_host && v.pref.build_mode != .build { 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', 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', '-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', '-lc', '-lcrypto', '-lssl', '-lpthread', '$sysroot/crtn.o', cflags.c_options_only_object_files()]
cflags.c_options_only_object_files()
]
// -ldl // -ldl
linker_args_str := linker_args.join(' ') linker_args_str := linker_args.join(' ')
cmd := '$sysroot/ld.lld ' + linker_args_str cmd := '$sysroot/ld.lld ' + linker_args_str

View File

@ -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 { pub fn (v &Builder) get_user_files() []string {
if v.pref.path in ['vlib/builtin', 'vlib/strconv', 'vlib/strings', 'vlib/hash'] { if v.pref.path in ['vlib/builtin', 'vlib/strconv', 'vlib/strings', 'vlib/hash', 'vlib/hash/wyhash'] {
// get_builtin_files() has already added the builtin files: // 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.') v.log('Skipping user files.')
return [] return []
} }