Goose  Diff

Differences From Artifact [905d5822ea]:

  • File bs/builtins/types/runtime/array.cpp — part of check-in [3c074f1b7d] at 2019-07-30 22:05:49 on branch trunk —
    • Builtin functions are now explicitely marked if they need to be evaluated eagerly.
    • Using errors out if the expression doesn't evaluate to a constant.
    (user: achavasse size: 1602)

To Artifact [b4aa07a586]:

  • File bs/builtins/types/runtime/array.cpp — part of check-in [fbc9052f6a] at 2019-08-06 22:22:48 on branch trunk — Renamed runtime types, because most of them (except pointers) will have to be available during compile time as well, so their names may as well be generic. (user: achavasse size: 1606)

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
#include "builtins/builtins.h"

using namespace empathy;
using namespace empathy::builtins;

namespace empathy::builtins
{
    void SetupRuntimeArrayType( Env& e )
    {
        RegisterBuiltinFunc< Eager< Value > ( Value, uint64_t ) >( e, "RTArray"_sid,
            []( const Value& containedType, uint64_t count )
            {
                if( !GetLLVMType( containedType ) )
                {
                    // TODO come up with some lightweight builtin option type
                    // for the builtin apis, because this is a very bullshit
                    // way to handle errors
                    return ToValue( "error"s );
                }

                return ToValue( RTArray( ValueToIRExpr( containedType ), count ) );
            } );
    }
}

namespace empathy::ir
{
    Value Bridge< RTArray >::ToValue( const RTArray& a )
    {
        return Value( Type(), TVEC( TSID( rt_type ),
            TERM( llvm::ArrayType::get( GetLLVMType( *ValueFromIRExpr( a.m_containedType ) ), a.m_count ) ),
            TSID( rt_array ), TERM( a.m_count ), a.m_containedType ) );
    }

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

        if( !result )
            return nullopt;

        auto&& [llvmType, count, containedType] = *result;
        return RTArray( containedType, count );
    }
}









|










|






|



|


|





|









|


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
#include "builtins/builtins.h"

using namespace empathy;
using namespace empathy::builtins;

namespace empathy::builtins
{
    void SetupRuntimeArrayType( Env& e )
    {
        RegisterBuiltinFunc< Eager< Value > ( Value, uint64_t ) >( e, "array"_sid,
            []( const Value& containedType, uint64_t count )
            {
                if( !GetLLVMType( containedType ) )
                {
                    // TODO come up with some lightweight builtin option type
                    // for the builtin apis, because this is a very bullshit
                    // way to handle errors
                    return ToValue( "error"s );
                }

                return ToValue( ArrayType( ValueToIRExpr( containedType ), count ) );
            } );
    }
}

namespace empathy::ir
{
    Value Bridge< ArrayType >::ToValue( const ArrayType& a )
    {
        return Value( Type(), TVEC( TSID( rt_type ),
            TERM( llvm::ArrayType::get( GetLLVMType( *ValueFromIRExpr( a.m_containedType ) ), a.m_count ) ),
            TSID( array ), TERM( a.m_count ), a.m_containedType ) );
    }

    optional< ArrayType > Bridge< ArrayType >::FromValue( const Value& v )
    {
        auto result = Decompose( v.val(),
            Vec(
                Lit( "rt_type"_sid ),
                Val< void* >(),
                Lit( "array"_sid ),
                Val< uint64_t >(),
                SubTerm()
            )
        );

        if( !result )
            return nullopt;

        auto&& [llvmType, count, containedType] = *result;
        return ArrayType( containedType, count );
    }
}