#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 >() );
}
}