general improvements

including rust arg taking, rust feature work and changing the name of
the executable in ada
This commit is contained in:
jacekpoz 2024-03-22 13:09:09 +01:00
parent a4638192c6
commit 26a7b3d447
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
8 changed files with 54 additions and 15 deletions

View file

@ -6,4 +6,8 @@ project Zad2 is
for Source_Dirs use ("src", Impl);
for Object_Dir use "target";
package Builder is
for Executable ("main.adb") use "z2";
end Builder;
end Zad2;

View file

@ -2,3 +2,7 @@
name = "zad3"
version = "0.1.0"
edition = "2021"
[features]
iter = []
rec = []

View file

@ -6,29 +6,28 @@ use crate::module::{Module, ModuleIter, ModuleRec};
fn main() {
let args = env::args().collect::<Vec<_>>();
if args.len() != 2 {
eprintln!("usage: {} <impl>" /*<a> <b> <c>"*/, args[0]);
if args.len() != 4 {
eprintln!("usage: {} <a> <b> <c>", args[0]);
exit(1);
}
let r#impl = &args[1];
// let a = args[2].parse::<i64>().expect("failed to parse a");
// let b = args[3].parse::<i64>().expect("failed to parse b");
// let c = args[4].parse::<i64>().expect("failed to parse c");
let a = args[1].parse::<i64>().expect("failed to parse a");
let b = args[2].parse::<i64>().expect("failed to parse b");
let c = args[3].parse::<i64>().expect("failed to parse c");
let module: Box<dyn Module> =
if r#impl == "iter" {
if cfg!(feature = "iter") {
Box::new(ModuleIter {})
} else if r#impl == "rec" {
} else if cfg!(feature = "rec") {
Box::new(ModuleRec {})
} else {
eprintln!("unknown module type");
exit(1);
};
println!("gcd(a, b): {}", module.gcd(10, 5));
println!("factorial(a): {}", module.factorial(5));
let r = module.diophantine(1027, 712, 1);
println!("gcd(a, b): {}", module.gcd(a as u64, b as u64));
println!("factorial(a): {}", module.factorial(a as u64));
let r = module.diophantine(a, b, c);
print!("diophantine(a, b, c): ");
if r.is_none() {
println!("there's no solution");

View file

@ -8,4 +8,8 @@ project Zad4 is
for Source_Dirs use ("src", "include", Impl);
for Object_Dir use "target";
package Builder is
for Executable ("main.c") use "z4";
end Builder;
end Zad4;

View file

@ -8,4 +8,8 @@ project Zad5 is
for Source_Dirs use ("src", Impl);
for Object_Dir use "target";
package Builder is
for Executable ("main.adb") use "z5";
end Builder;
end Zad5;

View file

@ -8,3 +8,7 @@ libc = "0.2.153"
[build-dependencies]
cc = "1.0.90"
[features]
iter = []
rec = []

View file

@ -1,8 +1,16 @@
extern crate cc;
fn main() {
let module =
if cfg!(feature = "iter") {
"src/mod_iter.c"
} else if cfg!(feature = "rec") {
"src/mod_rec.c"
} else {
panic!("unknown module type")
};
cc::Build::new()
.file("src/mod_iter.c")
.file(module)
.shared_flag(true)
.compile("mod.a");
}

View file

@ -1,3 +1,5 @@
use std::{env, process::exit};
#[repr(C)]
pub struct Result {
pub resultExists: libc::c_int,
@ -15,9 +17,19 @@ extern "C" {
fn main() {
unsafe {
println!("gcd(a, b): {}", gcd(10, 5));
println!("factorial(a): {}", factorial(5));
let r = diophantine(1027, 712, 1);
let args = env::args().collect::<Vec<_>>();
if args.len() != 4 {
eprintln!("usage: {} <a> <b> <c>", args[0]);
exit(1);
}
let a = args[1].parse::<i32>().expect("failed to parse a");
let b = args[2].parse::<i32>().expect("failed to parse b");
let c = args[3].parse::<i32>().expect("failed to parse c");
println!("gcd(a, b): {}", gcd(a as u32, b as u32));
println!("factorial(a): {}", factorial(a as u32));
let r = diophantine(a, b, c);
print!("diophantine(a, b, c): ");
if r.resultExists == 0 {
println!("there's no solution");