about summary refs log tree commit diff
path: root/src/types/mod.rs
blob: ecea5789b1ef44ede224e91c89cab62abebfc9a5 (plain)
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
pub mod bag;

use std::cell::RefCell;
use std::collections::HashMap;

use crate::interpret::value::ValueMap;
use crate::parse::ast::nodes::Identifier;

#[derive(Debug, Clone)]
pub struct Type {
    kind: Box<TypeKind>,
    global_associated_values: &'static RefValueMap,
}

#[derive(Debug, Clone)]
pub enum TypeKind {
    // Concrete types
    Str,
    Int,
    Float,
    Bool,
    Void,
    Fn {
        parameters: TypeMap,
        returns: Type,
    },
    Array(Type),
    Tuple(Vec<Type>),
    Data {
        data: TypeMap,
        associated_values: RefValueMap,
    },
    // TODO: Implement abstract types.
    // These should also definitely have `associated_values`,
    // but as they're not implemented yet...
    Face(TypeMap),
    Var(TypeMap),
}

type TypeMap = HashMap<Identifier, Type>;

type RefValueMap = RefCell<ValueMap>;