Goose  Artifact [ba9ce0d963]

Artifact ba9ce0d963c077305c9b2d1e1acccaf68171c55b74f8564be3969d1efd738c53:

  • File bs/builtins/types/localvar/invoke.cpp — part of check-in [10df99e08a] at 2020-05-04 18:43:39 on branch trunk — Refactored the Initialize() extension point to take a mutable reference instead of directly taking a locvar. (user: achavasse size: 1283)

#include "builtins/builtins.h"

using namespace goose::sema;

namespace goose::builtins
{
    class LocVarInvocationRule : public InvocationRule
    {
        public:
            bool canBeInvoked( const Context& c, const Value& callee ) const final
            {
                auto lv = *FromValue< LocalVar >( callee );

                auto val = BuildComputedValue( lv.type(),
                    llr::Load( llr::VarAddress( lv.index() ), lv.type() ) );

                return sema::CanBeInvoked( c, val );
            }

            Value resolveInvocation( const Context& c, uint32_t locationId, const Value& callee, const Value& args ) const final
            {
                auto lv = *FromValue< LocalVar >( callee );

                auto val = BuildComputedValue( lv.type(),
                    llr::Load( llr::VarAddress( lv.index() ), lv.type() ) );

                return sema::GetInvocationRule( *c.env(), val )->resolveInvocation( c, locationId, val, args );
            }
    };

    void SetupLocalVarInvocationRule( Env& e )
    {
        e.invocationRuleSet()->addRule(
            ValueToIRExpr( Value(
                GetValueType< LocalVar >( ANYTERM( _ ) ),
                ANYTERM( _ ) ) ),
            make_shared< LocVarInvocationRule >() );
    }
}