diff --git a/src/ir/arbitrary.rs b/src/ir/arbitrary.rs index ce1aa24..16f8b99 100644 --- a/src/ir/arbitrary.rs +++ b/src/ir/arbitrary.rs @@ -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(), diff --git a/src/ir/ast.rs b/src/ir/ast.rs index 8920d69..d775a91 100644 --- a/src/ir/ast.rs +++ b/src/ir/ast.rs @@ -52,32 +52,6 @@ impl Arbitrary for Program { } } -/// A thing that can sit at the top level of a file. -/// -/// For the moment, these are statements and functions. Other things -/// will likely be added in the future, but for now: just statements -/// and functions -#[derive(Clone, Debug)] -pub enum TopLevel { - Statement(Expression), - // FIXME: Is the return type actually necessary, given we can infer it from - // the expression type? - Function(Name, Vec<(Name, Type)>, Type, Expression), -} - -impl TopLevel { - /// Return the type of the item, as inferred or recently - /// computed. - pub fn type_of(&self) -> T { - match self { - TopLevel::Statement(expr) => expr.type_of(), - TopLevel::Function(_, args, ret, _) => { - T::build_function_type(args.iter().map(|(_, t)| t.clone()).collect(), ret.clone()) - } - } - } -} - /// The representation of an expression. /// /// Note that expressions, like everything else in this syntax tree, @@ -479,8 +453,6 @@ fn struct_sizes_are_rational() { assert_eq!(80, std::mem::size_of::>()); assert_eq!(200, std::mem::size_of::>()); assert_eq!(200, std::mem::size_of::>()); - assert_eq!(272, std::mem::size_of::>()); - assert_eq!(272, std::mem::size_of::>()); assert_eq!(72, std::mem::size_of::>()); assert_eq!(72, std::mem::size_of::>()); } diff --git a/src/ir/pretty.rs b/src/ir/pretty.rs index 9c20e74..4b80178 100644 --- a/src/ir/pretty.rs +++ b/src/ir/pretty.rs @@ -1,4 +1,4 @@ -use crate::ir::{Expression, Primitive, Program, TopLevel, Type, TypeOrVar, Value, ValueOrRef}; +use crate::ir::{Expression, Primitive, Program, Type, TypeOrVar, Value, ValueOrRef}; use crate::syntax::{self, ConstantType}; use crate::util::pretty::{derived_display, pretty_function_type, Allocator}; use pretty::{Arena, DocAllocator, DocBuilder}; @@ -57,33 +57,6 @@ impl Program { } } -impl TopLevel { - pub fn pretty<'a>( - &self, - allocator: &'a Arena<'a, ()>, - ) -> pretty::DocBuilder<'a, Arena<'a, ()>, ()> { - match self { - TopLevel::Function(name, args, _, expr) => allocator - .text("function") - .append(allocator.space()) - .append(allocator.text(name.current_name().to_string())) - .append(allocator.space()) - .append( - allocator - .intersperse( - args.iter().map(|(x, _)| allocator.text(x.to_string())), - allocator.text(","), - ) - .parens(), - ) - .append(allocator.space()) - .append(expr.pretty(allocator)), - - TopLevel::Statement(stmt) => stmt.pretty(allocator), - } - } -} - impl Expression { pub fn pretty<'a>( &self, @@ -267,7 +240,6 @@ impl TypeOrVar { } derived_display!(Program); -derived_display!(TopLevel); derived_display!(Expression); derived_display!(Primitive); derived_display!(Type);