Skip to main content

lift_core/
functions.rs

1use crate::interning::StringId;
2use crate::location::Location;
3use crate::regions::RegionKey;
4use crate::types::TypeId;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct FunctionData {
9    pub name: StringId,
10    pub params: Vec<TypeId>,
11    pub returns: Vec<TypeId>,
12    pub body: Option<RegionKey>,
13    pub location: Location,
14    pub is_declaration: bool,
15}
16
17impl FunctionData {
18    pub fn new(name: StringId, params: Vec<TypeId>, returns: Vec<TypeId>) -> Self {
19        Self {
20            name,
21            params,
22            returns,
23            body: None,
24            location: Location::unknown(),
25            is_declaration: false,
26        }
27    }
28
29    pub fn num_params(&self) -> usize {
30        self.params.len()
31    }
32
33    pub fn num_returns(&self) -> usize {
34        self.returns.len()
35    }
36}