1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
Alexander Medvednikov
2019-12-20 00:29:37 +03:00
parent b6fe2ebc0b
commit 6210984c97
54 changed files with 1757 additions and 1993 deletions

View File

@ -1,5 +1,4 @@
module compiler
// `a in [1,2,3]` => `a == 1 || a == 2 || a == 3`
// avoid allocation
// `typ` is the type of `a`
@ -13,12 +12,13 @@ fn (p mut Parser) in_optimization(typ string, ph int) {
// Get `a` expr value (can be a string literal, not a variable)
expr := p.cgen.cur_line[ph..]
is_str := typ == 'string'
//println('!! $p.expr_var.name => $name ($typ)')
// println('!! $p.expr_var.name => $name ($typ)')
for p.tok != .rsbr && p.tok != .eof {
if i > 0 {
if is_str {
p.gen(' || string_eq($expr, ')
} else {
}
else {
p.gen(' || $expr == ')
}
}
@ -26,7 +26,8 @@ fn (p mut Parser) in_optimization(typ string, ph int) {
if is_str {
p.cgen.set_placeholder(ph, ' (string_eq(')
p.gen(', ')
} else {
}
else {
p.cgen.set_placeholder(ph, ' (')
p.gen(' ==')
}
@ -44,3 +45,4 @@ fn (p mut Parser) in_optimization(typ string, ph int) {
p.gen(')')
p.check(.rsbr)
}