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
|
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
|
-
+
-
+
|
)
);
assert( result );
auto&& [arg, rhs] = *result;
auto val = *EIRToValue( arg );
ReferenceType rt( val.type(), TempAccessSpecifer() );
ReferenceType rt( val.type(), TempAccessSpecifier() );
auto rhsVal = *EIRToValue( rhs );
auto cfg = GetCFG( tcc.context() );
if( !cfg )
return nullopt;
// TODO create an ext point for this
auto loc = rhsVal.locationId();
auto tempIndex = util::GenerateNewUID();
return ValueToEIR( BuildComputedValue( ValueToEIR( ToValue( rt ) ), rhsVal,
TempAddr( tempIndex, loc ) ).setLocationId( loc ) );
DataPathOf( tempIndex, loc ) ).setLocationId( loc ) );
} );
// Override the weight because we don't want
// this solution to count more than directly using
// the value without wrapping it into a tempref
SetWeight( wrapped, GetWeight( rhs ) - 1 );
co_yield { move( wrapped ), tcc };
|
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
-
+
-
+
-
+
|
auto refTypePattern = ValueToEIR(
Value( GetValueType< ReferenceType >(), TVEC( TSID( reference ), ANYTERM( _ ), ANYTERM( _ ) ) ) );
auto refRefTypePattern = ValueToEIR(
Value( GetValueType< ReferenceType >(), TVEC( TSID( reference ), ANYTERM( _ ), refTypePattern ) ) );
auto refTypePatternConstant = ValueToEIR(
Value( GetValueType< ReferenceType >(), TVEC( TSID( reference ), ConstAccessSpecifer(), ANYTERM( _ ) ) ) );
Value( GetValueType< ReferenceType >(), TVEC( TSID( reference ), ConstAccessSpecifier(), ANYTERM( _ ) ) ) );
auto refTypePatternMutable = ValueToEIR(
Value( GetValueType< ReferenceType >(), TVEC( TSID( reference ), MutAccessSpecifer(), ANYTERM( _ ) ) ) );
Value( GetValueType< ReferenceType >(), TVEC( TSID( reference ), MutAccessSpecifier(), ANYTERM( _ ) ) ) );
auto refTypePatternTemporary = ValueToEIR(
Value( GetValueType< ReferenceType >(), TVEC( TSID( reference ), TempAccessSpecifer(), ANYTERM( _ ) ) ) );
Value( GetValueType< ReferenceType >(), TVEC( TSID( reference ), TempAccessSpecifier(), ANYTERM( _ ) ) ) );
auto localVarPattern = GetValueType< LocalVar >( ANYTERM( _ ) );
// Reference type checking rule.
e.typeCheckingRuleSet()->addTypeCheckingRule(
ParamPat( refTypePattern ),
|
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
|
}
}
}
);
// mut -> const reference type checking rule.
e.typeCheckingRuleSet()->addTypeCheckingRule(
ConstAccessSpecifer(),
MutAccessSpecifer(),
ConstAccessSpecifier(),
MutAccessSpecifier(),
[]( const Term& lhs, const Term& rhs, const TypeCheckingContext& tcc ) -> TCGen
{
co_yield { lhs, tcc };
}
);
// mut -> const reference unification rule.
e.typeCheckingRuleSet()->addUnificationRule(
ConstAccessSpecifer(),
MutAccessSpecifer(),
ConstAccessSpecifier(),
MutAccessSpecifier(),
[]( const Term& lhs, const Term& rhs, const TypeCheckingContext& tcc ) -> TCGen
{
co_yield { lhs, tcc };
}
);
// temp -> const reference type checking rule.
e.typeCheckingRuleSet()->addTypeCheckingRule(
ConstAccessSpecifer(),
TempAccessSpecifer(),
ConstAccessSpecifier(),
TempAccessSpecifier(),
[]( const Term& lhs, const Term& rhs, const TypeCheckingContext& tcc ) -> TCGen
{
co_yield { lhs, tcc };
}
);
// temp -> const reference unification rule.
e.typeCheckingRuleSet()->addUnificationRule(
ConstAccessSpecifer(),
TempAccessSpecifer(),
ConstAccessSpecifier(),
TempAccessSpecifier(),
[]( const Term& lhs, const Term& rhs, const TypeCheckingContext& tcc ) -> TCGen
{
co_yield { lhs, tcc };
}
);
|