From 4b8ed3f831fa753b753265aac900ba6dbe668e4b Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 22 Apr 2020 10:35:14 +0300 Subject: [PATCH] cgen: fixes for ustring, makes utf8_util_test.v pass --- cmd/tools/vtest-fixed.v | 1 - vlib/builtin/string_test.v | 2 +- vlib/v/gen/cgen.v | 18 +++++++++++++++++- vlib/v/table/atypes.v | 19 +++++++++++++++---- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/cmd/tools/vtest-fixed.v b/cmd/tools/vtest-fixed.v index e0b8501036..53a4937b26 100644 --- a/cmd/tools/vtest-fixed.v +++ b/cmd/tools/vtest-fixed.v @@ -9,7 +9,6 @@ const ( 'vlib/arrays/arrays_test.v', 'vlib/crypto/aes/aes_test.v', 'vlib/crypto/rc4/rc4_test.v', - 'vlib/encoding/utf8/utf8_util_test.v', 'vlib/eventbus/eventbus_test.v', 'vlib/json/json_test.v', 'vlib/net/ftp/ftp_test.v', diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 6688664387..58eada529f 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -366,7 +366,7 @@ fn test_to_num() { assert s.u64() == 7 f := '71.5 hasdf' // QTODO - //assert f.f32() == 71.5 + assert f.f32() == 71.5 vals := ['9'] assert vals[0].int() == 9 big := '93993993939322' diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index bb79b8a52e..ed8c08f832 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1285,7 +1285,23 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) { return } right_sym := g.table.get_type_symbol(node.right_type) - if node.left_type == table.string_type_idx && node.op != .key_in && node.op != .not_in { + if node.left_type == table.ustring_type_idx && node.op != .key_in && node.op != .not_in { + fn_name := match node.op { + .plus { 'ustring_add(' } + .eq { 'ustring_eq(' } + .ne { 'ustring_ne(' } + .lt { 'ustring_lt(' } + .le { 'ustring_le(' } + .gt { 'ustring_gt(' } + .ge { 'ustring_ge(' } + else { '/*node error*/' } + } + g.write(fn_name) + g.expr(node.left) + g.write(', ') + g.expr(node.right) + g.write(')') + } else if node.left_type == table.string_type_idx && node.op != .key_in && node.op != .not_in { fn_name := match node.op { .plus { 'string_add(' } .eq { 'string_eq(' } diff --git a/vlib/v/table/atypes.v b/vlib/v/table/atypes.v index 6809b90c15..903f288ba2 100644 --- a/vlib/v/table/atypes.v +++ b/vlib/v/table/atypes.v @@ -153,8 +153,9 @@ pub const ( bool_type_idx = 16 none_type_idx = 17 string_type_idx = 18 - array_type_idx = 19 - map_type_idx = 20 + ustring_type_idx = 19 + array_type_idx = 20 + map_type_idx = 21 ) pub const ( @@ -164,6 +165,7 @@ pub const ( number_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, f32_type_idx, f64_type_idx] pointer_type_idxs = [voidptr_type_idx, byteptr_type_idx, charptr_type_idx] + string_type_idxs = [string_type_idx, ustring_type_idx] ) pub const ( @@ -185,14 +187,15 @@ pub const ( bool_type = new_type(bool_type_idx) none_type = new_type(none_type_idx) string_type = new_type(string_type_idx) + ustring_type = new_type(ustring_type_idx) array_type = new_type(array_type_idx) map_type = new_type(map_type_idx) ) pub const ( builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', - 'u16', 'u32', 'u64', 'f32', 'f64', 'string', 'char', 'byte', 'bool', 'none', 'array', 'array_fixed', - 'map', 'struct', 'mapnode', 'ustring', 'size_t'] + 'u16', 'u32', 'u64', 'f32', 'f64', 'string', 'ustring', 'char', 'byte', 'bool', 'none', 'array', 'array_fixed', + 'map', 'struct', 'mapnode', 'size_t'] ) pub struct MultiReturn { @@ -229,6 +232,7 @@ pub enum Kind { bool none_ string + ustring array array_fixed map @@ -388,6 +392,10 @@ pub fn (var t Table) register_builtin_type_symbols() { kind: .string name: 'string' }) + t.register_type_symbol(TypeSymbol{ + kind: .ustring + name: 'ustring' + }) t.register_type_symbol(TypeSymbol{ kind: .array name: 'array' @@ -488,6 +496,9 @@ pub fn (k Kind) str() string { .string { 'string' } + .ustring { + 'ustring' + } .char { 'char' }