Skip to main content

normalize_surface_syntax/ir/
mod.rs

1//! Core IR types for surface syntax translation.
2//!
3//! This IR is deliberately minimal and opcode-agnostic. It represents
4//! common programming constructs without domain-specific knowledge.
5//!
6//! Domain operations like `lotus.spawn_entity(x)` are just function calls -
7//! the runtime (spore) provides the actual implementations.
8
9mod expr;
10mod stmt;
11mod structure_eq;
12
13pub use expr::*;
14pub use stmt::*;
15pub use structure_eq::StructureEq;
16
17use serde::{Deserialize, Serialize};
18
19/// A complete program/module.
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21pub struct Program {
22    /// Top-level statements.
23    pub body: Vec<Stmt>,
24}
25
26impl Program {
27    pub fn new(body: Vec<Stmt>) -> Self {
28        Self { body }
29    }
30}
31
32/// A function definition.
33#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
34pub struct Function {
35    /// Function name (empty for anonymous functions).
36    pub name: String,
37    /// Parameter names.
38    pub params: Vec<String>,
39    /// Function body.
40    pub body: Vec<Stmt>,
41}
42
43impl Function {
44    pub fn new(name: impl Into<String>, params: Vec<String>, body: Vec<Stmt>) -> Self {
45        Self {
46            name: name.into(),
47            params,
48            body,
49        }
50    }
51
52    pub fn anonymous(params: Vec<String>, body: Vec<Stmt>) -> Self {
53        Self::new("", params, body)
54    }
55}