Goose  Diff

Differences From Artifact [50a35b4666]:

  • File bs/builtins/types/runtime/array.cpp — part of check-in [1ad61a2717] at 2021-11-11 20:05:58 on branch trunk — Refactored the code builder: it is now carried around as a Value, and accessed through a bunch of extension points, so we can have different builders (and even user defined ones) later to make classes etc. (user: zlodo size: 1672)

To Artifact [c835010917]:

  • File bs/builtins/types/runtime/array.cpp — part of check-in [0c646816e4] at 2023-02-20 17:54:25 on branch trunk — Migrated to clang16/llvm16. Created a shitty layer on top of llvm to cope with losing the pointee types from llvm pointer types (which are now opaques). It was a huge pain in the ass. (user: zlodo size: 1726)

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

using namespace goose;
using namespace goose::builtins;

namespace goose::builtins
{
    void SetupRuntimeArrayType( Env& e )
    {
        RegisterBuiltinFunc< Eager< Value > ( Value, uint32_t ) >( e, "array"_sid,
            []( const Value& containedType, uint32_t count )
            {
                if( !GetLLVMType( containedType ) )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( containedType.locationId(), "runtime arrays can only contain runtime types." );
                    return PoisonValue();
                }

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

    llvm::Type* GetLLVMType( const ArrayType& a )
    {

        return llvm::ArrayType::get( GetLLVMType( *EIRToValue( a.m_containedType ) ), a.m_count );
    }
}

namespace goose::eir
{
    Value Bridge< ArrayType >::ToValue( const ArrayType& a )
    {
        return Value( Type(), MkStdRTType( TSID( rt_type ),
            GetLLVMType( a ), 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 ),
                SubTerm(),
                Val< void* >(),
                Lit( "array"_sid ),
                Val< uint64_t >(),
                SubTerm()
            )
        );

        if( !result )
            return nullopt;

        auto&& [predicates, llvmType, count, containedType] = *result;
        return ArrayType( 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
54
55
56
57
58
#include "builtins/builtins.h"

using namespace goose;
using namespace goose::builtins;

namespace goose::builtins
{
    void SetupRuntimeArrayType( Env& e )
    {
        RegisterBuiltinFunc< Eager< Value > ( Value, uint32_t ) >( e, "array"_sid,
            []( const Value& containedType, uint32_t count )
            {
                if( !GetCodegenType( containedType ) )
                {
                    DiagnosticsManager::GetInstance().emitErrorMessage( containedType.locationId(), "runtime arrays can only contain runtime types." );
                    return PoisonValue();
                }

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

    const codegen::Type* GetCodegenType( const ArrayType& a )
    {
        return codegen::Type::Get( llvm::ArrayType::get(
            *GetCodegenType( *EIRToValue( a.m_containedType ) ), a.m_count ) );
    }
}

namespace goose::eir
{
    Value Bridge< ArrayType >::ToValue( const ArrayType& a )
    {
        return Value( Type(), MkStdRTType( TSID( rt_type ),
            GetCodegenType( a ), 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 ),
                SubTerm(),
                Val< void* >(),
                Lit( "array"_sid ),
                Val< uint64_t >(),
                SubTerm()
            )
        );

        if( !result )
            return nullopt;

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