diff --git a/reid/src/ast/mod.rs b/reid/src/ast/mod.rs index 9acbe9d..238c086 100644 --- a/reid/src/ast/mod.rs +++ b/reid/src/ast/mod.rs @@ -115,8 +115,8 @@ pub struct FunctionCallExpression(pub String, pub Vec, pub TokenRang #[derive(Debug, Clone)] pub struct IfExpression( pub Expression, - pub Block, - pub Option, + pub Expression, + pub Option, #[allow(dead_code)] pub TokenRange, ); diff --git a/reid/src/ast/process.rs b/reid/src/ast/process.rs index d47e690..a3740d2 100644 --- a/reid/src/ast/process.rs +++ b/reid/src/ast/process.rs @@ -3,8 +3,8 @@ use std::path::PathBuf; use crate::{ ast::{self}, mir::{ - self, ModuleMap, NamedVariableRef, SourceModuleId, StmtKind, StructField, StructType, - CustomTypeKey, + self, CustomTypeKey, ModuleMap, NamedVariableRef, SourceModuleId, StmtKind, StructField, + StructType, }, }; @@ -205,13 +205,17 @@ impl ast::Expression { } ast::ExpressionKind::IfExpr(if_expression) => { let cond = if_expression.0.process(module_id); - let then_block = if_expression.1.into_mir(module_id); + let then_block = if_expression.1.process(module_id); let else_block = if let Some(el) = &if_expression.2 { - Some(el.into_mir(module_id)) + Some(el.process(module_id)) } else { None }; - mir::ExprKind::If(mir::IfExpression(Box::new(cond), then_block, else_block)) + mir::ExprKind::If(mir::IfExpression( + Box::new(cond), + Box::new(then_block), + Box::new(else_block), + )) } ast::ExpressionKind::Array(expressions) => { mir::ExprKind::Array(expressions.iter().map(|e| e.process(module_id)).collect()) diff --git a/reid/src/mir/fmt.rs b/reid/src/mir/fmt.rs index dbe054f..6944120 100644 --- a/reid/src/mir/fmt.rs +++ b/reid/src/mir/fmt.rs @@ -240,7 +240,7 @@ impl Display for IfExpression { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "if {} ", self.0)?; Display::fmt(&self.1, f)?; - if let Some(e) = &self.2 { + if let Some(e) = *self.2 { Display::fmt(&e, f)?; } Ok(()) diff --git a/reid/src/mir/mod.rs b/reid/src/mir/mod.rs index eedd37f..bb1ce85 100644 --- a/reid/src/mir/mod.rs +++ b/reid/src/mir/mod.rs @@ -267,7 +267,11 @@ pub struct Expression(pub ExprKind, pub Metadata); /// Condition, Then, Else #[derive(Debug)] -pub struct IfExpression(pub Box, pub Block, pub Option); +pub struct IfExpression( + pub Box, + pub Box, + pub Box>, +); #[derive(Debug)] pub struct FunctionCall {