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.
module builtin
import strconv.ftoa
import strconv
#include <float.h>
// ----- 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 -----

View File

@ -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")

View File

@ -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:

View File

@ -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 {

View File

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

View File

@ -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()

View File

@ -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 270282 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 {

View File

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

View File

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

View File

@ -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

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 {
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 []
}