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
|
#include "builtins/builtins.h"
#include "precedence.h"
#include "helpers.h"
using namespace empathy;
using namespace empathy::ir;
using namespace empathy::parse;
namespace empathy::builtins
{
void SetupCommaOp( Env& e )
{
BuildParseRule( e, ","_sid,
LeftAssInfixOp( "operator_comma"_sid, precedence::CommaOp,
// Overload: any tuple, anything
ForTypes< CustomPattern< Value, TuplePattern >, Value >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
if( IsOpenTuple( lhs ) )
{
if( IsOpenTuple( rhs ) )
return ConcatenateTuples( lhs, rhs );
return AppendToTuple( lhs, rhs );
}
if( IsOpenTuple( rhs ) )
return PrependToTuple( lhs, rhs );
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
// Overload: anything, anything
ForType< Value >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} )
)
);
}
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
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
71
72
73
|
#include "builtins/builtins.h"
#include "precedence.h"
#include "helpers.h"
using namespace empathy;
using namespace empathy::ir;
using namespace empathy::parse;
namespace empathy::builtins
{
void SetupCommaOp( Env& e )
{
using LocVarOfAnyType =
CustomPattern< LocalVar, LocalVar::PatternAny >;
BuildParseRule( e, ","_sid,
LeftAssInfixOp( "operator_comma"_sid, precedence::CommaOp,
// Overload: any tuple, anything
ForTypes< CustomPattern< Value, TuplePattern >, Value >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
if( IsOpenTuple( lhs ) )
{
if( IsOpenTuple( rhs ) )
return ConcatenateTuples( lhs, rhs );
return AppendToTuple( lhs, rhs );
}
if( IsOpenTuple( rhs ) )
return PrependToTuple( lhs, rhs );
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
// Overload: anything, anything
ForType< Value >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
// By default, locvars return their content during unification.
// Since we want to keep them as is in tuples, we need specific overloads that will
// get locvars as such.
ForType< LocVarOfAnyType >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
ForTypes< CustomPattern< Value, TuplePattern >, LocVarOfAnyType >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
if( IsOpenTuple( lhs ) )
return AppendToTuple( lhs, rhs );
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
ForTypes< LocVarOfAnyType, CustomPattern< Value, TuplePattern > >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
if( IsOpenTuple( rhs ) )
return PrependToTuple( lhs, rhs );
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} )
)
);
}
}
|