diff --git a/lib/bait/ast/ast.bt b/lib/bait/ast/ast.bt index 12eb4d72..5e2691dc 100644 --- a/lib/bait/ast/ast.bt +++ b/lib/bait/ast/ast.bt @@ -91,7 +91,7 @@ pub struct FunDecl { pub is_pub bool pub lang Language pub name string - pub mix_name string // TMP + pub key string // TODO rework generics and possibly remove this field pub params []Param pub return_type Type pub is_test bool diff --git a/lib/bait/ast/repr.bt b/lib/bait/ast/repr.bt index 018852c4..f2051c51 100644 --- a/lib/bait/ast/repr.bt +++ b/lib/bait/ast/repr.bt @@ -36,10 +36,3 @@ pub fun (e Expr) repr() string { InvalidExpr { 'InvalidExpr' } } } - -pub fun (fn FunDecl) key() string { - if fn.is_method { - return '${fn.params[0].typ}.${fn.name}' - } - return fn.mix_name -} diff --git a/lib/bait/ast/table.bt b/lib/bait/ast/table.bt index d478a447..eade2aa1 100644 --- a/lib/bait/ast/table.bt +++ b/lib/bait/ast/table.bt @@ -3,7 +3,6 @@ package ast pub struct Table { - pub mut fun_decls map[string]FunDecl pub mut type_idxs map[string]Type pub mut type_symbols []TypeSymbol pub mut needed_equality_funs []Type diff --git a/lib/bait/checker/fun.bt b/lib/bait/checker/fun.bt index ea24c938..132f3da4 100644 --- a/lib/bait/checker/fun.bt +++ b/lib/bait/checker/fun.bt @@ -104,10 +104,6 @@ fun (c Checker) fun_params(params []ast.Param){ if sym.kind == .fun_ { info := sym.info as ast.FunInfo - c.table.fun_decls[p.name] = ast.FunDecl{ - return_type = info.return_type - params = info.to_params() - } c.scope.register(p.name, context.ScopeObject{ typ = p.typ kind = .function @@ -158,7 +154,6 @@ fun (mut c Checker) fun_call(mut node ast.CallExpr) ast.Type { c.error("function `${node.full_name()}` is private", node.pos) } - mut def := c.table.fun_decls[node.full_name()] node.noreturn = obj.noreturn node.return_type = obj.return_type @@ -181,7 +176,7 @@ fun (mut c Checker) fun_call(mut node ast.CallExpr) ast.Type { c.or_block(mut node) - c.set_conc_types(mut node, obj.generic_names, def.key()) + c.set_conc_types(mut node, obj.generic_names, obj.key) if node.name == 'error' { node.return_type = c.cur_fun.return_type @@ -331,7 +326,7 @@ fun (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { c.or_block(mut node) - c.set_conc_types(mut node, def.generic_names, def.key()) + c.set_conc_types(mut node, def.generic_names, def.key) return node.return_type } @@ -458,7 +453,7 @@ fun (mut c Checker) or_block(mut node ast.CallExpr) { fun (mut c Checker) resolve_generics_funs() { for mut fn in c.file.generic_funs { - gtypes := c.table.generic_fun_types[fn.key()] + gtypes := c.table.generic_fun_types[fn.key] for concrete in gtypes { c.cur_concrete_types = concrete c.fun_instance(mut fn) diff --git a/lib/bait/context/scope.bt b/lib/bait/context/scope.bt index 8bbb73a3..a8d7c91d 100644 --- a/lib/bait/context/scope.bt +++ b/lib/bait/context/scope.bt @@ -24,6 +24,7 @@ pub struct ScopeObject{ pub params []ast.Param pub attrs []ast.Attribute pub generic_names []string + pub key string } pub enum ObjectKind { diff --git a/lib/bait/gen/c/fun.bt b/lib/bait/gen/c/fun.bt index d0f7d763..a7caf17d 100644 --- a/lib/bait/gen/c/fun.bt +++ b/lib/bait/gen/c/fun.bt @@ -22,7 +22,7 @@ fun (mut g Gen) anon_fun(node ast.AnonFun) { fun (mut g Gen) fun_decl(node ast.FunDecl) { if node.generic_names.length > 0 and g.cur_concrete_types.length == 0 { - gtypes := g.table.generic_fun_types[node.key()] + gtypes := g.table.generic_fun_types[node.key] for conc_types in gtypes { for i, gn in node.generic_names { g.cur_concrete_types[gn] = conc_types[i] diff --git a/lib/bait/gen/js/fun.bt b/lib/bait/gen/js/fun.bt index 408288ec..d5c1b0e1 100644 --- a/lib/bait/gen/js/fun.bt +++ b/lib/bait/gen/js/fun.bt @@ -6,7 +6,7 @@ import bait.ast fun (mut g Gen) fun_decl(node ast.FunDecl) { if node.generic_names.length > 0 and g.cur_concrete_types.length == 0 { - gtypes := g.table.generic_fun_types[node.key()] + gtypes := g.table.generic_fun_types[node.key] for conc_types in gtypes { for i, gn in node.generic_names { g.cur_concrete_types[gn] = conc_types[i] diff --git a/lib/bait/parser/fun.bt b/lib/bait/parser/fun.bt index 6ecc6ba8..ef16e56e 100644 --- a/lib/bait/parser/fun.bt +++ b/lib/bait/parser/fun.bt @@ -43,17 +43,19 @@ fun (mut p Parser) fun_decl() !ast.FunDecl{ ffi := p.parse_ffi_pkg()! lang = ffi.lang - mut mix_name := "" + mut key := "" if lang != .bait { - mix_name = ffi.pkg + "." // TMP + key = ffi.pkg + "." // TMP } // normal function name name := p.check_name()! - mix_name += name + key += name is_test := name.starts_with('test_') - if not is_method and lang == .bait { - mix_name = p.prepend_pkg(mix_name) + if is_method { + key = '${params[0].typ}.${name}' + } else if lang == .bait { + key = p.prepend_pkg(key) } // Generics @@ -73,7 +75,7 @@ fun (mut p Parser) fun_decl() !ast.FunDecl{ is_test = is_test is_pub = is_pub name = name - mix_name = mix_name + key = key generic_names = generic_names params = params return_type = return_type @@ -92,7 +94,6 @@ fun (mut p Parser) fun_decl() !ast.FunDecl{ } sym.methods.push(node) } else { - p.table.fun_decls[mix_name] = node mut param_types := []ast.Type for param in params { param_types.push(param.typ) @@ -110,6 +111,7 @@ fun (mut p Parser) fun_decl() !ast.FunDecl{ params = params attrs = p.attributes generic_names = generic_names + key = key }) } else { ffi_scope := p.sema_ctx.obtain_root_scope(ffi.pkg) @@ -118,6 +120,7 @@ fun (mut p Parser) fun_decl() !ast.FunDecl{ is_pub = true return_type = return_type params = params + key = key }) } } diff --git a/lib/bait/parser/stmt.bt b/lib/bait/parser/stmt.bt index 904721af..b06fe0c7 100644 --- a/lib/bait/parser/stmt.bt +++ b/lib/bait/parser/stmt.bt @@ -59,7 +59,6 @@ fun (mut p Parser) script_mode_main() !ast.FunDecl { name = "main" return_type = ast.VOID_TYPE } - p.table.fun_decls['main'] = node node.stmts = stmts return node }