#include "builtins/builtins.h"
using namespace empathy::builtins;
namespace empathy::builtins
{
bool IsTExpr( const Value& te )
{
if( te.isConstant() )
{
const auto* ppVec = get_if< pvec >( &te.val().content() );
if( ppVec && !( *ppVec )->empty()
&&( **ppVec )[0] == TSID( texpr ) )
{
return true;
}
}
auto typeVal = ValueFromIRExpr( te.type() );
if( !typeVal )
return false;
const auto* ppVec = get_if< pvec >( &typeVal->val().content() );
if( !ppVec )
return false;
if( ( *ppVec )->empty() )
return false;
return ( **ppVec )[0] == TSID( texpr );
}
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 ), TVEC( TSID( texpr ), 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 );
}
}