Index: /trunk/abdev/BasicCompiler32/Compile_ProcOp.cpp
===================================================================
--- /trunk/abdev/BasicCompiler32/Compile_ProcOp.cpp	(revision 246)
+++ /trunk/abdev/BasicCompiler32/Compile_ProcOp.cpp	(revision 247)
@@ -413,8 +413,6 @@
 
 	//プロシージャ抜け出しスケジュール（Exit Sub/Function）
-	extern DWORD *pExitSubSchedule;
-	extern int ExitSubScheduleNum;
-	pExitSubSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
-	ExitSubScheduleNum=0;
+	compiler.codeGenerator.exitSubCodePositions.clear();
+	compiler.codeGenerator._exitSubCodePositions_ObpOld.clear();
 
 	//ラベル用のメモリを確保
@@ -620,8 +618,5 @@
 
 	//プロシージャ抜け出しスケジュール（Exit Sub/Function）
-	for(i3=0;i3<ExitSubScheduleNum;i3++){
-		*((long *)(OpBuffer+pExitSubSchedule[i3]))=obp-(pExitSubSchedule[i3]+sizeof(long));
-	}
-	HeapDefaultFree(pExitSubSchedule);
+	compiler.codeGenerator.ResolveExitSubSchedule();
 
 	if(bDebugCompile&&bDebugSupportProc==0){
Index: /trunk/abdev/BasicCompiler32/Compile_Statement.cpp
===================================================================
--- /trunk/abdev/BasicCompiler32/Compile_Statement.cpp	(revision 246)
+++ /trunk/abdev/BasicCompiler32/Compile_Statement.cpp	(revision 247)
@@ -580,5 +580,5 @@
 void OpcodeDo(char *Parameter){
 	extern HANDLE hHeap;
-	int i,i2,i3,i4;
+	int i,i2,i3;
 
 	if(Parameter[0]) SetError(10,"Do",cp);
@@ -702,9 +702,5 @@
 
 				//jne
-				OpBuffer[obp++]=(char)0x0F;
-				OpBuffer[obp++]=(char)0x85;
-				obp+=sizeof(long);
-				i2=obp;
-
+				const CodeGenerator::PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
 
 				//cmp ebx,0
@@ -712,9 +708,5 @@
 
 				//jne
-				OpBuffer[obp++]=(char)0x0F;
-				OpBuffer[obp++]=(char)0x85;
-				obp+=sizeof(long);
-				i4=obp;
-
+				const CodeGenerator::PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
 
 				if(basbuf[i3]=='0'){
@@ -724,6 +716,6 @@
 					pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
 
-					*((long *)(OpBuffer+i2-sizeof(long)))=obp-i2;
-					*((long *)(OpBuffer+i4-sizeof(long)))=obp-i4;
+					compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 );
+					compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
 				}
 				else if(basbuf[i3]=='1'){
@@ -731,12 +723,13 @@
 
 					//jmp 2（ループを続ける）
-					OpBuffer[obp++]=(char)0xEB;
-					OpBuffer[obp++]=(char)0x02;
-
-					*((long *)(OpBuffer+i2-sizeof(long)))=obp-i2;
-					*((long *)(OpBuffer+i4-sizeof(long)))=obp-i4;
+					const CodeGenerator::PertialSchedule *pTempPertialSchedule3 = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
+
+					compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 );
+					compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
 
 					//jmp 5（ループ終了）
 					pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
+
+					compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule3 );
 				}
 			}
@@ -791,6 +784,4 @@
 
 void OpcodeExitSub(void){
-	extern DWORD *pExitSubSchedule;
-	extern int ExitSubScheduleNum;
 	extern HANDLE hHeap;
 
@@ -804,11 +795,5 @@
 
 	//jmp ...(End Sub/Function)
-	OpBuffer[obp++]=(char)0xE9;
-
-	pExitSubSchedule=(DWORD *)HeapReAlloc(hHeap,0,pExitSubSchedule,(ExitSubScheduleNum+1)*sizeof(DWORD));
-	pExitSubSchedule[ExitSubScheduleNum]=obp;
-	ExitSubScheduleNum++;
-
-	obp+=sizeof(long);
+	compiler.codeGenerator.op_jmp_exitsub();
 }
 
