Index: trunk/abdev/BasicCompiler32/Compile_Statement.cpp
===================================================================
--- trunk/abdev/BasicCompiler32/Compile_Statement.cpp	(revision 248)
+++ trunk/abdev/BasicCompiler32/Compile_Statement.cpp	(revision 250)
@@ -798,38 +798,26 @@
 }
 
-void AddCaseSchedule(void){
-	extern DWORD *pCaseSchedule;
-	extern int CaseScheduleNum;
-	extern HANDLE hHeap;
-
-	pCaseSchedule=(DWORD *)HeapReAlloc(hHeap,0,pCaseSchedule,(CaseScheduleNum+1)*sizeof(DWORD));
-	pCaseSchedule[CaseScheduleNum]=obp;
-	CaseScheduleNum++;
-}
-
-int CaseTypeSize;
+//Caseスケジュール
+class SelectSchedule
+{
+public:
+	SelectSchedule( int typeSize )
+		: typeSize( typeSize )
+		, nowCaseSchedule( 0 )
+	{
+	}
+
+	PertialSchedules casePertialSchedules;
+	int typeSize;
+	int nowCaseSchedule;
+};
+std::vector<SelectSchedule> selectSchedules;
+
 void OpcodeSelect(const char *lpszParms){
-	extern DWORD *pCaseSchedule;
-	extern int CaseScheduleNum;
-	extern int NowCaseSchedule;
-	extern int CaseTypeSize;
 	extern HANDLE hHeap;
 	extern char *basbuf;
 	int i,i2,i3,sw,NowCaseCp;
 	char temporary[VN_SIZE];
-
-	DWORD *temp_pCaseSchedule;
-	int temp_CaseScheduleNum;
-	int temp_NowCaseSchedule;
-	int temp_CaseTypeSize;
-
-	temp_pCaseSchedule=pCaseSchedule;
-	temp_CaseScheduleNum=CaseScheduleNum;
-	temp_NowCaseSchedule=NowCaseSchedule;
-	temp_CaseTypeSize=CaseTypeSize;
-	pCaseSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
-	CaseScheduleNum=0;
-	NowCaseSchedule=0;
-
+	
 	Type type1;
 	if( !NumOpe(lpszParms,Type(), type1 ) ){
@@ -837,16 +825,13 @@
 	}
 
-	CaseTypeSize = type1.GetSize();
-	if( CaseTypeSize < sizeof(long) ){
-		CaseTypeSize=sizeof(long);
+	selectSchedules.push_back( SelectSchedule( type1.GetSize() ) );
+
+	if( selectSchedules.back().typeSize < sizeof(long) ){
+		selectSchedules.back().typeSize = sizeof(long);
 	}
 
 	for(i=cp,sw=0;;i++){
 		if(basbuf[i]=='\0'){
-			HeapDefaultFree(pCaseSchedule);
-			pCaseSchedule=temp_pCaseSchedule;
-			CaseScheduleNum=temp_CaseScheduleNum;
-			NowCaseSchedule=temp_NowCaseSchedule;
-			CaseTypeSize=temp_CaseTypeSize;
+			selectSchedules.pop_back();
 			SetError(22,"Select",cp);
 			return;
@@ -865,5 +850,5 @@
 			if(sw==0){
 				//add esp,CaseTypeSize
-				compiler.codeGenerator.op_add_esp(CaseTypeSize);
+				compiler.codeGenerator.op_add_esp( selectSchedules.back().typeSize );
 			}
 			break;
@@ -957,8 +942,7 @@
 
 					//jne ...
-					OpBuffer[obp++]=(char)0x0F;
-					OpBuffer[obp++]=(char)0x85;
-					AddCaseSchedule();
-					obp+=sizeof(long);
+					selectSchedules.back().casePertialSchedules.push_back(
+						compiler.codeGenerator.op_jne( 0, sizeof(long), true )
+					);
 				}
 				else if(type1.IsDouble()){
@@ -969,5 +953,5 @@
 
 					//add esp,CaseTypeSize
-					compiler.codeGenerator.op_add_esp(CaseTypeSize);
+					compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize);
 
 					//fld qword ptr[esp]
@@ -984,8 +968,7 @@
 
 					//jne ...
-					OpBuffer[obp++]=(char)0x0F;
-					OpBuffer[obp++]=(char)0x85;
-					AddCaseSchedule();
-					obp+=sizeof(long);
+					selectSchedules.back().casePertialSchedules.push_back(
+						compiler.codeGenerator.op_jne( 0, sizeof(long), true )
+					);
 				}
 				else if(type1.IsSingle()){
@@ -996,5 +979,5 @@
 
 					//add esp,CaseTypeSize
-					compiler.codeGenerator.op_add_esp(CaseTypeSize);
+					compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize);
 
 					//fld dword ptr[esp]
@@ -1011,8 +994,7 @@
 
 					//jne ...
-					OpBuffer[obp++]=(char)0x0F;
-					OpBuffer[obp++]=(char)0x85;
-					AddCaseSchedule();
-					obp+=sizeof(long);
+					selectSchedules.back().casePertialSchedules.push_back(
+						compiler.codeGenerator.op_jne( 0, sizeof(long), true )
+					);
 				}
 				else{
@@ -1029,8 +1011,7 @@
 
 					//je ...
-					OpBuffer[obp++]=(char)0x0F;
-					OpBuffer[obp++]=(char)0x84;
-					AddCaseSchedule();
-					obp+=sizeof(long);
+					selectSchedules.back().casePertialSchedules.push_back(
+						compiler.codeGenerator.op_je( 0, sizeof(long), true )
+					);
 				}
 
@@ -1042,7 +1023,7 @@
 
 			//jmp ...
-			OpBuffer[obp++]=(char)0xE9;
-			AddCaseSchedule();
-			obp+=sizeof(long);
+			selectSchedules.back().casePertialSchedules.push_back(
+				compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
+			);
 		}
 	}
