Add AST -> MIR for typecasting
This commit is contained in:
parent
c4ab4ac0b3
commit
3378f556ec
@ -256,7 +256,9 @@ impl ast::Expression {
|
|||||||
Box::new(expr.process(module_id)),
|
Box::new(expr.process(module_id)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
ast::ExpressionKind::CastTo(expression, _) => todo!(),
|
ast::ExpressionKind::CastTo(expression, ty) => {
|
||||||
|
mir::ExprKind::CastTo(Box::new(expression.process(module_id)), ty.0.clone().into())
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mir::Expression(kind, self.1.as_meta(module_id))
|
mir::Expression(kind, self.1.as_meta(module_id))
|
||||||
|
@ -1028,6 +1028,7 @@ impl mir::Expression {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
mir::ExprKind::CastTo(expression, type_kind) => todo!(),
|
||||||
};
|
};
|
||||||
if let Some(value) = &value {
|
if let Some(value) = &value {
|
||||||
value.instr().maybe_location(&mut scope.block, location);
|
value.instr().maybe_location(&mut scope.block, location);
|
||||||
|
@ -211,6 +211,7 @@ impl Display for ExprKind {
|
|||||||
ExprKind::Borrow(var_ref, false) => write!(f, "&{}", var_ref),
|
ExprKind::Borrow(var_ref, false) => write!(f, "&{}", var_ref),
|
||||||
ExprKind::Borrow(var_ref, true) => write!(f, "&mut {}", var_ref),
|
ExprKind::Borrow(var_ref, true) => write!(f, "&mut {}", var_ref),
|
||||||
ExprKind::Deref(var_ref) => write!(f, "*{}", var_ref),
|
ExprKind::Deref(var_ref) => write!(f, "*{}", var_ref),
|
||||||
|
ExprKind::CastTo(expression, type_kind) => write!(f, "{} as {}", expression, type_kind),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,6 +319,13 @@ impl Expression {
|
|||||||
_ => Err(ReturnTypeOther::DerefNonBorrow(var.2)),
|
_ => Err(ReturnTypeOther::DerefNonBorrow(var.2)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CastTo(expr, type_kind) => match expr.return_type(refs) {
|
||||||
|
Ok(ret_type) => match ret_type {
|
||||||
|
(ReturnKind::Hard, ty) => Ok((ReturnKind::Hard, ty)),
|
||||||
|
_ => Ok((ReturnKind::Soft, type_kind.clone())),
|
||||||
|
},
|
||||||
|
Err(_) => Ok((ReturnKind::Soft, type_kind.clone())),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,6 +343,7 @@ impl Expression {
|
|||||||
ExprKind::BinOp(_, _, _) => None,
|
ExprKind::BinOp(_, _, _) => None,
|
||||||
ExprKind::FunctionCall(_) => None,
|
ExprKind::FunctionCall(_) => None,
|
||||||
ExprKind::If(_) => None,
|
ExprKind::If(_) => None,
|
||||||
|
ExprKind::CastTo(expression, _) => expression.backing_var(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,6 +371,7 @@ impl Expression {
|
|||||||
ExprKind::Block(_) => None,
|
ExprKind::Block(_) => None,
|
||||||
ExprKind::Borrow(_, _) => None,
|
ExprKind::Borrow(_, _) => None,
|
||||||
ExprKind::Deref(_) => None,
|
ExprKind::Deref(_) => None,
|
||||||
|
ExprKind::CastTo(expression, _) => expression.num_value(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,6 +254,7 @@ pub enum ExprKind {
|
|||||||
Block(Block),
|
Block(Block),
|
||||||
Borrow(NamedVariableRef, bool),
|
Borrow(NamedVariableRef, bool),
|
||||||
Deref(NamedVariableRef),
|
Deref(NamedVariableRef),
|
||||||
|
CastTo(Box<Expression>, TypeKind),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -712,6 +712,7 @@ impl Expression {
|
|||||||
|
|
||||||
Ok(*inner)
|
Ok(*inner)
|
||||||
}
|
}
|
||||||
|
ExprKind::CastTo(expression, type_kind) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,6 +397,7 @@ impl Expression {
|
|||||||
_ => Err(ErrorKind::AttemptedDerefNonBorrow(var.1.clone())),
|
_ => Err(ErrorKind::AttemptedDerefNonBorrow(var.1.clone())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ExprKind::CastTo(expression, type_kind) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user