diff --git a/compiler/ast/Scope.v b/compiler/ast/Scope.v index 5907680e..27854c65 100644 --- a/compiler/ast/Scope.v +++ b/compiler/ast/Scope.v @@ -31,7 +31,7 @@ pub fn (sc &Scope) derive() &Scope { } } -pub fn (mut sc Scope) add_symbol(sym Symbol) ! { +pub fn (mut sc Scope) add_symbol_with_lookup(sym Symbol) ! { if other := sc.lookup(sym.name) { m := if other is Variable && other.is_arg { '${sym.type_of()} `${sym.name}` has the same name as an argument' @@ -45,7 +45,7 @@ pub fn (mut sc Scope) add_symbol(sym Symbol) ! { sc.syms << sym } -pub fn (mut sc Scope) add_local_symbol(sym Symbol) ! { +pub fn (mut sc Scope) add_symbol(sym Symbol) ! { if other := sc.find(sym.name) { m := if other.type_of() == sym.type_of() { 'duplicate ${sym.type_of()} `${sym.name}`' diff --git a/compiler/context/mod.v b/compiler/context/mod.v index 55491f9d..899ae159 100644 --- a/compiler/context/mod.v +++ b/compiler/context/mod.v @@ -72,62 +72,62 @@ pub fn (mut ctx CContext) load_builtin_symbols() { } pub fn (mut ctx CContext) load_universe() { - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'i8' kind: .i8 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'i16' kind: .i16 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'i32' kind: .i32 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'i64' kind: .i64 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'int' kind: .int }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'u8' kind: .u8 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'u16' kind: .u16 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'u32' kind: .u32 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'u64' kind: .u64 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'uint' kind: .uint }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'f32' kind: .f32 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'f64' kind: .f64 }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'bool' kind: .bool }) or { ic_error(err.msg()) } - ctx.universe.add_local_symbol(ast.TypeSym{ + ctx.universe.add_symbol(ast.TypeSym{ name: 'rune' kind: .rune }) or { ic_error(err.msg()) } diff --git a/compiler/sema/mod.v b/compiler/sema/mod.v index 8a81ea56..14fcb96c 100644 --- a/compiler/sema/mod.v +++ b/compiler/sema/mod.v @@ -35,7 +35,7 @@ fn (mut sema Sema) check_file(mut file ast.File) { kind: .struct } - sema.ctx.universe.add_local_symbol(sema.sym) or { + sema.ctx.universe.add_symbol(sema.sym) or { context.ic_error('cannot load module `${file.mod_name}`, there is another symbol with the same name') } @@ -104,11 +104,11 @@ fn (mut sema Sema) fn_stmt(mut stmt ast.FnStmt) { node: unsafe { stmt } } sema.sym = stmt.sym - stmt.scope = ast.Scope.new(sema.scope, ?ast.Symbol(stmt.sym)) - sema.scope.add_local_symbol(stmt.sym) or { context.error(err.msg(), stmt.name_pos) } + stmt.scope = ast.Scope.new(sema.scope, ?ast.Symbol(sema.sym)) + sema.scope.add_symbol(stmt.sym) or { context.error(err.msg(), stmt.name_pos) } sema.scope = stmt.scope for arg in stmt.args { - sema.scope.add_local_symbol(ast.Variable{ + sema.scope.add_symbol(ast.Variable{ name: arg.name is_local: true is_arg: true @@ -147,12 +147,12 @@ fn (mut sema Sema) let_stmt(mut stmt ast.LetStmt) { for var in stmt.lefts { if var.is_local { // local variables - sema.scope.add_symbol(var) or { + sema.scope.add_symbol_with_lookup(var) or { context.error(err.msg(), var.pos, context.note('inside ${sema.sym.type_of()} `${sema.sym.name}`')) } } else { // variables declared at module scope - sema.scope.add_local_symbol(var) or { + sema.scope.add_symbol(var) or { context.error(err.msg(), var.pos, context.note('inside ${sema.sym.type_of()} `${sema.sym.name}`')) } }