make print() generic, just like println()
parent
7fc899dfd6
commit
0c31172fb0
|
@ -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
|
// Optimize `println`: replace it with `printf` to avoid extra allocations and
|
||||||
// function calls. `println(777)` => `printf("%d\n", 777)`
|
// function calls. `println(777)` => `printf("%d\n", 777)`
|
||||||
// (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' || f.name == 'print') && typ != 'string' && typ != 'void' {
|
||||||
T := p.table.find_type(typ)
|
T := p.table.find_type(typ)
|
||||||
$if !windows {
|
$if !windows {
|
||||||
fmt := p.typ_to_fmt(typ, 0)
|
fmt := p.typ_to_fmt(typ, 0)
|
||||||
if fmt != '' {
|
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
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ const (
|
||||||
CReserved = [
|
CReserved = [
|
||||||
'exit',
|
'exit',
|
||||||
'unix',
|
'unix',
|
||||||
'print',
|
//'print',
|
||||||
// 'ok',
|
// 'ok',
|
||||||
'error',
|
'error',
|
||||||
'malloc',
|
'malloc',
|
||||||
|
|
Loading…
Reference in New Issue