Clean up primitive handling, finally.
This commit is contained in:
@@ -347,12 +347,25 @@ fn generate_random_expression(
|
||||
Some((operator, arg_count)) => {
|
||||
let primop = Primitive::from_str(operator).expect("chose valid primitive");
|
||||
let mut args = vec![base_expr];
|
||||
let mut argtys = vec![];
|
||||
|
||||
while args.len() < *arg_count {
|
||||
args.push(generate_random_valueref(rng, env, Some(primty)));
|
||||
argtys.push(Type::Primitive(primty));
|
||||
}
|
||||
|
||||
Expression::Primitive(Location::manufactured(), out_type, primop, args)
|
||||
let primtype = Type::Function(argtys, Box::new(Type::Primitive(primty)));
|
||||
|
||||
Expression::Call(
|
||||
Location::manufactured(),
|
||||
out_type,
|
||||
Box::new(ValueOrRef::Primitive(
|
||||
Location::manufactured(),
|
||||
primtype,
|
||||
primop,
|
||||
)),
|
||||
args,
|
||||
)
|
||||
}
|
||||
},
|
||||
Type::Structure(_) => unimplemented!(),
|
||||
@@ -377,9 +390,19 @@ fn generate_random_expression(
|
||||
} else {
|
||||
let (variable, var_type) = possible_variables.choose(rng).unwrap();
|
||||
|
||||
Expression::Print(
|
||||
Expression::Call(
|
||||
Location::manufactured(),
|
||||
ValueOrRef::Ref(Location::manufactured(), var_type.clone(), variable.clone()),
|
||||
Type::void(),
|
||||
Box::new(ValueOrRef::Primitive(
|
||||
Location::manufactured(),
|
||||
Type::void(),
|
||||
Primitive::Print,
|
||||
)),
|
||||
vec![ValueOrRef::Ref(
|
||||
Location::manufactured(),
|
||||
var_type.clone(),
|
||||
variable.clone(),
|
||||
)],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user