Goose  Artifact [0fb2bcab89]

Artifact 0fb2bcab89258dec90e1da13fc5af690db0b25b4dc9a13cda02a31290b97f0f4:

  • File bs/builtins/types/template/tfunc.cpp — part of check-in [27fc719d74] at 2019-08-16 14:48:20 on branch trunk — Added a new type of template expression: TVec, along with a helper function to make it possible for parametric types to be constructed either normally or as a template expression when passed template parameters. Only used by LocalVar for now, parametric runtime types require some refactoring. (user: achavasse size: 1154)

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

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

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

    Value Bridge< TFunc >::ToValue( const TFunc& tf )
    {
        return Value( Type( tf ), VEC( Quote( tf.signature() ), tf.identity(),
            TERM( 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
                SubTerm(),              // identity
                Val< ptr< void > >()    // toks
            )
        );

        if( !result )
            return nullopt;

        auto&& [signature, identity, toks] = *result;

        return TFunc( move( *type ), *Unquote( signature ),
            identity, toks );
    }
}