Clean up primitive handling, finally.

This commit is contained in:
2024-04-16 16:20:31 -07:00
parent 763a895285
commit 7d4f182a67
19 changed files with 399 additions and 550 deletions

View File

@@ -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(),
)],
)
}
}