1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#include "g0api/g0api.h"
#include "eir/eir.h"
#include "parse/parse.h"
#include "builtins/helpers.h"
using namespace goose;
using namespace goose::parse;
using namespace goose::builtins;
namespace goose::g0api
{
void SetupEIRExtensibilityFuncs( Env& e )
{
// Constants.
DefineConstant( e, "DelimiterOpenParen"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( Delimiter::OpenParen ) ) ) );
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "g0api/g0api.h"
#include "eir/eir.h"
#include "parse/parse.h"
#include "builtins/helpers.h"
using namespace goose;
using namespace goose::parse;
using namespace goose::g0api;
namespace
{
template< typename T >
void RegisterMkTermOverload( Env& e, const ptr< OverloadSet >& pOvlSet )
{
if constexpr( IsTypeWrapper< T >::value )
{
RegisterBuiltinFunc< TermWrapper ( T ) >( e, pOvlSet,
[]( const T& v ) -> TermWrapper
{
return TERM( v.get() );
} );
}
else
{
RegisterBuiltinFunc< TermWrapper ( T ) >( e, pOvlSet,
[]( const T& v ) -> TermWrapper
{
return TERM( v );
} );
}
}
template< typename T >
void RegisterGetTermValueOverload( Env& e, const ptr< OverloadSet >& pOvlSet )
{
if constexpr( IsTypeWrapper< T >::value )
{
RegisterBuiltinFunc< bool ( TermWrapper, TermRef< T > ) >( e, pOvlSet,
[]( const TermWrapper& t, TermRef< T >& tref )
{
const auto* pVal = get_if< typename T::type >( &t.get() );
if( !pVal )
return ToValue( false );
tref = *pVal;
return ToValue( true );
} );
}
else
{
RegisterBuiltinFunc< bool ( TermWrapper, TermRef< T > ) >( e, pOvlSet,
[]( const TermWrapper& t, TermRef< T >& tref )
{
const auto* pVal = get_if< T >( &t.get() );
if( !pVal )
return ToValue( false );
tref = *pVal;
return ToValue( true );
} );
}
}
}
namespace goose::g0api
{
void SetupEIRExtensibilityFuncs( Env& e )
{
// Constants.
DefineConstant( e, "DelimiterOpenParen"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( Delimiter::OpenParen ) ) ) );
|
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
} );
////////////////////////////
// MkTerm overloads
////////////////////////////
auto MkTerm = CreateOverloadSet( e, "MkTerm"_sid );
RegisterBuiltinFunc< TermWrapper ( uint32_t ) >( e, MkTerm,
[]( uint32_t v ) -> TermWrapper
{
return TERM( v );
} );
// TODO locId (need type wrapper)
RegisterBuiltinFunc< TermWrapper ( string ) >( e, MkTerm,
[]( string s ) -> TermWrapper
{
return TERM( s );
} );
// TODO stringId (need type wrapper)
RegisterBuiltinFunc< TermWrapper ( uint8_t ) >( e, "MkDelimiterTerm"_sid,
[]( uint8_t d ) -> TermWrapper
{
return TERM( static_cast< Delimiter >( d ) );
} );
// TODO hole (need type wrapper)
// TODO AnyTerm
// TODO VecOfLength
// TODO Vec
RegisterBuiltinFunc< TermWrapper ( BigInt ) >( e, MkTerm,
[]( BigInt bi ) -> TermWrapper
{
return TERM( bi );
} );
// TODO FixedInt
////////////////////////////
// GetTermValue overloads
////////////////////////////
auto GetTermValue = CreateOverloadSet( e, "GetTermValue"_sid );
RegisterBuiltinFunc< bool ( TermWrapper, TermRef< uint32_t > ) >( e, GetTermValue,
[]( const TermWrapper& t, TermRef< uint32_t >& tref )
{
const auto* pVal = get_if< uint32_t >( &t.get() );
if( !pVal )
return ToValue( false );
tref = *pVal;
return ToValue( true );
} );
// TODO locId (need type wrapper)
RegisterBuiltinFunc< bool ( TermWrapper, TermRef< string > ) >( e, GetTermValue,
[]( const TermWrapper& t, TermRef< string >& tref )
{
const auto* pVal = get_if< string >( &t.get() );
if( !pVal )
return ToValue( false );
tref = *pVal;
return ToValue( true );
} );
// TODO stringId (need type wrapper)
RegisterBuiltinFunc< bool ( TermWrapper, TermRef< uint8_t > ) >( e, "GetDelimiterTermValue"_sid,
[]( const TermWrapper& t, TermRef< uint8_t >& tref )
{
const auto* pVal = get_if< Delimiter >( &t.get() );
if( !pVal )
return ToValue( false );
tref = static_cast< uint8_t >( *pVal );
return ToValue( true );
} );
// TODO hole (need type wrapper)
// TODO AnyTerm
// TODO VecOfLength
// TODO Vec
RegisterBuiltinFunc< bool ( TermWrapper, TermRef< BigInt > ) >( e, GetTermValue,
[]( const TermWrapper& t, TermRef< BigInt >& tref )
{
const auto* pVal = get_if< BigInt >( &t.get() );
if( !pVal )
return ToValue( false );
tref = *pVal;
return ToValue( true );
} );
// TODO FixedInt
}
}
|
<
|
<
<
<
|
<
|
<
<
<
<
<
|
<
|
|
|
<
|
<
<
<
<
<
|
<
|
|
<
<
<
<
<
<
|
<
<
<
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
|
|
<
<
<
<
<
|
<
<
<
|
<
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
} );
////////////////////////////
// MkTerm overloads
////////////////////////////
auto MkTerm = CreateOverloadSet( e, "MkTerm"_sid );
RegisterMkTermOverload< uint32_t >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< LocationId > >( e, MkTerm );
RegisterMkTermOverload< string >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< StringId > >( e, MkTerm );
RegisterBuiltinFunc< TermWrapper ( uint8_t ) >( e, "MkDelimiterTerm"_sid,
[]( uint8_t d ) -> TermWrapper
{
return TERM( static_cast< Delimiter >( d ) );
} );
RegisterMkTermOverload< TypeWrapper< Hole > >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< AnyTerm > >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< VecOfLength > >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< pvec > >( e, MkTerm );
RegisterMkTermOverload< BigInt >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< APSInt > >( e, MkTerm );
////////////////////////////
// GetTermValue overloads
////////////////////////////
auto GetTermValue = CreateOverloadSet( e, "GetTermValue"_sid );
RegisterGetTermValueOverload< uint32_t >( e, GetTermValue );
RegisterGetTermValueOverload< TypeWrapper< LocationId > >( e, GetTermValue );
RegisterGetTermValueOverload< string >( e, GetTermValue );
RegisterGetTermValueOverload< TypeWrapper< StringId > >( e, GetTermValue );
RegisterBuiltinFunc< bool ( TermWrapper, TermRef< uint8_t > ) >( e, "GetDelimiterTermValue"_sid,
[]( const TermWrapper& t, TermRef< uint8_t >& tref )
{
const auto* pVal = get_if< Delimiter >( &t.get() );
if( !pVal )
return ToValue( false );
tref = static_cast< uint8_t >( *pVal );
return ToValue( true );
} );
RegisterGetTermValueOverload< TypeWrapper< Hole > >( e, GetTermValue );
RegisterGetTermValueOverload< TypeWrapper< AnyTerm > >( e, GetTermValue );
RegisterGetTermValueOverload< TypeWrapper< VecOfLength > >( e, GetTermValue );
RegisterGetTermValueOverload< TypeWrapper< pvec > >( e, GetTermValue );
RegisterGetTermValueOverload< BigInt >( e, GetTermValue );
RegisterGetTermValueOverload< TypeWrapper< APSInt > >( e, GetTermValue );
}
}
|