Changeset a805100 for src


Ignore:
Timestamp:
Nov 4, 2022, 12:07:04 PM (23 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
44547b0
Parents:
7ed7b4a
Message:

Cleaning old box pass for easier translation. Refactor to remove unneeded parameters. In the future someone may have to put them back, but that flexibility is not being used now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r7ed7b4a ra805100  
    9797                        void passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes );
    9898                        /// passes extra type parameters into a polymorphic function application
    99                         void passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
     99                        /// Returns an iterator to the first argument after the added
     100                        /// arguments, which are added at the beginning.
     101                        std::list< Expression *>::iterator passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, const TyVarMap &exprTyVars );
    100102                        /// wraps a function application with a new temporary for the out-parameter return value
    101                         Expression *addRetParam( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, Type *retType );
     103                        /// The new out-parameter is the new first parameter.
     104                        Expression *addRetParam( ApplicationExpr *appExpr, Type *retType );
    102105                        /// wraps a function application returning a polymorphic type with a new temporary for the out-parameter return value
    103                         Expression *addDynRetParam( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, Type *polyType );
     106                        Expression *addDynRetParam( ApplicationExpr *appExpr, Type *polyType );
    104107                        /// Converts a function call into a call of the adapter with the
    105108                        /// original function as the first argument (all other arguments
    106109                        /// are pushed back). May adjust return value.
    107                         Expression *applyAdapter( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *function, const TyVarMap &exprTyVars );
     110                        Expression *applyAdapter( ApplicationExpr *appExpr, FunctionType *function );
    108111                        /// Modifies the `arg`, replacing it with a boxed expression
    109112                        /// that matches `formal` under the current TyVarMap.
     
    555558                }
    556559
    557                 void Pass1::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
     560                std::list< Expression *>::iterator Pass1::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, const TyVarMap &exprTyVars ) {
     561                        assert( env );
     562                        std::list< Expression *>::iterator arg = appExpr->args.begin();
    558563                        // pass size/align for type variables
    559564                        for ( std::pair<std::string, TypeDecl::Data> const & tyParam : exprTyVars ) {
    560565                                ResolvExpr::EqvClass eqvClass;
    561                                 assert( env );
    562566                                if ( tyParam.second.isComplete ) {
    563567                                        Type *concrete = env->lookup( tyParam.first );
     
    574578
    575579                        // add size/align for generic types to parameter list
    576                         if ( ! appExpr->get_function()->result ) return;
     580                        if ( ! appExpr->get_function()->result ) return arg;
    577581                        FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result() );
    578582                        assert( funcType );
     
    595599                                passArgTypeVars( appExpr, (*fnParm)->get_type(), argType, arg, exprTyVars, seenTypes );
    596600                        }
     601                        return arg;
    597602                }
    598603
     
    603608                }
    604609
    605                 Expression *Pass1::addRetParam( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, Type *retType ) {
     610                Expression *Pass1::addRetParam( ApplicationExpr *appExpr, Type *retType ) {
    606611                        // Create temporary to hold return value of polymorphic function and produce that temporary as a result
    607612                        // using a comma expression.
     
    623628                                paramExpr = new AddressExpr( paramExpr );
    624629                        } // if
    625                         arg = appExpr->args.insert( arg, paramExpr ); // add argument to function call
    626                         arg++;
     630                        // Add argument to function call.
     631                        appExpr->args.push_front( paramExpr );
    627632                        // Build a comma expression to call the function and emulate a normal return.
    628633                        CommaExpr *commaExpr = new CommaExpr( appExpr, retExpr );
     
    666671                }
    667672
    668                 Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, Type *dynType ) {
     673                Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, Type *dynType ) {
    669674                        Type *concrete = replaceWithConcrete( dynType, env );
    670675                        // add out-parameter for return value
    671                         return addRetParam( appExpr, arg, concrete );
    672                 }
    673 
    674                 Expression *Pass1::applyAdapter( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *function, const TyVarMap &tyVars ) {
     676                        return addRetParam( appExpr, concrete );
     677                }
     678
     679                Expression *Pass1::applyAdapter( ApplicationExpr *appExpr, FunctionType *function ) {
    675680                        Expression *ret = appExpr;
    676681//                      if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) {
    677                         if ( isDynRet( function, tyVars ) ) {
    678                                 ret = addRetParam( appExpr, arg, function->returnVals.front()->get_type() );
     682                        if ( isDynRet( function, scopeTyVars ) ) {
     683                                ret = addRetParam( appExpr, function->returnVals.front()->get_type() );
    679684                        } // if
    680                         std::string mangleName = mangleAdapterName( function, tyVars );
     685                        std::string mangleName = mangleAdapterName( function, scopeTyVars );
    681686                        std::string adapterName = makeAdapterName( mangleName );
    682687
     
    10971102
    10981103                        Expression *ret = appExpr;
    1099 
    1100                         std::list< Expression *>::iterator arg = appExpr->get_args().begin();
    11011104                        std::list< Expression *>::iterator paramBegin = appExpr->get_args().begin();
    11021105
     
    11191122                                // std::cerr << "dynRetType: " << dynRetType << std::endl;
    11201123                                Type *concRetType = appExpr->get_result()->isVoid() ? nullptr : appExpr->get_result();
    1121                                 ret = addDynRetParam( appExpr, arg, concRetType ); // xxx - used to use dynRetType instead of concRetType
     1124                                ret = addDynRetParam( appExpr, concRetType ); // xxx - used to use dynRetType instead of concRetType
    11221125                        } else if ( needsAdapter( function, scopeTyVars ) && ! needsAdapter( function, exprTyVars) ) { // xxx - exprTyVars is used above...?
    11231126                                // xxx - the ! needsAdapter check may be incorrect. It seems there is some situation where an adapter is applied where it shouldn't be, and this fixes it for some cases. More investigation is needed.
     
    11271130                                // std::cerr << *env << std::endl;
    11281131                                // change the application so it calls the adapter rather than the passed function
    1129                                 ret = applyAdapter( appExpr, arg, function, scopeTyVars );
     1132                                ret = applyAdapter( appExpr, function );
    11301133                        } // if
    1131                         arg = appExpr->get_args().begin();
    11321134
    11331135                        Type *concRetType = replaceWithConcrete( dynRetType, env );
    1134                         passTypeVars( appExpr, concRetType, arg, exprTyVars ); // xxx - used to use dynRetType instead of concRetType; this changed so that the correct type paramaters are passed for return types (it should be the concrete type's parameters, not the formal type's)
     1136                        std::list< Expression *>::iterator arg =
     1137                                passTypeVars( appExpr, concRetType, exprTyVars ); // xxx - used to use dynRetType instead of concRetType; this changed so that the correct type paramaters are passed for return types (it should be the concrete type's parameters, not the formal type's)
    11351138                        addInferredParams( appExpr, arg, function, exprTyVars );
    11361139
    1137                         arg = paramBegin;
    1138 
    1139                         boxParams( appExpr, arg, function, exprTyVars );
     1140                        // This needs to point at the original first argument.
     1141                        boxParams( appExpr, paramBegin, function, exprTyVars );
     1142
    11401143                        passAdapters( appExpr, function, exprTyVars );
    11411144
Note: See TracChangeset for help on using the changeset viewer.