#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 ) );
}
}