summaryrefslogtreecommitdiff
path: root/src/ast/provided_module.cpp
blob: 8d32fb960c81c1ff882c8a53ea2226d8b04496c5 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 */
#include "ast.hpp"

void AST_InitProvidedModule_Impls();

AST::Module g_compiler_module;
AST::Path   g_copy_marker_path;
AST::Path   g_sized_marker_path;

void AST_InitProvidedModule()
{
    // "struct str([u8])"
    g_compiler_module.add_struct(true, "str",
        AST::Struct( AST::MetaItems(), AST::GenericParams(), ::std::vector<AST::StructItem> {
            AST::StructItem("", TypeRef(TypeRef::TagUnsizedArray(), TypeRef(CORETYPE_U8)), false),
        }));
    
    // TODO: Defer this until AFTER 
    AST_InitProvidedModule_Impls();
}

void AST_InitProvidedModule_Impls()
{
    if( !g_copy_marker_path.is_valid() ) {
        g_copy_marker_path = AST::Path( "", {AST::PathNode("marker"),AST::PathNode("Copy")} );
    }
    
    if( !g_sized_marker_path.is_valid() ) {
        g_sized_marker_path = AST::Path( "", {AST::PathNode("marker"),AST::PathNode("Sized")} );
    }
    
    #define impl(trait, type) \
        g_compiler_module.add_impl(AST::Impl(AST::MetaItems(), AST::GenericParams(), type, trait))
    impl(g_copy_marker_path, TypeRef(CORETYPE_U8));
    impl(g_copy_marker_path, TypeRef(CORETYPE_U16));
    impl(g_copy_marker_path, TypeRef(CORETYPE_U32));
    impl(g_copy_marker_path, TypeRef(CORETYPE_U64));
    impl(g_copy_marker_path, TypeRef(CORETYPE_UINT));
    impl(g_copy_marker_path, TypeRef(CORETYPE_I8));
    impl(g_copy_marker_path, TypeRef(CORETYPE_I16));
    impl(g_copy_marker_path, TypeRef(CORETYPE_I32));
    impl(g_copy_marker_path, TypeRef(CORETYPE_I64));
    impl(g_copy_marker_path, TypeRef(CORETYPE_INT));
    impl(g_copy_marker_path, TypeRef(CORETYPE_F32));
    impl(g_copy_marker_path, TypeRef(CORETYPE_F64));
    
    // A hacky default impl of 'Sized', with a negative impl on [T]
    impl(g_sized_marker_path, TypeRef());
    
    {
        AST::GenericParams tps;
        tps.add_ty_param( AST::TypeParam("T") );
        g_compiler_module.add_neg_impl(AST::ImplDef(
            AST::MetaItems(), ::std::move(tps),
            g_sized_marker_path,
            TypeRef(TypeRef::TagUnsizedArray(), TypeRef(TypeRef::TagArg(), "T"))
            ));
    }
}