| [3] | 1 | #include "../BasicCompiler_Common/common.h"
 | 
|---|
 | 2 | #include "Opcode.h"
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | 
 | 
|---|
| [86] | 5 | void SystemProc( const UserProc &userProc ){
 | 
|---|
 | 6 |     if( userProc.GetName() == "_System_GetEip" ){
 | 
|---|
| [3] | 7 |         //mov eax,dword ptr[esp]
 | 
|---|
 | 8 |         OpBuffer[obp++]=(char)0x8B;
 | 
|---|
 | 9 |         OpBuffer[obp++]=(char)0x04;
 | 
|---|
 | 10 |         OpBuffer[obp++]=(char)0x24;
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 |         //ret
 | 
|---|
 | 13 |         OpBuffer[obp++]=(char)0xC3;
 | 
|---|
 | 14 |     }
 | 
|---|
| [86] | 15 |     else if( userProc.GetName() == "_System_InitDllGlobalVariables" ){
 | 
|---|
| [3] | 16 |         ////////////////////////////////////////
 | 
|---|
 | 17 |         // DLLのグローバル領域をコンパイル
 | 
|---|
 | 18 |         ////////////////////////////////////////
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 |         extern BOOL bDll;
 | 
|---|
 | 21 |         if(!bDll){
 | 
|---|
 | 22 |             //ret
 | 
|---|
 | 23 |             OpBuffer[obp++]=(char)0xC3;
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 |             return;
 | 
|---|
 | 26 |         }
 | 
|---|
 | 27 | 
 | 
|---|
| [76] | 28 |         UserProc *pBackUserProc;
 | 
|---|
 | 29 |         pBackUserProc = &UserProc::CompilingUserProc();
 | 
|---|
 | 30 |         UserProc::CompileStartForGlobalArea();
 | 
|---|
| [3] | 31 | 
 | 
|---|
 | 32 |         int BackCp;
 | 
|---|
 | 33 |         BackCp=cp;
 | 
|---|
 | 34 |         cp=-1;
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 |         extern BOOL bDebugCompile;
 | 
|---|
 | 37 |         if(bDebugCompile){
 | 
|---|
 | 38 |             //デバッグ用の変数を定義
 | 
|---|
 | 39 |             DebugVariable();
 | 
|---|
 | 40 |         }
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 |         //GC用の変数を定義
 | 
|---|
 | 43 |         InitGCVariables();
 | 
|---|
 | 44 | 
 | 
|---|
| [42] | 45 |         //クラスに属する静的メンバを定義
 | 
|---|
 | 46 |         CMember::InitStaticMember();
 | 
|---|
 | 47 | 
 | 
|---|
| [3] | 48 |         GetGlobalDataForDll();
 | 
|---|
 | 49 | 
 | 
|---|
| [76] | 50 |         UserProc::CompileStartForUserProc( pBackUserProc );
 | 
|---|
| [3] | 51 |         cp=BackCp;
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 |         //ret
 | 
|---|
 | 54 |         OpBuffer[obp++]=(char)0xC3;
 | 
|---|
 | 55 |     }
 | 
|---|
| [86] | 56 |     else if( userProc.GetName() == "_System_InitStaticLocalVariables" ){
 | 
|---|
| [3] | 57 |         //静的ローカルオブジェクトのコンストラクタ呼び出し
 | 
|---|
 | 58 | 
 | 
|---|
| [76] | 59 |         foreach( Variable *pVar, globalVars ){
 | 
|---|
 | 60 |             if(memicmp(pVar->GetName().c_str(),"Static%",7)==0){
 | 
|---|
| [3] | 61 |                 //コンストラクタ呼び出し
 | 
|---|
| [76] | 62 |                 if( pVar->IsObject() ){
 | 
|---|
| [3] | 63 | 
 | 
|---|
 | 64 |                     //エラー用
 | 
|---|
| [76] | 65 |                     cp=pVar->source_code_address;
 | 
|---|
| [3] | 66 | 
 | 
|---|
| [50] | 67 |                     CallConstructor(
 | 
|---|
| [76] | 68 |                         pVar->GetName().c_str(),
 | 
|---|
 | 69 |                         pVar->GetSubScriptsPtr(),
 | 
|---|
 | 70 |                         *pVar,
 | 
|---|
 | 71 |                         pVar->paramStrForConstructor.c_str());
 | 
|---|
| [3] | 72 |                 }
 | 
|---|
 | 73 |             }
 | 
|---|
 | 74 |         }
 | 
|---|
 | 75 | 
 | 
|---|
 | 76 |         //ret
 | 
|---|
 | 77 |         OpBuffer[obp++]=(char)0xC3;
 | 
|---|
 | 78 |     }
 | 
|---|
| [86] | 79 |     else if( userProc.GetName() == "_System_Call_Destructor_of_GlobalObject" ){
 | 
|---|
| [3] | 80 | 
 | 
|---|
| [76] | 81 |         UserProc *pBackUserProc;
 | 
|---|
 | 82 |         pBackUserProc = &UserProc::CompilingUserProc();
 | 
|---|
 | 83 |         UserProc::CompileStartForGlobalArea();
 | 
|---|
| [3] | 84 | 
 | 
|---|
| [34] | 85 |         obj_LexScopes.CallDestructorsOfScopeEnd();
 | 
|---|
| [3] | 86 | 
 | 
|---|
| [76] | 87 |         UserProc::CompileStartForUserProc( pBackUserProc );
 | 
|---|
| [3] | 88 | 
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 |         //ret
 | 
|---|
 | 91 |         OpBuffer[obp++]=(char)0xC3;
 | 
|---|
 | 92 |     }
 | 
|---|
| [86] | 93 |     else if( userProc.GetName() == "_System_GetSp" ){
 | 
|---|
| [3] | 94 |         //mov eax,esp
 | 
|---|
 | 95 |         op_mov_RR(REG_EAX,REG_ESP);
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 |         //add eax,PTR_SIZE
 | 
|---|
 | 98 |         op_add_RV8(REG_EAX,PTR_SIZE);
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 |         //ret
 | 
|---|
 | 101 |         OpBuffer[obp++]=(char)0xC3;
 | 
|---|
 | 102 |     }
 | 
|---|
| [86] | 103 |     else if( userProc.GetName() == "_allrem" ){
 | 
|---|
| [3] | 104 |         //乗除演算用の特殊関数(64ビット整数対応)
 | 
|---|
 | 105 |         BYTE Buffer_allrem[]={
 | 
|---|
 | 106 |             0x53,0x57,0x33,0xFF,0x8B,0x44,0x24,0x10,0x0B,0xC0,0x7D,0x14,0x47,0x8B,0x54,0x24,0x0C,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x10,0x89,0x54,0x24,0x0C,0x8B,0x44,0x24,0x18,0x0B,0xC0,0x7D,0x13,0x8B,0x54,0x24,0x14,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x18,0x89,0x54,0x24,0x14,0x0B,0xC0,0x75,0x1B,0x8B,0x4C,0x24,0x14,0x8B,0x44,0x24,0x10,0x33,0xD2,0xF7,0xF1,0x8B,0x44,0x24,0x0C,0xF7,0xF1,0x8B,0xC2,0x33,0xD2,0x4F,0x79,0x4E,0xEB,0x53,0x8B,0xD8,0x8B,0x4C,0x24,0x14,0x8B,0x54,0x24,0x10,0x8B,0x44,0x24,0x0C,0xD1,0xEB,0xD1,0xD9,0xD1,0xEA,0xD1,0xD8,0x0B,0xDB,0x75,0xF4,0xF7,0xF1,0x8B,0xC8,0xF7,0x64,0x24,0x18,0x91,0xF7,0x64,0x24,0x14,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x10,0x77,0x08,0x72,0x0E,0x3B,0x44,0x24,0x0C,0x76,0x08,0x2B,0x44,0x24,0x14,0x1B,0x54,0x24,0x18,0x2B,0x44,0x24,0x0C,0x1B,0x54,0x24,0x10,0x4F,0x79,0x07,0xF7,0xDA,0xF7,0xD8,0x83,0xDA,0x00,0x5F,0x5B,0xC2,0x10,0x00
 | 
|---|
 | 107 |         };
 | 
|---|
 | 108 | 
 | 
|---|
 | 109 |         memcpy(OpBuffer+obp,Buffer_allrem,178);
 | 
|---|
 | 110 |         obp+=178;
 | 
|---|
 | 111 |     }
 | 
|---|
| [86] | 112 |     else if( userProc.GetName() == "_aullrem" ){
 | 
|---|
| [3] | 113 |         //乗除演算用の特殊関数(64ビット整数対応)
 | 
|---|
 | 114 |         BYTE Buffer_aullrem[]={
 | 
|---|
 | 115 |             0x53,0x8B,0x44,0x24,0x14,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x10,0x8B,
 | 
|---|
 | 116 |             0x44,0x24,0x0C,0x33,0xD2,0xF7,0xF1,0x8B,0x44,0x24,0x08,0xF7,0xF1,0x8B,
 | 
|---|
 | 117 |             0xC2,0x33,0xD2,0xEB,0x50,0x8B,0xC8,0x8B,0x5C,0x24,0x10,0x8B,0x54,0x24,
 | 
|---|
 | 118 |             0x0C,0x8B,0x44,0x24,0x08,0xD1,0xE9,0xD1,0xDB,0xD1,0xEA,0xD1,0xD8,0x0B,
 | 
|---|
 | 119 |             0xC9,0x75,0xF4,0xF7,0xF3,0x8B,0xC8,0xF7,0x64,0x24,0x14,0x91,0xF7,0x64,
 | 
|---|
 | 120 |             0x24,0x10,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x0C,0x77,0x08,0x72,0x0E,
 | 
|---|
 | 121 |             0x3B,0x44,0x24,0x08,0x76,0x08,0x2B,0x44,0x24,0x10,0x1B,0x54,0x24,0x14,
 | 
|---|
 | 122 |             0x2B,0x44,0x24,0x08,0x1B,0x54,0x24,0x0C,0xF7,0xDA,0xF7,0xD8,0x83,0xDA,
 | 
|---|
 | 123 |             0x00,0x5B,0xC2,0x10,0x00
 | 
|---|
 | 124 |         };
 | 
|---|
 | 125 | 
 | 
|---|
 | 126 |         memcpy(OpBuffer+obp,Buffer_aullrem,117);
 | 
|---|
 | 127 |         obp+=117;
 | 
|---|
 | 128 |     }
 | 
|---|
| [86] | 129 |     else if( userProc.GetName() == "_allmul" ){
 | 
|---|
| [3] | 130 |         //乗算用の特殊関数(64ビット整数対応)
 | 
|---|
 | 131 |         BYTE Buffer_allmul[]={
 | 
|---|
 | 132 |             0x8B,0x44,0x24,0x08,0x8B,0x4C,0x24,0x10,0x0B,0xC8,0x8B,0x4C,0x24,0x0C,0x75,0x09,0x8B,0x44,0x24,0x04,0xF7,0xE1,0xC2,0x10,0x00,0x53,0xF7,0xE1,0x8B,0xD8,0x8B,0x44,0x24,0x08,0xF7,0x64,0x24,0x14,0x03,0xD8,0x8B,0x44,0x24,0x08,0xF7,0xE1,0x03,0xD3,0x5B,0xC2,0x10,0x00
 | 
|---|
 | 133 |         };
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 |         memcpy(OpBuffer+obp,Buffer_allmul,52);
 | 
|---|
 | 136 |         obp+=52;
 | 
|---|
 | 137 |     }
 | 
|---|
| [86] | 138 |     else if( userProc.GetName() == "_alldiv" ){
 | 
|---|
| [3] | 139 |         //除算用の特殊関数(64ビット整数対応)
 | 
|---|
 | 140 |         BYTE Buffer_alldiv[]={
 | 
|---|
 | 141 |             0x57,0x56,0x53,0x33,0xFF,0x8B,0x44,0x24,0x14,0x0B,0xC0,0x7D,0x14,0x47,0x8B,0x54,0x24,0x10,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x14,0x89,0x54,0x24,0x10,0x8B,0x44,0x24,0x1C,0x0B,0xC0,0x7D,0x14,0x47,0x8B,0x54,0x24,0x18,0xF7,0xD8,0xF7,0xDA,0x83,0xD8,0x00,0x89,0x44,0x24,0x1C,0x89,0x54,0x24,0x18,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x18,0x8B,0x44,0x24,0x14,0x33,0xD2,0xF7,0xF1,0x8B,0xD8,0x8B,0x44,0x24,0x10,0xF7,0xF1,0x8B,0xD3,0xEB,0x41,0x8B,0xD8,0x8B,0x4C,0x24,0x18,0x8B,0x54,0x24,0x14,0x8B,0x44,0x24,0x10,0xD1,0xEB,0xD1,0xD9,0xD1,0xEA,0xD1,0xD8,0x0B,0xDB,0x75,0xF4,0xF7,0xF1,0x8B,0xF0,0xF7,0x64,0x24,0x1C,0x8B,0xC8,0x8B,0x44,0x24,0x18,0xF7,0xE6,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x14,0x77,0x08,0x72,0x07,0x3B,0x44,0x24,0x10,0x76,0x01,0x4E,0x33,0xD2,0x8B,0xC6,0x4F,0x75,0x07,0xF7,0xDA,0xF7,0xD8,0x83,0xDA,0x00,0x5B,0x5E,0x5F,0xC2,0x10,0x00
 | 
|---|
 | 142 |         };
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 |         memcpy(OpBuffer+obp,Buffer_alldiv,170);
 | 
|---|
 | 145 |         obp+=170;
 | 
|---|
 | 146 |     }
 | 
|---|
| [86] | 147 |     else if( userProc.GetName() == "_aulldiv" ){
 | 
|---|
| [3] | 148 |         //整数除算用の特殊関数(64ビット整数対応)
 | 
|---|
 | 149 |         BYTE Buffer_aulldiv[]={
 | 
|---|
 | 150 |             0x53,0x56,0x8B,0x44,0x24,0x18,0x0B,0xC0,0x75,0x18,0x8B,0x4C,0x24,0x14,
 | 
|---|
 | 151 |             0x8B,0x44,0x24,0x10,0x33,0xD2,0xF7,0xF1,0x8B,0xD8,0x8B,0x44,0x24,0x0C,
 | 
|---|
 | 152 |             0xF7,0xF1,0x8B,0xD3,0xEB,0x41,0x8B,0xC8,0x8B,0x5C,0x24,0x14,0x8B,0x54,
 | 
|---|
 | 153 |             0x24,0x10,0x8B,0x44,0x24,0x0C,0xD1,0xE9,0xD1,0xDB,0xD1,0xEA,0xD1,0xD8,
 | 
|---|
 | 154 |             0x0B,0xC9,0x75,0xF4,0xF7,0xF3,0x8B,0xF0,0xF7,0x64,0x24,0x18,0x8B,0xC8,
 | 
|---|
 | 155 |             0x8B,0x44,0x24,0x14,0xF7,0xE6,0x03,0xD1,0x72,0x0E,0x3B,0x54,0x24,0x10,
 | 
|---|
 | 156 |             0x77,0x08,0x72,0x07,0x3B,0x44,0x24,0x0C,0x76,0x01,0x4E,0x33,0xD2,0x8B,
 | 
|---|
 | 157 |             0xC6,0x5E,0x5B,0xC2,0x10,0x00
 | 
|---|
 | 158 |         };
 | 
|---|
 | 159 | 
 | 
|---|
 | 160 |         memcpy(OpBuffer+obp,Buffer_aulldiv,104);
 | 
|---|
 | 161 |         obp+=104;
 | 
|---|
 | 162 |     }
 | 
|---|
| [86] | 163 |     else if( userProc.GetName() == "_allshl" ){
 | 
|---|
| [3] | 164 |         //符号あり左ビットシフト用の特殊関数(64ビット整数対応)
 | 
|---|
 | 165 |         BYTE Buffer_allshl[]={
 | 
|---|
 | 166 |             0x80,0xF9,0x40,0x73,0x15,0x80,0xF9,0x20,0x73,0x06,0x0F,0xA5,0xC2,0xD3,0xE0,0xC3,0x8B,0xD0,0x33,0xC0,0x80,0xE1,0x1F,0xD3,0xE2,0xC3,0x33,0xC0,0x33,0xD2,0xC3
 | 
|---|
 | 167 |         };
 | 
|---|
 | 168 | 
 | 
|---|
 | 169 |         memcpy(OpBuffer+obp,Buffer_allshl,31);
 | 
|---|
 | 170 |         obp+=31;
 | 
|---|
 | 171 |     }
 | 
|---|
| [86] | 172 |     else if( userProc.GetName() == "_allshr" ){
 | 
|---|
| [3] | 173 |         //符号あり右ビットシフト用の特殊関数(64ビット整数対応)
 | 
|---|
 | 174 |         BYTE Buffer_allshr[]={
 | 
|---|
 | 175 |             0x80,0xF9,0x40,0x73,0x16,0x80,0xF9,0x20,0x73,0x06,0x0F,0xAD,0xD0,0xD3,0xFA,0xC3,0x8B,0xC2,0xC1,0xFA,0x1F,0x80,0xE1,0x1F,0xD3,0xF8,0xC3,0xC1,0xFA,0x1F,0x8B,0xC2,0xC3
 | 
|---|
 | 176 |         };
 | 
|---|
 | 177 | 
 | 
|---|
 | 178 |         memcpy(OpBuffer+obp,Buffer_allshr,33);
 | 
|---|
 | 179 |         obp+=33;
 | 
|---|
 | 180 |     }
 | 
|---|
| [86] | 181 |     else if( userProc.GetName() == "_aullshr" ){
 | 
|---|
| [3] | 182 |         //符号なし右ビットシフト用の特殊関数(64ビット整数対応)
 | 
|---|
 | 183 |         BYTE Buffer_aullshr[]={
 | 
|---|
 | 184 |             0x80,0xF9,0x40,         //cmp         cl,40h
 | 
|---|
 | 185 |             0x73,0x15,              //jae         RETZERO (0040d71a)
 | 
|---|
 | 186 |             0x80,0xF9,0x20,         //cmp         cl,20h
 | 
|---|
 | 187 |             0x73,0x06,              //jae         MORE32 (0040d710)
 | 
|---|
 | 188 |             0x0F,0xAD,0xD0,         //shrd        eax,edx,cl
 | 
|---|
 | 189 |             0xD3,0xEA,              //shr         edx,cl
 | 
|---|
 | 190 |             0xC3,                   //ret
 | 
|---|
 | 191 |             //MORE32:
 | 
|---|
 | 192 |             0x8B,0xC2,              //mov         eax,edx
 | 
|---|
 | 193 |             0x33,0xD2,              //xor         edx,edx
 | 
|---|
 | 194 |             0x80,0xE1,0x1F,         //and         cl,1Fh
 | 
|---|
 | 195 |             0xD3,0xE8,              //shr         eax,cl
 | 
|---|
 | 196 |             0xC3,                   //ret
 | 
|---|
 | 197 |             //RETZERO:
 | 
|---|
 | 198 |             0x33,0xC0,              //xor         eax,eax
 | 
|---|
 | 199 |             0x33,0xD2,              //xor         edx,edx
 | 
|---|
 | 200 |             0xC3                    //ret
 | 
|---|
 | 201 |         };
 | 
|---|
 | 202 | 
 | 
|---|
 | 203 |         memcpy(OpBuffer+obp,Buffer_aullshr,31);
 | 
|---|
 | 204 |         obp+=31;
 | 
|---|
 | 205 |     }
 | 
|---|
| [90] | 206 |     else{
 | 
|---|
 | 207 |         SetError();
 | 
|---|
 | 208 |     }
 | 
|---|
 | 209 | }
 | 
