Goose  Check-in [54b8960363]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:builtins: added definitions for basic runtime types.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 54b8960363c1fcf6180c72a08355229083c9f80d8a79f7bd70f0bec1c8a60b9a
User & Date: achavasse 2019-07-15 20:21:07.084
Context
2019-07-15
21:13
sema: removed a couple of superfluous rule lookups when resolving an invocation. check-in: c7da710bb0 user: achavasse tags: trunk
20:21
builtins: added definitions for basic runtime types. check-in: 54b8960363 user: achavasse tags: trunk
19:10
builtins: renamed int and string to ct_int and ct_string to distinguish them from the future runtime and user facing types. In the end there should be little to no reason to ever use these types directly outside of the library anyway. check-in: f40cfaed57 user: achavasse tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to bs/builtins/CMakeLists.txt.
1
2
3
4
5


6
7
8
9
10
11
12
add_library( empathy-builtins
    helpers.cpp

    types/basic.cpp
    types/decl.cpp



    types/tuple/tuple.cpp
    types/tuple/unify.cpp

    types/func/bfunc.cpp
    types/func/func.cpp
    types/func/build.cpp





>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
add_library( empathy-builtins
    helpers.cpp

    types/basic.cpp
    types/decl.cpp

    types/runtime/basic.cpp

    types/tuple/tuple.cpp
    types/tuple/unify.cpp

    types/func/bfunc.cpp
    types/func/func.cpp
    types/func/build.cpp
Added bs/builtins/types/runtime/basic.cpp.














































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "builtins/builtins.h"

using namespace empathy;
using namespace empathy::builtins;

namespace empathy::builtins
{
    void SetupRuntimeBasicTypes( Env& e )
    {
        e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_half ) ), ANYTERM( _ ), GetValueType< RTHalf >() );
        e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_float ) ), ANYTERM( _ ), GetValueType< RTFloat >() );
        e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_double ) ), ANYTERM( _ ), GetValueType< RTDouble >() );

        RegisterBuiltinFunc< uint64_t ( uint64_t ) >( e, "RTInteger"_sid,
            []( uint64_t numBits )
            {
                return ToValue( RTInteger( numBits ) );
            } );
    }
}

namespace empathy::ir
{
    const Term& Bridge< RTHalf >::Type()
    {
        static auto type = ValueToIRExpr( Value( TypeType(), TSID( rt_half ) ) );
        return type;
    }

    const Value& Bridge< RTHalf >::TypeVal()
    {
        static auto type = Value( TypeType(), TSID( rt_half ) );
        return type;
    }

    const Term& Bridge< RTFloat >::Type()
    {
        static auto type = ValueToIRExpr( Value( TypeType(), TSID( rt_float ) ) );
        return type;
    }

    const Value& Bridge< RTFloat >::TypeVal()
    {
        static auto type = Value( TypeType(), TSID( rt_float ) );
        return type;
    }

    const Term& Bridge< RTDouble >::Type()
    {
        static auto type = ValueToIRExpr( Value( TypeType(), TSID( rt_double ) ) );
        return type;
    }

    const Value& Bridge< RTDouble >::TypeVal()
    {
        static auto type = Value( TypeType(), TSID( rt_double ) );
        return type;
    }

    const Term& Bridge< RTInteger >::Type()
    {
        static auto type = ValueToIRExpr( Value( TypeType(), TSID( rt_integer ) ) );
        return type;
    }

    Value Bridge< RTInteger >::ToValue( const RTInteger& i )
    {
        return Value( Type(), TERM( i.m_numBits ) );
    }

    optional< RTInteger > Bridge< RTInteger >::FromValue( const Value& v )
    {
        auto typeVal = ValueFromIRExpr( v.type() );
        auto result = Decompose( typeVal->val(),
            Vec(
                Lit( "decl"_sid ),
                Val< uint64_t >()
            )
        );

        if( !result )
            return nullopt;

        auto&& [numBits] = *result;
        return RTInteger( numBits );
    }
}
Added bs/builtins/types/runtime/basic.h.
















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#ifndef EMPATHY_BUILTINS_TYPES_RUNTIME_BASIC_H
#define EMPATHY_BUILTINS_TYPES_RUNTIME_BASIC_H

namespace empathy::builtins
{
    extern void SetupRuntimeBasicTypes( Env& e );

    // Stand-ins for runtime types, used to specialize
    // Bridge to provide the corresponding IR types representations.
    // Most don't carry any parameter.
    struct RTHalf {};
    struct RTFloat {};
    struct RTDouble {};

    struct RTInteger
    {
        RTInteger( uint32_t numBits ) : m_numBits( numBits ) {}
        uint32_t m_numBits = 1;
    };

    // TODO structs, arrays, and pointers.
}

namespace empathy::ir
{
    template<>
    struct Bridge< builtins::RTHalf >
    {
        static const Term& Type();
        static const Value& TypeVal();
    };

    template<>
    struct Bridge< builtins::RTFloat >
    {
        static const Term& Type();
        static const Value& TypeVal();
    };

    template<>
    struct Bridge< builtins::RTDouble >
    {
        static const Term& Type();
        static const Value& TypeVal();
    };

    template<>
    struct Bridge< builtins::RTInteger >
    {
        static const Term& Type();
        static Value ToValue( const builtins::RTInteger& i );
        static optional< builtins::RTInteger > FromValue( const Value& v );
    };
}

#endif
Added bs/builtins/types/runtime/runtime.h.
































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef EMPATHY_BUILTINS_TYPES_RUNTIME_H
#define EMPATHY_BUILTINS_TYPES_RUNTIME_H

#include "basic.h"

namespace empathy::builtins
{
    extern void SetupRuntimeBasicTypes( Env& e );

    static inline void SetupRuntimeTypes( Env& e )
    {
        SetupRuntimeBasicTypes( e );
    }
}

#endif
Changes to bs/builtins/types/types.h.
1
2
3
4
5

6
7
8
9
10
11
12
#ifndef EMPATHY_BUILTINS_TYPES_H
#define EMPATHY_BUILTINS_TYPES_H

#include "basic.h"
#include "decl.h"

#include "tuple/tuple.h"
#include "func/bfunc.h"
#include "func/func.h"
#include "func/build.h"

#include "template/tvar.h"
#include "template/tdecl.h"





>







1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef EMPATHY_BUILTINS_TYPES_H
#define EMPATHY_BUILTINS_TYPES_H

#include "basic.h"
#include "decl.h"
#include "runtime/runtime.h"
#include "tuple/tuple.h"
#include "func/bfunc.h"
#include "func/func.h"
#include "func/build.h"

#include "template/tvar.h"
#include "template/tdecl.h"
36
37
38
39
40
41
42

43
44
45
46
        SetupTemplateFunctionInvocationRule( e );
        SetupTemplateFunctionUnification( e );
        SetupTDeclUnification( e );
        SetupOverloadSetInvocationRule( e );
        SetupOverloadSetUnification( e );
        SetupConstrainedFuncInvocationRule( e );
        SetupConstrainedFuncUnification( e );

    }
}

#endif







>




37
38
39
40
41
42
43
44
45
46
47
48
        SetupTemplateFunctionInvocationRule( e );
        SetupTemplateFunctionUnification( e );
        SetupTDeclUnification( e );
        SetupOverloadSetInvocationRule( e );
        SetupOverloadSetUnification( e );
        SetupConstrainedFuncInvocationRule( e );
        SetupConstrainedFuncUnification( e );
        SetupRuntimeTypes( e );
    }
}

#endif