Skip to content

Commit

Permalink
minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
serkonda7 committed Feb 4, 2025
1 parent 252dfdb commit 1a9377e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 5 additions & 1 deletion lib/bait/ast/table.bt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package ast

pub struct Table {
pub mut type_idxs map[string]Type
mut type_idxs map[string]Type
pub mut type_symbols []TypeSymbol
pub mut needed_equality_funs []Type
pub mut needed_str_funs []Type
Expand Down Expand Up @@ -34,6 +34,10 @@ pub fun (t Table) type_exists(name string) bool {
return sym.kind != .placeholder
}

pub fun (t Table) type_idx_exists(name string) bool {
return t.type_idxs.contains(name)
}

pub fun (t Table) unwrap_result(typ Type) Type {
sym := t.get_sym(typ)
return if sym.kind == .result { sym.parent } else { typ }
Expand Down
24 changes: 14 additions & 10 deletions lib/bait/checker/fun.bt
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,8 @@ fun (mut c Checker) fun_decl(mut node ast.FunDecl) {
}
}
}
} else {
if node.is_test {
c.gen_ctx.test_fun_names.push(node.name)
} else if c.prefs.is_test {
if node.name == "testsuite_begin" {
c.gen_ctx.has_test_begin = true
} else if node.name == "testsuite_end" {
c.gen_ctx.has_test_end = true
}
}
} else if c.prefs.is_test {
c.testing_fun_checks(node)
}

if node.generic_names.length > 0 and c.cur_concrete_types.length == 0 {
Expand Down Expand Up @@ -121,6 +113,18 @@ fun (c Checker) fun_params(params []ast.Param){
}
}

fun (mut c Checker) testing_fun_checks(node ast.FunDecl) {
if node.is_test {
c.gen_ctx.test_fun_names.push(node.name)
} else {
if node.name == "testsuite_begin" {
c.gen_ctx.has_test_begin = true
} else if node.name == "testsuite_end" {
c.gen_ctx.has_test_end = true
}
}
}

fun (mut c Checker) check_main_fun(stmts []ast.Stmt) {
for stmt in stmts {
if stmt is ast.FunDecl and stmt.is_main() {
Expand Down
2 changes: 1 addition & 1 deletion lib/bait/parser/type.bt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fun (mut p Parser) parse_name_type(lang ast.Language) !ast.Type {

} else if p.expr_pkg.length > 0 {
name = p.prepend_expr_pkg(name)
} else if not name.contains('.') and not p.table.type_idxs.contains(name) {
} else if not name.contains('.') and not p.table.type_idx_exists(name) {
name = p.prepend_pkg(name)
}

Expand Down

0 comments on commit 1a9377e

Please sign in to comment.