Start turning AirTree statements into expressions (let)

Still many places to fix, WIP.
This commit is contained in:
KtorZ 2023-10-06 19:16:53 +02:00 committed by Kasey
parent cf51b30045
commit a12c374258
3 changed files with 569 additions and 570 deletions

File diff suppressed because it is too large Load Diff

View File

@ -659,10 +659,7 @@ pub fn erase_opaque_type_operations(
/// Determine whether this air_tree node introduces any shadowing over `potential_matches`
pub fn find_introduced_variables(air_tree: &AirTree) -> Vec<String> {
match air_tree {
AirTree::Statement {
statement: AirStatement::Let { name, .. },
..
} => vec![name.clone()],
AirTree::Expression(AirExpression::Let { name, .. }) => vec![name.clone()],
AirTree::Statement {
statement: AirStatement::TupleGuard { indices, .. },
..

View File

@ -117,11 +117,6 @@ pub enum AirTree {
#[derive(Debug, Clone, PartialEq)]
pub enum AirStatement {
// Assignment
Let {
name: String,
value: Box<AirTree>,
},
DefineFunc {
func_name: String,
module_name: String,
@ -209,6 +204,13 @@ pub enum AirStatement {
#[derive(Debug, Clone, PartialEq)]
pub enum AirExpression {
// Assignment
Let {
name: String,
value: Box<AirTree>,
then: Box<AirTree>,
},
// Primitives
Int {
value: String,
@ -494,14 +496,12 @@ impl AirTree {
arg: arg.into(),
})
}
pub fn let_assignment(name: impl ToString, value: AirTree) -> AirTree {
AirTree::Statement {
statement: AirStatement::Let {
name: name.to_string(),
value: value.into(),
},
hoisted_over: None,
}
pub fn let_assignment(name: impl ToString, value: AirTree, then: AirTree) -> AirTree {
AirTree::Expression(AirExpression::Let {
name: name.to_string(),
value: value.into(),
then: then.into(),
})
}
pub fn cast_from_data(value: AirTree, tipo: Rc<Type>, msg: Option<AirMsg>) -> AirTree {
AirTree::Expression(AirExpression::CastFromData {
@ -755,6 +755,7 @@ impl AirTree {
hoisted_over: None,
}
}
pub fn list_access(
names: Vec<String>,
tipo: Rc<Type>,
@ -889,8 +890,6 @@ impl AirTree {
vec![head_list],
);
let assign = AirTree::let_assignment("_", expect_on_head);
let next_call = AirTree::call(
AirTree::var(
ValueConstructor::public(
@ -918,11 +917,13 @@ impl AirTree {
],
);
let assign = AirTree::let_assignment("_", expect_on_head, next_call);
AirTree::list_clause(
"__list_to_check",
void(),
AirTree::void(),
assign.hoist_over(next_call),
assign,
None,
false,
)
@ -941,10 +942,6 @@ impl AirTree {
hoisted_over: Some(exp),
} => {
match statement {
AirStatement::Let { value, name } => {
air_vec.push(Air::Let { name: name.clone() });
value.create_air_vec(air_vec);
}
AirStatement::DefineFunc {
func_name,
module_name,
@ -1143,6 +1140,11 @@ impl AirTree {
exp.create_air_vec(air_vec);
}
AirTree::Expression(exp) => match exp {
AirExpression::Let { value, then, name } => {
air_vec.push(Air::Let { name: name.clone() });
value.create_air_vec(air_vec);
then.create_air_vec(air_vec);
}
AirExpression::Int { value } => air_vec.push(Air::Int {
value: value.clone(),
}),
@ -1517,9 +1519,10 @@ impl AirTree {
let mut index_count = IndexCounter::new();
tree_path.push(current_depth, depth_index);
if let AirTree::Statement { statement, .. } = self {
match statement {
AirStatement::Let { value, .. } => {
match self {
AirTree::UnhoistedSequence(..) => unreachable!("No unhoisted sequence at this point"),
AirTree::Expression(expr) => match expr {
AirExpression::Let { value, .. } => {
value.do_traverse_tree_with(
tree_path,
current_depth + 1,
@ -1528,6 +1531,9 @@ impl AirTree {
apply_with_func_last,
);
}
_ => (),
},
AirTree::Statement { statement, .. } => match statement {
AirStatement::DefineFunc { func_body, .. } => {
func_body.do_traverse_tree_with(
tree_path,
@ -1628,7 +1634,7 @@ impl AirTree {
apply_with_func_last,
);
}
};
},
}
if !apply_with_func_last {
@ -1649,6 +1655,15 @@ impl AirTree {
);
}
AirTree::Expression(e) => match e {
AirExpression::Let { then, .. } => {
then.do_traverse_tree_with(
tree_path,
current_depth + 1,
index_count.next_number(),
with,
apply_with_func_last,
);
}
AirExpression::List { items, .. } => {
for item in items {
item.do_traverse_tree_with(
@ -1987,15 +2002,6 @@ impl AirTree {
statement,
hoisted_over: Some(hoisted_over),
} => match statement {
AirStatement::Let { value, .. } => {
if *index == 0 {
value.as_mut().do_find_air_tree_node(tree_path_iter)
} else if *index == 1 {
hoisted_over.as_mut().do_find_air_tree_node(tree_path_iter)
} else {
panic!("Tree Path index outside tree children nodes")
}
}
AirStatement::AssertConstr { constr, .. } => {
if *index == 0 {
constr.as_mut().do_find_air_tree_node(tree_path_iter)
@ -2100,6 +2106,15 @@ impl AirTree {
}
},
AirTree::Expression(e) => match e {
AirExpression::Let { value, then, .. } => {
if *index == 0 {
value.as_mut().do_find_air_tree_node(tree_path_iter)
} else if *index == 1 {
then.as_mut().do_find_air_tree_node(tree_path_iter)
} else {
panic!("Tree Path index outside tree children nodes")
}
}
AirExpression::List { items, .. }
| AirExpression::Tuple { items, .. }
| AirExpression::Builtin { args: items, .. } => {