general improvements
including rust arg taking, rust feature work and changing the name of the executable in ada
This commit is contained in:
parent
a4638192c6
commit
26a7b3d447
8 changed files with 54 additions and 15 deletions
|
@ -6,4 +6,8 @@ project Zad2 is
|
||||||
for Source_Dirs use ("src", Impl);
|
for Source_Dirs use ("src", Impl);
|
||||||
for Object_Dir use "target";
|
for Object_Dir use "target";
|
||||||
|
|
||||||
|
package Builder is
|
||||||
|
for Executable ("main.adb") use "z2";
|
||||||
|
end Builder;
|
||||||
|
|
||||||
end Zad2;
|
end Zad2;
|
||||||
|
|
|
@ -2,3 +2,7 @@
|
||||||
name = "zad3"
|
name = "zad3"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
iter = []
|
||||||
|
rec = []
|
||||||
|
|
|
@ -6,29 +6,28 @@ use crate::module::{Module, ModuleIter, ModuleRec};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = env::args().collect::<Vec<_>>();
|
let args = env::args().collect::<Vec<_>>();
|
||||||
if args.len() != 2 {
|
if args.len() != 4 {
|
||||||
eprintln!("usage: {} <impl>" /*<a> <b> <c>"*/, args[0]);
|
eprintln!("usage: {} <a> <b> <c>", args[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let r#impl = &args[1];
|
let a = args[1].parse::<i64>().expect("failed to parse a");
|
||||||
// let a = args[2].parse::<i64>().expect("failed to parse a");
|
let b = args[2].parse::<i64>().expect("failed to parse b");
|
||||||
// let b = args[3].parse::<i64>().expect("failed to parse b");
|
let c = args[3].parse::<i64>().expect("failed to parse c");
|
||||||
// let c = args[4].parse::<i64>().expect("failed to parse c");
|
|
||||||
|
|
||||||
let module: Box<dyn Module> =
|
let module: Box<dyn Module> =
|
||||||
if r#impl == "iter" {
|
if cfg!(feature = "iter") {
|
||||||
Box::new(ModuleIter {})
|
Box::new(ModuleIter {})
|
||||||
} else if r#impl == "rec" {
|
} else if cfg!(feature = "rec") {
|
||||||
Box::new(ModuleRec {})
|
Box::new(ModuleRec {})
|
||||||
} else {
|
} else {
|
||||||
eprintln!("unknown module type");
|
eprintln!("unknown module type");
|
||||||
exit(1);
|
exit(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("gcd(a, b): {}", module.gcd(10, 5));
|
println!("gcd(a, b): {}", module.gcd(a as u64, b as u64));
|
||||||
println!("factorial(a): {}", module.factorial(5));
|
println!("factorial(a): {}", module.factorial(a as u64));
|
||||||
let r = module.diophantine(1027, 712, 1);
|
let r = module.diophantine(a, b, c);
|
||||||
print!("diophantine(a, b, c): ");
|
print!("diophantine(a, b, c): ");
|
||||||
if r.is_none() {
|
if r.is_none() {
|
||||||
println!("there's no solution");
|
println!("there's no solution");
|
||||||
|
|
|
@ -8,4 +8,8 @@ project Zad4 is
|
||||||
for Source_Dirs use ("src", "include", Impl);
|
for Source_Dirs use ("src", "include", Impl);
|
||||||
for Object_Dir use "target";
|
for Object_Dir use "target";
|
||||||
|
|
||||||
|
package Builder is
|
||||||
|
for Executable ("main.c") use "z4";
|
||||||
|
end Builder;
|
||||||
|
|
||||||
end Zad4;
|
end Zad4;
|
||||||
|
|
|
@ -8,4 +8,8 @@ project Zad5 is
|
||||||
for Source_Dirs use ("src", Impl);
|
for Source_Dirs use ("src", Impl);
|
||||||
for Object_Dir use "target";
|
for Object_Dir use "target";
|
||||||
|
|
||||||
|
package Builder is
|
||||||
|
for Executable ("main.adb") use "z5";
|
||||||
|
end Builder;
|
||||||
|
|
||||||
end Zad5;
|
end Zad5;
|
||||||
|
|
|
@ -8,3 +8,7 @@ libc = "0.2.153"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cc = "1.0.90"
|
cc = "1.0.90"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
iter = []
|
||||||
|
rec = []
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
extern crate cc;
|
extern crate cc;
|
||||||
|
|
||||||
fn main() {
|
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()
|
cc::Build::new()
|
||||||
.file("src/mod_iter.c")
|
.file(module)
|
||||||
.shared_flag(true)
|
.shared_flag(true)
|
||||||
.compile("mod.a");
|
.compile("mod.a");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::{env, process::exit};
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Result {
|
pub struct Result {
|
||||||
pub resultExists: libc::c_int,
|
pub resultExists: libc::c_int,
|
||||||
|
@ -15,9 +17,19 @@ extern "C" {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
println!("gcd(a, b): {}", gcd(10, 5));
|
let args = env::args().collect::<Vec<_>>();
|
||||||
println!("factorial(a): {}", factorial(5));
|
if args.len() != 4 {
|
||||||
let r = diophantine(1027, 712, 1);
|
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): ");
|
print!("diophantine(a, b, c): ");
|
||||||
if r.resultExists == 0 {
|
if r.resultExists == 0 {
|
||||||
println!("there's no solution");
|
println!("there's no solution");
|
||||||
|
|
Loading…
Reference in a new issue