Goose  Check-in [eade11527c]

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

Overview
Comment:builtins: added definitions for runtime array type.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: eade11527c035da50b1a1430689eaf3c0e6e7f02a26a012369eea6dfb10669ba
User & Date: achavasse 2019-07-15 21:58:00.837
Context
2019-07-16
20:06
builtins:
  • fixed runtime type definitions.
  • added definitions for runtime struct types.
check-in: 1f7039ee83 user: achavasse tags: trunk
2019-07-15
21:58
builtins: added definitions for runtime array type. check-in: eade11527c user: achavasse tags: trunk
21:43
builtins: added definitions for runtime pointer type. check-in: 84b541f45b 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
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







>
>







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

    types/basic.cpp
    types/decl.cpp

    types/runtime/basic.cpp
    types/runtime/pointer.cpp
    types/runtime/array.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/array.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
#include "builtins/builtins.h"

using namespace empathy;
using namespace empathy::builtins;

namespace empathy::builtins
{
    void SetupRuntimeArrayType( Env& e )
    {
        RegisterBuiltinFunc< Value ( Value, uint64_t ) >( e, "RTArray"_sid,
            []( const Value& containedType, uint64_t count )
            {
                assert( containedType.isType() );
                return ToValue( RTArray( ValueToIRExpr( containedType ), count ) );
            } );
    }
}

namespace empathy::ir
{
    Term Bridge< RTArray >::Type( const Term& arrayType, uint64_t count )
    {
        return ValueToIRExpr( Value( TypeType(), TVEC( TSID( rt_array ), TERM( count ), arrayType ) ) );
    }

    Value Bridge< RTArray >::ToValue( const RTArray& p )
    {
        return Value( Type( p.m_containedType, p.m_count ), TERM( 0ULL ) );
    }

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

        if( !result )
            return nullopt;

        auto&& [count, containedType] = *result;
        return RTArray( containedType, count );
    }
}
Added bs/builtins/types/runtime/array.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
#ifndef EMPATHY_BUILTINS_TYPES_RUNTIME_ARRAY_H
#define EMPATHY_BUILTINS_TYPES_RUNTIME_ARRAY_H

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

    struct RTArray
    {
        template< typename T >
        RTArray( T&& containedType, uint64_t count ) :
            m_containedType( forward< T >( containedType ) ),
            m_count( count )
        {}

        Term m_containedType;
        uint64_t m_count = 1;
    };
}

namespace empathy::ir
{
    template<>
    struct Bridge< builtins::RTArray >
    {
        static Term Type( const Term& arrayType, uint64_t count );
        static Value ToValue( const builtins::RTArray& a );
        static optional< builtins::RTArray > FromValue( const Value& v );
    };
}

#endif
Changes to bs/builtins/types/runtime/basic.cpp.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
        e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_double ) ), ANYTERM( _ ), GetValueType< RTDouble >() );

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

        RegisterBuiltinFunc< Value ( Value ) >( e, "RTPointer"_sid,
            []( const Value& pointedType )
            {
                assert( pointedType.isType() );
                return ToValue( RTPointer( ValueToIRExpr( pointedType ) ) );
            } );
    }
}

namespace empathy::ir
{
    //// Half
    const Term& Bridge< RTHalf >::Type()







<
<
<
<
<
<
<







12
13
14
15
16
17
18







19
20
21
22
23
24
25
        e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_double ) ), ANYTERM( _ ), GetValueType< RTDouble >() );

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







    }
}

namespace empathy::ir
{
    //// Half
    const Term& Bridge< RTHalf >::Type()
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

        if( !result )
            return nullopt;

        auto&& [numBits] = *result;
        return RTInteger( numBits );
    }

    //// Pointer
    Term Bridge< RTPointer >::Type( const Term& ptrType )
    {
        return ValueToIRExpr( Value( TypeType(), TVEC( TSID( rt_pointer ), ptrType ) ) );
    }

    Value Bridge< RTPointer >::ToValue( const RTPointer& p )
    {
        return Value( Type( p.m_pointedType ), TERM( 0ULL ) );
    }

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

        if( !result )
            return nullopt;

        auto&& [pointedType] = *result;
        return RTPointer( pointedType );
    }
}







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
84
85
86
87
88
89
90
91





























        if( !result )
            return nullopt;

        auto&& [numBits] = *result;
        return RTInteger( numBits );
    }
}




























Changes to bs/builtins/types/runtime/basic.h.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    struct RTDouble {};

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

    struct RTPointer
    {
        template< typename T >
        RTPointer( T&& pointedType ) : m_pointedType( forward< T >( pointedType ) ) {}
        Term m_pointedType;
    };

    // TODO structs and arrays.
}

namespace empathy::ir
{
    template<>
    struct Bridge< builtins::RTHalf >
    {







<
<
<
<
<
<
<
<
<







13
14
15
16
17
18
19









20
21
22
23
24
25
26
    struct RTDouble {};

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









}

namespace empathy::ir
{
    template<>
    struct Bridge< builtins::RTHalf >
    {
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    template<>
    struct Bridge< builtins::RTInteger >
    {
        static const Term& Type();
        static Value ToValue( const builtins::RTInteger& i );
        static optional< builtins::RTInteger > FromValue( const Value& v );
    };

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

#endif







<
<
<
<
<
<
<
<



45
46
47
48
49
50
51








52
53
54
    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/pointer.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
#include "builtins/builtins.h"

using namespace empathy;
using namespace empathy::builtins;

namespace empathy::builtins
{
    void SetupRuntimePointerType( Env& e )
    {
        RegisterBuiltinFunc< Value ( Value ) >( e, "RTPointer"_sid,
            []( const Value& pointedType )
            {
                assert( pointedType.isType() );
                return ToValue( RTPointer( ValueToIRExpr( pointedType ) ) );
            } );
    }
}

namespace empathy::ir
{
    Term Bridge< RTPointer >::Type( const Term& ptrType )
    {
        return ValueToIRExpr( Value( TypeType(), TVEC( TSID( rt_pointer ), ptrType ) ) );
    }

    Value Bridge< RTPointer >::ToValue( const RTPointer& p )
    {
        return Value( Type( p.m_pointedType ), TERM( 0ULL ) );
    }

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

        if( !result )
            return nullopt;

        auto&& [pointedType] = *result;
        return RTPointer( pointedType );
    }
}
Added bs/builtins/types/runtime/pointer.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
#ifndef EMPATHY_BUILTINS_TYPES_RUNTIME_POINTER_H
#define EMPATHY_BUILTINS_TYPES_RUNTIME_POINTER_H

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

    struct RTPointer
    {
        template< typename T >
        RTPointer( T&& pointedType ) : m_pointedType( forward< T >( pointedType ) ) {}

        Term m_pointedType;
    };
}

namespace empathy::ir
{
    template<>
    struct Bridge< builtins::RTPointer >
    {
        static Term Type( const Term& ptrType );
        static Value ToValue( const builtins::RTPointer& p );
        static optional< builtins::RTPointer > FromValue( const Value& v );
    };
}

#endif
Changes to 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




>
>








>
>




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

#include "basic.h"
#include "pointer.h"
#include "array.h"

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

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

#endif