#include "builtins/builtins.h"
using namespace goose::builtins;
namespace goose::builtins
{
bool IsDecl( const Value& d )
{
auto typeVal = ValueFromEIR( d.type() );
auto result = Decompose( typeVal->val(),
Vec(
Lit( "decl"_sid ),
SubTerm()
)
);
return !!result;
}
const Term& Decl::Pattern::GetPattern()
{
static auto pattern = ValueToEIR(
Value( TypeType(), VEC( TSID( decl ), HOLE( "_"_sid ) ) ) );
return pattern;
}
}
namespace goose::eir
{
Term Bridge< Decl >::Type( const Term& declType )
{
return ValueToEIR( Value( TypeType(), VEC( TSID( decl ), declType ) ) );
}
Value Bridge< Decl >::ToValue( const Decl& d )
{
return Value( Type( d.type() ), TERM( d.name() ) );
}
optional< Decl > Bridge< Decl >::FromValue( const Value& v )
{
auto typeVal = ValueFromEIR( v.type() );
auto result = Decompose( typeVal->val(),
Vec(
Lit( "decl"_sid ),
SubTerm()
)
);
if( !result )
return nullopt;
auto&& [type] = *result;
const auto& name = get< StringId >( v.val() );
return Decl( move( type ), name );
}
}