1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::rc::Rc;

use crate::identity::Identifier;
use crate::types::concept::{DataType, Type};
use crate::types::sequence::Tuple;
use crate::value::concept::ValueCell;
use crate::value::error::TypeResult;

#[derive(Clone, Debug)]
pub struct FunctionType {
    pub arguments: Tuple,
    pub return_type: Type,
}

impl FunctionType {
    pub fn new(arguments: Tuple, return_type: Type) -> Self { Self { arguments, return_type } }
    pub fn to_rc(self) -> Rc<Self> { Rc::new(self) }
}

impl DataType for FunctionType {
    fn size(&self) -> usize { 8 }

    fn typename(&self) -> String {
        format!("{} -> {}", self.arguments.typename(), self.return_type)
    }

    fn construct_from_raw(&self, _raw: &[u8]) -> TypeResult<ValueCell> {
        todo!()
    }
}

#[derive(Clone, Debug)]
pub struct FunctionDeclaration {
    pub identifier: Identifier,
    pub signature: FunctionType,
}

impl FunctionDeclaration {
    pub fn new(identifier: Identifier, signature: FunctionType) -> Self {
        Self { identifier, signature }
    }
}