Compare commits

..

No commits in common. "a40d4c3410a86c82e7045d2750dbde50c10e9923" and "e0535acc917dc2c4f9dfd89f16bcbcb65f6ad3fb" have entirely different histories.

4 changed files with 7 additions and 43 deletions

View file

@ -64,17 +64,16 @@
get_instant = 0.0 get_instant = 0.0
[types.gen_integer] [types.gen_integer]
expr_add = 0.2 expr_add = 0.0
expr_sub = 0.2 expr_sub = 0.0
expr_mul = 0.1 expr_mul = 0.0
expr_div = 0.1 expr_div = 0.0
expr_rem = 0.0 expr_rem = 0.0
expr_exp = 0.0 expr_exp = 0.0
expr_pos = 0.0 expr_pos = 0.0
expr_neg = 0.0 expr_neg = 0.0
get_instant = 0.4 get_instant = 0.0
max_depth = 20
[types.gen_real] [types.gen_real]
expr_add = 0.0 expr_add = 0.0

View file

@ -135,7 +135,7 @@ impl BinaryOperator {
} }
} }
pub fn subtract(left: Expr, right: Expr) -> Self { pub fn sub(left: Expr, right: Expr) -> Self {
let is_both_same = left.get_base() == right.get_base(); let is_both_same = left.get_base() == right.get_base();
let is_one_real = left.get_base() == BaseType::Real || right.get_base() == BaseType::Real; let is_one_real = left.get_base() == BaseType::Real || right.get_base() == BaseType::Real;
let is_one_int = left.get_base() == BaseType::Int || right.get_base() == BaseType::Int; let is_one_int = left.get_base() == BaseType::Int || right.get_base() == BaseType::Int;

View file

@ -6,18 +6,12 @@ use std::collections::HashMap;
use crate::params::Params; use crate::params::Params;
use crate::ast::*; use crate::ast::*;
#[derive(Default)]
struct StateTracking {
int_recursion_depth: u32,
}
pub struct AstBuilder { pub struct AstBuilder {
params: Params, params: Params,
ast: GlobalBlock, ast: GlobalBlock,
name_counter: u64, name_counter: u64,
typedef_map: HashMap<BaseType, Vec<String>>, typedef_map: HashMap<BaseType, Vec<String>>,
typedef_vec: Vec<(String, BaseType)>, typedef_vec: Vec<(String, BaseType)>,
state: StateTracking,
// Random generation // Random generation
rng: rand::rngs::ThreadRng, rng: rand::rngs::ThreadRng,
rng_float: FloatGenerator, rng_float: FloatGenerator,
@ -39,7 +33,6 @@ impl AstBuilder {
name_counter: 0, name_counter: 0,
typedef_map, typedef_map,
typedef_vec, typedef_vec,
state: StateTracking::default(),
rng: rand::thread_rng(), rng: rand::thread_rng(),
rng_float: FloatGenerator::new(&params), rng_float: FloatGenerator::new(&params),
rng_int: IntGenerator::new(&params), rng_int: IntGenerator::new(&params),
@ -126,34 +119,7 @@ impl AstBuilder {
} }
fn gen_integer(&mut self) -> Expr { fn gen_integer(&mut self) -> Expr {
let p: f64 = self.rng.gen(); Expr::new_literal(self.gen_literal(BaseType::Int))
let mut ps = &self.params.types.gen_integer;
self.state.int_recursion_depth += 1;
if p < ps.get_instant || self.state.int_recursion_depth >= ps.max_depth {
self.state.int_recursion_depth -= 1;
return Expr::new_literal(self.gen_literal(BaseType::Int));
}
let lhs = self.gen_integer();
let rhs = self.gen_integer();
self.state.int_recursion_depth -= 1;
ps = &self.params.types.gen_integer;
if p < ps.get_instant + ps.expr_add {
Expr::new_binary_op(BinaryOperator::add(lhs, rhs))
} else if p < ps.get_instant + ps.expr_add + ps.expr_sub {
Expr::new_binary_op(BinaryOperator::subtract(lhs, rhs))
} else if p < ps.get_instant + ps.expr_add + ps.expr_sub + ps.expr_mul {
Expr::new_binary_op(BinaryOperator::multiply(lhs, rhs))
} else if p < ps.get_instant + ps.expr_add + ps.expr_sub + ps.expr_mul + ps.expr_div {
Expr::new_binary_op(BinaryOperator::divide(lhs, rhs))
} else {
Expr::new_literal(self.gen_literal(BaseType::Int)) // TODO: this shouldn't be here
}
} }
fn gen_real(&mut self) -> Expr { fn gen_real(&mut self) -> Expr {

View file

@ -132,7 +132,6 @@ toml_struct!{
expr_pos: f64, expr_pos: f64,
expr_neg: f64, expr_neg: f64,
get_instant: f64, get_instant: f64,
max_depth: u32,
} }
} }