Goose  Diff

Differences From Artifact [297bd1834e]:

  • File bs/builtins/types/func/invoke.cpp — part of check-in [bb17e9f3dd] at 2020-05-25 22:08:44 on branch trunk —
    • Added a "LowerConstantForRuntime" extension point, similar to LowerTypeForRunTime.
    • Added a way to represent Record constants.
    • Implemented LowerConstantForRunTime for tuples, which lowers them into a constant record.
    • Implemented codegen for constant records.
    • Implemented codegen for storing an aggregate constant.
    • Implemented a way (not exposed in the syntax for now) to create vararg function types, to be able to call vararg external functions such as printf.
    • Enabled the tuple runtime/compilation combined test which is now working.
    • Various bug fixes.
    (user: achavasse size: 4493)

To Artifact [e2dd0e554d]:

  • File bs/builtins/types/func/invoke.cpp — part of check-in [df0ad9a7f1] at 2020-06-15 19:16:15 on branch trunk — Moved some common code into a helper function to facilitate some future refactoring. (user: achavasse size: 4176)

11
12
13
14
15
16
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
11
12
13
14
15
16
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







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


-
+







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







            {
                optional< UnificationContext > bestUC;
                optional< Term > bestSol;
                bool ambiguous = false;
                auto sig = GetFuncSig( callee );

                auto callPat = VEC( c.domain(), args.val(), HOLE( "_"_sid ) );
                for( auto&& [s, uc] : FullUnify( sig, callPat, c ) )
                {

                    if( !bestSol || uc.score() > bestUC->score() )
                    {
                        bestUC = uc;
                auto us = FindBestUnification( sig, callPat, c );
                        bestSol = s;
                        ambiguous = false;
                        continue;
                    }


                if( holds_alternative< NoUnification >( us ) )
                {
                    if( uc.score() < bestUC->score() )
                        continue;

                    // TODO display details
                    DiagnosticsManager::GetInstance().emitErrorMessage( loc,
                        "function arguments mismatch." );
                    return PoisonValue();
                    ambiguous = true;
                }

                if( ambiguous )
                if( holds_alternative< AmbiguousUnification >( us ) )
                {
                    // TODO display details
                    DiagnosticsManager::GetInstance().emitErrorMessage( loc,
                        "ambiguous function call." );
                    return PoisonValue();
                }

                if( !bestSol )
                {
                auto&& [s,uc] = get< UniSol >( us );

                    // TODO display details
                    DiagnosticsManager::GetInstance().emitErrorMessage( loc,
                        "function arguments mismatch." );
                    return PoisonValue();
                }

                return invoke( c, loc, callee, *bestSol, *bestUC );
                return invoke( c, loc, callee, s, uc );
            }

            Value invoke( const Context& c, uint32_t loc, const Value& callee, const Term& unifiedCallPat, UnificationContext& uc ) const final
            {
                auto newCallee = prepareFunc( c, 0, callee, unifiedCallPat, uc );
                if( newCallee.isPoison() )
                    return PoisonValue();