Goose  Artifact [7ddf3664d4]

Artifact 7ddf3664d4a5f77bcdf343daee323e61e2b727a6f90adf453ba3eceadf4aaa51:

  • File bs/builtins/types/runtime/array.cpp — part of check-in [4edaeb8115] at 2020-07-09 21:33:54 on branch llr-stack-language — Starting a new branch to turn the llr into a stack language, still structured as a cfg. Cut off the llvm backend from the build for now. (user: achavasse size: 1703)

#include "builtins/builtins.h"
#include "builtins/helpers.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( ValueToIRExpr( containedType ), count ) );
            } );
    }

    llvm::Type* GetLLVMType( const ArrayType& a )
    {
        // DISABLE_CODEGEN
        return nullptr; //llvm::ArrayType::get( GetLLVMType( *ValueFromIRExpr( a.m_containedType ) ), a.m_count );
    }
}

namespace goose::ir
{
    Value Bridge< ArrayType >::ToValue( const ArrayType& a )
    {
        return Value( Type(), MkStdRTType( TSID( array ),
            GetLLVMType( a ),
            TERM( a.m_count ), a.m_containedType ) );
    }

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

        if( !result )
            return nullopt;

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