Changeset 64eae56 for src


Ignore:
Timestamp:
Dec 21, 2016, 5:15:27 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
0c286cf
Parents:
53e3b4a
Message:

match formal parameter type of actual function when specializing ttype parameter, flatten types when unifying ttype parameters

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Specialize.cc

    r53e3b4a r64eae56  
    194194        }
    195195
     196        /// restructures arg to match the structure of a single formal parameter. Assumes that atomic types are compatible (as the Resolver should have ensured this)
     197        template< typename OutIterator >
     198        void matchOneFormal( Expression * arg, unsigned & idx, Type * formal, OutIterator out ) {
     199                if ( TupleType * tupleType = dynamic_cast< TupleType * >( formal ) ) {
     200                        std::list< Expression * > exprs;
     201                        for ( Type * t : *tupleType ) {
     202                                matchOneFormal( arg, idx, t, back_inserter( exprs ) );
     203                        }
     204                        *out++ = new TupleExpr( exprs );
     205                } else {
     206                        *out++ = new TupleIndexExpr( arg->clone(), idx++ );
     207                }
     208        }
     209
     210        /// restructures the ttype argument to match the structure of the formal parameters of the actual function.
     211        // [begin, end) are the formal parameters.
     212        // args is the list of arguments currently given to the actual function, the last of which needs to be restructured.
    196213        template< typename Iterator >
    197214        void fixLastArg( std::list< Expression * > & args, Iterator begin, Iterator end ) {
     
    203220                unsigned idx = 0;
    204221                for ( ; begin != end; ++begin ) {
    205                         // DeclarationWithType * formal = *begin;
    206                         // Type * formalType = formal->get_type();
    207                         args.push_back( new TupleIndexExpr( last->clone(), idx++ ) );
     222                        DeclarationWithType * formal = *begin;
     223                        Type * formalType = formal->get_type();
     224                        matchOneFormal( last, idx, formalType, back_inserter( args ) );
    208225                }
    209226                delete last;
     
    238255
    239256                for ( DeclarationWithType* param : thunkFunc->get_functionType()->get_parameters() ) {
     257                        // walk the parameters to the actual function alongside the parameters to the thunk to find the location where the ttype parameter begins to satisfy parameters in the actual function.
     258                        assert( begin != end );
    240259                        ++begin;
    241                         assert( begin != end );
    242260
    243261                        // std::cerr << "thunk param: " << param << std::endl;
  • src/ResolvExpr/Unify.cc

    r53e3b4a r64eae56  
    491491                std::list< Type * > types;
    492492                for ( ; begin != end; ++begin ) {
    493                         // might need to break apart these types too?
    494                         // yes, looks like we should flatten begin and push back each types individually
    495                         types.push_back( (*begin)->get_type()->clone() );
     493                        // it's guaranteed that a ttype variable will be bound to a flat tuple, so ensure that this results in a flat tuple
     494                        flatten( (*begin)->get_type(), back_inserter( types ) );
    496495                }
    497496                return new TupleType( Type::Qualifiers(), types );
  • src/tests/tupleVariadic.c

    r53e3b4a r64eae56  
    5757}
    5858
    59 void ?{}(array * a, int a0, int a1, int a2, int a3) {
     59// test use of a tuple argument
     60[void] ?{}(array * a, [int, int, int, int] args) {
     61        int a0, a1, a2, a3;
     62        [a0, a1, a2, a3] = args;
    6063        a->size = 4;
    61         a->data = (int*)malloc(sizeof(int)*a->size);
     64        a->data = malloc(sizeof(int)*a->size);
    6265        a->data[0] = a0;
    6366        a->data[1] = a1;
Note: See TracChangeset for help on using the changeset viewer.