changed: documentation types cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 21 Mar 2023 04:16:05 +0000 (23:16 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 24 Mar 2023 01:51:04 +0000 (20:51 -0500)
compiler/include/astnodes.h
compiler/src/doc.c
compiler/src/polymorph.h
core/container/map.onyx
core/hash/hash.onyx
core/misc/arg_parse.onyx

index f41112b092ed26a6e41876ef265014715aa21d52..770e48f4d26b748b071d8c101cbad0b8727b32cb 100644 (file)
@@ -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;
index 5dd7333440f6998b64cfd266c6d4cb0e38ce7779..7b9d1512e0409df1dcc71fd3959b7dfdba1f91e0 100644 (file)
@@ -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) {
index a432752c8061e85407c02e3020513cbf26d60692..cbe005f97c3f872798aae1d8a80ab472fc3f6ab7 100644 (file)
@@ -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) {
index 1d69cf40cef47f3749fb9a2282f9030fe66c9cd3..be23ee87783964baf394409f7baf9e24e90bb03a 100644 (file)
@@ -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
index 2639ec24e197623dad366550b5b2b5a9be32e57f..a93aca9f5487f00266a8cb6f9adc8e667e6d4fe8 100644 (file)
@@ -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 // ...
             }
         }
index 5e3248810d7f1d9e53e41ecb6ba29143f952cc43..cedb3e8f731a97e716048e2d2d052ab76cbf56d7 100644 (file)
@@ -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);