Goose  Artifact [b3b06c1cd7]

Artifact b3b06c1cd76862e1189c9f453a0a1ed5d500e47a8a633eb9ec63538dc2fca678:

  • File bs/builtins/types/template/tdecl.cpp — part of check-in [64224a915f] at 2022-07-04 17:45:47 on branch trunk — Refactored some template rules and type checking rules to avoid calling BuildTemplateSignature from inside type checking rules (user: zlodo size: 1375)

#include "builtins/builtins.h"

using namespace goose::builtins;

namespace goose::builtins
{
    bool IsTDecl( const Value& td )
    {
        return td.type() == GetValueType< TDecl >();
    }

    Term TDeclSigPattern( const Term& name, Term&& sig )
    {
        return VEC( TSID( tdecl_sig ), name, move( sig ) );
    }

    tuple< StringId, Term > DecomposeTDSig( const Term& tdsig )
    {
        auto result = Decompose( tdsig,
            Vec(
                Lit( "tdecl_sig"_sid ),
                Val< StringId >(),
                SubTerm()
            )
        );

        auto&& [name,sig] = *result;
        return { name, sig };
    }
}

namespace goose::eir
{
    const Term& Bridge< TDecl >::Type()
    {
        static auto type = ValueToEIR( Value( TypeType(), TSID( tdecl ) ) );
        return type;
    }

    Value Bridge< TDecl >::ToValue( const TDecl& td )
    {
        return Value( Type(), VEC( 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( type, name );
    }
}