Goose  Diff

Differences From Artifact [3e730f7617]:

  • File bs/builtins/types/template/build.cpp — part of check-in [e87aad0ef1] at 2019-03-03 15:00:39 on branch trunk — Added return types to function signatures, so that any TExpr constraint they may contain are taken into account during unification. (user: achavasse size: 1832)

To Artifact [3ffc6459f1]:

  • File bs/builtins/types/template/build.cpp — part of check-in [65cbac9aa3] at 2019-03-19 20:17:30 on branch trunk — Higher-order functions: implemented BuildArgPatternFromFuncType() and BuildArgPatternFromTFuncType(). (user: achavasse size: 2900)

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
21
22
23
24
25
26
27

28
29
30
31
32
33
34







-







        auto funcType = BuildTFuncType( returnType, params );

        // Build the signature
        immer::vector< Term > v;
        auto vt = v.transient();

        bool success = true;

        ForEachInTuple( params, [&]( auto&& param )
        {
            auto teSig = BuildTemplateSignature( c, ValueToIRExpr( param ) );
            if( !teSig )
            {
                cout << "Invalid template parameter.\n";
                success = false;
55
56
57
58
59
60
61
62







































54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99







-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
            TVEC(
                TERM( make_shared< Vector >( vt.persistent(), false ) ),
                *rtSig
            ),
            AppendToVectorTerm( c.identity(), TERM( id ) ),
            move( pToks ) ) );
    }
}

    optional< Term > BuildArgPatternFromTFuncType( const Context& c, const Value& tfuncType )
    {
        const auto& ftype = *FromValue< TFuncType >( tfuncType );

        immer::vector< Term > apv;
        auto apvt = apv.transient();

        bool success = true;
        ForEachInVectorTerm( ftype.params(), [&]( auto&& param )
        {
            auto teArgPat = BuildTemplateArgPattern( c, param );
            if( !teArgPat )
            {
                cout << "Invalid template parameter.\n";
                success = false;
                return false;
            }

            apvt.push_back( move( *teArgPat ) );
            return true;
        } );

        if( !success )
            return nullopt;

        auto rtArgPat = BuildTemplateArgPattern( c, ftype.returnType() );
        if( !rtArgPat )
        {
            cout << "Invalid template return type or texpr.\n";
            return nullopt;
        }

        return TVEC(
            TERM( make_shared< Vector >( apvt.persistent(), false ) ),
            *rtArgPat
        );
    }
}