Goose  Artifact [de358cc8a2]

Artifact de358cc8a23f19ac1f11268bf5098aee2a41ffa01efd46a433d1dd4cd0a1073b:

  • File bs/builtins/types/decl.cpp — part of check-in [aee388d9c0] at 2019-08-09 19:54:22 on branch trunk — Cleanup: got rid of the half-assed location and poisoning systems in ir::Terms. (user: achavasse size: 1352)

#include "builtins/builtins.h"

using namespace empathy::builtins;

namespace empathy::builtins
{
    bool IsDecl( const Value& d )
    {
        auto typeVal = ValueFromIRExpr( d.type() );
        auto result = Decompose( typeVal->val(),
            Vec(
                Lit( "decl"_sid ),
                SubTerm()
            )
        );

        return !!result;
    }

    const Term& Decl::PatternTypeT::GetPattern()
    {
        static auto pattern = ValueToIRExpr(
            Value( TypeType(), TVEC( TSID( decl ), MkHole( "T"_sid ) ) ) );

        return pattern;
    }
}

namespace empathy::ir
{
    Term Bridge< Decl >::Type( const Term& declType )
    {
        return ValueToIRExpr( Value( TypeType(), TVEC( 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 = ValueFromIRExpr( 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 );
    }
}