Goose  Diff

Differences From Artifact [997ae9812a]:

  • File bs/builtins/types/drop.cpp — part of check-in [1ad61a2717] at 2021-11-11 20:05:58 on branch trunk — Refactored the code builder: it is now carried around as a Value, and accessed through a bunch of extension points, so we can have different builders (and even user defined ones) later to make classes etc. (user: zlodo size: 2085)

To Artifact [cfeaaa9d02]:

  • File bs/builtins/types/drop.cpp — part of check-in [c33b227735] at 2021-11-13 14:09:04 on branch trunk — The builder is now passed as the first param of the _DropValue extension point (user: zlodo size: 2131)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


16
17
18
19
20
21
22
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 )
        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
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 )
        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() );
            } );
    }
}