gaia_assembler/types/mod.rs
1//! Gaia Assembler Core Type Definitions
2
3use serde::{Deserialize, Serialize};
4
5/// Gaia Address Spaces
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub enum AddressSpace {
8 /// Generic or default address space.
9 Generic,
10 /// Stack or local memory.
11 Local,
12 /// Global memory.
13 Global,
14 /// Shared memory (e.g., GPU LDS).
15 Shared,
16 /// Constant memory.
17 Constant,
18 /// Managed heap (e.g., JVM/CLR).
19 Managed,
20}
21
22/// Gaia Type System
23#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
24pub enum GaiaType {
25 // --- Scalar Types ---
26 /// 1-bit boolean type.
27 Bool,
28 /// 8-bit signed integer.
29 I8,
30 /// 8-bit unsigned integer.
31 U8,
32 /// 16-bit signed integer.
33 I16,
34 /// 16-bit unsigned integer.
35 U16,
36 /// 32-bit signed integer.
37 I32,
38 /// 32-bit unsigned integer.
39 U32,
40 /// 64-bit signed integer.
41 I64,
42 /// 64-bit unsigned integer.
43 U64,
44 /// 16-bit half-precision floating point.
45 F16,
46 /// 32-bit single-precision floating point.
47 F32,
48 /// 64-bit double-precision floating point.
49 F64,
50
51 // --- Composite Types ---
52 /// Pointer type (pointee type, address space).
53 Pointer(Box<GaiaType>, AddressSpace),
54 /// Array type (element type, length).
55 Array(Box<GaiaType>, usize),
56 /// Vector type (element type, count).
57 Vector(Box<GaiaType>, usize),
58 /// Struct type (name/ID).
59 Struct(String),
60 /// String type (managed or raw).
61 String,
62
63 // --- Managed Types ---
64 /// Dynamic object type (e.g., Python/JS).
65 Object,
66 /// Managed class (e.g., JVM/CLR).
67 Class(String),
68 /// Interface or Trait.
69 Interface(String),
70 /// Dynamic or arbitrary type (Variant).
71 Any,
72
73 // --- Domain-Specific Types ---
74 /// Tensor type (element type, shape).
75 /// Shape uses -1 for dynamic dimensions.
76 Tensor(Box<GaiaType>, Vec<isize>),
77
78 // --- Special Types ---
79 /// Void type.
80 Void,
81 /// Opaque type for external references.
82 Opaque(String),
83 /// Function pointer.
84 FunctionPtr(Box<GaiaSignature>),
85}
86
87impl GaiaType {
88 /// Check if this is an integer type.
89 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 /// Check if this is a floating point type.
97 pub fn is_float(&self) -> bool {
98 match self {
99 Self::F16 | Self::F32 | Self::F64 => true,
100 _ => false,
101 }
102 }
103}
104
105/// Function signature.
106#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
107pub struct GaiaSignature {
108 pub params: Vec<GaiaType>,
109 pub return_type: GaiaType,
110}