From 317a9bae5f3fb836f05a2bce7e5a848e5b9958ab Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 7 Oct 2020 11:06:52 +0300 Subject: [PATCH] backporting: remove redefinition of strconv__Float64u --- vlib/strconv/atof.v | 19 +--------------- vlib/strconv/atofq.v | 10 ++------ vlib/strconv/atoi.v | 2 +- vlib/strconv/f32_str.v | 16 ++----------- vlib/strconv/f64_str.v | 23 ++----------------- vlib/strconv/format.v | 3 ++- vlib/strconv/ftoa.v | 3 ++- vlib/strconv/structs.v | 49 ++++++++++++++++++++++++++++++++++++++++ vlib/strconv/utilities.v | 3 ++- vlib/v/gen/cgen.v | 1 + 10 files changed, 64 insertions(+), 65 deletions(-) create mode 100644 vlib/strconv/structs.v diff --git a/vlib/strconv/atof.v b/vlib/strconv/atof.v index e3b28634a0..325893f411 100644 --- a/vlib/strconv/atof.v +++ b/vlib/strconv/atof.v @@ -1,3 +1,4 @@ +module strconv /* atof util @@ -17,17 +18,6 @@ Grzegorz Kraszewski krashan@teleinfo.pb.edu.pl URL: http://krashan.ppa.pl/articles/stringtofloat/ Original license: MIT -*/ -module strconv - -union Float64u { -mut: - f f64 - u u64 -} - -/* - 96 bit operation utilities Note: when u128 will be available these function can be refactored @@ -162,13 +152,6 @@ Support struct */ -// The structure is filled by parser, then given to converter. -pub struct PrepNumber { -pub mut: - negative bool // 0 if positive number, 1 if negative - exponent int // power of 10 exponent - mantissa u64 // integer mantissa -} /* String parser diff --git a/vlib/strconv/atofq.v b/vlib/strconv/atofq.v index 3517f7bdf5..e322294005 100644 --- a/vlib/strconv/atofq.v +++ b/vlib/strconv/atofq.v @@ -1,3 +1,5 @@ +module strconv + /* atof util @@ -16,14 +18,6 @@ Know limitation: */ -module strconv - -union Float64u { -mut: - f f64 - u u64 -} - // atof_quick return a f64 number from a string in a quick way pub fn atof_quick(s string) f64 { mut f := Float64u{} // result diff --git a/vlib/strconv/atoi.v b/vlib/strconv/atoi.v index 87628eee0d..c002ba6569 100644 --- a/vlib/strconv/atoi.v +++ b/vlib/strconv/atoi.v @@ -1,8 +1,8 @@ +module strconv // Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved. // Use of this source code is governed by an MIT license // that can be found in the LICENSE file. // TODO: use optionals, or some way to return default with error. -module strconv const ( // int_size is the size in bits of an int or uint value. diff --git a/vlib/strconv/f32_str.v b/vlib/strconv/f32_str.v index 353b4a08d4..ae26e94bac 100644 --- a/vlib/strconv/f32_str.v +++ b/vlib/strconv/f32_str.v @@ -1,3 +1,5 @@ +module strconv + /* f32 to string @@ -17,21 +19,7 @@ inspired by the Go version here: https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea */ -module strconv -// dec32 is a floating decimal type representing m * 10^e. -struct Dec32 { -mut: - m u32 - e int -} - -// support union for convert f32 to u32 -union Uf32 { -mut: - f f32 - u u32 -} // pow of ten table used by n_digit reduction const( diff --git a/vlib/strconv/f64_str.v b/vlib/strconv/f64_str.v index b9aee66f80..3bba450158 100644 --- a/vlib/strconv/f64_str.v +++ b/vlib/strconv/f64_str.v @@ -1,3 +1,5 @@ +module strconv + /* f32 to string @@ -17,27 +19,6 @@ inspired by the Go version here: https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea */ -module strconv - -struct Uint128 { -mut: - lo u64 - hi u64 -} - -// dec64 is a floating decimal type representing m * 10^e. -struct Dec64 { -mut: - m u64 - e int -} - -// support union for convert f64 to u64 -union Uf64 { -mut: - f f64 - u u64 -} // pow of ten table used by n_digit reduction const( diff --git a/vlib/strconv/format.v b/vlib/strconv/format.v index b4dccd7fd1..52292c5804 100644 --- a/vlib/strconv/format.v +++ b/vlib/strconv/format.v @@ -1,3 +1,5 @@ +module strconv + /* printf/sprintf V implementation @@ -9,7 +11,6 @@ that can be found in the LICENSE file. This file contains the printf/sprintf functions */ -module strconv import strings diff --git a/vlib/strconv/ftoa.v b/vlib/strconv/ftoa.v index 39708c931f..faca018122 100644 --- a/vlib/strconv/ftoa.v +++ b/vlib/strconv/ftoa.v @@ -1,3 +1,5 @@ +module strconv + /* f32/f64 ftoa functions @@ -17,7 +19,6 @@ inspired by the Go version here: https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea */ -module strconv [inline] pub fn ftoa_64(f f64) string { diff --git a/vlib/strconv/structs.v b/vlib/strconv/structs.v new file mode 100644 index 0000000000..ebc45712e2 --- /dev/null +++ b/vlib/strconv/structs.v @@ -0,0 +1,49 @@ +module strconv + +// The structure is filled by parser, then given to converter. +pub struct PrepNumber { +pub mut: + negative bool // 0 if positive number, 1 if negative + exponent int // power of 10 exponent + mantissa u64 // integer mantissa +} + +// dec32 is a floating decimal type representing m * 10^e. +struct Dec32 { +mut: + m u32 + e int +} + +// dec64 is a floating decimal type representing m * 10^e. +struct Dec64 { +mut: + m u64 + e int +} + +struct Uint128 { +mut: + lo u64 + hi u64 +} + +// support union for convert f32 to u32 +union Uf32 { +mut: + f f32 + u u32 +} + +// support union for convert f64 to u64 +union Uf64 { +mut: + f f64 + u u64 +} + +union Float64u { +mut: + f f64 + u u64 +} diff --git a/vlib/strconv/utilities.v b/vlib/strconv/utilities.v index e3305a986e..3dce03bb93 100644 --- a/vlib/strconv/utilities.v +++ b/vlib/strconv/utilities.v @@ -1,3 +1,5 @@ +module strconv + /* f32/f64 to string utilities @@ -17,7 +19,6 @@ inspired by the Go version here: https://github.com/cespare/ryu/tree/ba56a33f39e3bbbfa409095d0f9ae168a595feea */ -module strconv import math.bits diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 128c27fbb6..a49b2649dd 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -204,6 +204,7 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string // mut b := strings.new_builder(250000) b.write(g.hashes()) + b.writeln('\n// V comptime_defines:') b.write(g.comptime_defines.str()) b.writeln('\n// V typedefs:') b.write(g.typedefs.str())