|---|
 | 210 | void AutoGeneration(UserProc &userProc){
 | 
|---|
 | 211 |     if( userProc.GetName() == "InitializeUserTypes"
 | 
|---|
| [89] | 212 |         && userProc.HasParentClass()
 | 
|---|
 | 213 |         && (string)userProc.GetParentClass().name == "_System_TypeBase" ){
 | 
|---|
 | 214 | 
 | 
|---|
 | 215 |             pobj_DBClass->Compile_System_InitializeUserTypes();
 | 
|---|
| [86] | 216 |     }
 | 
|---|
| [95] | 217 |     else if( userProc.GetName() == "RegisterGlobalRoots"
 | 
|---|
 | 218 |         && userProc.HasParentClass()
 | 
|---|
 | 219 |         && (string)userProc.GetParentClass().name == "_System_CGarbageCollection" ){
 | 
|---|
 | 220 | 
 | 
|---|
 | 221 |             Compile_AddGlobalRootsForGc();
 | 
|---|
 | 222 |     }
 | 
|---|
| [78] | 223 |     else{
 | 
|---|
 | 224 |         SetError();
 | 
|---|
 | 225 |     }
 | 
|---|
| [3] | 226 | }
 | 
|---|
 | 227 | 
 | 
|---|
| [91] | 228 | void _compile_proc(UserProc *pUserProc){
 | 
|---|
| [3] | 229 |     extern char *basbuf;
 | 
|---|
 | 230 |     extern HANDLE hHeap;
 | 
|---|
| [75] | 231 |     extern UserProc **ppSubHash;
 | 
|---|
| [3] | 232 |     extern BOOL bDebugCompile;
 | 
|---|
| [76] | 233 |     int i3,i4,LocalVarSchedule,EspOffsetSchedule,BaseOffset;
 | 
|---|
| [3] | 234 |     char temporary[VN_SIZE];
 | 
|---|
 | 235 | 
 | 
|---|
| [75] | 236 |     if( pUserProc->IsUsing() == false || pUserProc->IsCompiled() ) return;
 | 
|---|
| [3] | 237 | 
 | 
|---|
| [76] | 238 |     if( pUserProc->localVars.size() ){
 | 
|---|
 | 239 |         SetError();
 | 
|---|
 | 240 |         return;
 | 
|---|
 | 241 |     }
 | 
|---|
 | 242 | 
 | 
|---|
| [75] | 243 |     pUserProc->CompleteCompile();
 | 
|---|
| [3] | 244 | 
 | 
|---|
 | 245 |     extern BOOL bSystemProc;
 | 
|---|
| [75] | 246 |     if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1;
 | 
|---|
| [3] | 247 |     else bSystemProc=0;
 | 
|---|
 | 248 | 
 | 
|---|
 | 249 |     extern BOOL bDebugSupportProc;
 | 
|---|
| [75] | 250 |     if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){
 | 
|---|
| [3] | 251 |         if(!bDebugCompile){
 | 
|---|
 | 252 |             return;
 | 
|---|
 | 253 |         }
 | 
|---|
 | 254 |         bDebugSupportProc=1;
 | 
|---|
 | 255 |     }
 | 
