Goose  Diff

Differences From Artifact [2b9930028d]:

  • File bs/builtins/types/overloadset/overloadset.cpp — part of check-in [aebe047a28] at 2019-03-15 20:34:46 on branch trunk — Overloading: added OverloadSet type. (user: achavasse size: 896)

To Artifact [814bfa2d61]:

  • File bs/builtins/types/overloadset/overloadset.cpp — part of check-in [5f82b82cc8] at 2019-03-16 15:19:32 on branch trunk — Overloading: implemented OverloadSet::add() (user: achavasse size: 1545)

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
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






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+





-
+





-
+

-
+


-
+


-
+






-
+

-
+


#include "builtins/builtins.h"

using namespace empathy::builtins;

namespace empathy::builtins
{
    void OverloadSet::add( const Term& signature, const Value& callable )
    {
        auto result = Decompose( signature,
            Vec(
                Val< pvec >(),
                SubTerm()
            )
        );

        assert( result );

        auto&& [params,rt] = *result;
        const auto& rtype = rt;

        m_trie = m_trie->merge( *params, [&]( auto&& rtTrie )
        {
            return Merge( rtTrie, rtype, [&]( auto&& )
            {
                return callable;
            } );
        } );
    }

    bool IsOverloadSet( const Value& os )
    {
        return os.type() == GetValueType< OverloadSet >();
        return os.type() == GetValueType< ptr< OverloadSet > >();
    }
}

namespace empathy::ir
{
    const Term& Bridge< OverloadSet >::Type()
    const Term& Bridge< ptr< builtins::OverloadSet > >::Type()
    {
        static auto type = ValueToIRExpr( Value( TSID( type ), TSID( overloadset ) ) );
        return type;
    }

    Value Bridge< OverloadSet >::ToValue( OverloadSet&& td )
    Value Bridge< ptr< builtins::OverloadSet > >::ToValue( const ptr< builtins::OverloadSet >& os )
    {
        return Value( Type(), TERM( static_pointer_cast< void >( td.utrie() ) ) );
        return Value( Type(), TERM( static_pointer_cast< void >( os ) ) );
    }

    optional< OverloadSet > Bridge< OverloadSet >::FromValue( const Value& v )
    ptr< builtins::OverloadSet > Bridge< ptr< builtins::OverloadSet > >::FromValue( const Value& v )
    {
        if( !IsOverloadSet( v ) )
            return nullopt;
            return nullptr;

        auto result = Decompose( v.val(),
            Val< ptr< void > >()
        );

        if( !result )
            return nullopt;
            return nullptr;

        return OverloadSet( *result );
        return static_pointer_cast< builtins::OverloadSet >( result->get() );
    }
}