1use std::{cell::RefCell, fmt, rc::Rc};
2
3use rimu_ast::{SpannedBlock, SpannedExpression};
4
5use crate::{native::NativeFunction, Environment};
6
7#[derive(Debug, Clone)]
8pub struct Function {
9 pub args: Vec<String>,
10 pub body: FunctionBody,
11 pub env: Rc<RefCell<Environment>>,
12}
13
14impl PartialEq for Function {
15 fn eq(&self, other: &Self) -> bool {
16 self.args.eq(&other.args) && self.body.eq(&other.body) && Rc::ptr_eq(&self.env, &other.env)
17 }
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
21pub enum FunctionBody {
22 Block(SpannedBlock),
23 Expression(SpannedExpression),
24 Native(NativeFunction),
25}
26
27impl fmt::Display for Function {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 write!(f, "function")
30 }
31}