|---|
 | 256 |     else bDebugSupportProc=0;
 | 
|---|
 | 257 | 
 | 
|---|
| [75] | 258 |     pUserProc->beginOpAddress=obp;
 | 
|---|
| [3] | 259 | 
 | 
|---|
| [89] | 260 |     //コンパイル中の関数が属するクラス
 | 
|---|
 | 261 |     pobj_CompilingClass=pUserProc->GetParentClassPtr();
 | 
|---|
 | 262 | 
 | 
|---|
 | 263 |     //コンパイルスタートをクラス管理クラスに追加
 | 
|---|
 | 264 |     pobj_DBClass->StartCompile( pUserProc );
 | 
|---|
 | 265 | 
 | 
|---|
 | 266 |     //コンパイル中の関数
 | 
|---|
 | 267 |     UserProc::CompileStartForUserProc( pUserProc );
 | 
|---|
 | 268 | 
 | 
|---|
| [75] | 269 |     if(pUserProc->IsSystem()){
 | 
|---|
| [89] | 270 |         ////////////////////
 | 
|---|
 | 271 |         // 特殊関数
 | 
|---|
 | 272 |         ////////////////////
 | 
|---|
 | 273 | 
 | 
|---|
| [3] | 274 |         extern int AllLocalVarSize;
 | 
|---|
 | 275 |         AllLocalVarSize=0;
 | 
|---|
 | 276 | 
 | 
|---|
| [86] | 277 |         SystemProc(*pUserProc);
 | 
|---|
| [3] | 278 | 
 | 
|---|
| [75] | 279 |         pUserProc->endOpAddress=obp;
 | 
|---|
| [3] | 280 |         return;
 | 
|---|
 | 281 |     }
 | 
|---|
 | 282 | 
 | 
|---|
| [75] | 283 |     cp=pUserProc->GetCodePos();
 | 
|---|
| [3] | 284 |     for(;;cp++){
 | 
|---|
 | 285 |         if(IsCommandDelimitation(basbuf[cp])) break;
 | 
|---|
 | 286 |     }
 | 
|---|
 | 287 |     cp--;
 | 
|---|
 | 288 | 
 | 
|---|
 | 289 |     //ローカル変数に関する情報
 | 
|---|
 | 290 |     extern int AllLocalVarSize;
 | 
|---|
 | 291 |     AllLocalVarSize=0;
 | 
|---|
 | 292 | 
 | 
|---|
 | 293 |     //ローカル変数アドレススケジュール
 | 
|---|
 | 294 |     extern DWORD *pLocalVarAddrSchedule;
 | 
|---|
 | 295 |     extern int LocalVarAddrScheduleNum;
 | 
|---|
 | 296 |     pLocalVarAddrSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
 | 
|---|
 | 297 |     LocalVarAddrScheduleNum=0;
 | 
|---|
 | 298 | 
 | 
|---|
 | 299 |     //パラメータ用の変数データを考慮
 | 
|---|
| [75] | 300 |     for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
 | 
|---|
 | 301 |         Parameter ¶m = *pUserProc->RealParams()[i3];
 | 
|---|
| [73] | 302 | 
 | 
|---|
| [76] | 303 |         Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef() );
 | 
|---|
| [3] | 304 | 
 | 
|---|
| [76] | 305 |         if( param.IsArray() ){
 | 
|---|
 | 306 |             pVar->SetArray( param.GetSubScriptsPtr() );
 | 
|---|
| [3] | 307 |         }
 | 
|---|
 | 308 | 
 | 
|---|
| [76] | 309 |         int varSize;
 | 
|---|
| [73] | 310 |         if( param.IsRef() == false && param.IsStruct() ){
 | 
|---|
| [64] | 311 |             //構造体のByValパラメータ
 | 
|---|
| [76] | 312 |             pVar->ThisIsParameter();
 | 
|---|
 | 313 |             varSize=PTR_SIZE;
 | 
|---|
| [3] | 314 |         }
 | 
|---|
 | 315 |         else{
 | 
|---|
| [76] | 316 |             if( param.IsArray() == false ){
 | 
|---|
 | 317 |                 varSize = pVar->GetMemorySize();
 | 
|---|
| [3] | 318 |             }
 | 
|---|
 | 319 |             else{
 | 
|---|
| [76] | 320 |                 varSize=PTR_SIZE;
 | 
|---|
| [3] | 321 |             }
 | 
|---|
 | 322 |         }
 | 