Index: /trunk/abdev/BasicCompiler_Common/Compile.cpp
===================================================================
--- /trunk/abdev/BasicCompiler_Common/Compile.cpp	(revision 246)
+++ /trunk/abdev/BasicCompiler_Common/Compile.cpp	(revision 247)
@@ -28,8 +28,4 @@
 int CaseScheduleNum;
 int NowCaseSchedule;
-
-//プロシージャ抜け出しスケジュール（Exit Sub/Function）
-DWORD *pExitSubSchedule;
-int ExitSubScheduleNum;
 
 //グローバル変数初期バッファ
Index: /trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h
===================================================================
--- /trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h	(revision 246)
+++ /trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h	(revision 247)
@@ -101,4 +101,8 @@
 public:
 
+	// Exit Subスケジュールの管理
+	std::vector<long> exitSubCodePositions;
+	std::vector<int> _exitSubCodePositions_ObpOld;
+
 	// Gotoスケジュールの管理
 	std::vector<GotoLabelSchedule> gotoLabelSchedules;
@@ -158,4 +162,6 @@
 		return _continueCodePositions_ObpOld[_continueCodePositions_ObpOld.size()-1];
 	}
+	
+	void ResolveExitSubSchedule();
 
 	void CheckUnresolveSchedule();
@@ -183,4 +189,5 @@
 	const PertialSchedule *op_jmp( long offset, int op_size = sizeof(char), bool isPertialSchedule = false, bool isSelfOpcodeOffset = false );
 	void op_jmp_continue();
+	void op_jmp_exitsub();
 	void op_jmp_goto_schedule( const GotoLabelSchedule &gotoLabelSchedule );
 
Index: /trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp
===================================================================
--- /trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp	(revision 246)
+++ /trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp	(revision 247)
@@ -3,4 +3,19 @@
 #include <CodeGenerator.h>
 
+
+void CodeGenerator::ResolveExitSubSchedule()
+{
+	BOOST_FOREACH( long exitSubCodePosition, exitSubCodePositions )
+	{
+		pNativeCode->Overwrite( exitSubCodePosition, (long)( pNativeCode->GetSize()-(exitSubCodePosition+sizeof(long)) ) );
+	}
+	
+	// TODO: 未完成
+	BOOST_FOREACH( long exitSubCodePositionOld, _exitSubCodePositions_ObpOld )
+	{
+		extern int obp;
+		pNativeCode->OverwriteOld( exitSubCodePositionOld, (long)( obp-(exitSubCodePositionOld+sizeof(long)) ) );
+	}
+}
 
 void CodeGenerator::CheckUnresolveSchedule()
@@ -202,9 +217,21 @@
 	op_jmp( GetContinueCodePosOld()-obp, sizeof(long), false, true );
 }
-void CodeGenerator::op_jmp_goto_schedule( const GotoLabelSchedule &gotoLabelSchedule )
+void CodeGenerator::op_jmp_exitsub()
 {
 	// オペコード
 	pNativeCode->Put( (char)0xE9 );
 
+	exitSubCodePositions.push_back( pNativeCode->GetSize() );
+	
+	extern int obp;
+	_exitSubCodePositions_ObpOld.push_back( obp );
+
+	pNativeCode->Put( (long)0 );
+}
+void CodeGenerator::op_jmp_goto_schedule( const GotoLabelSchedule &gotoLabelSchedule )
+{
+	// オペコード
+	pNativeCode->Put( (char)0xE9 );
+
 	gotoLabelSchedules.push_back( gotoLabelSchedule );
 
