Skip to main content

factorio_ir/
enumeration.rs

1use crate::{
2    debug::StructDebug, expression::Expression, function::Function, structure::StructField,
3    r#type::Type,
4};
5
6/// How an enum variant carries its payload.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum EnumVariantFields {
9    /// `Color::Red`
10    Unit,
11    /// `Msg::Move(x, y)` - positional fields lowered as `_1`, `_2`, ...
12    Tuple { types: Vec<Type> },
13    /// `Msg::Move { x, y }`
14    Named(Vec<StructField>),
15}
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct EnumVariant {
19    pub name: String,
20    pub fields: EnumVariantFields,
21}
22
23/// A user-defined enum: method table plus tagged-table values at runtime.
24#[derive(Debug, Clone, PartialEq)]
25pub struct Enum {
26    pub name: String,
27    pub variants: Vec<EnumVariant>,
28    pub constants: Vec<(String, Expression)>,
29    pub methods: Vec<Function>,
30    pub doc: Option<String>,
31    pub debug: Option<StructDebug>,
32}