Goose  Artifact [a2129f90fb]

Artifact a2129f90fb140cf1b122beda84679265e146b438e8e19174a2439280894dc03a:

  • File bs/builtins/types/param.h — 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: 1356)

#ifndef GOOSE_BUILTINS_TYPES_PARAM_H
#define GOOSE_BUILTINS_TYPES_PARAM_H

namespace goose::builtins
{
    template< typename T, typename V >
    auto ParamPat( T&& type, V&& val )
    {
        // If the type is a tuple of type, convert it to the type of a tuple.
        // (the type of a tuple is just a list of values, so just extract the value part of the tuple)
        if( auto typeVal = ValueFromIRExpr( type ); typeVal && IsTuple( *typeVal ) )
            return ValueToIRExpr( Value( ValueToIRExpr( TupleOfTypesToTupleType( *typeVal ) ), HOLE( "_"_sid ) ) );

        return ValueToIRExpr( Value( forward< T >( type ), forward< V >( val ) ) );
    }

    template< typename T >
    auto ParamPat( T&& type )
    {
        // If the type is a tuple of type, convert it to the type of a tuple.
        // (the type of a tuple is just a list of values, so just extract the value part of the tuple)
        if( auto typeVal = ValueFromIRExpr( type ); typeVal && IsTuple( *typeVal ) )
            return ValueToIRExpr( ValuePattern( TSID( param ), ValueToIRExpr( TupleOfTypesToTupleType( *typeVal ) ), HOLE( "_"_sid ) ) );

        return ValueToIRExpr( ValuePattern( TSID( param ), forward< T >( type ), HOLE( "_"_sid ) ) );
    }

    template< typename T >
    auto ParamPatFromTerm( T&& t )
    {
        return forward< T >( t );
    }
}

#endif