|---|
| [76] | 323 |         AllLocalVarSize+=varSize;
 | 
|---|
 | 324 |         pVar->offset=AllLocalVarSize;
 | 
|---|
| [3] | 325 | 
 | 
|---|
 | 326 |         //レキシカルスコープ情報
 | 
|---|
| [76] | 327 |         pVar->ScopeLevel=obj_LexScopes.GetNowLevel();
 | 
|---|
 | 328 |         pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress();
 | 
|---|
 | 329 |         pVar->bLiving=TRUE;
 | 
|---|
| [3] | 330 | 
 | 
|---|
| [76] | 331 |         pUserProc->localVars.push_back( pVar );
 | 
|---|
| [3] | 332 |     }
 | 
|---|
 | 333 | 
 | 
|---|
 | 334 |     //Thisポインタを示すローカルオフセット値をセット
 | 
|---|
 | 335 |     extern int LocalVar_ThisPtrOffset;
 | 
|---|
 | 336 |     LocalVar_ThisPtrOffset=AllLocalVarSize;
 | 
|---|
 | 337 | 
 | 
|---|
 | 338 |     BaseOffset=AllLocalVarSize;
 | 
|---|
 | 339 | 
 | 
|---|
 | 340 |     //ret用のアドレスを考慮
 | 
|---|
 | 341 |     AllLocalVarSize+=sizeof(long);
 | 
|---|
 | 342 | 
 | 
|---|
 | 343 | 
 | 
|---|
 | 344 |     ///////////////////////
 | 
|---|
 | 345 |     // ここからコード生成
 | 
|---|
 | 346 | 
 | 
|---|
 | 347 |     //sub esp,AllLocalVarSize(スケジュール)
 | 
|---|
 | 348 |     op_sub_esp(0xFFFFFFFF);
 | 
|---|
 | 349 |     LocalVarSchedule=obp-sizeof(long);
 | 
|---|
 | 350 | 
 | 
|---|
 | 351 |     //push ebp
 | 
|---|
 | 352 |     op_push(REG_EBP);
 | 
|---|
 | 353 | 
 | 
|---|
 | 354 |     //mov ebp,esp
 | 
|---|
 | 355 |     OpBuffer[obp++]=(char)0x8B;
 | 
|---|
 | 356 |     OpBuffer[obp++]=(char)0xEC;
 | 
|---|
 | 357 | 
 | 
|---|
 | 358 |     //push ebx
 | 
|---|
 | 359 |     op_push(REG_EBX);
 | 
|---|
 | 360 | 
 | 
|---|
 | 361 |     //push esi
 | 
|---|
 | 362 |     OpBuffer[obp++]=(char)0x56;
 | 
|---|
 | 363 | 
 | 
|---|
 | 364 |     //push edi
 | 
|---|
 | 365 |     OpBuffer[obp++]=(char)0x57;
 | 
|---|
 | 366 | 
 | 
|---|
| [75] | 367 |     if( !pUserProc->ReturnType().IsNull() ){
 | 
|---|
| [3] | 368 |         //戻り値が存在するとき
 | 
|---|
 | 369 | 
 | 
|---|
| [75] | 370 |         const char *temp = pUserProc->GetName().c_str();
 | 
|---|
 | 371 |         if( temp[0]==1&&temp[1]==ESC_OPERATOR ){
 | 
|---|
 | 372 |             temp = "_System_ReturnValue";
 | 
|---|
 | 373 |         }
 | 
|---|
| [3] | 374 | 
 | 
|---|
| [75] | 375 |         if( pUserProc->ReturnType().IsStruct() ){
 | 
|---|
| [64] | 376 |             //戻り値用の構造体(値型)はパラメータで引き渡される
 | 
|---|
| [3] | 377 |         }
 | 
|---|
 | 378 |         else{
 | 
|---|
| [89] | 379 |             if( pUserProc->ReturnType().IsObject() ){
 | 
|---|
 | 380 |                 sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() );
 | 
|---|
 | 381 |             }
 | 
|---|
 | 382 |             else{
 | 
|---|
 | 383 |                 //戻り値用の変数の定義
 | 
|---|
 | 384 |                 sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() );
 | 
|---|
 | 385 |             }
 | 
|---|
| [40] | 386 | 
 | 
|---|
| [3] | 387 |             OpcodeDim(temporary,0);
 | 
|---|
 | 388 |         }
 | 
|---|
 | 389 |     }
 | 
|---|
 | 390 | 
 | 
|---|
 | 391 |     //プロシージャ抜け出しスケジュール(Exit Sub/Function)
 | 
|---|
 | 392 |     extern DWORD *pExitSubSchedule;
 | 
|---|
 | 393 |     extern int ExitSubScheduleNum;
 | 
|---|
 | 394 |     pExitSubSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
 | 
|---|
 | 395 |     ExitSubScheduleNum=0;
 | 
|---|
 | 396 | 
 | 
|---|
 | 397 |     //ラベル用のメモリを確保
 | 
|---|
 | 398 |     extern LABEL *pLabelNames;
 | 
|---|
 | 399 |     extern int MaxLabelNum;
 | 
|---|
 | 400 |     pLabelNames=(LABEL *)HeapAlloc(hHeap,0,1);
 | 
|---|
 | 401 |     MaxLabelNum=0;
 | 
|---|
 | 402 | 
 | 
|---|
 | 403 |     //Gotoラベルスケジュール
 | 
|---|
 | 404 |     extern GOTOLABELSCHEDULE *pGotoLabelSchedule;
 | 
|---|
 | 405 |     extern int GotoLabelScheduleNum;
 | 
|---|
 | 406 |     pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapAlloc(hHeap,0,1);
 | 
|---|
 | 407 |     GotoLabelScheduleNum=0;
 | 
|---|
 | 408 | 
 | 
|---|
 | 409 |     //With情報のメモリを確保
 | 
|---|
 | 410 |     extern WITHINFO WithInfo;
 | 
|---|
 | 411 |     WithInfo.ppName=(char **)HeapAlloc(hHeap,0,1);
 | 
|---|
 | 412 |     WithInfo.pWithCp=(int *)HeapAlloc(hHeap,0,1);
 | 
|---|
 | 413 |     WithInfo.num=0;
 | 
|---|
 | 414 | 
 | 
|---|
 | 415 |     //重複エラー情報管理のメモリを確保
 | 
|---|
 | 416 |     extern char **SynonymErrorWords;
 | 
|---|
 | 417 |     extern int SynonymErrorNum;
 | 
|---|
 | 418 |     SynonymErrorNum=0;
 | 
|---|
 | 419 |     SynonymErrorWords=(char **)HeapAlloc(hHeap,0,1);
 | 
|---|
 | 420 | 
 | 
|---|
 | 421 |     //Continueアドレスを初期化
 | 
|---|
 | 422 |     extern DWORD dwContinueAddress;
 | 
|---|
 | 423 |     dwContinueAddress=-1;
 | 
|---|
 | 424 | 
 | 
|---|
 | 425 |     if(bDebugCompile&&bDebugSupportProc==0){
 | 
|---|
 | 426 |         //push dword ptr[ebp+(AllLocalVarSize-BaseOffset)](スケジュール)
 | 
|---|
 | 427 |         OpBuffer[obp++]=(char)0xFF;
 | 
|---|
 | 428 |         OpBuffer[obp++]=(char)0xB5;
 | 
|---|
 | 429 |         EspOffsetSchedule=obp;
 | 
|---|
 | 430 |         obp+=sizeof(long);  
 | 
|---|
 | 431 | 
 | 
|---|
 | 432 |         //push dword ptr[ebp](以前のebp)
 | 
|---|
 | 433 |         OpBuffer[obp++]=(char)0xFF;
 | 
|---|
 | 434 |         OpBuffer[obp++]=(char)0x75;
 | 
|---|
 | 435 |         OpBuffer[obp++]=(char)0x00;
 | 
|---|
 | 436 | 
 | 
|---|
 | 437 |         //call _DebugSys_StartProc
 | 
|---|
| [75] | 438 |         extern UserProc *pSub_DebugSys_StartProc;
 | 
|---|
| [3] | 439 |         op_call(pSub_DebugSys_StartProc);
 | 
|---|
 | 440 |     }
 | 
|---|
 | 441 | 
 | 
