|  | 
|  | 1 | +use std::{env, f64, hint, io}; | 
|  | 2 | + | 
| 1 | 3 | #[cfg(target_os = "hermit")] | 
| 2 | 4 | use hermit as _; | 
| 3 | 5 | 
 | 
|  | 6 | +mod fs; | 
| 4 | 7 | mod laplace; | 
| 5 | 8 | mod matmul; | 
| 6 |  | -mod tests; | 
| 7 |  | -mod thread_local; | 
|  | 9 | +mod pi; | 
|  | 10 | +mod thread; | 
|  | 11 | + | 
|  | 12 | +fn main() -> io::Result<()> { | 
|  | 13 | +	hello(); | 
|  | 14 | +	print_env(); | 
|  | 15 | +	arithmetic(); | 
|  | 16 | +	thread::sleep(); | 
|  | 17 | +	thread::spawn()?; | 
|  | 18 | +	fs::fs()?; | 
|  | 19 | +	pi::pi(); | 
|  | 20 | +	matmul::matmul(); | 
|  | 21 | +	laplace::laplace(); | 
|  | 22 | +	Ok(()) | 
|  | 23 | +} | 
|  | 24 | + | 
|  | 25 | +pub fn hello() { | 
|  | 26 | +	eprintln!(); | 
|  | 27 | +	eprintln!("Hello, Hermit! 🦀"); | 
|  | 28 | +	eprintln!("Hello, world!"); | 
|  | 29 | +	eprintln!("Привет, мир!"); | 
|  | 30 | +	eprintln!("こんにちは世界!"); | 
|  | 31 | +	eprintln!("你好世界!"); | 
|  | 32 | +	eprintln!("สวัสดีชาวโลก!"); | 
|  | 33 | +	eprintln!("Chào thế giới!"); | 
|  | 34 | +} | 
| 8 | 35 | 
 | 
| 9 |  | -use tests::*; | 
|  | 36 | +pub fn print_env() { | 
|  | 37 | +	eprintln!(); | 
|  | 38 | +	eprintln!("Arguments:"); | 
|  | 39 | +	for argument in env::args() { | 
|  | 40 | +		eprintln!("{argument}"); | 
|  | 41 | +	} | 
| 10 | 42 | 
 | 
| 11 |  | -fn test_result<T>(result: Result<(), T>) -> &'static str { | 
| 12 |  | -	match result { | 
| 13 |  | -		Ok(_) => "ok", | 
| 14 |  | -		Err(_) => "failed!", | 
|  | 43 | +	eprintln!(); | 
|  | 44 | +	eprintln!("Environment variables:"); | 
|  | 45 | +	for (key, value) in env::vars() { | 
|  | 46 | +		eprintln!("{key}: {value}"); | 
| 15 | 47 | 	} | 
| 16 | 48 | } | 
| 17 | 49 | 
 | 
| 18 |  | -fn main() { | 
| 19 |  | -	println!("Test {} ... {}", stringify!(hello), test_result(hello())); | 
| 20 |  | -	println!( | 
| 21 |  | -		"Test {} ... {}", | 
| 22 |  | -		stringify!(sleep), | 
| 23 |  | -		test_result(test_sleep()) | 
| 24 |  | -	); | 
| 25 |  | -	println!( | 
| 26 |  | -		"Test {} ... {}", | 
| 27 |  | -		stringify!(test_thread_local), | 
| 28 |  | -		test_result(thread_local::test_thread_local()) | 
| 29 |  | -	); | 
| 30 |  | -	println!( | 
| 31 |  | -		"Test {} ... {}", | 
| 32 |  | -		stringify!(arithmetic), | 
| 33 |  | -		test_result(arithmetic()) | 
| 34 |  | -	); | 
| 35 |  | -	println!( | 
| 36 |  | -		"Test {} ... {}", | 
| 37 |  | -		stringify!(print_argv), | 
| 38 |  | -		test_result(print_argv()) | 
| 39 |  | -	); | 
| 40 |  | -	println!( | 
| 41 |  | -		"Test {} ... {}", | 
| 42 |  | -		stringify!(print_env), | 
| 43 |  | -		test_result(print_env()) | 
| 44 |  | -	); | 
| 45 |  | -	println!( | 
| 46 |  | -		"Test {} ... {}", | 
| 47 |  | -		stringify!(read_file), | 
| 48 |  | -		test_result(read_file()) | 
| 49 |  | -	); | 
| 50 |  | -	println!( | 
| 51 |  | -		"Test {} ... {}", | 
| 52 |  | -		stringify!(read_dir), | 
| 53 |  | -		test_result(read_dir()) | 
| 54 |  | -	); | 
| 55 |  | -	println!( | 
| 56 |  | -		"Test {} ... {}", | 
| 57 |  | -		stringify!(create_file), | 
| 58 |  | -		test_result(create_file()) | 
| 59 |  | -	); | 
| 60 |  | -	println!( | 
| 61 |  | -		"Test {} ... {}", | 
| 62 |  | -		stringify!(threading), | 
| 63 |  | -		test_result(threading()) | 
| 64 |  | -	); | 
| 65 |  | -	println!( | 
| 66 |  | -		"Test {} ... {}", | 
| 67 |  | -		stringify!(pi_sequential), | 
| 68 |  | -		test_result(pi_sequential(5000000)) | 
| 69 |  | -	); | 
| 70 |  | -	println!( | 
| 71 |  | -		"Test {} ... {}", | 
| 72 |  | -		stringify!(pi_parallel), | 
| 73 |  | -		test_result(pi_parallel(5000000)) | 
| 74 |  | -	); | 
| 75 |  | -	println!( | 
| 76 |  | -		"Test {} ... {}", | 
| 77 |  | -		stringify!(laplace), | 
| 78 |  | -		test_result(laplace::laplace(128, 128)) | 
| 79 |  | -	); | 
| 80 |  | -	println!( | 
| 81 |  | -		"Test {} ... {}", | 
| 82 |  | -		stringify!(test_matmul_strassen), | 
| 83 |  | -		test_result(matmul::test_matmul_strassen()) | 
| 84 |  | -	); | 
| 85 |  | -	println!( | 
| 86 |  | -		"Test {} ... {}", | 
| 87 |  | -		stringify!(thread_creation), | 
| 88 |  | -		test_result(thread_creation()) | 
| 89 |  | -	); | 
|  | 50 | +pub fn arithmetic() { | 
|  | 51 | +	eprintln!(); | 
|  | 52 | + | 
|  | 53 | +	let x = hint::black_box(f64::consts::PI) * 2.0; | 
|  | 54 | +	let y: f64 = hint::black_box(x).exp(); | 
|  | 55 | +	let z: f64 = hint::black_box(y).ln(); | 
|  | 56 | + | 
|  | 57 | +	eprintln!("x = {x}"); | 
|  | 58 | +	eprintln!("e^x = {y}"); | 
|  | 59 | +	eprintln!("ln(e^x) = {z}"); | 
| 90 | 60 | } | 
0 commit comments