Skip to content

Commit

Permalink
[BROKEN] In progress function overload resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
LensPlaysGames committed Dec 31, 2022
1 parent 9d61a0b commit 95a65ab
Show file tree
Hide file tree
Showing 3 changed files with 362 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/ast.c
Expand Up @@ -36,8 +36,8 @@ void scope_pop(AST *ast) {
}

Symbol *scope_add_symbol(Scope *scope, enum SymbolKind kind, span name, void *value) {
/// Check if the symbol already exists.
if (scope_find_symbol(scope, name, true)) return NULL;
/// DON'T check if the symbol already exists.
//if (scope_find_symbol(scope, name, true)) return NULL;

Symbol *symbol = calloc(1, sizeof(Symbol));
symbol->kind = kind;
Expand Down Expand Up @@ -69,8 +69,8 @@ Symbol *scope_find_symbol(Scope *scope, span name, bool this_scope_only) {
}

Symbol *scope_find_or_add_symbol(Scope *scope, enum SymbolKind kind, span name, bool this_scope_only) {
Symbol *symbol = scope_find_symbol(scope, name, this_scope_only);
if (symbol) return symbol;
//Symbol *symbol = scope_find_symbol(scope, name, this_scope_only);
//if (symbol) return symbol;
return scope_add_symbol(scope, kind, name, NULL);
}

Expand Down Expand Up @@ -990,4 +990,4 @@ void ast_replace_node(AST *ast, Node *old, Node *new) {
}

#undef REPLACE_IN_CHILDREN
}
}
3 changes: 2 additions & 1 deletion src/parser.c
Expand Up @@ -823,6 +823,7 @@ static Node *parse_decl_rest(Parser *p, Token ident) {
if (!is_ext) {
/// Create a symbol table entry before parsing the body.
Symbol *sym = scope_find_or_add_symbol(curr_scope(p), SYM_FUNCTION, ident.text, true);

if (sym->kind != SYM_FUNCTION || sym->node)
ERR_AT(ident.source_location, "Redefinition of symbol '%.*s'", (int) ident.text.size, ident.text.data);

Expand Down Expand Up @@ -1160,4 +1161,4 @@ NODISCARD const char *token_type_to_string(enum TokenType type) {
}

return "\?\?\?";
}
}

0 comments on commit 95a65ab

Please sign in to comment.