Goose  Diff

Differences From Artifact [ab510f970f]:

  • File bs/builtins/types/template/build.cpp — part of check-in [10aff6cb27] at 2019-03-27 23:27:10 on branch trunk — Templates: implemented the rules for tfunctype texprs. (user: achavasse size: 3041)

To Artifact [a050f96efc]:

  • File bs/builtins/types/template/build.cpp — part of check-in [ee15f9081f] at 2019-03-28 21:00:54 on branch trunk — Higher order functions: plain lambdas can be passed to template function type parameters. (user: achavasse size: 3067)

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
100
101
102
103
104
105
106
            *sig,
            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
        );
    }
}







|
>





|
















|












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
100
101
102
103
104
105
106
107
            *sig,
            AppendToVectorTerm( c.identity(), TERM( id ) ),
            move( pToks ) ) );
    }

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

        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
        );
    }
}