#include "builtins/builtins.h"
using namespace empathy::builtins;
namespace empathy::builtins
{
bool IsTDecl( const Value& td )
{
return td.type() == GetValueType< TDecl >();
}
}
namespace empathy::ir
{
const Term& Bridge< TDecl >::Type()
{
static auto type = ValueToIRExpr( Value( TypeType(), TSID( tdecl ) ) );
return type;
}
Value Bridge< TDecl >::ToValue( const TDecl& td )
{
return Value( Type(), TVEC( td.type(), TERM( td.name() ) ) );
}
optional< TDecl > Bridge< TDecl >::FromValue( const Value& v )
{
if( !IsTDecl( v ) )
return nullopt;
auto result = Decompose( v.val(),
Vec(
SubTerm(),
Val< StringId >()
)
);
if( !result )
return nullopt;
auto&& [type,name] = *result;
return TDecl( move( type ), name );
}
}