|---|
 | 442 |     if(pobj_CompilingClass){
 | 
|---|
| [75] | 443 |         if( pUserProc->GetName() == pobj_CompilingClass->name ){
 | 
|---|
| [3] | 444 |             ////////////////////////////////////
 | 
|---|
 | 445 |             // コンストラクタをコンパイルするとき
 | 
|---|
 | 446 |             ////////////////////////////////////
 | 
|---|
 | 447 | 
 | 
|---|
| [17] | 448 |             //コンストラクタのコンパイル開始を通知
 | 
|---|
 | 449 |             pobj_CompilingClass->NotifyStartConstructorCompile();
 | 
|---|
 | 450 | 
 | 
|---|
| [27] | 451 |             //基底クラスかどうかの識別
 | 
|---|
 | 452 |             //(継承元がインターフェイスの場合も基底クラスと見なす)
 | 
|---|
| [3] | 453 |             BOOL bThisIsSuperClass;
 | 
|---|
 | 454 |             if(pobj_CompilingClass->pobj_InheritsClass==0) bThisIsSuperClass=1;
 | 
|---|
| [51] | 455 |             else if( pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod() == NULL ){
 | 
|---|
| [3] | 456 |                 //インターフェイスを継承したときはコンストラクタを持たない
 | 
|---|
 | 457 |                 bThisIsSuperClass=1;
 | 
|---|
 | 458 |             }
 | 
|---|
 | 459 |             else bThisIsSuperClass=0;
 | 
|---|
 | 460 | 
 | 
|---|
 | 461 |             if(!bThisIsSuperClass){
 | 
|---|
 | 462 |                 /* サブクラスコンストラクタをコンパイルしているときは、
 | 
|---|
| [27] | 463 |                     基底クラスのコンストラクタを呼び出す */
 | 
|---|
| [3] | 464 | 
 | 
|---|
 | 465 |                 i3=cp+1;
 | 
|---|
 | 466 |                 while(IsCommandDelimitation(basbuf[i3])) i3++;
 | 
|---|
 | 467 |                 for(i4=0;;i3++,i4++){
 | 
|---|
 | 468 |                     if(!IsVariableChar(basbuf[i3])){
 | 
|---|
 | 469 |                         temporary[i4]=0;
 | 
|---|
 | 470 |                         break;
 | 
|---|
 | 471 |                     }
 | 
|---|
 | 472 |                     temporary[i4]=basbuf[i3];
 | 
|---|
 | 473 |                 }
 | 
|---|
 | 474 |                 if(lstrcmp(temporary,
 | 
|---|
 | 475 |                     pobj_CompilingClass->pobj_InheritsClass->name)==0){
 | 
|---|
| [27] | 476 |                     //基底クラスのコンストラクタを呼び出す
 | 
|---|
| [3] | 477 |                     cp=i3;
 | 
|---|
 | 478 |                     for(i4=0;;cp++,i4++){
 | 
|---|
 | 479 |                         if(IsCommandDelimitation(basbuf[cp])){
 | 
|---|
 | 480 |                             temporary[i4]=0;
 | 
|---|
 | 481 |                             break;
 | 
|---|
 | 482 |                         }
 | 
|---|
 | 483 |                         temporary[i4]=basbuf[cp];
 | 
|---|
 | 484 |                     }
 | 
|---|
 | 485 |                     if(!(temporary[0]=='('&&temporary[lstrlen(temporary)-1]==')')){
 | 
|---|
 | 486 |                         SetError(1,NULL,cp);
 | 
|---|
 | 487 |                     }
 | 
|---|
 | 488 |                     RemoveStringPare(temporary);
 | 
|---|
 | 489 | 
 | 
|---|
| [89] | 490 |                     Type dummyType;
 | 
|---|
 | 491 |                     CallProc( PROC_DEFAULT
 | 
|---|
 | 492 |                         , pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc
 | 
|---|
 | 493 |                         , pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc->GetName().c_str()
 | 
|---|
 | 494 |                         , temporary
 | 
|---|
 | 495 |                         , dummyType );
 | 
|---|
| [3] | 496 |                 }
 | 
|---|
 | 497 |                 else{
 | 
|---|
| [27] | 498 |                     //基底クラスのコンストラクタを暗黙的に呼び出す
 | 
|---|
| [3] | 499 |                     Opcode_CallProc("",
 | 
|---|
| [75] | 500 |                         pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc,
 | 
|---|
| [3] | 501 |                         0,
 | 
|---|
 | 502 |                         "",
 | 
|---|
 | 503 |                         0);
 | 
|---|
 | 504 |                 }
 | 
|---|
 | 505 |             }
 | 
|---|
 | 506 | 
 | 
|---|
| [85] | 507 |             //新しいオブジェクト領域は0で初期化されているため、Nothingを明示的に代入する必要はない
 | 
|---|
 | 508 | /*
 | 
|---|
| [3] | 509 |             //実体クラスを持つメンバのコンストラクタ(引数有りを除く)を呼び出す
 | 
|---|
 | 510 |             for(i3=0;i3<pobj_CompilingClass->iMemberNum;i3++){
 | 
|---|
| [40] | 511 |                 CMember *pMember = pobj_CompilingClass->ppobj_Member[i3];
 | 
|---|
| [76] | 512 |                 if(pMember->IsObject()){
 | 
|---|
| [64] | 513 |                     // オブジェクトメンバを発見したとき
 | 
|---|
| [3] | 514 | 
 | 
|---|
| [85] | 515 |                     sprintf(temporary, "This.%s=Nothing",
 | 
|---|
 | 516 |                         pMember->name );
 | 
|---|
| [64] | 517 |                     OpcodeCalc( temporary );
 | 
|---|
| [3] | 518 |                 }
 | 
|---|
 | 519 |             }
 | 
|---|
| [85] | 520 | */
 | 
|---|
| [3] | 521 | 
 | 
|---|
 | 522 |             //仮想関数テーブルを初期化
 | 
|---|
 | 523 |             if(pobj_CompilingClass->vtbl_num&&
 | 
|---|
| [28] | 524 |                 pobj_CompilingClass->IsAbstract()==false){
 | 
|---|
 | 525 |                     //関数テーブルに値をセット
 | 
|---|
| [63] | 526 |                     int offset = (int)pobj_CompilingClass->GetVtblGlobalOffset();
 | 
|---|
| [3] | 527 | 
 | 
|---|
| [28] | 528 |                     //mov eax,offset
 | 
|---|
 | 529 |                     OpBuffer[obp++]=(char)0xB8;
 | 
|---|
 | 530 |                     *((long *)(OpBuffer+obp))=offset;
 | 
|---|
 | 531 |                     pobj_DataTableSchedule->add();
 | 
|---|
 | 532 |                     obp+=sizeof(long);
 | 
|---|
| [3] | 533 | 
 | 
|---|
| [28] | 534 |                     //Thisポインタをecxにコピー
 | 
|---|
 | 535 |                     SetThisPtrToReg(REG_ECX);
 | 
|---|
| [3] | 536 | 
 | 
|---|
| [28] | 537 |                     //mov dword ptr[ecx],eax
 | 
|---|
 | 538 |                     OpBuffer[obp++]=(char)0x89;
 | 
|---|
 | 539 |                     OpBuffer[obp++]=(char)0x01;
 | 
|---|
| [3] | 540 |             }
 | 
|---|
 | 541 |         }
 | 
|---|
| [75] | 542 |         else if( pUserProc->IsDestructor() ){
 | 
|---|
| [18] | 543 |             //デストラクタをコンパイルしたとき
 | 
|---|
 | 544 | 
 | 
|---|
 | 545 |             //デストラクタのコンパイル開始を通知
 | 
|---|
 | 546 |             pobj_CompilingClass->NotifyStartDestructorCompile();
 | 
|---|
 | 547 |         }
 | 
|---|
| [3] | 548 |     }
 | 
|---|
 | 549 | 
 | 
|---|
 | 550 |     //////////////////////////////////////////
 | 
|---|
 | 551 |     //////////////////////////////////////////
 | 
|---|
 | 552 |     ////// プロシージャ内をコンパイル ////////
 | 
|---|
| [90] | 553 |     if( pUserProc->IsAutoGeneration() ){
 | 
|---|
 | 554 |         AutoGeneration( *pUserProc );
 | 
|---|
 | 555 |     }
 | 
|---|
| [75] | 556 |     else{
 | 
|---|
| [90] | 557 |         if(pUserProc->IsMacro()){
 | 
|---|
 | 558 |             CompileBuffer(ESC_ENDMACRO,0);
 | 
|---|
 | 559 |         }
 | 
|---|
 | 560 |         else{
 | 
|---|
 | 561 |             if(pUserProc->IsSub()){
 | 
|---|
 | 562 |                 CompileBuffer(ESC_ENDSUB,0);
 | 
|---|
 | 563 |             }
 | 
|---|
 | 564 |             else if(pUserProc->IsFunction()){
 | 
|---|
 | 565 |                 CompileBuffer(ESC_ENDFUNCTION,0);
 | 
|---|
 | 566 |             }
 | 
|---|
 | 567 |         }
 | 
|---|
| [75] | 568 |     }
 | 
|---|
| [3] | 569 |     //////////////////////////////////////////
 | 
|---|
 | 570 |     //////////////////////////////////////////
 | 
|---|
 | 571 | 
 | 
