| 1 | #include "stdafx.h" | 
|---|
| 2 |  | 
|---|
| 3 | #include <jenga/include/smoothie/LexicalAnalysis.h> | 
|---|
| 4 |  | 
|---|
| 5 | #include <LexicalScope.h> | 
|---|
| 6 | #include <Compiler.h> | 
|---|
| 7 |  | 
|---|
| 8 | #include "../BasicCompiler_Common/common.h" | 
|---|
| 9 | #include "Opcode.h" | 
|---|
| 10 |  | 
|---|
| 11 | void OpcodeOthers( const char *Command ){ | 
|---|
| 12 | int i,i2; | 
|---|
| 13 |  | 
|---|
| 14 | char leftTerm[8192]; | 
|---|
| 15 | int lastParePos = 0; | 
|---|
| 16 | for(i=0;;i++){ | 
|---|
| 17 | if(Command[i]=='\"'){ | 
|---|
| 18 | //ダブルクォートは不正なのでエラー扱い | 
|---|
| 19 | leftTerm[i]=0; | 
|---|
| 20 | SetError(3,leftTerm,cp); | 
|---|
| 21 | return; | 
|---|
| 22 | } | 
|---|
| 23 |  | 
|---|
| 24 | if(Command[i]=='('){ | 
|---|
| 25 | lastParePos = i; | 
|---|
| 26 | i2=GetStringInPare(leftTerm+i,Command+i); | 
|---|
| 27 | i+=i2-1; | 
|---|
| 28 | continue; | 
|---|
| 29 | } | 
|---|
| 30 | if(Command[i]=='['){ | 
|---|
| 31 | i2=GetStringInBracket(leftTerm+i,Command+i); | 
|---|
| 32 | i+=i2-1; | 
|---|
| 33 | continue; | 
|---|
| 34 | } | 
|---|
| 35 | if(Command[i]=='\0'){ | 
|---|
| 36 | leftTerm[i] = 0; | 
|---|
| 37 | break; | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | if( IsNumCalcMark( Command, i ) ){ | 
|---|
| 41 | leftTerm[i] = 0; | 
|---|
| 42 | break; | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | leftTerm[i]=Command[i]; | 
|---|
| 46 | } | 
|---|
| 47 | if(!( | 
|---|
| 48 | IsVariableTopChar(leftTerm[0])|| | 
|---|
| 49 | leftTerm[0]=='.'|| | 
|---|
| 50 | (leftTerm[0]==1&&leftTerm[1]==ESC_PSMEM) | 
|---|
| 51 | )){ | 
|---|
| 52 | SetError(1,NULL,cp); | 
|---|
| 53 | return; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 |  | 
|---|
| 57 | if(Command[i]=='\0' && lastParePos == 0){ | 
|---|
| 58 | ////////////////////////////// | 
|---|
| 59 | // パラメータ無しのマクロ検索 | 
|---|
| 60 | ////////////////////////////// | 
|---|
| 61 |  | 
|---|
| 62 | const UserProc *pUserProc = GetSubHash(Command); | 
|---|
| 63 |  | 
|---|
| 64 | //GetSubHash内でエラー提示が行われた場合 | 
|---|
| 65 | if(pUserProc==(UserProc *)-1) return; | 
|---|
| 66 |  | 
|---|
| 67 | if(pUserProc==0){ | 
|---|
| 68 | char temporary[VN_SIZE]; | 
|---|
| 69 | lstrcpy(temporary,Command); | 
|---|
| 70 |  | 
|---|
| 71 | CharUpper(temporary); | 
|---|
| 72 | pUserProc=GetSubHash(temporary); | 
|---|
| 73 |  | 
|---|
| 74 | //GetSubHash内でエラー提示が行われた場合 | 
|---|
| 75 | if(pUserProc==(UserProc *)-1) return; | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | if(pUserProc){ | 
|---|
| 79 | if( !pUserProc->IsMacro() ){ | 
|---|
| 80 | SetError(10,Command,cp); | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | Opcode_CallProc("",pUserProc,0,""); | 
|---|
| 84 |  | 
|---|
| 85 | return; | 
|---|
| 86 | } | 
|---|
| 87 | } | 
|---|
| 88 | else if(IsNumCalcMark(Command,i)){ | 
|---|
| 89 | //代入演算 | 
|---|
| 90 | OpcodeCalc(Command); | 
|---|
| 91 | return; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | Type resultType; | 
|---|
| 95 | bool isLiteral; | 
|---|
| 96 | BOOL bUseHeap; | 
|---|
| 97 | bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, false, NULL, true ); | 
|---|
| 98 | if( result ){ | 
|---|
| 99 |  | 
|---|
| 100 | ///////////////////// | 
|---|
| 101 | // 戻り値の処理 | 
|---|
| 102 | ///////////////////// | 
|---|
| 103 |  | 
|---|
| 104 | if( resultType.IsReal() ){ | 
|---|
| 105 | //fstp st(0) | 
|---|
| 106 | compiler.codeGenerator.PutOld( | 
|---|
| 107 | (char)0xDD, | 
|---|
| 108 | (char)0xD8 | 
|---|
| 109 | ); | 
|---|
| 110 | } | 
|---|
| 111 | else if( resultType.IsStruct() ){ | 
|---|
| 112 | //mov ebx,eax | 
|---|
| 113 | compiler.codeGenerator.op_mov_RR(REG_EBX,REG_EAX); | 
|---|
| 114 |  | 
|---|
| 115 | FreeTempObject(REG_EBX,&resultType.GetClass()); | 
|---|
| 116 | } | 
|---|
| 117 | } | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | void OpcodeIf(char *Parameter){ | 
|---|
| 121 | int i,i2; | 
|---|
| 122 | Type tempType; | 
|---|
| 123 |  | 
|---|
| 124 | for(i=0;;i++){ | 
|---|
| 125 | if(Parameter[i]=='\0'){ | 
|---|
| 126 | SetError(21,NULL,cp); | 
|---|
| 127 | return; | 
|---|
| 128 | } | 
|---|
| 129 | if(Parameter[i]==1&&Parameter[i+1]==ESC_THEN){ | 
|---|
| 130 | Parameter[i]=0; | 
|---|
| 131 | break; | 
|---|
| 132 | } | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 | const PertialSchedule *pIfPertialSchedule = NULL; | 
|---|
| 136 | if( !NumOpe(Parameter,Type(DEF_BOOLEAN),tempType) ){ | 
|---|
| 137 | //NumOpe内でエラー | 
|---|
| 138 | } | 
|---|
| 139 | else if( tempType.IsDouble() ){ | 
|---|
| 140 | //fld qword ptr[esp] | 
|---|
| 141 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); | 
|---|
| 142 |  | 
|---|
| 143 | //push 0 | 
|---|
| 144 | compiler.codeGenerator.op_push_V(0); | 
|---|
| 145 |  | 
|---|
| 146 | //fild dword ptr[esp] | 
|---|
| 147 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG); | 
|---|
| 148 |  | 
|---|
| 149 | //add esp,sizeof(double)+sizeof(long) | 
|---|
| 150 | compiler.codeGenerator.op_add_esp(sizeof(double)+sizeof(long)); | 
|---|
| 151 |  | 
|---|
| 152 | //fcompp | 
|---|
| 153 | compiler.codeGenerator.op_fcompp(); | 
|---|
| 154 |  | 
|---|
| 155 | //fnstsw ax | 
|---|
| 156 | compiler.codeGenerator.op_fnstsw_ax(); | 
|---|
| 157 |  | 
|---|
| 158 | //test ah,40 | 
|---|
| 159 | compiler.codeGenerator.op_test_ah( (char)0x40 ); | 
|---|
| 160 |  | 
|---|
| 161 | //jne (endif、または else まで) | 
|---|
| 162 | pIfPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true ); | 
|---|
| 163 | } | 
|---|
| 164 | else if( tempType.IsSingle() ){ | 
|---|
| 165 | //fld dword ptr[esp] | 
|---|
| 166 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); | 
|---|
| 167 |  | 
|---|
| 168 | //push 0 | 
|---|
| 169 | compiler.codeGenerator.op_push_V(0); | 
|---|
| 170 |  | 
|---|
| 171 | //fild dword ptr[esp] | 
|---|
| 172 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG); | 
|---|
| 173 |  | 
|---|
| 174 | //add esp,sizeof(float)+sizeof(long) | 
|---|
| 175 | compiler.codeGenerator.op_add_esp(sizeof(float)+sizeof(long)); | 
|---|
| 176 |  | 
|---|
| 177 | //fcompp | 
|---|
| 178 | compiler.codeGenerator.op_fcompp(); | 
|---|
| 179 |  | 
|---|
| 180 | //fnstsw ax | 
|---|
| 181 | compiler.codeGenerator.op_fnstsw_ax(); | 
|---|
| 182 |  | 
|---|
| 183 | //test ah,40 | 
|---|
| 184 | compiler.codeGenerator.op_test_ah( (char)0x40 ); | 
|---|
| 185 |  | 
|---|
| 186 | //jne (endif、または else まで) | 
|---|
| 187 | pIfPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true ); | 
|---|
| 188 | } | 
|---|
| 189 | else if( tempType.Is64() ){ | 
|---|
| 190 | //64ビット型 | 
|---|
| 191 |  | 
|---|
| 192 | //pop eax | 
|---|
| 193 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 194 |  | 
|---|
| 195 | //pop ebx | 
|---|
| 196 | compiler.codeGenerator.op_pop(REG_EBX); | 
|---|
| 197 |  | 
|---|
| 198 | //cmp eax,0 | 
|---|
| 199 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 ); | 
|---|
| 200 |  | 
|---|
| 201 | //jne | 
|---|
| 202 | const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); | 
|---|
| 203 |  | 
|---|
| 204 | //cmp ebx,0 | 
|---|
| 205 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EBX, 0 ); | 
|---|
| 206 |  | 
|---|
| 207 | //jne | 
|---|
| 208 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); | 
|---|
| 209 |  | 
|---|
| 210 | //jmp (endif、または else までジャンプ) | 
|---|
| 211 | pIfPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); | 
|---|
| 212 |  | 
|---|
| 213 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 ); | 
|---|
| 214 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 ); | 
|---|
| 215 | } | 
|---|
| 216 | else{ | 
|---|
| 217 | //32ビット型 | 
|---|
| 218 |  | 
|---|
| 219 | //pop eax | 
|---|
| 220 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 221 |  | 
|---|
| 222 | //cmp eax,0 | 
|---|
| 223 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 ); | 
|---|
| 224 |  | 
|---|
| 225 | //je (endif、または else まで条件ジャンプ) | 
|---|
| 226 | pIfPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 |  | 
|---|
| 230 | ///////////////////////// | 
|---|
| 231 | // If内をコード化 | 
|---|
| 232 | ///////////////////////// | 
|---|
| 233 |  | 
|---|
| 234 | //レキシカルスコープをレベルアップ | 
|---|
| 235 | compiler.codeGenerator.lexicalScopes.Start( | 
|---|
| 236 | compiler.codeGenerator.GetNativeCodeSize(), | 
|---|
| 237 | LexicalScope::SCOPE_TYPE_IF | 
|---|
| 238 | ); | 
|---|
| 239 |  | 
|---|
| 240 | i2=CompileBuffer(ESC_ENDIF,0); | 
|---|
| 241 |  | 
|---|
| 242 | //レキシカルスコープをレベルダウン | 
|---|
| 243 | compiler.codeGenerator.lexicalScopes.End(); | 
|---|
| 244 |  | 
|---|
| 245 |  | 
|---|
| 246 | if( pIfPertialSchedule == NULL ) return; | 
|---|
| 247 |  | 
|---|
| 248 | if(i2==ESC_ELSE){ | 
|---|
| 249 | //jmp (endifまで) | 
|---|
| 250 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); | 
|---|
| 251 |  | 
|---|
| 252 | compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule ); | 
|---|
| 253 |  | 
|---|
| 254 |  | 
|---|
| 255 | ///////////////////////// | 
|---|
| 256 | // Else内をコード化 | 
|---|
| 257 | ///////////////////////// | 
|---|
| 258 |  | 
|---|
| 259 | //レキシカルスコープをレベルアップ | 
|---|
| 260 | compiler.codeGenerator.lexicalScopes.Start( | 
|---|
| 261 | compiler.codeGenerator.GetNativeCodeSize(), | 
|---|
| 262 | LexicalScope::SCOPE_TYPE_IF | 
|---|
| 263 | ); | 
|---|
| 264 |  | 
|---|
| 265 | CompileBuffer(ESC_ENDIF,0); | 
|---|
| 266 |  | 
|---|
| 267 | //レキシカルスコープをレベルダウン | 
|---|
| 268 | compiler.codeGenerator.lexicalScopes.End(); | 
|---|
| 269 |  | 
|---|
| 270 |  | 
|---|
| 271 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); | 
|---|
| 272 | } | 
|---|
| 273 | else{ | 
|---|
| 274 | compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule ); | 
|---|
| 275 | } | 
|---|
| 276 | } | 
|---|
| 277 |  | 
|---|
| 278 | int GetLabelAddress(char *LabelName,int LineNum){ | 
|---|
| 279 | if(LabelName){ | 
|---|
| 280 | BOOST_FOREACH( const GotoLabel &label, compiler.codeGenerator.gotoLabels ) | 
|---|
| 281 | { | 
|---|
| 282 | if( label.name.size() > 0 ) | 
|---|
| 283 | { | 
|---|
| 284 | if( label.name == LabelName ) | 
|---|
| 285 | { | 
|---|
| 286 | return label.address; | 
|---|
| 287 | } | 
|---|
| 288 | } | 
|---|
| 289 | } | 
|---|
| 290 | } | 
|---|
| 291 | else{ | 
|---|
| 292 | BOOST_FOREACH( const GotoLabel &label, compiler.codeGenerator.gotoLabels ) | 
|---|
| 293 | { | 
|---|
| 294 | if( label.name.size() == 0 ) | 
|---|
| 295 | { | 
|---|
| 296 | if( label.line == LineNum ) | 
|---|
| 297 | { | 
|---|
| 298 | return label.address; | 
|---|
| 299 | } | 
|---|
| 300 | } | 
|---|
| 301 | } | 
|---|
| 302 | } | 
|---|
| 303 | return -1; | 
|---|
| 304 | } | 
|---|
| 305 | void OpcodeGoto(char *Parameter){ | 
|---|
| 306 | extern HANDLE hHeap; | 
|---|
| 307 | int i,LineNum; | 
|---|
| 308 |  | 
|---|
| 309 | if(Parameter[0]=='*'){ | 
|---|
| 310 | i=GetLabelAddress(Parameter+1,0); | 
|---|
| 311 |  | 
|---|
| 312 | if( i == -1 ) | 
|---|
| 313 | { | 
|---|
| 314 | //jmp ...(schedule) | 
|---|
| 315 | compiler.codeGenerator.op_jmp_goto_schedule( (const std::string)(Parameter + 1), 0, cp ); | 
|---|
| 316 | } | 
|---|
| 317 | else | 
|---|
| 318 | { | 
|---|
| 319 | //jmp ... | 
|---|
| 320 | compiler.codeGenerator.op_jmp( | 
|---|
| 321 | i-compiler.codeGenerator.GetNativeCodeSize(), | 
|---|
| 322 | sizeof(long), | 
|---|
| 323 | false, | 
|---|
| 324 | true | 
|---|
| 325 | ); | 
|---|
| 326 | } | 
|---|
| 327 | } | 
|---|
| 328 | else{ | 
|---|
| 329 | LineNum=atoi(Parameter); | 
|---|
| 330 | i=GetLabelAddress(0,LineNum); | 
|---|
| 331 |  | 
|---|
| 332 | if( i == -1 ) | 
|---|
| 333 | { | 
|---|
| 334 | //jmp ...(schedule) | 
|---|
| 335 | compiler.codeGenerator.op_jmp_goto_schedule( "", LineNum, cp ); | 
|---|
| 336 | } | 
|---|
| 337 | else | 
|---|
| 338 | { | 
|---|
| 339 | //jmp ... | 
|---|
| 340 | compiler.codeGenerator.op_jmp( | 
|---|
| 341 | i-compiler.codeGenerator.GetNativeCodeSize(), | 
|---|
| 342 | sizeof(long), | 
|---|
| 343 | false, | 
|---|
| 344 | true | 
|---|
| 345 | ); | 
|---|
| 346 | } | 
|---|
| 347 | } | 
|---|
| 348 | } | 
|---|
| 349 | void OpcodeWhile(char *Parameter){ | 
|---|
| 350 | extern HANDLE hHeap; | 
|---|
| 351 |  | 
|---|
| 352 | //Continueアドレスのバックアップとセット | 
|---|
| 353 | compiler.codeGenerator.ContinueAreaBegin(); | 
|---|
| 354 |  | 
|---|
| 355 | if(!Parameter[0]) SetError(10,"While",cp); | 
|---|
| 356 |  | 
|---|
| 357 | const PertialSchedule *pWhilePertialSchedule = NULL; | 
|---|
| 358 | Type tempType; | 
|---|
| 359 | if( !NumOpe(Parameter,Type(),tempType) ){ | 
|---|
| 360 | //ダミー | 
|---|
| 361 | } | 
|---|
| 362 | else if( tempType.IsDouble() ){ | 
|---|
| 363 | //fld qword ptr[esp] | 
|---|
| 364 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); | 
|---|
| 365 |  | 
|---|
| 366 | //push 0 | 
|---|
| 367 | compiler.codeGenerator.op_push_V(0); | 
|---|
| 368 |  | 
|---|
| 369 | //fild dword ptr[esp] | 
|---|
| 370 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG); | 
|---|
| 371 |  | 
|---|
| 372 | //add esp,sizeof(double)+sizeof(long) | 
|---|
| 373 | compiler.codeGenerator.op_add_esp(sizeof(double)+sizeof(long)); | 
|---|
| 374 |  | 
|---|
| 375 | //fcompp | 
|---|
| 376 | compiler.codeGenerator.op_fcompp(); | 
|---|
| 377 |  | 
|---|
| 378 | //fnstsw ax | 
|---|
| 379 | compiler.codeGenerator.op_fnstsw_ax(); | 
|---|
| 380 |  | 
|---|
| 381 | //test ah,40 | 
|---|
| 382 | compiler.codeGenerator.op_test_ah( (char)0x40 ); | 
|---|
| 383 |  | 
|---|
| 384 | //jne (Wend まで) | 
|---|
| 385 | pWhilePertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true ); | 
|---|
| 386 | } | 
|---|
| 387 | else if( tempType.IsSingle() ){ | 
|---|
| 388 | //fld dword ptr[esp] | 
|---|
| 389 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); | 
|---|
| 390 |  | 
|---|
| 391 | //push 0 | 
|---|
| 392 | compiler.codeGenerator.op_push_V(0); | 
|---|
| 393 |  | 
|---|
| 394 | //fild dword ptr[esp] | 
|---|
| 395 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG); | 
|---|
| 396 |  | 
|---|
| 397 | //add esp,sizeof(float)+sizeof(long) | 
|---|
| 398 | compiler.codeGenerator.op_add_esp(sizeof(float)+sizeof(long)); | 
|---|
| 399 |  | 
|---|
| 400 | //fcompp | 
|---|
| 401 | compiler.codeGenerator.op_fcompp(); | 
|---|
| 402 |  | 
|---|
| 403 | //fnstsw ax | 
|---|
| 404 | compiler.codeGenerator.op_fnstsw_ax(); | 
|---|
| 405 |  | 
|---|
| 406 | //test ah,40h | 
|---|
| 407 | compiler.codeGenerator.op_test_ah( (char)0x40 ); | 
|---|
| 408 |  | 
|---|
| 409 | //jne (Wend まで) | 
|---|
| 410 | pWhilePertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true ); | 
|---|
| 411 | } | 
|---|
| 412 | else if( tempType.Is64() ){ | 
|---|
| 413 | //64ビット型 | 
|---|
| 414 |  | 
|---|
| 415 | //pop eax | 
|---|
| 416 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 417 |  | 
|---|
| 418 | //pop ebx | 
|---|
| 419 | compiler.codeGenerator.op_pop(REG_EBX); | 
|---|
| 420 |  | 
|---|
| 421 | //cmp eax,0 | 
|---|
| 422 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 ); | 
|---|
| 423 |  | 
|---|
| 424 | //jne | 
|---|
| 425 | const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); | 
|---|
| 426 |  | 
|---|
| 427 | //cmp ebx,0 | 
|---|
| 428 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EBX, 0 ); | 
|---|
| 429 |  | 
|---|
| 430 | //jne | 
|---|
| 431 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); | 
|---|
| 432 |  | 
|---|
| 433 | //jmp (Wendまでジャンプ) | 
|---|
| 434 | pWhilePertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); | 
|---|
| 435 |  | 
|---|
| 436 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 ); | 
|---|
| 437 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 ); | 
|---|
| 438 | } | 
|---|
| 439 | else{ | 
|---|
| 440 | //その他整数型 | 
|---|
| 441 |  | 
|---|
| 442 | //pop eax | 
|---|
| 443 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 444 |  | 
|---|
| 445 | //cmp eax,0 | 
|---|
| 446 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 ); | 
|---|
| 447 |  | 
|---|
| 448 | //je (Wend まで) | 
|---|
| 449 | pWhilePertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); | 
|---|
| 450 | } | 
|---|
| 451 |  | 
|---|
| 452 | //レキシカルスコープをレベルアップ | 
|---|
| 453 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_WHILE ); | 
|---|
| 454 |  | 
|---|
| 455 | //While内をコンパイル | 
|---|
| 456 | CompileBuffer(0,COM_WEND); | 
|---|
| 457 |  | 
|---|
| 458 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd(); | 
|---|
| 459 |  | 
|---|
| 460 | //jmp ... | 
|---|
| 461 | compiler.codeGenerator.op_jmp_continue(); | 
|---|
| 462 |  | 
|---|
| 463 | //レキシカルスコープをレベルダウン | 
|---|
| 464 | compiler.codeGenerator.lexicalScopes.End(); | 
|---|
| 465 |  | 
|---|
| 466 | if( pWhilePertialSchedule ) | 
|---|
| 467 | { | 
|---|
| 468 | compiler.codeGenerator.opfix_JmpPertialSchedule( pWhilePertialSchedule ); | 
|---|
| 469 | } | 
|---|
| 470 |  | 
|---|
| 471 | compiler.codeGenerator.ContinueAreaEnd(); | 
|---|
| 472 | } | 
|---|
| 473 |  | 
|---|
| 474 | char szNextVariable[VN_SIZE]; | 
|---|
| 475 | void OpcodeFor(char *Parameter){ | 
|---|
| 476 | extern HANDLE hHeap; | 
|---|
| 477 | int i,i2; | 
|---|
| 478 | char temporary[VN_SIZE],variable[VN_SIZE],JudgeNum[VN_SIZE],StepNum[VN_SIZE]; | 
|---|
| 479 |  | 
|---|
| 480 | //第1パラメータを取得 | 
|---|
| 481 | i=GetOneParameter(Parameter,0,temporary); | 
|---|
| 482 | if(!Parameter[i]){ | 
|---|
| 483 | SetError(12,"For",cp); | 
|---|
| 484 | goto ErrorStep; | 
|---|
| 485 | } | 
|---|
| 486 |  | 
|---|
| 487 | for(i2=0;;i2++){ | 
|---|
| 488 | if(temporary[i2]=='='){ | 
|---|
| 489 | variable[i2]=0; | 
|---|
| 490 |  | 
|---|
| 491 | //カウンタ初期化 | 
|---|
| 492 | OpcodeCalc(temporary); | 
|---|
| 493 | break; | 
|---|
| 494 | } | 
|---|
| 495 | if(temporary[i2]=='\0'){ | 
|---|
| 496 | SetError(12,"For",cp); | 
|---|
| 497 | goto ErrorStep; | 
|---|
| 498 | } | 
|---|
| 499 | variable[i2]=temporary[i2]; | 
|---|
| 500 | } | 
|---|
| 501 |  | 
|---|
| 502 | //jmp ... | 
|---|
| 503 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); | 
|---|
| 504 |  | 
|---|
| 505 | //Continueアドレスのバックアップとセット | 
|---|
| 506 | compiler.codeGenerator.ContinueAreaBegin(); | 
|---|
| 507 |  | 
|---|
| 508 | //第2パラメータを取得(to~) | 
|---|
| 509 | i=GetOneParameter(Parameter,i,JudgeNum); | 
|---|
| 510 |  | 
|---|
| 511 | //第3パラメータを取得(step~) | 
|---|
| 512 | if(Parameter[i]){ | 
|---|
| 513 | i=GetOneParameter(Parameter,i,StepNum); | 
|---|
| 514 | if(Parameter[i]) SetError(12,"For",cp); | 
|---|
| 515 | } | 
|---|
| 516 | else lstrcpy(StepNum,"1"); | 
|---|
| 517 |  | 
|---|
| 518 | //カウンタを増加させる | 
|---|
| 519 | sprintf(temporary,"%s=(%s)+(%s)",variable,variable,StepNum); | 
|---|
| 520 | OpcodeCalc(temporary); | 
|---|
| 521 |  | 
|---|
| 522 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); | 
|---|
| 523 |  | 
|---|
| 524 | //増加か減少かを区別する | 
|---|
| 525 | sprintf(temporary,"(%s)>=0",StepNum); | 
|---|
| 526 | NumOpe(temporary,Type(),Type()); | 
|---|
| 527 |  | 
|---|
| 528 | //pop eax | 
|---|
| 529 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 530 |  | 
|---|
| 531 | //cmp eax,0 | 
|---|
| 532 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 ); | 
|---|
| 533 |  | 
|---|
| 534 | //je [カウンタ減少の場合の判定] | 
|---|
| 535 | pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); | 
|---|
| 536 |  | 
|---|
| 537 | //判定(カウンタ増加の場合) | 
|---|
| 538 | sprintf(temporary,"%s<=(%s)",variable,JudgeNum); | 
|---|
| 539 | NumOpe(temporary,Type(),Type()); | 
|---|
| 540 |  | 
|---|
| 541 | //pop eax | 
|---|
| 542 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 543 |  | 
|---|
| 544 | //jmp [カウンタ減少の場合の判定を飛び越す] | 
|---|
| 545 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); | 
|---|
| 546 |  | 
|---|
| 547 | //jeジャンプ先のオフセット値 | 
|---|
| 548 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); | 
|---|
| 549 |  | 
|---|
| 550 | //判定(カウンタ減少の場合) | 
|---|
| 551 | sprintf(temporary,"%s>=(%s)",variable,JudgeNum); | 
|---|
| 552 | NumOpe(temporary,Type(),Type()); | 
|---|
| 553 |  | 
|---|
| 554 | //pop eax | 
|---|
| 555 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 556 |  | 
|---|
| 557 | //jmpジャンプ先のオフセット値 | 
|---|
| 558 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 ); | 
|---|
| 559 |  | 
|---|
| 560 | //cmp eax,0 | 
|---|
| 561 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 ); | 
|---|
| 562 |  | 
|---|
| 563 | ErrorStep: | 
|---|
| 564 |  | 
|---|
| 565 | //je ... | 
|---|
| 566 | pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); | 
|---|
| 567 |  | 
|---|
| 568 | //レキシカルスコープをレベルアップ | 
|---|
| 569 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_FOR ); | 
|---|
| 570 |  | 
|---|
| 571 | //For内をコンパイル | 
|---|
| 572 | CompileBuffer(0,COM_NEXT); | 
|---|
| 573 |  | 
|---|
| 574 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd(); | 
|---|
| 575 |  | 
|---|
| 576 | if(szNextVariable[0]){ | 
|---|
| 577 | if(lstrcmp(szNextVariable,variable)!=0){ | 
|---|
| 578 | SetError(55,szNextVariable,cp); | 
|---|
| 579 | } | 
|---|
| 580 | } | 
|---|
| 581 |  | 
|---|
| 582 | //jmp ... | 
|---|
| 583 | compiler.codeGenerator.op_jmp_continue(); | 
|---|
| 584 |  | 
|---|
| 585 | //レキシカルスコープをレベルダウン | 
|---|
| 586 | compiler.codeGenerator.lexicalScopes.End(); | 
|---|
| 587 |  | 
|---|
| 588 | //jeジャンプ先のオフセット値 | 
|---|
| 589 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); | 
|---|
| 590 |  | 
|---|
| 591 | //Continueアドレスを復元 | 
|---|
| 592 | compiler.codeGenerator.ContinueAreaEnd(); | 
|---|
| 593 | } | 
|---|
| 594 |  | 
|---|
| 595 | void OpcodeForeach( const char *Parameter ) | 
|---|
| 596 | { | 
|---|
| 597 | Type resultType; | 
|---|
| 598 | int i; | 
|---|
| 599 | char temporary[VN_SIZE],variable[VN_SIZE],collectionVar[VN_SIZE]; | 
|---|
| 600 | bool isError = false; | 
|---|
| 601 |  | 
|---|
| 602 | //第1パラメータを取得 | 
|---|
| 603 | i=GetOneParameter(Parameter,0,temporary); | 
|---|
| 604 | if(!Parameter[i]){ | 
|---|
| 605 | SetError(12,"Foreach",cp); | 
|---|
| 606 | isError = true; | 
|---|
| 607 | goto ErrorStep; | 
|---|
| 608 | } | 
|---|
| 609 |  | 
|---|
| 610 | lstrcpy( variable, temporary ); | 
|---|
| 611 |  | 
|---|
| 612 | //第2パラメータを取得(in~) | 
|---|
| 613 | i=GetOneParameter(Parameter,i,collectionVar); | 
|---|
| 614 |  | 
|---|
| 615 | // Resetメソッドを呼び出す | 
|---|
| 616 | sprintf( temporary, "%s.Reset()", collectionVar ); | 
|---|
| 617 | Compile( temporary ); | 
|---|
| 618 |  | 
|---|
| 619 | //Continueアドレスのバックアップとセット | 
|---|
| 620 | compiler.codeGenerator.ContinueAreaBegin(); | 
|---|
| 621 |  | 
|---|
| 622 | // MoveNextメソッドを呼び出す | 
|---|
| 623 | sprintf( temporary, "%s.MoveNext()", collectionVar ); | 
|---|
| 624 | NumOpe(temporary,Type(),Type()); | 
|---|
| 625 |  | 
|---|
| 626 | //pop eax | 
|---|
| 627 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 628 |  | 
|---|
| 629 | //cmp eax,0 | 
|---|
| 630 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 ); | 
|---|
| 631 |  | 
|---|
| 632 | ErrorStep: | 
|---|
| 633 |  | 
|---|
| 634 | //je ... | 
|---|
| 635 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true ); | 
|---|
| 636 |  | 
|---|
| 637 | //レキシカルスコープをレベルアップ | 
|---|
| 638 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_FOR ); | 
|---|
| 639 |  | 
|---|
| 640 | // Currentプロパティから現在の値を取得 | 
|---|
| 641 | // TODO: 型指定が未完成 | 
|---|
| 642 | sprintf( temporary, "%s=%s.Current As String", variable, collectionVar ); | 
|---|
| 643 | Compile( temporary ); | 
|---|
| 644 |  | 
|---|
| 645 | //For内をコンパイル | 
|---|
| 646 | CompileBuffer(0,COM_NEXT); | 
|---|
| 647 |  | 
|---|
| 648 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd(); | 
|---|
| 649 |  | 
|---|
| 650 | if(szNextVariable[0]){ | 
|---|
| 651 | if(lstrcmp(szNextVariable,variable)!=0){ | 
|---|
| 652 | SetError(55,szNextVariable,cp); | 
|---|
| 653 | } | 
|---|
| 654 | } | 
|---|
| 655 |  | 
|---|
| 656 | //jmp ... | 
|---|
| 657 | compiler.codeGenerator.op_jmp_continue(); | 
|---|
| 658 |  | 
|---|
| 659 | //レキシカルスコープをレベルダウン | 
|---|
| 660 | compiler.codeGenerator.lexicalScopes.End(); | 
|---|
| 661 |  | 
|---|
| 662 | //jeジャンプ先のオフセット値 | 
|---|
| 663 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); | 
|---|
| 664 |  | 
|---|
| 665 | //Continueアドレスを復元 | 
|---|
| 666 | compiler.codeGenerator.ContinueAreaEnd(); | 
|---|
| 667 | } | 
|---|
| 668 |  | 
|---|
| 669 | void OpcodeDo(char *Parameter){ | 
|---|
| 670 | extern HANDLE hHeap; | 
|---|
| 671 | int i,i2,i3; | 
|---|
| 672 |  | 
|---|
| 673 | if(Parameter[0]) SetError(10,"Do",cp); | 
|---|
| 674 |  | 
|---|
| 675 | //Continueアドレスのバックアップとセット | 
|---|
| 676 | compiler.codeGenerator.ContinueAreaBegin(); | 
|---|
| 677 |  | 
|---|
| 678 | //レキシカルスコープをレベルアップ | 
|---|
| 679 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_DO ); | 
|---|
| 680 |  | 
|---|
| 681 | //Do内をコンパイル | 
|---|
| 682 | CompileBuffer(0,COM_LOOP); | 
|---|
| 683 |  | 
|---|
| 684 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd(); | 
|---|
| 685 |  | 
|---|
| 686 | const PertialSchedule *pDoPertialSchedule = NULL; | 
|---|
| 687 |  | 
|---|
| 688 | extern char *basbuf; | 
|---|
| 689 | char temporary[VN_SIZE]; | 
|---|
| 690 | for(i=cp-1;;i--){ | 
|---|
| 691 | if(IsCommandDelimitation(basbuf[i])){ | 
|---|
| 692 | i+=3; | 
|---|
| 693 | if(!(basbuf[i]=='0'||basbuf[i]=='1')){ | 
|---|
| 694 | //無条件ループ | 
|---|
| 695 | break; | 
|---|
| 696 | } | 
|---|
| 697 | i3=i; | 
|---|
| 698 |  | 
|---|
| 699 | for(i+=2,i2=0;;i++,i2++){ | 
|---|
| 700 | if(IsCommandDelimitation(basbuf[i])){ | 
|---|
| 701 | temporary[i2]=0; | 
|---|
| 702 | break; | 
|---|
| 703 | } | 
|---|
| 704 | temporary[i2]=basbuf[i]; | 
|---|
| 705 | } | 
|---|
| 706 |  | 
|---|
| 707 | Type tempType; | 
|---|
| 708 | NumOpe(temporary,Type(),tempType); | 
|---|
| 709 |  | 
|---|
| 710 | if( tempType.IsDouble() ){ | 
|---|
| 711 | //fld qword ptr[esp] | 
|---|
| 712 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); | 
|---|
| 713 |  | 
|---|
| 714 | //push 0 | 
|---|
| 715 | compiler.codeGenerator.op_push_V(0); | 
|---|
| 716 |  | 
|---|
| 717 | //fild dword ptr[esp] | 
|---|
| 718 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG); | 
|---|
| 719 |  | 
|---|
| 720 | //add esp,sizeof(double)+sizeof(long) | 
|---|
| 721 | compiler.codeGenerator.op_add_esp(sizeof(double)+sizeof(long)); | 
|---|
| 722 |  | 
|---|
| 723 | //fcompp | 
|---|
| 724 | compiler.codeGenerator.op_fcompp(); | 
|---|
| 725 |  | 
|---|
| 726 | //fnstsw ax | 
|---|
| 727 | compiler.codeGenerator.op_fnstsw_ax(); | 
|---|
| 728 |  | 
|---|
| 729 | //test ah,40 | 
|---|
| 730 | compiler.codeGenerator.op_test_ah( (char)0x40 ); | 
|---|
| 731 |  | 
|---|
| 732 | if(basbuf[i3]=='0'){ | 
|---|
| 733 | //While | 
|---|
| 734 |  | 
|---|
| 735 | //jne 5(ループ終了) | 
|---|
| 736 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); | 
|---|
| 737 | } | 
|---|
| 738 | else if(basbuf[i3]=='1'){ | 
|---|
| 739 | //Until | 
|---|
| 740 |  | 
|---|
| 741 | //je 5(ループ終了) | 
|---|
| 742 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true ); | 
|---|
| 743 | } | 
|---|
| 744 | } | 
|---|
| 745 | else if( tempType.IsSingle() ){ | 
|---|
| 746 | //fld dword ptr[esp] | 
|---|
| 747 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); | 
|---|
| 748 |  | 
|---|
| 749 | //push 0 | 
|---|
| 750 | compiler.codeGenerator.op_push_V(0); | 
|---|
| 751 |  | 
|---|
| 752 | //fild dword ptr[esp] | 
|---|
| 753 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG); | 
|---|
| 754 |  | 
|---|
| 755 | //add esp,sizeof(float)+sizeof(long) | 
|---|
| 756 | compiler.codeGenerator.op_add_esp(sizeof(float)+sizeof(long)); | 
|---|
| 757 |  | 
|---|
| 758 | //fcompp | 
|---|
| 759 | compiler.codeGenerator.op_fcompp(); | 
|---|
| 760 |  | 
|---|
| 761 | //fnstsw ax | 
|---|
| 762 | compiler.codeGenerator.op_fnstsw_ax(); | 
|---|
| 763 |  | 
|---|
| 764 | //test ah,40 | 
|---|
| 765 | compiler.codeGenerator.op_test_ah( (char)0x40 ); | 
|---|
| 766 |  | 
|---|
| 767 | if(basbuf[i3]=='0'){ | 
|---|
| 768 | //While | 
|---|
| 769 |  | 
|---|
| 770 | //jne 5(ループ終了) | 
|---|
| 771 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); | 
|---|
| 772 | } | 
|---|
| 773 | else if(basbuf[i3]=='1'){ | 
|---|
| 774 | //Until | 
|---|
| 775 |  | 
|---|
| 776 | //je 5(ループ終了) | 
|---|
| 777 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true ); | 
|---|
| 778 | } | 
|---|
| 779 | } | 
|---|
| 780 | else if( tempType.Is64() ){ | 
|---|
| 781 | //64ビット型 | 
|---|
| 782 |  | 
|---|
| 783 | //pop eax | 
|---|
| 784 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 785 |  | 
|---|
| 786 | //pop ebx | 
|---|
| 787 | compiler.codeGenerator.op_pop(REG_EBX); | 
|---|
| 788 |  | 
|---|
| 789 | //cmp eax,0 | 
|---|
| 790 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 ); | 
|---|
| 791 |  | 
|---|
| 792 | //jne | 
|---|
| 793 | const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); | 
|---|
| 794 |  | 
|---|
| 795 | //cmp ebx,0 | 
|---|
| 796 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EBX, 0 ); | 
|---|
| 797 |  | 
|---|
| 798 | //jne | 
|---|
| 799 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); | 
|---|
| 800 |  | 
|---|
| 801 | if(basbuf[i3]=='0'){ | 
|---|
| 802 | //While | 
|---|
| 803 |  | 
|---|
| 804 | //jmp 5(ループ終了) | 
|---|
| 805 | pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true ); | 
|---|
| 806 |  | 
|---|
| 807 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 ); | 
|---|
| 808 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 ); | 
|---|
| 809 | } | 
|---|
| 810 | else if(basbuf[i3]=='1'){ | 
|---|
| 811 | //Until | 
|---|
| 812 |  | 
|---|
| 813 | //jmp 2(ループを続ける) | 
|---|
| 814 | const PertialSchedule *pTempPertialSchedule3 = compiler.codeGenerator.op_jmp( 0, sizeof(char), true ); | 
|---|
| 815 |  | 
|---|
| 816 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 ); | 
|---|
| 817 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 ); | 
|---|
| 818 |  | 
|---|
| 819 | //jmp 5(ループ終了) | 
|---|
| 820 | pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true ); | 
|---|
| 821 |  | 
|---|
| 822 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule3 ); | 
|---|
| 823 | } | 
|---|
| 824 | } | 
|---|
| 825 | else{ | 
|---|
| 826 | //pop eax | 
|---|
| 827 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 828 |  | 
|---|
| 829 | //cmp eax,0 | 
|---|
| 830 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 ); | 
|---|
| 831 |  | 
|---|
| 832 | if(basbuf[i3]=='0'){ | 
|---|
| 833 | //While | 
|---|
| 834 |  | 
|---|
| 835 | //je 5(ループ終了) | 
|---|
| 836 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true ); | 
|---|
| 837 | } | 
|---|
| 838 | else if(basbuf[i3]=='1'){ | 
|---|
| 839 | //Until | 
|---|
| 840 |  | 
|---|
| 841 | //jne 5(ループ終了) | 
|---|
| 842 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true ); | 
|---|
| 843 | } | 
|---|
| 844 | } | 
|---|
| 845 | break; | 
|---|
| 846 | } | 
|---|
| 847 | } | 
|---|
| 848 |  | 
|---|
| 849 | //jmp ... | 
|---|
| 850 | compiler.codeGenerator.op_jmp_continue(); | 
|---|
| 851 |  | 
|---|
| 852 | if( pDoPertialSchedule ) | 
|---|
| 853 | { | 
|---|
| 854 | compiler.codeGenerator.opfix_JmpPertialSchedule( pDoPertialSchedule ); | 
|---|
| 855 | } | 
|---|
| 856 |  | 
|---|
| 857 | //jmp ... | 
|---|
| 858 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true ); | 
|---|
| 859 |  | 
|---|
| 860 | //レキシカルスコープをレベルダウン | 
|---|
| 861 | compiler.codeGenerator.lexicalScopes.End(); | 
|---|
| 862 |  | 
|---|
| 863 | //jmpジャンプ先のオフセット値 | 
|---|
| 864 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule ); | 
|---|
| 865 |  | 
|---|
| 866 | //Continueアドレスを復元 | 
|---|
| 867 | compiler.codeGenerator.ContinueAreaEnd(); | 
|---|
| 868 | } | 
|---|
| 869 | void OpcodeContinue(void){ | 
|---|
| 870 | //jmp ...(Continue addr) | 
|---|
| 871 | compiler.codeGenerator.op_jmp_continue(); | 
|---|
| 872 | } | 
|---|
| 873 |  | 
|---|
| 874 | void OpcodeExitSub(void){ | 
|---|
| 875 | if( UserProc::IsGlobalAreaCompiling() ){ | 
|---|
| 876 | SetError(12,"Exit Sub/Function",cp); | 
|---|
| 877 | return; | 
|---|
| 878 | } | 
|---|
| 879 |  | 
|---|
| 880 | //未解放のローカルオブジェクトのデストラクタを呼び出す | 
|---|
| 881 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfReturn(); | 
|---|
| 882 |  | 
|---|
| 883 | //jmp ...(End Sub/Function) | 
|---|
| 884 | compiler.codeGenerator.op_jmp_exitsub(); | 
|---|
| 885 | } | 
|---|
| 886 |  | 
|---|
| 887 | //Caseスケジュール | 
|---|
| 888 | class SelectSchedule | 
|---|
| 889 | { | 
|---|
| 890 | public: | 
|---|
| 891 | SelectSchedule( int typeSize ) | 
|---|
| 892 | : typeSize( typeSize ) | 
|---|
| 893 | , nowCaseSchedule( 0 ) | 
|---|
| 894 | { | 
|---|
| 895 | } | 
|---|
| 896 |  | 
|---|
| 897 | PertialSchedules casePertialSchedules; | 
|---|
| 898 | int typeSize; | 
|---|
| 899 | int nowCaseSchedule; | 
|---|
| 900 | }; | 
|---|
| 901 | std::vector<SelectSchedule> selectSchedules; | 
|---|
| 902 |  | 
|---|
| 903 | void OpcodeSelect(const char *lpszParms){ | 
|---|
| 904 | extern HANDLE hHeap; | 
|---|
| 905 | extern char *basbuf; | 
|---|
| 906 | int i,i2,i3,sw,NowCaseCp; | 
|---|
| 907 | char temporary[VN_SIZE]; | 
|---|
| 908 |  | 
|---|
| 909 | Type type1; | 
|---|
| 910 | if( !NumOpe(lpszParms,Type(), type1 ) ){ | 
|---|
| 911 | return; | 
|---|
| 912 | } | 
|---|
| 913 |  | 
|---|
| 914 | selectSchedules.push_back( SelectSchedule( type1.GetSize() ) ); | 
|---|
| 915 |  | 
|---|
| 916 | if( selectSchedules.back().typeSize < sizeof(long) ){ | 
|---|
| 917 | selectSchedules.back().typeSize = sizeof(long); | 
|---|
| 918 | } | 
|---|
| 919 |  | 
|---|
| 920 | for(i=cp,sw=0;;i++){ | 
|---|
| 921 | if(basbuf[i]=='\0'){ | 
|---|
| 922 | selectSchedules.pop_back(); | 
|---|
| 923 | SetError(22,"Select",cp); | 
|---|
| 924 | return; | 
|---|
| 925 | } | 
|---|
| 926 | if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE){ | 
|---|
| 927 | for(i2=0;;i++){ | 
|---|
| 928 | if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE) i2++; | 
|---|
| 929 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){ | 
|---|
| 930 | i2--; | 
|---|
| 931 | if(i2==0) break; | 
|---|
| 932 | } | 
|---|
| 933 | } | 
|---|
| 934 | continue; | 
|---|
| 935 | } | 
|---|
| 936 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){ | 
|---|
| 937 | if(sw==0){ | 
|---|
| 938 | //add esp,CaseTypeSize | 
|---|
| 939 | compiler.codeGenerator.op_add_esp( selectSchedules.back().typeSize ); | 
|---|
| 940 | } | 
|---|
| 941 | break; | 
|---|
| 942 | } | 
|---|
| 943 | if(basbuf[i]==1&&basbuf[i+1]==ESC_CASE){ | 
|---|
| 944 | NowCaseCp=i; | 
|---|
| 945 |  | 
|---|
| 946 | i++; | 
|---|
| 947 | while(1){ | 
|---|
| 948 | for(i++,i2=0;;i++,i2++){ | 
|---|
| 949 | if(basbuf[i]=='\"'){ | 
|---|
| 950 | i3=GetStringInQuotation(temporary+i2,basbuf+i); | 
|---|
| 951 | i+=i3-1; | 
|---|
| 952 | i2+=i3-1; | 
|---|
| 953 | continue; | 
|---|
| 954 | } | 
|---|
| 955 | if(basbuf[i]=='('){ | 
|---|
| 956 | i3=GetStringInPare(temporary+i2,basbuf+i); | 
|---|
| 957 | i+=i3-1; | 
|---|
| 958 | i2+=i3-1; | 
|---|
| 959 | continue; | 
|---|
| 960 | } | 
|---|
| 961 | if(basbuf[i]=='['){ | 
|---|
| 962 | i3=GetStringInBracket(temporary+i2,basbuf+i); | 
|---|
| 963 | i+=i3-1; | 
|---|
| 964 | i2+=i3-1; | 
|---|
| 965 | continue; | 
|---|
| 966 | } | 
|---|
| 967 |  | 
|---|
| 968 | if(IsCommandDelimitation(basbuf[i])){ | 
|---|
| 969 | temporary[i2]=0; | 
|---|
| 970 | break; | 
|---|
| 971 | } | 
|---|
| 972 | if(basbuf[i]==','){ | 
|---|
| 973 | temporary[i2]=0; | 
|---|
| 974 | break; | 
|---|
| 975 | } | 
|---|
| 976 |  | 
|---|
| 977 | temporary[i2]=basbuf[i]; | 
|---|
| 978 | } | 
|---|
| 979 |  | 
|---|
| 980 | //エラー用 | 
|---|
| 981 | i2=cp; | 
|---|
| 982 | cp=NowCaseCp; | 
|---|
| 983 |  | 
|---|
| 984 | Type type2; | 
|---|
| 985 | if( !NumOpe(temporary,type1,type2) ){ | 
|---|
| 986 | return; | 
|---|
| 987 | } | 
|---|
| 988 |  | 
|---|
| 989 | cp=i2; | 
|---|
| 990 |  | 
|---|
| 991 | if(type1.IsObject()){ | 
|---|
| 992 | std::vector<const UserProc *> subs; | 
|---|
| 993 | type1.GetClass().GetDynamicMethods().Enum( CALC_EQUAL, subs ); | 
|---|
| 994 | if( subs.size() == 0 ){ | 
|---|
| 995 | return; | 
|---|
| 996 | } | 
|---|
| 997 |  | 
|---|
| 998 | Parameters params; | 
|---|
| 999 | params.push_back( new Parameter( "", Type( type2 ) ) ); | 
|---|
| 1000 |  | 
|---|
| 1001 | //オーバーロードを解決 | 
|---|
| 1002 | const UserProc *pUserProc = OverloadSolution("==",subs, params, NULL); | 
|---|
| 1003 |  | 
|---|
| 1004 | delete params[0]; | 
|---|
| 1005 |  | 
|---|
| 1006 | if(!pUserProc){ | 
|---|
| 1007 | //エラー | 
|---|
| 1008 | return; | 
|---|
| 1009 | } | 
|---|
| 1010 |  | 
|---|
| 1011 |  | 
|---|
| 1012 | //pop edx | 
|---|
| 1013 | compiler.codeGenerator.op_pop(REG_EDX); | 
|---|
| 1014 |  | 
|---|
| 1015 | //mov ecx,dword ptr[esp] | 
|---|
| 1016 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_ESP,0,MOD_BASE); | 
|---|
| 1017 |  | 
|---|
| 1018 | //push edx | 
|---|
| 1019 | compiler.codeGenerator.op_push(REG_EDX); | 
|---|
| 1020 |  | 
|---|
| 1021 | //push ecx | 
|---|
| 1022 | compiler.codeGenerator.op_push(REG_ECX); | 
|---|
| 1023 |  | 
|---|
| 1024 | //call operator_proc    ※ ==演算子 | 
|---|
| 1025 | compiler.codeGenerator.op_call(pUserProc); | 
|---|
| 1026 |  | 
|---|
| 1027 | //test eax,eax | 
|---|
| 1028 | compiler.codeGenerator.op_test(REG_EAX,REG_EAX); | 
|---|
| 1029 |  | 
|---|
| 1030 | //jne ... | 
|---|
| 1031 | selectSchedules.back().casePertialSchedules.push_back( | 
|---|
| 1032 | compiler.codeGenerator.op_jne( 0, sizeof(long), true ) | 
|---|
| 1033 | ); | 
|---|
| 1034 | } | 
|---|
| 1035 | else if(type1.IsDouble()){ | 
|---|
| 1036 | ChangeTypeToDouble(type2.GetBasicType()); | 
|---|
| 1037 |  | 
|---|
| 1038 | //fld qword ptr[esp] | 
|---|
| 1039 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); | 
|---|
| 1040 |  | 
|---|
| 1041 | //add esp,CaseTypeSize | 
|---|
| 1042 | compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); | 
|---|
| 1043 |  | 
|---|
| 1044 | //fld qword ptr[esp] | 
|---|
| 1045 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); | 
|---|
| 1046 |  | 
|---|
| 1047 | //fcompp | 
|---|
| 1048 | compiler.codeGenerator.op_fcompp(); | 
|---|
| 1049 |  | 
|---|
| 1050 | //fnstsw ax | 
|---|
| 1051 | compiler.codeGenerator.op_fnstsw_ax(); | 
|---|
| 1052 |  | 
|---|
| 1053 | //test ah,40 | 
|---|
| 1054 | compiler.codeGenerator.op_test_ah( (char)0x40 ); | 
|---|
| 1055 |  | 
|---|
| 1056 | //jne ... | 
|---|
| 1057 | selectSchedules.back().casePertialSchedules.push_back( | 
|---|
| 1058 | compiler.codeGenerator.op_jne( 0, sizeof(long), true ) | 
|---|
| 1059 | ); | 
|---|
| 1060 | } | 
|---|
| 1061 | else if(type1.IsSingle()){ | 
|---|
| 1062 | ChangeTypeToSingle(type2.GetBasicType()); | 
|---|
| 1063 |  | 
|---|
| 1064 | //fld dword ptr[esp] | 
|---|
| 1065 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); | 
|---|
| 1066 |  | 
|---|
| 1067 | //add esp,CaseTypeSize | 
|---|
| 1068 | compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); | 
|---|
| 1069 |  | 
|---|
| 1070 | //fld dword ptr[esp] | 
|---|
| 1071 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); | 
|---|
| 1072 |  | 
|---|
| 1073 | //fcompp | 
|---|
| 1074 | compiler.codeGenerator.op_fcompp(); | 
|---|
| 1075 |  | 
|---|
| 1076 | //fnstsw ax | 
|---|
| 1077 | compiler.codeGenerator.op_fnstsw_ax(); | 
|---|
| 1078 |  | 
|---|
| 1079 | //test ah,40 | 
|---|
| 1080 | compiler.codeGenerator.op_test_ah( (char)0x40 ); | 
|---|
| 1081 |  | 
|---|
| 1082 | //jne ... | 
|---|
| 1083 | selectSchedules.back().casePertialSchedules.push_back( | 
|---|
| 1084 | compiler.codeGenerator.op_jne( 0, sizeof(long), true ) | 
|---|
| 1085 | ); | 
|---|
| 1086 | } | 
|---|
| 1087 | else{ | 
|---|
| 1088 | //その他整数型 | 
|---|
| 1089 |  | 
|---|
| 1090 | //pop ebx | 
|---|
| 1091 | compiler.codeGenerator.op_pop(REG_EBX); | 
|---|
| 1092 |  | 
|---|
| 1093 | //mov eax,dword ptr[esp] | 
|---|
| 1094 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE ); | 
|---|
| 1095 |  | 
|---|
| 1096 | //cmp eax,ebx | 
|---|
| 1097 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX ); | 
|---|
| 1098 |  | 
|---|
| 1099 | //je ... | 
|---|
| 1100 | selectSchedules.back().casePertialSchedules.push_back( | 
|---|
| 1101 | compiler.codeGenerator.op_je( 0, sizeof(long), true ) | 
|---|
| 1102 | ); | 
|---|
| 1103 | } | 
|---|
| 1104 |  | 
|---|
| 1105 | if(basbuf[i]!=',') break; | 
|---|
| 1106 | } | 
|---|
| 1107 | } | 
|---|
| 1108 | if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){ | 
|---|
| 1109 | sw=1; | 
|---|
| 1110 |  | 
|---|
| 1111 | //jmp ... | 
|---|
| 1112 | selectSchedules.back().casePertialSchedules.push_back( | 
|---|
| 1113 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) | 
|---|
| 1114 | ); | 
|---|
| 1115 | } | 
|---|
| 1116 | } | 
|---|
| 1117 |  | 
|---|
| 1118 | //レキシカルスコープをレベルアップ | 
|---|
| 1119 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_SELECT ); | 
|---|
| 1120 |  | 
|---|
| 1121 | //Select Case内をコンパイル | 
|---|
| 1122 | CompileBuffer(ESC_ENDSELECT,0); | 
|---|
| 1123 |  | 
|---|
| 1124 | //jmp EndSelect | 
|---|
| 1125 | selectSchedules.back().casePertialSchedules.push_back( | 
|---|
| 1126 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) | 
|---|
| 1127 | ); | 
|---|
| 1128 |  | 
|---|
| 1129 | //最終スケジュール | 
|---|
| 1130 | for(i=selectSchedules.back().nowCaseSchedule;i<(int)selectSchedules.back().casePertialSchedules.size();i++){ | 
|---|
| 1131 | compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[i] ); | 
|---|
| 1132 | } | 
|---|
| 1133 |  | 
|---|
| 1134 | //レキシカルスコープをレベルダウン | 
|---|
| 1135 | compiler.codeGenerator.lexicalScopes.End(); | 
|---|
| 1136 |  | 
|---|
| 1137 | selectSchedules.pop_back(); | 
|---|
| 1138 | } | 
|---|
| 1139 | void OpcodeCase(char *Parameter){ | 
|---|
| 1140 | int i; | 
|---|
| 1141 |  | 
|---|
| 1142 | if(selectSchedules.back().typeSize==-1){ | 
|---|
| 1143 | SetError(30,"Case",cp); | 
|---|
| 1144 | return; | 
|---|
| 1145 | } | 
|---|
| 1146 |  | 
|---|
| 1147 | //jmp EndSelect | 
|---|
| 1148 | selectSchedules.back().casePertialSchedules.push_back( | 
|---|
| 1149 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) | 
|---|
| 1150 | ); | 
|---|
| 1151 |  | 
|---|
| 1152 | i=0; | 
|---|
| 1153 | while(1){ | 
|---|
| 1154 | //Caseスケジュール | 
|---|
| 1155 | compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[selectSchedules.back().nowCaseSchedule] ); | 
|---|
| 1156 | selectSchedules.back().nowCaseSchedule++; | 
|---|
| 1157 |  | 
|---|
| 1158 | i=JumpOneParameter(Parameter,i); | 
|---|
| 1159 | if(Parameter[i]=='\0') break; | 
|---|
| 1160 | } | 
|---|
| 1161 |  | 
|---|
| 1162 | //add esp,CaseTypeSize | 
|---|
| 1163 | compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); | 
|---|
| 1164 | } | 
|---|
| 1165 |  | 
|---|
| 1166 | void OpcodeGosub(char *Parameter){ | 
|---|
| 1167 | extern HANDLE hHeap; | 
|---|
| 1168 | int i,LineNum; | 
|---|
| 1169 |  | 
|---|
| 1170 | if(Parameter[0]=='*'){ | 
|---|
| 1171 | i=GetLabelAddress(Parameter+1,0); | 
|---|
| 1172 |  | 
|---|
| 1173 | if( i == -1 ) | 
|---|
| 1174 | { | 
|---|
| 1175 | //jmp ...(schedule) | 
|---|
| 1176 | compiler.codeGenerator.op_jmp_goto_schedule( (const std::string)(Parameter + 1), 0, cp ); | 
|---|
| 1177 | } | 
|---|
| 1178 | else | 
|---|
| 1179 | { | 
|---|
| 1180 | //jmp ... | 
|---|
| 1181 | compiler.codeGenerator.op_jmp( | 
|---|
| 1182 | i-compiler.codeGenerator.GetNativeCodeSize(), | 
|---|
| 1183 | sizeof(long), | 
|---|
| 1184 | false, | 
|---|
| 1185 | true | 
|---|
| 1186 | ); | 
|---|
| 1187 | } | 
|---|
| 1188 | } | 
|---|
| 1189 | else{ | 
|---|
| 1190 | LineNum=atoi(Parameter); | 
|---|
| 1191 | i=GetLabelAddress(0,LineNum); | 
|---|
| 1192 |  | 
|---|
| 1193 | if( i == -1 ) | 
|---|
| 1194 | { | 
|---|
| 1195 | //jmp ...(schedule) | 
|---|
| 1196 | compiler.codeGenerator.op_jmp_goto_schedule( "", LineNum, cp ); | 
|---|
| 1197 | } | 
|---|
| 1198 | else | 
|---|
| 1199 | { | 
|---|
| 1200 | //jmp ... | 
|---|
| 1201 | compiler.codeGenerator.op_jmp( | 
|---|
| 1202 | i-compiler.codeGenerator.GetNativeCodeSize(), | 
|---|
| 1203 | sizeof(long), | 
|---|
| 1204 | false, | 
|---|
| 1205 | true | 
|---|
| 1206 | ); | 
|---|
| 1207 | } | 
|---|
| 1208 | } | 
|---|
| 1209 | } | 
|---|
| 1210 | void OpcodeReturn(char *Parameter){ | 
|---|
| 1211 | if( UserProc::IsGlobalAreaCompiling() ){ | 
|---|
| 1212 | //Gosub~Returnとして扱う | 
|---|
| 1213 |  | 
|---|
| 1214 | //ret | 
|---|
| 1215 | compiler.codeGenerator.op_ret(); | 
|---|
| 1216 | } | 
|---|
| 1217 | else{ | 
|---|
| 1218 | //戻り値をセット | 
|---|
| 1219 | if(Parameter[0]){ | 
|---|
| 1220 | const UserProc &proc = UserProc::CompilingUserProc(); | 
|---|
| 1221 |  | 
|---|
| 1222 | const char *temp = "_System_ReturnValue"; | 
|---|
| 1223 | if(proc.GetName()[0]==1&&proc.GetName()[1]==ESC_OPERATOR) | 
|---|
| 1224 | { | 
|---|
| 1225 | } | 
|---|
| 1226 | else{ | 
|---|
| 1227 | temp=proc.GetName().c_str(); | 
|---|
| 1228 | } | 
|---|
| 1229 |  | 
|---|
| 1230 | char temporary[VN_SIZE]; | 
|---|
| 1231 | sprintf(temporary,"%s=%s",temp,Parameter); | 
|---|
| 1232 | OpcodeCalc(temporary); | 
|---|
| 1233 | } | 
|---|
| 1234 |  | 
|---|
| 1235 | //プロシージャを抜け出す(C言語のreturnと同様の処理を行う) | 
|---|
| 1236 | OpcodeExitSub(); | 
|---|
| 1237 | } | 
|---|
| 1238 | } | 
|---|
| 1239 |  | 
|---|
| 1240 |  | 
|---|
| 1241 | //////////// | 
|---|
| 1242 | // ポインタ | 
|---|
| 1243 |  | 
|---|
| 1244 | void OpcodeSetPtrData(char *Parameter,int type){ | 
|---|
| 1245 | int i; | 
|---|
| 1246 | char temporary[VN_SIZE]; | 
|---|
| 1247 |  | 
|---|
| 1248 | if(Parameter[0]=='('){ | 
|---|
| 1249 | i=JumpStringInPare(Parameter,1); | 
|---|
| 1250 | if(Parameter[i+1]=='\0'){ | 
|---|
| 1251 | for(i=0;;i++){ | 
|---|
| 1252 | Parameter[i]=Parameter[i+1]; | 
|---|
| 1253 | if(Parameter[i]=='\0') break; | 
|---|
| 1254 | } | 
|---|
| 1255 | Parameter[i-1]=0; | 
|---|
| 1256 | } | 
|---|
| 1257 | } | 
|---|
| 1258 |  | 
|---|
| 1259 | //第1パラメータを取得 | 
|---|
| 1260 | i=GetOneParameter(Parameter,0,temporary); | 
|---|
| 1261 | if(!Parameter[i]){ | 
|---|
| 1262 | SetError(1,NULL,cp); | 
|---|
| 1263 | return; | 
|---|
| 1264 | } | 
|---|
| 1265 |  | 
|---|
| 1266 | Type resultType; | 
|---|
| 1267 | if( !NumOpe(temporary,Type(),resultType) ){ | 
|---|
| 1268 | return; | 
|---|
| 1269 | } | 
|---|
| 1270 | if(!resultType.IsWhole()){ | 
|---|
| 1271 | SetError(11,Parameter,cp); | 
|---|
| 1272 | return; | 
|---|
| 1273 | } | 
|---|
| 1274 |  | 
|---|
| 1275 | ChangeTypeToLong( resultType.GetBasicType() ); | 
|---|
| 1276 |  | 
|---|
| 1277 | //第2パラメータを取得 | 
|---|
| 1278 | i=GetOneParameter(Parameter,i,temporary); | 
|---|
| 1279 | if(Parameter[i]){ | 
|---|
| 1280 | SetError(1,NULL,cp); | 
|---|
| 1281 | return; | 
|---|
| 1282 | } | 
|---|
| 1283 |  | 
|---|
| 1284 | if( !NumOpe(temporary,Type(),resultType) ){ | 
|---|
| 1285 | return; | 
|---|
| 1286 | } | 
|---|
| 1287 |  | 
|---|
| 1288 | if(type==DEF_DOUBLE){ | 
|---|
| 1289 | ChangeTypeToDouble_ToFpuReg( resultType.GetBasicType() ); | 
|---|
| 1290 |  | 
|---|
| 1291 | //pop eax | 
|---|
| 1292 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 1293 |  | 
|---|
| 1294 | //fstp qword ptr[eax] | 
|---|
| 1295 | compiler.codeGenerator.PutOld( | 
|---|
| 1296 | (char)0xDD, | 
|---|
| 1297 | (char)0x18 | 
|---|
| 1298 | ); | 
|---|
| 1299 | } | 
|---|
| 1300 | else if(type==DEF_SINGLE){ | 
|---|
| 1301 | ChangeTypeToSingle( resultType.GetBasicType() ); | 
|---|
| 1302 |  | 
|---|
| 1303 | //pop ebx | 
|---|
| 1304 | compiler.codeGenerator.op_pop(REG_EBX); | 
|---|
| 1305 |  | 
|---|
| 1306 | //pop eax | 
|---|
| 1307 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 1308 |  | 
|---|
| 1309 | //mov dword ptr[eax],ebx | 
|---|
| 1310 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EBX, REG_EAX, 0, MOD_BASE ); | 
|---|
| 1311 | } | 
|---|
| 1312 | else if(type==DEF_QWORD){ | 
|---|
| 1313 | ChangeTypeToInt64( resultType.GetBasicType() ); | 
|---|
| 1314 |  | 
|---|
| 1315 | //pop ecx | 
|---|
| 1316 | compiler.codeGenerator.op_pop(REG_ECX); | 
|---|
| 1317 |  | 
|---|
| 1318 | //pop ebx | 
|---|
| 1319 | compiler.codeGenerator.op_pop(REG_EBX); | 
|---|
| 1320 |  | 
|---|
| 1321 | //pop eax | 
|---|
| 1322 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 1323 |  | 
|---|
| 1324 | //mov dword ptr[eax],ecx | 
|---|
| 1325 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE ); | 
|---|
| 1326 |  | 
|---|
| 1327 | //mov dword ptr[eax+sizeof(long)],ebx | 
|---|
| 1328 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EBX, REG_EAX, 0x04, MOD_BASE_DISP8 ); | 
|---|
| 1329 | } | 
|---|
| 1330 | else if(type==DEF_DWORD){ | 
|---|
| 1331 | ChangeTypeToLong( resultType.GetBasicType() ); | 
|---|
| 1332 |  | 
|---|
| 1333 | //pop ebx | 
|---|
| 1334 | compiler.codeGenerator.op_pop(REG_EBX); | 
|---|
| 1335 |  | 
|---|
| 1336 | //pop eax | 
|---|
| 1337 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 1338 |  | 
|---|
| 1339 | //mov dword ptr[eax],ebx | 
|---|
| 1340 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EBX, REG_EAX, 0, MOD_BASE ); | 
|---|
| 1341 | } | 
|---|
| 1342 | else if(type==DEF_WORD){ | 
|---|
| 1343 | ChangeTypeToLong( resultType.GetBasicType() ); | 
|---|
| 1344 |  | 
|---|
| 1345 | //pop ebx | 
|---|
| 1346 | compiler.codeGenerator.op_pop(REG_EBX); | 
|---|
| 1347 |  | 
|---|
| 1348 | //pop eax | 
|---|
| 1349 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 1350 |  | 
|---|
| 1351 | //mov word ptr[eax],bx | 
|---|
| 1352 | compiler.codeGenerator.op_mov_MR( sizeof(short), REG_EBX, REG_EAX, 0, MOD_BASE ); | 
|---|
| 1353 | } | 
|---|
| 1354 | else if(type==DEF_BYTE){ | 
|---|
| 1355 | ChangeTypeToLong( resultType.GetBasicType() ); | 
|---|
| 1356 |  | 
|---|
| 1357 | //pop ebx | 
|---|
| 1358 | compiler.codeGenerator.op_pop(REG_EBX); | 
|---|
| 1359 |  | 
|---|
| 1360 | //pop eax | 
|---|
| 1361 | compiler.codeGenerator.op_pop(REG_EAX); | 
|---|
| 1362 |  | 
|---|
| 1363 | //mov byte ptr[eax],bl | 
|---|
| 1364 | compiler.codeGenerator.op_mov_MR( sizeof(char), REG_EBX, REG_EAX, 0, MOD_BASE ); | 
|---|
| 1365 | } | 
|---|
| 1366 | } | 
|---|