aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-11-29 15:27:53 +0000
committergingerBill <bill@gingerbill.org>2020-11-29 15:27:53 +0000
commit97c66c9c732af1e0735ee3f48a8af08b199bddf9 (patch)
treeaaedfa7f85390520f3d6d60064cedd8a4cb9af17 /src/check_expr.cpp
parent085972bb2ccde65d148b7fdc07b7ea8329e46293 (diff)
Add `intrinsics.type_hasher_proc`; Make `map` work with generic hasher procedure
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index e2a6089b9..6ba25619f 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -91,7 +91,7 @@ Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type, ProcCal
bool abi_compat_return_by_pointer(gbAllocator a, ProcCallingConvention cc, Type *abi_return_type);
void set_procedure_abi_types(Type *type);
void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type);
-
+void add_map_key_type_dependencies(CheckerContext *ctx, Type *key);
Type *make_soa_struct_slice(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem);
Type *make_soa_struct_dynamic_array(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem);
@@ -6081,6 +6081,29 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
operand->type = t_equal_proc;
break;
}
+
+ case BuiltinProc_type_hasher_proc:
+ {
+ Operand op = {};
+ Type *bt = check_type(c, ce->args[0]);
+ Type *type = base_type(bt);
+ if (type == nullptr || type == t_invalid) {
+ error(ce->args[0], "Expected a type for '%.*s'", LIT(builtin_name));
+ return false;
+ }
+ if (!is_type_valid_for_keys(type)) {
+ gbString t = type_to_string(type);
+ error(ce->args[0], "Expected a valid type for map keys for '%.*s', got %s", LIT(builtin_name), t);
+ gb_string_free(t);
+ return false;
+ }
+
+ add_map_key_type_dependencies(c, type);
+
+ operand->mode = Addressing_Value;
+ operand->type = t_hasher_proc;
+ break;
+ }
}
return true;