Goose  Artifact [6d037de2b6]

Artifact 6d037de2b69f86788a327216acb3965703ec1c670df4a3ddd8ef935226ff9d8d:

  • File bs/builtins/types/runtime/unify.cpp — part of check-in [f31afce8ce] at 2019-07-26 22:30:22 on branch trunk —
    • Implemented an unification rule of ct_integer versus rt_integer.
    • Fixed multiple bugs related to compile time eager evaluation.
    • Fixed incorrect usage of CompileFunc which resulted in not actually calling the domain specific version of the function.
    (user: achavasse size: 1529)

#include "builtins/builtins.h"

using namespace empathy;
using namespace empathy::ir;

namespace empathy::builtins
{
    void SetupRuntimeTypesUnification( Env& e )
    {
        auto rtTypePattern = Value( TypeType(), TVEC( TSID( rt_type ),
            ANYTERM( _ ),
            TSID( rt_integer ), ANYTERM( _ ) ) );

        // ct_integer constant unification against a RTInteger:
        // Check if the RTInteger is big enough for the constant,
        // and emit a LoadConstantInt llr instruction if so.
        e.unificationRuleSet()->addSymRule(

            ValueToIRExpr( Value(
                GetValueType< uint64_t >(),
                ANYTERM( _ ) ) ),

            ValueToIRExpr( ValuePattern(
                ANYTERM( _ ),
                ValueToIRExpr( rtTypePattern ),
                ANYTERM( _ ) ) ),

        []( const Term& lhs, const Term& rhs, UnificationContext& c ) -> UniGen
        {
            auto ct = *FromValue< uint64_t >( *ValueFromIRExpr( lhs ) );
            auto rhsVal = *ValuePatternFromIRExpr( rhs );
            auto rttypeVal = *ValueFromIRExpr( rhsVal.type() );
            auto rttype = *FromValue< RTInteger >( rttypeVal );

            if( ( 1 << rttype.m_numBits ) > ct )
            {
                auto* llvmType = static_cast< llvm::IntegerType* >( GetLLVMType( rttypeVal ) );
                co_yield { ValueToIRExpr( Value( rhsVal.type(),
                    make_shared< llr::Instruction >( llr::LoadConstInt( llvmType, ct ) ) ) ), c };
            }
        } );
    }
}