Goose  Artifact [1e3e9976a9]

Artifact 1e3e9976a9ba567e9e795345ab5ed4a7cff8e8eda19d534f480f4d333fbfb706:

  • File bs/builtins/types/localvar.cpp — part of check-in [3e177bc8cf] at 2019-08-08 09:59:54 on branch trunk — Implemented the localvar builtin type. (user: achavasse size: 1096)
  • File bs/builtins/types/localvar/localvar.cpp — part of check-in [c9a44e2fb9] at 2019-08-08 16:53:15 on branch trunk —
    • Implemented the local variable unification rule, which allows to read them.
    • Fixed comparison operators not returning bools.
    (user: achavasse size: 1096)

#include "builtins/builtins.h"

using namespace empathy::builtins;

namespace empathy::ir
{
    Term Bridge< LocalVar >::Type( const Term& type )
    {
        return ValueToIRExpr( Value( TypeType(), TVEC( TSID( local_var ), type ) ) );
    }

    Value Bridge< LocalVar >::ToValue( const LocalVar& d )
    {
        return Value( Type( d.type() ), TVEC( TERM( d.cfgId() ), TERM( d.index() ) ) );
    }

    optional< LocalVar > Bridge< LocalVar >::FromValue( const Value& v )
    {
        auto typeVal = ValueFromIRExpr( v.type() );
        auto result = Decompose( typeVal->val(),
            Vec(
                Lit( "local_var"_sid ),
                SubTerm()
            )
        );

        if( !result )
            return nullopt;

        auto valResult = Decompose( v.val(),
            Vec(
                Val< uint64_t >(),
                Val< uint64_t >()
            )
        );

        if( !valResult )
            return nullopt;

        auto&& [type] = *result;
        auto&& [cfgId,index] = *valResult;

        return LocalVar( move( type ), cfgId, index );
    }
}