Skip to main content

gaia_assembler/program/
mod.rs

1use crate::{
2    instruction::GaiaInstruction,
3    types::{GaiaSignature, GaiaType},
4};
5use serde::{Deserialize, Serialize};
6
7/// Gaia Program Module
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct GaiaModule {
10    pub name: String,
11    pub functions: Vec<GaiaFunction>,
12    pub structs: Vec<GaiaStruct>,
13    pub classes: Vec<GaiaClass>,
14    pub constants: Vec<(String, GaiaConstant)>,
15    pub globals: Vec<GaiaGlobal>,
16    pub imports: Vec<GaiaImport>,
17}
18
19/// External import entry.
20#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
21pub struct GaiaImport {
22    pub library: String,
23    pub symbol: String,
24}
25
26/// Gaia Class (for managed runtimes).
27#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
28pub struct GaiaClass {
29    pub name: String,
30    pub parent: Option<String>,
31    pub interfaces: Vec<String>,
32    pub fields: Vec<GaiaField>,
33    pub methods: Vec<GaiaFunction>,
34    pub attributes: Vec<String>,
35}
36
37/// Gaia Field definition.
38#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
39pub struct GaiaField {
40    pub name: String,
41    pub ty: GaiaType,
42    pub is_static: bool,
43    pub visibility: Visibility,
44}
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
47pub enum Visibility {
48    Public,
49    Private,
50    Protected,
51    Internal,
52}
53
54/// Gaia Function definition.
55#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
56pub struct GaiaFunction {
57    pub name: String,
58    pub signature: GaiaSignature,
59    pub blocks: Vec<GaiaBlock>,
60    pub is_external: bool,
61}
62
63/// Gaia Basic Block.
64#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65pub struct GaiaBlock {
66    pub label: String,
67    pub instructions: Vec<GaiaInstruction>,
68    pub terminator: GaiaTerminator,
69}
70
71/// Terminator instructions (control flow).
72#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
73pub enum GaiaTerminator {
74    /// Unconditional jump.
75    Jump(String),
76    /// Conditional branch (true label, false label).
77    Branch { true_label: String, false_label: String },
78    /// Function return.
79    Return,
80    /// Call and jump (callee name, argument count, next label).
81    Call { callee: String, args_count: usize, next_block: String },
82    /// Halt or exit.
83    Halt,
84}
85
86/// Gaia Struct definition.
87#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
88pub struct GaiaStruct {
89    pub name: String,
90    pub fields: Vec<(String, GaiaType)>,
91}
92
93/// Gaia Global Variable.
94#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
95pub struct GaiaGlobal {
96    pub name: String,
97    pub ty: GaiaType,
98    pub initial_value: Option<GaiaConstant>,
99}
100
101/// Gaia Constant
102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
103pub enum GaiaConstant {
104    Bool(bool),
105    I8(i8),
106    U8(u8),
107    I16(i16),
108    U16(u16),
109    I32(i32),
110    U32(u32),
111    I64(i64),
112    U64(u64),
113    F32(f32),
114    F64(f64),
115    String(String),
116    /// Raw binary data (used for weights, constant arrays, etc.)
117    Blob(Vec<u8>),
118    /// Constant array
119    Array(Vec<GaiaConstant>),
120    /// Null value or null reference
121    Null,
122}