Merge remote-tracking branch 'origin/dev' into docgen
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 28 Mar 2023 13:37:15 +0000 (08:37 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 28 Mar 2023 13:37:15 +0000 (08:37 -0500)
21 files changed:
1  2 
compiler/include/astnodes.h
compiler/include/parser.h
compiler/src/astnodes.c
compiler/src/parser.c
compiler/src/polymorph.h
compiler/src/symres.c
compiler/src/utils.c
core/builtin.onyx
core/container/iter.onyx
core/container/map.onyx
core/conv/conv.onyx
core/conv/format.onyx
core/conv/parse.onyx
core/encoding/base64.onyx
core/io/stdio.onyx
core/misc/any_utils.onyx
core/misc/arg_parse.onyx
core/std.onyx
core/sync/mutex.onyx
core/sync/semaphore.onyx
core/threads/thread.onyx

Simple merge
Simple merge
index 98c520bcb906fb2f3a50db91242bcc952117ce60,c131ed06608fbd207578f003de7f8093b03c1e98..3227cab7784fe194b932fea6965e0a225e955932
@@@ -1540,7 -1540,7 +1540,7 @@@ AstLocal* make_local_with_type(bh_alloc
  }
  
  AstNode* make_symbol(bh_allocator a, OnyxToken* sym) {
--    AstNode* symbol = onyx_ast_node_new(a, sizeof(AstNode), Ast_Kind_Symbol);
++    AstNode* symbol = onyx_ast_node_new(a, sizeof(AstTyped), Ast_Kind_Symbol);
      symbol->token = sym;
      return symbol;
  }
index 2ae6a7843802d12510096777915f69bbca5e7c1a,02a646218a09d3cc1e47af9b2d90d10f7f1f37d2..a9e0d20113094003ff42da0556824d34f8a748c1
@@@ -711,7 -714,7 +714,7 @@@ static AstTyped* parse_factor(OnyxParse
                  while (!consume_token_if_next(parser, '}')) {
                      if (parser->hit_unexpected_token) break;
  
--                    AstNode* poly_var = make_node(AstNode, Ast_Kind_Symbol);
++                    AstNode* poly_var = (void *) make_node(AstTyped, Ast_Kind_Symbol);
                      poly_var->token = expect_token(parser, Token_Type_Symbol);
  
                      expect_token(parser, '=');
@@@ -1459,9 -1464,9 +1464,9 @@@ static i32 parse_possible_symbol_declar
          // INVESTIGATE: I don't know why, but appearantly, this has to be a
          // symbol node, not a direct link to the local. There is an error about
          // being unable to resolve the type of the local if it is immediately set.
--        AstNode* left_symbol = make_node(AstNode, Ast_Kind_Symbol);
++        AstTyped* left_symbol = make_node(AstTyped, Ast_Kind_Symbol);
          left_symbol->token = symbol;
--        assignment->left = (AstTyped *) left_symbol;
++        assignment->left = left_symbol;
      }
  
      return 1;
@@@ -1797,9 -1767,8 +1767,9 @@@ static void parse_polymorphic_variable(
  
      consume_token(parser);
  
--    AstNode* symbol_node = make_node(AstNode, Ast_Kind_Symbol);
++    AstTyped* symbol_node = make_node(AstTyped, Ast_Kind_Symbol);
      symbol_node->token = expect_token(parser, Token_Type_Symbol);
 +    symbol_node->flags |= Ast_Flag_Symbol_Is_PolyVar;
  
      AstNode *implicit_interface = NULL;
      if (consume_token_if_next(parser, '/')) {
      if (pv != NULL) {
          bh_arr_push(pv, ((AstPolyParam) {
              .kind     = PPK_Poly_Type,
--            .poly_sym = symbol_node,
++            .poly_sym = (AstNode *) symbol_node,
              .implicit_interface = implicit_interface,
  
              // These will be filled out by function_params()
@@@ -1960,7 -1929,7 +1930,7 @@@ static AstType* parse_type(OnyxParser* 
              }
  
              case Token_Type_Symbol: {
--                AstNode* symbol_node = make_node(AstNode, Ast_Kind_Symbol);
++                AstTyped* symbol_node = make_node(AstTyped, Ast_Kind_Symbol);
                  symbol_node->token = expect_token(parser, Token_Type_Symbol);
  
                  *next_insertion = (AstType *) symbol_node;
@@@ -2924,7 -2892,7 +2894,7 @@@ static AstEnumType* parse_enum_declarat
  
      AstType* backing = (AstType *) &basic_type_u32;
      if (consume_token_if_next(parser, '(')) {
--        AstNode* backing_sym = make_node(AstNode, Ast_Kind_Symbol);
++        AstTyped* backing_sym = make_node(AstTyped, Ast_Kind_Symbol);
          backing_sym->token = expect_token(parser, Token_Type_Symbol);
          backing = (AstType *) backing_sym;
  
@@@ -3722,7 -3750,7 +3760,8 @@@ OnyxParser onyx_parser_create(bh_alloca
      parser.tag_depth = 0;
      parser.overload_count = 0;
      parser.injection_point = NULL;
 +    parser.last_documentation_token = NULL;
+     parser.allow_package_expressions = 0;
  
      parser.polymorph_context = (PolymorphicContext) {
          .root_node = NULL,
Simple merge
Simple merge
Simple merge
index 3902de7e54c9ae886e906b886a2bfa36692f5866,8885c70a4ccdfd35ddc18d92f09bed3f0e9b1bb6..0b90dcd1c672794dc2adacfb7d18fe78c93fea3f
@@@ -443,21 -442,20 +448,21 @@@ any :: struct 
  Code :: struct {_:i32;}
  
  
 -//
 -// Define aliases for common datastructures in the core library, if the core library is available.
 -// I'm on the fence about keeping this, as the programmer may want to use these names for their own
 -// structures, but for the moment I don't see any harm. I'm also thinking about removing the '[..]'
 -// syntax for dynamic arrays and just make them like Map's and Set's, i.e. Array(T). This would
 -// remove some confusion around the 3 different array types as dynamic arrays would clearly just be
 -// normal structures. With the recent addition of macros and iterators, there really wouldn't be much
 -// difference anyway.
 +#doc """
 +    Define aliases for common datastructures in the core library, if the core library is available.
 +    I'm on the fence about keeping this, as the programmer may want to use these names for their own
 +    structures, but for the moment I don't see any harm. I'm also thinking about removing the '[..]'
 +    syntax for dynamic arrays and just make them like Map's and Set's, i.e. Array(T). This would
 +    remove some confusion around the 3 different array types as dynamic arrays would clearly just be
 +    normal structures. With the recent addition of macros and iterators, there really wouldn't be much
 +    difference anyway.
 +"""
- #if #defined((package core.map).Map) {
-     Map :: (package core.map).Map;
+ #if #defined(core.map.Map) {
+     Map :: core.map.Map;
  }
  
- #if #defined((package core.set).Set) {
-     Set :: (package core.set).Set;
+ #if #defined(core.set.Set) {
+     Set :: core.set.Set;
  }
  
  
Simple merge
index be23ee87783964baf394409f7baf9e24e90bb03a,2d712b807ed2eecd716e8fb20d618c6b16ad4e42..9edcaa308a1caa59af5729517279a1d28d94415d
@@@ -1,13 -1,20 +1,20 @@@
  package core.map
  
- use core {array, hash, memory, math, conv, Optional}
+ use core
+ use core.array
+ use core.hash
+ use core.memory
+ use core.math
+ use core.conv
+ use core {Optional}
  use core.intrinsics.onyx { __initialize }
  
 -//
 -// Map is a generic hash-map implementation that uses chaining.
 -// Values can be of any type. Keys must of a type that supports
 -// the core.hash.hash, and the '==' operator.
 -//
 +#doc """
 +    Map is a generic hash-map implementation that uses chaining.
 +    Values can be of any type. Keys must of a type that supports
 +    the core.hash.hash, and the '==' operator.
 +"""
  @conv.Custom_Format.{ #solidify format_map {K=Key_Type, V=Value_Type} }
  Map :: struct (Key_Type: type_expr, Value_Type: type_expr) where ValidKey(Key_Type) {
      allocator : Allocator;
index b65b738ad0aca8333afb99337d9cd8abb0a15d91,058d56cf8ed7566da39bbe4508b6d11484e0251f..88378619beacaabc11faff4a204022b7de1a7c22
@@@ -2,13 -2,13 +2,14 @@@ package core.con
  
  Enable_Custom_Formatters :: true
  
- use core {string, math}
+ use core.string
+ use core.math
  
 -//
 -// Converts a string into an integer. Works with positive and
 -// negative integers. If given a pointer to a string, will
 -// modify the string to extract the integer part.
 +#doc """
 +    Converts a string into an integer. Works with positive and
 +    negative integers. If given a pointer to a string, will
 +    modify the string to extract the integer part.
 +"""
  str_to_i64 :: #match #local {}
  
  #overload
index 668b8e67385b6c7d61da45be436b11ef84b98b76,3e1b10afe9e6b77b9c061f591559ddc1c8f71187..c79a10e4399134447f18cb8e834b6af168ca5685
@@@ -402,14 -401,12 +407,13 @@@ format_va :: (output: &Format_Output, f
  }
  
  
 -//
 -// This procedure converts any value into a string, using the type information system.
 -// If a custom formatter is specified for the type, that is used instead.
 -// This procedure is generally not used directly; instead, through format or format_va.
 +#doc """
 +    This procedure converts any value into a string, using the type information system.
 +    If a custom formatter is specified for the type, that is used instead.
 +    This procedure is generally not used directly; instead, through format or format_va.
 +"""
  format_any :: (output: &Format_Output, formatting: &Format, v: any) {
-     use package runtime.info
-     array :: package core.array;
+     use runtime.info {*};
  
      //
      // Dereference the any if the '*' format specifier was given.
index 9156de0d8f6d0bd82aa3b40a9b41936ebc06cbe7,b43b50d8ae7e1fdb11e02e0e996c58f3654dd54f..a248b591ea23767f7e051865422da22bb8664bac
@@@ -1,11 -1,14 +1,15 @@@
  package core.conv
  
- use core {map, string, array, math}
+ use core.map
+ use core.string
+ use core.array
+ use core.math
+ use runtime
  
 -//
 -// Parses many different types from a string into a value.
 -// Uses a custom parser if one has been specified for the type given.
 +#doc """
 +    Parses many different types from a string into a value.
 +    Uses a custom parser if one has been specified for the type given.
 +"""
  parse_any :: #match {}
  
  #overload
Simple merge
index 6a848979f2d4fbea60f512cf50b4be188ed6ab42,4f5e8fa155202568e417a549d77c5a74f052fa02..34fe387e779bb95c30b64f279fcae8cb1a217eec
@@@ -75,8 -77,8 +77,9 @@@ print :: #match #locked 
  //
  // Helper procedure that prints something, then prints a newline.
  println :: (x) => {
--    print(x);
--    print("\n");
++    use core
++    core.print(x);
++    core.print("\n");
  }
  
  //
Simple merge
index cedb3e8f731a97e716048e2d2d052ab76cbf56d7,1bda7de3a9390b99ce43ef72f4ff94fd5caea6b6..cdf7054d01f4b2629fa77adc51a0859af8312e87
@@@ -1,28 -1,33 +1,32 @@@
  package core.arg_parse
  
- use core
 -//
 -// 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 {package, printf}
+ use core.iter
+ use core.conv
+ use core.string
+ use runtime
  
 +#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);
diff --cc core/std.onyx
Simple merge
index 1705612d9d459d01d0526e08a16033a2961f5ea3,e1982011a7706c71e936bd6d833d4657b423bc32..6651d3a48001bce0ae7d3b3fc37ebaed6776e485
@@@ -1,28 -1,31 +1,30 @@@
  package core.sync
  
- use core.intrinsics.atomics
+ use runtime
+ use core
+ use core.intrinsics.atomics {*}
  use core.thread { Thread_ID }
  
 -//
 -// A mutex represents a resource that can only be held by one
 -// thread at a time. It is used to create sections of code that
 -// only one thread can be in at a time.
 -//
 -// Mutexes in WebAssembly are very cheap, because they simply
 -// use the atomic_cmpxchg intrinsic to operate. This only uses
 -// memory, so no real resource allocation is necessary.
 -//
 -// `lock` has two states: 0, and 1.
 -//    0 means unlocked
 -//    1 means locked
 -//
 -// To lock it:
 -//    Try to store 1 if the value was already 0
 -//    Otherwise, if it was already 1, wait until it goes to 0.
 -//
 -// To unlock it:
 -//    Atomically set it to 0.
 -//    Notify at most 1 other thread about this change.
 -//
 +#doc """
 +    A mutex represents a resource that can only be held by one
 +    thread at a time. It is used to create sections of code that
 +    only one thread can be in at a time.
 +   
 +    Mutexes in WebAssembly are very cheap, because they simply
 +    use the atomic_cmpxchg intrinsic to operate. This only uses
 +    memory, so no real resource allocation is necessary.
 +   
 +    `lock` has two states: 0, and 1.
 +    0 means unlocked, 1 means locked
 +   
 +    To lock it:
 +        Try to store 1 if the value was already 0.
 +        Otherwise, if it was already 1, wait until it goes to 0.
 +   
 +    To unlock it:
 +        Atomically set it to 0.
 +        Notify at most 1 other thread about this change.
 +"""
  Mutex :: struct {
      lock  : i32;
      owner : Thread_ID;
index 3314e7b8bc8e5ef5438da92d4e612e7bd2b3976a,c9c3d5e01d8753fdbfb86a06b91ffcf753e54c36..f033cd2daa92594b1fc507d83b2d4b07bccf4f6f
@@@ -1,24 -1,27 +1,27 @@@
  package core.sync
  
+ use runtime
+ use core
  use core.intrinsics.atomics
  
 -//
 -// A semaphore represents a counter that can only be incremented
 -// and decremented by one thread at a time. "Waiting" on a semaphore
 -// means decrementing the counter by 1 if it is greater than 0, otherwise
 -// waiting until the counter is incremented. "Posting" on a semaphore
 -// means incrementing the counter by a certain value, in turn releasing
 -// other threads that might have been waiting for the value to change.
 -//
 -// Semaphores are generally used for controlling access to shared
 -// resources. For a contrived example, say only 4 threads can use
 -// a given network connection at a time. A semaphore would be created
 -// with a value of 4. When a thread wants to use the network connection,
 -// it would use `semaphore_wait` to obtain the resource, or wait if
 -// the network is currently available. When it is done using the
 -// network, it would call `semaphore_post` to release the resource,
 -// allowing another thread to use it.
 -//
 +#doc """
 +    A semaphore represents a counter that can only be incremented
 +    and decremented by one thread at a time. "Waiting" on a semaphore
 +    means decrementing the counter by 1 if it is greater than 0, otherwise
 +    waiting until the counter is incremented. "Posting" on a semaphore
 +    means incrementing the counter by a certain value, in turn releasing
 +    other threads that might have been waiting for the value to change.
 +   
 +    Semaphores are generally used for controlling access to shared
 +    resources. For a contrived example, say only 4 threads can use
 +    a given network connection at a time. A semaphore would be created
 +    with a value of 4. When a thread wants to use the network connection,
 +    it would use `semaphore_wait` to obtain the resource, or wait if
 +    the network is currently available. When it is done using the
 +    network, it would call `semaphore_post` to release the resource,
 +    allowing another thread to use it.
 +"""
  Semaphore :: struct {
      mutex   : Mutex;
      counter : i32;
Simple merge