2 acceptance tests left to fix

This commit is contained in:
Kasey White
2023-03-27 11:01:18 -04:00
committed by Lucas
parent eef34b8f4b
commit 51a6589aac
4 changed files with 138 additions and 47 deletions

View File

@@ -213,6 +213,9 @@ pub enum Air {
scope: Scope,
tipo: Arc<Type>,
},
Noop {
scope: Scope,
},
}
impl Air {
@@ -255,7 +258,8 @@ impl Air {
| Air::TupleAccessor { scope, .. }
| Air::TupleIndex { scope, .. }
| Air::ErrorTerm { scope, .. }
| Air::Trace { scope, .. } => scope.clone(),
| Air::Trace { scope, .. }
| Air::Noop { scope } => scope.clone(),
}
}
pub fn scope_mut(&mut self) -> &mut Scope {
@@ -297,7 +301,8 @@ impl Air {
| Air::TupleAccessor { scope, .. }
| Air::TupleIndex { scope, .. }
| Air::ErrorTerm { scope, .. }
| Air::Trace { scope, .. } => scope,
| Air::Trace { scope, .. }
| Air::Noop { scope } => scope,
}
}
pub fn tipo(&self) -> Option<Arc<Type>> {
@@ -386,7 +391,8 @@ impl Air {
| Air::AssertConstr { .. }
| Air::AssertBool { .. }
| Air::Finally { .. }
| Air::FieldsExpose { .. } => None,
| Air::FieldsExpose { .. }
| Air::Noop { .. } => None,
Air::UnOp { op, .. } => match op {
UnOp::Not => Some(
Type::App {

View File

@@ -20,6 +20,7 @@ use crate::{
},
expr::TypedExpr,
tipo::{PatternConstructor, Type, TypeVar, ValueConstructorVariant},
IdGenerator,
};
use super::{air::Air, scope::Scope, stack::AirStack};
@@ -1435,6 +1436,7 @@ pub fn handle_func_dependencies(
func_index_map: &IndexMap<FunctionAccessKey, Scope>,
func_scope: &Scope,
to_be_defined: &mut IndexMap<FunctionAccessKey, ()>,
id_gen: Rc<IdGenerator>,
) {
let mut function_component = function_component.clone();
@@ -1476,16 +1478,28 @@ pub fn handle_func_dependencies(
let mut recursion_ir = vec![];
handle_recursion_ir(&dependency, depend_comp, &mut recursion_ir);
let mut temp_ir = vec![Air::DefineFunc {
let mut temp_stack = AirStack {
id_gen: id_gen.clone(),
scope: func_scope.clone(),
func_name: dependency.function_name.clone(),
module_name: dependency.module_name.clone(),
params: depend_comp.args.clone(),
recursive: depend_comp.recursive,
variant_name: dependency.variant_name.clone(),
}];
air: vec![],
};
temp_ir.append(&mut recursion_ir);
let recursion_stack = AirStack {
id_gen: id_gen.clone(),
scope: func_scope.clone(),
air: recursion_ir,
};
temp_stack.define_func(
dependency.function_name.clone(),
dependency.module_name.clone(),
dependency.variant_name.clone(),
depend_comp.args.clone(),
depend_comp.recursive,
recursion_stack,
);
let mut temp_ir = temp_stack.complete();
temp_ir.append(dependencies_ir);

View File

@@ -12,6 +12,7 @@ use crate::{
use super::{air::Air, scope::Scope};
/// A builder for [`Air`].
#[derive(Debug)]
pub struct AirStack {
pub id_gen: Rc<IdGenerator>,
pub scope: Scope,
@@ -404,12 +405,14 @@ impl AirStack {
self.merge_child(body);
}
pub fn wrap_clause(&mut self) {
pub fn wrap_clause(&mut self, body: AirStack) {
self.new_scope();
self.air.push(Air::WrapClause {
scope: self.scope.clone(),
});
self.merge_child(body);
}
pub fn trace(&mut self, tipo: Arc<Type>) {
@@ -652,4 +655,33 @@ impl AirStack {
self.merge_child(void_stack);
}
pub fn define_func(
&mut self,
func_name: String,
module_name: String,
variant_name: String,
params: Vec<String>,
recursive: bool,
body_stack: AirStack,
) {
self.air.push(Air::DefineFunc {
scope: self.scope.clone(),
func_name,
module_name,
params,
recursive,
variant_name,
});
self.merge_child(body_stack);
}
pub fn noop(&mut self) {
self.new_scope();
self.air.push(Air::Noop {
scope: self.scope.clone(),
});
}
}