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 goose;
using namespace goose::ir;
namespace goose::builtins
{
void SetupRuntimeTypesUnification( Env& e )
{
auto rtIntTypePattern = Value( TypeType(), VEC( TSID( rt_type ),
ANYTERM( _ ),
TSID( integer ), VEC( ANYTERM( _ ), ANYTERM( _ ) ) ) );
// ct_int type against a IntegerType type:
// return the IntegerType type. We don't care if the
// ct_int fits at this point, this will be dealt with by
// the ct_int value unification rule below.
e.unificationRuleSet()->addSymRule(
ValueToIRExpr( rtIntTypePattern ),
|
>
|
<
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include "builtins/builtins.h"
#include "builtins/helpers.h"
using namespace goose;
using namespace goose::ir;
namespace goose::builtins
{
void SetupRuntimeTypesUnification( Env& e )
{
auto rtIntTypePattern = Value( TypeType(), MkStdType( TSID( integer ),
VEC( ANYTERM( _ ), ANYTERM( _ ) ) ) );
// ct_int type against a IntegerType type:
// return the IntegerType type. We don't care if the
// ct_int fits at this point, this will be dealt with by
// the ct_int value unification rule below.
e.unificationRuleSet()->addSymRule(
ValueToIRExpr( rtIntTypePattern ),
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
}
auto* llvmType = static_cast< llvm::IntegerType* >( GetLLVMType( *rttypeVal ) );
co_yield { ValueToIRExpr(
Value( lhsVal->type(), move( valToLoad ) ) ), c };
} );
auto rtInt8TypePattern = Value( TypeType(), VEC( TSID( rt_type ),
ANYTERM( _ ),
TSID( integer ), VEC( TERM( 8U ), ANYTERM( _ ) ) ) );
auto rtInt8PtrTypePattern = Value( TypeType(), VEC( TSID( rt_type ),
ANYTERM( _ ),
TSID( pointer ), ValueToIRExpr( rtInt8TypePattern ) ) );
// ct_string type against a char*:
// return the char* type.
e.unificationRuleSet()->addSymRule(
ValueToIRExpr( rtInt8PtrTypePattern ),
GetValueType< string >(),
[]( const Term& lhs, const Term& rhs, UnificationContext& c ) -> UniGen
|
|
<
|
|
<
|
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
}
auto* llvmType = static_cast< llvm::IntegerType* >( GetLLVMType( *rttypeVal ) );
co_yield { ValueToIRExpr(
Value( lhsVal->type(), move( valToLoad ) ) ), c };
} );
auto rtInt8TypePattern = Value( TypeType(), MkStdType( TSID( integer ),
VEC( TERM( 8U ), ANYTERM( _ ) ) ) );
auto rtInt8PtrTypePattern = Value( TypeType(), MkStdType( TSID( pointer ),
ValueToIRExpr( rtInt8TypePattern ) ) );
// ct_string type against a char*:
// return the char* type.
e.unificationRuleSet()->addSymRule(
ValueToIRExpr( rtInt8PtrTypePattern ),
GetValueType< string >(),
[]( const Term& lhs, const Term& rhs, UnificationContext& c ) -> UniGen
|
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
auto str = *FromValue< string >( *ValueFromIRExpr( lhs ) );
auto rhsVal = *ValuePatternFromIRExpr( rhs );
co_yield { ValueToIRExpr(
BuildComputedValue( rhsVal.type(), llr::LoadConstStr( str ) ) ), c };
} );
auto ptrTypePattern = Value( TypeType(), VEC( TSID( rt_type ),
ANYTERM( _ ),
TSID( pointer ), ANYTERM( _ ) ) );
// nullptr constant unification against a pointer of any type;
// Yield a value of the given pointer type, with a 0 integer as its content.
// This'll be recognized by codegen to emit a null pointer value of the right type.
e.unificationRuleSet()->addSymRule(
ParamPat( ValueToIRExpr( ptrTypePattern ) ),
|
|
|
<
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
auto str = *FromValue< string >( *ValueFromIRExpr( lhs ) );
auto rhsVal = *ValuePatternFromIRExpr( rhs );
co_yield { ValueToIRExpr(
BuildComputedValue( rhsVal.type(), llr::LoadConstStr( str ) ) ), c };
} );
auto ptrTypePattern = Value( TypeType(), MkStdType( TSID( pointer ),
ANYTERM( _ ) ) );
// nullptr constant unification against a pointer of any type;
// Yield a value of the given pointer type, with a 0 integer as its content.
// This'll be recognized by codegen to emit a null pointer value of the right type.
e.unificationRuleSet()->addSymRule(
ParamPat( ValueToIRExpr( ptrTypePattern ) ),
|