From: Brendan Hansen Date: Sat, 24 Sep 2022 01:23:50 +0000 (-0500) Subject: solidified overload precedence order within a file X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=2dcbb7a3c65677ed77408720e430d65c2c88f0c4;p=onyx.git solidified overload precedence order within a file --- diff --git a/compiler/include/parser.h b/compiler/include/parser.h index 48889a86..325f552a 100644 --- a/compiler/include/parser.h +++ b/compiler/include/parser.h @@ -34,6 +34,13 @@ typedef struct OnyxParser { bh_arr(AstTyped *) stored_tags; + // Used to set default precedence of #overload options. + // This way, the precedence order of multiple #overload + // options in the same file is given to be the lexical + // order. This does not make any guarentees about #overloads + // in other files. + u32 overload_count; + u16 tag_depth : 16; b32 hit_unexpected_token : 1; diff --git a/compiler/src/parser.c b/compiler/src/parser.c index 30da360e..ea4ef81d 100644 --- a/compiler/src/parser.c +++ b/compiler/src/parser.c @@ -3231,7 +3231,7 @@ static void parse_top_level_statement(OnyxParser* parser) { add_overload->precedence = bh_max(pre->value.l, 0); } else { - add_overload->precedence = 0; + add_overload->precedence = parser->overload_count++; } parser->parse_calls = 0; @@ -3486,6 +3486,7 @@ OnyxParser onyx_parser_create(bh_allocator alloc, OnyxTokenizer *tokenizer) { parser.stored_tags = NULL; parser.parse_calls = 1; parser.tag_depth = 0; + parser.overload_count = 0; parser.polymorph_context = (PolymorphicContext) { .root_node = NULL, diff --git a/core/container/map.onyx b/core/container/map.onyx index e2513ac0..63c29fb5 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -44,15 +44,15 @@ Map :: struct (Key_Type: type_expr, Value_Type: type_expr) where ValidKey(Key_Ty // These need to have aliases because some of them like // 'delete', collide with the global 'delete', which // causes it to map to the wrong function. - init :: (package core.map).init - has :: (package core.map).has - get :: (package core.map).get - get_ptr :: (package core.map).get_ptr - put :: (package core.map).put - delete :: (package core.map).delete - update :: (package core.map).update - clear :: (package core.map).clear - empty :: (package core.map).empty + init :: init + has :: has + get :: get + get_ptr :: get_ptr + put :: put + delete :: delete + update :: update + clear :: clear + empty :: empty } make :: ($Key: type_expr, $Value: type_expr, default := Value.{}) -> Map(Key, Value) { diff --git a/core/io/stream.onyx b/core/io/stream.onyx index ca8d5398..20ff8399 100644 --- a/core/io/stream.onyx +++ b/core/io/stream.onyx @@ -129,7 +129,7 @@ stream_size :: (use s: ^Stream) -> i32 { // // - You can pass an existing slice. The behavior of this // buffer depend on the other arguments. If you set -// write_enabled to false, then writing will be allowed +// write_enabled to false, then writing will not be allowed // into this buffer. This is good practice if you only // plan on using the stream as a read-only output for // io.Reader. If you enable writing, then you can