AstBuilder: switch to global decls
All checks were successful
ci/woodpecker/push/build_rust Pipeline was successful

This commit is contained in:
Akemi Izuko 2023-11-18 13:18:10 -07:00
parent 4f6f81714d
commit 5c80987aa5
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
3 changed files with 17 additions and 6 deletions

View file

@ -26,8 +26,8 @@ verify_config = true
[statements.gen_global_decl] [statements.gen_global_decl]
gen_boolean = 0.0 gen_boolean = 0.0
gen_character = 0.0 gen_character = 0.0
gen_integer = 0.0 gen_integer = 0.5
gen_real = 0.0 gen_real = 0.5
gen_tuple = 0.0 gen_tuple = 0.0
[statements.gen_if_statement] [statements.gen_if_statement]

View file

@ -59,15 +59,15 @@ impl AstBuilder {
let typedef = self.gen_typedef(); let typedef = self.gen_typedef();
self.ast.push(typedef); self.ast.push(typedef);
} else { } else {
let decl = self.gen_decl(); let decl = self.gen_global_decl();
self.ast.push(decl); self.ast.push(decl);
} }
} }
} }
fn gen_decl(&mut self) -> Stat { fn gen_global_decl(&mut self) -> Stat {
let mut p: f64 = self.rng.gen(); let mut p: f64 = self.rng.gen();
let ps = &self.params.statements.gen_decl; let ps = &self.params.statements.gen_global_decl;
let t: BaseType; let t: BaseType;
let assn: Expr; let assn: Expr;

View file

@ -176,9 +176,20 @@ toml_struct!{
impl GenGlobalDecl { impl GenGlobalDecl {
fn verify(&self) -> Result<(), String> { fn verify(&self) -> Result<(), String> {
let sum_type = self.gen_boolean
+ self.gen_character
+ self.gen_integer
+ self.gen_real
+ self.gen_tuple;
if (sum_type - 1.0).abs() > f64::EPSILON {
Err(format!("statements.gen_global_decl probability sum for types is = {}", sum_type))
} else {
Ok(()) Ok(())
} }
} }
}
toml_struct!{ toml_struct!{
struct GenIfStatement { struct GenIfStatement {