feat: start on nested clauses

chore: remove then field from list clause guard and clause guard
This commit is contained in:
microproofs 2023-07-01 20:27:48 -04:00 committed by Kasey
parent 5bcc425f0f
commit f6e163d16d
2 changed files with 17 additions and 39 deletions

View File

@ -1142,12 +1142,10 @@ impl<'a> CodeGenerator<'a> {
builder::handle_clause_guard(guard),
);
clause_then = clause_guard_assign.hoist_over(AirTree::clause_guard(
clause_guard_name,
AirTree::bool(true),
bool(),
clause_then,
));
clause_then = clause_guard_assign.hoist_over(
AirTree::clause_guard(clause_guard_name, AirTree::bool(true), bool())
.hoist_over(clause_then),
);
}
match &mut props.specific_clause {
@ -1423,12 +1421,8 @@ impl<'a> CodeGenerator<'a> {
elem_name.clone(),
);
let statement = self.nested_clause_condition(
elem,
AirTree::local_var(&elem_name, list_elem_type.clone()),
list_elem_type,
&mut elem_props,
);
let statement =
self.nested_clause_condition(elem, list_elem_type, &mut elem_props);
*complex_clause = *complex_clause || elem_props.complex_clause;
@ -1472,12 +1466,8 @@ impl<'a> CodeGenerator<'a> {
specific_clause: props.specific_clause.clone(),
};
let statement = self.nested_clause_condition(
elem,
AirTree::local_var(&elem_name, subject_tipo.clone()),
subject_tipo,
&mut elem_props,
);
let statement =
self.nested_clause_condition(elem, subject_tipo, &mut elem_props);
*complex_clause = *complex_clause || elem_props.complex_clause;
air_elems.push(statement);
@ -1578,7 +1568,6 @@ impl<'a> CodeGenerator<'a> {
let statement = self.nested_clause_condition(
&arg.value,
AirTree::local_var(&field_name, arg_type.clone()),
arg_type,
&mut field_props,
);
@ -1622,20 +1611,24 @@ impl<'a> CodeGenerator<'a> {
fn nested_clause_condition(
&mut self,
pattern: &Pattern<PatternConstructor, Arc<Type>>,
value: AirTree,
subject_tipo: &Arc<Type>,
props: &mut ClauseProperties,
) -> AirTree {
match pattern {
Pattern::Int { value, .. } => {
todo!();
AirTree::clause_guard(&props.original_subject_name, AirTree::int(value), int())
}
Pattern::Var { location, name } => todo!(),
Pattern::Var { name, .. } => AirTree::let_assignment(
name,
AirTree::local_var(&props.clause_var_name, subject_tipo.clone()),
),
Pattern::Assign {
name,
location,
pattern,
} => todo!(),
} => {
todo!();
}
Pattern::Discard { name, location } => todo!(),
Pattern::List {
location,

View File

@ -50,14 +50,12 @@ pub enum AirStatement {
subject_name: String,
tipo: Arc<Type>,
pattern: Box<AirTree>,
then: Box<AirTree>,
},
ListClauseGuard {
tipo: Arc<Type>,
tail_name: String,
next_tail_name: Option<String>,
inverse: bool,
then: Box<AirTree>,
},
// Field Access
FieldsExpose {
@ -475,18 +473,12 @@ impl AirTree {
otherwise: otherwise.into(),
})
}
pub fn clause_guard(
subject_name: impl ToString,
pattern: AirTree,
tipo: Arc<Type>,
then: AirTree,
) -> AirTree {
pub fn clause_guard(subject_name: impl ToString, pattern: AirTree, tipo: Arc<Type>) -> AirTree {
AirTree::Statement {
statement: AirStatement::ClauseGuard {
subject_name: subject_name.to_string(),
tipo,
pattern: pattern.into(),
then: then.into(),
},
hoisted_over: None,
}
@ -495,7 +487,6 @@ impl AirTree {
tail_name: impl ToString,
tipo: Arc<Type>,
inverse: bool,
then: AirTree,
next_tail_name: Option<String>,
) -> AirTree {
AirTree::Statement {
@ -504,7 +495,6 @@ impl AirTree {
tail_name: tail_name.to_string(),
next_tail_name,
inverse,
then: then.into(),
},
hoisted_over: None,
}
@ -780,7 +770,6 @@ impl AirTree {
subject_name,
tipo,
pattern,
then,
} => {
air_vec.push(Air::ClauseGuard {
subject_name: subject_name.clone(),
@ -788,14 +777,12 @@ impl AirTree {
});
pattern.create_air_vec(air_vec);
then.create_air_vec(air_vec);
}
AirStatement::ListClauseGuard {
tipo,
tail_name,
next_tail_name,
inverse,
then,
} => {
air_vec.push(Air::ListClauseGuard {
tipo: tipo.clone(),
@ -803,8 +790,6 @@ impl AirTree {
next_tail_name: next_tail_name.clone(),
inverse: *inverse,
});
then.create_air_vec(air_vec);
}
AirStatement::FieldsExpose {
indices,