Map redesign, removing just flags as unoccupied, when getting value we dont check occupancy but key, avoids hanging values due to the nature of linear probing
This commit is contained in:
@@ -44,28 +44,17 @@ sym_insert(Sym *sym){
|
||||
Sym *is_sym = (Sym *)map_get(&pctx->syms, hash);
|
||||
if(is_sym){
|
||||
parsing_error(sym->ast->pos, "Symbol with name: [%s] defined multiple times", sym->name.s.str);
|
||||
return;
|
||||
}
|
||||
if(pctx->scope > 0){
|
||||
For(pctx->local_syms){
|
||||
if(it[0]->name.str == sym->name.str) parsing_error(sym->ast->pos, "Symbol with name: [%s] defined multiple times", sym->name.s.str);
|
||||
return;
|
||||
}
|
||||
pctx->local_syms.add(sym);
|
||||
}
|
||||
else{
|
||||
|
||||
map_insert(&pctx->syms, hash, sym);
|
||||
}
|
||||
}
|
||||
|
||||
function Sym *
|
||||
sym_get(Intern_String name){
|
||||
Sym *result = (Sym *)map_get(&pctx->syms, hash_string(name.s));
|
||||
if(!result){
|
||||
For(pctx->local_syms){
|
||||
if(it[0]->name.str == name.str) return it[0];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -80,6 +69,11 @@ function void
|
||||
scope_close(S64 local_sym_count){
|
||||
pctx->scope--;
|
||||
assert(pctx->scope >= 0);
|
||||
for(S64 i = local_sym_count; i < pctx->local_syms.len; i++){
|
||||
Sym *it = pctx->local_syms.data[i];
|
||||
void *removed = map_remove(&pctx->syms, hash_string(it->name.s));
|
||||
assert(removed);
|
||||
}
|
||||
pctx->local_syms.len = local_sym_count;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user