Goose  Artifact [f741efa183]

Artifact f741efa1831bde106d288de23087333f36e3e742efc34c208ddeed529919ab95:

  • File bs/sema/uni-quote.cpp — part of check-in [c39a302502] at 2020-05-23 12:58:20 on branch trunk —
    • Fixed the hole matching score which prevented some unification rules to be selected.
    • Implemented LowerTypeForRuntime for tuples.
    • Implemented an unification rule for constant tuples.
    • Added some debugging helpers.
    (user: achavasse size: 1021)

#include "sema.h"

namespace goose::sema
{
    Term Quote( const Term& t )
    {
        return SetComplexity( VEC( TSID( quote ), t ), 0 );
    }

    optional< Term > Unquote( const Term& t )
    {
        auto result = Decompose( t,
            Vec(
                Lit( "quote"_sid ),
                SubTerm()
            )
        );

        if( !result )
            return nullopt;

        auto&& [quoted] = *result;
        return quoted;
    }

    void SetupQuoteUnificationRules( UnificationRuleSet& ruleSet )
    {
        ruleSet.addHalfUnificationRule( URINFOS, VEC( TSID( quote ), ANYTERM( _ ) ),
            []( const Term& lhs, UnificationContext& c ) -> UniGen
            {
                co_yield { lhs, c };
            } );

        ruleSet.addSymRule( URINFOS, VEC( TSID( quote ), ANYTERM( _ ) ),
            []( const Term& lhs, const Term& rhs, UnificationContext& c ) -> UniGen
            {
                if( lhs == rhs )
                    co_yield { lhs, c };
            } );
    }
}