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 "parse/parse.h"
using namespace goose::parse;
using namespace goose::cir;
namespace goose::builtins
{
void SetupDropValue( Env& e )
{
// Default implementation of DropValue().
// Constant values are discarded, and the cir of computed values
// is appended to the current BB of the current parser.
RegisterBuiltinFunc< Intrinsic< void ( Value ) > >( e, e.extDropValue(),
[]( const Context& c, const Value& v )
{
if( v.isConstant() )
return;
// Reference use a load instruction to store their address,
// so don't emit them. There is never any point in emitting
// a load whose result isn't used anyway.
|
|
|
|
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 "parse/parse.h"
using namespace goose::parse;
using namespace goose::cir;
namespace goose::builtins
{
void SetupDropValue( Env& e )
{
// Default implementation of DropValue().
// Constant values are discarded, and the cir of computed values
// is appended to the current BB of the current parser.
RegisterBuiltinFunc< Intrinsic< void ( Value, Value ) > >( e, e.extDropValue(),
[]( const Context& c, const Value& b, const Value& v )
{
if( v.isConstant() )
return;
// Reference use a load instruction to store their address,
// so don't emit them. There is never any point in emitting
// a load whose result isn't used anyway.
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
using AnyDeclType = CustomPattern< Decl, Decl::Pattern >;
// DropValue for Decls: declare a local variable with default initialization.
// TODO: if the invocation to InitializeValue fails, we should have a way to
// replace the generic "function arguments mismatch" error message with something
// more specific such as "can't default-initialize a variable of type XXX"
RegisterBuiltinFunc< Intrinsic< void ( AnyDeclType ) > >( e, e.extDropValue(),
[]( const Context& c, const Value& v )
{
if( !GetCFG( c ) )
{
DiagnosticsManager::GetInstance().emitSyntaxErrorMessage( 0, "variable declarations are not allowed here." );
return PoisonValue();
}
auto decl = *FromValue< Decl >( v );
return DeclareLocalVar( c, decl.type(), decl.name(), nullopt, v.locationId() );
} );
}
}
|
|
|
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
using AnyDeclType = CustomPattern< Decl, Decl::Pattern >;
// DropValue for Decls: declare a local variable with default initialization.
// TODO: if the invocation to InitializeValue fails, we should have a way to
// replace the generic "function arguments mismatch" error message with something
// more specific such as "can't default-initialize a variable of type XXX"
RegisterBuiltinFunc< Intrinsic< void ( Value, AnyDeclType ) > >( e, e.extDropValue(),
[]( const Context& c, const Value& b, const Value& v )
{
if( !GetCFG( c ) )
{
DiagnosticsManager::GetInstance().emitSyntaxErrorMessage( 0, "variable declarations are not allowed here." );
return PoisonValue();
}
auto decl = *FromValue< Decl >( v );
return DeclareLocalVar( c, decl.type(), decl.name(), nullopt, v.locationId() );
} );
}
}
|