v2: checker & unresolved fixes & small updates
parent
36e636743b
commit
35bef514b0
|
@ -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) {
|
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.parsed_files = parser.parse_files(v_files, b.table)
|
||||||
b.parse_imports()
|
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)
|
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)
|
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
|
// 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)
|
res << filepath.join(dir,file)
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -14,7 +14,6 @@ pub struct Checker {
|
||||||
table &table.Table
|
table &table.Table
|
||||||
mut:
|
mut:
|
||||||
file_name string
|
file_name string
|
||||||
unresolved []ast.Expr
|
|
||||||
resolved []table.TypeRef
|
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) {
|
pub fn (c mut Checker) check(ast_file ast.File) {
|
||||||
c.file_name = ast_file.path
|
c.file_name = ast_file.path
|
||||||
c.unresolved = ast_file.unresolved
|
// if ast_file.unresolved.len != c.resolved.len {
|
||||||
c.resolve_types()
|
// c.resolve_exprs(file)
|
||||||
|
// }
|
||||||
|
c.complete_types(ast_file)
|
||||||
for stmt in ast_file.stmts {
|
for stmt in ast_file.stmts {
|
||||||
c.stmt(stmt)
|
c.stmt(stmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (c mut Checker) check_files(ast_files []ast.File) {
|
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 {
|
for file in ast_files {
|
||||||
c.check(file)
|
c.check(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (c mut Checker) resolve_types() {
|
|
||||||
// resolve type of unresolved expressions
|
// 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)
|
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 {
|
for idx, t in c.table.types {
|
||||||
println('Resolve type: $t.name')
|
// println('Resolve type: $t.name')
|
||||||
if t.kind == .array {
|
if t.kind == .array {
|
||||||
mut info := t.array_info()
|
mut info := t.array_info()
|
||||||
if info.elem_type.typ.kind == .unresolved {
|
if info.elem_type.typ.kind == .unresolved {
|
||||||
|
|
|
@ -44,7 +44,7 @@ mut:
|
||||||
builtin_mod bool
|
builtin_mod bool
|
||||||
mod string
|
mod string
|
||||||
unresolved []ast.Expr
|
unresolved []ast.Expr
|
||||||
unresolved_idxs map[string]int
|
unresolved_offset int
|
||||||
}
|
}
|
||||||
|
|
||||||
// for tests
|
// 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 {
|
fn (p mut Parser) add_unresolved(key string, expr ast.Expr) table.TypeRef {
|
||||||
mut idx := p.unresolved.len
|
mut idx := p.unresolved_offset + p.unresolved.len
|
||||||
if key in p.unresolved_idxs {
|
if key in p.table.unresolved_idxs {
|
||||||
idx = p.unresolved_idxs[key]
|
idx = p.table.unresolved_idxs[key]
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p.unresolved << expr
|
p.unresolved << expr
|
||||||
|
@ -1235,7 +1235,7 @@ fn (p mut Parser) add_unresolved(key string, expr ast.Expr) table.TypeRef {
|
||||||
typ: &table.Type{
|
typ: &table.Type{
|
||||||
parent: 0
|
parent: 0
|
||||||
kind: .unresolved
|
kind: .unresolved
|
||||||
name: 'unresolved $idx'
|
name: 'unresolved-$idx'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t
|
return t
|
||||||
|
|
|
@ -11,6 +11,7 @@ pub mut:
|
||||||
types []Type
|
types []Type
|
||||||
// type_idxs Hashmap
|
// type_idxs Hashmap
|
||||||
type_idxs map[string]int
|
type_idxs map[string]int
|
||||||
|
unresolved_idxs map[string]int
|
||||||
local_vars []Var
|
local_vars []Var
|
||||||
scope_level int
|
scope_level int
|
||||||
var_idx int
|
var_idx int
|
||||||
|
|
Loading…
Reference in New Issue