use crate::def::DefId;
use crate::native::NativeTypeId;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RtType {
Any,
Unit,
Bool,
Str,
Bytes,
Float { name: &'static str },
Int {
name: &'static str,
min: i64,
max: i64,
},
Tuple(Vec<RtType>),
List,
Map,
Adt {
def: DefId,
name: String,
},
Native {
id: NativeTypeId,
name: String,
},
Ptr,
Fn {
params: Vec<RtType>,
ret: Box<RtType>,
},
Type,
}
impl std::fmt::Display for RtType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Any => f.write_str("_"),
Self::Unit => f.write_str("()"),
Self::Bool => f.write_str("bool"),
Self::Str => f.write_str("str"),
Self::Bytes => f.write_str("bytes"),
Self::Float { name } => f.write_str(name),
Self::Int { name, .. } => f.write_str(name),
Self::Tuple(tys) => {
let tys: Vec<_> = tys.iter().map(ToString::to_string).collect();
write!(f, "({})", tys.join(", "))
}
Self::Ptr => f.write_str("*_"),
Self::List => f.write_str("[_]"),
Self::Map => f.write_str("map"),
Self::Adt { name, .. } | Self::Native { name, .. } => f.write_str(name),
Self::Fn { params, ret } => {
let params: Vec<_> = params.iter().map(ToString::to_string).collect();
write!(f, "fn({}) -> {}", params.join(", "), ret)
}
Self::Type => f.write_str("type"),
}
}
}