cgen: fixes for ustring, makes utf8_util_test.v pass

pull/4550/head
Delyan Angelov 2020-04-22 10:35:14 +03:00
parent b228bd267f
commit 4b8ed3f831
4 changed files with 33 additions and 7 deletions

View File

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

View File

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

View File

@ -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(' }

View File

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