1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include "builtins/builtins.h"
using namespace empathy;
using namespace empathy::builtins;
namespace empathy::builtins
{
void SetupRuntimePointerType( Env& e )
{
RegisterBuiltinFunc< Eager< Value > ( Value ) >( e, "pointer"_sid,
[]( const Value& pointedType )
{
if( !GetLLVMType( pointedType ) )
{
// TODO come up with some lightweight builtin option type
// for the builtin apis, because this is a very bullshit
|
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include "builtins/builtins.h"
using namespace empathy;
using namespace empathy::builtins;
namespace empathy::builtins
{
void SetupRuntimePointerType( Env& e )
{
// null pointer literal
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( nullptr ) ), ANYTERM( _ ), ValueToIRExpr( ToValue( NullPointer() ) ) );
RegisterBuiltinFunc< Eager< Value > ( Value ) >( e, "pointer"_sid,
[]( const Value& pointedType )
{
if( !GetLLVMType( pointedType ) )
{
// TODO come up with some lightweight builtin option type
// for the builtin apis, because this is a very bullshit
|
45
46
47
48
49
50
51
52
|
if( !result )
return nullopt;
auto&& [llvmType, pointedType] = *result;
return PointerType( pointedType );
}
}
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
if( !result )
return nullopt;
auto&& [llvmType, pointedType] = *result;
return PointerType( pointedType );
}
const Value& Bridge< NullPointerType >::ToValue( const NullPointerType& np )
{
static auto val = Value( Type(), TSID( nullptr ) );
return val;
}
optional< NullPointerType > Bridge< NullPointerType >::FromValue( const Value& v )
{
auto result = Decompose( v.val(),
Lit( "nullptr"_sid )
);
if( !result )
return nullopt;
return NullPointerType();
}
const Term& Bridge< NullPointer >::Type()
{
static auto type = ValueToIRExpr( ir::ToValue( NullPointerType() ) );
return type;
}
const Value& Bridge< NullPointer >::ToValue( const NullPointer& np )
{
static auto val = Value( Type(), TSID( nullptr ) );
return val;
}
optional< NullPointer > Bridge< NullPointer >::FromValue( const Value& v )
{
if( !FromValue< NullPointerType >( *ValueFromIRExpr( v.type() ) ) )
return nullopt;
auto result = Decompose( v.val(),
Lit( "nullptr"_sid )
);
if( !result )
return nullopt;
return NullPointer();
}
}
|