1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include "builtins/builtins.h"
#include "precedence.h"
#include "helpers.h"
using namespace goose;
using namespace goose::eir;
using namespace goose::parse;
namespace goose::builtins
{
void SetupCommaOp( Env& e )
{
using LocVarOfAnyType =
CustomPattern< LocalVar, LocalVar::PatternAny >;
using RefOfAnyType =
CustomPattern< Value, ReferenceType::PatternAny >;
BuildParseRule( e, ","_sid,
LeftAssInfixOp( "operator_comma"_sid, precedence::CommaOp,
// Overload: open tuple, open tuple
|
<
<
<
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include "builtins/builtins.h"
#include "precedence.h"
#include "helpers.h"
using namespace goose;
using namespace goose::eir;
using namespace goose::parse;
namespace goose::builtins
{
void SetupCommaOp( Env& e )
{
using RefOfAnyType =
CustomPattern< Value, ReferenceType::PatternAny >;
BuildParseRule( e, ","_sid,
LeftAssInfixOp( "operator_comma"_sid, precedence::CommaOp,
// Overload: open tuple, open tuple
|
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
74
75
76
77
78
|
// Overload: anything, anything
ForType< Value >(
[]( auto&& c, auto&& lhs, auto&& rhs ) -> Value
{
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
// By default, locvars return their content during type checking.
// Since we want to keep them as is in tuples, we need specific overloads that will
// get locvars as such.
ForType< LocVarOfAnyType >(
[]( auto&& c, auto&& lhs, auto&& rhs ) -> Value
{
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
ForTypes< CustomPattern< Value, TupleOpenPattern >, LocVarOfAnyType >(
[]( auto&& c, auto&& lhs, auto&& rhs ) -> Value
{
return AppendToTuple( lhs, rhs );
} ),
ForTypes< LocVarOfAnyType, CustomPattern< Value, TupleOpenPattern > >(
[]( auto&& c, auto&& lhs, auto&& rhs ) -> Value
{
return PrependToTuple( lhs, rhs );
} ),
// Likewise for references.
ForType< RefOfAnyType >(
[]( auto&& c, auto&& lhs, auto&& rhs ) -> Value
{
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
ForTypes< Value, RefOfAnyType >(
|
<
<
<
<
<
<
<
<
|
<
<
<
<
<
|
<
<
<
<
<
|
<
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Overload: anything, anything
ForType< Value >(
[]( auto&& c, auto&& lhs, auto&& rhs ) -> Value
{
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
// We want to be able to put references in tuples without them getting
// automatically dereferenced, so we have specific overloads that treat
// them explicitely.
ForType< RefOfAnyType >(
[]( auto&& c, auto&& lhs, auto&& rhs ) -> Value
{
return AppendToTuple( AppendToTuple( EmptyTuple(), lhs ), rhs );
} ),
ForTypes< Value, RefOfAnyType >(
|