|---|
| [17] | 572 |     if( pobj_CompilingClass ){
 | 
|---|
 | 573 | 
 | 
|---|
 | 574 |         if( pobj_CompilingClass->IsCompilingConstructor() ){
 | 
|---|
 | 575 |             // コンストラクタをコンパイルしていたとき
 | 
|---|
| [18] | 576 | 
 | 
|---|
| [17] | 577 |             // コンストラクタのコンパイルが完了したことを通知
 | 
|---|
 | 578 |             pobj_CompilingClass->NotifyFinishConstructorCompile();
 | 
|---|
 | 579 |         }
 | 
|---|
| [75] | 580 |         else if( pUserProc->IsDestructor() ){
 | 
|---|
| [3] | 581 |             ////////////////////////////////////
 | 
|---|
 | 582 |             //デストラクタをコンパイルしたとき
 | 
|---|
 | 583 |             ////////////////////////////////////
 | 
|---|
 | 584 | 
 | 
|---|
| [18] | 585 |             // デストラクタのコンパイルが完了したことを通知
 | 
|---|
 | 586 |             pobj_CompilingClass->NotifyFinishDestructorCompile();
 | 
|---|
 | 587 | 
 | 
|---|
| [3] | 588 |             if(pobj_CompilingClass->pobj_InheritsClass){
 | 
|---|
 | 589 |                 /* サブクラスのデストラクタをコンパイルしているときは、
 | 
|---|
| [27] | 590 |                     基底クラスのデストラクタを呼び出す */
 | 
|---|
| [3] | 591 | 
 | 
|---|
| [51] | 592 |                 CMethod *method = pobj_CompilingClass->pobj_InheritsClass->GetDestructorMethod();
 | 
|---|
 | 593 |                 if( method ){
 | 
|---|
| [3] | 594 |                     Opcode_CallProc("",
 | 
|---|
| [75] | 595 |                         method->pUserProc,
 | 
|---|
| [3] | 596 |                         0,
 | 
|---|
 | 597 |                         "",
 | 
|---|
 | 598 |                         0);
 | 
|---|
 | 599 |                 }
 | 
|---|
 | 600 |             }
 | 
|---|
 | 601 | 
 | 
|---|
| [64] | 602 |             //実体クラスを持つメンバのデストラクタ呼び出しはGCに任せる
 | 
|---|
 | 603 |             /*
 | 
|---|
| [3] | 604 |             //※コンストラクタと逆順序で呼び出す
 | 
|---|
 | 605 |             int offset;
 | 
|---|
 | 606 |             int MemberTypeSize;
 | 
|---|
 | 607 |             int MemberObjectNum;
 | 
|---|
 | 608 |             offset=GetTypeSize(DEF_OBJECT,(LONG_PTR)pobj_CompilingClass);
 | 
|---|
 | 609 |             for(i3=pobj_CompilingClass->iMemberNum-1;i3>=0;i3--){
 | 
|---|
| [40] | 610 |                 CMember *pMember = pobj_CompilingClass->ppobj_Member[i3];
 | 
|---|
 | 611 | 
 | 
|---|
| [3] | 612 |                 MemberTypeSize=
 | 
|---|
| [40] | 613 |                     GetTypeSize(pMember->TypeInfo.type,
 | 
|---|
 | 614 |                         pMember->TypeInfo.u.lpIndex);
 | 
|---|
| [3] | 615 | 
 | 
|---|
 | 616 |                 MemberObjectNum=
 | 
|---|
| [40] | 617 |                     JumpSubScripts(pMember->SubScripts);
 | 
|---|
| [3] | 618 | 
 | 
|---|
 | 619 |                 offset-=MemberTypeSize*MemberObjectNum;
 | 
|---|
 | 620 | 
 | 
|---|
| [40] | 621 |                 if(pMember->TypeInfo.type==DEF_OBJECT){
 | 
|---|
| [51] | 622 |                     CMethod *method = pMember->TypeInfo.u.pobj_Class->GetDestructorMethod();
 | 
|---|
 | 623 |                     if( method ){
 | 
|---|
| [3] | 624 |                         for(i4=MemberObjectNum-1;i4>=0;i4--){
 | 
|---|
 | 625 |                             //Thisポインタをecxにコピー
 | 
|---|
 | 626 |                             SetThisPtrToReg(REG_ECX);
 | 
|---|
 | 627 | 
 | 
|---|
 | 628 |                             //add ecx,offset
 | 
|---|
 | 629 |                             OpBuffer[obp++]=(char)0x81;
 | 
|---|
 | 630 |                             OpBuffer[obp++]=(char)0xC1;
 | 
|---|
 | 631 |                             *((long *)(OpBuffer+obp))=offset+i4*MemberTypeSize;
 | 
|---|
 | 632 |                             obp+=sizeof(long);
 | 
|---|
 | 633 | 
 | 
|---|
 | 634 |                             //push ecx
 | 
|---|
 | 635 |                             op_push(REG_ECX);
 | 
|---|
 | 636 | 
 | 
|---|
 | 637 |                             //call destructor
 | 
|---|
| [75] | 638 |                             op_call( method->pUserProc );
 | 
|---|
| [3] | 639 |                         }
 | 
|---|
 | 640 |                     }
 | 
|---|
 | 641 |                 }
 | 
|---|
| [64] | 642 |             }*/
 | 
|---|
| [3] | 643 |         }
 | 
|---|
 | 644 |     }
 | 
|---|
 | 645 | 
 | 
|---|
 | 646 |     //ラベル用のメモリを解放
 | 
|---|
 | 647 |     for(i3=0;i3<MaxLabelNum;i3++){
 | 
|---|
 | 648 |         if(pLabelNames[i3].pName) HeapDefaultFree(pLabelNames[i3].pName);
 | 
|---|
 | 649 |     }
 | 
|---|
 | 650 |     HeapDefaultFree(pLabelNames);
 | 
|---|
 | 651 | 
 | 
|---|
 | 652 |     //Goto未知ラベルスケジュールを解放
 | 
|---|
 | 653 |     for(i3=0;i3<GotoLabelScheduleNum;i3++){
 | 
|---|
 | 654 |         if(pGotoLabelSchedule[i3].pName){
 | 
|---|
 | 655 |             SetError(6,pGotoLabelSchedule[i3].pName,pGotoLabelSchedule[i3].now_cp);
 | 
|---|
 | 656 |             HeapDefaultFree(pGotoLabelSchedule[i3].pName);
 | 
|---|
 | 657 |         }
 | 
|---|
 | 658 |         else{
 | 
|---|
 | 659 |             sprintf(temporary,"%d",pGotoLabelSchedule[i3].line);
 | 
|---|
 | 660 |             SetError(6,temporary,pGotoLabelSchedule[i3].now_cp);
 | 
|---|
 | 661 |         }
 | 
|---|
 | 662 |     }
 | 
|---|
 | 663 |     HeapDefaultFree(pGotoLabelSchedule);
 | 
|---|
 | 664 | 
 | 
|---|
 | 665 |     //With情報のメモリを解放
 | 
|---|
 | 666 |     for(i3=0;i3<WithInfo.num;i3++){
 | 
|---|
 | 667 |         SetError(22,"With",WithInfo.pWithCp[i3]);
 | 
|---|
 | 668 |         HeapDefaultFree(WithInfo.ppName[i3]);
 | 
|---|
 | 669 |     }
 | 
|---|
 | 670 |     HeapDefaultFree(WithInfo.ppName);
 | 
|---|
 | 671 |     HeapDefaultFree(WithInfo.pWithCp);
 | 
|---|
 | 672 | 
 | 
|---|
 | 673 |     //push ebp
 | 
|---|
 | 674 |     AllLocalVarSize+=sizeof(long);
 | 
|---|
 | 675 | 
 | 
|---|
 | 676 |     //ローカルオブジェクトの解放処理
 | 
|---|
| [34] | 677 |     obj_LexScopes.CallDestructorsOfScopeEnd();
 | 
|---|
| [3] | 678 | 
 | 
|---|
| [34] | 679 |     //プロシージャ抜け出しスケジュール(Exit Sub/Function)
 | 
|---|
 | 680 |     for(i3=0;i3<ExitSubScheduleNum;i3++){
 | 
|---|
 | 681 |         *((long *)(OpBuffer+pExitSubSchedule[i3]))=obp-(pExitSubSchedule[i3]+sizeof(long));
 | 
|---|
 | 682 |     }
 | 
|---|
 | 683 |     HeapDefaultFree(pExitSubSchedule);
 | 
|---|
 | 684 | 
 | 
|---|
 | 685 |     if(bDebugCompile&&bDebugSupportProc==0){
 | 
|---|
| [64] | 686 |         *((long *)(OpBuffer+EspOffsetSchedule))=AllLocalVarSize-BaseOffset-sizeof(long);
 | 
|---|
| [34] | 687 | 
 | 
|---|
 | 688 |         //call _DebugSys_EndProc
 | 
|---|
| [75] | 689 |         extern UserProc *pSub_DebugSys_EndProc;
 | 
|---|
| [34] | 690 |         op_call(pSub_DebugSys_EndProc);
 | 
|---|
 | 691 |     }
 | 
|---|
 | 692 | 
 | 
