#include "builtins/builtins.h"

using namespace goose::builtins;

bool goose::builtins::IsOverloadSet( const Value& os )
{
    return os.type() == GetValueType< ptr< OverloadSet > >();
}

namespace goose::eir
{
    const Term& Bridge< ptr< sema::OverloadSet > >::Type()
    {
        static auto type =
            ValueToEIR( Value( TypeType(), VEC( TSID( ct_type ), TSID( overloadset ) ) ) );
        return type;
    }

    Value Bridge< ptr< sema::OverloadSet > >::ToValue( const ptr< sema::OverloadSet >& os )
    {
        return Value( Type(), TERM( static_pointer_cast< void >( os ) ) );
    }

    optional< ptr< sema::OverloadSet > > Bridge< ptr< sema::OverloadSet > >::FromValue(
        const Value& v )
    {
        if( !IsOverloadSet( v ) )
            return nullopt;

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

        if( !result )
            return nullopt;

        return static_pointer_cast< sema::OverloadSet >( result->get() );
    }
} // namespace goose::eir
