From ccfde6c237116a2f9163490c0ba929d5a3f91de3 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sun, 20 Oct 2024 15:33:32 +0200 Subject: [PATCH] adding more tests and organizing things --- lang/README.md | 37 +++++++------- lang/src/son.rs | 50 +++++++++++-------- ...ts_comptime_function_from_another_file.txt | 7 +++ lang/tests/son_tests_main_fn.txt | 6 +++ .../son_tests_sort_something_viredly.txt | 29 +++++++++++ lang/tests/son_tests_writing_into_string.txt | 15 ++++++ 6 files changed, 104 insertions(+), 40 deletions(-) create mode 100644 lang/tests/son_tests_comptime_function_from_another_file.txt create mode 100644 lang/tests/son_tests_main_fn.txt create mode 100644 lang/tests/son_tests_sort_something_viredly.txt create mode 100644 lang/tests/son_tests_writing_into_string.txt diff --git a/lang/README.md b/lang/README.md index 986088a..771bf54 100644 --- a/lang/README.md +++ b/lang/README.md @@ -41,7 +41,7 @@ Following examples incrementally introduce language features and syntax. #### main_fn ```hb main := fn(): int { - return 1; + return 1 } ``` @@ -191,6 +191,21 @@ odher_pass := fn(t: Ty2): Ty2 { } ``` +#### hex_octal_binary_literals +```hb +main := fn(): int { + hex := 0xFF + decimal := 255 + octal := 0o377 + binary := 0b11111111 + + if hex == decimal & octal == decimal & binary == decimal { + return 0 + } + return 1 +} +``` + #### struct_operators ```hb Point := struct { @@ -619,8 +634,7 @@ Foo := struct {x: int, y: u32, z: u32} #### sort_something_viredly ```hb main := fn(): int { - foo := sqrt - return 0 + return sqrt(1) } sqrt := fn(x: int): int { @@ -642,21 +656,6 @@ sqrt := fn(x: int): int { } ``` -#### hex_octal_binary_literals -```hb -main := fn(): int { - hex := 0xFF - decimal := 255 - octal := 0o377 - binary := 0b11111111 - - if hex == decimal & octal == decimal & binary == decimal { - return 0 - } - return 1 -} -``` - #### structs_in_registers ```hb ColorBGRA := struct {b: u8, g: u8, r: u8, a: u8} @@ -824,7 +823,7 @@ integer_range := fn(min: uint, max: int): uint { ```hb outl := fn(): void { msg := "whahaha\0" - @as(u8, 0) + _u := @as(u8, 0) return } diff --git a/lang/src/son.rs b/lang/src/son.rs index e9eebad..9e5c380 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -3268,44 +3268,52 @@ mod tests { } crate::run_tests! { generate: + // Tour Examples + main_fn; arithmetic; - variables; functions; comments; if_statements; + variables; loops; - fb_driver; pointers; structs; - //different_types; + hex_octal_binary_literals; //struct_operators; - //directives; global_variables; - //generic_types; - //generic_functions; + //directives; c_strings; //struct_patterns; arrays; - //struct_return_from_module_function; - ////comptime_pointers; - //sort_something_viredly; - hex_octal_binary_literals; - //comptime_min_reg_leak; - ////structs_in_registers; - //comptime_function_from_another_file; //inline; + //idk; + //wide_ret; + + // Incomplete Examples; + //comptime_pointers; + //generic_types; + //generic_functions; + fb_driver; + + // Purely Testing Examples; + comptime_min_reg_leak; + //different_types; + //struct_return_from_module_function; + sort_something_viredly; + //structs_in_registers; + comptime_function_from_another_file; //inline_test; + //inlined_generic_functions; + //some_generic_code; + //integer_inference_issues; + writing_into_string; + //request_page; + //tests_ptr_to_ptr_copy; + + // Just Testing Optimizations; const_folding_with_arg; branch_assignments; exhaustive_loop_testing; - //idk; - comptime_min_reg_leak; - //some_generic_code; - //integer_inference_issues; - //writing_into_string; - //request_page; - //tests_ptr_to_ptr_copy; - //wide_ret; pointer_opts; conditional_stores; loop_stores; diff --git a/lang/tests/son_tests_comptime_function_from_another_file.txt b/lang/tests/son_tests_comptime_function_from_another_file.txt new file mode 100644 index 0000000..a9b8fb9 --- /dev/null +++ b/lang/tests/son_tests_comptime_function_from_another_file.txt @@ -0,0 +1,7 @@ +main: + LRA r1, r0, :a + LD r1, r1, 0a, 8h + JALA r0, r31, 0a +code size: 47 +ret: 50 +status: Ok(()) diff --git a/lang/tests/son_tests_main_fn.txt b/lang/tests/son_tests_main_fn.txt new file mode 100644 index 0000000..ecb617f --- /dev/null +++ b/lang/tests/son_tests_main_fn.txt @@ -0,0 +1,6 @@ +main: + LI64 r1, 1d + JALA r0, r31, 0a +code size: 29 +ret: 1 +status: Ok(()) diff --git a/lang/tests/son_tests_sort_something_viredly.txt b/lang/tests/son_tests_sort_something_viredly.txt new file mode 100644 index 0000000..0212f2f --- /dev/null +++ b/lang/tests/son_tests_sort_something_viredly.txt @@ -0,0 +1,29 @@ +main: + ADDI64 r254, r254, -8d + ST r31, r254, 0a, 8h + LI64 r2, 1d + JAL r31, r0, :sqrt + LD r31, r254, 0a, 8h + ADDI64 r254, r254, 8d + JALA r0, r31, 0a +sqrt: + LI64 r7, 15d + LI64 r8, 32768d + LI64 r5, 0d + CP r1, r5 + 3: JNE r8, r5, :0 + JMP :1 + 0: SLUI64 r4, r1, 1b + ADDI64 r7, r7, -1d + ADD64 r9, r4, r8 + SLU64 r9, r9, r7 + JLTU r2, r9, :2 + ADD64 r1, r8, r1 + SUB64 r2, r2, r9 + JMP :2 + 2: SRUI64 r8, r8, 1b + JMP :3 + 1: JALA r0, r31, 0a +code size: 188 +ret: 0 +status: Ok(()) diff --git a/lang/tests/son_tests_writing_into_string.txt b/lang/tests/son_tests_writing_into_string.txt new file mode 100644 index 0000000..7247085 --- /dev/null +++ b/lang/tests/son_tests_writing_into_string.txt @@ -0,0 +1,15 @@ +inl: + JALA r0, r31, 0a +main: + ADDI64 r254, r254, -8d + ST r31, r254, 0a, 8h + JAL r31, r0, :outl + JAL r31, r0, :inl + LD r31, r254, 0a, 8h + ADDI64 r254, r254, 8d + JALA r0, r31, 0a +outl: + JALA r0, r31, 0a +code size: 103 +ret: 0 +status: Ok(())