1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub enum AddressSpace {
8 Generic,
10 Local,
12 Global,
14 Shared,
16 Constant,
18 Managed,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
24pub enum GaiaType {
25 Bool,
28 I8,
30 U8,
32 I16,
34 U16,
36 I32,
38 U32,
40 I64,
42 U64,
44 F16,
46 F32,
48 F64,
50
51 Pointer(Box<GaiaType>, AddressSpace),
54 Array(Box<GaiaType>, usize),
56 Vector(Box<GaiaType>, usize),
58 Struct(String),
60 String,
62
63 Object,
66 Class(String),
68 Interface(String),
70 Any,
72
73 Tensor(Box<GaiaType>, Vec<isize>),
77
78 Void,
81 Opaque(String),
83 FunctionPtr(Box<GaiaSignature>),
85}
86
87impl GaiaType {
88 pub fn is_integer(&self) -> bool {
90 match self {
91 Self::I8 | Self::U8 | Self::I16 | Self::U16 | Self::I32 | Self::U32 | Self::I64 | Self::U64 => true,
92 _ => false,
93 }
94 }
95
96 pub fn is_float(&self) -> bool {
98 match self {
99 Self::F16 | Self::F32 | Self::F64 => true,
100 _ => false,
101 }
102 }
103}
104
105impl std::fmt::Display for GaiaType {
106 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
107 match self {
108 Self::Bool => write!(f, "bool"),
109 Self::I8 => write!(f, "i8"),
110 Self::U8 => write!(f, "u8"),
111 Self::I16 => write!(f, "i16"),
112 Self::U16 => write!(f, "u16"),
113 Self::I32 => write!(f, "i32"),
114 Self::U32 => write!(f, "u32"),
115 Self::I64 => write!(f, "i64"),
116 Self::U64 => write!(f, "u64"),
117 Self::F16 => write!(f, "f16"),
118 Self::F32 => write!(f, "f32"),
119 Self::F64 => write!(f, "f64"),
120 Self::Pointer(ty, _) => write!(f, "*{}", ty),
121 Self::Array(ty, len) => write!(f, "[{}; {}]", ty, len),
122 Self::Vector(ty, count) => write!(f, "vec{}<{}>", count, ty),
123 Self::Struct(name) => write!(f, "struct {}", name),
124 Self::String => write!(f, "string"),
125 Self::Object => write!(f, "object"),
126 Self::Class(name) => write!(f, "class {}", name),
127 Self::Interface(name) => write!(f, "interface {}", name),
128 Self::Any => write!(f, "any"),
129 Self::Tensor(ty, shape) => write!(f, "tensor<{}; {:?}>", ty, shape),
130 Self::Void => write!(f, "void"),
131 Self::Opaque(name) => write!(f, "opaque {}", name),
132 Self::FunctionPtr(sig) => write!(f, "fn({}) -> {}", sig.params.iter().map(|p| p.to_string()).collect::<Vec<_>>().join(", "), sig.return_type),
133 }
134 }
135}
136
137
138
139#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
141pub struct GaiaSignature {
142 pub params: Vec<GaiaType>,
144 pub return_type: GaiaType,
146}
147
148pub mod mapping;