make print() generic, just like println()

pull/1794/head
Alexander Medvednikov 2019-08-30 00:40:46 +03:00
parent 7fc899dfd6
commit 0c31172fb0
2 changed files with 3 additions and 3 deletions

View File

@ -834,12 +834,12 @@ fn (p mut Parser) fn_call_args(f mut Fn) *Fn {
// Optimize `println`: replace it with `printf` to avoid extra allocations and
// function calls. `println(777)` => `printf("%d\n", 777)`
// (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' || f.name == 'print') && typ != 'string' && typ != 'void' {
T := p.table.find_type(typ)
$if !windows {
fmt := p.typ_to_fmt(typ, 0)
if fmt != '' {
p.cgen.resetln(p.cgen.cur_line.replace('println (', '/*opt*/printf ("' + fmt + '\\n", '))
p.cgen.resetln(p.cgen.cur_line.replace(f.name + ' (', '/*opt*/printf ("' + fmt + '\\n", '))
continue
}
}

View File

@ -132,7 +132,7 @@ const (
CReserved = [
'exit',
'unix',
'print',
//'print',
// 'ok',
'error',
'malloc',