roussillon_type_system/
lib.rs

1//! # Roussillon : Type System
2//!
3//! This crate provides some structs and traits to manage types and typed values.
4//!
5//! This crate goal **IS NOT** to manage memory allocation.
6//!
7//! ## Primitive types
8//!
9//! These are the necessary types to construct any other meaningful type.
10//! Usually, these are "machine types" :
11//!
12//! - [types::primitive::Primitive::Boolean] type of [value::boolean::Boolean],
13//! - [types::primitive::Primitive::Byte] type of [value::byte::Bytes::Byte],
14//! - [types::primitive::Primitive::Bytes] type of :
15//!     - [value::byte::Bytes::Arch],
16//!     - [value::byte::Bytes::Word],
17//!     - [value::byte::Bytes::Quad],
18//!     - [value::byte::Bytes::Long],
19//!     - [value::byte::Bytes::Wide], and
20//!     - [value::byte::Bytes::Bytes],
21//! - [types::primitive::Primitive::Float] type of [value::number::Float],
22//! - [types::primitive::Primitive::Integer] type of [value::number::Integer],
23//! - [types::primitive::Primitive::Reference] type of [value::reference::Reference],
24//! - [types::primitive::Primitive::List] type of [value::list::List],
25//!
26//! ## The "tuple" type
27//!
28//! A sequence of heterogeneous typed values.
29//!
30//! - [types::sequence::Tuple] type of [value::sequence::Sequence],
31//!
32//! ## Algebraic Data Types
33//!
34//! - [types::algebraic::SumType] type of [value::union::SumValue],
35//! - [types::algebraic::ProductType] type of [value::record::ProductValue],
36//!
37//! ## Custom types
38//!
39//! These types are [identity::Identified] ADTs with [identity::Labelled] fields.
40//!
41//! - [types::typedef::Enumeration] type of [value::union::Union],
42//! - [types::typedef::Structure] type of [value::record::Record],
43//!
44//! ## Functional
45//!
46//! - [types::functional::FunctionType] type of [types::functional::FunctionDeclaration] composed in [value::function::FunctionDefinition] with [value::function::FunctionBody].
47//!
48//! ## Experimental types
49//!
50//! > These types are experimental and should not be used yet.
51//!
52//! - [types::dynamic::AnyType], [types::dynamic::Dynamic] and [value::value_type::ValueType],
53//! - [types::interface::Interface].
54//!
55
56pub mod identity;
57mod parse;
58pub mod types;
59pub mod value;
60pub mod facade;
61
62#[cfg(test)]
63mod test {
64    use std::rc::Rc;
65    use crate::types::primitive::Primitive;
66    use crate::value::concept::DataValue;
67    use crate::value::number::{Float, Integer};
68    use crate::facade::{copy_value, create_struct};
69    use crate::identity::LabelBank;
70    use crate::value::record::Record;
71
72    #[test]
73    fn test() {
74        let my_struct = create_struct("MyStruct", LabelBank::from(&[
75            "field_a",
76            "field_b",
77            "field_c",
78        ]), &[
79            Primitive::Integer.to_rc(),
80            Primitive::Integer.to_rc(),
81            Primitive::Float.to_rc(),
82        ]);
83        println!("\n{:?}", my_struct.as_ref());
84
85        let object = Record::new(Rc::clone(&my_struct), &[
86            Integer::new(40).to_cell(),
87            Integer::new(96).to_cell(),
88            Float::new(40.0).to_cell()
89        ]).unwrap();
90        println!("\n{:?}", object.clone().to_cell().borrow());
91        for i in 0..3 {
92            let field = object.get_field(i).unwrap();
93            println!("\n{:?}", field.borrow());
94        }
95
96        let copy = copy_value(my_struct.clone(), &object.clone().to_cell()).unwrap();
97        assert_eq!(object.data_type().typename(), copy.borrow().data_type().typename());
98    }
99}