mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
compiler: make compiler an ordinary vlib/compiler module
* Move compiler/ under vlib/compiler/ . * Add a minimal compiler/main.v driver program. * Cleanup compiler/main.v . * Make most compiler tests pass again. * Apply the fix by @joe-conigliaro , so that the rest of the compiler tests are fixed too. * Thanks to @avitkauskas, now the vlib/vcompiler/tests/str_gen_test.v test does not need to be special cased anymore. * Reapply @joe-conigliaro fix for vgen.
This commit is contained in:
parent
59d4535f84
commit
53c64abdeb
71 changed files with 1095 additions and 1080 deletions
|
@ -1,40 +0,0 @@
|
|||
module main
|
||||
|
||||
// `a in [1,2,3]` => `a == 1 || a == 2 || a == 3`
|
||||
// avoid allocation
|
||||
// `typ` is the type of `a`
|
||||
// `ph` is for string_eq()
|
||||
fn (p mut Parser) in_optimization(typ string, ph int) {
|
||||
p.check(.lsbr)
|
||||
mut i := 0
|
||||
// Get `a` expr value (can be a string literal, not a variable)
|
||||
expr := p.cgen.cur_line.right(ph)
|
||||
is_str := typ == 'string'
|
||||
//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 {
|
||||
p.gen(' || $expr == ')
|
||||
}
|
||||
}
|
||||
if i == 0 {
|
||||
if is_str {
|
||||
p.cgen.set_placeholder(ph, ' string_eq(')
|
||||
p.gen(', ')
|
||||
} else {
|
||||
p.gen(' ==')
|
||||
}
|
||||
}
|
||||
p.check_types(p.bool_expression(), typ)
|
||||
if is_str {
|
||||
p.gen(')')
|
||||
}
|
||||
if p.tok != .rsbr {
|
||||
p.check(.comma)
|
||||
}
|
||||
i++
|
||||
}
|
||||
p.check(.rsbr)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue