Goose  Artifact [66fdccbf22]

Artifact 66fdccbf226fc3cdf7290ff6e9530f70802d6a8b2d3e0749c4843e281b201665:

  • File bs/builtins/types/template/tfunc.cpp — part of check-in [114cdaf51b] at 2019-02-22 21:43:18 on branch trunk — Templates: implemented BuildTFuncType() and BuildTFunc(). (user: achavasse size: 1199)

#include "builtins/builtins.h"
#include "lex/lex.h"
#include "parse/parse.h"

using namespace empathy::builtins;
using namespace empathy::parse;

namespace empathy::ir
{
    const Term& Bridge< TFunc >::Type( const builtins::TFunc& tf )
    {
        static auto type = ValueToIRExpr( ::ToValue( tf.type() ) );
        return type;
    }

    Value Bridge< TFunc >::ToValue( const TFunc& tf )
    {
        return Value( Type( tf ), TVEC( tf.signature(),
            TERM( static_pointer_cast< void >( tf.toks() ) ) ) );
    }

    optional< TFunc > Bridge< TFunc >::FromValue( const Value& v )
    {
        auto typeVal = ValueFromIRExpr( v.type() );
        auto type = ::FromValue< TFuncType >( *typeVal );
        if( !type )
            return nullopt;

        auto result = Decompose( v.val(),
            Vec(
                SubTerm(),              // signature
                Val< ptr< void > >()    // toks
            )
        );

        if( !result )
            return nullopt;

        auto&& [signature, toks] = *result;
        auto pBodyToks = static_pointer_cast< vector< Term > >( toks );

        return TFunc( move( *type ), move( signature ), move( pBodyToks ) );
    }
}