Goose  Artifact [c4e2b2097e]

Artifact c4e2b2097eb6e2e6ad615f670380fd28d2fc0199315bbf74838431b9a99457d8:

  • File bs/builtins/types/runtime/array.cpp — part of check-in [eade11527c] at 2019-07-15 21:58:00 on branch trunk — builtins: added definitions for runtime array type. (user: achavasse size: 1320)

#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 );
    }
}