adding more tests and organizing things

This commit is contained in:
Jakub Doka 2024-10-20 15:33:32 +02:00
parent 44c4b71bb3
commit ccfde6c237
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
6 changed files with 104 additions and 40 deletions

View file

@ -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
}

View file

@ -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;

View file

@ -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(())

View file

@ -0,0 +1,6 @@
main:
LI64 r1, 1d
JALA r0, r31, 0a
code size: 29
ret: 1
status: Ok(())

View file

@ -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(())

View file

@ -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(())