#include "builtins/builtins.h"
using namespace empathy;
using namespace empathy::builtins;
namespace empathy::builtins
{
void SetupRuntimeArrayType( Env& e )
{
RegisterBuiltinFunc< Value ( Value, uint64_t ) >( e, "RTArray"_sid,
[]( const Value& containedType, uint64_t count )
{
assert( containedType.isType() );
return ToValue( RTArray( ValueToIRExpr( containedType ), count ) );
} );
}
}
namespace empathy::ir
{
Term Bridge< RTArray >::Type( const Term& arrayType, uint64_t count )
{
return ValueToIRExpr( Value( TypeType(), TVEC( TSID( rt_array ), TERM( count ), arrayType ) ) );
}
Value Bridge< RTArray >::ToValue( const RTArray& p )
{
return Value( Type( p.m_containedType, p.m_count ), TERM( 0ULL ) );
}
optional< RTArray > Bridge< RTArray >::FromValue( const Value& v )
{
auto typeVal = ValueFromIRExpr( v.type() );
auto result = Decompose( typeVal->val(),
Vec(
Lit( "rt_array"_sid ),
Val< uint64_t >(),
SubTerm()
)
);
if( !result )
return nullopt;
auto&& [count, containedType] = *result;
return RTArray( containedType, count );
}
}