Goose  Diff

Differences From Artifact [956c9ccd05]:

  • File bs/builtins/types/localvar/unify.cpp — part of check-in [652107629a] at 2020-02-20 22:42:24 on branch trunk —
    • Wrap function parameters into local variables, which will make it easier later on to distinguish temporaries from stack values when implementing references.
    • Register parameters for destruction, which was missing.
    • Added an invocation rule for local variables, so that they can be invoked if they contain an invokable object.
    (user: achavasse size: 2074)

To Artifact [337391a751]:

  • File bs/builtins/types/localvar/unify.cpp — part of check-in [4940c5c904] at 2020-02-29 15:07:01 on branch trunk — Implemented unification for references. (user: achavasse size: 2162)

17
18
19
20
21
22
23
24
25
26
27
28
29






30
31
32


33
34
35
36



37
38
39
40
41
42
43
44
45
46
47
48
49
50



51
52
53


54
55
56
57
58
59
60






61
62
17
18
19
20
21
22
23






24
25
26
27
28
29
30


31
32
33



34
35
36
37
38
39
40
41
42
43
44
45
46
47



48
49
50
51


52
53
54






55
56
57
58
59
60
61
62







-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+

-
-
-
+
+
+











-
-
-
+
+
+

-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+


            ParamPat( ANYTERM( _ ) ),

            ValueToIRExpr( ValuePattern(
                ANYTERM( _ ),
                localVarPattern,
                ANYTERM( _ ) ) ),

        []( const Term& lhs, const Term& rhs, UnificationContext& c ) -> UniGen
        {
            auto lvval = *ValueFromIRExpr( rhs );
            auto locvar = FromValue< LocalVar >( lvval );
            if( !locvar )
                co_return;
            []( const Term& lhs, const Term& rhs, UnificationContext& c ) -> UniGen
            {
                auto lvval = *ValueFromIRExpr( rhs );
                auto locvar = FromValue< LocalVar >( lvval );
                if( !locvar )
                    co_return;

            auto varcontent = ValueToIRExpr( BuildComputedValue( locvar->type(),
                GetVar( locvar->type(), locvar->index() ) ).setLocationId( lvval.locationId() ) );
                auto varcontent = ValueToIRExpr( BuildComputedValue( locvar->type(),
                    GetVar( locvar->type(), locvar->index() ) ).setLocationId( lvval.locationId() ) );

            // Unify the param with the var's content
            co_yield Unify( lhs, varcontent, c );
        } );
                // Unify the param with the var's content
                co_yield Unify( lhs, varcontent, c );
            } );

        // LocalVar unification against another LocalVar: unify their types.
        e.unificationRuleSet()->addSymRule(

            ParamPat( localVarPattern ),

            ValueToIRExpr( ValuePattern(
                ANYTERM( _ ),
                localVarPattern,
                ANYTERM( _ ) ) ),

        []( const Term& lhs, const Term& rhs, UnificationContext& uc ) -> UniGen
        {
            auto lvarType = *FromValue< LocalVarType >( *ValueFromIRExpr( ValuePatternFromIRExpr( lhs )->type() ) );
            []( const Term& lhs, const Term& rhs, UnificationContext& uc ) -> UniGen
            {
                auto lvarType = *FromValue< LocalVarType >( *ValueFromIRExpr( ValuePatternFromIRExpr( lhs )->type() ) );

            auto rhsVal = *ValuePatternFromIRExpr( rhs );
            auto rvarType = *FromValue< LocalVarType >( *ValueFromIRExpr( rhsVal.type() ) );
                auto rhsVal = *ValuePatternFromIRExpr( rhs );
                auto rvarType = *FromValue< LocalVarType >( *ValueFromIRExpr( rhsVal.type() ) );

            for( auto&& [s, uc] : Unify( lvarType.type(), rvarType.type(), uc ) )
            {
                co_yield { ValueToIRExpr( Value( ValueToIRExpr( ToValue( LocalVarType( s ) ) ),
                    rhsVal.val() ) ), uc };
            }
        } );
                for( auto&& [s, uc] : Unify( lvarType.type(), rvarType.type(), uc ) )
                {
                    co_yield { ValueToIRExpr( Value( ValueToIRExpr( ToValue( LocalVarType( s ) ) ),
                        rhsVal.val() ) ), uc };
                }
            } );
    }
}