source: dev/BasicCompiler64/Compile_Statement.cpp@ 19

Last change on this file since 19 was 11, checked in by dai_9181, 18 years ago

Const変数の書き込み規制を有効化(グローバル/ローカル変数のみ)
定数オブジェクトと定数メンバは未実装。

File size: 33.6 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,"",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_OBJECT){
103 CClass *pobj_Class;
104 pobj_Class=(CClass *)lp;
105
106 //mov r14,rax
107 op_mov_RR(REG_R14,REG_RAX);
108
109 FreeTempObject(REG_R14,pobj_Class);
110 }
111 return;
112 }
113
114
115 //////////////////////////
116 // その他は代入演算を行う
117 //////////////////////////
118 OpcodeCalc(Command);
119}
120
121void Judgment(char *buffer){
122 int reg=REG_RAX,type;
123 type=NumOpe(&reg,buffer,0,0,0);
124
125 int offset;
126
127 if(type==DEF_DOUBLE){
128 double dbl=0;
129 offset=AddDataTable((char *)&dbl,sizeof(double));
130
131 //comisd xmm0,qword ptr[data table offset]
132 OpBuffer[obp++]=(char)0x66;
133 OpBuffer[obp++]=(char)0x0F;
134 OpBuffer[obp++]=(char)0x2F;
135 OpBuffer[obp++]=(char)0x04;
136 OpBuffer[obp++]=(char)0x25;
137 *((long *)(OpBuffer+obp))=offset;
138 pobj_DataTableSchedule->add();
139 obp+=sizeof(long);
140 }
141 else if(type==DEF_SINGLE){
142 float flt=0;
143 offset=AddDataTable((char *)&flt,sizeof(float));
144
145 //comiss xmm0,dword ptr[data table offset]
146 OpBuffer[obp++]=(char)0x0F;
147 OpBuffer[obp++]=(char)0x2F;
148 OpBuffer[obp++]=(char)0x04;
149 OpBuffer[obp++]=(char)0x25;
150 *((long *)(OpBuffer+obp))=offset;
151 pobj_DataTableSchedule->add();
152 obp+=sizeof(long);
153 }
154 else{
155 //整数型
156
157 //cmp rax,0
158 op_cmp_value(GetTypeSize(type,-1),REG_RAX,0);
159 }
160}
161
162void OpcodeIf(char *Parameter){
163 int i,i2,i3;
164
165 for(i=0;;i++){
166 if(Parameter[i]=='\0'){
167 SetError(21,NULL,cp);
168 return;
169 }
170 if(Parameter[i]==1&&Parameter[i+1]==ESC_THEN){
171 Parameter[i]=0;
172 break;
173 }
174 }
175
176 //条件式を実行してフラグをセット
177 Judgment(Parameter);
178
179 //je (endif、または else まで条件ジャンプ)
180 OpBuffer[obp++]=(char)0x0F;
181 OpBuffer[obp++]=(char)0x84;
182 obp+=sizeof(long);
183
184 //jeの番地
185 i3=obp;
186
187
188 /////////////////////////
189 // If内をコード化
190 /////////////////////////
191
192 //レキシカルスコープをレベルアップ
193 obj_LexScopes.LevelUp(obp);
194
195 i2=CompileBuffer(ESC_ENDIF,0);
196
197 //レキシカルスコープをレベルダウン
198 obj_LexScopes.LevelDown();
199
200
201 extern char *basbuf;
202 if(i2==ESC_ELSE){
203 //jmp (endifまで)
204 OpBuffer[obp++]=(char)0xE9;
205 obp+=sizeof(long);
206
207 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; //ifからelseへのジャンプ先のオフセット値
208
209 i3=obp;
210
211
212 /////////////////////////
213 // Else内をコード化
214 /////////////////////////
215
216 //レキシカルスコープをレベルアップ
217 obj_LexScopes.LevelUp(obp);
218
219 CompileBuffer(ESC_ENDIF,0);
220
221 //レキシカルスコープをレベルダウン
222 obj_LexScopes.LevelDown();
223
224
225 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; //jmpジャンプ先のオフセット値
226 }
227 else{
228 *((long *)(OpBuffer+i3-sizeof(long)))=obp-i3; //jeジャンプ先のオフセット値
229 }
230}
231
232int GetLabelAddress(char *LabelName,int LineNum){
233 extern int MaxLabelNum;
234 extern LABEL *pLabelNames;
235 int i;
236
237 if(LabelName){
238 for(i=0;i<MaxLabelNum;i++){
239 if(pLabelNames[i].pName){
240 if(lstrcmp(LabelName,pLabelNames[i].pName)==0) return pLabelNames[i].address;
241 }
242 }
243 }
244 else{
245 for(i=0;i<MaxLabelNum;i++){
246 if(pLabelNames[i].pName==0){
247 if(LineNum==pLabelNames[i].line) return pLabelNames[i].address;
248 }
249 }
250 }
251 return -1;
252}
253void OpcodeGoto(char *Parameter){
254 extern HANDLE hHeap;
255 extern GOTOLABELSCHEDULE *pGotoLabelSchedule;
256 extern int GotoLabelScheduleNum;
257 int i,LineNum;
258
259 if(Parameter[0]=='*'){
260 i=GetLabelAddress(Parameter+1,0);
261
262 //jmp ...
263 OpBuffer[obp++]=(char)0xE9;
264 if(i==-1){
265 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
266 pGotoLabelSchedule[GotoLabelScheduleNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter+1)+1);
267 lstrcpy(pGotoLabelSchedule[GotoLabelScheduleNum].pName,Parameter+1);
268 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
269 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
270 GotoLabelScheduleNum++;
271 }
272 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
273 obp+=sizeof(long);
274 }
275 else{
276 LineNum=atoi(Parameter);
277 i=GetLabelAddress(0,LineNum);
278
279 //jmp ...
280 OpBuffer[obp++]=(char)0xE9;
281 if(i==-1){
282 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
283 pGotoLabelSchedule[GotoLabelScheduleNum].pName=0;
284 pGotoLabelSchedule[GotoLabelScheduleNum].line=LineNum;
285 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
286 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
287 GotoLabelScheduleNum++;
288 }
289 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
290 obp+=sizeof(long);
291 }
292}
293void OpcodeWhile(char *Parameter){
294 extern DWORD *pExitWhileSchedule;
295 extern int ExitWhileScheduleNum;
296 extern HANDLE hHeap;
297 int i2;
298 DWORD *lpdwTemp;
299 int TempNum;
300
301 //Continueアドレスのバックアップとセット
302 extern DWORD dwContinueAddress;
303 DWORD dwTempContinue;
304 dwTempContinue=dwContinueAddress;
305 dwContinueAddress=obp;
306 pobj_TempSchedule->lock((int *)&dwTempContinue);
307 pobj_TempSchedule->lock((int *)&dwContinueAddress);
308
309 if(!Parameter[0]) SetError(10,"While",cp);
310
311 //条件式を実行してフラグをセット
312 Judgment(Parameter);
313
314 //je (Wend まで)
315 OpBuffer[obp++]=(char)0x0F;
316 OpBuffer[obp++]=(char)0x84;
317 obp+=sizeof(long);
318
319 //実行中の番地
320 int je_schedule=obp;
321 pobj_TempSchedule->lock(&je_schedule);
322
323 //ExitWhileスケジュールの準備
324 lpdwTemp=pExitWhileSchedule;
325 TempNum=ExitWhileScheduleNum;
326 pExitWhileSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
327 ExitWhileScheduleNum=0;
328
329 //レキシカルスコープをレベルアップ
330 obj_LexScopes.LevelUp(obp);
331
332 //While内をコンパイル
333 CompileBuffer(0,COM_WEND);
334
335 CallDestrouctorsOfScope();
336
337 //jmp ...
338 OpBuffer[obp++]=(char)0xE9;
339 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long));
340 obp+=sizeof(long);
341 pobj_TempSchedule->unlock();
342 pobj_TempSchedule->unlock();
343
344 //ExitWhileスケジュール
345 for(i2=0;i2<ExitWhileScheduleNum;i2++){
346 *((long *)(OpBuffer+pExitWhileSchedule[i2]))=obp-(pExitWhileSchedule[i2]+sizeof(long));
347 }
348 HeapDefaultFree(pExitWhileSchedule);
349 pExitWhileSchedule=lpdwTemp;
350 ExitWhileScheduleNum=TempNum;
351
352 //レキシカルスコープをレベルダウン
353 obj_LexScopes.LevelDown();
354
355 *((long *)(OpBuffer+je_schedule-sizeof(long)))=obp-je_schedule; //jeジャンプ先のオフセット値
356 pobj_TempSchedule->unlock();
357
358 //Continueアドレスを復元
359 dwContinueAddress=dwTempContinue;
360}
361void OpcodeExitWhile(void){
362 extern DWORD *pExitWhileSchedule;
363 extern int ExitWhileScheduleNum;
364 extern HANDLE hHeap;
365
366 if(!pExitWhileSchedule){
367 SetError(12,"Exit While",cp);
368 return;
369 }
370
371 //jmp ...(Wend addr)
372 OpBuffer[obp++]=(char)0xE9;
373
374 pExitWhileSchedule=(DWORD *)HeapReAlloc(hHeap,0,pExitWhileSchedule,(ExitWhileScheduleNum+1)*sizeof(DWORD));
375 pExitWhileSchedule[ExitWhileScheduleNum]=obp;
376 ExitWhileScheduleNum++;
377
378 obp+=sizeof(long);
379}
380char szNextVariable[VN_SIZE];
381void OpcodeFor(char *Parameter){
382 extern DWORD *pExitForSchedule;
383 extern int ExitForScheduleNum;
384 extern HANDLE hHeap;
385 DWORD *lpdwTemp;
386 int TempNum;
387 int i,i2,i3;
388 char temporary[VN_SIZE],variable[VN_SIZE],JudgeNum[VN_SIZE],StepNum[VN_SIZE];
389
390 //第1パラメータを取得
391 i=GetOneParameter(Parameter,0,temporary);
392 if(!Parameter[i]){
393 SetError(12,"For",cp);
394 goto ErrorStep;
395 }
396
397 for(i2=0;;i2++){
398 if(temporary[i2]=='='){
399 variable[i2]=0;
400
401 //カウンタ初期化
402 OpcodeCalc(temporary);
403 break;
404 }
405 if(temporary[i2]=='\0'){
406 SetError(12,"For",cp);
407 goto ErrorStep;
408 }
409 variable[i2]=temporary[i2];
410 }
411
412 //jmp ...
413 OpBuffer[obp++]=(char)0xE9;
414 i2=obp;
415 obp+=sizeof(long);
416
417 //Continueアドレスのバックアップとセット
418 extern DWORD dwContinueAddress;
419 DWORD dwTempContinue;
420 dwTempContinue=dwContinueAddress;
421 dwContinueAddress=obp;
422 pobj_TempSchedule->lock((int *)&dwTempContinue);
423 pobj_TempSchedule->lock((int *)&dwContinueAddress);
424
425 //第2パラメータを取得(to~)
426 i=GetOneParameter(Parameter,i,JudgeNum);
427
428 //第3パラメータを取得(step~)
429 if(Parameter[i]){
430 i=GetOneParameter(Parameter,i,StepNum);
431 if(Parameter[i]) SetError(12,"For",cp);
432 }
433 else lstrcpy(StepNum,"1");
434
435 //カウンタを増加させる
436 sprintf(temporary,"%s=(%s)+(%s)",variable,variable,StepNum);
437 OpcodeCalc(temporary);
438
439 *((long *)(OpBuffer+i2))=obp-(i2+sizeof(long));
440
441 //増加か減少かを区別する
442 sprintf(temporary,"(%s)>=0",StepNum);
443
444 int reg,type;
445 reg=REG_RAX;
446 type=NumOpe(&reg,temporary,0,0,0);
447
448 //cmp rax,0
449 op_cmp_value(GetTypeSize(type,-1),REG_RAX,0);
450
451 //je [カウンタ減少の場合の判定]
452 OpBuffer[obp++]=(char)0x0F;
453 OpBuffer[obp++]=(char)0x84;
454 i2=obp;
455 obp+=sizeof(long);
456
457 //判定(カウンタ増加の場合)
458 sprintf(temporary,"%s<=(%s)",variable,JudgeNum);
459
460 reg=REG_RAX;
461 type=NumOpe(&reg,temporary,0,0,0);
462
463 //jmp [カウンタ減少の場合の判定を飛び越す]
464 OpBuffer[obp++]=(char)0xE9;
465 i3=obp;
466 obp+=sizeof(long);
467
468 *((long *)(OpBuffer+i2))=obp-(i2+sizeof(long)); //jeジャンプ先のオフセット値
469
470 //判定(カウンタ減少の場合)
471 sprintf(temporary,"%s>=(%s)",variable,JudgeNum);
472
473 reg=REG_RAX;
474 type=NumOpe(&reg,temporary,0,0,0);
475
476 *((long *)(OpBuffer+i3))=obp-(i3+sizeof(long)); //jmpジャンプ先のオフセット値
477
478 //cmp rax,0
479 op_cmp_value(GetTypeSize(type,-1),REG_RAX,0);
480
481ErrorStep:
482
483 //je ...
484 OpBuffer[obp++]=(char)0x0F;
485 OpBuffer[obp++]=(char)0x84;
486 int je_schedule=obp;
487 obp+=sizeof(long);
488 pobj_TempSchedule->lock(&je_schedule);
489
490 //ExitForスケジュールの準備
491 lpdwTemp=pExitForSchedule;
492 TempNum=ExitForScheduleNum;
493 pExitForSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
494 ExitForScheduleNum=0;
495
496 //レキシカルスコープをレベルアップ
497 obj_LexScopes.LevelUp(obp);
498
499 //For内をコンパイル
500 CompileBuffer(0,COM_NEXT);
501
502 CallDestrouctorsOfScope();
503
504 if(szNextVariable[0]){
505 if(lstrcmp(szNextVariable,variable)!=0){
506 SetError(55,szNextVariable,cp);
507 }
508 }
509
510 //jmp ...
511 OpBuffer[obp++]=(char)0xE9;
512 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long));
513 obp+=sizeof(long);
514 pobj_TempSchedule->unlock();
515 pobj_TempSchedule->unlock();
516
517 //ExitForスケジュール
518 for(i=0;i<ExitForScheduleNum;i++){
519 *((long *)(OpBuffer+pExitForSchedule[i]))=obp-(pExitForSchedule[i]+sizeof(long));
520 }
521 HeapDefaultFree(pExitForSchedule);
522 pExitForSchedule=lpdwTemp;
523 ExitForScheduleNum=TempNum;
524
525 //レキシカルスコープをレベルダウン
526 obj_LexScopes.LevelDown();
527
528 *((long *)(OpBuffer+je_schedule))=obp-(je_schedule+sizeof(long)); //jeジャンプ先のオフセット値
529 pobj_TempSchedule->unlock();
530
531 //Continueアドレスを復元
532 dwContinueAddress=dwTempContinue;
533}
534void OpcodeExitFor(void){
535 extern DWORD *pExitForSchedule;
536 extern int ExitForScheduleNum;
537 extern HANDLE hHeap;
538
539 if(!pExitForSchedule){
540 SetError(12,"Exit For",cp);
541 return;
542 }
543
544 //jmp ...(Next addr)
545 OpBuffer[obp++]=(char)0xE9;
546
547 pExitForSchedule=(DWORD *)HeapReAlloc(hHeap,0,pExitForSchedule,(ExitForScheduleNum+1)*sizeof(DWORD));
548 pExitForSchedule[ExitForScheduleNum]=obp;
549 ExitForScheduleNum++;
550
551 obp+=sizeof(long);
552}
553
554void OpcodeDo(char *Parameter){
555 extern DWORD *pExitDoSchedule;
556 extern int ExitDoScheduleNum;
557 extern HANDLE hHeap;
558 int i,i2,i3;
559 DWORD *lpdwTemp;
560 int TempNum;
561
562 if(Parameter[0]) SetError(10,"Do",cp);
563
564 //ExitDoスケジュールの準備
565 lpdwTemp=pExitDoSchedule;
566 TempNum=ExitDoScheduleNum;
567 pExitDoSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
568 ExitDoScheduleNum=0;
569
570 //Continueアドレスのバックアップとセット
571 extern DWORD dwContinueAddress;
572 DWORD dwTempContinue;
573 dwTempContinue=dwContinueAddress;
574 dwContinueAddress=obp;
575 pobj_TempSchedule->lock((int *)&dwTempContinue);
576 pobj_TempSchedule->lock((int *)&dwContinueAddress);
577
578 //レキシカルスコープをレベルアップ
579 obj_LexScopes.LevelUp(obp);
580
581 //Do内をコンパイル
582 CompileBuffer(0,COM_LOOP);
583
584 CallDestrouctorsOfScope();
585
586 extern char *basbuf;
587 char temporary[VN_SIZE];
588 for(i=cp-1;;i--){
589 if(IsCommandDelimitation(basbuf[i])){
590 i+=3;
591 if(!(basbuf[i]=='0'||basbuf[i]=='1')){
592 //無条件ループ
593 break;
594 }
595 i3=i;
596
597 for(i+=2,i2=0;;i++,i2++){
598 if(IsCommandDelimitation(basbuf[i])){
599 temporary[i2]=0;
600 break;
601 }
602 temporary[i2]=basbuf[i];
603 }
604
605 //条件式を実行してフラグをセット
606 Judgment(temporary);
607
608 if(basbuf[i3]=='0'){
609 //While
610
611 //je 5(ループ終了)
612 OpBuffer[obp++]=(char)0x74;
613 OpBuffer[obp++]=(char)0x05;
614 }
615 else if(basbuf[i3]=='1'){
616 //Until
617
618 //jne 5(ループ終了)
619 OpBuffer[obp++]=(char)0x75;
620 OpBuffer[obp++]=(char)0x05;
621 }
622 break;
623 }
624 }
625
626 //jmp ...
627 OpBuffer[obp++]=(char)0xE9;
628 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long));
629 obp+=sizeof(long);
630 pobj_TempSchedule->unlock();
631 pobj_TempSchedule->unlock();
632
633 //jmp ...
634 OpBuffer[obp++]=(char)0xE9;
635 int je_schedule=obp;
636 obp+=sizeof(long);
637 pobj_TempSchedule->lock(&je_schedule);
638
639 //ExitDoスケジュール
640 for(i=0;i<ExitDoScheduleNum;i++){
641 *((long *)(OpBuffer+pExitDoSchedule[i]))=obp-(pExitDoSchedule[i]+sizeof(long));
642 }
643 HeapDefaultFree(pExitDoSchedule);
644 pExitDoSchedule=lpdwTemp;
645 ExitDoScheduleNum=TempNum;
646
647 //レキシカルスコープをレベルダウン
648 obj_LexScopes.LevelDown();
649
650 *((long *)(OpBuffer+je_schedule))=obp-(je_schedule+sizeof(long)); //jmpジャンプ先のオフセット値
651 pobj_TempSchedule->unlock();
652
653 //Continueアドレスを復元
654 dwContinueAddress=dwTempContinue;
655}
656void OpcodeExitDo(void){
657 extern HANDLE hHeap;
658 extern DWORD *pExitDoSchedule;
659 extern int ExitDoScheduleNum;
660
661 if(!pExitDoSchedule){
662 SetError(12,"Exit Do",cp);
663 return;
664 }
665
666 //jmp ...(Loop addr)
667 OpBuffer[obp++]=(char)0xE9;
668
669 pExitDoSchedule=(DWORD *)HeapReAlloc(hHeap,0,pExitDoSchedule,(ExitDoScheduleNum+1)*sizeof(DWORD));
670 pExitDoSchedule[ExitDoScheduleNum]=obp;
671 ExitDoScheduleNum++;
672
673 obp+=sizeof(long);
674}
675void OpcodeContinue(void){
676 extern DWORD dwContinueAddress;
677
678 if(dwContinueAddress==-1){
679 SetError(12,"Continue",cp);
680 return;
681 }
682
683 //jmp ...(Continue addr)
684 OpBuffer[obp++]=(char)0xE9;
685
686 *((long *)(OpBuffer+obp))=dwContinueAddress-(obp+sizeof(long));
687 obp+=sizeof(long);
688}
689
690void OpcodeExitSub(void){
691 extern DWORD *pExitSubSchedule;
692 extern int ExitSubScheduleNum;
693 extern HANDLE hHeap;
694
695 extern BOOL bCompilingGlobal;
696 if(bCompilingGlobal){
697 SetError(12,"Exit Sub/Function",cp);
698 return;
699 }
700
701 //jmp ...(End Sub/Function)
702 OpBuffer[obp++]=(char)0xE9;
703
704 pExitSubSchedule=(DWORD *)HeapReAlloc(hHeap,0,pExitSubSchedule,(ExitSubScheduleNum+1)*sizeof(DWORD));
705 pExitSubSchedule[ExitSubScheduleNum]=obp;
706 ExitSubScheduleNum++;
707
708 obp+=sizeof(long);
709}
710
711void AddCaseSchedule(void){
712 extern DWORD *pCaseSchedule;
713 extern int CaseScheduleNum;
714 extern HANDLE hHeap;
715
716 pCaseSchedule=(DWORD *)HeapReAlloc(hHeap,0,pCaseSchedule,(CaseScheduleNum+1)*sizeof(DWORD));
717 pCaseSchedule[CaseScheduleNum]=obp;
718 CaseScheduleNum++;
719}
720void OpcodeSelect(char *Parameter){
721 extern DWORD *pCaseSchedule;
722 extern int CaseScheduleNum;
723 extern int NowCaseSchedule;
724 extern HANDLE hHeap;
725 extern char *basbuf;
726 int i,i2,i3,NowCaseCp;
727 char temporary[VN_SIZE];
728
729 DWORD *temp_pCaseSchedule;
730 int temp_CaseScheduleNum;
731 int temp_NowCaseSchedule;
732
733 temp_pCaseSchedule=pCaseSchedule;
734 temp_CaseScheduleNum=CaseScheduleNum;
735 temp_NowCaseSchedule=NowCaseSchedule;
736 pCaseSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
737 CaseScheduleNum=0;
738 NowCaseSchedule=0;
739
740 int reg1=REG_RAX,type1;
741 LONG_PTR lpIndex;
742 type1=NumOpe(&reg1,Parameter,0,0,&lpIndex);
743
744 if(type1==DEF_DOUBLE){
745 //movsd qword ptr[rsp+offset],xmm_reg ※スタックフレームを利用
746 pobj_sf->push(reg1,sizeof(double));
747 }
748 else if(type1==DEF_SINGLE){
749 //movss dword ptr[rsp+offset],xmm_reg ※スタックフレームを利用
750 pobj_sf->push(reg1,sizeof(float));
751 }
752 else{
753 ExtendTypeTo64(type1,reg1);
754
755 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用
756 pobj_sf->push(reg1);
757 }
758
759 for(i=cp;;i++){
760 if(basbuf[i]=='\0'){
761 HeapDefaultFree(pCaseSchedule);
762 pCaseSchedule=temp_pCaseSchedule;
763 CaseScheduleNum=temp_CaseScheduleNum;
764 NowCaseSchedule=temp_NowCaseSchedule;
765 SetError(22,"Select",cp);
766 return;
767 }
768 if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE){
769 for(i2=0;;i++){
770 if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE) i2++;
771 if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){
772 i2--;
773 if(i2==0) break;
774 }
775 }
776 continue;
777 }
778 if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT) break;
779
780 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASE){
781 NowCaseCp=i;
782
783 i++;
784 while(1){
785 for(i++,i2=0;;i++,i2++){
786 if(basbuf[i]=='\"'){
787 i3=GetStringInQuotation(temporary+i2,basbuf+i);
788 i+=i3-1;
789 i2+=i3-1;
790 continue;
791 }
792 if(basbuf[i]=='('){
793 i3=GetStringInPare(temporary+i2,basbuf+i);
794 i+=i3-1;
795 i2+=i3-1;
796 continue;
797 }
798 if(basbuf[i]=='['){
799 i3=GetStringInBracket(temporary+i2,basbuf+i);
800 i+=i3-1;
801 i2+=i3-1;
802 continue;
803 }
804
805 if(IsCommandDelimitation(basbuf[i])){
806 temporary[i2]=0;
807 break;
808 }
809 if(basbuf[i]==','){
810 temporary[i2]=0;
811 break;
812 }
813
814 temporary[i2]=basbuf[i];
815 }
816
817 //エラー用
818 i2=cp;
819 cp=NowCaseCp;
820
821 int reg2=REG_RDX,type2;
822 LONG_PTR lpIndex2;
823 type2=NumOpe(&reg2,temporary,type1,lpIndex,&lpIndex2);
824
825 cp=i2;
826
827 if(type1==DEF_OBJECT){
828 CClass *pobj_c;
829 pobj_c=(CClass *)lpIndex;
830
831 SUBINFO **ppsi;
832 int num;
833 ppsi=pobj_c->GetOperatorSubInfo(CALC_EQUAL,num);
834 if(num==0){
835 HeapDefaultFree(ppsi);
836
837 return;
838 }
839
840 PARAMETER_INFO *ppi;
841 int iParmNum=0;
842
843 //_System_LocalThis
844 ppi=(PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3);
845 ppi[iParmNum].bArray=0;
846 ppi[iParmNum].bByVal=0;
847 ppi[iParmNum].name=0;
848 ppi[iParmNum].type=DEF_PTR_VOID;
849 ppi[iParmNum].u.index=-1;
850 ppi[iParmNum].SubScripts[0]=-1;
851 iParmNum++;
852
853 ppi[iParmNum].bArray=0;
854 ppi[iParmNum].bByVal=0;
855 ppi[iParmNum].name=0;
856 ppi[iParmNum].type=type2;
857 ppi[iParmNum].u.index=lpIndex2;
858 ppi[iParmNum].SubScripts[0]=-1;
859 iParmNum++;
860
861 //オーバーロードを解決
862 SUBINFO *psi;
863 psi=OverloadSolution("==",ppsi,num,ppi,iParmNum,NULL);
864 HeapDefaultFree(ppsi);
865 HeapDefaultFree(ppi);
866
867 if(!psi){
868 //エラー
869 return;
870 }
871
872
873 //実体オブジェクト
874 if(reg2!=REG_RDX){
875 //mov rdx,reg2
876 op_mov_RR(REG_RDX,reg2);
877 }
878
879 //mov rcx,qword ptr[rsp+offset] ※スタックフレームから参照
880 pobj_sf->ref(REG_RCX);
881
882 //call operator_proc ※ ==演算子
883 op_call(psi);
884
885 //test rax,rax
886 op_test(REG_RAX,REG_RAX);
887
888 //jne ...
889 OpBuffer[obp++]=(char)0x0F;
890 OpBuffer[obp++]=(char)0x85;
891 }
892 else{
893 if(type1==DEF_DOUBLE){
894 int xmm_reg;
895 if(IsXmmReg(reg2)) xmm_reg=reg2;
896 else xmm_reg=REG_XMM5;
897 ChangeTypeToXmm_Double(type2,xmm_reg,reg2);
898
899 //movsd xmm4,qword ptr[rsp+offset] ※スタックフレームから参照
900 pobj_sf->ref(REG_XMM4,sizeof(double));
901
902 //comiss xmm_reg1,xmm_reg2
903 op_comisd(xmm_reg,REG_XMM4);
904 }
905 else if(type1==DEF_SINGLE){
906 int xmm_reg;
907 if(IsXmmReg(reg2)) xmm_reg=reg2;
908 else xmm_reg=REG_XMM5;
909 ChangeTypeToXmm_Single(type2,xmm_reg,reg2);
910
911 //movss xmm4,dword ptr[rsp+offset] ※スタックフレームから参照
912 pobj_sf->ref(REG_XMM4,sizeof(float));
913
914 //comiss xmm_reg1,xmm_reg2
915 op_comiss(xmm_reg,REG_XMM4);
916 }
917 else{
918 //その他整数型
919
920 i2=NeutralizationType(type1,-1,type2,-1);
921
922 //mov r14,qword ptr[rsp+offset] ※スタックフレームから参照
923 pobj_sf->ref(REG_R14);
924
925 //cmp reg2,r14
926 op_cmp_reg(GetTypeSize(i2,-1),reg2,REG_R14);
927 }
928
929 //je ...
930 OpBuffer[obp++]=(char)0x0F;
931 OpBuffer[obp++]=(char)0x84;
932 }
933 AddCaseSchedule();
934 obp+=sizeof(long);
935
936 if(basbuf[i]!=',') break;
937 }
938 }
939 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){
940 //jmp ...
941 OpBuffer[obp++]=(char)0xE9;
942 AddCaseSchedule();
943 obp+=sizeof(long);
944 }
945 }
946
947 //スタックフレームを1スペースだけ解除
948 pobj_sf->pop(REG_NON);
949
950 //レキシカルスコープをレベルアップ
951 obj_LexScopes.LevelUp(obp);
952
953 //Select Case内をコンパイル
954 CompileBuffer(ESC_ENDSELECT,0);
955
956 //jmp EndSelect
957 OpBuffer[obp++]=(char)0xE9;
958 AddCaseSchedule();
959 obp+=sizeof(long);
960
961 //最終スケジュール
962 for(i=NowCaseSchedule;i<CaseScheduleNum;i++){
963 *(long *)(OpBuffer+pCaseSchedule[i])=obp-(pCaseSchedule[i]+sizeof(long));
964 }
965 HeapDefaultFree(pCaseSchedule);
966
967 //レキシカルスコープをレベルダウン
968 obj_LexScopes.LevelDown();
969
970 pCaseSchedule=temp_pCaseSchedule;
971 CaseScheduleNum=temp_CaseScheduleNum;
972 NowCaseSchedule=temp_NowCaseSchedule;
973}
974void OpcodeCase(char *Parameter){
975 extern DWORD *pCaseSchedule;
976 extern int NowCaseSchedule;
977 int i;
978
979 if(!pCaseSchedule){
980 SetError(30,"Case",cp);
981 return;
982 }
983
984 //jmp EndSelect
985 OpBuffer[obp++]=(char)0xE9;
986 AddCaseSchedule();
987 obp+=sizeof(long);
988
989 i=0;
990 while(1){
991 //Caseスケジュール
992 *(long *)(OpBuffer+pCaseSchedule[NowCaseSchedule])=obp-(pCaseSchedule[NowCaseSchedule]+sizeof(long));
993 NowCaseSchedule++;
994
995 i=JumpOneParameter(Parameter,i);
996 if(Parameter[i]=='\0') break;
997 }
998}
999
1000void OpcodeGosub(char *Parameter){
1001 extern HANDLE hHeap;
1002 extern GOTOLABELSCHEDULE *pGotoLabelSchedule;
1003 extern int GotoLabelScheduleNum;
1004 int i,LineNum;
1005
1006 //call _System_GetEip
1007 extern SUBINFO *pSub_System_GetEip;
1008 op_call(pSub_System_GetEip);
1009
1010 //add rax,offset(Gosubステートメントの最終ポイント)
1011 int schedule=obp,schedule2;
1012 op_add64_value(REG_RAX,0);
1013 schedule2=obp-sizeof(long);
1014
1015 //※戻り先用のrip
1016 //mov qword ptr[rsp+offset],rax ※スタックフレームを利用
1017 pobj_sf->push(REG_RAX);
1018
1019
1020 if(Parameter[0]=='*'){
1021 i=GetLabelAddress(Parameter+1,0);
1022
1023 //jmp ...
1024 OpBuffer[obp++]=(char)0xE9;
1025 if(i==-1){
1026 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
1027 pGotoLabelSchedule[GotoLabelScheduleNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter+1)+1);
1028 lstrcpy(pGotoLabelSchedule[GotoLabelScheduleNum].pName,Parameter+1);
1029 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
1030 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
1031 GotoLabelScheduleNum++;
1032 }
1033 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
1034 obp+=sizeof(long);
1035 }
1036 else{
1037 LineNum=atoi(Parameter);
1038 i=GetLabelAddress(0,LineNum);
1039
1040 //jmp ...
1041 OpBuffer[obp++]=(char)0xE9;
1042 if(i==-1){
1043 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
1044 pGotoLabelSchedule[GotoLabelScheduleNum].pName=0;
1045 pGotoLabelSchedule[GotoLabelScheduleNum].line=LineNum;
1046 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
1047 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
1048 GotoLabelScheduleNum++;
1049 }
1050 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
1051 obp+=sizeof(long);
1052 }
1053
1054 *((long *)(OpBuffer+schedule2))=obp-schedule;
1055
1056 //※スタックフレームを元に戻す
1057 pobj_sf->pop(REG_NON);
1058
1059 SetError(-1,"Gosub ~ Returnステートメントは64ビットコンパイラで利用することはできません。",cp);
1060}
1061void OpcodeReturn(char *Parameter){
1062 extern BOOL bCompilingGlobal;
1063 if(bCompilingGlobal){
1064 //Gosub~Returnとして扱う
1065
1066 //mov rax,qword ptr[rsp+offset] ※スタックフレームを利用
1067 pobj_sf->push(REG_NON);
1068 pobj_sf->ref(REG_RAX);
1069 pobj_sf->pop(REG_NON);
1070
1071 //jmp rax
1072 OpBuffer[obp++]=(char)0xFF;
1073 OpBuffer[obp++]=(char)0xE0;
1074 }
1075 else{
1076 //戻り値をセット
1077 if(Parameter[0]){
1078 extern SUBINFO *pCompilingSubInfo;
1079 char *temp;
1080 if(pCompilingSubInfo->name[0]==1&&pCompilingSubInfo->name[1]==ESC_OPERATOR)
1081 temp="_System_ReturnValue";
1082 else temp=pCompilingSubInfo->name;
1083
1084 char temporary[VN_SIZE];
1085 sprintf(temporary,"%s=%s",temp,Parameter);
1086 OpcodeCalc(temporary);
1087 }
1088
1089 //プロシージャを抜け出す(C言語のreturnと同様の処理を行う)
1090 OpcodeExitSub();
1091 }
1092}
1093
1094void Opcode_Input(char *Parameter){
1095 extern int cp;
1096 int i2,i3,i4,i5,type;
1097 BOOL bFile;
1098 char temporary[VN_SIZE],temp2[VN_SIZE],buffer[VN_SIZE];
1099
1100 KillStringSpaces(Parameter);
1101
1102 if(Parameter[0]=='#'){
1103 bFile=1;
1104 for(i2=0,i3=1;;i2++,i3++){
1105 buffer[i2]=Parameter[i3];
1106 if(Parameter[i3]==','||Parameter[i3]=='\0') break;
1107 }
1108 buffer[i2+1]=0;
1109 i2=i3+1;
1110 }
1111 else{
1112 bFile=0;
1113 i2=0;
1114 buffer[0]=0;
1115
1116 //表示用文字列パラメータをセット
1117 if(Parameter[0]=='\"'){
1118 buffer[0]='\"';
1119 for(i2=1;;i2++){
1120 if(Parameter[i2]=='\"'){
1121 buffer[i2]=0;
1122 break;
1123 }
1124 buffer[i2]=Parameter[i2];
1125 }
1126 if(Parameter[i2+1]==';') lstrcpy(buffer+i2,"? \"");
1127 else if(Parameter[i2+1]==',') lstrcpy(buffer+i2,"\"");
1128 else SetError(10,"Input",cp);
1129 i2+=2;
1130 }
1131 else if((Parameter[0]=='e'||Parameter[0]=='E')&&
1132 (Parameter[1]=='x'||Parameter[1]=='X')&&
1133 Parameter[2]=='\"'){
1134 memcpy(buffer,Parameter,3);
1135 for(i2=3;;i2++){
1136 if(Parameter[i2]=='\"'){
1137 buffer[i2]=0;
1138 break;
1139 }
1140 buffer[i2]=Parameter[i2];
1141 }
1142 if(Parameter[i2+1]==';') lstrcpy(buffer+i2,"? \"");
1143 else if(Parameter[i2+1]==',') lstrcpy(buffer+i2,"\"");
1144 else SetError(10,"Input",cp);
1145 i2+=2;
1146 }
1147 else{
1148 lstrcpy(buffer,"\"? \"");
1149 i2=0;
1150 }
1151 }
1152
1153 //変数ポインタ、変数のタイプをセット
1154 i4=0;
1155 while(1){
1156 for(i3=0;;i2++,i3++){
1157 if(Parameter[i2]=='('){
1158 i5=GetStringInPare(temporary+i3,Parameter+i2);
1159 i2+=i5-1;
1160 i3+=i5-1;
1161 }
1162 if(Parameter[i2]=='['){
1163 i5=GetStringInBracket(temporary+i3,Parameter+i2);
1164 i2+=i5-1;
1165 i3+=i5-1;
1166 }
1167 if(Parameter[i2]==','){
1168 temporary[i3]=0;
1169 i2++;
1170 break;
1171 }
1172 temporary[i3]=Parameter[i2];
1173 if(Parameter[i2]=='\0') break;
1174 }
1175 if(temporary[0]=='\0'){
1176 SetError(10,"Input",cp);
1177 return;
1178 }
1179
1180 LONG_PTR lpIndex;
1181 type = GetVarType(temporary, &lpIndex, 1);
1182
1183 sprintf(temp2,"_System_InputDataPtr[%d]=VarPtr(%s)",i4,temporary);
1184 OpcodeCalc(temp2);
1185
1186 if(type==DEF_LONG) type=DEF_DWORD;
1187 else if(type==DEF_INTEGER) type=DEF_WORD;
1188 else if(type==DEF_OBJECT){
1189 CClass *pobj_Class=(CClass *)lpIndex;
1190 if(lstrcmp(pobj_Class->name,"String")==0) type=DEF_STRING;
1191 }
1192 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,type);
1193 OpcodeCalc(temp2);
1194
1195 i4++;
1196 if(Parameter[i2]=='\0') break;
1197 }
1198 sprintf(temp2,"_System_InputDataPtr[%d]=0",i4);
1199 OpcodeCalc(temp2);
1200
1201 SUBINFO *psi;
1202 if(bFile) psi=GetSubHash("INPUT_FromFile");
1203 else psi=GetSubHash("INPUT_FromPrompt");
1204 if(!psi){
1205 SetError(3,"Input",cp);
1206 return;
1207 }
1208 Opcode_CallProc(buffer,psi,0,0,"",0);
1209}
1210void Opcode_PrintUsing(char *Parameter,char *buffer,BOOL bFile){
1211 extern int cp;
1212 int i2,i3,i4,i5;
1213 char temporary[VN_SIZE],temp2[8192];
1214 BOOL bReturnLine;
1215
1216 i2=lstrlen(Parameter);
1217 if(Parameter[i2-1]==';'){
1218 bReturnLine=0;
1219 Parameter[i2-1]=0;
1220 }
1221 else bReturnLine=1;
1222
1223 i3=lstrlen(buffer);
1224 for(i2=0;;i2++,i3++){
1225 if(Parameter[i2]==';'){
1226 buffer[i3]=0;
1227 break;
1228 }
1229 buffer[i3]=Parameter[i2];
1230 if(Parameter[i2]=='\0') break;
1231 }
1232 if(Parameter[i2]==';') i2++;
1233
1234 if(bReturnLine) lstrcat(buffer,"+Ex\"\\r\\n\"");
1235
1236 //データポインタ、データのタイプをセット
1237 i4=0;
1238 while(1){
1239 for(i3=0;;i2++,i3++){
1240 if(Parameter[i2]=='\"'){
1241 temporary[i3]=Parameter[i2];
1242 for(i2++,i3++;;i2++,i3++){
1243 temporary[i3]=Parameter[i2];
1244 if(Parameter[i2]=='\"') break;
1245 }
1246 continue;
1247 }
1248 if(Parameter[i2]=='('){
1249 i5=GetStringInPare(temporary+i3,Parameter+i2);
1250 i2+=i5-1;
1251 i3+=i5-1;
1252 continue;
1253 }
1254 if(Parameter[i2]=='['){
1255 i5=GetStringInBracket(temporary+i3,Parameter+i2);
1256 i2+=i5-1;
1257 i3+=i5-1;
1258 continue;
1259 }
1260 if(Parameter[i2]==','){
1261 temporary[i3]=0;
1262 i2++;
1263 break;
1264 }
1265 temporary[i3]=Parameter[i2];
1266 if(Parameter[i2]=='\0') break;
1267 }
1268 if(temporary[0]=='\0'){
1269 SetError(10,"Print",cp);
1270 return;
1271 }
1272
1273 int iResult;
1274 iResult=IsStrCalculation(temporary);
1275
1276 if(iResult==1){
1277 //文字列
1278 sprintf(temp2,"_System_UsingStrData[%d]=%s",i4,temporary);
1279 OpcodeCalc(temp2);
1280
1281 sprintf(temp2,"_System_UsingDataType[%d]=%d",i4,DEF_STRING);
1282 OpcodeCalc(temp2);
1283 }
1284 else if(iResult==0){
1285 //数値
1286 sprintf(temp2,"_System_UsingDblData[%d]=%s",i4,temporary);
1287 OpcodeCalc(temp2);
1288
1289 sprintf(temp2,"_System_UsingDataType[%d]=%d",i4,DEF_DOUBLE);
1290 OpcodeCalc(temp2);
1291 }
1292 //else if(iResult==-1) エラー
1293
1294 i4++;
1295 if(Parameter[i2]=='\0') break;
1296 }
1297 sprintf(temp2,"_System_UsingDataType[%d]=-1",i4);
1298 OpcodeCalc(temp2);
1299
1300 SUBINFO *psi;
1301 if(bFile) psi=GetSubHash("PRINTUSING_ToFile");
1302 else psi=GetSubHash("PRINTUSING_ToPrompt");
1303 if(!psi){
1304 SetError(3,"Print",cp);
1305 return;
1306 }
1307 Opcode_CallProc(buffer,psi,0,0,"",0);
1308}
1309void Opcode_Print(char *Parameter,BOOL bWrite){
1310 int i2,i3,i4,sw;
1311 char temporary[VN_SIZE],buffer[VN_SIZE];
1312 BOOL bFile;
1313
1314 KillStringSpaces(Parameter);
1315
1316 if(Parameter[0]=='#'){
1317 bFile=1;
1318 for(i2=0,i3=1;;i2++,i3++){
1319 buffer[i2]=Parameter[i3];
1320 if(Parameter[i3]==','||Parameter[i3]=='\0') break;
1321 }
1322 buffer[i2+1]=0;
1323 if(Parameter[i3]==',') i3++;
1324 i2=i3;
1325 }
1326 else{
1327 bFile=0;
1328 i2=0;
1329 buffer[0]=0;
1330 }
1331 if(Parameter[i2]==1&&Parameter[i2+1]==ESC_USING){
1332 Opcode_PrintUsing(Parameter+i2+2,buffer,bFile);
1333 return;
1334 }
1335
1336 lstrcat(buffer,"_System_DummyStr+");
1337
1338 sw=1;
1339 while(1){
1340 for(i3=0;;i2++,i3++){
1341 if(Parameter[i2]=='\"'){
1342 temporary[i3]=Parameter[i2];
1343 for(i2++,i3++;;i2++,i3++){
1344 temporary[i3]=Parameter[i2];
1345 if(Parameter[i2]=='\"') break;
1346 }
1347 continue;
1348 }
1349 if(Parameter[i2]=='('){
1350 i4=GetStringInPare(temporary+i3,Parameter+i2);
1351 i2+=i4-1;
1352 i3+=i4-1;
1353 continue;
1354 }
1355 if(Parameter[i2]=='['){
1356 i4=GetStringInBracket(temporary+i3,Parameter+i2);
1357 i2+=i4-1;
1358 i3+=i4-1;
1359 continue;
1360 }
1361 if(Parameter[i2]==','||Parameter[i2]==';'){
1362 temporary[i3]=0;
1363 break;
1364 }
1365 temporary[i3]=Parameter[i2];
1366 if(Parameter[i2]=='\0') break;
1367 }
1368
1369 if(temporary[0]=='\0') lstrcat(buffer,"\"\"");
1370 else{
1371 int iResult;
1372 iResult=IsStrCalculation(temporary);
1373 if(iResult==-1){
1374 //エラー
1375 lstrcat(buffer,"\"\"");
1376 }
1377 else if(iResult){
1378 //文字列
1379 lstrcat(buffer,temporary);
1380 }
1381 else{
1382 //数値
1383 sprintf(buffer+lstrlen(buffer),"Str$(%s)",temporary);
1384 }
1385 }
1386
1387 if(Parameter[i2]==','){
1388 if(bWrite) lstrcat(buffer,"+\",\"+");
1389 else lstrcat(buffer,"+\"\t\"+");
1390 }
1391 else if(Parameter[i2]==';'){
1392 if(Parameter[i2+1]=='\0'){
1393 sw=0;
1394 break;
1395 }
1396 if(bWrite) lstrcat(buffer,"+\",\"+");
1397 else lstrcat(buffer,"+\" \"+");
1398 }
1399 else if(Parameter[i2]=='\0') break;
1400
1401 i2++;
1402 }
1403
1404 if(sw) lstrcat(buffer,"+Ex\"\\r\\n\"");
1405
1406 SUBINFO *psi;
1407 if(bFile) psi=GetSubHash("PRINT_ToFile");
1408 else psi=GetSubHash("PRINT_ToPrompt");
1409 if(!psi){
1410 SetError(3,"Print",cp);
1411 return;
1412 }
1413 Opcode_CallProc(buffer,psi,0,0,"",0);
1414}
1415
1416
1417
1418
1419////////////
1420// ポインタ
1421////////////
1422
1423void OpcodeSetPtrData(char *Parameter,int type){
1424 int i,i2;
1425 char temporary[VN_SIZE];
1426
1427 if(Parameter[0]=='('){
1428 i=JumpStringInPare(Parameter,1);
1429 if(Parameter[i+1]=='\0'){
1430 for(i=0;;i++){
1431 Parameter[i]=Parameter[i+1];
1432 if(Parameter[i]=='\0') break;
1433 }
1434 Parameter[i-1]=0;
1435 }
1436 }
1437
1438 //第1パラメータを取得
1439 i=GetOneParameter(Parameter,0,temporary);
1440 if(!Parameter[i]){
1441 SetError(1,NULL,cp);
1442 return;
1443 }
1444
1445 int reg_ptr=REG_RAX;
1446 i2=NumOpe(&reg_ptr,temporary,0,0,0);
1447 if(!IsWholeNumberType(i2)){
1448 SetError(11,Parameter,cp);
1449 return;
1450 }
1451
1452 //結果を格納しているレジスタをブロッキング
1453 pobj_BlockReg->lock(reg_ptr);
1454
1455 //第2パラメータを取得
1456 i=GetOneParameter(Parameter,i,temporary);
1457 if(Parameter[i]){
1458 SetError(1,NULL,cp);
1459 return;
1460 }
1461
1462 int temp_reg=REG_NON;
1463 i2=NumOpe(&temp_reg,temporary,0,0,0);
1464
1465 //レジスタのブロッキングを解除
1466 pobj_BlockReg->clear();
1467
1468 if(type==DEF_DOUBLE){
1469 ChangeTypeToXmm_Double(i2,REG_XMM0,temp_reg);
1470
1471 //movsd qword ptr[reg_ptr],xmm0
1472 op_movsd_MR(REG_XMM0,reg_ptr,0,MOD_BASE);
1473 }
1474 else if(type==DEF_SINGLE){
1475 ChangeTypeToXmm_Single(i2,REG_XMM0,temp_reg);
1476
1477 //movss dword ptr[reg_ptr],xmm0
1478 op_movss_MR(REG_XMM0,reg_ptr,0,MOD_BASE);
1479 }
1480 else{
1481 ChangeTypeToWhole(i2,type,REG_RCX,temp_reg);
1482
1483 //mov ptr[reg_ptr],rcx
1484 op_mov_MR(GetTypeSize(type,-1),REG_RCX,reg_ptr,0,MOD_BASE);
1485 }
1486}
Note: See TracBrowser for help on using the repository browser.