| 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],collectionVar[VN_SIZE];
|
|---|
| 600 | bool isError = false;
|
|---|
| 601 |
|
|---|
| 602 | //レキシカルスコープをレベルアップ
|
|---|
| 603 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_FOR );
|
|---|
| 604 |
|
|---|
| 605 | //第1パラメータを取得
|
|---|
| 606 | char variable[VN_SIZE];
|
|---|
| 607 | i=GetOneParameter(Parameter,0,variable);
|
|---|
| 608 | if(!Parameter[i]){
|
|---|
| 609 | SetError(12,"Foreach",cp);
|
|---|
| 610 | isError = true;
|
|---|
| 611 | goto ErrorStep;
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | //第2パラメータを取得(in~)
|
|---|
| 615 | i=GetOneParameter(Parameter,i,collectionVar);
|
|---|
| 616 |
|
|---|
| 617 | if( !GetVarType( variable, resultType, false ) )
|
|---|
| 618 | {
|
|---|
| 619 | Type collectionType;
|
|---|
| 620 | if( !NumOpe_GetType( collectionVar, Type(), collectionType ) )
|
|---|
| 621 | {
|
|---|
| 622 | isError = true;
|
|---|
| 623 | goto ErrorStep;
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 | // 未定義の場合は自動的に定義する
|
|---|
| 627 | sprintf(temporary,"%s%c%c%s", variable, 1, ESC_AS, collectionType.GetActualGenericType(0).GetClass().GetFullName().c_str() );
|
|---|
| 628 | MessageBox(0,temporary,"test",0);
|
|---|
| 629 | OpcodeDim(temporary,DIMFLAG_INITDEBUGVAR);
|
|---|
| 630 | }
|
|---|
| 631 |
|
|---|
| 632 | // Resetメソッドを呼び出す
|
|---|
| 633 | sprintf( temporary, "%s.Reset()", collectionVar );
|
|---|
| 634 | Compile( temporary );
|
|---|
| 635 |
|
|---|
| 636 | //Continueアドレスのバックアップとセット
|
|---|
| 637 | compiler.codeGenerator.ContinueAreaBegin();
|
|---|
| 638 |
|
|---|
| 639 | // MoveNextメソッドを呼び出す
|
|---|
| 640 | sprintf( temporary, "%s.MoveNext()", collectionVar );
|
|---|
| 641 | NumOpe(temporary,Type(),Type());
|
|---|
| 642 |
|
|---|
| 643 | //pop eax
|
|---|
| 644 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 645 |
|
|---|
| 646 | //cmp eax,0
|
|---|
| 647 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
|---|
| 648 |
|
|---|
| 649 | ErrorStep:
|
|---|
| 650 |
|
|---|
| 651 | //je ...
|
|---|
| 652 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
|---|
| 653 |
|
|---|
| 654 | // Currentプロパティから現在の値を取得
|
|---|
| 655 | // TODO: 型指定が未完成
|
|---|
| 656 | sprintf( temporary, "%s=%s.Current As String", variable, collectionVar );
|
|---|
| 657 | Compile( temporary );
|
|---|
| 658 |
|
|---|
| 659 | //For内をコンパイル
|
|---|
| 660 | CompileBuffer(0,COM_NEXT);
|
|---|
| 661 |
|
|---|
| 662 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
|---|
| 663 |
|
|---|
| 664 | if(szNextVariable[0]){
|
|---|
| 665 | if(lstrcmp(szNextVariable,variable)!=0){
|
|---|
| 666 | SetError(55,szNextVariable,cp);
|
|---|
| 667 | }
|
|---|
| 668 | }
|
|---|
| 669 |
|
|---|
| 670 | //jmp ...
|
|---|
| 671 | compiler.codeGenerator.op_jmp_continue();
|
|---|
| 672 |
|
|---|
| 673 | //レキシカルスコープをレベルダウン
|
|---|
| 674 | compiler.codeGenerator.lexicalScopes.End();
|
|---|
| 675 |
|
|---|
| 676 | //jeジャンプ先のオフセット値
|
|---|
| 677 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
|---|
| 678 |
|
|---|
| 679 | //Continueアドレスを復元
|
|---|
| 680 | compiler.codeGenerator.ContinueAreaEnd();
|
|---|
| 681 | }
|
|---|
| 682 |
|
|---|
| 683 | void OpcodeDo(char *Parameter){
|
|---|
| 684 | extern HANDLE hHeap;
|
|---|
| 685 | int i,i2,i3;
|
|---|
| 686 |
|
|---|
| 687 | if(Parameter[0]) SetError(10,"Do",cp);
|
|---|
| 688 |
|
|---|
| 689 | //Continueアドレスのバックアップとセット
|
|---|
| 690 | compiler.codeGenerator.ContinueAreaBegin();
|
|---|
| 691 |
|
|---|
| 692 | //レキシカルスコープをレベルアップ
|
|---|
| 693 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_DO );
|
|---|
| 694 |
|
|---|
| 695 | //Do内をコンパイル
|
|---|
| 696 | CompileBuffer(0,COM_LOOP);
|
|---|
| 697 |
|
|---|
| 698 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
|---|
| 699 |
|
|---|
| 700 | const PertialSchedule *pDoPertialSchedule = NULL;
|
|---|
| 701 |
|
|---|
| 702 | extern char *basbuf;
|
|---|
| 703 | char temporary[VN_SIZE];
|
|---|
| 704 | for(i=cp-1;;i--){
|
|---|
| 705 | if(IsCommandDelimitation(basbuf[i])){
|
|---|
| 706 | i+=3;
|
|---|
| 707 | if(!(basbuf[i]=='0'||basbuf[i]=='1')){
|
|---|
| 708 | //無条件ループ
|
|---|
| 709 | break;
|
|---|
| 710 | }
|
|---|
| 711 | i3=i;
|
|---|
| 712 |
|
|---|
| 713 | for(i+=2,i2=0;;i++,i2++){
|
|---|
| 714 | if(IsCommandDelimitation(basbuf[i])){
|
|---|
| 715 | temporary[i2]=0;
|
|---|
| 716 | break;
|
|---|
| 717 | }
|
|---|
| 718 | temporary[i2]=basbuf[i];
|
|---|
| 719 | }
|
|---|
| 720 |
|
|---|
| 721 | Type tempType;
|
|---|
| 722 | NumOpe(temporary,Type(),tempType);
|
|---|
| 723 |
|
|---|
| 724 | if( tempType.IsDouble() ){
|
|---|
| 725 | //fld qword ptr[esp]
|
|---|
| 726 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 727 |
|
|---|
| 728 | //push 0
|
|---|
| 729 | compiler.codeGenerator.op_push_V(0);
|
|---|
| 730 |
|
|---|
| 731 | //fild dword ptr[esp]
|
|---|
| 732 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 733 |
|
|---|
| 734 | //add esp,sizeof(double)+sizeof(long)
|
|---|
| 735 | compiler.codeGenerator.op_add_esp(sizeof(double)+sizeof(long));
|
|---|
| 736 |
|
|---|
| 737 | //fcompp
|
|---|
| 738 | compiler.codeGenerator.op_fcompp();
|
|---|
| 739 |
|
|---|
| 740 | //fnstsw ax
|
|---|
| 741 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 742 |
|
|---|
| 743 | //test ah,40
|
|---|
| 744 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
|---|
| 745 |
|
|---|
| 746 | if(basbuf[i3]=='0'){
|
|---|
| 747 | //While
|
|---|
| 748 |
|
|---|
| 749 | //jne 5(ループ終了)
|
|---|
| 750 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
|---|
| 751 | }
|
|---|
| 752 | else if(basbuf[i3]=='1'){
|
|---|
| 753 | //Until
|
|---|
| 754 |
|
|---|
| 755 | //je 5(ループ終了)
|
|---|
| 756 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true );
|
|---|
| 757 | }
|
|---|
| 758 | }
|
|---|
| 759 | else if( tempType.IsSingle() ){
|
|---|
| 760 | //fld dword ptr[esp]
|
|---|
| 761 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 762 |
|
|---|
| 763 | //push 0
|
|---|
| 764 | compiler.codeGenerator.op_push_V(0);
|
|---|
| 765 |
|
|---|
| 766 | //fild dword ptr[esp]
|
|---|
| 767 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 768 |
|
|---|
| 769 | //add esp,sizeof(float)+sizeof(long)
|
|---|
| 770 | compiler.codeGenerator.op_add_esp(sizeof(float)+sizeof(long));
|
|---|
| 771 |
|
|---|
| 772 | //fcompp
|
|---|
| 773 | compiler.codeGenerator.op_fcompp();
|
|---|
| 774 |
|
|---|
| 775 | //fnstsw ax
|
|---|
| 776 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 777 |
|
|---|
| 778 | //test ah,40
|
|---|
| 779 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
|---|
| 780 |
|
|---|
| 781 | if(basbuf[i3]=='0'){
|
|---|
| 782 | //While
|
|---|
| 783 |
|
|---|
| 784 | //jne 5(ループ終了)
|
|---|
| 785 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
|---|
| 786 | }
|
|---|
| 787 | else if(basbuf[i3]=='1'){
|
|---|
| 788 | //Until
|
|---|
| 789 |
|
|---|
| 790 | //je 5(ループ終了)
|
|---|
| 791 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true );
|
|---|
| 792 | }
|
|---|
| 793 | }
|
|---|
| 794 | else if( tempType.Is64() ){
|
|---|
| 795 | //64ビット型
|
|---|
| 796 |
|
|---|
| 797 | //pop eax
|
|---|
| 798 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 799 |
|
|---|
| 800 | //pop ebx
|
|---|
| 801 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 802 |
|
|---|
| 803 | //cmp eax,0
|
|---|
| 804 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
|---|
| 805 |
|
|---|
| 806 | //jne
|
|---|
| 807 | const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
|---|
| 808 |
|
|---|
| 809 | //cmp ebx,0
|
|---|
| 810 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EBX, 0 );
|
|---|
| 811 |
|
|---|
| 812 | //jne
|
|---|
| 813 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
|---|
| 814 |
|
|---|
| 815 | if(basbuf[i3]=='0'){
|
|---|
| 816 | //While
|
|---|
| 817 |
|
|---|
| 818 | //jmp 5(ループ終了)
|
|---|
| 819 | pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
|
|---|
| 820 |
|
|---|
| 821 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 );
|
|---|
| 822 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
|
|---|
| 823 | }
|
|---|
| 824 | else if(basbuf[i3]=='1'){
|
|---|
| 825 | //Until
|
|---|
| 826 |
|
|---|
| 827 | //jmp 2(ループを続ける)
|
|---|
| 828 | const PertialSchedule *pTempPertialSchedule3 = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
|
|---|
| 829 |
|
|---|
| 830 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 );
|
|---|
| 831 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
|
|---|
| 832 |
|
|---|
| 833 | //jmp 5(ループ終了)
|
|---|
| 834 | pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
|
|---|
| 835 |
|
|---|
| 836 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule3 );
|
|---|
| 837 | }
|
|---|
| 838 | }
|
|---|
| 839 | else{
|
|---|
| 840 | //pop eax
|
|---|
| 841 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 842 |
|
|---|
| 843 | //cmp eax,0
|
|---|
| 844 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
|---|
| 845 |
|
|---|
| 846 | if(basbuf[i3]=='0'){
|
|---|
| 847 | //While
|
|---|
| 848 |
|
|---|
| 849 | //je 5(ループ終了)
|
|---|
| 850 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true );
|
|---|
| 851 | }
|
|---|
| 852 | else if(basbuf[i3]=='1'){
|
|---|
| 853 | //Until
|
|---|
| 854 |
|
|---|
| 855 | //jne 5(ループ終了)
|
|---|
| 856 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
|---|
| 857 | }
|
|---|
| 858 | }
|
|---|
| 859 | break;
|
|---|
| 860 | }
|
|---|
| 861 | }
|
|---|
| 862 |
|
|---|
| 863 | //jmp ...
|
|---|
| 864 | compiler.codeGenerator.op_jmp_continue();
|
|---|
| 865 |
|
|---|
| 866 | if( pDoPertialSchedule )
|
|---|
| 867 | {
|
|---|
| 868 | compiler.codeGenerator.opfix_JmpPertialSchedule( pDoPertialSchedule );
|
|---|
| 869 | }
|
|---|
| 870 |
|
|---|
| 871 | //jmp ...
|
|---|
| 872 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
|---|
| 873 |
|
|---|
| 874 | //レキシカルスコープをレベルダウン
|
|---|
| 875 | compiler.codeGenerator.lexicalScopes.End();
|
|---|
| 876 |
|
|---|
| 877 | //jmpジャンプ先のオフセット値
|
|---|
| 878 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
|---|
| 879 |
|
|---|
| 880 | //Continueアドレスを復元
|
|---|
| 881 | compiler.codeGenerator.ContinueAreaEnd();
|
|---|
| 882 | }
|
|---|
| 883 | void OpcodeContinue(void){
|
|---|
| 884 | //jmp ...(Continue addr)
|
|---|
| 885 | compiler.codeGenerator.op_jmp_continue();
|
|---|
| 886 | }
|
|---|
| 887 |
|
|---|
| 888 | void OpcodeExitSub(void){
|
|---|
| 889 | if( UserProc::IsGlobalAreaCompiling() ){
|
|---|
| 890 | SetError(12,"Exit Sub/Function",cp);
|
|---|
| 891 | return;
|
|---|
| 892 | }
|
|---|
| 893 |
|
|---|
| 894 | //未解放のローカルオブジェクトのデストラクタを呼び出す
|
|---|
| 895 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfReturn();
|
|---|
| 896 |
|
|---|
| 897 | //jmp ...(End Sub/Function)
|
|---|
| 898 | compiler.codeGenerator.op_jmp_exitsub();
|
|---|
| 899 | }
|
|---|
| 900 |
|
|---|
| 901 | //Caseスケジュール
|
|---|
| 902 | class SelectSchedule
|
|---|
| 903 | {
|
|---|
| 904 | public:
|
|---|
| 905 | SelectSchedule( int typeSize )
|
|---|
| 906 | : typeSize( typeSize )
|
|---|
| 907 | , nowCaseSchedule( 0 )
|
|---|
| 908 | {
|
|---|
| 909 | }
|
|---|
| 910 |
|
|---|
| 911 | PertialSchedules casePertialSchedules;
|
|---|
| 912 | int typeSize;
|
|---|
| 913 | int nowCaseSchedule;
|
|---|
| 914 | };
|
|---|
| 915 | std::vector<SelectSchedule> selectSchedules;
|
|---|
| 916 |
|
|---|
| 917 | void OpcodeSelect(const char *lpszParms){
|
|---|
| 918 | extern HANDLE hHeap;
|
|---|
| 919 | extern char *basbuf;
|
|---|
| 920 | int i,i2,i3,sw,NowCaseCp;
|
|---|
| 921 | char temporary[VN_SIZE];
|
|---|
| 922 |
|
|---|
| 923 | Type type1;
|
|---|
| 924 | if( !NumOpe(lpszParms,Type(), type1 ) ){
|
|---|
| 925 | return;
|
|---|
| 926 | }
|
|---|
| 927 |
|
|---|
| 928 | selectSchedules.push_back( SelectSchedule( type1.GetSize() ) );
|
|---|
| 929 |
|
|---|
| 930 | if( selectSchedules.back().typeSize < sizeof(long) ){
|
|---|
| 931 | selectSchedules.back().typeSize = sizeof(long);
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | for(i=cp,sw=0;;i++){
|
|---|
| 935 | if(basbuf[i]=='\0'){
|
|---|
| 936 | selectSchedules.pop_back();
|
|---|
| 937 | SetError(22,"Select",cp);
|
|---|
| 938 | return;
|
|---|
| 939 | }
|
|---|
| 940 | if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE){
|
|---|
| 941 | for(i2=0;;i++){
|
|---|
| 942 | if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE) i2++;
|
|---|
| 943 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){
|
|---|
| 944 | i2--;
|
|---|
| 945 | if(i2==0) break;
|
|---|
| 946 | }
|
|---|
| 947 | }
|
|---|
| 948 | continue;
|
|---|
| 949 | }
|
|---|
| 950 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){
|
|---|
| 951 | if(sw==0){
|
|---|
| 952 | //add esp,CaseTypeSize
|
|---|
| 953 | compiler.codeGenerator.op_add_esp( selectSchedules.back().typeSize );
|
|---|
| 954 | }
|
|---|
| 955 | break;
|
|---|
| 956 | }
|
|---|
| 957 | if(basbuf[i]==1&&basbuf[i+1]==ESC_CASE){
|
|---|
| 958 | NowCaseCp=i;
|
|---|
| 959 |
|
|---|
| 960 | i++;
|
|---|
| 961 | while(1){
|
|---|
| 962 | for(i++,i2=0;;i++,i2++){
|
|---|
| 963 | if(basbuf[i]=='\"'){
|
|---|
| 964 | i3=GetStringInQuotation(temporary+i2,basbuf+i);
|
|---|
| 965 | i+=i3-1;
|
|---|
| 966 | i2+=i3-1;
|
|---|
| 967 | continue;
|
|---|
| 968 | }
|
|---|
| 969 | if(basbuf[i]=='('){
|
|---|
| 970 | i3=GetStringInPare(temporary+i2,basbuf+i);
|
|---|
| 971 | i+=i3-1;
|
|---|
| 972 | i2+=i3-1;
|
|---|
| 973 | continue;
|
|---|
| 974 | }
|
|---|
| 975 | if(basbuf[i]=='['){
|
|---|
| 976 | i3=GetStringInBracket(temporary+i2,basbuf+i);
|
|---|
| 977 | i+=i3-1;
|
|---|
| 978 | i2+=i3-1;
|
|---|
| 979 | continue;
|
|---|
| 980 | }
|
|---|
| 981 |
|
|---|
| 982 | if(IsCommandDelimitation(basbuf[i])){
|
|---|
| 983 | temporary[i2]=0;
|
|---|
| 984 | break;
|
|---|
| 985 | }
|
|---|
| 986 | if(basbuf[i]==','){
|
|---|
| 987 | temporary[i2]=0;
|
|---|
| 988 | break;
|
|---|
| 989 | }
|
|---|
| 990 |
|
|---|
| 991 | temporary[i2]=basbuf[i];
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|
| 994 | //エラー用
|
|---|
| 995 | i2=cp;
|
|---|
| 996 | cp=NowCaseCp;
|
|---|
| 997 |
|
|---|
| 998 | Type type2;
|
|---|
| 999 | if( !NumOpe(temporary,type1,type2) ){
|
|---|
| 1000 | return;
|
|---|
| 1001 | }
|
|---|
| 1002 |
|
|---|
| 1003 | cp=i2;
|
|---|
| 1004 |
|
|---|
| 1005 | if(type1.IsObject()){
|
|---|
| 1006 | std::vector<const UserProc *> subs;
|
|---|
| 1007 | type1.GetClass().GetDynamicMethods().Enum( CALC_EQUAL, subs );
|
|---|
| 1008 | if( subs.size() == 0 ){
|
|---|
| 1009 | return;
|
|---|
| 1010 | }
|
|---|
| 1011 |
|
|---|
| 1012 | Parameters params;
|
|---|
| 1013 | params.push_back( new Parameter( "", Type( type2 ) ) );
|
|---|
| 1014 |
|
|---|
| 1015 | //オーバーロードを解決
|
|---|
| 1016 | const UserProc *pUserProc = OverloadSolution("==",subs, params, NULL);
|
|---|
| 1017 |
|
|---|
| 1018 | delete params[0];
|
|---|
| 1019 |
|
|---|
| 1020 | if(!pUserProc){
|
|---|
| 1021 | //エラー
|
|---|
| 1022 | return;
|
|---|
| 1023 | }
|
|---|
| 1024 |
|
|---|
| 1025 |
|
|---|
| 1026 | //pop edx
|
|---|
| 1027 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 1028 |
|
|---|
| 1029 | //mov ecx,dword ptr[esp]
|
|---|
| 1030 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_ESP,0,MOD_BASE);
|
|---|
| 1031 |
|
|---|
| 1032 | //push edx
|
|---|
| 1033 | compiler.codeGenerator.op_push(REG_EDX);
|
|---|
| 1034 |
|
|---|
| 1035 | //push ecx
|
|---|
| 1036 | compiler.codeGenerator.op_push(REG_ECX);
|
|---|
| 1037 |
|
|---|
| 1038 | //call operator_proc ※ ==演算子
|
|---|
| 1039 | compiler.codeGenerator.op_call(pUserProc);
|
|---|
| 1040 |
|
|---|
| 1041 | //test eax,eax
|
|---|
| 1042 | compiler.codeGenerator.op_test(REG_EAX,REG_EAX);
|
|---|
| 1043 |
|
|---|
| 1044 | //jne ...
|
|---|
| 1045 | selectSchedules.back().casePertialSchedules.push_back(
|
|---|
| 1046 | compiler.codeGenerator.op_jne( 0, sizeof(long), true )
|
|---|
| 1047 | );
|
|---|
| 1048 | }
|
|---|
| 1049 | else if(type1.IsDouble()){
|
|---|
| 1050 | ChangeTypeToDouble(type2.GetBasicType());
|
|---|
| 1051 |
|
|---|
| 1052 | //fld qword ptr[esp]
|
|---|
| 1053 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1054 |
|
|---|
| 1055 | //add esp,CaseTypeSize
|
|---|
| 1056 | compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize);
|
|---|
| 1057 |
|
|---|
| 1058 | //fld qword ptr[esp]
|
|---|
| 1059 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1060 |
|
|---|
| 1061 | //fcompp
|
|---|
| 1062 | compiler.codeGenerator.op_fcompp();
|
|---|
| 1063 |
|
|---|
| 1064 | //fnstsw ax
|
|---|
| 1065 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 1066 |
|
|---|
| 1067 | //test ah,40
|
|---|
| 1068 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
|---|
| 1069 |
|
|---|
| 1070 | //jne ...
|
|---|
| 1071 | selectSchedules.back().casePertialSchedules.push_back(
|
|---|
| 1072 | compiler.codeGenerator.op_jne( 0, sizeof(long), true )
|
|---|
| 1073 | );
|
|---|
| 1074 | }
|
|---|
| 1075 | else if(type1.IsSingle()){
|
|---|
| 1076 | ChangeTypeToSingle(type2.GetBasicType());
|
|---|
| 1077 |
|
|---|
| 1078 | //fld dword ptr[esp]
|
|---|
| 1079 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1080 |
|
|---|
| 1081 | //add esp,CaseTypeSize
|
|---|
| 1082 | compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize);
|
|---|
| 1083 |
|
|---|
| 1084 | //fld dword ptr[esp]
|
|---|
| 1085 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1086 |
|
|---|
| 1087 | //fcompp
|
|---|
| 1088 | compiler.codeGenerator.op_fcompp();
|
|---|
| 1089 |
|
|---|
| 1090 | //fnstsw ax
|
|---|
| 1091 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 1092 |
|
|---|
| 1093 | //test ah,40
|
|---|
| 1094 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
|---|
| 1095 |
|
|---|
| 1096 | //jne ...
|
|---|
| 1097 | selectSchedules.back().casePertialSchedules.push_back(
|
|---|
| 1098 | compiler.codeGenerator.op_jne( 0, sizeof(long), true )
|
|---|
| 1099 | );
|
|---|
| 1100 | }
|
|---|
| 1101 | else{
|
|---|
| 1102 | //その他整数型
|
|---|
| 1103 |
|
|---|
| 1104 | //pop ebx
|
|---|
| 1105 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 1106 |
|
|---|
| 1107 | //mov eax,dword ptr[esp]
|
|---|
| 1108 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE );
|
|---|
| 1109 |
|
|---|
| 1110 | //cmp eax,ebx
|
|---|
| 1111 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 1112 |
|
|---|
| 1113 | //je ...
|
|---|
| 1114 | selectSchedules.back().casePertialSchedules.push_back(
|
|---|
| 1115 | compiler.codeGenerator.op_je( 0, sizeof(long), true )
|
|---|
| 1116 | );
|
|---|
| 1117 | }
|
|---|
| 1118 |
|
|---|
| 1119 | if(basbuf[i]!=',') break;
|
|---|
| 1120 | }
|
|---|
| 1121 | }
|
|---|
| 1122 | if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){
|
|---|
| 1123 | sw=1;
|
|---|
| 1124 |
|
|---|
| 1125 | //jmp ...
|
|---|
| 1126 | selectSchedules.back().casePertialSchedules.push_back(
|
|---|
| 1127 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
|
|---|
| 1128 | );
|
|---|
| 1129 | }
|
|---|
| 1130 | }
|
|---|
| 1131 |
|
|---|
| 1132 | //レキシカルスコープをレベルアップ
|
|---|
| 1133 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_SELECT );
|
|---|
| 1134 |
|
|---|
| 1135 | //Select Case内をコンパイル
|
|---|
| 1136 | CompileBuffer(ESC_ENDSELECT,0);
|
|---|
| 1137 |
|
|---|
| 1138 | //jmp EndSelect
|
|---|
| 1139 | selectSchedules.back().casePertialSchedules.push_back(
|
|---|
| 1140 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
|
|---|
| 1141 | );
|
|---|
| 1142 |
|
|---|
| 1143 | //最終スケジュール
|
|---|
| 1144 | for(i=selectSchedules.back().nowCaseSchedule;i<(int)selectSchedules.back().casePertialSchedules.size();i++){
|
|---|
| 1145 | compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[i] );
|
|---|
| 1146 | }
|
|---|
| 1147 |
|
|---|
| 1148 | //レキシカルスコープをレベルダウン
|
|---|
| 1149 | compiler.codeGenerator.lexicalScopes.End();
|
|---|
| 1150 |
|
|---|
| 1151 | selectSchedules.pop_back();
|
|---|
| 1152 | }
|
|---|
| 1153 | void OpcodeCase(char *Parameter){
|
|---|
| 1154 | int i;
|
|---|
| 1155 |
|
|---|
| 1156 | if(selectSchedules.back().typeSize==-1){
|
|---|
| 1157 | SetError(30,"Case",cp);
|
|---|
| 1158 | return;
|
|---|
| 1159 | }
|
|---|
| 1160 |
|
|---|
| 1161 | //jmp EndSelect
|
|---|
| 1162 | selectSchedules.back().casePertialSchedules.push_back(
|
|---|
| 1163 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
|
|---|
| 1164 | );
|
|---|
| 1165 |
|
|---|
| 1166 | i=0;
|
|---|
| 1167 | while(1){
|
|---|
| 1168 | //Caseスケジュール
|
|---|
| 1169 | compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[selectSchedules.back().nowCaseSchedule] );
|
|---|
| 1170 | selectSchedules.back().nowCaseSchedule++;
|
|---|
| 1171 |
|
|---|
| 1172 | i=JumpOneParameter(Parameter,i);
|
|---|
| 1173 | if(Parameter[i]=='\0') break;
|
|---|
| 1174 | }
|
|---|
| 1175 |
|
|---|
| 1176 | //add esp,CaseTypeSize
|
|---|
| 1177 | compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize);
|
|---|
| 1178 | }
|
|---|
| 1179 |
|
|---|
| 1180 | void OpcodeGosub(char *Parameter){
|
|---|
| 1181 | extern HANDLE hHeap;
|
|---|
| 1182 | int i,LineNum;
|
|---|
| 1183 |
|
|---|
| 1184 | if(Parameter[0]=='*'){
|
|---|
| 1185 | i=GetLabelAddress(Parameter+1,0);
|
|---|
| 1186 |
|
|---|
| 1187 | if( i == -1 )
|
|---|
| 1188 | {
|
|---|
| 1189 | //jmp ...(schedule)
|
|---|
| 1190 | compiler.codeGenerator.op_jmp_goto_schedule( (const std::string)(Parameter + 1), 0, cp );
|
|---|
| 1191 | }
|
|---|
| 1192 | else
|
|---|
| 1193 | {
|
|---|
| 1194 | //jmp ...
|
|---|
| 1195 | compiler.codeGenerator.op_jmp(
|
|---|
| 1196 | i-compiler.codeGenerator.GetNativeCodeSize(),
|
|---|
| 1197 | sizeof(long),
|
|---|
| 1198 | false,
|
|---|
| 1199 | true
|
|---|
| 1200 | );
|
|---|
| 1201 | }
|
|---|
| 1202 | }
|
|---|
| 1203 | else{
|
|---|
| 1204 | LineNum=atoi(Parameter);
|
|---|
| 1205 | i=GetLabelAddress(0,LineNum);
|
|---|
| 1206 |
|
|---|
| 1207 | if( i == -1 )
|
|---|
| 1208 | {
|
|---|
| 1209 | //jmp ...(schedule)
|
|---|
| 1210 | compiler.codeGenerator.op_jmp_goto_schedule( "", LineNum, cp );
|
|---|
| 1211 | }
|
|---|
| 1212 | else
|
|---|
| 1213 | {
|
|---|
| 1214 | //jmp ...
|
|---|
| 1215 | compiler.codeGenerator.op_jmp(
|
|---|
| 1216 | i-compiler.codeGenerator.GetNativeCodeSize(),
|
|---|
| 1217 | sizeof(long),
|
|---|
| 1218 | false,
|
|---|
| 1219 | true
|
|---|
| 1220 | );
|
|---|
| 1221 | }
|
|---|
| 1222 | }
|
|---|
| 1223 | }
|
|---|
| 1224 | void OpcodeReturn(char *Parameter){
|
|---|
| 1225 | if( UserProc::IsGlobalAreaCompiling() ){
|
|---|
| 1226 | //Gosub~Returnとして扱う
|
|---|
| 1227 |
|
|---|
| 1228 | //ret
|
|---|
| 1229 | compiler.codeGenerator.op_ret();
|
|---|
| 1230 | }
|
|---|
| 1231 | else{
|
|---|
| 1232 | //戻り値をセット
|
|---|
| 1233 | if(Parameter[0]){
|
|---|
| 1234 | const UserProc &proc = UserProc::CompilingUserProc();
|
|---|
| 1235 |
|
|---|
| 1236 | const char *temp = "_System_ReturnValue";
|
|---|
| 1237 | if(proc.GetName()[0]==1&&proc.GetName()[1]==ESC_OPERATOR)
|
|---|
| 1238 | {
|
|---|
| 1239 | }
|
|---|
| 1240 | else{
|
|---|
| 1241 | temp=proc.GetName().c_str();
|
|---|
| 1242 | }
|
|---|
| 1243 |
|
|---|
| 1244 | char temporary[VN_SIZE];
|
|---|
| 1245 | sprintf(temporary,"%s=%s",temp,Parameter);
|
|---|
| 1246 | OpcodeCalc(temporary);
|
|---|
| 1247 | }
|
|---|
| 1248 |
|
|---|
| 1249 | //プロシージャを抜け出す(C言語のreturnと同様の処理を行う)
|
|---|
| 1250 | OpcodeExitSub();
|
|---|
| 1251 | }
|
|---|
| 1252 | }
|
|---|
| 1253 |
|
|---|
| 1254 |
|
|---|
| 1255 | ////////////
|
|---|
| 1256 | // ポインタ
|
|---|
| 1257 |
|
|---|
| 1258 | void OpcodeSetPtrData(char *Parameter,int type){
|
|---|
| 1259 | int i;
|
|---|
| 1260 | char temporary[VN_SIZE];
|
|---|
| 1261 |
|
|---|
| 1262 | if(Parameter[0]=='('){
|
|---|
| 1263 | i=JumpStringInPare(Parameter,1);
|
|---|
| 1264 | if(Parameter[i+1]=='\0'){
|
|---|
| 1265 | for(i=0;;i++){
|
|---|
| 1266 | Parameter[i]=Parameter[i+1];
|
|---|
| 1267 | if(Parameter[i]=='\0') break;
|
|---|
| 1268 | }
|
|---|
| 1269 | Parameter[i-1]=0;
|
|---|
| 1270 | }
|
|---|
| 1271 | }
|
|---|
| 1272 |
|
|---|
| 1273 | //第1パラメータを取得
|
|---|
| 1274 | i=GetOneParameter(Parameter,0,temporary);
|
|---|
| 1275 | if(!Parameter[i]){
|
|---|
| 1276 | SetError(1,NULL,cp);
|
|---|
| 1277 | return;
|
|---|
| 1278 | }
|
|---|
| 1279 |
|
|---|
| 1280 | Type resultType;
|
|---|
| 1281 | if( !NumOpe(temporary,Type(),resultType) ){
|
|---|
| 1282 | return;
|
|---|
| 1283 | }
|
|---|
| 1284 | if(!resultType.IsWhole()){
|
|---|
| 1285 | SetError(11,Parameter,cp);
|
|---|
| 1286 | return;
|
|---|
| 1287 | }
|
|---|
| 1288 |
|
|---|
| 1289 | ChangeTypeToLong( resultType.GetBasicType() );
|
|---|
| 1290 |
|
|---|
| 1291 | //第2パラメータを取得
|
|---|
| 1292 | i=GetOneParameter(Parameter,i,temporary);
|
|---|
| 1293 | if(Parameter[i]){
|
|---|
| 1294 | SetError(1,NULL,cp);
|
|---|
| 1295 | return;
|
|---|
| 1296 | }
|
|---|
| 1297 |
|
|---|
| 1298 | if( !NumOpe(temporary,Type(),resultType) ){
|
|---|
| 1299 | return;
|
|---|
| 1300 | }
|
|---|
| 1301 |
|
|---|
| 1302 | if(type==DEF_DOUBLE){
|
|---|
| 1303 | ChangeTypeToDouble_ToFpuReg( resultType.GetBasicType() );
|
|---|
| 1304 |
|
|---|
| 1305 | //pop eax
|
|---|
| 1306 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1307 |
|
|---|
| 1308 | //fstp qword ptr[eax]
|
|---|
| 1309 | compiler.codeGenerator.PutOld(
|
|---|
| 1310 | (char)0xDD,
|
|---|
| 1311 | (char)0x18
|
|---|
| 1312 | );
|
|---|
| 1313 | }
|
|---|
| 1314 | else if(type==DEF_SINGLE){
|
|---|
| 1315 | ChangeTypeToSingle( resultType.GetBasicType() );
|
|---|
| 1316 |
|
|---|
| 1317 | //pop ebx
|
|---|
| 1318 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 1319 |
|
|---|
| 1320 | //pop eax
|
|---|
| 1321 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1322 |
|
|---|
| 1323 | //mov dword ptr[eax],ebx
|
|---|
| 1324 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EBX, REG_EAX, 0, MOD_BASE );
|
|---|
| 1325 | }
|
|---|
| 1326 | else if(type==DEF_QWORD){
|
|---|
| 1327 | ChangeTypeToInt64( resultType.GetBasicType() );
|
|---|
| 1328 |
|
|---|
| 1329 | //pop ecx
|
|---|
| 1330 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1331 |
|
|---|
| 1332 | //pop ebx
|
|---|
| 1333 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 1334 |
|
|---|
| 1335 | //pop eax
|
|---|
| 1336 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1337 |
|
|---|
| 1338 | //mov dword ptr[eax],ecx
|
|---|
| 1339 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE );
|
|---|
| 1340 |
|
|---|
| 1341 | //mov dword ptr[eax+sizeof(long)],ebx
|
|---|
| 1342 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EBX, REG_EAX, 0x04, MOD_BASE_DISP8 );
|
|---|
| 1343 | }
|
|---|
| 1344 | else if(type==DEF_DWORD){
|
|---|
| 1345 | ChangeTypeToLong( resultType.GetBasicType() );
|
|---|
| 1346 |
|
|---|
| 1347 | //pop ebx
|
|---|
| 1348 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 1349 |
|
|---|
| 1350 | //pop eax
|
|---|
| 1351 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1352 |
|
|---|
| 1353 | //mov dword ptr[eax],ebx
|
|---|
| 1354 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EBX, REG_EAX, 0, MOD_BASE );
|
|---|
| 1355 | }
|
|---|
| 1356 | else if(type==DEF_WORD){
|
|---|
| 1357 | ChangeTypeToLong( resultType.GetBasicType() );
|
|---|
| 1358 |
|
|---|
| 1359 | //pop ebx
|
|---|
| 1360 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 1361 |
|
|---|
| 1362 | //pop eax
|
|---|
| 1363 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1364 |
|
|---|
| 1365 | //mov word ptr[eax],bx
|
|---|
| 1366 | compiler.codeGenerator.op_mov_MR( sizeof(short), REG_EBX, REG_EAX, 0, MOD_BASE );
|
|---|
| 1367 | }
|
|---|
| 1368 | else if(type==DEF_BYTE){
|
|---|
| 1369 | ChangeTypeToLong( resultType.GetBasicType() );
|
|---|
| 1370 |
|
|---|
| 1371 | //pop ebx
|
|---|
| 1372 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 1373 |
|
|---|
| 1374 | //pop eax
|
|---|
| 1375 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1376 |
|
|---|
| 1377 | //mov byte ptr[eax],bl
|
|---|
| 1378 | compiler.codeGenerator.op_mov_MR( sizeof(char), REG_EBX, REG_EAX, 0, MOD_BASE );
|
|---|
| 1379 | }
|
|---|
| 1380 | }
|
|---|