1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v2: checker & unresolved fixes & small updates

This commit is contained in:
joe-conigliaro 2020-02-08 04:46:42 +11:00 committed by GitHub
parent 36e636743b
commit 35bef514b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 51 deletions

View File

@ -47,14 +47,20 @@ pub fn (b mut Builder) build_c(v_files []string, out_file string) {
}
pub fn (b mut Builder) build_x64(v_files []string, out_file string) {
ticks := time.ticks()
t0 := time.ticks()
b.parsed_files = parser.parse_files(v_files, b.table)
b.parse_imports()
println('PARSE: ${time.ticks() - ticks}ms')
t1 := time.ticks()
parse_time := t1 - t0
println('PARSE: ${parse_time}ms')
b.checker.check_files(b.parsed_files)
println('CHECK: ${time.ticks() - ticks}ms')
t2 := time.ticks()
check_time := t2 - t1
println('CHECK: ${check_time}ms')
x64.gen(b.parsed_files, out_file)
println('x64 GEN: ${time.ticks() - ticks}ms')
t3 := time.ticks()
gen_time := t3 - t2
println('x64 GEN: ${gen_time}ms')
}
// parse all deps from already parsed files
@ -150,6 +156,7 @@ pub fn (b &Builder) v_files_from_dir(dir string) []string {
}
}
*/
res << filepath.join(dir,file)
}
return res

View File

@ -14,7 +14,6 @@ pub struct Checker {
table &table.Table
mut:
file_name string
unresolved []ast.Expr
resolved []table.TypeRef
}
@ -26,27 +25,38 @@ pub fn new_checker(table &table.Table) Checker {
pub fn (c mut Checker) check(ast_file ast.File) {
c.file_name = ast_file.path
c.unresolved = ast_file.unresolved
c.resolve_types()
// if ast_file.unresolved.len != c.resolved.len {
// c.resolve_exprs(file)
// }
c.complete_types(ast_file)
for stmt in ast_file.stmts {
c.stmt(stmt)
}
}
pub fn (c mut Checker) check_files(ast_files []ast.File) {
// this cant be moved to check() for multiple
// files this muse be done first. TODO: optimize
for file in ast_files {
c.file_name = file.path
c.resolve_expr_types(file)
}
for file in ast_files {
c.check(file)
}
}
fn (c mut Checker) resolve_types() {
// resolve type of unresolved expressions
for x in c.unresolved {
fn (c mut Checker) resolve_expr_types(f ast.File) {
for x in f.unresolved {
c.resolved << c.expr(x)
}
// update any types with unresolved sub types
}
// update any types chich contain unresolved sub types
fn (c &Checker) complete_types(f ast.File) {
for idx, t in c.table.types {
println('Resolve type: $t.name')
// println('Resolve type: $t.name')
if t.kind == .array {
mut info := t.array_info()
if info.elem_type.typ.kind == .unresolved {

View File

@ -44,7 +44,7 @@ mut:
builtin_mod bool
mod string
unresolved []ast.Expr
unresolved_idxs map[string]int
unresolved_offset int
}
// for tests
@ -1223,9 +1223,9 @@ fn (p mut Parser) match_expr() (ast.Expr,table.TypeRef) {
}
fn (p mut Parser) add_unresolved(key string, expr ast.Expr) table.TypeRef {
mut idx := p.unresolved.len
if key in p.unresolved_idxs {
idx = p.unresolved_idxs[key]
mut idx := p.unresolved_offset + p.unresolved.len
if key in p.table.unresolved_idxs {
idx = p.table.unresolved_idxs[key]
}
else {
p.unresolved << expr
@ -1235,7 +1235,7 @@ fn (p mut Parser) add_unresolved(key string, expr ast.Expr) table.TypeRef {
typ: &table.Type{
parent: 0
kind: .unresolved
name: 'unresolved $idx'
name: 'unresolved-$idx'
}
}
return t

View File

@ -11,6 +11,7 @@ pub mut:
types []Type
// type_idxs Hashmap
type_idxs map[string]int
unresolved_idxs map[string]int
local_vars []Var
scope_level int
var_idx int