|---|
| [75] | 693 |     if( !pUserProc->ReturnType().IsNull() ){
 | 
|---|
| [3] | 694 |         //戻り値をeax、edxに設定
 | 
|---|
 | 695 |         RELATIVE_VAR RelativeVar;
 | 
|---|
 | 696 | 
 | 
|---|
| [75] | 697 |         const char *temp = pUserProc->GetName().c_str();
 | 
|---|
 | 698 |         if( temp[0]==1 && temp[1]==ESC_OPERATOR ){
 | 
|---|
| [3] | 699 |             temp="_System_ReturnValue";
 | 
|---|
| [75] | 700 |         }
 | 
|---|
| [76] | 701 |         GetVarOffsetReadWrite(temp,&RelativeVar,Type());
 | 
|---|
| [3] | 702 | 
 | 
|---|
| [75] | 703 |         i3=pUserProc->ReturnType().GetBasicType();
 | 
|---|
| [3] | 704 | 
 | 
|---|
| [64] | 705 |         if(i3==DEF_OBJECT || i3==DEF_STRUCT){
 | 
|---|
| [3] | 706 |             SetVarPtrToEax(&RelativeVar);
 | 
|---|
| [64] | 707 |             if( i3==DEF_OBJECT ){
 | 
|---|
 | 708 |                 //mov eax,dword ptr[eax]
 | 
|---|
 | 709 |                 op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
 | 
|---|
 | 710 |             }
 | 
|---|
| [3] | 711 |         }
 | 
|---|
 | 712 |         else if(i3==DEF_DOUBLE){
 | 
|---|
 | 713 |             //fld qword ptr[ebp+offset]
 | 
|---|
 | 714 |             OpBuffer[obp++]=(char)0xDD;
 | 
|---|
 | 715 |             OpBuffer[obp++]=(char)0x85;
 | 
|---|
 | 716 |             *((long *)(OpBuffer+obp))=RelativeVar.offset;
 | 
|---|
 | 717 |             AddLocalVarAddrSchedule();
 | 
|---|
 | 718 |             obp+=sizeof(long);
 | 
|---|
 | 719 |         }
 | 
|---|
 | 720 |         else if(i3==DEF_SINGLE){
 | 
|---|
 | 721 |             //fld dword ptr[ebp+offset]
 | 
|---|
 | 722 |             OpBuffer[obp++]=(char)0xD9;
 | 
|---|
 | 723 |             OpBuffer[obp++]=(char)0x85;
 | 
|---|
 | 724 |             *((long *)(OpBuffer+obp))=RelativeVar.offset;
 | 
|---|
 | 725 |             AddLocalVarAddrSchedule();
 | 
|---|
 | 726 |             obp+=sizeof(long);
 | 
|---|
 | 727 |         }
 | 
|---|
 | 728 |         else if(i3==DEF_INT64||i3==DEF_QWORD){
 | 
|---|
 | 729 |             //mov eax,dword ptr[ebp+offset]
 | 
|---|
 | 730 |             OpBuffer[obp++]=(char)0x8B;
 | 
|---|
 | 731 |             OpBuffer[obp++]=(char)0x85;
 | 
|---|
 | 732 |             *((long *)(OpBuffer+obp))=RelativeVar.offset;
 | 
|---|
 | 733 |             AddLocalVarAddrSchedule();
 | 
|---|
 | 734 |             obp+=sizeof(long);
 | 
|---|
 | 735 | 
 | 
|---|
 | 736 |             //mov edx,dword ptr[ebp+offset+sizeof(long)]
 | 
|---|
 | 737 |             OpBuffer[obp++]=(char)0x8B;
 | 
|---|
 | 738 |             OpBuffer[obp++]=(char)0x95;
 | 
|---|
 | 739 |             *((long *)(OpBuffer+obp))=RelativeVar.offset+sizeof(long);
 | 
|---|
 | 740 |             AddLocalVarAddrSchedule();
 | 
|---|
 | 741 |             obp+=sizeof(long);
 | 
|---|
 | 742 |         }
 | 
|---|
 | 743 |         else if(i3==DEF_LONG||i3==DEF_DWORD||
 | 
|---|
 | 744 |             IsPtrType(i3)){
 | 
|---|
 | 745 |             //mov eax,dword ptr[ebp+offset]
 | 
|---|
 | 746 |             OpBuffer[obp++]=(char)0x8B;
 | 
|---|
 | 747 |             OpBuffer[obp++]=(char)0x85;
 | 
|---|
 | 748 |             *((long *)(OpBuffer+obp))=RelativeVar.offset;
 | 
|---|
 | 749 |             AddLocalVarAddrSchedule();
 | 
|---|
 | 750 |             obp+=sizeof(long);
 | 
|---|
 | 751 |         }
 | 
|---|
| [55] | 752 |         else if(i3==DEF_INTEGER||i3==DEF_WORD || (isUnicode&&i3==DEF_CHAR)){
 | 
|---|
| [3] | 753 |             //xor eax,eax(eaxを0に初期化する)
 | 
|---|
 | 754 |             op_zero_reg(REG_EAX);
 | 
|---|
 | 755 | 
 | 
|---|
 | 756 |             //mov ax,word ptr[ebp+offset]
 | 
|---|
 | 757 |             OpBuffer[obp++]=(char)0x66;
 | 
|---|
 | 758 |             OpBuffer[obp++]=(char)0x8B;
 | 
|---|
 | 759 |             OpBuffer[obp++]=(char)0x85;
 | 
|---|
 | 760 |             *((long *)(OpBuffer+obp))=RelativeVar.offset;
 | 
|---|
 | 761 |             AddLocalVarAddrSchedule();
 | 
|---|
 | 762 |             obp+=sizeof(long);
 | 
|---|
 | 763 |         }
 | 
|---|
| [55] | 764 |         else if(i3==DEF_SBYTE||i3==DEF_BYTE||i3==DEF_BOOLEAN || (isUnicode==false&&i3==DEF_CHAR)){
 | 
|---|
| [3] | 765 |             //xor eax,eax(eaxを0に初期化する)
 | 
|---|
 | 766 |             op_zero_reg(REG_EAX);
 | 
|---|
 | 767 | 
 | 
|---|
 | 768 |             //mov al,byte ptr[ebp+offset]
 | 
|---|
 | 769 |             OpBuffer[obp++]=(char)0x8A;
 | 
|---|
 | 770 |             OpBuffer[obp++]=(char)0x85;
 | 
|---|
 | 771 |             *((long *)(OpBuffer+obp))=RelativeVar.offset;
 | 
|---|
 | 772 |             AddLocalVarAddrSchedule();
 | 
|---|
 | 773 |             obp+=sizeof(long);
 | 
|---|
 | 774 |         }
 | 
|---|
 | 775 |     }
 | 
|---|
 | 776 | 
 | 
|---|
 | 777 |     //ローカル変数アドレススケジュール
 | 
|---|
 | 778 |     for(i3=0;i3<LocalVarAddrScheduleNum;i3++){
 | 
|---|
 | 779 |         *((long *)(OpBuffer+pLocalVarAddrSchedule[i3]))+=AllLocalVarSize;
 | 
|---|
 | 780 |     }
 | 
|---|
 | 781 |     HeapDefaultFree(pLocalVarAddrSchedule);
 | 
|---|
| [76] | 782 |     foreach( Variable *pVar, pUserProc->localVars ){
 | 
|---|
 | 783 |         //後にデバッグで利用する
 | 
|---|
 | 784 |         pVar->offset = AllLocalVarSize - pVar->offset;
 | 
|---|
| [3] | 785 |     }
 | 
|---|
 | 786 | 
 | 
|---|
 | 787 |     //push ebp、ret用のアドレスを考慮
 | 
|---|
 | 788 |     AllLocalVarSize-=sizeof(long)*2;
 | 
|---|
 | 789 | 
 | 
|---|
 | 790 |     //ローカル変数用メモリを確保するためのスケジュール(subコマンド)
 | 
|---|
 | 791 |     *((long *)(OpBuffer+LocalVarSchedule))=AllLocalVarSize-BaseOffset;
 | 
|---|
 | 792 | 
 | 
|---|
 | 793 |     //pop edi
 | 
|---|
 | 794 |     OpBuffer[obp++]=(char)0x5F;
 | 
|---|
 | 795 | 
 | 
|---|
 | 796 |     //pop esi
 | 
|---|
 | 797 |     OpBuffer[obp++]=(char)0x5E;
 | 
|---|
 | 798 | 
 | 
|---|
 | 799 |     //pop ebx
 | 
|---|
 | 800 |     op_pop(REG_EBX);
 | 
|---|
 | 801 | 
 | 
|---|
| [64] | 802 |     if(bDebugCompile){
 | 
|---|
 | 803 |         //cmp esp,ebp
 | 
|---|
 | 804 |         op_cmp_RR( REG_ESP, REG_EBP );
 | 
|---|
 | 805 | 
 | 
|---|
 | 806 |         //jz 6(次のcallとbreakpointを飛び越す)
 | 
|---|
 | 807 |         OpBuffer[obp++]=(char)0x74;
 | 
|---|
 | 808 |         OpBuffer[obp++]=(char)0x06;
 | 
|---|
 | 809 | 
 | 
|---|
 | 810 |         //call _esp_error
 | 
|---|
| [75] | 811 |         extern UserProc *pSub_esp_error;
 | 
|---|
| [64] | 812 |         op_call( pSub_esp_error );
 | 
|---|
 | 813 | 
 | 
|---|
 | 814 |         breakpoint;
 | 
|---|
 | 815 |     }
 | 
