Compare commits
No commits in common. "f9e4e554b6e9adf5348c1366fcde5dc61e0bf1aa" and "d70d12ea1f5f5207838639bd0afdf0c326305544" have entirely different histories.
f9e4e554b6
...
d70d12ea1f
|
@ -1,19 +1,18 @@
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
mod expr;
|
mod expr;
|
||||||
mod statement;
|
mod statement;
|
||||||
|
|
||||||
pub use expr::Expr;
|
use std::fmt;
|
||||||
pub use expr::Literal;
|
|
||||||
pub use expr::Variable;
|
|
||||||
pub use expr::VariableBuilder;
|
|
||||||
pub use expr::BinaryOperator;
|
|
||||||
|
|
||||||
pub use statement::Stat;
|
use expr::{
|
||||||
pub use statement::Block;
|
Expr,
|
||||||
pub use statement::GlobalBlock;
|
Literal,
|
||||||
pub use statement::Declaration;
|
Variable,
|
||||||
pub use statement::DeclarationBuilder;
|
BinaryOperator,
|
||||||
|
};
|
||||||
|
|
||||||
|
use statement::Stat;
|
||||||
|
use statement::Block;
|
||||||
|
use statement::GlobalBlock;
|
||||||
|
|
||||||
pub trait GazType {
|
pub trait GazType {
|
||||||
fn get_base(&self) -> BaseType;
|
fn get_base(&self) -> BaseType;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use rand_distr::Distribution;
|
||||||
use crate::params::Params;
|
use crate::params::Params;
|
||||||
use crate::ast::{
|
use crate::ast::{
|
||||||
Expr,
|
Expr,
|
||||||
Stat,
|
Statement,
|
||||||
Quantifier,
|
Quantifier,
|
||||||
BaseType,
|
BaseType,
|
||||||
GlobalBlock,
|
GlobalBlock,
|
||||||
|
@ -39,6 +39,7 @@ impl AstBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate(&mut self) {
|
pub fn generate(&mut self) {
|
||||||
|
|
||||||
let mut p: f64;
|
let mut p: f64;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -53,48 +54,54 @@ impl AstBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_decl(&mut self) -> Stat {
|
fn gen_decl(&mut self) -> Box<dyn Statement> {
|
||||||
let p: f64 = self.rng.gen();
|
let p: f64 = self.rng.gen();
|
||||||
let ps = &self.params.statements.gen_decl;
|
let ps = &self.params.statements.gen_decl;
|
||||||
|
|
||||||
let t: BaseType;
|
let t = if p < ps.gen_integer {
|
||||||
let assn: Expr;
|
BaseType::Int
|
||||||
|
|
||||||
if p < ps.gen_integer {
|
|
||||||
t = BaseType::Int;
|
|
||||||
assn = self.gen_integer();
|
|
||||||
} else {
|
} else {
|
||||||
t = BaseType::Real;
|
BaseType::Real
|
||||||
assn = self.gen_real();
|
};
|
||||||
}
|
|
||||||
|
|
||||||
let v = self.gen_variable_quantified(t, Quantifier::Const);
|
let v = self.gen_variable_quantified(t, Quantifier::Const);
|
||||||
|
|
||||||
Stat::new_decl(
|
Box::new(
|
||||||
DeclarationBuilder::default()
|
DeclarationBuilder::default()
|
||||||
.variable(v)
|
.variable(v)
|
||||||
.assn(Some(assn))
|
.assn(self.gen_literal(t))
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gen_variable(&mut self, t: BaseType) -> Variable {
|
||||||
|
VariableBuilder::default()
|
||||||
|
.type_(t)
|
||||||
|
.name(self.gen_name())
|
||||||
|
.quantifer(Quantifier::Var)
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
fn gen_variable_quantified(&mut self, t: BaseType, q: Quantifier) -> Variable {
|
fn gen_variable_quantified(&mut self, t: BaseType, q: Quantifier) -> Variable {
|
||||||
VariableBuilder::default()
|
VariableBuilder::default()
|
||||||
.type_(t)
|
.type_(t)
|
||||||
.name(self.gen_name())
|
.name(self.gen_name())
|
||||||
.quantifier(q)
|
.quantifer(q)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_integer(&mut self) -> Expr {
|
|
||||||
Expr::new_literal(self.gen_literal(BaseType::Int))
|
fn gen_name(&mut self) -> String {
|
||||||
|
let s = format!("_{}", self.name_counter);
|
||||||
|
self.name_counter += 1;
|
||||||
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_real(&mut self) -> Expr {
|
//fn gen_expr(&mut self, type_: BaseType) -> Box<dyn Expr> {
|
||||||
Expr::new_literal(self.gen_literal(BaseType::Real))
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
fn gen_literal(&mut self, t: BaseType) -> Literal {
|
fn gen_literal(&mut self, t: BaseType) -> Literal {
|
||||||
match t {
|
match t {
|
||||||
|
@ -110,12 +117,6 @@ impl AstBuilder {
|
||||||
BaseType::Unset => panic!("Attempted to generate literal of type Unset"),
|
BaseType::Unset => panic!("Attempted to generate literal of type Unset"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_name(&mut self) -> String {
|
|
||||||
let s = format!("_{}", self.name_counter);
|
|
||||||
self.name_counter += 1;
|
|
||||||
s
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for AstBuilder {
|
impl ToString for AstBuilder {
|
||||||
|
@ -153,16 +154,15 @@ impl Distribution<i32> for IntGenerator {
|
||||||
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> i32 {
|
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> i32 {
|
||||||
let p: f64 = rng.gen();
|
let p: f64 = rng.gen();
|
||||||
|
|
||||||
if p < 0.3 {
|
if p < 0.33 {
|
||||||
i32::MAX - (self.distro_pos.sample(rng).abs() as i32)
|
i32::MAX - (self.distro_pos.sample(rng).abs() as i32)
|
||||||
} else if p < 0.7 {
|
} else if p < 0.66 {
|
||||||
self.distro_zero.sample(rng) as i32
|
self.distro_zero.sample(rng) as i32
|
||||||
} else {
|
} else {
|
||||||
-1 * (i32::MAX - (self.distro_pos.sample(rng).abs() as i32))
|
-1 * (i32::MAX - (self.distro_pos.sample(rng).abs() as i32))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates values from regions of interest for a float
|
/// Generates values from regions of interest for a float
|
||||||
///
|
///
|
||||||
/// These are concentrated around f32::MIN, 0, and f32::MAX, though any f32 value is possible
|
/// These are concentrated around f32::MIN, 0, and f32::MAX, though any f32 value is possible
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -5,11 +5,11 @@ use clap::Parser;
|
||||||
extern crate derive_builder;
|
extern crate derive_builder;
|
||||||
|
|
||||||
mod ast;
|
mod ast;
|
||||||
mod ast_builder;
|
//mod ast_builder;
|
||||||
mod params;
|
mod params;
|
||||||
|
|
||||||
use params::Params;
|
use params::Params;
|
||||||
use ast_builder::AstBuilder;
|
//use ast_builder::AstBuilder;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
|
@ -20,9 +20,9 @@ struct Args {
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let params = Params::parse(&args.config);
|
let params = Params::parse(&args.config);
|
||||||
let mut builder = AstBuilder::from(params);
|
//let mut builder = AstBuilder::from(params);
|
||||||
|
|
||||||
builder.generate();
|
//builder.generate();
|
||||||
|
|
||||||
println!("{}", builder.to_string());
|
//println!("{}", builder.to_string());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue