Changeset a805100
- Timestamp:
- Nov 4, 2022, 12:07:04 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 44547b0
- Parents:
- 7ed7b4a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r7ed7b4a ra805100 97 97 void passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes ); 98 98 /// 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 ); 100 102 /// 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 ); 102 105 /// 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 ); 104 107 /// Converts a function call into a call of the adapter with the 105 108 /// original function as the first argument (all other arguments 106 109 /// 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 ); 108 111 /// Modifies the `arg`, replacing it with a boxed expression 109 112 /// that matches `formal` under the current TyVarMap. … … 555 558 } 556 559 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(); 558 563 // pass size/align for type variables 559 564 for ( std::pair<std::string, TypeDecl::Data> const & tyParam : exprTyVars ) { 560 565 ResolvExpr::EqvClass eqvClass; 561 assert( env );562 566 if ( tyParam.second.isComplete ) { 563 567 Type *concrete = env->lookup( tyParam.first ); … … 574 578 575 579 // add size/align for generic types to parameter list 576 if ( ! appExpr->get_function()->result ) return ;580 if ( ! appExpr->get_function()->result ) return arg; 577 581 FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result() ); 578 582 assert( funcType ); … … 595 599 passArgTypeVars( appExpr, (*fnParm)->get_type(), argType, arg, exprTyVars, seenTypes ); 596 600 } 601 return arg; 597 602 } 598 603 … … 603 608 } 604 609 605 Expression *Pass1::addRetParam( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg,Type *retType ) {610 Expression *Pass1::addRetParam( ApplicationExpr *appExpr, Type *retType ) { 606 611 // Create temporary to hold return value of polymorphic function and produce that temporary as a result 607 612 // using a comma expression. … … 623 628 paramExpr = new AddressExpr( paramExpr ); 624 629 } // if 625 arg = appExpr->args.insert( arg, paramExpr ); // add argument to function call626 a rg++;630 // Add argument to function call. 631 appExpr->args.push_front( paramExpr ); 627 632 // Build a comma expression to call the function and emulate a normal return. 628 633 CommaExpr *commaExpr = new CommaExpr( appExpr, retExpr ); … … 666 671 } 667 672 668 Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg,Type *dynType ) {673 Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, Type *dynType ) { 669 674 Type *concrete = replaceWithConcrete( dynType, env ); 670 675 // 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 ) { 675 680 Expression *ret = appExpr; 676 681 // 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() ); 679 684 } // if 680 std::string mangleName = mangleAdapterName( function, tyVars );685 std::string mangleName = mangleAdapterName( function, scopeTyVars ); 681 686 std::string adapterName = makeAdapterName( mangleName ); 682 687 … … 1097 1102 1098 1103 Expression *ret = appExpr; 1099 1100 std::list< Expression *>::iterator arg = appExpr->get_args().begin();1101 1104 std::list< Expression *>::iterator paramBegin = appExpr->get_args().begin(); 1102 1105 … … 1119 1122 // std::cerr << "dynRetType: " << dynRetType << std::endl; 1120 1123 Type *concRetType = appExpr->get_result()->isVoid() ? nullptr : appExpr->get_result(); 1121 ret = addDynRetParam( appExpr, arg,concRetType ); // xxx - used to use dynRetType instead of concRetType1124 ret = addDynRetParam( appExpr, concRetType ); // xxx - used to use dynRetType instead of concRetType 1122 1125 } else if ( needsAdapter( function, scopeTyVars ) && ! needsAdapter( function, exprTyVars) ) { // xxx - exprTyVars is used above...? 1123 1126 // 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. … … 1127 1130 // std::cerr << *env << std::endl; 1128 1131 // 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 ); 1130 1133 } // if 1131 arg = appExpr->get_args().begin();1132 1134 1133 1135 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) 1135 1138 addInferredParams( appExpr, arg, function, exprTyVars ); 1136 1139 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 1140 1143 passAdapters( appExpr, function, exprTyVars ); 1141 1144
Note: See TracChangeset
for help on using the changeset viewer.