From 3fe79f08da577e5737bdeb70b13ad5fac0d84393 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 27 May 2022 13:49:36 -0500 Subject: [PATCH] bugfix with implicit structure types --- core/alloc.onyx | 1 - core/container/list.onyx | 5 ++--- core/net/net.onyx | 8 ++++++++ scripts/onyx-pkg.onyx | 22 ++++++++-------------- src/astnodes.c | 17 ++++++++--------- src/onyx.c | 2 +- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/core/alloc.onyx b/core/alloc.onyx index 8bbdcb7d..3d4d1313 100644 --- a/core/alloc.onyx +++ b/core/alloc.onyx @@ -43,4 +43,3 @@ init_temp_allocator :: () { clear_temp_allocator :: () { arena.clear(^temp_state); } - diff --git a/core/container/list.onyx b/core/container/list.onyx index ec6022ec..4dce1596 100644 --- a/core/container/list.onyx +++ b/core/container/list.onyx @@ -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; diff --git a/core/net/net.onyx b/core/net/net.onyx index f8176b85..e89e4b87 100644 --- a/core/net/net.onyx +++ b/core/net/net.onyx @@ -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; diff --git a/scripts/onyx-pkg.onyx b/scripts/onyx-pkg.onyx index ad021424..43d371e5 100644 --- a/scripts/onyx-pkg.onyx +++ b/scripts/onyx-pkg.onyx @@ -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; } - - - - - diff --git a/src/astnodes.c b/src/astnodes.c index 9fa20585..4cfffce1 100644 --- a/src/astnodes.c +++ b/src/astnodes.c @@ -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; diff --git a/src/onyx.c b/src/onyx.c index 4343c816..13f80d2b 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -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); -- 2.25.1