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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use indexmap::{
    map::{Entry, Values},
    IndexMap,
};
use nyar_error::{NyarError, Result};
use nyar_wasm::Identifier;
use std::{
    fmt::{Debug, Formatter},
    ops::AddAssign,
};
use valkyrie_ast::{helper::WrapDisplay, ClassDeclaration, ClassTerm, IdentifierNode, NamePathNode};

// mod codegen;
mod parser;

#[derive(Clone, Eq, PartialEq)]
pub struct ValkyrieStructure {
    pub(crate) symbol: Identifier,
    pub(crate) fields: IndexMap<String, ValkyrieField>,
    pub(crate) methods: IndexMap<String, ValkyrieMethod>,
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ValkyrieField {}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ValkyrieMethod {}

impl Debug for ValkyrieStructure {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Structure")
            .field("symbol", &WrapDisplay::new(&self.symbol))
            .field("fields", &self.fields.values())
            // .field("methods", &self.methods.values())
            .finish()
    }
}

impl AddAssign<ValkyrieField> for ValkyrieStructure {
    fn add_assign(&mut self, rhs: ValkyrieField) {
        // self.fields.insert(rhs.name(), rhs);
    }
}
//
// impl AddAssign<MethodDefinition> for ValkyrieStructure {
//     fn add_assign(&mut self, rhs: MethodDefinition) {
//         self.methods.insert(rhs.name(), rhs);
//     }
// }

impl ValkyrieStructure {
    pub fn new(space: &NamePathNode, name: &IdentifierNode) -> Self {
        todo!()
    }
    pub fn name(&self) -> String {
        self.symbol.to_string()
    }
    // pub fn get_field(&self, name: &str) -> Option<&ValkyrieField> {
    //     self.fields.get(name)
    // }
    // pub fn add_field(&mut self, field: ValkyrieField) -> Result<()> {
    //     let name = field.name();
    //     let span = field.get_span();
    //     match self.fields.insert(field.name(), field) {
    //         Some(old) => Err(NyarError::duplicate_key(name, old.get_span(), span)),
    //         None => Ok(()),
    //     }
    // }
    // pub fn get_fields(&self) -> Values<String, ValkyrieField> {
    //     self.fields.values()
    // }
    // pub fn add_method(&mut self, method: MethodDefinition) -> Result<()> {
    //     let name = method.name();
    //     let span = method.get_span();
    //     match self.methods.insert(method.name(), method) {
    //         Some(old) => Err(NyarError::duplicate_key(name, old.get_span(), span)),
    //         None => Ok(()),
    //     }
    // }
}