source: dev/BasicCompiler64/Compile_Statement.cpp@ 31

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

_System_LocalThis(見えないThisポインタパラメータ)を通常のパラメータ保有領域ではなく、リアルパラメータ保有領域に移動した。
メソッドとグローバル関数のオーバーロードに対応(DLL関数オーバーロードには未対応)。

File size: 33.3 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_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 = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3);
841 int iParmNum=0;
842 ppi[iParmNum].bArray=0;
843 ppi[iParmNum].bByVal=0;
844 ppi[iParmNum].name=0;
845 ppi[iParmNum].type=type2;
846 ppi[iParmNum].u.index=lpIndex2;
847 ppi[iParmNum].SubScripts[0]=-1;
848 iParmNum++;
849
850 //オーバーロードを解決
851 SUBINFO *psi;
852 psi=OverloadSolution("==",ppsi,num,ppi,iParmNum,NULL);
853 HeapDefaultFree(ppsi);
854 HeapDefaultFree(ppi);
855
856 if(!psi){
857 //エラー
858 return;
859 }
860
861
862 //実体オブジェクト
863 if(reg2!=REG_RDX){
864 //mov rdx,reg2
865 op_mov_RR(REG_RDX,reg2);
866 }
867
868 //mov rcx,qword ptr[rsp+offset] ※スタックフレームから参照
869 pobj_sf->ref(REG_RCX);
870
871 //call operator_proc ※ ==演算子
872 op_call(psi);
873
874 //test rax,rax
875 op_test(REG_RAX,REG_RAX);
876
877 //jne ...
878 OpBuffer[obp++]=(char)0x0F;
879 OpBuffer[obp++]=(char)0x85;
880 }
881 else{
882 if(type1==DEF_DOUBLE){
883 int xmm_reg;
884 if(IsXmmReg(reg2)) xmm_reg=reg2;
885 else xmm_reg=REG_XMM5;
886 ChangeTypeToXmm_Double(type2,xmm_reg,reg2);
887
888 //movsd xmm4,qword ptr[rsp+offset] ※スタックフレームから参照
889 pobj_sf->ref(REG_XMM4,sizeof(double));
890
891 //comiss xmm_reg1,xmm_reg2
892 op_comisd(xmm_reg,REG_XMM4);
893 }
894 else if(type1==DEF_SINGLE){
895 int xmm_reg;
896 if(IsXmmReg(reg2)) xmm_reg=reg2;
897 else xmm_reg=REG_XMM5;
898 ChangeTypeToXmm_Single(type2,xmm_reg,reg2);
899
900 //movss xmm4,dword ptr[rsp+offset] ※スタックフレームから参照
901 pobj_sf->ref(REG_XMM4,sizeof(float));
902
903 //comiss xmm_reg1,xmm_reg2
904 op_comiss(xmm_reg,REG_XMM4);
905 }
906 else{
907 //その他整数型
908
909 i2=NeutralizationType(type1,-1,type2,-1);
910
911 //mov r14,qword ptr[rsp+offset] ※スタックフレームから参照
912 pobj_sf->ref(REG_R14);
913
914 //cmp reg2,r14
915 op_cmp_reg(GetTypeSize(i2,-1),reg2,REG_R14);
916 }
917
918 //je ...
919 OpBuffer[obp++]=(char)0x0F;
920 OpBuffer[obp++]=(char)0x84;
921 }
922 AddCaseSchedule();
923 obp+=sizeof(long);
924
925 if(basbuf[i]!=',') break;
926 }
927 }
928 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){
929 //jmp ...
930 OpBuffer[obp++]=(char)0xE9;
931 AddCaseSchedule();
932 obp+=sizeof(long);
933 }
934 }
935
936 //スタックフレームを1スペースだけ解除
937 pobj_sf->pop(REG_NON);
938
939 //レキシカルスコープをレベルアップ
940 obj_LexScopes.LevelUp(obp);
941
942 //Select Case内をコンパイル
943 CompileBuffer(ESC_ENDSELECT,0);
944
945 //jmp EndSelect
946 OpBuffer[obp++]=(char)0xE9;
947 AddCaseSchedule();
948 obp+=sizeof(long);
949
950 //最終スケジュール
951 for(i=NowCaseSchedule;i<CaseScheduleNum;i++){
952 *(long *)(OpBuffer+pCaseSchedule[i])=obp-(pCaseSchedule[i]+sizeof(long));
953 }
954 HeapDefaultFree(pCaseSchedule);
955
956 //レキシカルスコープをレベルダウン
957 obj_LexScopes.LevelDown();
958
959 pCaseSchedule=temp_pCaseSchedule;
960 CaseScheduleNum=temp_CaseScheduleNum;
961 NowCaseSchedule=temp_NowCaseSchedule;
962}
963void OpcodeCase(char *Parameter){
964 extern DWORD *pCaseSchedule;
965 extern int NowCaseSchedule;
966 int i;
967
968 if(!pCaseSchedule){
969 SetError(30,"Case",cp);
970 return;
971 }
972
973 //jmp EndSelect
974 OpBuffer[obp++]=(char)0xE9;
975 AddCaseSchedule();
976 obp+=sizeof(long);
977
978 i=0;
979 while(1){
980 //Caseスケジュール
981 *(long *)(OpBuffer+pCaseSchedule[NowCaseSchedule])=obp-(pCaseSchedule[NowCaseSchedule]+sizeof(long));
982 NowCaseSchedule++;
983
984 i=JumpOneParameter(Parameter,i);
985 if(Parameter[i]=='\0') break;
986 }
987}
988
989void OpcodeGosub(char *Parameter){
990 extern HANDLE hHeap;
991 extern GOTOLABELSCHEDULE *pGotoLabelSchedule;
992 extern int GotoLabelScheduleNum;
993 int i,LineNum;
994
995 //call _System_GetEip
996 extern SUBINFO *pSub_System_GetEip;
997 op_call(pSub_System_GetEip);
998
999 //add rax,offset(Gosubステートメントの最終ポイント)
1000 int schedule=obp,schedule2;
1001 op_add64_value(REG_RAX,0);
1002 schedule2=obp-sizeof(long);
1003
1004 //※戻り先用のrip
1005 //mov qword ptr[rsp+offset],rax ※スタックフレームを利用
1006 pobj_sf->push(REG_RAX);
1007
1008
1009 if(Parameter[0]=='*'){
1010 i=GetLabelAddress(Parameter+1,0);
1011
1012 //jmp ...
1013 OpBuffer[obp++]=(char)0xE9;
1014 if(i==-1){
1015 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
1016 pGotoLabelSchedule[GotoLabelScheduleNum].pName=(char *)HeapAlloc(hHeap,0,lstrlen(Parameter+1)+1);
1017 lstrcpy(pGotoLabelSchedule[GotoLabelScheduleNum].pName,Parameter+1);
1018 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
1019 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
1020 GotoLabelScheduleNum++;
1021 }
1022 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
1023 obp+=sizeof(long);
1024 }
1025 else{
1026 LineNum=atoi(Parameter);
1027 i=GetLabelAddress(0,LineNum);
1028
1029 //jmp ...
1030 OpBuffer[obp++]=(char)0xE9;
1031 if(i==-1){
1032 pGotoLabelSchedule=(GOTOLABELSCHEDULE *)HeapReAlloc(hHeap,0,pGotoLabelSchedule,(GotoLabelScheduleNum+1)*sizeof(GOTOLABELSCHEDULE));
1033 pGotoLabelSchedule[GotoLabelScheduleNum].pName=0;
1034 pGotoLabelSchedule[GotoLabelScheduleNum].line=LineNum;
1035 pGotoLabelSchedule[GotoLabelScheduleNum].pos=obp;
1036 pGotoLabelSchedule[GotoLabelScheduleNum].now_cp=cp;
1037 GotoLabelScheduleNum++;
1038 }
1039 *((long *)(OpBuffer+obp))=i-(obp+sizeof(long));
1040 obp+=sizeof(long);
1041 }
1042
1043 *((long *)(OpBuffer+schedule2))=obp-schedule;
1044
1045 //※スタックフレームを元に戻す
1046 pobj_sf->pop(REG_NON);
1047
1048 SetError(-1,"Gosub ~ Returnステートメントは64ビットコンパイラで利用することはできません。",cp);
1049}
1050void OpcodeReturn(char *Parameter){
1051 extern BOOL bCompilingGlobal;
1052 if(bCompilingGlobal){
1053 //Gosub~Returnとして扱う
1054
1055 //mov rax,qword ptr[rsp+offset] ※スタックフレームを利用
1056 pobj_sf->push(REG_NON);
1057 pobj_sf->ref(REG_RAX);
1058 pobj_sf->pop(REG_NON);
1059
1060 //jmp rax
1061 OpBuffer[obp++]=(char)0xFF;
1062 OpBuffer[obp++]=(char)0xE0;
1063 }
1064 else{
1065 //戻り値をセット
1066 if(Parameter[0]){
1067 extern SUBINFO *pCompilingSubInfo;
1068 char *temp;
1069 if(pCompilingSubInfo->name[0]==1&&pCompilingSubInfo->name[1]==ESC_OPERATOR)
1070 temp="_System_ReturnValue";
1071 else temp=pCompilingSubInfo->name;
1072
1073 char temporary[VN_SIZE];
1074 sprintf(temporary,"%s=%s",temp,Parameter);
1075 OpcodeCalc(temporary);
1076 }
1077
1078 //プロシージャを抜け出す(C言語のreturnと同様の処理を行う)
1079 OpcodeExitSub();
1080 }
1081}
1082
1083void Opcode_Input(char *Parameter){
1084 extern int cp;
1085 int i2,i3,i4,i5,type;
1086 BOOL bFile;
1087 char temporary[VN_SIZE],temp2[VN_SIZE],buffer[VN_SIZE];
1088
1089 KillStringSpaces(Parameter);
1090
1091 if(Parameter[0]=='#'){
1092 bFile=1;
1093 for(i2=0,i3=1;;i2++,i3++){
1094 buffer[i2]=Parameter[i3];
1095 if(Parameter[i3]==','||Parameter[i3]=='\0') break;
1096 }
1097 buffer[i2+1]=0;
1098 i2=i3+1;
1099 }
1100 else{
1101 bFile=0;
1102 i2=0;
1103 buffer[0]=0;
1104
1105 //表示用文字列パラメータをセット
1106 if(Parameter[0]=='\"'){
1107 buffer[0]='\"';
1108 for(i2=1;;i2++){
1109 if(Parameter[i2]=='\"'){
1110 buffer[i2]=0;
1111 break;
1112 }
1113 buffer[i2]=Parameter[i2];
1114 }
1115 if(Parameter[i2+1]==';') lstrcpy(buffer+i2,"? \"");
1116 else if(Parameter[i2+1]==',') lstrcpy(buffer+i2,"\"");
1117 else SetError(10,"Input",cp);
1118 i2+=2;
1119 }
1120 else if((Parameter[0]=='e'||Parameter[0]=='E')&&
1121 (Parameter[1]=='x'||Parameter[1]=='X')&&
1122 Parameter[2]=='\"'){
1123 memcpy(buffer,Parameter,3);
1124 for(i2=3;;i2++){
1125 if(Parameter[i2]=='\"'){
1126 buffer[i2]=0;
1127 break;
1128 }
1129 buffer[i2]=Parameter[i2];
1130 }
1131 if(Parameter[i2+1]==';') lstrcpy(buffer+i2,"? \"");
1132 else if(Parameter[i2+1]==',') lstrcpy(buffer+i2,"\"");
1133 else SetError(10,"Input",cp);
1134 i2+=2;
1135 }
1136 else{
1137 lstrcpy(buffer,"\"? \"");
1138 i2=0;
1139 }
1140 }
1141
1142 //変数ポインタ、変数のタイプをセット
1143 i4=0;
1144 while(1){
1145 for(i3=0;;i2++,i3++){
1146 if(Parameter[i2]=='('){
1147 i5=GetStringInPare(temporary+i3,Parameter+i2);
1148 i2+=i5-1;
1149 i3+=i5-1;
1150 }
1151 if(Parameter[i2]=='['){
1152 i5=GetStringInBracket(temporary+i3,Parameter+i2);
1153 i2+=i5-1;
1154 i3+=i5-1;
1155 }
1156 if(Parameter[i2]==','){
1157 temporary[i3]=0;
1158 i2++;
1159 break;
1160 }
1161 temporary[i3]=Parameter[i2];
1162 if(Parameter[i2]=='\0') break;
1163 }
1164 if(temporary[0]=='\0'){
1165 SetError(10,"Input",cp);
1166 return;
1167 }
1168
1169 LONG_PTR lpIndex;
1170 type = GetVarType(temporary, &lpIndex, 1);
1171
1172 sprintf(temp2,"_System_InputDataPtr[%d]=VarPtr(%s)",i4,temporary);
1173 OpcodeCalc(temp2);
1174
1175 if(type==DEF_LONG) type=DEF_DWORD;
1176 else if(type==DEF_INTEGER) type=DEF_WORD;
1177 else if(type==DEF_OBJECT){
1178 CClass *pobj_Class=(CClass *)lpIndex;
1179 if(lstrcmp(pobj_Class->name,"String")==0) type=DEF_STRING;
1180 }
1181 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,type);
1182 OpcodeCalc(temp2);
1183
1184 i4++;
1185 if(Parameter[i2]=='\0') break;
1186 }
1187 sprintf(temp2,"_System_InputDataPtr[%d]=0",i4);
1188 OpcodeCalc(temp2);
1189
1190 SUBINFO *psi;
1191 if(bFile) psi=GetSubHash("INPUT_FromFile");
1192 else psi=GetSubHash("INPUT_FromPrompt");
1193 if(!psi){
1194 SetError(3,"Input",cp);
1195 return;
1196 }
1197 Opcode_CallProc(buffer,psi,0,"",0);
1198}
1199void Opcode_PrintUsing(char *Parameter,char *buffer,BOOL bFile){
1200 extern int cp;
1201 int i2,i3,i4,i5;
1202 char temporary[VN_SIZE],temp2[8192];
1203 BOOL bReturnLine;
1204
1205 i2=lstrlen(Parameter);
1206 if(Parameter[i2-1]==';'){
1207 bReturnLine=0;
1208 Parameter[i2-1]=0;
1209 }
1210 else bReturnLine=1;
1211
1212 i3=lstrlen(buffer);
1213 for(i2=0;;i2++,i3++){
1214 if(Parameter[i2]==';'){
1215 buffer[i3]=0;
1216 break;
1217 }
1218 buffer[i3]=Parameter[i2];
1219 if(Parameter[i2]=='\0') break;
1220 }
1221 if(Parameter[i2]==';') i2++;
1222
1223 if(bReturnLine) lstrcat(buffer,"+Ex\"\\r\\n\"");
1224
1225 //データポインタ、データのタイプをセット
1226 i4=0;
1227 while(1){
1228 for(i3=0;;i2++,i3++){
1229 if(Parameter[i2]=='\"'){
1230 temporary[i3]=Parameter[i2];
1231 for(i2++,i3++;;i2++,i3++){
1232 temporary[i3]=Parameter[i2];
1233 if(Parameter[i2]=='\"') break;
1234 }
1235 continue;
1236 }
1237 if(Parameter[i2]=='('){
1238 i5=GetStringInPare(temporary+i3,Parameter+i2);
1239 i2+=i5-1;
1240 i3+=i5-1;
1241 continue;
1242 }
1243 if(Parameter[i2]=='['){
1244 i5=GetStringInBracket(temporary+i3,Parameter+i2);
1245 i2+=i5-1;
1246 i3+=i5-1;
1247 continue;
1248 }
1249 if(Parameter[i2]==','){
1250 temporary[i3]=0;
1251 i2++;
1252 break;
1253 }
1254 temporary[i3]=Parameter[i2];
1255 if(Parameter[i2]=='\0') break;
1256 }
1257 if(temporary[0]=='\0'){
1258 SetError(10,"Print",cp);
1259 return;
1260 }
1261
1262 int iResult;
1263 iResult=IsStrCalculation(temporary);
1264
1265 if(iResult==1){
1266 //文字列
1267 sprintf(temp2,"_System_UsingStrData[%d]=%s",i4,temporary);
1268 OpcodeCalc(temp2);
1269
1270 sprintf(temp2,"_System_UsingDataType[%d]=%d",i4,DEF_STRING);
1271 OpcodeCalc(temp2);
1272 }
1273 else if(iResult==0){
1274 //数値
1275 sprintf(temp2,"_System_UsingDblData[%d]=%s",i4,temporary);
1276 OpcodeCalc(temp2);
1277
1278 sprintf(temp2,"_System_UsingDataType[%d]=%d",i4,DEF_DOUBLE);
1279 OpcodeCalc(temp2);
1280 }
1281 //else if(iResult==-1) エラー
1282
1283 i4++;
1284 if(Parameter[i2]=='\0') break;
1285 }
1286 sprintf(temp2,"_System_UsingDataType[%d]=-1",i4);
1287 OpcodeCalc(temp2);
1288
1289 SUBINFO *psi;
1290 if(bFile) psi=GetSubHash("PRINTUSING_ToFile");
1291 else psi=GetSubHash("PRINTUSING_ToPrompt");
1292 if(!psi){
1293 SetError(3,"Print",cp);
1294 return;
1295 }
1296 Opcode_CallProc(buffer,psi,0,"",0);
1297}
1298void Opcode_Print(char *Parameter,BOOL bWrite){
1299 int i2,i3,i4,sw;
1300 char temporary[VN_SIZE],buffer[VN_SIZE];
1301 BOOL bFile;
1302
1303 KillStringSpaces(Parameter);
1304
1305 if(Parameter[0]=='#'){
1306 bFile=1;
1307 for(i2=0,i3=1;;i2++,i3++){
1308 buffer[i2]=Parameter[i3];
1309 if(Parameter[i3]==','||Parameter[i3]=='\0') break;
1310 }
1311 buffer[i2+1]=0;
1312 if(Parameter[i3]==',') i3++;
1313 i2=i3;
1314 }
1315 else{
1316 bFile=0;
1317 i2=0;
1318 buffer[0]=0;
1319 }
1320 if(Parameter[i2]==1&&Parameter[i2+1]==ESC_USING){
1321 Opcode_PrintUsing(Parameter+i2+2,buffer,bFile);
1322 return;
1323 }
1324
1325 lstrcat(buffer,"_System_DummyStr+");
1326
1327 sw=1;
1328 while(1){
1329 for(i3=0;;i2++,i3++){
1330 if(Parameter[i2]=='\"'){
1331 temporary[i3]=Parameter[i2];
1332 for(i2++,i3++;;i2++,i3++){
1333 temporary[i3]=Parameter[i2];
1334 if(Parameter[i2]=='\"') break;
1335 }
1336 continue;
1337 }
1338 if(Parameter[i2]=='('){
1339 i4=GetStringInPare(temporary+i3,Parameter+i2);
1340 i2+=i4-1;
1341 i3+=i4-1;
1342 continue;
1343 }
1344 if(Parameter[i2]=='['){
1345 i4=GetStringInBracket(temporary+i3,Parameter+i2);
1346 i2+=i4-1;
1347 i3+=i4-1;
1348 continue;
1349 }
1350 if(Parameter[i2]==','||Parameter[i2]==';'){
1351 temporary[i3]=0;
1352 break;
1353 }
1354 temporary[i3]=Parameter[i2];
1355 if(Parameter[i2]=='\0') break;
1356 }
1357
1358 if(temporary[0]=='\0') lstrcat(buffer,"\"\"");
1359 else{
1360 int iResult;
1361 iResult=IsStrCalculation(temporary);
1362 if(iResult==-1){
1363 //エラー
1364 lstrcat(buffer,"\"\"");
1365 }
1366 else if(iResult){
1367 //文字列
1368 lstrcat(buffer,temporary);
1369 }
1370 else{
1371 //数値
1372 sprintf(buffer+lstrlen(buffer),"Str$(%s)",temporary);
1373 }
1374 }
1375
1376 if(Parameter[i2]==','){
1377 if(bWrite) lstrcat(buffer,"+\",\"+");
1378 else lstrcat(buffer,"+\"\t\"+");
1379 }
1380 else if(Parameter[i2]==';'){
1381 if(Parameter[i2+1]=='\0'){
1382 sw=0;
1383 break;
1384 }
1385 if(bWrite) lstrcat(buffer,"+\",\"+");
1386 else lstrcat(buffer,"+\" \"+");
1387 }
1388 else if(Parameter[i2]=='\0') break;
1389
1390 i2++;
1391 }
1392
1393 if(sw) lstrcat(buffer,"+Ex\"\\r\\n\"");
1394
1395 SUBINFO *psi;
1396 if(bFile) psi=GetSubHash("PRINT_ToFile");
1397 else psi=GetSubHash("PRINT_ToPrompt");
1398 if(!psi){
1399 SetError(3,"Print",cp);
1400 return;
1401 }
1402 Opcode_CallProc(buffer,psi,0,"",0);
1403}
1404
1405
1406
1407
1408////////////
1409// ポインタ
1410////////////
1411
1412void OpcodeSetPtrData(char *Parameter,int type){
1413 int i,i2;
1414 char temporary[VN_SIZE];
1415
1416 if(Parameter[0]=='('){
1417 i=JumpStringInPare(Parameter,1);
1418 if(Parameter[i+1]=='\0'){
1419 for(i=0;;i++){
1420 Parameter[i]=Parameter[i+1];
1421 if(Parameter[i]=='\0') break;
1422 }
1423 Parameter[i-1]=0;
1424 }
1425 }
1426
1427 //第1パラメータを取得
1428 i=GetOneParameter(Parameter,0,temporary);
1429 if(!Parameter[i]){
1430 SetError(1,NULL,cp);
1431 return;
1432 }
1433
1434 int reg_ptr=REG_RAX;
1435 i2=NumOpe(&reg_ptr,temporary,0,0,0);
1436 if(!IsWholeNumberType(i2)){
1437 SetError(11,Parameter,cp);
1438 return;
1439 }
1440
1441 //結果を格納しているレジスタをブロッキング
1442 pobj_BlockReg->lock(reg_ptr);
1443
1444 //第2パラメータを取得
1445 i=GetOneParameter(Parameter,i,temporary);
1446 if(Parameter[i]){
1447 SetError(1,NULL,cp);
1448 return;
1449 }
1450
1451 int temp_reg=REG_NON;
1452 i2=NumOpe(&temp_reg,temporary,0,0,0);
1453
1454 //レジスタのブロッキングを解除
1455 pobj_BlockReg->clear();
1456
1457 if(type==DEF_DOUBLE){
1458 ChangeTypeToXmm_Double(i2,REG_XMM0,temp_reg);
1459
1460 //movsd qword ptr[reg_ptr],xmm0
1461 op_movsd_MR(REG_XMM0,reg_ptr,0,MOD_BASE);
1462 }
1463 else if(type==DEF_SINGLE){
1464 ChangeTypeToXmm_Single(i2,REG_XMM0,temp_reg);
1465
1466 //movss dword ptr[reg_ptr],xmm0
1467 op_movss_MR(REG_XMM0,reg_ptr,0,MOD_BASE);
1468 }
1469 else{
1470 ChangeTypeToWhole(i2,type,REG_RCX,temp_reg);
1471
1472 //mov ptr[reg_ptr],rcx
1473 op_mov_MR(GetTypeSize(type,-1),REG_RCX,reg_ptr,0,MOD_BASE);
1474 }
1475}
Note: See TracBrowser for help on using the repository browser.