|---|
 | 816 | 
 | 
|---|
| [3] | 817 |     //mov esp,ebp
 | 
|---|
 | 818 |     OpBuffer[obp++]=(char)0x8B;
 | 
|---|
 | 819 |     OpBuffer[obp++]=(char)0xE5;
 | 
|---|
 | 820 | 
 | 
|---|
 | 821 |     //pop ebp
 | 
|---|
 | 822 |     op_pop(REG_EBP);
 | 
|---|
 | 823 | 
 | 
|---|
 | 824 |     //add esp AllLocalVarSize
 | 
|---|
 | 825 |     op_add_esp(AllLocalVarSize-BaseOffset);
 | 
|---|
 | 826 | 
 | 
|---|
| [75] | 827 |     if( BaseOffset==0 || pUserProc->IsCdecl() ){
 | 
|---|
| [3] | 828 |         //ret 0
 | 
|---|
 | 829 |         OpBuffer[obp++]=(char)0xC3;
 | 
|---|
 | 830 |     }
 | 
|---|
 | 831 |     else{
 | 
|---|
 | 832 |         //ret BaseOffset(パラメータ分のスタック領域を解放)
 | 
|---|
 | 833 |         OpBuffer[obp++]=(char)0xC2;
 | 
|---|
 | 834 |         *((_int16 *)(OpBuffer+obp))=(_int16)BaseOffset;
 | 
|---|
 | 835 |         obp+=sizeof(_int16);
 | 
|---|
 | 836 |     }
 | 
|---|
 | 837 | 
 | 
|---|
| [76] | 838 | 
 | 
|---|
| [75] | 839 |     pUserProc->endOpAddress=obp;
 | 
|---|
| [3] | 840 | 
 | 
|---|
| [75] | 841 | 
 | 
|---|
 | 842 |     //重複エラー情報管理のメモリを解放
 | 
|---|
 | 843 |     for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
 | 
|---|
 | 844 |     HeapDefaultFree(SynonymErrorWords);
 | 
|---|
 | 845 |     SynonymErrorWords=0;
 | 
|---|
 | 846 | 
 | 
|---|
 | 847 | 
 | 
|---|
| [3] | 848 |     //ローカル変数のネーム情報は後に解放する
 | 
|---|
 | 849 | }
 | 
|---|
| [91] | 850 | 
 | 
|---|
 | 851 | void CompileBufferInProcedure( UserProc &userProc ){
 | 
|---|
 | 852 |     if( userProc.IsUsing() == false || userProc.IsCompiled() ) return;
 | 
|---|
 | 853 | 
 | 
|---|
 | 854 |     _compile_proc( &userProc );
 | 
|---|
| [92] | 855 | /*
 | 
|---|
| [91] | 856 |     // ログを履く
 | 
|---|
 | 857 |     char temporary[8192];
 | 
|---|
 | 858 |     temporary[0]=0;
 | 
|---|
 | 859 |     lstrcat( temporary, "------------------------------------------------------------------\n" );
 | 
|---|
 | 860 |     sprintf( temporary + lstrlen(temporary), "【 %s のコード情報】\n", userProc.GetFullName().c_str() );
 | 
|---|
 | 861 |     sprintf( temporary + lstrlen(temporary), "code size: %d bytes\n", userProc.GetCodeSize() );
 | 
|---|
 | 862 |     lstrcat( temporary, "------------------------------------------------------------------\n" );
 | 
|---|
 | 863 |     lstrcat( temporary, "\n" );
 | 
|---|
| [92] | 864 |     Smoothie::Logger::Put( temporary );*/
 | 
|---|
| [91] | 865 | }
 | 
|---|
| [3] | 866 | void CompileLocal(){
 | 
|---|
| [75] | 867 |     extern UserProc **ppSubHash;
 | 
|---|
| [3] | 868 |     int i2;
 | 
|---|
| [75] | 869 |     UserProc *pUserProc;
 | 
|---|
| [3] | 870 | 
 | 
|---|
 | 871 |     extern BOOL bDll;
 | 
|---|
 | 872 |     if(bDll){
 | 
|---|
 | 873 |         //DLLの場合はグローバル変数を初期化するための関数を一番初めにコンパイルする
 | 
|---|
| [75] | 874 |         pUserProc=GetSubHash("_System_InitDllGlobalVariables");
 | 
|---|
 | 875 |         if(pUserProc){
 | 
|---|
| [91] | 876 |             CompileBufferInProcedure( *pUserProc );
 | 
|---|
| [3] | 877 |         }
 | 
|---|
 | 878 |         else SetError(300,NULL,cp);
 | 
|---|
 | 879 |     }
 | 
|---|
 | 880 | 
 | 
|---|
| [94] | 881 |     //_System_TypeBase_InitializeUserTypesは一番最後にコンパイル
 | 
|---|
 | 882 |     extern UserProc *pSubStaticMethod_System_TypeBase_InitializeUserTypes;
 | 
|---|
 | 883 |     pSubStaticMethod_System_TypeBase_InitializeUserTypes->CompleteCompile();
 | 
|---|
 | 884 | 
 | 
|---|
| [3] | 885 |     //_System_InitStaticLocalVariablesは一番最後にコンパイル
 | 
|---|
 | 886 |     //※一般関数内の静的変数オブジェクトをすべて収集しなければならない
 | 
|---|
| [75] | 887 |     extern UserProc *pSub_System_InitStaticLocalVariables;
 | 
|---|
 | 888 |     pSub_System_InitStaticLocalVariables->CompleteCompile();
 | 
|---|
| [3] | 889 | 
 | 
|---|
 | 890 |     //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル
 | 
|---|
| [75] | 891 |     extern UserProc *pSub_System_Call_Destructor_of_GlobalObject;
 | 
|---|
 | 892 |     pSub_System_Call_Destructor_of_GlobalObject->CompleteCompile();
 | 
|---|
| [3] | 893 | 
 | 
|---|
| [94] | 894 | repeat:
 | 
|---|
| [3] | 895 |     for(i2=0;i2<MAX_HASH;i2++){
 | 
|---|
| [75] | 896 |         pUserProc=ppSubHash[i2];
 | 
|---|
 | 897 |         while(pUserProc){
 | 
|---|
| [91] | 898 |             CompileBufferInProcedure( *pUserProc );
 | 
|---|
| [75] | 899 |             pUserProc=pUserProc->pNextData;
 | 
|---|
| [3] | 900 |         }
 | 
|---|
 | 901 |     }
 | 
|---|
 | 902 | 
 | 
|---|
| [94] | 903 |     if( IsNeedProcCompile() ){
 | 
|---|
 | 904 |         //プロシージャコンパイルによって、プロシージャコンパイルが必要になる場合
 | 
|---|
 | 905 |         goto repeat;
 | 
|---|
 | 906 |     }
 | 
|---|
 | 907 | 
 | 
|---|
 | 908 |     //_System_TypeBase_InitializeUserTypesは最後のほうでコンパイル
 | 
|---|
 | 909 |     pSubStaticMethod_System_TypeBase_InitializeUserTypes->KillCompileStatus();
 | 
|---|
 | 910 |     CompileBufferInProcedure( *pSubStaticMethod_System_TypeBase_InitializeUserTypes );
 | 
|---|
 | 911 | 
 | 
|---|
 | 912 |     if( IsNeedProcCompile() ){
 | 
|---|
 | 913 |         //プロシージャコンパイルによって、プロシージャコンパイルが必要になる場合
 | 
|---|
 | 914 |         for(i2=0;i2<MAX_HASH;i2++){
 | 
|---|
 | 915 |             pUserProc=ppSubHash[i2];
 | 
|---|
 | 916 |             while(pUserProc){
 | 
|---|
 | 917 |                 CompileBufferInProcedure( *pUserProc );
 | 
|---|
 | 918 |                 pUserProc=pUserProc->pNextData;
 | 
|---|
| [3] | 919 |             }
 | 
|---|
 | 920 |         }
 | 
|---|
 | 921 |     }
 | 
|---|
 | 922 | 
 | 
|---|
 | 923 |     //_System_InitStaticLocalVariablesは一番最後にコンパイル
 | 
|---|
| [75] | 924 |     pSub_System_InitStaticLocalVariables->KillCompileStatus();
 | 
|---|
| [91] | 925 |     CompileBufferInProcedure( *pSub_System_InitStaticLocalVariables );
 | 
|---|
| [3] | 926 | 
 | 
|---|
 | 927 |     //_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル
 | 
|---|
| [75] | 928 |     pSub_System_Call_Destructor_of_GlobalObject->KillCompileStatus();
 | 
|---|
| [91] | 929 |     CompileBufferInProcedure( *pSub_System_Call_Destructor_of_GlobalObject );
 | 
|---|
| [3] | 930 | }
 | 
|---|