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
use std::any::TypeId;
use std::iter::Iterator;
use std::ptr::NonNull;

use xjbutil::void::Void;
use xjbutil::wide_ptr::WidePointer;

use crate::data::tyck::{TyckInfo, TyckInfoPool};

pub type ChildrenType = Option<Box<dyn Iterator<Item=WidePointer> + 'static>>;

pub trait StaticBase<T: 'static> {
    fn type_id() -> TypeId {
        TypeId::of::<T>()
    }

    fn tyck_info(tyck_info_pool: &mut TyckInfoPool) -> NonNull<TyckInfo> {
        tyck_info_pool.create_plain_type(TypeId::of::<T>())
    }

    fn tyck(tyck_info: &TyckInfo) -> bool {
        if let TyckInfo::Plain(type_id) = tyck_info {
            TypeId::of::<T>() == *type_id
        } else {
            false
        }
    }

    fn type_name() -> String {
        std::any::type_name::<T>().into()
    }

    #[inline] fn children(_vself: *const T) -> ChildrenType { None }
}

// impl !StaticBase<i64> for Void {}
// impl !StaticBase<f64> for Void {}
// impl !StaticBase<char> for Void {}
// impl !StaticBase<bool> for Void {}
// impl<T> !StaticBase<Option<T>> for Void {}
// impl<T, E> !StaticBase<Result<T>> for Void {}

impl StaticBase<String> for Void {
    fn type_name() -> String {
        "string".into()
    }
}

pub trait VMType<T: 'static> {}

impl<T> VMType<T> for Void where T: 'static, Void: StaticBase<T> {}
impl VMType<i64> for Void {}
impl VMType<f64> for Void {}
impl VMType<char> for Void {}
impl VMType<bool> for Void {}