source: dev/BasicCompiler32/Compile_Statement.cpp@ 60

Last change on this file since 60 was 55, checked in by dai_9181, 18 years ago

・コマンドラインオプション "/unicode" に対応。
・Unicode文字セットを使用する場合に "UNICODE" が自動的に#defineされるようにしました。
・SByte型(8ビット符号付き整数型)を追加。
・Char型を文字型に変更。
・プロジェクトオプションから「Unicode文字セットを使用する」チェックを選択できるようにしました。

File size: 39.4 KB
RevLine 
[3]1#include "../BasicCompiler_Common/common.h"
2#include "Opcode.h"
3
4void OpcodeOthers(char *Command){
5 int i,i2;
6 char buffer[8192];
7 SUBINFO *psi;
8
9 for(i=0;;i++){
10 if(Command[i]=='['){
11 i2=GetStringInBracket(buffer+i,Command+i);
12 i+=i2-1;
13 continue;
14 }
15 if(Command[i]==1&&Command[i+1]==ESC_PSMEM){
16 buffer[i]=Command[i];
17 i++;
18 buffer[i]=Command[i];
19 continue;
20 }
21 if(!IsVariableChar(Command[i])){
22 buffer[i]=0;
23 break;
24 }
25 buffer[i]=Command[i];
26 }
27
28 if(!(
29 IsVariableTopChar(buffer[0])||
30 buffer[0]=='.'||
31 (buffer[0]==1&&buffer[1]==ESC_PSMEM)
32 )){
33 SetError(1,NULL,cp);
34 return;
35 }
36
37
38 if(Command[i]=='\0'){
39 //////////////////////////////
40 // パラメータ無しのマクロ検索
41 //////////////////////////////
42
43 psi=GetSubHash(Command);
44
45 //GetSubHash内でエラー提示が行われた場合
46 if(psi==(SUBINFO *)-1) return;
47
48 if(psi==0){
49 char temporary[VN_SIZE];
50 lstrcpy(temporary,Command);
51
52 CharUpper(temporary);
53 psi=GetSubHash(temporary);
54
55 //GetSubHash内でエラー提示が行われた場合
56 if(psi==(SUBINFO *)-1) return;
57 }
58
59 if(psi){
60 if(psi->dwType!=SUBTYPE_MACRO) SetError(10,Command,cp);
61
[31]62 Opcode_CallProc("",psi,0,"",0);
[3]63
64 return;
65 }
66 }
67 else if(IsNumCalcMark(Command,i)){
68 //代入演算
69 OpcodeCalc(Command);
70 return;
71 }
72
73
74 int idProc;
75 void *pInfo;
76 idProc=GetProc(buffer,&pInfo);
77
78 int i4;
79 char temp2[VN_SIZE];
80 if(idProc){
81 if(Command[i]!='('){
82 SetError(10,buffer,cp);
83 return;
84 }
85 i4=GetStringInPare_RemovePare(temp2,Command+i+1);
86
87 //閉じカッコ")"に続く文字がNULLでないときはエラーにする
88 if(Command[i+1+i4+1]!='\0') SetError(42,NULL,cp);
89
90 ////////////////
91 // 呼び出し
92 ////////////////
93
94 LONG_PTR lp;
95 i2=CallProc(idProc,pInfo,buffer,temp2,&lp);
96
97
98 /////////////////////
99 // 戻り値の処理
100 /////////////////////
101
102 if(i2==DEF_DOUBLE||i2==DEF_SINGLE){
103 //fstp st(0)
104 OpBuffer[obp++]=(char)0xDD;
105 OpBuffer[obp++]=(char)0xD8;
106 }
107 if(i2==DEF_OBJECT){
[51]108 //mov ebx,eax
109 op_mov_RR(REG_EBX,REG_EAX);
[3]110
[51]111 FreeTempObject(REG_EBX,(CClass *)lp);
[3]112 }
113 return;
114 }
115
116
117 //////////////////////////
118 // その他は代入演算を行う
119 //////////////////////////
120 OpcodeCalc(Command);
121}
122
123void OpcodeIf(char *Parameter){
124 int i,i2,i3,i4,type;
125
126 for(i=0;;i++){
127 if(Parameter[i]=='\0'){
128 SetError(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 type=NumOpe(Parameter,0,0,0);
138
139 if(type==-1){
140 //NumOpe内でエラー
141 i3=-1; //ダミー
142 }
143 else if(type==DEF_DOUBLE){
144 //fld qword ptr[esp]
145 op_fld_ptr_esp(DEF_DOUBLE);
146
147 //push 0
148 op_push_value(0);
149
150 //fild dword ptr[esp]
151 op_fld_ptr_esp(DEF_LONG);
152
153 //add esp,sizeof(double)+sizeof(long)
154 op_add_esp(sizeof(double)+sizeof(long));
155
156 //fcompp
157 OpBuffer[obp++]=(char)0xDE;
158 OpBuffer[obp++]=(char)0xD9;
159
160 //fnstsw ax
161 OpBuffer[obp++]=(char)0xDF;
162 OpBuffer[obp++]=(char)0xE0;
163
164 //test ah,40
165 OpBuffer[obp++]=(char)0xF6;
166 OpBuffer[obp++]=(char)0xC4;
167 OpBuffer[obp++]=(char)0x40;
168
169 //jne (endif、または else まで)
170 OpBuffer[obp++]=(char)0x0F;
171 OpBuffer[obp++]=(char)0x85;
172 obp+=sizeof(long);
173
174 //jneの番地
175 i3=obp;
176 }
177 else if(type==DEF_SINGLE){
178 //fld dword ptr[esp]
179 op_fld_ptr_esp(DEF_SINGLE);
180
181 //push 0
182 op_push_value(0);
183
184 //fild dword ptr[esp]
185 op_fld_ptr_esp(DEF_LONG);
186
187 //add esp,sizeof(float)+sizeof(long)
188 op_add_esp(sizeof(float)+sizeof(long));
189
190 //fcompp
191 OpBuffer[obp++]=(char)0xDE;
192 OpBuffer[obp++]=(char)0xD9;
193
194 //fnstsw ax
195 OpBuffer[obp++]=(char)0xDF;
196 OpBuffer[obp++]=(char)0xE0;
197
198 //test ah,40
199 OpBuffer[obp++]=(char)0xF6;
200 OpBuffer[obp++]=(char)0xC4;
201 OpBuffer[obp++]=(char)0x40;
202
203 //jne (endif、または else まで)
204 OpBuffer[obp++]=(char)0x0F;
205 OpBuffer[obp++]=(char)0x85;
206 obp+=sizeof(long);
207
208 //jneの番地
209 i3=obp;
210 }
211 else if(type==DEF_INT64||type==DEF_QWORD){
212 //64ビット型
213
214 //pop eax
215 op_pop(REG_EAX);
216
217 //pop ebx
218 op_pop(REG_EBX);
219
220 //cmp eax,0
221 OpBuffer[obp++]=(char)0x83;
222 OpBuffer[obp++]=(char)0xF8;
223 OpBuffer[obp++]=(char)0x00;
224
225 //jne
226 OpBuffer[obp++]=(char)0x0F;
227 OpBuffer[obp++]=(char)0x85;
228 obp+=sizeof(long);
229 i3=obp;
230
231
232 //cmp ebx,0
233 OpBuffer[obp++]=(char)0x83;
234 OpBuffer[obp++]=(char)0xFB;
235 OpBuffer[obp++]=(char)0x00;
236
237 //jne
238 OpBuffer[obp++]=(char)0x0F;
239 OpBuffer[obp++]=(char)0x85;
240 obp+=sizeof(long);
241 i4=obp;
242
243
244
245 //jmp (endif、または else までジャンプ)
246 OpBuffer[obp++]=(char)0xE9;
247 obp+=sizeof(long);
248
249 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3;
250 *((long *)(OpBuffer+i4-sizeof(long)))=obp-i4;
251
252 //jmpの番地
253 i3=obp;
254 }
255 else{
256 //32ビット型
257
258 //pop eax
259 op_pop(REG_EAX);
260
261 //cmp eax,0
262 OpBuffer[obp++]=(char)0x83;
263 OpBuffer[obp++]=(char)0xF8;
264 OpBuffer[obp++]=(char)0x00;
265
266 //je (endif、または else まで条件ジャンプ)
267 OpBuffer[obp++]=(char)0x0F;
268 OpBuffer[obp++]=(char)0x84;
269 obp+=sizeof(long);
270
271 //jeの番地
272 i3=obp;
273 }
274
275
276 /////////////////////////
277 // If内をコード化
278 /////////////////////////
279
280 //レキシカルスコープをレベルアップ
[34]281 obj_LexScopes.Start( obp, SCOPE_TYPE_IF );
[3]282
283 i2=CompileBuffer(ESC_ENDIF,0);
284
285 //レキシカルスコープをレベルダウン
[34]286 obj_LexScopes.End();
[3]287
288
289 if(i3==-1) return;
290
291 extern char *basbuf;
292 if(i2==ESC_ELSE){
293 //jmp (endifまで)
294 OpBuffer[obp++]=(char)0xE9;
295 obp+=sizeof(long);
296
297 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; //ifからelseへのジャンプ先のオフセット値
298
299 i3=obp;
300
301
302 /////////////////////////
303 // Else内をコード化
304 /////////////////////////
305
306 //レキシカルスコープをレベルアップ
[34]307 obj_LexScopes.Start( obp, SCOPE_TYPE_IF );
[3]308
309 CompileBuffer(ESC_ENDIF,0);
310
311 //レキシカルスコープをレベルダウン
[34]312 obj_LexScopes.End();
[3]313
314
315 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; //jmpジャンプ先のオフセット値
316 }
317 else{
318 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; //jeジャンプ先のオフセット値
319 }
320}
321
322int GetLabelAddress(char *LabelName,int LineNum){
323 extern int MaxLabelNum;
324 extern LABEL *pLabelNames;
325 int i;
326
327 if(LabelName){
328 for(i=0;i<MaxLabelNum;i++){
329 if(pLabelNames[i].pName){
330 if(lstrcmp(LabelName,pLabelNames[i].pName)==0) return pLabelNames[i].address;
331 }
332 }
333 }
334 else{
335 for(i=0;i<MaxLabelNum;i++){
336 if(pLabelNames[i].pName==0){
337 if(LineNum==pLabelNames[i].line) return pLabelNames[i].address;
338 }
339 }
340 }
341 return -1;
342}
343void OpcodeGoto(char *Parameter){
344 extern HANDLE hHeap;
345 extern GOTOLABELSCHEDULE *pGotoLabelSchedule;
346 extern int GotoLabelScheduleNum;
347 int i,LineNum;
348
349 if(Parameter[0]=='*'){
350 i=GetLabelAddress(Parameter+1,0);
351
352 //jmp ...
353 OpBuffer[obp++]=(char)0xE9;
354 if(i==-1){
355 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
356 pGotoLabelSchedule[GotoLabelScheduleNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter+1)+1);
357 lstrcpy(pGotoLabelSchedule[GotoLabelScheduleNum].pName,Parameter+1);
358 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
359 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
360 GotoLabelScheduleNum++;
361 }
362 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
363 obp+=sizeof(long);
364 }
365 else{
366 LineNum=atoi(Parameter);
367 i=GetLabelAddress(0,LineNum);
368
369 //jmp ...
370 OpBuffer[obp++]=(char)0xE9;
371 if(i==-1){
372 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
373 pGotoLabelSchedule[GotoLabelScheduleNum].pName=0;
374 pGotoLabelSchedule[GotoLabelScheduleNum].line=LineNum;
375 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
376 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
377 GotoLabelScheduleNum++;
378 }
379 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
380 obp+=sizeof(long);
381 }
382}
383void OpcodeWhile(char *Parameter){
384 extern HANDLE hHeap;
385 int i2,i3,type;
386
387 //Continueアドレスのバックアップとセット
388 extern DWORD dwContinueAddress;
389 DWORD dwTempContinue;
390 dwTempContinue=dwContinueAddress;
391 dwContinueAddress=obp;
392
393 if(!Parameter[0]) SetError(10,"While",cp);
394 type=NumOpe(Parameter,0,0,0);
395
396 int je_schedule;
397 if(type==DEF_DOUBLE){
398 //fld qword ptr[esp]
399 op_fld_ptr_esp(DEF_DOUBLE);
400
401 //push 0
402 op_push_value(0);
403
404 //fild dword ptr[esp]
405 op_fld_ptr_esp(DEF_LONG);
406
407 //add esp,sizeof(double)+sizeof(long)
408 op_add_esp(sizeof(double)+sizeof(long));
409
410 //fcompp
411 OpBuffer[obp++]=(char)0xDE;
412 OpBuffer[obp++]=(char)0xD9;
413
414 //fnstsw ax
415 OpBuffer[obp++]=(char)0xDF;
416 OpBuffer[obp++]=(char)0xE0;
417
418 //test ah,40
419 OpBuffer[obp++]=(char)0xF6;
420 OpBuffer[obp++]=(char)0xC4;
421 OpBuffer[obp++]=(char)0x40;
422
423 //jne (Wend まで)
424 OpBuffer[obp++]=(char)0x0F;
425 OpBuffer[obp++]=(char)0x85;
426 obp+=sizeof(long);
427
428 //jeの番地
429 je_schedule=obp;
430 }
431 else if(type==DEF_SINGLE){
432 //fld dword ptr[esp]
433 op_fld_ptr_esp(DEF_SINGLE);
434
435 //push 0
436 op_push_value(0);
437
438 //fild dword ptr[esp]
439 op_fld_ptr_esp(DEF_LONG);
440
441 //add esp,sizeof(float)+sizeof(long)
442 op_add_esp(sizeof(float)+sizeof(long));
443
444 //fcompp
445 OpBuffer[obp++]=(char)0xDE;
446 OpBuffer[obp++]=(char)0xD9;
447
448 //fnstsw ax
449 OpBuffer[obp++]=(char)0xDF;
450 OpBuffer[obp++]=(char)0xE0;
451
452 //test ah,40
453 OpBuffer[obp++]=(char)0xF6;
454 OpBuffer[obp++]=(char)0xC4;
455 OpBuffer[obp++]=(char)0x40;
456
457 //jne (Wend まで)
458 OpBuffer[obp++]=(char)0x0F;
459 OpBuffer[obp++]=(char)0x85;
460 obp+=sizeof(long);
461
462 //jeの番地
463 je_schedule=obp;
464 }
465 else if(type==DEF_INT64||type==DEF_QWORD){
466 //64ビット型
467
468 //pop eax
469 op_pop(REG_EAX);
470
471 //pop ebx
472 op_pop(REG_EBX);
473
474 //cmp eax,0
475 OpBuffer[obp++]=(char)0x83;
476 OpBuffer[obp++]=(char)0xF8;
477 OpBuffer[obp++]=(char)0x00;
478
479 //jne
480 OpBuffer[obp++]=(char)0x0F;
481 OpBuffer[obp++]=(char)0x85;
482 obp+=sizeof(long);
483 i2=obp;
484
485
486 //cmp ebx,0
487 OpBuffer[obp++]=(char)0x83;
488 OpBuffer[obp++]=(char)0xFB;
489 OpBuffer[obp++]=(char)0x00;
490
491 //jne
492 OpBuffer[obp++]=(char)0x0F;
493 OpBuffer[obp++]=(char)0x85;
494 obp+=sizeof(long);
495 i3=obp;
496
497
498 //jmp (endif、または else までジャンプ)
499 OpBuffer[obp++]=(char)0xE9;
500 obp+=sizeof(long);
501
502 *((long *)(OpBuffer+i2-sizeof(long)))=obp-i2;
503 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3;
504
505 //jmpの番地
506 je_schedule=obp;
507 }
508 else{
509 //その他整数型
510
511 //pop eax
512 op_pop(REG_EAX);
513
514 //cmp eax,0
515 OpBuffer[obp++]=(char)0x83;
516 OpBuffer[obp++]=(char)0xF8;
517 OpBuffer[obp++]=(char)0x00;
518
519 //je (Wend まで)
520 OpBuffer[obp++]=(char)0x0F;
521 OpBuffer[obp++]=(char)0x84;
522 obp+=sizeof(long);
523
524 //実行中の番地
525 je_schedule=obp;
526 }
527
528 //レキシカルスコープをレベルアップ
[34]529 obj_LexScopes.Start( obp, SCOPE_TYPE_WHILE );
[3]530
531 //While内をコンパイル
532 CompileBuffer(0,COM_WEND);
533
[34]534 obj_LexScopes.CallDestructorsOfScopeEnd();
[3]535
536 //jmp ...
537 OpBuffer[obp++]=(char)0xE9;
538 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long));
539 obp+=sizeof(long);
540
541 //レキシカルスコープをレベルダウン
[34]542 obj_LexScopes.End();
[3]543
544 *((long *)(OpBuffer+je_schedule-sizeof(long)))=obp-je_schedule; //jeジャンプ先のオフセット値
545
546 //Continueアドレスを復元
547 dwContinueAddress=dwTempContinue;
548}
549
550char szNextVariable[VN_SIZE];
551void OpcodeFor(char *Parameter){
552 extern HANDLE hHeap;
553 int i,i2,i3;
554 char temporary[VN_SIZE],variable[VN_SIZE],JudgeNum[VN_SIZE],StepNum[VN_SIZE];
555
556 //第1パラメータを取得
557 i=GetOneParameter(Parameter,0,temporary);
558 if(!Parameter[i]){
559 SetError(12,"For",cp);
560 goto ErrorStep;
561 }
562
563 for(i2=0;;i2++){
564 if(temporary[i2]=='='){
565 variable[i2]=0;
566
567 //カウンタ初期化
568 OpcodeCalc(temporary);
569 break;
570 }
571 if(temporary[i2]=='\0'){
572 SetError(12,"For",cp);
573 goto ErrorStep;
574 }
575 variable[i2]=temporary[i2];
576 }
577
578 //jmp ...
579 OpBuffer[obp++]=(char)0xE9;
580 i2=obp;
581 obp+=sizeof(long);
582
583 //Continueアドレスのバックアップとセット
584 extern DWORD dwContinueAddress;
585 DWORD dwTempContinue;
586 dwTempContinue=dwContinueAddress;
587 dwContinueAddress=obp;
588
589 //第2パラメータを取得(to~)
590 i=GetOneParameter(Parameter,i,JudgeNum);
591
592 //第3パラメータを取得(step~)
593 if(Parameter[i]){
594 i=GetOneParameter(Parameter,i,StepNum);
595 if(Parameter[i]) SetError(12,"For",cp);
596 }
597 else lstrcpy(StepNum,"1");
598
599 //カウンタを増加させる
600 sprintf(temporary,"%s=(%s)+(%s)",variable,variable,StepNum);
601 OpcodeCalc(temporary);
602
603 *((long *)(OpBuffer+i2))=obp-(i2+sizeof(long));
604
605 //増加か減少かを区別する
606 sprintf(temporary,"(%s)>=0",StepNum);
607 NumOpe(temporary,0,0,0);
608
609 //pop eax
610 op_pop(REG_EAX);
611
612 //cmp eax,0
613 OpBuffer[obp++]=(char)0x83;
614 OpBuffer[obp++]=(char)0xF8;
615 OpBuffer[obp++]=(char)0x00;
616
617 //je [カウンタ減少の場合の判定]
618 OpBuffer[obp++]=(char)0x0F;
619 OpBuffer[obp++]=(char)0x84;
620 i2=obp;
621 obp+=sizeof(long);
622
623 //判定(カウンタ増加の場合)
624 sprintf(temporary,"%s<=(%s)",variable,JudgeNum);
625 NumOpe(temporary,0,0,0);
626
627 //pop eax
628 op_pop(REG_EAX);
629
630 //jmp [カウンタ減少の場合の判定を飛び越す]
631 OpBuffer[obp++]=(char)0xE9;
632 i3=obp;
633 obp+=sizeof(long);
634
635 *((long *)(OpBuffer+i2))=obp-(i2+sizeof(long)); //jeジャンプ先のオフセット値
636
637 //判定(カウンタ減少の場合)
638 sprintf(temporary,"%s>=(%s)",variable,JudgeNum);
639 NumOpe(temporary,0,0,0);
640
641 //pop eax
642 op_pop(REG_EAX);
643
644 *((long *)(OpBuffer+i3))=obp-(i3+sizeof(long)); //jmpジャンプ先のオフセット値
645
646 //cmp eax,0
647 OpBuffer[obp++]=(char)0x83;
648 OpBuffer[obp++]=(char)0xF8;
649 OpBuffer[obp++]=(char)0x00;
650
651ErrorStep:
652
653 //je ...
654 OpBuffer[obp++]=(char)0x0F;
655 OpBuffer[obp++]=(char)0x84;
656 int je_schedule=obp;
657 obp+=sizeof(long);
658
659 //レキシカルスコープをレベルアップ
[34]660 obj_LexScopes.Start( obp, SCOPE_TYPE_FOR );
[3]661
662 //For内をコンパイル
663 CompileBuffer(0,COM_NEXT);
664
[34]665 obj_LexScopes.CallDestructorsOfScopeEnd();
[3]666
667 if(szNextVariable[0]){
668 if(lstrcmp(szNextVariable,variable)!=0){
669 SetError(55,szNextVariable,cp);
670 }
671 }
672
673 //jmp ...
674 OpBuffer[obp++]=(char)0xE9;
675 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long));
676 obp+=sizeof(long);
677
678 //レキシカルスコープをレベルダウン
[34]679 obj_LexScopes.End();
[3]680
681 *((long *)(OpBuffer+je_schedule))=obp-(je_schedule+sizeof(long)); //jeジャンプ先のオフセット値
682
683 //Continueアドレスを復元
684 dwContinueAddress=dwTempContinue;
685}
686
687void OpcodeDo(char *Parameter){
688 extern HANDLE hHeap;
689 int i,i2,i3,i4,type;
690
691 if(Parameter[0]) SetError(10,"Do",cp);
692
693 //Continueアドレスのバックアップとセット
694 extern DWORD dwContinueAddress;
695 DWORD dwTempContinue;
696 dwTempContinue=dwContinueAddress;
697 dwContinueAddress=obp;
698
699 //レキシカルスコープをレベルアップ
[34]700 obj_LexScopes.Start( obp, SCOPE_TYPE_DO );
[3]701
702 //Do内をコンパイル
703 CompileBuffer(0,COM_LOOP);
704
[34]705 obj_LexScopes.CallDestructorsOfScopeEnd();
[3]706
707 extern char *basbuf;
708 char temporary[VN_SIZE];
709 for(i=cp-1;;i--){
710 if(IsCommandDelimitation(basbuf[i])){
711 i+=3;
712 if(!(basbuf[i]=='0'||basbuf[i]=='1')){
713 //無条件ループ
714 break;
715 }
716 i3=i;
717
718 for(i+=2,i2=0;;i++,i2++){
719 if(IsCommandDelimitation(basbuf[i])){
720 temporary[i2]=0;
721 break;
722 }
723 temporary[i2]=basbuf[i];
724 }
725
726 type=NumOpe(temporary,0,0,0);
727
728 if(type==DEF_DOUBLE){
729 //fld qword ptr[esp]
730 op_fld_ptr_esp(DEF_DOUBLE);
731
732 //push 0
733 op_push_value(0);
734
735 //fild dword ptr[esp]
736 op_fld_ptr_esp(DEF_LONG);
737
738 //add esp,sizeof(double)+sizeof(long)
739 op_add_esp(sizeof(double)+sizeof(long));
740
741 //fcompp
742 OpBuffer[obp++]=(char)0xDE;
743 OpBuffer[obp++]=(char)0xD9;
744
745 //fnstsw ax
746 OpBuffer[obp++]=(char)0xDF;
747 OpBuffer[obp++]=(char)0xE0;
748
749 //test ah,40
750 OpBuffer[obp++]=(char)0xF6;
751 OpBuffer[obp++]=(char)0xC4;
752 OpBuffer[obp++]=(char)0x40;
753
754 if(basbuf[i3]=='0'){
755 //While
756
757 //jne 5(ループ終了)
758 OpBuffer[obp++]=(char)0x75;
759 OpBuffer[obp++]=(char)0x05;
760 }
761 else if(basbuf[i3]=='1'){
762 //Until
763
764 //je 5(ループ終了)
765 OpBuffer[obp++]=(char)0x74;
766 OpBuffer[obp++]=(char)0x05;
767 }
768 }
769 else if(type==DEF_SINGLE){
770 //fld dword ptr[esp]
771 op_fld_ptr_esp(DEF_SINGLE);
772
773 //push 0
774 op_push_value(0);
775
776 //fild dword ptr[esp]
777 op_fld_ptr_esp(DEF_LONG);
778
779 //add esp,sizeof(float)+sizeof(long)
780 op_add_esp(sizeof(float)+sizeof(long));
781
782 //fcompp
783 OpBuffer[obp++]=(char)0xDE;
784 OpBuffer[obp++]=(char)0xD9;
785
786 //fnstsw ax
787 OpBuffer[obp++]=(char)0xDF;
788 OpBuffer[obp++]=(char)0xE0;
789
790 //test ah,40
791 OpBuffer[obp++]=(char)0xF6;
792 OpBuffer[obp++]=(char)0xC4;
793 OpBuffer[obp++]=(char)0x40;
794
795 if(basbuf[i3]=='0'){
796 //While
797
798 //jne 5(ループ終了)
799 OpBuffer[obp++]=(char)0x75;
800 OpBuffer[obp++]=(char)0x05;
801 }
802 else if(basbuf[i3]=='1'){
803 //Until
804
805 //je 5(ループ終了)
806 OpBuffer[obp++]=(char)0x74;
807 OpBuffer[obp++]=(char)0x05;
808 }
809 }
810 else if(type==DEF_INT64||type==DEF_QWORD){
811 //64ビット型
812
813 //pop eax
814 op_pop(REG_EAX);
815
816 //pop ebx
817 op_pop(REG_EBX);
818
819 //cmp eax,0
820 OpBuffer[obp++]=(char)0x83;
821 OpBuffer[obp++]=(char)0xF8;
822 OpBuffer[obp++]=(char)0x00;
823
824 //jne
825 OpBuffer[obp++]=(char)0x0F;
826 OpBuffer[obp++]=(char)0x85;
827 obp+=sizeof(long);
828 i2=obp;
829
830
831 //cmp ebx,0
832 OpBuffer[obp++]=(char)0x83;
833 OpBuffer[obp++]=(char)0xFB;
834 OpBuffer[obp++]=(char)0x00;
835
836 //jne
837 OpBuffer[obp++]=(char)0x0F;
838 OpBuffer[obp++]=(char)0x85;
839 obp+=sizeof(long);
840 i4=obp;
841
842
843 if(basbuf[i3]=='0'){
844 //While
845
846 //jmp 5(ループ終了)
847 OpBuffer[obp++]=(char)0xEB;
848 OpBuffer[obp++]=(char)0x05;
849
850 *((long *)(OpBuffer+i2-sizeof(long)))=obp-i2;
851 *((long *)(OpBuffer+i4-sizeof(long)))=obp-i4;
852 }
853 else if(basbuf[i3]=='1'){
854 //Until
855
856 //jmp 2(ループを続ける)
857 OpBuffer[obp++]=(char)0xEB;
858 OpBuffer[obp++]=(char)0x02;
859
860 *((long *)(OpBuffer+i2-sizeof(long)))=obp-i2;
861 *((long *)(OpBuffer+i4-sizeof(long)))=obp-i4;
862
863 //jmp 5(ループ終了)
864 OpBuffer[obp++]=(char)0xEB;
865 OpBuffer[obp++]=(char)0x05;
866 }
867 }
868 else{
869 //pop eax
870 op_pop(REG_EAX);
871
872 //cmp eax,0
873 OpBuffer[obp++]=(char)0x83;
874 OpBuffer[obp++]=(char)0xF8;
875 OpBuffer[obp++]=(char)0x00;
876
877 if(basbuf[i3]=='0'){
878 //While
879
880 //je 5(ループ終了)
881 OpBuffer[obp++]=(char)0x74;
882 OpBuffer[obp++]=(char)0x05;
883 }
884 else if(basbuf[i3]=='1'){
885 //Until
886
887 //jne 5(ループ終了)
888 OpBuffer[obp++]=(char)0x75;
889 OpBuffer[obp++]=(char)0x05;
890 }
891 }
892 break;
893 }
894 }
895
896 //jmp ...
897 OpBuffer[obp++]=(char)0xE9;
898 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long));
899 obp+=sizeof(long);
900
901 //jmp ...
902 OpBuffer[obp++]=(char)0xE9;
903 int je_schedule=obp;
904 obp+=sizeof(long);
905
906 //レキシカルスコープをレベルダウン
[34]907 obj_LexScopes.End();
[3]908
909 *((long *)(OpBuffer+je_schedule))=obp-(je_schedule+sizeof(long)); //jmpジャンプ先のオフセット値
910
911
912 //Continueアドレスを復元
913 dwContinueAddress=dwTempContinue;
914}
915void OpcodeContinue(void){
916 extern DWORD dwContinueAddress;
917
918 if(dwContinueAddress==-1){
919 SetError(12,"Continue",cp);
920 return;
921 }
922
923 //jmp ...(Continue addr)
924 OpBuffer[obp++]=(char)0xE9;
925
926 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long));
927 obp+=sizeof(long);
928}
929
930void OpcodeExitSub(void){
931 extern DWORD *pExitSubSchedule;
932 extern int ExitSubScheduleNum;
933 extern HANDLE hHeap;
934
935 extern BOOL bCompilingGlobal;
936 if(bCompilingGlobal){
937 SetError(12,"Exit Sub/Function",cp);
938 return;
939 }
940
[34]941 //未解放のローカルオブジェクトのデストラクタを呼び出す
942 obj_LexScopes.CallDestructorsOfReturn();
943
[3]944 //jmp ...(End Sub/Function)
945 OpBuffer[obp++]=(char)0xE9;
946
947 pExitSubSchedule=(DWORD *)HeapReAlloc(hHeap,0,pExitSubSchedule,(ExitSubScheduleNum+1)*sizeof(DWORD));
948 pExitSubSchedule[ExitSubScheduleNum]=obp;
949 ExitSubScheduleNum++;
950
951 obp+=sizeof(long);
952}
953
954void AddCaseSchedule(void){
955 extern DWORD *pCaseSchedule;
956 extern int CaseScheduleNum;
957 extern HANDLE hHeap;
958
959 pCaseSchedule=(DWORD *)HeapReAlloc(hHeap,0,pCaseSchedule,(CaseScheduleNum+1)*sizeof(DWORD));
960 pCaseSchedule[CaseScheduleNum]=obp;
961 CaseScheduleNum++;
962}
963
964int CaseTypeSize;
965void OpcodeSelect(char *Parameter){
966 extern DWORD *pCaseSchedule;
967 extern int CaseScheduleNum;
968 extern int NowCaseSchedule;
969 extern int CaseTypeSize;
970 extern HANDLE hHeap;
971 extern char *basbuf;
972 int i,i2,i3,sw,type1,type2,NowCaseCp;
973 char temporary[VN_SIZE];
974
975 DWORD *temp_pCaseSchedule;
976 int temp_CaseScheduleNum;
977 int temp_NowCaseSchedule;
978 int temp_CaseTypeSize;
979
980 temp_pCaseSchedule=pCaseSchedule;
981 temp_CaseScheduleNum=CaseScheduleNum;
982 temp_NowCaseSchedule=NowCaseSchedule;
983 temp_CaseTypeSize=CaseTypeSize;
984 pCaseSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
985 CaseScheduleNum=0;
986 NowCaseSchedule=0;
987
988 LONG_PTR lpIndex;
989 type1=NumOpe(Parameter,0,0,&lpIndex);
990 if(type1==DEF_INTEGER||
991 type1==DEF_WORD||
[55]992 type1==DEF_SBYTE||
[36]993 type1==DEF_BYTE||
[55]994 type1==DEF_BOOLEAN||
995 type1==DEF_CHAR) CaseTypeSize=sizeof(long);
[3]996 else{
997 CaseTypeSize=GetTypeSize(type1,lpIndex);
998 if(type1==DEF_OBJECT) CaseTypeSize=PTR_SIZE;
999 }
1000
1001 for(i=cp,sw=0;;i++){
1002 if(basbuf[i]=='\0'){
1003 HeapDefaultFree(pCaseSchedule);
1004 pCaseSchedule=temp_pCaseSchedule;
1005 CaseScheduleNum=temp_CaseScheduleNum;
1006 NowCaseSchedule=temp_NowCaseSchedule;
1007 CaseTypeSize=temp_CaseTypeSize;
1008 SetError(22,"Select",cp);
1009 return;
1010 }
1011 if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE){
1012 for(i2=0;;i++){
1013 if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE) i2++;
1014 if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){
1015 i2--;
1016 if(i2==0) break;
1017 }
1018 }
1019 continue;
1020 }
1021 if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){
1022 if(sw==0){
1023 //add esp,CaseTypeSize
1024 op_add_esp(CaseTypeSize);
1025 }
1026 break;
1027 }
1028 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASE){
1029 NowCaseCp=i;
1030
1031 i++;
1032 while(1){
1033 for(i++,i2=0;;i++,i2++){
1034 if(basbuf[i]=='\"'){
1035 i3=GetStringInQuotation(temporary+i2,basbuf+i);
1036 i+=i3-1;
1037 i2+=i3-1;
1038 continue;
1039 }
1040 if(basbuf[i]=='('){
1041 i3=GetStringInPare(temporary+i2,basbuf+i);
1042 i+=i3-1;
1043 i2+=i3-1;
1044 continue;
1045 }
1046 if(basbuf[i]=='['){
1047 i3=GetStringInBracket(temporary+i2,basbuf+i);
1048 i+=i3-1;
1049 i2+=i3-1;
1050 continue;
1051 }
1052
1053 if(IsCommandDelimitation(basbuf[i])){
1054 temporary[i2]=0;
1055 break;
1056 }
1057 if(basbuf[i]==','){
1058 temporary[i2]=0;
1059 break;
1060 }
1061
1062 temporary[i2]=basbuf[i];
1063 }
1064
1065 //エラー用
1066 i2=cp;
1067 cp=NowCaseCp;
1068
1069 LONG_PTR lpIndex2;
1070 type2=NumOpe(temporary,type1,lpIndex,&lpIndex2);
1071
1072 cp=i2;
1073
1074 if(type1==DEF_OBJECT){
1075 CClass *pobj_c;
1076 pobj_c=(CClass *)lpIndex;
1077
[50]1078 std::vector<SUBINFO *> subs;
1079 pobj_c->EnumMethod( CALC_EQUAL, subs );
1080 if( subs.size() == 0 ){
[3]1081 return;
1082 }
1083
[31]1084 PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3);
[3]1085 int iParmNum=0;
1086 ppi[iParmNum].bArray=0;
1087 ppi[iParmNum].bByVal=0;
1088 ppi[iParmNum].name=0;
1089 ppi[iParmNum].type=type2;
1090 ppi[iParmNum].u.index=lpIndex2;
1091 ppi[iParmNum].SubScripts[0]=-1;
1092 iParmNum++;
1093
1094 //オーバーロードを解決
1095 SUBINFO *psi;
[50]1096 psi=OverloadSolution("==",subs,ppi,iParmNum,NULL);
[3]1097 HeapDefaultFree(ppi);
1098
1099 if(!psi){
1100 //エラー
1101 return;
1102 }
1103
1104
1105 //pop edx
1106 op_pop(REG_EDX);
1107
1108 //mov ecx,dword ptr[esp]
1109 op_mov_RM(sizeof(long),REG_ECX,REG_ESP,0,MOD_BASE);
1110
1111 //push edx
1112 op_push(REG_EDX);
1113
1114 //push ecx
1115 op_push(REG_ECX);
1116
1117 //call operator_proc ※ ==演算子
1118 op_call(psi);
1119
1120 //test eax,eax
1121 op_test(REG_EAX,REG_EAX);
1122
1123 //jne ...
1124 OpBuffer[obp++]=(char)0x0F;
1125 OpBuffer[obp++]=(char)0x85;
1126 AddCaseSchedule();
1127 obp+=sizeof(long);
1128 }
1129 else if(type1==DEF_DOUBLE){
1130 ChangeTypeToDouble(type2);
1131
1132 //fld qword ptr[esp]
1133 op_fld_ptr_esp(DEF_DOUBLE);
1134
1135 //add esp,CaseTypeSize
1136 op_add_esp(CaseTypeSize);
1137
1138 //fld qword ptr[esp]
1139 op_fld_ptr_esp(DEF_DOUBLE);
1140
1141 //fcompp
1142 OpBuffer[obp++]=(char)0xDE;
1143 OpBuffer[obp++]=(char)0xD9;
1144
1145 //fnstsw ax
1146 OpBuffer[obp++]=(char)0xDF;
1147 OpBuffer[obp++]=(char)0xE0;
1148
1149 //test ah,40
1150 OpBuffer[obp++]=(char)0xF6;
1151 OpBuffer[obp++]=(char)0xC4;
1152 OpBuffer[obp++]=(char)0x40;
1153
1154 //jne ...
1155 OpBuffer[obp++]=(char)0x0F;
1156 OpBuffer[obp++]=(char)0x85;
1157 AddCaseSchedule();
1158 obp+=sizeof(long);
1159 }
1160 else if(type1==DEF_SINGLE){
1161 ChangeTypeToSingle(type2);
1162
1163 //fld dword ptr[esp]
1164 op_fld_ptr_esp(DEF_SINGLE);
1165
1166 //add esp,CaseTypeSize
1167 op_add_esp(CaseTypeSize);
1168
1169 //fld dword ptr[esp]
1170 op_fld_ptr_esp(DEF_SINGLE);
1171
1172 //fcompp
1173 OpBuffer[obp++]=(char)0xDE;
1174 OpBuffer[obp++]=(char)0xD9;
1175
1176 //fnstsw ax
1177 OpBuffer[obp++]=(char)0xDF;
1178 OpBuffer[obp++]=(char)0xE0;
1179
1180 //test ah,40
1181 OpBuffer[obp++]=(char)0xF6;
1182 OpBuffer[obp++]=(char)0xC4;
1183 OpBuffer[obp++]=(char)0x40;
1184
1185 //jne ...
1186 OpBuffer[obp++]=(char)0x0F;
1187 OpBuffer[obp++]=(char)0x85;
1188 AddCaseSchedule();
1189 obp+=sizeof(long);
1190 }
1191 else{
1192 //その他整数型
1193
1194 //pop ebx
1195 op_pop(REG_EBX);
1196
1197 //mov eax,dword ptr[esp]
1198 OpBuffer[obp++]=(char)0x8B;
1199 OpBuffer[obp++]=(char)0x04;
1200 OpBuffer[obp++]=(char)0x24;
1201
1202 //cmp eax,ebx
1203 OpBuffer[obp++]=(char)0x3B;
1204 OpBuffer[obp++]=(char)0xC3;
1205
1206 //je ...
1207 OpBuffer[obp++]=(char)0x0F;
1208 OpBuffer[obp++]=(char)0x84;
1209 AddCaseSchedule();
1210 obp+=sizeof(long);
1211 }
1212
1213 if(basbuf[i]!=',') break;
1214 }
1215 }
1216 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){
1217 sw=1;
1218
1219 //jmp ...
1220 OpBuffer[obp++]=(char)0xE9;
1221 AddCaseSchedule();
1222 obp+=sizeof(long);
1223 }
1224 }
1225
1226 //レキシカルスコープをレベルアップ
[34]1227 obj_LexScopes.Start( obp, SCOPE_TYPE_SELECT );
[3]1228
1229 //Select Case内をコンパイル
1230 CompileBuffer(ESC_ENDSELECT,0);
1231
1232 //jmp EndSelect
1233 OpBuffer[obp++]=(char)0xE9;
1234 AddCaseSchedule();
1235 obp+=sizeof(long);
1236
1237 //最終スケジュール
1238 for(i=NowCaseSchedule;i<CaseScheduleNum;i++){
1239 *(long *)(OpBuffer+pCaseSchedule[i])=obp-(pCaseSchedule[i]+sizeof(long));
1240 }
1241 HeapDefaultFree(pCaseSchedule);
1242
1243 //レキシカルスコープをレベルダウン
[34]1244 obj_LexScopes.End();
[3]1245
1246 pCaseSchedule=temp_pCaseSchedule;
1247 CaseScheduleNum=temp_CaseScheduleNum;
1248 NowCaseSchedule=temp_NowCaseSchedule;
1249 CaseTypeSize=temp_CaseTypeSize;
1250}
1251void OpcodeCase(char *Parameter){
1252 extern DWORD *pCaseSchedule;
1253 extern int NowCaseSchedule;
1254 extern int CaseTypeSize;
1255 int i;
1256
1257 if(!pCaseSchedule){
1258 SetError(30,"Case",cp);
1259 return;
1260 }
1261
1262 //jmp EndSelect
1263 OpBuffer[obp++]=(char)0xE9;
1264 AddCaseSchedule();
1265 obp+=sizeof(long);
1266
1267 i=0;
1268 while(1){
1269 //Caseスケジュール
1270 *(long *)(OpBuffer+pCaseSchedule[NowCaseSchedule])=obp-(pCaseSchedule[NowCaseSchedule]+sizeof(long));
1271 NowCaseSchedule++;
1272
1273 i=JumpOneParameter(Parameter,i);
1274 if(Parameter[i]=='\0') break;
1275 }
1276
1277 //add esp,CaseTypeSize
1278 op_add_esp(CaseTypeSize);
1279}
1280
1281void OpcodeGosub(char *Parameter){
1282 extern HANDLE hHeap;
1283 extern GOTOLABELSCHEDULE *pGotoLabelSchedule;
1284 extern int GotoLabelScheduleNum;
1285 int i,LineNum;
1286
1287 if(Parameter[0]=='*'){
1288 i=GetLabelAddress(Parameter+1,0);
1289
1290 //call ...
1291 OpBuffer[obp++]=(char)0xE8;
1292 if(i==-1){
1293 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
1294 pGotoLabelSchedule[GotoLabelScheduleNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter+1)+1);
1295 lstrcpy(pGotoLabelSchedule[GotoLabelScheduleNum].pName,Parameter+1);
1296 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
1297 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
1298 GotoLabelScheduleNum++;
1299 }
1300 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
1301 obp+=sizeof(long);
1302 }
1303 else{
1304 LineNum=atoi(Parameter);
1305 i=GetLabelAddress(0,LineNum);
1306
1307 //call ...
1308 OpBuffer[obp++]=(char)0xE8;
1309 if(i==-1){
1310 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
1311 pGotoLabelSchedule[GotoLabelScheduleNum].pName=0;
1312 pGotoLabelSchedule[GotoLabelScheduleNum].line=LineNum;
1313 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
1314 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
1315 GotoLabelScheduleNum++;
1316 }
1317 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
1318 obp+=sizeof(long);
1319 }
1320}
1321void OpcodeReturn(char *Parameter){
1322 extern BOOL bCompilingGlobal;
1323 if(bCompilingGlobal){
1324 //Gosub~Returnとして扱う
1325
1326 //ret
1327 OpBuffer[obp++]=(char)0xC3;
1328 }
1329 else{
1330 //戻り値をセット
1331 if(Parameter[0]){
1332 extern SUBINFO *pCompilingSubInfo;
1333 char *temp;
1334 if(pCompilingSubInfo->name[0]==1&&pCompilingSubInfo->name[1]==ESC_OPERATOR)
1335 temp="_System_ReturnValue";
1336 else temp=pCompilingSubInfo->name;
1337
[40]1338 if( pCompilingSubInfo->isReturnRef ){
1339 //参照型
1340 SetRefVariable( temp, Parameter );
1341 }
1342 else{
1343 //値型
1344 char temporary[VN_SIZE];
1345 sprintf(temporary,"%s=%s",temp,Parameter);
1346 OpcodeCalc(temporary);
1347 }
[3]1348 }
1349
1350 //プロシージャを抜け出す(C言語のreturnと同様の処理を行う)
1351 OpcodeExitSub();
1352 }
1353}
1354
1355void Opcode_Input(char *Parameter){
1356 extern int cp;
1357 int i2,i3,i4,i5,type;
1358 BOOL bFile;
1359 char temporary[VN_SIZE],temp2[VN_SIZE],buffer[VN_SIZE];
1360
1361 KillStringSpaces(Parameter);
1362
1363 if(Parameter[0]=='#'){
1364 bFile=1;
1365 for(i2=0,i3=1;;i2++,i3++){
1366 buffer[i2]=Parameter[i3];
1367 if(Parameter[i3]==','||Parameter[i3]=='\0') break;
1368 }
1369 buffer[i2+1]=0;
1370 i2=i3+1;
1371 }
1372 else{
1373 bFile=0;
1374 i2=0;
1375 buffer[0]=0;
1376
1377 //表示用文字列パラメータをセット
1378 if(Parameter[0]=='\"'){
1379 buffer[0]='\"';
1380 for(i2=1;;i2++){
1381 if(Parameter[i2]=='\"'){
1382 buffer[i2]=0;
1383 break;
1384 }
1385 buffer[i2]=Parameter[i2];
1386 }
1387 if(Parameter[i2+1]==';') lstrcpy(buffer+i2,"? \"");
1388 else if(Parameter[i2+1]==',') lstrcpy(buffer+i2,"\"");
1389 else SetError(10,"Input",cp);
1390 i2+=2;
1391 }
1392 else if((Parameter[0]=='e'||Parameter[0]=='E')&&
1393 (Parameter[1]=='x'||Parameter[1]=='X')&&
1394 Parameter[2]=='\"'){
1395 memcpy(buffer,Parameter,3);
1396 for(i2=3;;i2++){
1397 if(Parameter[i2]=='\"'){
1398 buffer[i2]=0;
1399 break;
1400 }
1401 buffer[i2]=Parameter[i2];
1402 }
1403 if(Parameter[i2+1]==';') lstrcpy(buffer+i2,"? \"");
1404 else if(Parameter[i2+1]==',') lstrcpy(buffer+i2,"\"");
1405 else SetError(10,"Input",cp);
1406 i2+=2;
1407 }
1408 else{
1409 lstrcpy(buffer,"\"? \"");
1410 i2=0;
1411 }
1412 }
1413
1414 //変数ポインタ、変数のタイプをセット
1415 i4=0;
1416 while(1){
1417 for(i3=0;;i2++,i3++){
1418 if(Parameter[i2]=='('){
1419 i5=GetStringInPare(temporary+i3,Parameter+i2);
1420 i2+=i5-1;
1421 i3+=i5-1;
1422 }
1423 if(Parameter[i2]=='['){
1424 i5=GetStringInBracket(temporary+i3,Parameter+i2);
1425 i2+=i5-1;
1426 i3+=i5-1;
1427 }
1428 if(Parameter[i2]==','){
1429 temporary[i3]=0;
1430 i2++;
1431 break;
1432 }
1433 temporary[i3]=Parameter[i2];
1434 if(Parameter[i2]=='\0') break;
1435 }
1436 if(temporary[0]=='\0'){
1437 SetError(10,"Input",cp);
1438 return;
1439 }
1440
1441 LONG_PTR lpIndex;
[11]1442 type = GetVarType(temporary,&lpIndex,1);
[3]1443
1444 sprintf(temp2,"_System_InputDataPtr[%d]=VarPtr(%s)",i4,temporary);
1445 OpcodeCalc(temp2);
1446
1447 if(type==DEF_LONG) type=DEF_DWORD;
1448 else if(type==DEF_INTEGER) type=DEF_WORD;
1449 else if(type==DEF_OBJECT){
1450 CClass *pobj_Class=(CClass *)lpIndex;
1451 if(lstrcmp(pobj_Class->name,"String")==0) type=DEF_STRING;
1452 }
1453 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,type);
1454 OpcodeCalc(temp2);
1455
1456 i4++;
1457 if(Parameter[i2]=='\0') break;
1458 }
1459 sprintf(temp2,"_System_InputDataPtr[%d]=0",i4);
1460 OpcodeCalc(temp2);
1461
1462 SUBINFO *psi;
1463 if(bFile) psi=GetSubHash("INPUT_FromFile");
1464 else psi=GetSubHash("INPUT_FromPrompt");
1465 if(!psi){
1466 SetError(3,"Input",cp);
1467 return;
1468 }
[31]1469 Opcode_CallProc(buffer,psi,0,"",0);
[3]1470}
1471void Opcode_PrintUsing(char *Parameter,char *buffer,BOOL bFile){
1472 extern int cp;
1473 int i2,i3,i4,i5;
1474 char temporary[VN_SIZE],temp2[8192];
1475 BOOL bReturnLine;
1476
1477 i2=lstrlen(Parameter);
1478 if(Parameter[i2-1]==';'){
1479 bReturnLine=0;
1480 Parameter[i2-1]=0;
1481 }
1482 else bReturnLine=1;
1483
1484 i3=lstrlen(buffer);
1485 for(i2=0;;i2++,i3++){
1486 if(Parameter[i2]==';'){
1487 buffer[i3]=0;
1488 break;
1489 }
1490 buffer[i3]=Parameter[i2];
1491 if(Parameter[i2]=='\0') break;
1492 }
1493 if(Parameter[i2]==';') i2++;
1494
1495 if(bReturnLine) lstrcat(buffer,"+Ex\"\\r\\n\"");
1496
1497 //データポインタ、データのタイプをセット
1498 i4=0;
1499 while(1){
1500 for(i3=0;;i2++,i3++){
1501 if(Parameter[i2]=='\"'){
1502 temporary[i3]=Parameter[i2];
1503 for(i2++,i3++;;i2++,i3++){
1504 temporary[i3]=Parameter[i2];
1505 if(Parameter[i2]=='\"') break;
1506 }
1507 continue;
1508 }
1509 if(Parameter[i2]=='('){
1510 i5=GetStringInPare(temporary+i3,Parameter+i2);
1511 i2+=i5-1;
1512 i3+=i5-1;
1513 continue;
1514 }
1515 if(Parameter[i2]=='['){
1516 i5=GetStringInBracket(temporary+i3,Parameter+i2);
1517 i2+=i5-1;
1518 i3+=i5-1;
1519 continue;
1520 }
1521 if(Parameter[i2]==','){
1522 temporary[i3]=0;
1523 i2++;
1524 break;
1525 }
1526 temporary[i3]=Parameter[i2];
1527 if(Parameter[i2]=='\0') break;
1528 }
1529 if(temporary[0]=='\0'){
1530 SetError(10,"Print",cp);
1531 return;
1532 }
1533
1534 int iResult;
1535 iResult=IsStrCalculation(temporary);
1536
1537 if(iResult==1){
1538 //文字列
1539 sprintf(temp2,"_System_UsingStrData[%d]=%s",i4,temporary);
1540 OpcodeCalc(temp2);
1541
1542 sprintf(temp2,"_System_UsingDataType[%d]=%d",i4,DEF_STRING);
1543 OpcodeCalc(temp2);
1544 }
1545 else if(iResult==0){
1546 //数値
1547 sprintf(temp2,"_System_UsingDblData[%d]=%s",i4,temporary);
1548 OpcodeCalc(temp2);
1549
1550 sprintf(temp2,"_System_UsingDataType[%d]=%d",i4,DEF_DOUBLE);
1551 OpcodeCalc(temp2);
1552 }
1553 //else if(iResult==-1) エラー
1554
1555 i4++;
1556 if(Parameter[i2]=='\0') break;
1557 }
1558 sprintf(temp2,"_System_UsingDataType[%d]=-1",i4);
1559 OpcodeCalc(temp2);
1560
1561 SUBINFO *psi;
1562 if(bFile) psi=GetSubHash("PRINTUSING_ToFile");
1563 else psi=GetSubHash("PRINTUSING_ToPrompt");
1564 if(!psi){
1565 SetError(3,"Print",cp);
1566 return;
1567 }
[31]1568 Opcode_CallProc(buffer,psi,0,"",0);
[3]1569}
1570void Opcode_Print(char *Parameter,BOOL bWrite){
1571 int i2,i3,i4,sw;
1572 char temporary[VN_SIZE],buffer[VN_SIZE];
1573 BOOL bFile;
1574
1575 KillStringSpaces(Parameter);
1576
1577 if(Parameter[0]=='#'){
1578 bFile=1;
1579 for(i2=0,i3=1;;i2++,i3++){
1580 buffer[i2]=Parameter[i3];
1581 if(Parameter[i3]==','||Parameter[i3]=='\0') break;
1582 }
1583 buffer[i2+1]=0;
1584 if(Parameter[i3]==',') i3++;
1585 i2=i3;
1586 }
1587 else{
1588 bFile=0;
1589 i2=0;
1590 buffer[0]=0;
1591 }
1592 if(Parameter[i2]==1&&Parameter[i2+1]==ESC_USING){
1593 Opcode_PrintUsing(Parameter+i2+2,buffer,bFile);
1594 return;
1595 }
1596
1597 lstrcat(buffer,"_System_DummyStr+");
1598
1599 sw=1;
1600 while(1){
1601 for(i3=0;;i2++,i3++){
1602 if(Parameter[i2]=='\"'){
1603 temporary[i3]=Parameter[i2];
1604 for(i2++,i3++;;i2++,i3++){
1605 temporary[i3]=Parameter[i2];
1606 if(Parameter[i2]=='\"') break;
1607 }
1608 continue;
1609 }
1610 if(Parameter[i2]=='('){
1611 i4=GetStringInPare(temporary+i3,Parameter+i2);
1612 i2+=i4-1;
1613 i3+=i4-1;
1614 continue;
1615 }
1616 if(Parameter[i2]=='['){
1617 i4=GetStringInBracket(temporary+i3,Parameter+i2);
1618 i2+=i4-1;
1619 i3+=i4-1;
1620 continue;
1621 }
1622 if(Parameter[i2]==','||Parameter[i2]==';'){
1623 temporary[i3]=0;
1624 break;
1625 }
1626 temporary[i3]=Parameter[i2];
1627 if(Parameter[i2]=='\0') break;
1628 }
1629
1630 if(temporary[0]=='\0') lstrcat(buffer,"\"\"");
1631 else{
1632 int iResult;
1633 iResult=IsStrCalculation(temporary);
1634 if(iResult==-1){
1635 //エラー
1636 lstrcat(buffer,"\"\"");
1637 }
1638 else if(iResult){
1639 //文字列
1640 lstrcat(buffer,temporary);
1641 }
1642 else{
1643 //数値
1644 sprintf(buffer+lstrlen(buffer),"Str$(%s)",temporary);
1645 }
1646 }
1647
1648 if(Parameter[i2]==','){
1649 if(bWrite) lstrcat(buffer,"+\",\"+");
1650 else lstrcat(buffer,"+\"\t\"+");
1651 }
1652 else if(Parameter[i2]==';'){
1653 if(Parameter[i2+1]=='\0'){
1654 sw=0;
1655 break;
1656 }
1657 if(bWrite) lstrcat(buffer,"+\",\"+");
1658 else lstrcat(buffer,"+\" \"+");
1659 }
1660 else if(Parameter[i2]=='\0') break;
1661
1662 i2++;
1663 }
1664
1665 if(sw) lstrcat(buffer,"+Ex\"\\r\\n\"");
1666
1667 SUBINFO *psi;
1668 if(bFile) psi=GetSubHash("PRINT_ToFile");
1669 else psi=GetSubHash("PRINT_ToPrompt");
1670 if(!psi){
1671 SetError(3,"Print",cp);
1672 return;
1673 }
[31]1674 Opcode_CallProc(buffer,psi,0,"",0);
[3]1675}
1676
1677
1678
1679
1680////////////
1681// ポインタ
1682
1683void OpcodeCallPtr(char *Parameter){
1684 extern HANDLE hHeap;
1685 int i,i2,i3,num,types[255];
1686 BOOL bCdecl;
1687 char szFuncPtr[VN_SIZE],temporary[VN_SIZE],*Parms[255];
1688
1689 //関数ポインタを取得
1690 i=GetOneParameter(Parameter,0,szFuncPtr);
1691
1692 if(lstrcmpi(szFuncPtr,"cdecl")==0){
1693 //cdeclが指定された場合は、第2パラメータを関数ポインタとして扱う
1694 bCdecl=1;
1695
1696 i=GetOneParameter(Parameter,i,szFuncPtr);
1697 }
1698 else bCdecl=0;
1699
1700 if(Parameter[0]=='\0'){
1701 SetError(10,"CallPtr",cp);
1702 }
1703
1704 num=0;
1705 while(Parameter[i]){
1706 i=GetOneParameter(Parameter,i,temporary);
1707
1708 types[num]=DEF_LONG;
1709
1710 for(i2=0;;i2++){
1711 if(temporary[i2]=='\0') break;
1712 if(temporary[i2]==1&&temporary[i2+1]==ESC_AS){
1713 LONG_PTR lp;
1714 types[num]=GetTypeFixed(temporary+i2+2,&lp);
1715
1716 if(types[num]==DEF_OBJECT){
1717 SetError(11,temporary+i2+2,cp);
1718 }
1719
1720 temporary[i2]=0;
1721 break;
1722 }
1723 }
1724
1725 Parms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
1726 lstrcpy(Parms[num],temporary);
1727
1728 num++;
1729 }
1730
1731 int ParmSize=0;
1732
1733 for(i=num-1;i>=0;i--){
1734 //スタックへプッシュ
1735 i3=NumOpe(Parms[i],0,0,0);
1736
1737 switch(types[i]){
1738 case DEF_INT64:
1739 case DEF_QWORD:
1740 ChangeTypeToInt64(i3);
1741 break;
1742 case DEF_SINGLE:
1743 ChangeTypeToSingle(i3);
1744 break;
1745 case DEF_DOUBLE:
1746 ChangeTypeToDouble(i3);
1747 break;
1748
1749 default:
1750 ChangeTypeToLong(i3);
1751 break;
1752 }
1753
1754 ParmSize+=GetTypeSize(types[i],0);
1755
1756 HeapDefaultFree(Parms[i]);
1757 }
1758
1759 i3=NumOpe(szFuncPtr,0,0,0);
1760 ChangeTypeToLong(i3);
1761
1762 //pop eax
1763 op_pop(REG_EAX);
1764
1765 //call eax
1766 OpBuffer[obp++]=(char)0xFF;
1767 OpBuffer[obp++]=(char)0xD0;
1768
1769 if(bCdecl){
1770 //スタックを戻す
1771
1772 //add esp,ParmSize
1773 op_add_esp(ParmSize);
1774 }
1775}
1776
1777void OpcodeSetPtrData(char *Parameter,int type){
1778 int i,i2;
1779 char temporary[VN_SIZE];
1780
1781 if(Parameter[0]=='('){
1782 i=JumpStringInPare(Parameter,1);
1783 if(Parameter[i+1]=='\0'){
1784 for(i=0;;i++){
1785 Parameter[i]=Parameter[i+1];
1786 if(Parameter[i]=='\0') break;
1787 }
1788 Parameter[i-1]=0;
1789 }
1790 }
1791
1792 //第1パラメータを取得
1793 i=GetOneParameter(Parameter,0,temporary);
1794 if(!Parameter[i]){
1795 SetError(1,NULL,cp);
1796 return;
1797 }
1798
1799 i2=NumOpe(temporary,0,0,0);
1800 ChangeTypeToLong(i2);
1801
1802 //第2パラメータを取得
1803 i=GetOneParameter(Parameter,i,temporary);
1804 if(Parameter[i]){
1805 SetError(1,NULL,cp);
1806 return;
1807 }
1808
1809 i2=NumOpe(temporary,0,0,0);
1810 if(type==DEF_DOUBLE){
1811 ChangeTypeToDouble_ToFpuReg(i2);
1812
1813 //pop eax
1814 op_pop(REG_EAX);
1815
1816 //fstp qword ptr[eax]
1817 OpBuffer[obp++]=(char)0xDD;
1818 OpBuffer[obp++]=(char)0x18;
1819 }
1820 else if(type==DEF_SINGLE){
1821 ChangeTypeToSingle(i2);
1822
1823 //pop ebx
1824 op_pop(REG_EBX);
1825
1826 //pop eax
1827 op_pop(REG_EAX);
1828
1829 //mov dword ptr[eax],ebx
1830 OpBuffer[obp++]=(char)0x89;
1831 OpBuffer[obp++]=(char)0x18;
1832 }
1833 else if(type==DEF_QWORD){
1834 ChangeTypeToInt64(i2);
1835
1836 //pop ecx
1837 op_pop(REG_ECX);
1838
1839 //pop ebx
1840 op_pop(REG_EBX);
1841
1842 //pop eax
1843 op_pop(REG_EAX);
1844
1845 //mov dword ptr[eax],ecx
1846 OpBuffer[obp++]=(char)0x89;
1847 OpBuffer[obp++]=(char)0x08;
1848
1849 //mov dword ptr[eax+sizeof(long)],ebx
1850 OpBuffer[obp++]=(char)0x89;
1851 OpBuffer[obp++]=(char)0x58;
1852 OpBuffer[obp++]=(char)0x04;
1853 }
1854 else if(type==DEF_DWORD){
1855 ChangeTypeToLong(i2);
1856
1857 //pop ebx
1858 op_pop(REG_EBX);
1859
1860 //pop eax
1861 op_pop(REG_EAX);
1862
1863 //mov dword ptr[eax],ebx
1864 OpBuffer[obp++]=(char)0x89;
1865 OpBuffer[obp++]=(char)0x18;
1866 }
1867 else if(type==DEF_WORD){
1868 ChangeTypeToLong(i2);
1869
1870 //pop ebx
1871 op_pop(REG_EBX);
1872
1873 //pop eax
1874 op_pop(REG_EAX);
1875
1876 //mov word ptr[eax],bx
1877 OpBuffer[obp++]=(char)0x66;
1878 OpBuffer[obp++]=(char)0x89;
1879 OpBuffer[obp++]=(char)0x18;
1880 }
1881 else if(type==DEF_BYTE){
1882 ChangeTypeToLong(i2);
1883
1884 //pop ebx
1885 op_pop(REG_EBX);
1886
1887 //pop eax
1888 op_pop(REG_EAX);
1889
1890 //mov byte ptr[eax],bl
1891 OpBuffer[obp++]=(char)0x88;
1892 OpBuffer[obp++]=(char)0x18;
1893 }
1894}
Note: See TracBrowser for help on using the repository browser.