Formatting and comments.
This commit is contained in:
@@ -13,12 +13,13 @@ const VALID_VARIABLE_NAMES: &str = r"[a-z][a-zA-Z0-9_]*";
|
||||
impl ConstantType {
|
||||
fn get_operators(&self) -> &'static [(&'static str, usize)] {
|
||||
match self {
|
||||
ConstantType::I8| ConstantType::I16 | ConstantType::I32 | ConstantType::I64 =>
|
||||
&[("+", 2), ("-", 1), ("-", 2), ("*", 2), ("/", 2)],
|
||||
ConstantType::U8| ConstantType::U16 | ConstantType::U32 | ConstantType::U64 =>
|
||||
&[("+", 2), ("-", 2), ("*", 2), ("/", 2)],
|
||||
ConstantType::I8 | ConstantType::I16 | ConstantType::I32 | ConstantType::I64 => {
|
||||
&[("+", 2), ("-", 1), ("-", 2), ("*", 2), ("/", 2)]
|
||||
}
|
||||
ConstantType::U8 | ConstantType::U16 | ConstantType::U32 | ConstantType::U64 => {
|
||||
&[("+", 2), ("-", 2), ("*", 2), ("/", 2)]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,38 +56,41 @@ impl Arbitrary for Program {
|
||||
type Strategy = BoxedStrategy<Self>;
|
||||
|
||||
fn arbitrary_with(genenv: Self::Parameters) -> Self::Strategy {
|
||||
proptest::collection::vec(ProgramStatementInfo::arbitrary(), genenv.block_length.clone())
|
||||
.prop_flat_map(move |mut items| {
|
||||
let mut statements = Vec::new();
|
||||
let mut genenv = genenv.clone();
|
||||
proptest::collection::vec(
|
||||
ProgramStatementInfo::arbitrary(),
|
||||
genenv.block_length.clone(),
|
||||
)
|
||||
.prop_flat_map(move |mut items| {
|
||||
let mut statements = Vec::new();
|
||||
let mut genenv = genenv.clone();
|
||||
|
||||
for psi in items.drain(..) {
|
||||
if genenv.bindings.is_empty() || psi.should_be_binding {
|
||||
genenv.return_type = psi.binding_type;
|
||||
let expr = Expression::arbitrary_with(genenv.clone());
|
||||
genenv.bindings.insert(psi.name.clone(), psi.binding_type);
|
||||
statements.push(
|
||||
expr.prop_map(move |expr| {
|
||||
Statement::Binding(Location::manufactured(), psi.name.clone(), expr)
|
||||
})
|
||||
.boxed(),
|
||||
);
|
||||
} else {
|
||||
let printers = genenv.bindings.keys().map(|n| {
|
||||
Just(Statement::Print(
|
||||
Location::manufactured(),
|
||||
Name::manufactured(n),
|
||||
))
|
||||
});
|
||||
statements.push(Union::new(printers).boxed());
|
||||
}
|
||||
for psi in items.drain(..) {
|
||||
if genenv.bindings.is_empty() || psi.should_be_binding {
|
||||
genenv.return_type = psi.binding_type;
|
||||
let expr = Expression::arbitrary_with(genenv.clone());
|
||||
genenv.bindings.insert(psi.name.clone(), psi.binding_type);
|
||||
statements.push(
|
||||
expr.prop_map(move |expr| {
|
||||
Statement::Binding(Location::manufactured(), psi.name.clone(), expr)
|
||||
})
|
||||
.boxed(),
|
||||
);
|
||||
} else {
|
||||
let printers = genenv.bindings.keys().map(|n| {
|
||||
Just(Statement::Print(
|
||||
Location::manufactured(),
|
||||
Name::manufactured(n),
|
||||
))
|
||||
});
|
||||
statements.push(Union::new(printers).boxed());
|
||||
}
|
||||
}
|
||||
|
||||
statements
|
||||
.prop_map(|statements| Program { statements })
|
||||
.boxed()
|
||||
})
|
||||
.boxed()
|
||||
statements
|
||||
.prop_map(|statements| Program { statements })
|
||||
.boxed()
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,15 +173,18 @@ impl Arbitrary for Expression {
|
||||
// now we generate our recursive types, given our leaf strategy
|
||||
leaf_strategy
|
||||
.prop_recursive(3, 10, 2, move |strat| {
|
||||
(select(genenv.return_type.get_operators()), strat.clone(), strat).prop_map(
|
||||
|((oper, count), left, right)| {
|
||||
(
|
||||
select(genenv.return_type.get_operators()),
|
||||
strat.clone(),
|
||||
strat,
|
||||
)
|
||||
.prop_map(|((oper, count), left, right)| {
|
||||
let mut args = vec![left, right];
|
||||
while args.len() > count {
|
||||
args.pop();
|
||||
}
|
||||
Expression::Primitive(Location::manufactured(), oper.to_string(), args)
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user