From 3ef8751dc48363ae445dac9b0799e45c37dd42ba Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 7 Feb 2023 15:14:27 -0600 Subject: [PATCH] renamed core.hash.to_u32 to core.hash.hash --- compiler/src/symres.c | 13 +++++++++++-- core/hash/hash.onyx | 23 +++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/compiler/src/symres.c b/compiler/src/symres.c index bbd01ace..1ed93a93 100644 --- a/compiler/src/symres.c +++ b/compiler/src/symres.c @@ -1381,12 +1381,21 @@ static SymresStatus symres_process_directive(AstNode* directive) { SYMRES(expression, (AstTyped **) &add_overload->overloaded_function); if (add_overload->overloaded_function == NULL) return Symres_Error; // NOTE: Error message will already be generated - if (add_overload->overloaded_function->kind != Ast_Kind_Overloaded_Function) { + AstOverloadedFunction *ofunc = (AstOverloadedFunction *) strip_aliases((AstNode *) add_overload->overloaded_function); + if (ofunc->kind == Ast_Kind_Symbol) { + if (context.cycle_detected) { + onyx_report_error(add_overload->token->pos, Error_Waiting_On, "Waiting for matched procedure to be known."); + return Symres_Error; + } + + return Symres_Yield_Macro; + } + + if (ofunc->kind != Ast_Kind_Overloaded_Function) { onyx_report_error(add_overload->token->pos, Error_Critical, "#match directive expects a matched procedure."); return Symres_Error; } - AstOverloadedFunction* ofunc = (AstOverloadedFunction *) add_overload->overloaded_function; if (ofunc->locked) { onyx_report_error(add_overload->token->pos, Error_Critical, "Cannot add match option here as the original #match was declared as #locked."); onyx_report_error(ofunc->token->pos, Error_Critical, "Here is the original #match."); diff --git a/core/hash/hash.onyx b/core/hash/hash.onyx index 9ab6333f..1208f6dc 100644 --- a/core/hash/hash.onyx +++ b/core/hash/hash.onyx @@ -1,6 +1,25 @@ package core.hash -to_u32 :: #match -> u32 { +// +// DEPRECATED: to_u32 is the old name that kind of +// makes sense, but is a little unintuitive. Use +// core.hash.hash instead. +to_u32 :: hash + +// +// This overloaded procedure defines how to hash something. +// It is used throughout the standard library to hash values. +// There are many overloads to it in the standard library, and +// more can be added using #overload. Or, a hash method can be +// defined for a structure or distinct type. +// +// Person :: struct { +// hash :: (p: Person) { +// return // ... +// } +// } + +hash :: #match -> u32 { // Does this need to have a higher precedence value? // Because if I wanted to have a custom type as the key // of a map that only looks at some of the members of the @@ -26,7 +45,7 @@ to_u32 :: #match -> u32 { } Hashable :: interface (t: $T) { - { to_u32(t) } -> u32; + { hash(t) } -> u32; } #local -- 2.25.1