Goose  Artifact [7adf4bef51]

Artifact 7adf4bef51c064d002d5823445abf1c0fa87e50d3c6dd2b75226bb78aa1caee8:

  • File bs/builtins/types/func/invocation/bfunc.cpp — part of check-in [b4d5bdf6ec] at 2022-06-18 18:51:47 on branch cir-stack-language —
    • Added a location id to all CIR instructions (needed with the stack based approach to locate intermediate results)
    • Fixed a bunch of verifier errors
    • Re-enabled most verifier tests, other than some requiring to re-implement a few more bits
    (user: zlodo size: 1778) [more...]

#include "builtins/builtins.h"
#include "common.h"

using namespace goose::sema;

namespace goose::builtins
{
    class BuiltinFuncInvocationRule : public BaseFuncInvocationRule
    {
        public:
            Value invoke( Context& c, LocationId loc, const Value& callee, const Term& args, const Term& typeCheckedCallPat, TypeCheckingContext& tcc ) const final
            {
                auto callDecomp = Decompose( typeCheckedCallPat,
                    Val< pvec >()
                );

                const auto& typeCheckedRType = callDecomp->get()->terms().front();
                auto typeCheckedArgs = DropVectorTerm( typeCheckedCallPat, 1 );
                auto argCount = VecSize( typeCheckedArgs );
                auto argsInstrSeq = BuildArgsInstrSeq( typeCheckedArgs );

                return BuildComputedValue( typeCheckedRType, argsInstrSeq, callee, cir::Call( argCount, loc ) );
            }

            Value prepareFunc( const Context& c, LocationId funcValLocation, const Value& callee, const Term& typeCheckedCallPat, TypeCheckingContext& tcc ) const final
            {
                return callee;
            }
    };

    const ptr< InvocationRule >& GetBuiltinFuncInvocationRule()
    {
        static ptr< InvocationRule > pRule = make_shared< BuiltinFuncInvocationRule >();
        return pRule;
    }

    void SetupBuiltinFuncInvocationRule( Env& e )
    {
        e.invocationRuleSet()->addRule(
            ValueToEIR( ValuePattern( ANYTERM( _ ),

                ValueToEIR( Value( TypeType(), VEC( TSID( func ),
                TSID( builtin ),
                ANYTERM( _ ), ANYTERM( _ ),
                ANYTERM( _ ), ANYTERM( _ ) ) ) ),

                ANYTERM( _ ) ) ),
            GetBuiltinFuncInvocationRule() );
    }
}