From: Brendan Hansen Date: Tue, 21 Mar 2023 04:16:05 +0000 (-0500) Subject: changed: documentation types cleanup X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=cd2b4b5659e20b9e8ac819cb96b6c57a845eb0c4;p=onyx.git changed: documentation types cleanup --- diff --git a/compiler/include/astnodes.h b/compiler/include/astnodes.h index f41112b0..770e48f4 100644 --- a/compiler/include/astnodes.h +++ b/compiler/include/astnodes.h @@ -289,6 +289,7 @@ typedef enum AstFlags { Ast_Flag_Extra_Field_Access = BH_BIT(23), Ast_Flag_Symbol_Is_PolyVar = BH_BIT(24), + Ast_Flag_Poly_Call_From_Auto = BH_BIT(24), Ast_Flag_Binding_Isnt_Captured = BH_BIT(25), } AstFlags; diff --git a/compiler/src/doc.c b/compiler/src/doc.c index 5dd73334..7b9d1512 100644 --- a/compiler/src/doc.c +++ b/compiler/src/doc.c @@ -244,7 +244,15 @@ static void write_type_node(bh_buffer *buffer, void *vnode) { return; case Ast_Kind_Poly_Call_Type: + if (((AstPolyCallType *) node)->callee == (AstNode *) builtin_optional_type) { + bh_buffer_write_string(buffer, "? "); + write_type_node(buffer, ((AstPolyCallType *) node)->params[0]); + return; + } + write_type_node(buffer, ((AstPolyCallType *) node)->callee); + if (node->flags & Ast_Flag_Poly_Call_From_Auto) return; + bh_buffer_write_byte(buffer, '('); bh_arr_each(AstNode *, param, ((AstPolyCallType *) node)->params) { diff --git a/compiler/src/polymorph.h b/compiler/src/polymorph.h index a432752c..cbe005f9 100644 --- a/compiler/src/polymorph.h +++ b/compiler/src/polymorph.h @@ -1000,6 +1000,7 @@ b32 potentially_convert_function_to_polyproc(AstFunction *func) { AstPolyCallType* pcall = onyx_ast_node_new(context.ast_alloc, sizeof(AstPolyCallType), Ast_Kind_Poly_Call_Type); pcall->callee = *apv->replace; pcall->token = pcall->callee->token; + pcall->flags |= Ast_Flag_Poly_Call_From_Auto; bh_arr_new(global_heap_allocator, pcall->params, apv->variable_count); if (apv->base_type->kind == Ast_Kind_Poly_Struct_Type) { diff --git a/core/container/map.onyx b/core/container/map.onyx index 1d69cf40..be23ee87 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -193,16 +193,16 @@ delete :: (use map: &Map, key: map.Key_Type) { } #doc """ - Helper macro that finds a value by the key, and if it exists, - runs the code, providing an `it` variable that is a pointer - to the value. - - m: Map(str, i32); - m->update("test") { - *it += 10; - } - or: - m->update("test", #(*it += 10)); +Helper macro that finds a value by the key, and if it exists, +runs the code, providing an `it` variable that is a pointer +to the value. + + m: Map(str, i32); + m->update("test") { + *it += 10; + } +or: + m->update("test", #(*it += 10)); """ update :: macro (map: ^Map, key: map.Key_Type, body: Code) { lookup_ :: lookup diff --git a/core/hash/hash.onyx b/core/hash/hash.onyx index 2639ec24..a93aca9f 100644 --- a/core/hash/hash.onyx +++ b/core/hash/hash.onyx @@ -10,11 +10,12 @@ 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. + more can be added using #overload. + + Alternatively, a hash method can be defined for a structure or distinct type. Person :: struct { - hash :: (p: Person) { + hash :: (p: Person) -> u32 { return // ... } } diff --git a/core/misc/arg_parse.onyx b/core/misc/arg_parse.onyx index 5e324881..cedb3e8f 100644 --- a/core/misc/arg_parse.onyx +++ b/core/misc/arg_parse.onyx @@ -1,29 +1,28 @@ package core.arg_parse -// -// This is currently a very basic argument parsing library. -// The options are given through a structure like so: -// -// Options :: struct { -// @"--option_1" -// option_1: str; -// -// @"--option_2", "-o2" -// option_2: bool; -// } -// -// main :: (args) => { -// o: Options; -// arg_parse.arg_parse(args, &o); -// } -// -// Options that are strings and integers expect an argument after -// them to specify their value. Options that are bool default to -// false and are true if one or more of the option values are present. -// - use core +#doc """ + This is currently a very basic argument parsing library. + The options are given through a structure like so: + + Options :: struct { + @"--option_1" + option_1: str; + + @"--option_2", "-o2" + option_2: bool; + } + + main :: (args) => { + o: Options; + arg_parse.arg_parse(args, &o); + } + + Options that are strings and integers expect an argument after + them to specify their value. Options that are bool default to + false and are true if one or more of the option values are present. +""" arg_parse :: (c_args: [] cstr, output: any) -> bool { arg_iter := iter.as_iter(c_args) |> iter.map(string.from_cstr);