bugfix with implicit structure types
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 27 May 2022 18:49:36 +0000 (13:49 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 27 May 2022 18:49:36 +0000 (13:49 -0500)
core/alloc.onyx
core/container/list.onyx
core/net/net.onyx
scripts/onyx-pkg.onyx
src/astnodes.c
src/onyx.c

index 8bbdcb7d729a530e0147bca04c4cf06e7e1bec63..3d4d131364e0a6b71cd184e08e21af6b620e296f 100644 (file)
@@ -43,4 +43,3 @@ init_temp_allocator :: () {
 clear_temp_allocator :: () {
     arena.clear(^temp_state);
 }
-
index ec6022ec3fcffbb25f58c18e90983dd1070202c3..4dce1596579a72254fef87fc3cd437e7d99d0a1a 100644 (file)
@@ -39,7 +39,7 @@ free :: (list: ^List) {
     }
 }
 
-push_end :: (list: ^List, x: list.Elem_Type) { 
+push_end :: (list: ^List, x: list.Elem_Type) {
     new_elem := allocate_elem(list);
     new_elem.data = x;
 
@@ -145,8 +145,7 @@ map :: #match {}
     }
 }
 
-#local iter :: package core.iter
-#match iter.as_iterator get_iterator
+#match core.iter.as_iterator get_iterator
 get_iterator :: (list: ^List($T)) -> Iterator(T) {
     iterator_next :: (list_iter: ^ListIterator($T)) -> (T, bool) {
         if list_iter.current == null do return .{}, false;
index f8176b85c2ffc714153ff14ed039684f67f2f859..e89e4b87b0de4b7ff37d6eff849343731a9b263c 100644 (file)
@@ -204,6 +204,14 @@ network_to_host :: #match {}
         return .None, bytes_read;
     },
 
+    write_byte = (use s: ^Socket, byte: u8) -> io.Error {
+        if handle == 0 do return .BadFile;
+
+        bytes_written := __net_send(handle, .[ byte ]);
+        if bytes_written < 0 { s.vtable = null; return .BufferFull; }
+        return .None;
+    },
+
     write = (use s: ^Socket, buffer: [] u8) -> (io.Error, u32) {
         if handle == 0 do return .BadFile, 0;
         
index ad021424a33aeba8eccbe04e1bffa18e81d60b8e..43d371e5af7780bc21abd3842acd9d96c07e6d22 100644 (file)
@@ -4,7 +4,6 @@
 Version :: SemVer.{0, 1, 1}
 
 use core
-use core.intrinsics.onyx {__initialize}
 
 global_arguments: struct {
     #tag "--config-file"
@@ -12,7 +11,7 @@ global_arguments: struct {
 } = .{};
 
 main :: (args: [] cstr) {
-    __initialize(^config);
+    config = .{};
 
     arg_parse.arg_parse(args, ^global_arguments);
 
@@ -155,7 +154,7 @@ run_add_command :: (args: [] cstr) {
     }
 }
 
-#tag Command.{ "remove", "Remove a dependency.", "package-or-url", 
+#tag Command.{ "remove", "Remove a dependency.", "package-or-url",
 """
 package-or-url   Git repository name or package name on disk to remove.
 """
@@ -467,7 +466,7 @@ uninstall_package :: (pack: Package) -> bool {
             attempt_remove_native_library(package_folder);
             os.remove_directory(package_folder);
         }
-        
+
         return true;
     }
 
@@ -483,7 +482,7 @@ attempt_remove_native_library :: (package_folder: str) -> bool {
         if result != .Success do return false;
         if string.is_empty(inner_config.native_library.library) do return false;
 
-        os.remove_file(tprintf("{}/{}{}", config.config.lib_bin_directory, inner_config.native_library.library, native_library_suffix));             
+        os.remove_file(tprintf("{}/{}{}", config.config.lib_bin_directory, inner_config.native_library.library, native_library_suffix));
     }
 
     return true;
@@ -529,7 +528,7 @@ run_native_library_installation :: (folder: str) -> bool {
             eprintf("Failed to build native library in {}.\n", folder);
             return false;
         }
-        
+
         if !os.dir_exists(config.config.lib_bin_directory) {
             if !os.dir_create(config.config.lib_bin_directory) {
                 eprintf("Failed to create native library directory, {}.\n", config.config.lib_bin_directory);
@@ -540,7 +539,7 @@ run_native_library_installation :: (folder: str) -> bool {
         source_path := tprintf("{}/{}{}", installed_dest, inner_config.native_library.library, native_library_suffix);
         dest_path   := tprintf("{}/{}{}", config.config.lib_bin_directory, inner_config.native_library.library, native_library_suffix);
         success := os.rename_file(source_path, dest_path);
-                                  
+
         if !success {
             eprintf("Failed to move native library to final destination.\n {} -> {}\n", source_path, dest_path);
         }
@@ -561,7 +560,7 @@ SemVer :: struct {
 
     parse :: (semver: ^SemVer, to_parse_: str, _: Allocator) -> bool {
         to_parse := to_parse_;
-        
+
         major := string.read_until(^to_parse, #char ".") |> conv.str_to_i64();
         string.advance(^to_parse);
         minor := string.read_until(^to_parse, #char ".") |> conv.str_to_i64();
@@ -825,7 +824,7 @@ Config :: struct {
         r->skip_whitespace();
         if r->is_empty() do return true;
         if p, _ := r->peek_byte(); p == #char "[" do return true;
-        
+
         dep := r->read_until(#char "=") |> string.strip_trailing_whitespace();
         r->read_byte();
         r->skip_whitespace();
@@ -1014,8 +1013,3 @@ write_ini_file :: (w: ^io.Writer, output: any) -> bool {
 
     return true;
 }
-
-
-
-
-
index 9fa20585115024d4c86c62b5d6df1cf9189336f1..4cfffce1adf7e45c83c9f9c3ebdc13b3117b3c64 100644 (file)
@@ -473,7 +473,7 @@ b32 convert_numlit_to_type(AstNumLit* num, Type* to_type) {
                                 return 1;
                             }
                 }
-                
+
                 onyx_report_error(num->token->pos, Error_Critical, "Unsigned integer constant with value '%l' does not fit into %d-bits.",
                         num->value.l,
                         type->Basic.size * 8);
@@ -685,7 +685,7 @@ TypeMatch unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) {
 
     // Here are some of the ways you can unify a node with a type if the type of the
     // node does not match the given type:
-    // 
+    //
     // If the nodes type is a function type and that function has an automatic return
     // value placeholder, fill in that placeholder with the actual type.
     // :AutoReturnType
@@ -753,7 +753,7 @@ TypeMatch unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) {
         }
 
         compound->type = type_build_compound_type(context.ast_alloc, compound);
-        
+
         return TYPE_MATCH_SUCCESS;
     }
 
@@ -785,7 +785,7 @@ TypeMatch unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) {
         if (address_of->can_be_removed) {
             if (!permanent) {
                 return unify_node_and_type_(&address_of->expr, type, permanent);
-                
+
             } else {
                 *pnode = (AstTyped *) address_of->expr;
                 return unify_node_and_type_(pnode, type, permanent);
@@ -847,7 +847,7 @@ Type* resolve_expression_type(AstTyped* node) {
         if (elem_type) {
             node->type = type_make_array(context.ast_alloc, elem_type, bh_arr_length(al->values));
             node->flags |= Ast_Flag_Array_Literal_Typed;
-            
+
             if (node->entity == NULL) {
                 add_entities_for_node(NULL, (AstNode *) node, NULL, NULL);
             }
@@ -856,8 +856,7 @@ Type* resolve_expression_type(AstTyped* node) {
 
     if (node->kind == Ast_Kind_Struct_Literal && node->type == NULL) {
         AstStructLiteral* sl = (AstStructLiteral *) node;
-        assert(sl->stnode == NULL);
-        assert(sl->type_node == NULL);
+        if (sl->stnode || sl->type_node) return NULL;
 
         // If values without names are given to a struct literal without
         // a type, then we cannot implicitly build the type of the struct
@@ -1208,7 +1207,7 @@ AstAddressOf* make_address_of(bh_allocator a, AstTyped* node) {
     if (node->token) ao->token = node->token;
     ao->expr = node;
 
-    return ao; 
+    return ao;
 }
 
 AstLocal* make_local(bh_allocator a, OnyxToken* token, AstType* type_node) {
@@ -1269,7 +1268,7 @@ void arguments_ensure_length(Arguments* args, u32 count) {
 void arguments_copy(Arguments* dest, Arguments* src) {
     dest->used_argument_count = -1;
     dest->named_values = src->named_values;
-    
+
     bh_arr_grow(dest->values, (u32) bh_arr_length(src->values));
     bh_arr_set_length(dest->values, (u32) bh_arr_length(src->values));
     bh_arr_each(AstTyped*, arg, dest->values) *arg = NULL;
index 4343c816fa397b057db8c28bd318ca5f8f05a5e7..13f80d2bd7b5e4b51ed48df1d5e6cb73c63466d3 100644 (file)
@@ -402,7 +402,7 @@ static b32 process_load_entity(Entity* ent) {
 
         bh_dir_close(dir);
         return success;
-        
+
     } else if (include->kind == Ast_Kind_Load_Path) {
         bh_arr_push(context.options->included_folders, include->name);