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