From 1ca7da6914ed12f5180c569ae87051415c3143e2 Mon Sep 17 00:00:00 2001 From: Thomas Stibor Date: Wed, 14 Dec 2022 14:11:05 +0100 Subject: [PATCH 1/3] Enable -out: for build and runs with the attribute @(test) According to the odin help command $ odin help test ... -out: Set the file name of the outputted executable Example: -out:foo.exe building and running tests the executable output filepath shall be specified. However, the -out parameter is disabled, resulting in error message: Unknown flag for 'odin test': 'out' 'out' is supported with the following commands: run, build Omitting the -out parameter results in default filepath '01.bin' (on Linux). However, it is desirable for user specifying the output filepath, e.g. by using this Makefile snippet: TARGET=main FLAGS=-warnings-as-errors -verbose-errors all: run run: @odin run . $(FLAGS) -out:$(TARGET) test: @odin test . $(FLAGS) -out:$(TARGET) clean: @rm -f $(TARGET) In addition a typo is fixed. --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3b0a599db..e816906d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -764,7 +764,7 @@ bool parse_build_flags(Array args) { auto build_flags = array_make(heap_allocator(), 0, BuildFlag_COUNT); add_flag(&build_flags, BuildFlag_Help, str_lit("help"), BuildFlagParam_None, Command_all); add_flag(&build_flags, BuildFlag_SingleFile, str_lit("file"), BuildFlagParam_None, Command__does_build | Command__does_check); - add_flag(&build_flags, BuildFlag_OutFile, str_lit("out"), BuildFlagParam_String, Command__does_build &~ Command_test); + add_flag(&build_flags, BuildFlag_OutFile, str_lit("out"), BuildFlagParam_String, Command__does_build | Command_test); add_flag(&build_flags, BuildFlag_OptimizationMode, str_lit("o"), BuildFlagParam_String, Command__does_build); add_flag(&build_flags, BuildFlag_OptimizationMode, str_lit("O"), BuildFlagParam_String, Command__does_build); add_flag(&build_flags, BuildFlag_ShowTimings, str_lit("show-timings"), BuildFlagParam_None, Command__does_check); @@ -1930,7 +1930,7 @@ void print_show_help(String const arg0, String const &command) { print_usage_line(3, "odin check # Type check package in "); print_usage_line(3, "odin check filename.odin -file # Type check single-file package, must contain entry point."); } else if (command == "test") { - print_usage_line(1, "test Build ands runs procedures with the attribute @(test) in the initial package"); + print_usage_line(1, "test Build and runs procedures with the attribute @(test) in the initial package"); } else if (command == "query") { print_usage_line(1, "query [experimental] Parse, type check, and output a .json file containing information about the program"); } else if (command == "doc") { From f029b4beb1f8a037334ff68bd459049b1e44ef31 Mon Sep 17 00:00:00 2001 From: Lucas Perlind Date: Sat, 17 Dec 2022 14:23:05 +1100 Subject: [PATCH 2/3] Add more utility procedures to small array --- core/container/small_array/small_array.odin | 47 +++++++++++++++- tests/core/build.bat | 7 ++- .../core/container/test_core_small_array.odin | 56 +++++++++++++++++++ 3 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 tests/core/container/test_core_small_array.odin diff --git a/core/container/small_array/small_array.odin b/core/container/small_array/small_array.odin index b8210d1b0..b471d1706 100644 --- a/core/container/small_array/small_array.odin +++ b/core/container/small_array/small_array.odin @@ -1,6 +1,8 @@ package container_small_array import "core:builtin" +import "core:runtime" +_ :: runtime Small_Array :: struct($N: int, $T: typeid) where N >= 0 { data: [N]T, @@ -32,6 +34,20 @@ get_ptr :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int) -> ^T { return &a.data[index] } +get_safe :: proc(a: $A/Small_Array($N, $T), index: int) -> (T, bool) #no_bounds_check { + if index < 0 || index >= a.len { + return {}, false + } + return a.data[index], true +} + +get_ptr_safe :: proc(a: ^$A/Small_Array($N, $T), index: int) -> (^T, bool) #no_bounds_check { + if index < 0 || index >= a.len { + return {}, false + } + return &a.data[index], true +} + set :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, item: T) { a.data[index] = item } @@ -93,7 +109,7 @@ pop_front_safe :: proc "contextless" (a: ^$A/Small_Array($N, $T)) -> (item: T, o copy(s[:], s[1:]) a.len -= 1 ok = true - } + } return } @@ -102,6 +118,23 @@ consume :: proc "odin" (a: ^$A/Small_Array($N, $T), count: int, loc := #caller_l a.len -= count } +ordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check { + runtime.bounds_check_error_loc(loc, index, a.len) + if index+1 < a.len { + copy(a.data[index:], a.data[index+1:]) + } + a.len -= 1 +} + +unordered_remove :: proc "contextless" (a: ^$A/Small_Array($N, $T), index: int, loc := #caller_location) #no_bounds_check { + runtime.bounds_check_error_loc(loc, index, a.len) + n := a.len-1 + if index != n { + a.data[index] = a.data[n] + } + a.len -= 1 +} + clear :: proc "contextless" (a: ^$A/Small_Array($N, $T)) { resize(a, 0) } @@ -111,6 +144,18 @@ push_back_elems :: proc "contextless" (a: ^$A/Small_Array($N, $T), items: ..T) { a.len += n } +inject_at :: proc "contextless" (a: ^$A/Small_Array($N, $T), item: T, index: int) -> bool #no_bounds_check { + if a.len < cap(a^) && index >= 0 && index <= len(a^) { + a.len += 1 + for i := a.len - 1; i >= index + 1; i -= 1 { + a.data[i] = a.data[i - 1] + } + a.data[index] = item + return true + } + return false +} + append_elem :: push_back append_elems :: push_back_elems push :: proc{push_back, push_back_elems} diff --git a/tests/core/build.bat b/tests/core/build.bat index 94f8e0fd8..69a102daa 100644 --- a/tests/core/build.bat +++ b/tests/core/build.bat @@ -74,4 +74,9 @@ echo --- echo --- echo Running core:slice tests echo --- -%PATH_TO_ODIN% run slice %COMMON% -out:test_core_slice.exe \ No newline at end of file +%PATH_TO_ODIN% run slice %COMMON% -out:test_core_slice.exe + +echo --- +echo Running core:container tests +echo --- +%PATH_TO_ODIN% run container %COMMON% %COLLECTION% -out:test_core_container.exe diff --git a/tests/core/container/test_core_small_array.odin b/tests/core/container/test_core_small_array.odin new file mode 100644 index 000000000..88bc8e532 --- /dev/null +++ b/tests/core/container/test_core_small_array.odin @@ -0,0 +1,56 @@ +package test_core_compress + +import "core:fmt" +import "core:testing" +import "core:container/small_array" +import tc "tests:common" + +main :: proc() { + t := testing.T{} + test_small_array_removes(&t) + test_small_array_inject_at(&t) + tc.report(&t) +} + +expect_equal :: proc(t: ^testing.T, the_slice, expected: []int, loc := #caller_location) { + _eq :: proc(a, b: []int) -> bool { + if len(a) != len(b) do return false + for a, i in a { + if b[i] != a do return false + } + return true + } + tc.expect(t, _eq(the_slice, expected), fmt.tprintf("Expected %v, got %v\n", the_slice, expected), loc) +} + +@test +test_small_array_removes :: proc(t: ^testing.T) { + array: small_array.Small_Array(10, int) + small_array.append(&array, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) + + small_array.ordered_remove(&array, 0) + expect_equal(t, small_array.slice(&array), []int { 1, 2, 3, 4, 5, 6, 7, 8, 9 }) + small_array.ordered_remove(&array, 5) + expect_equal(t, small_array.slice(&array), []int { 1, 2, 3, 4, 5, 7, 8, 9 }) + small_array.ordered_remove(&array, 6) + expect_equal(t, small_array.slice(&array), []int { 1, 2, 3, 4, 5, 7, 9 }) + small_array.unordered_remove(&array, 0) + expect_equal(t, small_array.slice(&array), []int { 9, 2, 3, 4, 5, 7 }) + small_array.unordered_remove(&array, 2) + expect_equal(t, small_array.slice(&array), []int { 9, 2, 7, 4, 5 }) + small_array.unordered_remove(&array, 4) + expect_equal(t, small_array.slice(&array), []int { 9, 2, 7, 4 }) +} + +@test +test_small_array_inject_at :: proc(t: ^testing.T) { + array: small_array.Small_Array(13, int) + small_array.append(&array, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) + + tc.expect(t, small_array.inject_at(&array, 0, 0), "Expected to be able to inject into small array") + expect_equal(t, small_array.slice(&array), []int { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }) + tc.expect(t, small_array.inject_at(&array, 0, 5), "Expected to be able to inject into small array") + expect_equal(t, small_array.slice(&array), []int { 0, 0, 1, 2, 3, 0, 4, 5, 6, 7, 8, 9 }) + tc.expect(t, small_array.inject_at(&array, 0, small_array.len(array)), "Expected to be able to inject into small array") + expect_equal(t, small_array.slice(&array), []int { 0, 0, 1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 0 }) +} From 81037b30919340b4d2d0cf1304fbf8fde0591c1f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 21 Dec 2022 23:56:34 +0000 Subject: [PATCH 3/3] Change the order of the args and ret for Arm64 ABI --- src/llvm_abi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm_abi.cpp b/src/llvm_abi.cpp index 166fcb3ee..2cabc2dc7 100644 --- a/src/llvm_abi.cpp +++ b/src/llvm_abi.cpp @@ -987,8 +987,8 @@ namespace lbAbiArm64 { LB_ABI_INFO(abi_info) { lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); ft->ctx = c; + ft->args = compute_arg_types(c, arg_types, arg_count); ft->ret = compute_return_type(ft, c, return_type, return_is_defined, return_is_tuple); - ft -> args = compute_arg_types(c, arg_types, arg_count); ft->calling_convention = calling_convention; return ft; }