use cairo_lang_defs::diagnostic_utils::StableLocation;
use cairo_lang_semantic as semantic;
use super::context::LoweringContext;
use super::LoweredExpr;
use crate::VariableId;
pub fn extern_facade_return_tys(
ctx: &mut LoweringContext<'_>,
ret_ty: semantic::TypeId,
) -> Vec<semantic::TypeId> {
if let semantic::TypeLongId::Tuple(tys) = ctx.db.lookup_intern_type(ret_ty) {
tys
} else {
vec![ret_ty]
}
}
pub fn extern_facade_expr(
ctx: &mut LoweringContext<'_>,
ty: semantic::TypeId,
returns: Vec<VariableId>,
location: StableLocation,
) -> LoweredExpr {
if let semantic::TypeLongId::Tuple(subtypes) = ctx.db.lookup_intern_type(ty) {
assert_eq!(returns.len(), subtypes.len());
LoweredExpr::Tuple {
exprs: returns.into_iter().map(LoweredExpr::AtVariable).collect(),
location,
}
} else {
assert_eq!(returns.len(), 1);
LoweredExpr::AtVariable(returns.into_iter().next().unwrap())
}
}