use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AddressSpace {
Generic,
Local,
Global,
Shared,
Constant,
Managed,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum GaiaType {
Bool,
I8,
U8,
I16,
U16,
I32,
U32,
I64,
U64,
F16,
F32,
F64,
Pointer(Box<GaiaType>, AddressSpace),
Array(Box<GaiaType>, usize),
Vector(Box<GaiaType>, usize),
Struct(String),
String,
Object,
Class(String),
Interface(String),
Any,
Tensor(Box<GaiaType>, Vec<isize>),
Void,
Opaque(String),
FunctionPtr(Box<GaiaSignature>),
}
impl GaiaType {
pub fn is_integer(&self) -> bool {
match self {
Self::I8 | Self::U8 | Self::I16 | Self::U16 | Self::I32 | Self::U32 | Self::I64 | Self::U64 => true,
_ => false,
}
}
pub fn is_float(&self) -> bool {
match self {
Self::F16 | Self::F32 | Self::F64 => true,
_ => false,
}
}
}
impl std::fmt::Display for GaiaType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Bool => write!(f, "bool"),
Self::I8 => write!(f, "i8"),
Self::U8 => write!(f, "u8"),
Self::I16 => write!(f, "i16"),
Self::U16 => write!(f, "u16"),
Self::I32 => write!(f, "i32"),
Self::U32 => write!(f, "u32"),
Self::I64 => write!(f, "i64"),
Self::U64 => write!(f, "u64"),
Self::F16 => write!(f, "f16"),
Self::F32 => write!(f, "f32"),
Self::F64 => write!(f, "f64"),
Self::Pointer(ty, _) => write!(f, "*{}", ty),
Self::Array(ty, len) => write!(f, "[{}; {}]", ty, len),
Self::Vector(ty, count) => write!(f, "vec{}<{}>", count, ty),
Self::Struct(name) => write!(f, "struct {}", name),
Self::String => write!(f, "string"),
Self::Object => write!(f, "object"),
Self::Class(name) => write!(f, "class {}", name),
Self::Interface(name) => write!(f, "interface {}", name),
Self::Any => write!(f, "any"),
Self::Tensor(ty, shape) => write!(f, "tensor<{}; {:?}>", ty, shape),
Self::Void => write!(f, "void"),
Self::Opaque(name) => write!(f, "opaque {}", name),
Self::FunctionPtr(sig) => write!(f, "fn({}) -> {}", sig.params.iter().map(|p| p.to_string()).collect::<Vec<_>>().join(", "), sig.return_type),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct GaiaSignature {
pub params: Vec<GaiaType>,
pub return_type: GaiaType,
}
pub mod mapping;