source: dev/trunk/abdev/BasicCompiler32/Compile_Statement.cpp@ 228

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