@@ -1055,29 +1036,22 @@
 
 	//jmp EndSelect
-	OpBuffer[obp++]=(char)0xE9;
-	AddCaseSchedule();
-	obp+=sizeof(long);
+	selectSchedules.back().casePertialSchedules.push_back(
+		compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
+	);
 
 	//最終スケジュール
-	for(i=NowCaseSchedule;i<CaseScheduleNum;i++){
-		*(long *)(OpBuffer+pCaseSchedule[i])=obp-(pCaseSchedule[i]+sizeof(long));
-	}
-	HeapDefaultFree(pCaseSchedule);
+	for(i=selectSchedules.back().nowCaseSchedule;i<(int)selectSchedules.back().casePertialSchedules.size();i++){
+		compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[i] );
+	}
 
 	//レキシカルスコープをレベルダウン
 	compiler.codeGenerator.lexicalScopes.End();
 
-	pCaseSchedule=temp_pCaseSchedule;
-	CaseScheduleNum=temp_CaseScheduleNum;
-	NowCaseSchedule=temp_NowCaseSchedule;
-	CaseTypeSize=temp_CaseTypeSize;
+	selectSchedules.pop_back();
 }
 void OpcodeCase(char *Parameter){
-	extern DWORD *pCaseSchedule;
-	extern int NowCaseSchedule;
-	extern int CaseTypeSize;
 	int i;
 
-	if(!pCaseSchedule){
+	if(selectSchedules.back().typeSize==-1){
 		SetError(30,"Case",cp);
 		return;
@@ -1085,13 +1059,13 @@
 
 	//jmp EndSelect
-	OpBuffer[obp++]=(char)0xE9;
-	AddCaseSchedule();
-	obp+=sizeof(long);
+	selectSchedules.back().casePertialSchedules.push_back(
+		compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
+	);
 
 	i=0;
 	while(1){
 		//Caseスケジュール
-		*(long *)(OpBuffer+pCaseSchedule[NowCaseSchedule])=obp-(pCaseSchedule[NowCaseSchedule]+sizeof(long));
-		NowCaseSchedule++;
+		compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[selectSchedules.back().nowCaseSchedule] );
+		selectSchedules.back().nowCaseSchedule++;
 
 		i=JumpOneParameter(Parameter,i);
@@ -1100,5 +1074,5 @@
 
 	//add esp,CaseTypeSize
-	compiler.codeGenerator.op_add_esp(CaseTypeSize);
+	compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize);
 }
 
