Index: BasicCompiler32/Compile_ProcOp.cpp
===================================================================
--- BasicCompiler32/Compile_ProcOp.cpp	(revision 75)
+++ BasicCompiler32/Compile_ProcOp.cpp	(revision 76)
@@ -26,8 +26,7 @@
 		}
 
-		extern BOOL bCompilingGlobal;
-		BOOL bBackCompilingGlobal;
-		bBackCompilingGlobal=bCompilingGlobal;
-		bCompilingGlobal=1;
+		UserProc *pBackUserProc;
+		pBackUserProc = &UserProc::CompilingUserProc();
+		UserProc::CompileStartForGlobalArea();
 
 		int BackCp;
@@ -49,5 +48,5 @@
 		GetGlobalDataForDll();
 
-		bCompilingGlobal=bBackCompilingGlobal;
+		UserProc::CompileStartForUserProc( pBackUserProc );
 		cp=BackCp;
 
@@ -58,23 +57,17 @@
 		//静的ローカルオブジェクトのコンストラクタ呼び出し
 
-		extern int MaxGlobalVarNum;
-		extern VARIABLE *GlobalVar;
-		int i;
-		for(i=0;i<MaxGlobalVarNum;i++){
-			if(_memicmp(GlobalVar[i].name,"Static%",7)==0){
+		foreach( Variable *pVar, globalVars ){
+			if(memicmp(pVar->GetName().c_str(),"Static%",7)==0){
 				//コンストラクタ呼び出し
-				if(GlobalVar[i].type==DEF_OBJECT){
+				if( pVar->IsObject() ){
 
 					//エラー用
-					cp=GlobalVar[i].source_code_address;
-
-					Type TypeInfo;
-					TypeInfo.type=GlobalVar[i].type;
-					TypeInfo.u.lpIndex=GlobalVar[i].u.index;
+					cp=pVar->source_code_address;
+
 					CallConstructor(
-						GlobalVar[i].name,
-						GlobalVar[i].SubScripts,
-						TypeInfo,
-						GlobalVar[i].ConstractParameter);
+						pVar->GetName().c_str(),
+						pVar->GetSubScriptsPtr(),
+						*pVar,
+						pVar->paramStrForConstructor.c_str());
 				}
 			}
@@ -86,12 +79,11 @@
 	else if(lstrcmp(name,"_System_Call_Destructor_of_GlobalObject")==0){
 
-		extern BOOL bCompilingGlobal;
-		BOOL bBackCompilingGlobal;
-		bBackCompilingGlobal=bCompilingGlobal;
-		bCompilingGlobal=1;
+		UserProc *pBackUserProc;
+		pBackUserProc = &UserProc::CompilingUserProc();
+		UserProc::CompileStartForGlobalArea();
 
 		obj_LexScopes.CallDestructorsOfScopeEnd();
 
-		bCompilingGlobal=bBackCompilingGlobal;
+		UserProc::CompileStartForUserProc( pBackUserProc );
 
 
@@ -219,10 +211,13 @@
 	extern UserProc **ppSubHash;
 	extern BOOL bDebugCompile;
-	int i3,i4,VarSize,LocalVarSchedule,EspOffsetSchedule,BufferSize,BaseOffset;
+	int i3,i4,LocalVarSchedule,EspOffsetSchedule,BaseOffset;
 	char temporary[VN_SIZE];
 
-	BufferSize=128;
-
 	if( pUserProc->IsUsing() == false || pUserProc->IsCompiled() ) return;
+
+	if( pUserProc->localVars.size() ){
+		SetError();
+		return;
+	}
 
 	pUserProc->CompleteCompile();
@@ -235,6 +230,4 @@
 	if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){
 		if(!bDebugCompile){
-			pUserProc->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1);
-			pUserProc->VarNum=0;
 			return;
 		}
@@ -246,7 +239,5 @@
 
 	if(pUserProc->IsSystem()){
-		extern int MaxLocalVarNum;
 		extern int AllLocalVarSize;
-		MaxLocalVarNum=0;
 		AllLocalVarSize=0;
 
@@ -254,6 +245,4 @@
 
 		pUserProc->endOpAddress=obp;
-		pUserProc->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1);
-		pUserProc->VarNum=0;
 		return;
 	}
@@ -266,9 +255,5 @@
 
 	//ローカル変数に関する情報
-	extern VARIABLE *LocalVar;
-	extern int MaxLocalVarNum;
 	extern int AllLocalVarSize;
-	LocalVar=(VARIABLE *)HeapAlloc(hHeap,0,1);
-	MaxLocalVarNum=0;
 	AllLocalVarSize=0;
 
@@ -283,49 +268,33 @@
 		Parameter &param = *pUserProc->RealParams()[i3];
 
-		//変数データを追加
-		LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE));
-
-		lstrcpy( LocalVar[MaxLocalVarNum].name,param.GetVarName().c_str() );
-
-		// TODO: パラメータのConst定義の指定が未完成
-		LocalVar[MaxLocalVarNum].bConst=false;
-
-		LocalVar[MaxLocalVarNum].bArray=param.IsArray()?TRUE:FALSE;
-		memcpy(LocalVar[MaxLocalVarNum].SubScripts,param.GetSubScriptsPtr(),MAX_ARRAYDIM*sizeof(int));
-
-		LocalVar[MaxLocalVarNum].type=param.GetBasicType();
-		if(LocalVar[MaxLocalVarNum].type==DEF_OBJECT
-			||LocalVar[MaxLocalVarNum].type==DEF_STRUCT){
-				if(pUserProc->IsExport())
-					SetError(24,NULL,cp);
-		}
-
-		LocalVar[MaxLocalVarNum].u.index=param.GetIndex();
-
+		Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef() );
+
+		if( param.IsArray() ){
+			pVar->SetArray( param.GetSubScriptsPtr() );
+		}
+
+		int varSize;
 		if( param.IsRef() == false && param.IsStruct() ){
 			//構造体のByValパラメータ
-			LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER | OBJECT_PARAMETER;
-			VarSize=PTR_SIZE;
+			pVar->ThisIsParameter();
+			varSize=PTR_SIZE;
 		}
 		else{
-			if( param.IsRef() == false && param.IsArray() == false ){
-				LocalVar[MaxLocalVarNum].fRef=0;
-				VarSize=GetTypeSize(LocalVar[MaxLocalVarNum].type,LocalVar[MaxLocalVarNum].u.index);
-				if(VarSize%PTR_SIZE) VarSize+=PTR_SIZE-(VarSize%PTR_SIZE);
+			if( param.IsArray() == false ){
+				varSize = pVar->GetMemorySize();
 			}
 			else{
-				LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER;
-				VarSize=PTR_SIZE;
-			}
-		}
-		AllLocalVarSize+=VarSize;
-		LocalVar[MaxLocalVarNum].offset=AllLocalVarSize;
+				varSize=PTR_SIZE;
+			}
+		}
+		AllLocalVarSize+=varSize;
+		pVar->offset=AllLocalVarSize;
 
 		//レキシカルスコープ情報
