#include "builtins/builtins.h"
namespace goose::builtins
{
void SetupBuiltinTypes( Env& e )
{
SetupDefaultTypeExtPoints( e );
SetupPredicatesTypeChecking( e );
SetupBasicTypes( e );
SetupBasicTypesPrettyPrinting();
SetupTupleTypeChecking( e );
SetupFunctionInvocationRule( e );
SetupFunctionTypeChecking( e );
SetupFunctionLowering( e );
SetupTemplateRules( e );
SetupTemplateFunctionInvocationRule( e );
SetupTemplateFunctionTypeChecking( e );
SetupTDeclTypeChecking( e );
SetupTemplatePrettyPrinting();
SetupOverloadSetInvocationRule( e );
SetupOverloadSetTypeChecking( e );
SetupConstrainedFuncInvocationRule( e );
SetupConstrainedFuncTypeChecking( e );
SetupLocalVarDropValue( e );
SetupLocalVarTypeChecking( e );
SetupLocalVarInvocationRule( e );
SetupReferenceTypeChecking( e );
SetupRefTypeParsingRule( e );
SetupReferenceInitialize( e );
SetupReferenceLowering( e );
SetupRuntimeTypes( e );
SetupInitialize( e );
SetupDestroyValue( e );
SetupDropValue( e );
SetupLower( e );
SetupConvert( e );
SetupTupleTypeExtPoints( e );
SetupTupleInitialize( e );
SetupTupleDestroyValue( e );
SetupTupleDropValue( e );
SetupTupleLowering( e );
SetupRuntimeBasicTypesInitialize( e );
}
void SetupDefaultTypeExtPoints( Env& e )
{
RegisterBuiltinFunc< Intrinsic< bool ( Value ) > >( e, e.extIsType(),
[]( const Context& c, const Value& v )
{
return ToValue( false );
} );
RegisterBuiltinFunc< Intrinsic< bool ( CustomPattern< Value, PatternType > ) > >( e, e.extIsType(),
[]( const Context& c, const Value& v )
{
return ToValue( true );
} );
RegisterBuiltinFunc< Intrinsic< Value ( CustomPattern< Value, PatternType > ) > >( e, e.extToType(),
[]( const Context& c, const Value& v )
{
return v;
} );
}
bool IsType( const Context& c, const Value& v )
{
if( v.isType() )
return true;
auto result = InvokeOverloadSet( c,
c.env()->extIsType(),
MakeTuple( v ) );
if( result.isPoison() )
{
PoisonBuilder( c );
return false;
}
auto boolRes = FromValue< bool >( result );
if( !boolRes )
{
DiagnosticsManager::GetInstance().emitErrorMessage( v.locationId(),
"the IsType extension point returned a non boolean value." );
PoisonBuilder( c );
return false;
}
return *boolRes;
}
Value ToType( const Context& c, const Value& v )
{
auto result = InvokeOverloadSet( c,
c.env()->extToType(),
MakeTuple( v ) );
if( result.isPoison() )
{
PoisonBuilder( c );
return PoisonType();
}
if( !result.isType() )
{
DiagnosticsManager::GetInstance().emitErrorMessage( v.locationId(),
"the ToType extension point returned a non type value." );
PoisonBuilder( c );
return PoisonType();
}
return result;
}
}