compiler: no need to optimize println on Windows

this fixes string interpolation
pull/1394/head
Vitaly Takmazov 2019-07-31 10:51:24 +03:00 committed by Alexander Medvednikov
parent e592485395
commit f3d6bc9146
2 changed files with 15 additions and 11 deletions

View File

@ -808,11 +808,13 @@ fn (p mut Parser) fn_call_args(f mut Fn) *Fn {
// (If we don't check for void, then V will compile `println(func())`) // (If we don't check for void, then V will compile `println(func())`)
if i == 0 && f.name == 'println' && typ != 'string' && typ != 'void' { if i == 0 && f.name == 'println' && typ != 'string' && typ != 'void' {
T := p.table.find_type(typ) T := p.table.find_type(typ)
fmt := p.typ_to_fmt(typ, 0) $if !windows {
if fmt != '' { fmt := p.typ_to_fmt(typ, 0)
p.cgen.resetln(p.cgen.cur_line.replace('println (', '/*opt*/printf ("' + fmt + '\\n", ')) if fmt != '' {
continue p.cgen.resetln(p.cgen.cur_line.replace('println (', '/*opt*/printf ("' + fmt + '\\n", '))
} continue
}
}
if typ.ends_with('*') { if typ.ends_with('*') {
p.cgen.set_placeholder(ph, 'ptr_str(') p.cgen.set_placeholder(ph, 'ptr_str(')
p.gen(')') p.gen(')')

View File

@ -2395,12 +2395,14 @@ fn (p mut Parser) string_expr() {
return return
} }
// println: don't allocate a new string, just print it. // println: don't allocate a new string, just print it.
cur_line := p.cgen.cur_line.trim_space() $if !windows {
if cur_line.contains('println (') && p.tok != .plus && cur_line := p.cgen.cur_line.trim_space()
!cur_line.contains('string_add') && !cur_line.contains('eprintln') { if cur_line.contains('println (') && p.tok != .plus &&
p.cgen.resetln(cur_line.replace('println (', 'printf(')) !cur_line.contains('string_add') && !cur_line.contains('eprintln') {
p.gen('$format\\n$args') p.cgen.resetln(cur_line.replace('println (', 'printf('))
return p.gen('$format\\n$args')
return
}
} }
// '$age'! means the user wants this to be a tmp string (uses global buffer, no allocation, // '$age'! means the user wants this to be a tmp string (uses global buffer, no allocation,
// won't be used again) // won't be used again)