eval: fix new_checker call

pull/4222/head
yuyi 2020-04-04 08:03:41 +08:00 committed by GitHub
parent f8b4a6f168
commit bb5ed66bb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import (
v.ast v.ast
v.checker v.checker
v.table v.table
v.pref
) )
pub type Object = int | string pub type Object = int | string
@ -23,9 +24,10 @@ pub struct Var {
} }
pub fn (e mut Eval) eval(file ast.File, table &table.Table) string { pub fn (e mut Eval) eval(file ast.File, table &table.Table) string {
vpref := &pref.Preferences{}
e.table = table e.table = table
mut res := '' mut res := ''
e.checker = checker.new_checker(table) e.checker = checker.new_checker(table, vpref)
for stmt in file.stmts { for stmt in file.stmts {
res += e.stmt(stmt) + '\n' res += e.stmt(stmt) + '\n'
} }

View File

@ -37,6 +37,7 @@ fn test_eval() {
// //
] ]
table := table.new_table() table := table.new_table()
vpref := &pref.Preferences{}
mut scope := &ast.Scope{ mut scope := &ast.Scope{
start_pos: 0 start_pos: 0
parent: 0 parent: 0
@ -49,7 +50,7 @@ fn test_eval() {
stmts: stmts stmts: stmts
scope: scope scope: scope
} }
mut checker := checker.new_checker(table) mut checker := checker.new_checker(table, vpref)
checker.check(file) checker.check(file)
mut ev := eval.Eval{} mut ev := eval.Eval{}
s := ev.eval(file, table) s := ev.eval(file, table)
@ -79,7 +80,7 @@ x := 10
table := &table.Table{} table := &table.Table{}
vpref := &pref.Preferences{} vpref := &pref.Preferences{}
prog := parse_file(s, table, .skip_comments, vpref) prog := parse_file(s, table, .skip_comments, vpref)
mut checker := checker.new_checker(table) mut checker := checker.new_checker(table, vpref)
checker.check(prog) checker.check(prog)
res := gen.cgen([prog], table, vpref) res := gen.cgen([prog], table, vpref)
println(res) println(res)
@ -111,7 +112,7 @@ fn test_one() {
stmts: e stmts: e
scope: scope scope: scope
} }
mut checker := checker.new_checker(table) mut checker := checker.new_checker(table, vpref)
checker.check(program) checker.check(program)
res := gen.cgen([program], table, vpref).replace('\n', '').trim_space().after('#endif') res := gen.cgen([program], table, vpref).replace('\n', '').trim_space().after('#endif')
println(res) println(res)
@ -196,7 +197,7 @@ fn test_parse_expr() {
mut e := []ast.Stmt mut e := []ast.Stmt
table := table.new_table() table := table.new_table()
vpref := &pref.Preferences{} vpref := &pref.Preferences{}
mut checker := checker.new_checker(table) mut checker := checker.new_checker(table, vpref)
scope := &ast.Scope{ scope := &ast.Scope{
start_pos: 0 start_pos: 0
parent: 0 parent: 0