minor V.js fixes

pull/2538/head
Alexander Medvednikov 2019-10-25 11:24:34 +03:00
parent 97096e4e6c
commit 4e21e9ed44
4 changed files with 27 additions and 18 deletions

View File

@ -19,7 +19,7 @@ pub fn panic(s string) {
}
pub fn println(s string) {
#console.log(s)
#console.log(s.str)
}
pub fn eprintln(s string) {

View File

@ -17,6 +17,15 @@ fn C.strlen(s byteptr) int
fn todo() { }
pub fn tos(s byteptr) string {
len := 0
#len = s.length;
return string{
str: s
len: len
}
}
pub fn (a string) clone() string {
return a

View File

@ -214,22 +214,22 @@ fn type_default(typ string) string {
return '{}'
}
// Default values for other types are not needed because of mandatory initialization
switch typ {
case 'bool': return '0'
case 'string': return '""'
case 'i8': return '0'
case 'i16': return '0'
case 'i64': return '0'
case 'u16': return '0'
case 'u32': return '0'
case 'u64': return '0'
case 'byte': return '0'
case 'int': return '0'
case 'rune': return '0'
case 'f32': return '0.0'
case 'f64': return '0.0'
case 'byteptr': return '0'
case 'voidptr': return '0'
match typ {
'bool'{ return '0'}
'string'{ return 'tos("")'}
'i8'{ return '0'}
'i16'{ return '0'}
'i64'{ return '0'}
'u16'{ return '0'}
'u32'{ return '0'}
'u64'{ return '0'}
'byte'{ return '0'}
'int'{ return '0'}
'rune'{ return '0'}
'f32'{ return '0.0'}
'f64'{ return '0.0'}
'byteptr'{ return '0'}
'voidptr'{ return '0'}
}
return '{}'
}

View File

@ -2688,7 +2688,7 @@ fn (p mut Parser) string_expr() {
p.gen("'$str'")
}
else if p.is_js {
p.gen('"$f"')
p.gen('tos("$f")')
}
else {
p.gen('tos3("$f")')