diff options
Diffstat (limited to 'scope.c')
| -rw-r--r-- | scope.c | 39 |
1 files changed, 18 insertions, 21 deletions
@@ -17,14 +17,14 @@ static void var_destroy(struct var_def* var) { } void scope_destroy(struct scope* scope) { - for (unsigned long long i = 0; i < scope->type_cap; i++) { + for (integral_t i = 0; i < scope->type_cap; i++) { if (scope->types[i] != NULL) { free(scope->types[i]); } } free(scope->types); - for (unsigned long long i = 0; i < scope->var_cap; i++) { + for (integral_t i = 0; i < scope->var_cap; i++) { if (scope->vars[i] != NULL) { var_destroy(scope->vars[i]); free(scope->vars[i]); @@ -33,25 +33,22 @@ void scope_destroy(struct scope* scope) { free(scope->vars); } -static inline unsigned long long advance_hash( - unsigned long long hash, - unsigned long long val, - unsigned long long cap +static inline integral_t advance_hash( + integral_t hash, + integral_t val, + integral_t cap ) { return ((hash << 5) - hash + val) % cap;; } -static unsigned long long hash_name(const char* name, unsigned long long cap) { - unsigned long long hash = 0, i = 0; +static integral_t hash_name(const char* name, integral_t cap) { + integral_t hash = 0, i = 0; while (name[i] != 0) hash = advance_hash(hash, name[i++], cap); return hash; } -unsigned long long hash_type_key( - const struct type_key* key, - unsigned long long cap -) { - unsigned long long hash = hash_name(key->name, cap); +integral_t hash_type_key(const struct type_key* key, integral_t cap) { + integral_t hash = hash_name(key->name, cap); hash = advance_hash(hash, key->how_long, cap); hash = advance_hash(hash, key->marked_signed, cap); hash = advance_hash(hash, key->marked_unsigned, cap); @@ -72,8 +69,8 @@ static struct type_def** type_cell( const struct scope* scope, const struct type_key* key ) { - unsigned long long orig_idx = hash_type_key(key, scope->type_cap); - unsigned long long idx = orig_idx; + integral_t orig_idx = hash_type_key(key, scope->type_cap); + integral_t idx = orig_idx; do { if (scope->types[idx] == NULL @@ -85,7 +82,7 @@ static struct type_def** type_cell( static void rehash_types(struct scope* scope) { struct type_def** old_types = scope->types; - unsigned long long old_cap = scope->type_cap; + integral_t old_cap = scope->type_cap; scope->type_cap *= 2; scope->types = calloc(scope->type_cap, sizeof(struct type_def*)); if (scope->types == NULL) { @@ -93,7 +90,7 @@ static void rehash_types(struct scope* scope) { exit(1); } - for (unsigned long long i = 0; i < old_cap; i++) { + for (integral_t i = 0; i < old_cap; i++) { if (old_types[i] == NULL) continue; struct type_def** cell = type_cell(scope, &old_types[i]->key); @@ -110,8 +107,8 @@ static struct var_def** var_cell( const struct scope* scope, const char* name ) { - unsigned long long orig_idx = hash_name(name, scope->var_cap); - unsigned long long idx = orig_idx; + integral_t orig_idx = hash_name(name, scope->var_cap); + integral_t idx = orig_idx; do { if (scope->vars[idx] == NULL @@ -123,7 +120,7 @@ static struct var_def** var_cell( static void rehash_vars(struct scope* scope) { struct var_def** old_vars = scope->vars; - unsigned long long old_cap = scope->var_cap; + integral_t old_cap = scope->var_cap; scope->var_cap *= 2; scope->vars = calloc(scope->var_cap, sizeof(struct var_def*)); if (scope->vars == NULL) { @@ -131,7 +128,7 @@ static void rehash_vars(struct scope* scope) { exit(1); } - for (unsigned long long i = 0; i < old_cap; i++) { + for (integral_t i = 0; i < old_cap; i++) { if (old_vars[i] == NULL) continue; struct var_def** cell = var_cell(scope, old_vars[i]->name); |
