feat: start on nested clauses
chore: remove then field from list clause guard and clause guard
This commit is contained in:
parent
5bcc425f0f
commit
f6e163d16d
|
@ -1142,12 +1142,10 @@ impl<'a> CodeGenerator<'a> {
|
||||||
builder::handle_clause_guard(guard),
|
builder::handle_clause_guard(guard),
|
||||||
);
|
);
|
||||||
|
|
||||||
clause_then = clause_guard_assign.hoist_over(AirTree::clause_guard(
|
clause_then = clause_guard_assign.hoist_over(
|
||||||
clause_guard_name,
|
AirTree::clause_guard(clause_guard_name, AirTree::bool(true), bool())
|
||||||
AirTree::bool(true),
|
.hoist_over(clause_then),
|
||||||
bool(),
|
);
|
||||||
clause_then,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match &mut props.specific_clause {
|
match &mut props.specific_clause {
|
||||||
|
@ -1423,12 +1421,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
elem_name.clone(),
|
elem_name.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let statement = self.nested_clause_condition(
|
let statement =
|
||||||
elem,
|
self.nested_clause_condition(elem, list_elem_type, &mut elem_props);
|
||||||
AirTree::local_var(&elem_name, list_elem_type.clone()),
|
|
||||||
list_elem_type,
|
|
||||||
&mut elem_props,
|
|
||||||
);
|
|
||||||
|
|
||||||
*complex_clause = *complex_clause || elem_props.complex_clause;
|
*complex_clause = *complex_clause || elem_props.complex_clause;
|
||||||
|
|
||||||
|
@ -1472,12 +1466,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
specific_clause: props.specific_clause.clone(),
|
specific_clause: props.specific_clause.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let statement = self.nested_clause_condition(
|
let statement =
|
||||||
elem,
|
self.nested_clause_condition(elem, subject_tipo, &mut elem_props);
|
||||||
AirTree::local_var(&elem_name, subject_tipo.clone()),
|
|
||||||
subject_tipo,
|
|
||||||
&mut elem_props,
|
|
||||||
);
|
|
||||||
*complex_clause = *complex_clause || elem_props.complex_clause;
|
*complex_clause = *complex_clause || elem_props.complex_clause;
|
||||||
|
|
||||||
air_elems.push(statement);
|
air_elems.push(statement);
|
||||||
|
@ -1578,7 +1568,6 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
let statement = self.nested_clause_condition(
|
let statement = self.nested_clause_condition(
|
||||||
&arg.value,
|
&arg.value,
|
||||||
AirTree::local_var(&field_name, arg_type.clone()),
|
|
||||||
arg_type,
|
arg_type,
|
||||||
&mut field_props,
|
&mut field_props,
|
||||||
);
|
);
|
||||||
|
@ -1622,20 +1611,24 @@ impl<'a> CodeGenerator<'a> {
|
||||||
fn nested_clause_condition(
|
fn nested_clause_condition(
|
||||||
&mut self,
|
&mut self,
|
||||||
pattern: &Pattern<PatternConstructor, Arc<Type>>,
|
pattern: &Pattern<PatternConstructor, Arc<Type>>,
|
||||||
value: AirTree,
|
|
||||||
subject_tipo: &Arc<Type>,
|
subject_tipo: &Arc<Type>,
|
||||||
props: &mut ClauseProperties,
|
props: &mut ClauseProperties,
|
||||||
) -> AirTree {
|
) -> AirTree {
|
||||||
match pattern {
|
match pattern {
|
||||||
Pattern::Int { value, .. } => {
|
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 {
|
Pattern::Assign {
|
||||||
name,
|
name,
|
||||||
location,
|
location,
|
||||||
pattern,
|
pattern,
|
||||||
} => todo!(),
|
} => {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
Pattern::Discard { name, location } => todo!(),
|
Pattern::Discard { name, location } => todo!(),
|
||||||
Pattern::List {
|
Pattern::List {
|
||||||
location,
|
location,
|
||||||
|
|
|
@ -50,14 +50,12 @@ pub enum AirStatement {
|
||||||
subject_name: String,
|
subject_name: String,
|
||||||
tipo: Arc<Type>,
|
tipo: Arc<Type>,
|
||||||
pattern: Box<AirTree>,
|
pattern: Box<AirTree>,
|
||||||
then: Box<AirTree>,
|
|
||||||
},
|
},
|
||||||
ListClauseGuard {
|
ListClauseGuard {
|
||||||
tipo: Arc<Type>,
|
tipo: Arc<Type>,
|
||||||
tail_name: String,
|
tail_name: String,
|
||||||
next_tail_name: Option<String>,
|
next_tail_name: Option<String>,
|
||||||
inverse: bool,
|
inverse: bool,
|
||||||
then: Box<AirTree>,
|
|
||||||
},
|
},
|
||||||
// Field Access
|
// Field Access
|
||||||
FieldsExpose {
|
FieldsExpose {
|
||||||
|
@ -475,18 +473,12 @@ impl AirTree {
|
||||||
otherwise: otherwise.into(),
|
otherwise: otherwise.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn clause_guard(
|
pub fn clause_guard(subject_name: impl ToString, pattern: AirTree, tipo: Arc<Type>) -> AirTree {
|
||||||
subject_name: impl ToString,
|
|
||||||
pattern: AirTree,
|
|
||||||
tipo: Arc<Type>,
|
|
||||||
then: AirTree,
|
|
||||||
) -> AirTree {
|
|
||||||
AirTree::Statement {
|
AirTree::Statement {
|
||||||
statement: AirStatement::ClauseGuard {
|
statement: AirStatement::ClauseGuard {
|
||||||
subject_name: subject_name.to_string(),
|
subject_name: subject_name.to_string(),
|
||||||
tipo,
|
tipo,
|
||||||
pattern: pattern.into(),
|
pattern: pattern.into(),
|
||||||
then: then.into(),
|
|
||||||
},
|
},
|
||||||
hoisted_over: None,
|
hoisted_over: None,
|
||||||
}
|
}
|
||||||
|
@ -495,7 +487,6 @@ impl AirTree {
|
||||||
tail_name: impl ToString,
|
tail_name: impl ToString,
|
||||||
tipo: Arc<Type>,
|
tipo: Arc<Type>,
|
||||||
inverse: bool,
|
inverse: bool,
|
||||||
then: AirTree,
|
|
||||||
next_tail_name: Option<String>,
|
next_tail_name: Option<String>,
|
||||||
) -> AirTree {
|
) -> AirTree {
|
||||||
AirTree::Statement {
|
AirTree::Statement {
|
||||||
|
@ -504,7 +495,6 @@ impl AirTree {
|
||||||
tail_name: tail_name.to_string(),
|
tail_name: tail_name.to_string(),
|
||||||
next_tail_name,
|
next_tail_name,
|
||||||
inverse,
|
inverse,
|
||||||
then: then.into(),
|
|
||||||
},
|
},
|
||||||
hoisted_over: None,
|
hoisted_over: None,
|
||||||
}
|
}
|
||||||
|
@ -780,7 +770,6 @@ impl AirTree {
|
||||||
subject_name,
|
subject_name,
|
||||||
tipo,
|
tipo,
|
||||||
pattern,
|
pattern,
|
||||||
then,
|
|
||||||
} => {
|
} => {
|
||||||
air_vec.push(Air::ClauseGuard {
|
air_vec.push(Air::ClauseGuard {
|
||||||
subject_name: subject_name.clone(),
|
subject_name: subject_name.clone(),
|
||||||
|
@ -788,14 +777,12 @@ impl AirTree {
|
||||||
});
|
});
|
||||||
|
|
||||||
pattern.create_air_vec(air_vec);
|
pattern.create_air_vec(air_vec);
|
||||||
then.create_air_vec(air_vec);
|
|
||||||
}
|
}
|
||||||
AirStatement::ListClauseGuard {
|
AirStatement::ListClauseGuard {
|
||||||
tipo,
|
tipo,
|
||||||
tail_name,
|
tail_name,
|
||||||
next_tail_name,
|
next_tail_name,
|
||||||
inverse,
|
inverse,
|
||||||
then,
|
|
||||||
} => {
|
} => {
|
||||||
air_vec.push(Air::ListClauseGuard {
|
air_vec.push(Air::ListClauseGuard {
|
||||||
tipo: tipo.clone(),
|
tipo: tipo.clone(),
|
||||||
|
@ -803,8 +790,6 @@ impl AirTree {
|
||||||
next_tail_name: next_tail_name.clone(),
|
next_tail_name: next_tail_name.clone(),
|
||||||
inverse: *inverse,
|
inverse: *inverse,
|
||||||
});
|
});
|
||||||
|
|
||||||
then.create_air_vec(air_vec);
|
|
||||||
}
|
}
|
||||||
AirStatement::FieldsExpose {
|
AirStatement::FieldsExpose {
|
||||||
indices,
|
indices,
|
||||||
|
|
Loading…
Reference in New Issue