Goose  Artifact [e84f85fa76]

Artifact e84f85fa7608294d87077c9ff0213ee407731c4fb59273ef39085d1649bbd5c4:

  • File bs/builtins/types/overloadset/helpers.cpp — part of check-in [c768853a4f] at 2019-07-22 13:15:30 on branch trunk — Added a helper to perform a compile time OverloadSet invocation. (user: achavasse size: 931)

#include "builtins/builtins.h"
#include "execute/execute.h"

namespace empathy::builtins
{
    ptr< OverloadSet > CreateOverloadSet( Env& env, const StringId& name )
    {
        auto identity = AppendToVectorTerm( RootIdentity(), TERM( name ) );
        auto pOvlSet = make_shared< OverloadSet >( identity );
        env.storeValue( identity, ANYTERM( _ ), ValueToIRExpr( ToValue( pOvlSet ) ) );
        return pOvlSet;
    }

    optional< Value > InvokeOverloadSet( const Context& c, const ptr< OverloadSet >& pOvlSet, const Value& args )
    {
        Context localC( make_shared< Env >( *c.env() ), InjectDomainIntoIdentity( c.identity(), DomainCompileTime() ), GetValueType< uint64_t >() );

        auto val = ResolveInvocation( localC, GetOverloadSetInvocationRule(), ToValue( pOvlSet ), args );
        if( !val )
            return nullopt;

        execute::VM vm;
        return execute::Evaluate( *val, vm );
    }
}