From 917776617580a05c651058595fdbaf84a66b2c84 Mon Sep 17 00:00:00 2001 From: Lukas Neubert <40118727+serkonda7@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:51:30 +0100 Subject: [PATCH] TypeSymbol: name --> mix_name --- lib/bait/ast/ast.bt | 4 ++-- lib/bait/ast/table.bt | 18 +++++++++--------- lib/bait/ast/types.bt | 23 ++++++++++++----------- lib/bait/checker/assign.bt | 2 +- lib/bait/checker/attribute.bt | 2 +- lib/bait/checker/expr.bt | 18 +++++++++--------- lib/bait/checker/fun.bt | 6 +++--- lib/bait/checker/stmt.bt | 2 +- lib/bait/checker/struct.bt | 8 ++++---- lib/bait/checker/type.bt | 8 ++++---- lib/bait/gen/c/auto_str.bt | 10 +++++----- lib/bait/gen/c/cgen.bt | 2 +- lib/bait/gen/c/eq_funs.bt | 2 +- lib/bait/gen/c/expr.bt | 8 ++++---- lib/bait/gen/c/fun.bt | 4 ++-- lib/bait/gen/c/stmt.bt | 2 +- lib/bait/gen/c/type.bt | 8 ++++---- lib/bait/gen/js/auto_str.bt | 14 +++++++------- lib/bait/gen/js/expr.bt | 10 +++++----- lib/bait/gen/js/fun.bt | 4 ++-- lib/bait/gen/js/jsgen.bt | 6 +++--- lib/bait/gen/js/stmt.bt | 2 +- lib/bait/parser/fun.bt | 2 +- lib/bait/parser/stmt.bt | 10 +++++----- lib/bait/parser/struct.bt | 2 +- lib/bait/parser/type.bt | 6 +++--- 26 files changed, 92 insertions(+), 91 deletions(-) diff --git a/lib/bait/ast/ast.bt b/lib/bait/ast/ast.bt index aea59814..193c3bb3 100644 --- a/lib/bait/ast/ast.bt +++ b/lib/bait/ast/ast.bt @@ -397,8 +397,8 @@ pub struct InvalidStmt { } pub struct Import { - pub name string // Full import name - pub alias string // Custom alias or the part after the last dot + pub name string // Full name, e.g. `crypto.sha1` + pub alias string // Last name part or custom alias, e.g. `sha1` pub lang Language pub pos token.Pos } diff --git a/lib/bait/ast/table.bt b/lib/bait/ast/table.bt index 02b8f60c..657ebcc7 100644 --- a/lib/bait/ast/table.bt +++ b/lib/bait/ast/table.bt @@ -66,11 +66,11 @@ pub fun (mut t Table) register_concrete(key string, concrete []Type) bool { pub fun (t Table) type_name(typ Type) string { amps := '&'.repeat(typ.get_nr_amp()) - return amps + t.get_sym(typ).name + return amps + t.get_sym(typ).mix_name } pub fun (t Table) register_sym(sym TypeSymbol) Type { - idx := t.get_idx(sym.name) + idx := t.get_idx(sym.mix_name) if idx > 0 as Type { cur_sym := t.get_sym(idx) if cur_sym.kind == .placeholder { @@ -96,13 +96,13 @@ pub fun (t Table) register_sym(sym TypeSymbol) Type { new_idx := t.type_symbols.length as Type t.type_symbols.push(sym) - t.type_idxs[sym.name] = new_idx + t.type_idxs[sym.mix_name] = new_idx return new_idx } pub fun (t Table) find_or_register_array(elem_type Type) Type { elem_sym := t.get_sym(elem_type) - name := '[]' + elem_sym.name + name := '[]' + elem_sym.mix_name idx := t.get_idx(name) if idx > 0 as Type { return idx @@ -110,7 +110,7 @@ pub fun (t Table) find_or_register_array(elem_type Type) Type { return t.register_sym(TypeSymbol{ kind = .array - name = name + mix_name = name pkg = elem_sym.pkg parent = ARRAY_TYPE info = ArrayInfo{ @@ -122,14 +122,14 @@ pub fun (t Table) find_or_register_array(elem_type Type) Type { pub fun (t Table) find_or_register_map(key_type Type, val_type Type) Type { key_sym := t.get_sym(key_type) val_sym := t.get_sym(val_type) - name := 'map[${key_sym.name}]${val_sym.name}' + name := 'map[${key_sym.mix_name}]${val_sym.mix_name}' idx := t.get_idx(name) if idx > 0 as Type { return idx } return t.register_sym(TypeSymbol{ kind = .map - name = name + mix_name = name parent = MAP_TYPE info = MapInfo{ key_type = key_type @@ -148,7 +148,7 @@ pub fun (t Table) find_or_register_fun(param_types []Type, return_type Type, ali return t.register_sym(TypeSymbol{ kind = .fun_ - name = name + mix_name = name info = FunInfo{ is_alias = alias param_types = param_types @@ -166,7 +166,7 @@ pub fun (t Table) find_type_or_add_placeholder(name string, pkg string) Type { return t.register_sym(TypeSymbol{ kind = .placeholder - name = name + mix_name = name pkg = pkg }) } diff --git a/lib/bait/ast/types.bt b/lib/bait/ast/types.bt index c8c90e0f..e6cb5624 100644 --- a/lib/bait/ast/types.bt +++ b/lib/bait/ast/types.bt @@ -70,6 +70,7 @@ pub enum TypeKind { pub struct TypeSymbol{ pub mut name string + pub mut mix_name string // TMP pub mut kind TypeKind pub mut methods []FunDecl pub mut parent Type @@ -113,9 +114,9 @@ pub fun (sym TypeSymbol) has_method(name string) bool { pub fun (t Table) register_builtins(){ // IMPORTANT: Order of registration must match the order of the constants above - _ = t.register_sym(TypeSymbol{ name = '_' }) // PLACEHOLDER_TYPE - _ = t.register_sym(TypeSymbol{ name = '_err' }) // ERROR_TYPE - _ = t.register_sym(TypeSymbol{ name = 'void' }) + _ = t.register_sym(TypeSymbol{ mix_name = '_' }) // PLACEHOLDER_TYPE + _ = t.register_sym(TypeSymbol{ mix_name = '_err' }) // ERROR_TYPE + _ = t.register_sym(TypeSymbol{ mix_name = 'void' }) _ = t.register_num('i8') _ = t.register_num('i16') _ = t.register_num('i32') @@ -124,27 +125,27 @@ pub fun (t Table) register_builtins(){ _ = t.register_num('u16') _ = t.register_num('u32') _ = t.register_num('u64') - _ = t.register_sym(TypeSymbol{ name = 'f32' }) - _ = t.register_sym(TypeSymbol{ name = 'f64' }) - _ = t.register_sym(TypeSymbol{ name = 'bool' }) + _ = t.register_sym(TypeSymbol{ mix_name = 'f32' }) + _ = t.register_sym(TypeSymbol{ mix_name = 'f64' }) + _ = t.register_sym(TypeSymbol{ mix_name = 'bool' }) _ = t.register_sym(TypeSymbol{ - name = 'string' + mix_name = 'string' kind = .string }) _ = t.register_sym(TypeSymbol{ - name = 'Array' + mix_name = 'Array' kind = .array }) _ = t.register_sym(TypeSymbol{ - name = 'Map' + mix_name = 'Map' kind = .map }) - _ = t.register_sym(TypeSymbol{ name = 'any'}) + _ = t.register_sym(TypeSymbol{ mix_name = 'any'}) } pub fun (t Table) register_num(name string) { _ = t.register_sym(TypeSymbol{ - name = name + mix_name = name kind = .number is_pub = true }) diff --git a/lib/bait/checker/assign.bt b/lib/bait/checker/assign.bt index 6393786a..5b5f60fb 100644 --- a/lib/bait/checker/assign.bt +++ b/lib/bait/checker/assign.bt @@ -114,7 +114,7 @@ fun (c Checker) is_field_mutable(left ast.SelectorExpr) bool { sym := c.table.get_sym(left.expr_type) field := sym.find_field(left.field_name, c.table) if (not field.is_mut or sym.pkg != c.pkg) and not field.is_global { - c.error('field `${sym.name}.${left.field_name}` is immutable', left.pos) + c.error('field `${sym.mix_name}.${left.field_name}` is immutable', left.pos) return false } return true diff --git a/lib/bait/checker/attribute.bt b/lib/bait/checker/attribute.bt index 1be92f78..112b13be 100644 --- a/lib/bait/checker/attribute.bt +++ b/lib/bait/checker/attribute.bt @@ -79,7 +79,7 @@ fun (c Checker) attr_overload(node ast.FunDecl, attr ast.Attribute) { rec_sym := c.table.get_sym(node.params[0].typ) if rec_sym.overloads.contains(attr.value) { // TODO print positions of all overloads - c.error('"${attr.value}" was overloaded twice for type "${rec_sym.name}"', attr.pos) + c.error('"${attr.value}" was overloaded twice for type "${rec_sym.mix_name}"', attr.pos) return } diff --git a/lib/bait/checker/expr.bt b/lib/bait/checker/expr.bt index f4ec8a42..84135b22 100644 --- a/lib/bait/checker/expr.bt +++ b/lib/bait/checker/expr.bt @@ -154,19 +154,19 @@ fun (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type { return ast.ERROR_TYPE } if sym.kind != .enum_ { - c.error('expected type is not an enum, got ${sym.name}', node.pos) + c.error('expected type is not an enum, got ${sym.mix_name}', node.pos) return ast.ERROR_TYPE } - if not sym.is_pub and sym.name.contains('.') and sym.pkg != c.pkg { - c.error('enum ${sym.name} is private', node.pos) + if not sym.is_pub and sym.mix_name.contains('.') and sym.pkg != c.pkg { + c.error('enum ${sym.mix_name} is private', node.pos) return ast.ERROR_TYPE } info := sym.info as ast.EnumInfo if not info.vals.contains(node.val) { - c.error('enum ${sym.name} has no value ${node.val}', node.pos) + c.error('enum ${sym.mix_name} has no value ${node.val}', node.pos) return ast.ERROR_TYPE } - node.name = sym.name + node.name = sym.mix_name return node.typ } @@ -312,19 +312,19 @@ fun (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { if [ast.TypeKind.struct_, .interface_, .array, .string, .map].contains(sym.kind) { field := sym.find_field(node.field_name, c.table) if field.name.length == 0 { - c.error('${sym.name} has no field ${node.field_name}', node.pos) + c.error('${sym.mix_name} has no field ${node.field_name}', node.pos) return ast.ERROR_TYPE } if not field.is_pub and sym.pkg != c.pkg { - c.error('field ${sym.name}.${node.field_name} is private', node.pos) + c.error('field ${sym.mix_name}.${node.field_name} is private', node.pos) } fsym := c.table.get_sym(field.typ) if fsym.kind == .generic { gen_info := gen_sym.info as ast.GenericInst info := sym.info as ast.StructInfo - return gen_info.concrete_types[info.generic_names.index(fsym.name)] + return gen_info.concrete_types[info.generic_names.index(fsym.mix_name)] } return field.typ @@ -332,7 +332,7 @@ fun (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { if sym.kind == .sum_type { // TODO check if field is present on all variants (with same type) - c.error('cast to the variant before accessing field of sumtype ${sym.name}', node.pos) + c.error('cast to the variant before accessing field of sumtype ${sym.mix_name}', node.pos) return ast.VOID_TYPE } diff --git a/lib/bait/checker/fun.bt b/lib/bait/checker/fun.bt index 41279632..18964c96 100644 --- a/lib/bait/checker/fun.bt +++ b/lib/bait/checker/fun.bt @@ -229,7 +229,7 @@ fun (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { return node.return_type } - c.error('method ${node.mix_name} not found on type ${left_sym.name}', node.pos) + c.error('method ${node.mix_name} not found on type ${left_sym.mix_name}', node.pos) return ast.ERROR_TYPE } @@ -334,7 +334,7 @@ fun (mut c Checker) set_conc_types(mut node ast.CallExpr, mut def ast.FunDecl) { ret_sym := c.table.get_sym(node.return_type) if ret_sym.kind == .generic { - idx := def.generic_names.index(ret_sym.name) + idx := def.generic_names.index(ret_sym.mix_name) node.return_type = node.concrete_types[idx] } } @@ -349,7 +349,7 @@ fun (mut c Checker) call_args(def ast.FunDecl, mut node ast.CallExpr, poffset i3 psym := c.table.get_sym(param_type) if should_resolve_generics and psym.kind == .generic { - gi := def.generic_names.index(psym.name) + gi := def.generic_names.index(psym.mix_name) if gi < node.concrete_types.length { param_type = node.concrete_types[gi] } else if gi < c.cur_concrete_types.length { diff --git a/lib/bait/checker/stmt.bt b/lib/bait/checker/stmt.bt index 83487fbe..51ac7120 100644 --- a/lib/bait/checker/stmt.bt +++ b/lib/bait/checker/stmt.bt @@ -183,7 +183,7 @@ fun (mut c Checker) for_in_loop(mut node ast.ForInLoop) { } else if sym.kind == .string { node.val_type = ast.U8_TYPE } else { - c.error('cannot iterate over ${sym.name}', node.pos) + c.error('cannot iterate over ${sym.mix_name}', node.pos) } if node.idxvar is ast.Ident { diff --git a/lib/bait/checker/struct.bt b/lib/bait/checker/struct.bt index 3630f1e5..2ad9d30a 100644 --- a/lib/bait/checker/struct.bt +++ b/lib/bait/checker/struct.bt @@ -55,19 +55,19 @@ fun (mut c Checker) struct_init(mut node ast.StructInit) ast.Type { c.error('undefined struct ${node.name}', node.pos) return ast.ERROR_TYPE } - if not sym.is_pub and sym.name.contains('.') and sym.pkg != c.pkg { - c.error('struct ${sym.name} is private', node.pos) + if not sym.is_pub and sym.mix_name.contains('.') and sym.pkg != c.pkg { + c.error('struct ${sym.mix_name} is private', node.pos) return ast.ERROR_TYPE } c.check_init_field_values(node, sym.info as ast.StructInfo) - node.name = sym.name + node.name = sym.mix_name for field in node.fields { def := sym.find_field(field.name, c.table) if def.name.length == 0 { - c.error('struct ${sym.name} has no field ${field.name}', node.pos) + c.error('struct ${sym.mix_name} has no field ${field.name}', node.pos) // Stay in the loop to also check the field expression } diff --git a/lib/bait/checker/type.bt b/lib/bait/checker/type.bt index d3925ed7..29ccbf18 100644 --- a/lib/bait/checker/type.bt +++ b/lib/bait/checker/type.bt @@ -44,7 +44,7 @@ fun (c Checker) check_types(got ast.Type, expected ast.Type) bool { } if exp_sym.kind == .array and got_sym.kind == .array { - if exp_sym.name == 'Array' or got_sym.name == 'Array' { + if exp_sym.mix_name == 'Array' or got_sym.mix_name == 'Array' { return true } got_info := got_sym.info as ast.ArrayInfo @@ -81,8 +81,8 @@ fun (c Checker) check_types(got ast.Type, expected ast.Type) bool { } fun (c Checker) does_type_exist(sym ast.TypeSymbol, pos token.Pos) bool { - if (sym.kind == .placeholder and sym.name != '_') or (sym.kind == .generic and not (c.cur_generic_names.contains(sym.name))) { - c.error('unknown type ${sym.name}', pos) + if (sym.kind == .placeholder and sym.mix_name != '_') or (sym.kind == .generic and not (c.cur_generic_names.contains(sym.mix_name))) { + c.error('unknown type ${sym.mix_name}', pos) return false } @@ -134,6 +134,6 @@ fun (c Checker) does_type_exist(sym ast.TypeSymbol, pos token.Pos) bool { return true } - c.error('type ${sym.name} is private', pos) + c.error('type ${sym.mix_name} is private', pos) return false } diff --git a/lib/bait/gen/c/auto_str.bt b/lib/bait/gen/c/auto_str.bt index aeb2d6fe..a6b78ce1 100644 --- a/lib/bait/gen/c/auto_str.bt +++ b/lib/bait/gen/c/auto_str.bt @@ -11,7 +11,7 @@ const LB := if os.platform() == 'windows' { '\\r\\n' } else { '\\n' } fun (mut g Gen) get_str_fun(typ ast.Type) string { g.table.needed_str_funs.push(typ) sym := g.table.get_sym(typ) - return c_esc('${sym.name}_str') + return c_esc('${sym.mix_name}_str') } // TODO transformer? @@ -27,7 +27,7 @@ fun (mut g Gen) generate_str_fun(typ ast.Type) { g.generated_str_funs.push(typ) - sname := c_esc(sym.name) + sname := c_esc(sym.mix_name) fname := sname + '_str' if sym.kind == .struct_ { @@ -40,14 +40,14 @@ fun (mut g Gen) generate_str_fun(typ ast.Type) { string space = string_repeat(from_c_string(" "), indent * 2); strings__Builder b = strings__new_builder(100); strings__Builder_write(&b, space); - strings__Builder_write(&b, from_c_string("${sym.name}{"));\n' + strings__Builder_write(&b, from_c_string("${sym.mix_name}{"));\n' if info.fields.length > 0 { g.auto_funs_out += '\tstrings__Builder_write(&b, from_c_string("${LB}"));\n' } for field in info.fields { if typ == field.typ { g.auto_funs_out += '\tstrings__Builder_write(&b, space); - strings__Builder_write(&b, from_c_string(" ${field.name} = ${sym.name}{...}${LB}"));\n' + strings__Builder_write(&b, from_c_string(" ${field.name} = ${sym.mix_name}{...}${LB}"));\n' continue } @@ -69,6 +69,6 @@ fun (mut g Gen) generate_str_fun(typ ast.Type) { // TODO other types - errors.generic_error('cannot convert ${sym.name} to string') + errors.generic_error('cannot convert ${sym.mix_name} to string') exit(1) } diff --git a/lib/bait/gen/c/cgen.bt b/lib/bait/gen/c/cgen.bt index 3dd2f35c..a871b23a 100644 --- a/lib/bait/gen/c/cgen.bt +++ b/lib/bait/gen/c/cgen.bt @@ -140,7 +140,7 @@ fun (mut g Gen) c_main() { fun (g Gen) get_concrete_name(name string, concrete_types []ast.Type) string { mut full_name := name for t in concrete_types { - full_name += '_' + g.table.get_sym(t).name + full_name += '_' + g.table.get_sym(t).mix_name } return c_esc(full_name) } diff --git a/lib/bait/gen/c/eq_funs.bt b/lib/bait/gen/c/eq_funs.bt index 9ab8d9eb..891fc512 100644 --- a/lib/bait/gen/c/eq_funs.bt +++ b/lib/bait/gen/c/eq_funs.bt @@ -33,6 +33,6 @@ fun (g Gen) equality_fun(typ ast.Type) string { return '' } - errors.generic_error('cannot generate equality function for type ${sym.name}') + errors.generic_error('cannot generate equality function for type ${sym.mix_name}') exit(1) } diff --git a/lib/bait/gen/c/expr.bt b/lib/bait/gen/c/expr.bt index 4d45dbc1..fadaa0e4 100644 --- a/lib/bait/gen/c/expr.bt +++ b/lib/bait/gen/c/expr.bt @@ -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.mix_name + '_' + overload.mix_name)) g.write('(') g.expr(node.left) g.write(', ') @@ -282,7 +282,7 @@ fun (mut g Gen) struct_init(node ast.StructInit) { fun (mut g Gen) type_of(node ast.TypeOf){ sym := g.concrete_sym(node.typ) amp := '*'.repeat(node.typ.get_nr_amp()) - g.write('from_c_string("' + amp + sym.name + '")') + g.write('from_c_string("' + amp + sym.mix_name + '")') } fun (mut g Gen) expr_to_string(expr ast.Expr, typ ast.Type) { @@ -295,7 +295,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 { final_sym := g.table.get_sym(str_def.params[0].typ) - mut name := c_esc(final_sym.name) + mut name := c_esc(final_sym.mix_name) g.write('${name}_str(') g.expr(expr) g.write(')') @@ -303,7 +303,7 @@ fun (mut g Gen) expr_to_string(expr ast.Expr, typ ast.Type) { } if sym.kind == .generic { - g.expr_to_string(expr, g.cur_concrete_types[sym.name]) + g.expr_to_string(expr, g.cur_concrete_types[sym.mix_name]) return } diff --git a/lib/bait/gen/c/fun.bt b/lib/bait/gen/c/fun.bt index b6b7dc72..ceb75e3d 100644 --- a/lib/bait/gen/c/fun.bt +++ b/lib/bait/gen/c/fun.bt @@ -46,7 +46,7 @@ fun (mut g Gen) fun_decl(node ast.FunDecl) { mut name := c_esc(node.mix_name) if node.is_method { sym := g.table.get_sym(node.params[0].typ) - name = c_esc(sym.name + '_' + node.mix_name) + name = c_esc(sym.mix_name + '_' + node.mix_name) } if g.cur_concrete_types.length > 0 { name = g.get_concrete_name(name, g.cur_concrete_types.values()) @@ -109,7 +109,7 @@ fun (mut g Gen) call_expr(node ast.CallExpr) { } } - name = c_esc(sym.name + '_' + node.mix_name) + name = c_esc(sym.mix_name + '_' + node.mix_name) } else if node.lang != .bait{ name = node.mix_name.replace('C.', '') } diff --git a/lib/bait/gen/c/stmt.bt b/lib/bait/gen/c/stmt.bt index 551c4bee..e2348184 100644 --- a/lib/bait/gen/c/stmt.bt +++ b/lib/bait/gen/c/stmt.bt @@ -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.mix_name + '_' + overload.mix_name)) g.write('(') g.expr(node.left) g.write(', ') diff --git a/lib/bait/gen/c/type.bt b/lib/bait/gen/c/type.bt index 297c0b93..4cef5259 100644 --- a/lib/bait/gen/c/type.bt +++ b/lib/bait/gen/c/type.bt @@ -10,13 +10,13 @@ fun (g Gen) concrete_sym(typ ast.Type) ast.TypeSymbol { return sym } - return g.table.get_sym(g.cur_concrete_types[sym.name]) + return g.table.get_sym(g.cur_concrete_types[sym.mix_name]) } fun (g Gen) typ(typ ast.Type) string { sym := g.concrete_sym(typ) - name := sym.name.replace('[]', 'Array_').replace('C.', '').replace('.', '__') + name := sym.mix_name.replace('[]', 'Array_').replace('C.', '').replace('.', '__') ptrs := '*'.repeat(typ.get_nr_amp()) prefix := if sym.kind == .enum_ { 'enum ' } else { '' } return prefix + name + ptrs @@ -24,11 +24,11 @@ fun (g Gen) typ(typ ast.Type) string { fun (mut g Gen) write_types() { for sym in g.table.type_symbols { - if sym.name.starts_with('C.') { + if sym.mix_name.starts_with('C.') { continue } - cname := c_esc(sym.name) + cname := c_esc(sym.mix_name) if sym.info is ast.StructInfo { info := sym.info as ast.StructInfo g.type_defs_out += 'typedef struct ${cname} ${cname};\n' diff --git a/lib/bait/gen/js/auto_str.bt b/lib/bait/gen/js/auto_str.bt index e887ca55..8b4b77cf 100644 --- a/lib/bait/gen/js/auto_str.bt +++ b/lib/bait/gen/js/auto_str.bt @@ -11,7 +11,7 @@ const LB := if os.platform() == 'windows' { '\\r\\n' } else { '\\n' } fun (mut g Gen) get_str_fun(typ ast.Type) string { g.table.needed_str_funs.push(typ) sym := g.table.get_sym(typ) - return js_esc('${sym.name}_str') + return js_esc('${sym.mix_name}_str') } fun (mut g Gen) generate_str_fun(typ ast.Type) { @@ -26,7 +26,7 @@ fun (mut g Gen) generate_str_fun(typ ast.Type) { g.generated_str_funs.push(typ) - name := js_esc('${sym.name}_str') + name := js_esc('${sym.mix_name}_str') if sym.kind == .array { info := sym.info as ast.ArrayInfo @@ -49,13 +49,13 @@ fun (mut g Gen) generate_str_fun(typ ast.Type) { info := sym.info as ast.StructInfo g.fun_decls_out += 'function ${name}(it, indent) { const space = " ".repeat(indent * 2) - let s = "${sym.name}{"\n' + let s = "${sym.mix_name}{"\n' if info.fields.length > 0 { g.fun_decls_out += '\ts += "${LB}"\n' } for field in info.fields { if typ == field.typ { - g.fun_decls_out += '\ts += space + " ${field.name} = ${sym.name}{...}${LB}"\n' + g.fun_decls_out += '\ts += space + " ${field.name} = ${sym.mix_name}{...}${LB}"\n' continue } @@ -103,7 +103,7 @@ fun (mut g Gen) generate_str_fun(typ ast.Type) { g.fun_decls_out += 'function ${name}(it, indent) {\n' for var in info.variants { var_sym := g.table.get_sym(var) - g.fun_decls_out += '\tif (it instanceof ${js_esc(var_sym.name)}) { + g.fun_decls_out += '\tif (it instanceof ${js_esc(var_sym.mix_name)}) { return ${g.get_str_fun(var)}(it, indent) } ' @@ -117,7 +117,7 @@ fun (mut g Gen) generate_str_fun(typ ast.Type) { switch(it) {\n' info := sym.info as ast.EnumInfo for val in info.vals { - g.fun_decls_out += '\t\tcase ${js_esc(sym.name)}.${val}: return from_js_string("${val}")\n' + g.fun_decls_out += '\t\tcase ${js_esc(sym.mix_name)}.${val}: return from_js_string("${val}")\n' } g.fun_decls_out += '\t}\n}\n\n' return @@ -131,6 +131,6 @@ fun (mut g Gen) generate_str_fun(typ ast.Type) { return } - errors.generic_error('cannot convert ${sym.name} to string') + errors.generic_error('cannot convert ${sym.mix_name} to string') exit(1) } diff --git a/lib/bait/gen/js/expr.bt b/lib/bait/gen/js/expr.bt index f380cd5f..008ea582 100644 --- a/lib/bait/gen/js/expr.bt +++ b/lib/bait/gen/js/expr.bt @@ -208,7 +208,7 @@ fun (mut g Gen) infix_expr(node ast.InfixExpr){ if node.op == .ne { g.write('!') } - g.write(js_esc(lsym.name + '_' + overload.mix_name)) + g.write(js_esc(lsym.mix_name + '_' + overload.mix_name)) g.write('(') g.expr(node.left) g.write(', ') @@ -232,7 +232,7 @@ fun (mut g Gen) infix_expr(node ast.InfixExpr){ // Normal cases if lsym.kind == .number { - g.write('${lsym.name}(') + g.write('${lsym.mix_name}(') } g.expr(node.left) g.write(' ') @@ -314,7 +314,7 @@ fun (mut g Gen) string_inter_literal(node ast.StringInterLiteral) { fun (mut g Gen) type_of(node ast.TypeOf) { sym := g.concrete_sym(node.typ) amp := '*'.repeat(node.typ.get_nr_amp()) - g.write('from_js_string("' + amp + sym.name + '")') + g.write('from_js_string("' + amp + sym.mix_name + '")') } fun (mut g Gen) expr_to_string(expr ast.Expr, typ ast.Type) { @@ -327,7 +327,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 { final_sym := g.table.get_sym(str_def.params[0].typ) - mut name := js_esc(final_sym.name) + mut name := js_esc(final_sym.mix_name) g.write('${name}_str(') g.expr(expr) g.write(')') @@ -335,7 +335,7 @@ fun (mut g Gen) expr_to_string(expr ast.Expr, typ ast.Type) { } if sym.kind == .generic { - g.expr_to_string(expr, g.cur_concrete_types[sym.name]) + g.expr_to_string(expr, g.cur_concrete_types[sym.mix_name]) return } diff --git a/lib/bait/gen/js/fun.bt b/lib/bait/gen/js/fun.bt index 380e8669..4d417ec1 100644 --- a/lib/bait/gen/js/fun.bt +++ b/lib/bait/gen/js/fun.bt @@ -30,7 +30,7 @@ fun (mut g Gen) fun_decl(node ast.FunDecl) { mut name := '' if node.is_method { sym := g.table.get_sym(node.params[0].typ) - name = js_esc(sym.name + '_' + node.mix_name) + name = js_esc(sym.mix_name + '_' + node.mix_name) } else { name = js_esc(node.mix_name) } @@ -128,7 +128,7 @@ fun (mut g Gen) call_expr_no_or(node ast.CallExpr) { return } - name = js_esc(sym.name + '_' + node.mix_name) + name = js_esc(sym.mix_name + '_' + node.mix_name) } else if node.lang == .bait{ name = js_esc(node.mix_name) } diff --git a/lib/bait/gen/js/jsgen.bt b/lib/bait/gen/js/jsgen.bt index aa2b133a..2179b3fe 100644 --- a/lib/bait/gen/js/jsgen.bt +++ b/lib/bait/gen/js/jsgen.bt @@ -245,7 +245,7 @@ fun (mut g Gen) write_default_value(typ ast.Type) { keys = []ast.Expr }) } else if sym.kind == .struct_ { - g.write('new ${js_esc(sym.name)}({})') + g.write('new ${js_esc(sym.mix_name)}({})') } else if sym.kind == .alias_type { g.write_default_value(sym.parent) } else if sym.kind == .enum_ { @@ -261,7 +261,7 @@ fun (mut g Gen) write_default_value(typ ast.Type) { fun (g Gen) get_concrete_name(name string, concrete_types []ast.Type) string { mut full_name := name for t in concrete_types { - full_name += '_' + g.table.get_sym(t).name + full_name += '_' + g.table.get_sym(t).mix_name } return js_esc(full_name) } @@ -272,7 +272,7 @@ fun (g Gen) concrete_sym(typ ast.Type) ast.TypeSymbol { return sym } - return g.table.get_sym(g.cur_concrete_types[sym.name]) + return g.table.get_sym(g.cur_concrete_types[sym.mix_name]) } // TODO evaluate where js_esc can be replaced by this (see also cgen) diff --git a/lib/bait/gen/js/stmt.bt b/lib/bait/gen/js/stmt.bt index d18b06db..65eaed2a 100644 --- a/lib/bait/gen/js/stmt.bt +++ b/lib/bait/gen/js/stmt.bt @@ -162,7 +162,7 @@ fun (mut g Gen) assign_stmt(node ast.AssignStmt){ if lsym.overloads.contains(node.op.js_repr()) { g.write(' = ') overload := lsym.overloads[node.op.js_repr()] - g.write(js_esc(lsym.name + '_' + overload.mix_name)) + g.write(js_esc(lsym.mix_name + '_' + overload.mix_name)) g.write('(') g.expr(node.left) g.write(', ') diff --git a/lib/bait/parser/fun.bt b/lib/bait/parser/fun.bt index ad4bd800..1f26a6e3 100644 --- a/lib/bait/parser/fun.bt +++ b/lib/bait/parser/fun.bt @@ -90,7 +90,7 @@ fun (mut p Parser) fun_decl() !ast.FunDecl{ sym := p.table.get_sym(params[0].typ) // TODO move this error into checker if lang == .bait and sym.has_method(mix_name) { - p.error('Method "${mix_name}" already exists on type "${sym.name}"')! + p.error('Method "${mix_name}" already exists on type "${sym.mix_name}"')! } sym.methods.push(node) } else { diff --git a/lib/bait/parser/stmt.bt b/lib/bait/parser/stmt.bt index 54bdc2c0..1b5062aa 100644 --- a/lib/bait/parser/stmt.bt +++ b/lib/bait/parser/stmt.bt @@ -237,7 +237,7 @@ fun (mut p Parser) enum_decl() !ast.EnumDecl{ p.check(.rcur)! typ := p.table.register_sym(ast.TypeSymbol{ - name = name + mix_name = name is_pub = is_pub pkg = p.pkg_name kind = .enum_ @@ -297,7 +297,7 @@ fun (mut p Parser) interface_decl() !ast.InterfaceDecl{ // TODO investigate why registration of the sym after loop with methods as struct field does not work mut tsym := ast.TypeSymbol{ kind = .interface_ - name = name + mix_name = name is_pub = is_pub pkg = p.pkg_name } @@ -417,7 +417,7 @@ fun (mut p Parser) type_decl() !ast.TypeDecl { sym := p.table.get_sym(variants[0]) typ := p.table.register_sym(ast.TypeSymbol{ kind = .fun_ - name = name + mix_name = name is_pub = is_pub pkg = p.pkg_name info = sym.info @@ -439,7 +439,7 @@ fun (mut p Parser) type_decl() !ast.TypeDecl { if p.tok != .pipe { typ := p.table.register_sym(ast.TypeSymbol{ kind = .alias_type - name = name + mix_name = name parent = variants[0] is_pub = is_pub pkg = p.pkg_name @@ -465,7 +465,7 @@ fun (mut p Parser) type_decl() !ast.TypeDecl { typ := p.table.register_sym(ast.TypeSymbol{ kind = .sum_type - name = name + mix_name = name is_pub = is_pub pkg = p.pkg_name info = ast.SumTypeInfo{ diff --git a/lib/bait/parser/struct.bt b/lib/bait/parser/struct.bt index dba93d91..966884c6 100644 --- a/lib/bait/parser/struct.bt +++ b/lib/bait/parser/struct.bt @@ -46,7 +46,7 @@ fun (mut p Parser) struct_decl() !ast.StructDecl{ tsym := ast.TypeSymbol{ kind = .struct_ - name = p.prepend_pkg(name) + mix_name = p.prepend_pkg(name) is_pub = is_pub pkg = p.pkg_name info = ast.StructInfo{ diff --git a/lib/bait/parser/type.bt b/lib/bait/parser/type.bt index 783df9e2..b904768b 100644 --- a/lib/bait/parser/type.bt +++ b/lib/bait/parser/type.bt @@ -12,7 +12,7 @@ fun (mut p Parser) parse_type() !ast.Type { if p.tok == .lcur { return p.table.register_sym(ast.TypeSymbol{ kind = .result - name = 'Result[void]' + mix_name = 'Result[void]' parent = ast.VOID_TYPE }) } @@ -21,7 +21,7 @@ fun (mut p Parser) parse_type() !ast.Type { tsym := p.table.get_sym(typ) return p.table.register_sym(ast.TypeSymbol{ kind = .result - name = 'Result[' + tsym.name + ']' + mix_name = 'Result[' + tsym.mix_name + ']' parent = typ }) } @@ -163,7 +163,7 @@ fun (mut p Parser) generic_type_names() ![]string { idx := p.table.get_idx(name) if idx == 0 { _ = p.table.register_sym(ast.TypeSymbol{ - name = name + mix_name = name kind = .generic is_pub = true })