Goose  Artifact [be4d6a0eb7]

Artifact be4d6a0eb7c55688d4374175f535e495b0241a934778f3bf901257646a8fb3cf:

  • File bs/builtins/types/template/tfunc.h — part of check-in [06b4cded56] at 2019-03-25 22:39:47 on branch trunk — Higher order functions: it is now possible to bind a template lambda to a function typed parameter. (user: achavasse size: 1553)

#ifndef EMPATHY_BUILTINS_TYPES_TEMPLATE_TFUNC_H
#define EMPATHY_BUILTINS_TYPES_TEMPLATE_TFUNC_H

namespace empathy::builtins
{
    extern void SetupTemplateFunctionInvocationRule( Env& e );
    extern void SetupTemplateFunctionUnification( Env& e );

    class TFunc
    {
        public:
            template< typename T, typename S, typename I, typename V >
            TFunc( T&& type, S&& signature, I&& identity, V&& toks ) :
                m_type( forward< T >( type ) ),
                m_signature( forward< S >( signature ) ),
                m_identity( forward< I >( identity ) ),
                m_toks( forward< V >( toks ) )
            {}

            const auto& type() const { return m_type; }
            const auto& signature() const { return m_signature; }
            const auto& identity() const { return m_identity; }
            const auto& toks() const { return m_toks; }

        private:
            TFuncType                   m_type;
            Term                        m_signature;
            Term                        m_identity;
            ptr< vector< ir::Term > >   m_toks;
    };

    extern optional< Value > InstantiateTFunc( const Context& c, const Value& callee, const Term& unifiedCallPat, UnificationContext& uc );
}

namespace empathy::ir
{
    template<>
    struct Bridge< builtins::TFunc >
    {
        static Term Type( const builtins::TFunc& tf );
        static Value ToValue( const builtins::TFunc& tf );
        static optional< builtins::TFunc > FromValue( const Value& v );
    };
}

#endif