Goose  Artifact [e9404a81ff]

Artifact e9404a81ff3c3d444e6858897eda5d7a19f1e949eeac2683e02aab6d87530cc6:

  • File bs/builtins/types/texpr/tvar.cpp — part of check-in [2d763f32b8] at 2019-02-14 22:36:21 on branch trunk — Templates: added TVar type. (user: achavasse size: 791)

#include "builtins/builtins.h"

using namespace empathy::builtins;

namespace empathy::builtins
{
    bool IsTVar( const Value& tv )
    {
        return tv.type() == GetValueType< TVar >();
    }
}

namespace empathy::ir
{
    const Term& Bridge< TVar >::Type()
    {
        static auto type = ValueToIRExpr( Value( TSID( type ), TSID( tvar ) ) );
        return type;
    }

    Value Bridge< TVar >::ToValue( TVar&& td )
    {
        return Value( Type(), TERM( td.name() ) );
    }

    optional< TVar > Bridge< TVar >::FromValue( const Value& v )
    {
        if( !IsTVar( v ) )
            return nullopt;

        auto result = Decompose( v.val(),
            Val< StringId >()
        );

        if( !result )
            return nullopt;

        return TVar( *result );
    }
}