Changeset 435 in dev
- Timestamp:
- Mar 15, 2008, 1:20:13 PM (17 years ago)
- Location:
- trunk/abdev
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/CParameter.cpp
r331 r435 65 65 //変数ではないとき 66 66 Type calcType; 67 NumOpe( Parms[i2], dummyType, calcType ); 67 BOOL bUseHeap; 68 NumOpe( Parms[i2], dummyType, calcType, &bUseHeap ); 68 69 //↑ここでスタックに積む 69 70 … … 85 86 i2); 86 87 87 if( result ){88 if( result && bUseHeap ){ 88 89 useTempParameters[i2] = true; 89 90 useTempObject = true; -
trunk/abdev/BasicCompiler32/Compile_Calc.cpp
r415 r435 646 646 647 647 SetVariableFromEax(varType,calcType.GetBasicType(),&VarRelativeVar); 648 } 648 649 650 // コード生成過程で発生した構造体の一時メモリを破棄する 651 compiler.codeGenerator.op_FreeTempStructure(); 652 } -
trunk/abdev/BasicCompiler32/Compile_CallProc.cpp
r420 r435 289 289 if(lstrcmpi(ObjectName,"Super")==0) goto InClassMember; 290 290 else{ 291 bool isLiteral ;291 bool isLiteral, isNeedHeapFreeStructure = false; 292 292 Type baseType( DEF_OBJECT, *pUserProc->GetParentClassPtr() ) , resultType; 293 if( !TermOpe( ObjectName, baseType, resultType, isLiteral, NULL, NULL, false, !pMethod->IsConst() ) )293 if( !TermOpe( ObjectName, baseType, resultType, isLiteral, isNeedHeapFreeStructure, NULL, false, !pMethod->IsConst() ) ) 294 294 { 295 295 return false; 296 } 297 if( !resultType.IsObject() ) 298 { 299 SetError(); 296 300 } 297 301 -
trunk/abdev/BasicCompiler32/Compile_Statement.cpp
r424 r435 91 91 92 92 Type resultType; 93 bool isLiteral; 94 BOOL bUseHeap; 95 bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, NULL, true ); 93 bool isLiteral, isNeedHeapFreeStructure = false; 94 bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, isNeedHeapFreeStructure, NULL, true ); 96 95 if( result ){ 97 96 -
trunk/abdev/BasicCompiler32/MakePeHdr.cpp
r422 r435 33 33 *pSub_System_GC_malloc_ForObjectPtr, 34 34 *pSub_System_GC_free_for_SweepingDelete, 35 *pSub_System_AddNeedFreeTempStructure, 36 *pSub_System_FreeTempStructure, 35 37 *pSubStaticMethod_System_TypeBase_InitializeUserTypes, 36 38 *pSubStaticMethod_System_TypeBase_InitializeUserTypesForBaseType, … … 273 275 if( pSub_System_GC_free_for_SweepingDelete = GetSubHash( "_System_GC_free_for_SweepingDelete",1 ) ) 274 276 pSub_System_GC_free_for_SweepingDelete->Using(); 277 278 if( pSub_System_AddNeedFreeTempStructure = GetSubHash( "_System_AddNeedFreeTempStructure",1 ) ) 279 { 280 pSub_System_AddNeedFreeTempStructure->Using(); 281 } 282 if( pSub_System_FreeTempStructure = GetSubHash( "_System_FreeTempStructure",1 ) ) 283 { 284 pSub_System_FreeTempStructure->Using(); 285 } 275 286 276 287 if( pSubStaticMethod_System_TypeBase_InitializeUserTypes = GetSubHash( "ActiveBasic.Core._System_TypeBase.InitializeUserTypes",1 ) ){ -
trunk/abdev/BasicCompiler32/NumOpe.cpp
r429 r435 140 140 return true; 141 141 } 142 bool TermMemberOpe( const Type &leftType, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool &isVariable, RELATIVE_VAR &relativeVar )142 bool TermMemberOpe( const Type &leftType, bool &isNeedHeapFreeStructure, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool &isVariable, RELATIVE_VAR &relativeVar ) 143 143 { 144 144 const CClass &objClass = leftType.GetClass(); … … 222 222 // メンバが見つかったとき 223 223 224 if( isNeedHeapFreeStructure ) 225 { 226 if( !leftType.IsStruct() ) 227 { 228 SetError(); 229 } 230 231 // 親となる構造体が一時メモリに存在していた場合、後ほど解放する必要がある 232 compiler.codeGenerator.op_AddNeedFreeTempStructure( useReg ); 233 isNeedHeapFreeStructure = false; 234 } 235 224 236 //オブジェクトポインタをecxにコピー 225 237 compiler.codeGenerator.op_mov_RR( REG_ECX, useReg ); … … 271 283 bool dummyIsVariable; 272 284 RELATIVE_VAR dummyRelativeVar; 273 TermMemberOpe( leftType, baseType, resultType, termFull, termLeft, methodName, dummyIsVariable, dummyRelativeVar );285 TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, methodName, dummyIsVariable, dummyRelativeVar ); 274 286 275 287 // 戻り値のオブジェクトインスタンスのインデクサを呼び出す … … 278 290 sprintf( temp2, "%s.%s", termLeft, methodName ); 279 291 Type classType = resultType; 280 return TermMemberOpe( classType, baseType, resultType, termFull, temp2, temporary, isVariable, relativeVar );292 return TermMemberOpe( classType, isNeedHeapFreeStructure, baseType, resultType, termFull, temp2, temporary, isVariable, relativeVar ); 281 293 } 282 294 … … 336 348 return false; 337 349 } 338 bool _TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly, bool &isVariable, RELATIVE_VAR &relativeVar, bool isWriteAccess )350 bool _TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool &isVariable, RELATIVE_VAR &relativeVar, bool isWriteAccess ) 339 351 { 340 352 char parameter[VN_SIZE]; … … 377 389 } 378 390 379 if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, &isClassName ) ){391 if( !TermOpe( termLeft, baseType, leftType, isLiteral, isNeedHeapFreeStructure, &isClassName ) ){ 380 392 goto globalArea; 381 393 } … … 395 407 } 396 408 397 return TermMemberOpe( leftType, baseType, resultType, termFull, termLeft, member, isVariable, relativeVar );409 return TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, member, isVariable, relativeVar ); 398 410 } 399 411 globalArea: … … 492 504 493 505 494 if(resultType.IsStruct()){ 506 if(resultType.IsStruct()) 507 { 495 508 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 496 509 //※後にfreeする必要あり 497 510 // TODO: 解放はGCに任せる 498 *pbUseHeap = 1;511 isNeedHeapFreeStructure = true; 499 512 } 500 513 … … 603 616 604 617 605 if(resultType.IsStruct()){ 618 if(resultType.IsStruct()) 619 { 606 620 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 607 621 //※後にfreeする必要あり 608 622 // TODO: 解放はGCに任せる 609 *pbUseHeap = 1;623 isNeedHeapFreeStructure = true; 610 624 } 611 625 … … 623 637 } 624 638 625 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly, bool isWriteAccess )639 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool isWriteAccess ) 626 640 { 627 641 RELATIVE_VAR relativeVar; 628 642 bool isVariable = false; 629 bool result = _TermOpe( term, baseType, resultType, isLiteral, pbUseHeap, pIsClassName, isProcedureCallOnly, isVariable, relativeVar, isWriteAccess );643 bool result = _TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructure, pIsClassName, isProcedureCallOnly, isVariable, relativeVar, isWriteAccess ); 630 644 631 645 if( isVariable ) … … 641 655 bool TermOpeOnlyVariable( const char *term, Type &resultType, RELATIVE_VAR &relativeVar, bool isWriteAccess ) 642 656 { 643 bool isLiteral, isVariable = false ;644 bool result = _TermOpe( term, Type(), resultType, isLiteral, NULL, NULL, false, isVariable, relativeVar, isWriteAccess );657 bool isLiteral, isVariable = false, isNeedHeapFreeStructure = false; 658 bool result = _TermOpe( term, Type(), resultType, isLiteral, isNeedHeapFreeStructure, NULL, false, isVariable, relativeVar, isWriteAccess ); 645 659 646 660 if( !isVariable ) … … 823 837 bool isNothing_stack[255]; 824 838 LONG_PTR index_stack[255]; 825 BOOL bUseHeap[255];839 bool isNeedHeapFreeStructureStack[255]; 826 840 _int64 i64data; 827 841 for(i=0,sp=0;i<pnum;i++){ … … 845 859 else{ 846 860 //オーバーロードされたオペレータを呼び出す 847 i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack, bUseHeap,sp);861 i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,isNeedHeapFreeStructureStack,sp); 848 862 if(i2==0){ 849 863 if(idCalc==CALC_EQUAL) lstrcpy(temp2,"=="); … … 867 881 index_stack[sp]=-1; 868 882 isNothing_stack[sp] = false; 869 bUseHeap[sp]=0;883 isNeedHeapFreeStructureStack[sp] = false; 870 884 871 885 char *term; … … 954 968 955 969 bool isLiteral; 956 if( TermOpe( term, baseType, resultType, isLiteral, &bUseHeap[sp] ) ){970 if( TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructureStack[sp] ) ){ 957 971 if(resultType.IsNull()){ 958 972 //戻り値が存在しないとき … … 1260 1274 } 1261 1275 1262 if(pbUseHeap) *pbUseHeap =bUseHeap[0];1276 if(pbUseHeap) *pbUseHeap = isNeedHeapFreeStructureStack[0]; 1263 1277 1264 1278 resultType.SetType( type_stack[0], index_stack[0] ); -
trunk/abdev/BasicCompiler32/Opcode.h
r424 r435 65 65 Type &resultType, 66 66 bool &isLiteral, 67 BOOL *pbUseHeap,67 bool &isNeedHeapFreeStructure, 68 68 bool *pIsClassName = NULL, 69 69 bool isProcedureCallOnly = false, … … 222 222 //OperatorProc.cpp 223 223 void FreeTempObject(int reg,const CClass *pobj_c); 224 int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack, LONG_PTR *index_stack, BOOL *bUseHeap,int &sp);224 int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack, LONG_PTR *index_stack,bool isNeedHeapFreeStructureStack[],int &sp); 225 225 void CallCastOperatorProc(Type &calcType,BOOL bCalcUseHeap,const Type &toType); 226 226 void CallIndexerGetterProc( const Type &classType, const char *ObjectName, char *Parameter,Type &resultType, DWORD dwProcFlags = 0 ); -
trunk/abdev/BasicCompiler32/OperatorProc.cpp
r424 r435 26 26 } 27 27 28 int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack, LONG_PTR *index_stack, BOOL *bUseHeap,int &sp)28 int CallOperatorProc(int idCalc, const Type &baseType, int *type_stack, LONG_PTR *index_stack,bool isNeedHeapFreeStructureStack[],int &sp) 29 29 { 30 30 Type leftType( type_stack[sp-2], index_stack[sp-2] ); … … 95 95 if( pUserProc->RealParams()[1]->IsStruct() &&pUserProc->RealParams()[1]->IsRef() == false ){ 96 96 //一時オブジェクトはメソッド内で破棄される 97 bUseHeap[sp-1]=0;97 isNeedHeapFreeStructureStack[sp-1] = false; 98 98 } 99 99 } … … 140 140 141 141 //ヒープ解放用に退避 142 if( bUseHeap[sp-1]){142 if(isNeedHeapFreeStructureStack[sp-1]){ 143 143 //mov esi,eax 144 144 compiler.codeGenerator.op_mov_RR(REG_ESI,REG_EAX); 145 145 } 146 if( bUseHeap[sp-2]){146 if(isNeedHeapFreeStructureStack[sp-2]){ 147 147 //mov edi,ecx 148 148 compiler.codeGenerator.op_mov_RR(REG_EDI,REG_ECX); … … 198 198 } 199 199 200 if( bUseHeap[sp-1]){200 if(isNeedHeapFreeStructureStack[sp-1]){ 201 201 FreeTempObject(REG_ESI,(CClass *)index_stack[sp-1]); 202 202 } 203 if( bUseHeap[sp-2]){203 if(isNeedHeapFreeStructureStack[sp-2]){ 204 204 FreeTempObject(REG_EDI,(CClass *)index_stack[sp-2]); 205 205 } … … 209 209 index_stack[sp-1]=pUserProc->ReturnType().GetIndex(); 210 210 211 if( pUserProc->ReturnType().IsStruct() ){ 211 if( pUserProc->ReturnType().IsStruct() ) 212 { 212 213 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 213 214 //※後にfreeする必要あり 214 bUseHeap[sp-1]=1; 215 } 216 else bUseHeap[sp-1]=0; 215 isNeedHeapFreeStructureStack[sp-1] = true; 216 } 217 else 218 { 219 isNeedHeapFreeStructureStack[sp-1] = false; 220 } 217 221 218 222 return 1; … … 222 226 int type_stack[10]; 223 227 LONG_PTR index_stack[10]; 224 BOOLarray_bUseHeap[10];228 bool array_bUseHeap[10]; 225 229 int sp=2; 226 230 -
trunk/abdev/BasicCompiler_Common/Compile.cpp
r424 r435 457 457 case COM_LET: 458 458 OpcodeCalc(Command+2); 459 459 460 break; 460 461 default: 461 462 OpcodeOthers(Command); 463 464 // コード生成過程で発生した構造体の一時メモリを破棄する 465 compiler.codeGenerator.op_FreeTempStructure(); 466 462 467 break; 463 468 } -
trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h
r370 r435 198 198 std::vector<long> continueCodePositions; 199 199 200 // コンパイル中のステップにおいて、構造体の一時オブジェクトの解放が必要かどうか 201 bool isNeedFreeTempStructureInCurrentStep; 202 200 203 public: 201 204 … … 215 218 CodeGenerator() 216 219 : pNativeCode( 0 ) 220 , isNeedFreeTempStructureInCurrentStep( false ) 217 221 { 218 222 } … … 294 298 void op_jmp_exitsub(); 295 299 void op_jmp_goto_schedule( const std::string &name, int lineNum, int sourceCodePos ); 300 void op_AddNeedFreeTempStructure( int reg ); 301 void op_FreeTempStructure(); 296 302 297 303 -
trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp
r357 r435 304 304 pNativeCode->Put( (long)0 ); 305 305 } 306 307 void CodeGenerator::op_AddNeedFreeTempStructure( int reg ) 308 { 309 #ifdef _AMD64_ 310 ////////////////////////////////////////////////////// 311 ///// レジスタ資源のバックアップ 312 { BACKUP_REGISTER_RESOURCE 313 ////////////////////////////////////////////////////// 314 315 //mov rcx,reg 316 compiler.codeGenerator.op_mov_RR( REG_RCX, reg ); 317 318 //call _System_AddNeedFreeTempStructure 319 extern const UserProc *pSub_System_AddNeedFreeTempStructure; 320 compiler.codeGenerator.op_call( pSub_System_AddNeedFreeTempStructure ); 321 322 ///////////////////////////////////////////// 323 ////// レジスタ資源を復元 324 RESTORE_REGISTER_RESOURCE 325 }//////////////////////////////////////////// 326 #else 327 328 //push useReg(引き続き利用するため、退避しておく) 329 compiler.codeGenerator.op_push( reg ); 330 331 //push useReg 332 compiler.codeGenerator.op_push( reg ); 333 334 //call _System_AddNeedFreeTempStructure 335 extern const UserProc *pSub_System_AddNeedFreeTempStructure; 336 compiler.codeGenerator.op_call( pSub_System_AddNeedFreeTempStructure ); 337 338 //pop useReg(復元する) 339 compiler.codeGenerator.op_pop( reg ); 340 #endif 341 342 isNeedFreeTempStructureInCurrentStep = true; 343 } 344 void CodeGenerator::op_FreeTempStructure() 345 { 346 if( !isNeedFreeTempStructureInCurrentStep ) 347 { 348 // 解放の必要はない 349 return; 350 } 351 352 // call _System_FreeTempStructure 353 extern const UserProc *pSub_System_FreeTempStructure; 354 op_call( pSub_System_FreeTempStructure ); 355 356 isNeedFreeTempStructureInCurrentStep = false; 357 }
Note:
See TracChangeset
for help on using the changeset viewer.