Skip to content

Commit

Permalink
gen: remove mix_name usage
Browse files Browse the repository at this point in the history
  • Loading branch information
serkonda7 committed Jan 22, 2025
1 parent dd929c7 commit b7d997e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/bait/ast/ast.bt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub struct BoolLiteral {

pub struct CallExpr {
global lang Language
pub pkg string
global pkg string
global name string
global mix_name string // TMP
global return_type Type
Expand Down
5 changes: 5 additions & 0 deletions lib/bait/checker/fun.bt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ fun (mut c Checker) fun_call(mut node ast.CallExpr) ast.Type {
}
}

// Set package
if node.pkg.length == 0 and obj.pkg != "main" and obj.pkg != "builtin" {
node.pkg = obj.pkg
}

// Check visibility
if not obj.is_pub and obj.pkg != c.pkg {
c.error("function `${node.full_name()}` is private", node.pos)
Expand Down
2 changes: 1 addition & 1 deletion lib/bait/gen/c/comptime.bt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fun (mut g Gen) get_comptime_val(kind token.ComptimeVar, pos token.Pos) string {
line := g.get_comptime_val(.line, pos)
'${file}:${line}'
}
.fun_ { g.cur_fun.mix_name }
.fun_ { g.cur_fun.name }

// Cached
.baitexe { g.comptime_baitexe() }
Expand Down
4 changes: 2 additions & 2 deletions lib/bait/gen/c/expr.bt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fun (mut g Gen) infix_expr(node ast.InfixExpr) {
if node.op == .ne {
g.write('!')
}
g.write(c_esc(lsym.name + '_' + overload.mix_name))
g.write(c_esc(lsym.name + '_' + overload.name))
g.write('(')
g.expr(node.left)
g.write(', ')
Expand Down Expand Up @@ -293,7 +293,7 @@ fun (mut g Gen) expr_to_string(expr ast.Expr, typ ast.Type) {
}

str_def := g.table.get_method(sym, 'str')
if str_def.mix_name.length > 0 {
if str_def.name.length > 0 {
final_sym := g.table.get_sym(str_def.params[0].typ)
mut name := c_esc(final_sym.name)
g.write('${name}_str(')
Expand Down
16 changes: 8 additions & 8 deletions lib/bait/gen/c/fun.bt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fun (mut g Gen) anon_fun(node ast.AnonFun) {
g.indent = last_indent
g.empty_line = was_line_empty

g.write(node.decl.mix_name)
g.write(node.decl.name)
}

fun (mut g Gen) fun_decl(node ast.FunDecl) {
Expand All @@ -37,10 +37,10 @@ fun (mut g Gen) fun_decl(node ast.FunDecl) {
g.cur_fun = node

type_str := g.typ(node.return_type)
mut name := c_esc(node.mix_name)
mut name := c_esc(node.name)
if node.is_method {
sym := g.table.get_sym(node.params[0].typ)
name = c_esc(sym.name + '_' + node.mix_name)
name = c_name(sym.name + '_' + node.name)
}
if g.cur_concrete_types.length > 0 {
name = g.get_concrete_name(name, g.cur_concrete_types.values())
Expand Down Expand Up @@ -77,14 +77,14 @@ fun (mut g Gen) call_expr(node ast.CallExpr) {
} else {
g.write('.')
}
g.write(node.mix_name)
g.write(node.name)
g.write('(')
g.call_args(node.args)
g.write(')')
return
}

mut name := c_esc(node.mix_name)
mut name := c_esc(node.full_name())
if node.is_method {
sym := g.table.get_sym(node.left_type)
final_sym := g.table.get_final_sym(sym)
Expand All @@ -103,9 +103,9 @@ fun (mut g Gen) call_expr(node ast.CallExpr) {
}
}

name = c_esc(sym.name + '_' + node.mix_name)
name = c_name(sym.name + '_' + node.name)
} else if node.lang != .bait{
name = node.mix_name.replace('C.', '')
name = node.name.replace('C.', '')
}

if node.concrete_types.length > 0 {
Expand All @@ -114,7 +114,7 @@ fun (mut g Gen) call_expr(node ast.CallExpr) {

g.write(name)

if not node.is_method and ['println', 'eprintln', 'print', 'eprint'].contains(node.mix_name) {
if not node.is_method and ['println', 'eprintln', 'print', 'eprint'].contains(node.name) {
g.write('(')
g.expr_to_string(node.args[0].expr, node.args[0].typ)
g.write(')')
Expand Down
2 changes: 1 addition & 1 deletion lib/bait/gen/c/stmt.bt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun (mut g Gen) assign_stmt(node ast.AssignStmt) {
if lsym.overloads.contains(node.op.c_repr()) {
g.write(' = ')
overload := lsym.overloads[node.op.c_repr()]
g.write(c_esc(lsym.name + '_' + overload.mix_name))
g.write(c_esc(lsym.name + '_' + overload.name))
g.write('(')
g.expr(node.left)
g.write(', ')
Expand Down
8 changes: 4 additions & 4 deletions lib/bait/gen/js/fun.bt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fun (mut g Gen) fun_decl(node ast.FunDecl) {

export_attr := node.attrs.find_attr('export')
if export_attr.name != '' {
g.writeln('module.exports.${export_attr.value} = ${js_esc(node.mix_name)}')
g.writeln('module.exports.${export_attr.value} = ${name}')
}

g.writeln('')
Expand Down Expand Up @@ -113,7 +113,7 @@ fun (mut g Gen) call_expr_no_or(node ast.CallExpr) {
return
}

mut name := node.mix_name
mut name := node.full_name()
if node.is_method {
if name == 'str' {
g.expr_to_string(node.left, node.left_type)
Expand All @@ -127,9 +127,9 @@ fun (mut g Gen) call_expr_no_or(node ast.CallExpr) {
return
}

name = js_esc(sym.name + '_' + node.name)
name = js_name(sym.name + '_' + node.name)
} else if node.lang == .bait{
name = js_esc(node.mix_name)
name = js_esc(name)
}

if node.concrete_types.length > 0 {
Expand Down

0 comments on commit b7d997e

Please sign in to comment.