-		LocalVar[MaxLocalVarNum].ScopeLevel=obj_LexScopes.GetNowLevel();
-		LocalVar[MaxLocalVarNum].ScopeStartAddress=obj_LexScopes.GetStartAddress();
-		LocalVar[MaxLocalVarNum].bLiving=TRUE;
-
-		MaxLocalVarNum++;
+		pVar->ScopeLevel=obj_LexScopes.GetNowLevel();
+		pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress();
+		pVar->bLiving=TRUE;
+
+		pUserProc->localVars.push_back( pVar );
 	}
 
@@ -346,6 +315,5 @@
 
 	//コンパイル中の関数
-	extern UserProc *pCompilingUserProc;
-	pCompilingUserProc=pUserProc;
+	UserProc::CompileStartForUserProc( pUserProc );
 
 
@@ -507,9 +475,8 @@
 			}
 
-
 			//実体クラスを持つメンバのコンストラクタ（引数有りを除く）を呼び出す
 			for(i3=0;i3<pobj_CompilingClass->iMemberNum;i3++){
 				CMember *pMember = pobj_CompilingClass->ppobj_Member[i3];
-				if(pMember->TypeInfo.type==DEF_OBJECT){
+				if(pMember->IsObject()){
 					// オブジェクトメンバを発見したとき
 
@@ -517,9 +484,8 @@
 						pMember->name,
 						1, ESC_NEW,
-						pMember->TypeInfo.u.pobj_Class->name );
+						pMember->GetClass().name );
 					OpcodeCalc( temporary );
 				}
 			}
-
 
 			//仮想関数テーブルを初期化
@@ -686,5 +652,4 @@
 		//戻り値をeax、edxに設定
 		RELATIVE_VAR RelativeVar;
-		LONG_PTR lpIndex;
 
 		const char *temp = pUserProc->GetName().c_str();
@@ -692,5 +657,5 @@
 			temp="_System_ReturnValue";
 		}
-		GetVarOffsetReadWrite(temp,&i3,&RelativeVar,&lpIndex);
+		GetVarOffsetReadWrite(temp,&RelativeVar,Type());
 
 		i3=pUserProc->ReturnType().GetBasicType();
@@ -773,6 +738,7 @@
 	}
 	HeapDefaultFree(pLocalVarAddrSchedule);
-	for(i3=0;i3<MaxLocalVarNum;i3++){
-		LocalVar[i3].offset=AllLocalVarSize-LocalVar[i3].offset;//後にデバッグで利用する
+	foreach( Variable *pVar, pUserProc->localVars ){
+		//後にデバッグで利用する
+		pVar->offset = AllLocalVarSize - pVar->offset;
 	}
 
@@ -828,7 +794,6 @@
 	}
 
+
 	pUserProc->endOpAddress=obp;
-	pUserProc->pVar=LocalVar;
-	pUserProc->VarNum=MaxLocalVarNum;
 
 
