Goose  Artifact [e68360f01f]

Artifact e68360f01f5d35709bbb0530b92a6007a0bd8cbfaa6433fd2ea51c9b6eeb216a:

  • File bs/builtins/types/runtime/pointer.cpp — part of check-in [64244c6d0c] at 2019-07-22 14:50:03 on branch trunk — builtins: runtime types: added a common prefix to easily be able to check if a type is a runtime type. (user: achavasse size: 1051)

#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
{
    Value Bridge< RTPointer >::ToValue( const RTPointer& p )
    {
        return Value( Type(), TVEC( TSID( rt_type ), TSID( rt_pointer ), p.m_pointedType ) );
    }

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

        if( !result )
            return nullopt;

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