Remove IR TopLevel.

This commit is contained in:
2024-06-03 20:38:45 -07:00
parent 88d128df9f
commit cf7eff7a93
3 changed files with 31 additions and 89 deletions

View File

@@ -1,7 +1,5 @@
use crate::eval::PrimitiveType;
use crate::ir::{
Expression, Name, Primitive, Program, TopLevel, Type, TypeWithVoid, Value, ValueOrRef,
};
use crate::ir::{Expression, Name, Primitive, Program, Type, TypeWithVoid, Value, ValueOrRef};
use crate::syntax::Location;
use crate::util::scoped_map::ScopedMap;
use proptest::strategy::{NewTree, Strategy, ValueTree};
@@ -183,37 +181,37 @@ pub struct ProgramTree {
impl ProgramTree {
fn new(mut rng: TestRng) -> Self {
let mut items = vec![];
// let mut items = vec![];
let program_length = PROGRAM_LENGTH_DISTRIBUTION.sample(&mut rng);
let mut env = ScopedMap::new();
// let mut env = ScopedMap::new();
for _ in 0..program_length {
match STATEMENT_TYPE_FREQUENCIES[STATEMENT_TYPE_DISTRIBUTION.sample(&mut rng)].0 {
StatementType::Binding => {
let binding = generate_random_binding(&mut rng, &mut env);
items.push(TopLevel::Statement(binding));
}
StatementType::Expression => {
let expr = generate_random_expression(&mut rng, &mut env);
items.push(TopLevel::Statement(expr));
}
StatementType::Function => {
env.new_scope();
let name = generate_random_name(&mut rng);
let mut args = vec![];
let arg_count = FUNCTION_ARGUMENTS_DISTRIBUTION.sample(&mut rng);
for _ in 0..arg_count {
let name = generate_random_name(&mut rng);
let ty = generate_random_argument_type(&mut rng);
args.push((name, ty));
}
let body = generate_random_expression(&mut rng, &mut env);
let rettype = body.type_of();
env.release_scope();
items.push(TopLevel::Function(name, args, rettype, body))
}
}
}
// for _ in 0..program_length {
// match STATEMENT_TYPE_FREQUENCIES[STATEMENT_TYPE_DISTRIBUTION.sample(&mut rng)].0 {
// StatementType::Binding => {
// let binding = generate_random_binding(&mut rng, &mut env);
// items.push(TopLevel::Statement(binding));
// }
// StatementType::Expression => {
// let expr = generate_random_expression(&mut rng, &mut env);
// items.push(TopLevel::Statement(expr));
// }
// StatementType::Function => {
// env.new_scope();
// let name = generate_random_name(&mut rng);
// let mut args = vec![];
// let arg_count = FUNCTION_ARGUMENTS_DISTRIBUTION.sample(&mut rng);
// for _ in 0..arg_count {
// let name = generate_random_name(&mut rng);
// let ty = generate_random_argument_type(&mut rng);
// args.push((name, ty));
// }
// let body = generate_random_expression(&mut rng, &mut env);
// let rettype = body.type_of();
// env.release_scope();
// items.push(TopLevel::Function(name, args, rettype, body))
// }
// }
// }
let current = Program {
functions: HashMap::new(),