source: dev/BasicCompiler32/Compile_Statement.cpp@ 47

Last change on this file since 47 was 40, checked in by dai_9181, 18 years ago

ByRef修飾子を関数戻り値とDimステートメントで指定可能にした。

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