Skip to content

Commit

Permalink
ast: rename Scope.add_symbol->Scope.add_symbol_with_lookup && Scope.a…
Browse files Browse the repository at this point in the history
…dd_local_symbol->Scope.add_symbol
  • Loading branch information
StunxFS committed Dec 30, 2024
1 parent fc4307b commit e39b59d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions compiler/ast/Scope.v
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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}`'
Expand Down
28 changes: 14 additions & 14 deletions compiler/context/mod.v
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand Down
12 changes: 6 additions & 6 deletions compiler/sema/mod.v
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}`'))
}
}
Expand Down

0 comments on commit e39b59d

Please sign in to comment.