Changeset 75 in dev for BasicCompiler64/Compile_Statement.cpp
- Timestamp:
- Mar 20, 2007, 4:36:16 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler64/Compile_Statement.cpp
r73 r75 5 5 int i,i2; 6 6 char buffer[8192]; 7 SubInfo *psi;7 UserProc *pUserProc; 8 8 9 9 for(i=0;;i++){ … … 41 41 ////////////////////////////// 42 42 43 p si=GetSubHash(Command);43 pUserProc=GetSubHash(Command); 44 44 45 45 //GetSubHash内でエラー提示が行われた場合 46 if(p si==(SubInfo*)-1) return;47 48 if(p si==0){46 if(pUserProc==(UserProc *)-1) return; 47 48 if(pUserProc==0){ 49 49 char temporary[VN_SIZE]; 50 50 lstrcpy(temporary,Command); 51 51 52 52 CharUpper(temporary); 53 p si=GetSubHash(temporary);53 pUserProc=GetSubHash(temporary); 54 54 55 55 //GetSubHash内でエラー提示が行われた場合 56 if(p si==(SubInfo*)-1) return;57 } 58 59 if(p si){60 if( psi->dwType!=SUBTYPE_MACRO) SetError(10,Command,cp);61 62 Opcode_CallProc("",p si,0,"",0);56 if(pUserProc==(UserProc *)-1) return; 57 } 58 59 if(pUserProc){ 60 if( !pUserProc->IsMacro() ) SetError(10,Command,cp); 61 62 Opcode_CallProc("",pUserProc,0,"",0); 63 63 64 64 return; … … 72 72 73 73 int idProc; 74 void *p Info;75 idProc=GetProc(buffer, &pInfo);74 void *pProc; 75 idProc=GetProc(buffer,(void **)&pProc); 76 76 77 77 int i4; … … 91 91 //////////////// 92 92 93 LONG_PTR lp;94 i2=CallProc(idProc,pInfo,buffer,temp2,&lp);93 Type resultType; 94 CallProc(idProc,pProc,buffer,temp2,resultType); 95 95 96 96 … … 99 99 ///////////////////// 100 100 101 if( i2==DEF_STRUCT){101 if( resultType.IsStruct() ){ 102 102 //mov r14,rax 103 103 op_mov_RR(REG_R14,REG_RAX); 104 104 105 FreeTempObject(REG_R14, (CClass *)lp);105 FreeTempObject(REG_R14,&resultType.GetClass()); 106 106 } 107 107 return; … … 116 116 117 117 void Judgment(char *buffer){ 118 int reg=REG_RAX,type; 119 type=NumOpe(®,buffer,0,0,0); 118 int reg=REG_RAX; 119 Type resultType; 120 if( !NumOpe(®,buffer,Type(),resultType) ){ 121 return; 122 } 120 123 121 124 int offset; 122 125 123 if( type==DEF_DOUBLE){126 if(resultType.IsDouble()){ 124 127 double dbl=0; 125 128 offset=dataTable.Add( dbl ); … … 135 138 obp+=sizeof(long); 136 139 } 137 else if( type==DEF_SINGLE){140 else if(resultType.IsSingle()){ 138 141 float flt=0; 139 142 offset=dataTable.Add( flt ); … … 152 155 153 156 //cmp rax,0 154 op_cmp_value( GetTypeSize(type,-1),REG_RAX,0);157 op_cmp_value(resultType.GetSize(),REG_RAX,0); 155 158 } 156 159 } … … 340 343 void OpcodeFor(char *Parameter){ 341 344 extern HANDLE hHeap; 345 Type resultType; 342 346 int i,i2,i3; 343 347 char temporary[VN_SIZE],variable[VN_SIZE],JudgeNum[VN_SIZE],StepNum[VN_SIZE]; … … 400 404 sprintf(temporary,"(%s)>=0",StepNum); 401 405 402 int reg ,type;406 int reg; 403 407 reg=REG_RAX; 404 type=NumOpe(®,temporary,0,0,0); 408 if( !NumOpe(®,temporary,Type(),resultType) ){ 409 return; 410 } 405 411 406 412 //cmp rax,0 407 op_cmp_value( GetTypeSize(type,-1),REG_RAX,0);413 op_cmp_value(resultType.GetSize(),REG_RAX,0); 408 414 409 415 //je [カウンタ減少の場合の判定] … … 417 423 418 424 reg=REG_RAX; 419 type=NumOpe(®,temporary,0,0,0);425 NumOpe(®,temporary,Type(),Type()); 420 426 421 427 //jmp [カウンタ減少の場合の判定を飛び越す] … … 430 436 431 437 reg=REG_RAX; 432 type=NumOpe(®,temporary,0,0,0);438 NumOpe(®,temporary,Type(),resultType); 433 439 434 440 *((long *)(OpBuffer+i3))=obp-(i3+sizeof(long)); //jmpジャンプ先のオフセット値 435 441 436 442 //cmp rax,0 437 op_cmp_value( GetTypeSize(type,-1),REG_RAX,0);443 op_cmp_value(resultType.GetSize(),REG_RAX,0); 438 444 439 445 ErrorStep: … … 583 589 extern HANDLE hHeap; 584 590 585 extern BOOL bCompilingGlobal; 586 if(bCompilingGlobal){ 591 if( UserProc::IsGlobalAreaCompiling() ){ 587 592 SetError(12,"Exit Sub/Function",cp); 588 593 return; … … 611 616 CaseScheduleNum++; 612 617 } 613 void OpcodeSelect( char *Parameter){618 void OpcodeSelect( const char *lpszParms ){ 614 619 extern DWORD *pCaseSchedule; 615 620 extern int CaseScheduleNum; … … 631 636 NowCaseSchedule=0; 632 637 633 int reg1=REG_RAX,type1; 634 LONG_PTR lpIndex; 635 type1=NumOpe(®1,Parameter,0,0,&lpIndex); 636 637 if(type1==DEF_DOUBLE){ 638 int reg1=REG_RAX; 639 Type type1; 640 if( !NumOpe(®1,lpszParms,Type(), type1 ) ){ 641 return; 642 } 643 644 if(type1.IsDouble()){ 638 645 //movsd qword ptr[rsp+offset],xmm_reg ※スタックフレームを利用 639 646 pobj_sf->push(reg1,sizeof(double)); 640 647 } 641 else if(type1 ==DEF_SINGLE){648 else if(type1.IsSingle()){ 642 649 //movss dword ptr[rsp+offset],xmm_reg ※スタックフレームを利用 643 650 pobj_sf->push(reg1,sizeof(float)); 644 651 } 645 652 else{ 646 ExtendTypeTo64(type1 ,reg1);653 ExtendTypeTo64(type1.GetBasicType(),reg1); 647 654 648 655 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用 … … 712 719 cp=NowCaseCp; 713 720 714 int reg2=REG_RDX,type2; 715 LONG_PTR lpIndex2; 716 type2=NumOpe(®2,temporary,type1,lpIndex,&lpIndex2); 721 int reg2=REG_RDX; 722 Type type2; 723 if( !NumOpe(®2,temporary,type1,type2) ){ 724 return; 725 } 717 726 718 727 cp=i2; 719 728 720 if(type1==DEF_OBJECT){ 721 CClass *pobj_c; 722 pobj_c=(CClass *)lpIndex; 723 724 std::vector<SubInfo *> subs; 725 pobj_c->EnumMethod( CALC_EQUAL, subs ); 729 if(type1.IsObject()){ 730 std::vector<UserProc *> subs; 731 type1.GetClass().EnumMethod( CALC_EQUAL, subs ); 726 732 if( subs.size() == 0 ){ 727 733 return; 728 734 } 729 735 730 PARAMETER_INFO *ppi = (PARAMETER_INFO *)HeapAlloc(hHeap,0,sizeof(PARAMETER_INFO)*3); 731 int iParmNum=0; 732 ppi[iParmNum].bArray=0; 733 ppi[iParmNum].bByVal=0; 734 ppi[iParmNum].name=0; 735 ppi[iParmNum].type=type2; 736 ppi[iParmNum].u.index=lpIndex2; 737 ppi[iParmNum].SubScripts[0]=-1; 738 iParmNum++; 736 Parameters params; 737 params.push_back( new Parameter( "", Type( type2 ) ) ); 739 738 740 739 //オーバーロードを解決 741 SubInfo *psi; 742 psi=OverloadSolution("==",subs,ppi,iParmNum,NULL); 743 HeapDefaultFree(ppi); 744 745 if(!psi){ 740 UserProc *pUserProc; 741 pUserProc=OverloadSolution("==",subs, params, NULL); 742 743 delete params[0]; 744 745 if(!pUserProc){ 746 746 //エラー 747 747 return; … … 759 759 760 760 //call operator_proc ※ ==演算子 761 op_call(p si);761 op_call(pUserProc); 762 762 763 763 //test rax,rax … … 769 769 } 770 770 else{ 771 if(type1 ==DEF_DOUBLE){771 if(type1.IsDouble()){ 772 772 int xmm_reg; 773 773 if(IsXmmReg(reg2)) xmm_reg=reg2; 774 774 else xmm_reg=REG_XMM5; 775 ChangeTypeToXmm_Double(type2 ,xmm_reg,reg2);775 ChangeTypeToXmm_Double(type2.GetBasicType(),xmm_reg,reg2); 776 776 777 777 //movsd xmm4,qword ptr[rsp+offset] ※スタックフレームから参照 … … 781 781 op_comisd(xmm_reg,REG_XMM4); 782 782 } 783 else if(type1 ==DEF_SINGLE){783 else if(type1.IsSingle()){ 784 784 int xmm_reg; 785 785 if(IsXmmReg(reg2)) xmm_reg=reg2; 786 786 else xmm_reg=REG_XMM5; 787 ChangeTypeToXmm_Single(type2 ,xmm_reg,reg2);787 ChangeTypeToXmm_Single(type2.GetBasicType(),xmm_reg,reg2); 788 788 789 789 //movss xmm4,dword ptr[rsp+offset] ※スタックフレームから参照 … … 796 796 //その他整数型 797 797 798 i2=NeutralizationType(type1 ,-1,type2,-1);798 i2=NeutralizationType(type1.GetBasicType(),-1,type2.GetBasicType(),-1); 799 799 800 800 //mov r14,qword ptr[rsp+offset] ※スタックフレームから参照 … … 883 883 884 884 //call _System_GetEip 885 extern SubInfo*pSub_System_GetEip;885 extern UserProc *pSub_System_GetEip; 886 886 op_call(pSub_System_GetEip); 887 887 … … 938 938 } 939 939 void OpcodeReturn(char *Parameter){ 940 extern BOOL bCompilingGlobal; 941 if(bCompilingGlobal){ 940 if( UserProc::IsGlobalAreaCompiling() ){ 942 941 SetError(62,NULL,cp); 943 942 } … … 945 944 //戻り値をセット 946 945 if(Parameter[0]){ 947 extern SubInfo *pCompilingSubInfo; 948 char *temp; 949 if(pCompilingSubInfo->name[0]==1&&pCompilingSubInfo->name[1]==ESC_OPERATOR) 950 temp="_System_ReturnValue"; 951 else temp=pCompilingSubInfo->name; 952 953 /* 954 TODO: 消す 955 if( pCompilingSubInfo->isReturnRef ){ 956 //参照型 957 SetRefVariable( temp, Parameter ); 946 UserProc &proc = UserProc::CompilingUserProc(); 947 948 const char *temp = "_System_ReturnValue"; 949 if(proc.GetName()[0]==1&&proc.GetName()[1]==ESC_OPERATOR) 950 { 958 951 } 959 952 else{ 960 //値型*/ 961 char temporary[VN_SIZE]; 962 sprintf(temporary,"%s=%s",temp,Parameter); 963 OpcodeCalc(temporary); 964 //} 953 temp=proc.GetName().c_str(); 954 } 955 956 char temporary[VN_SIZE]; 957 sprintf(temporary,"%s=%s",temp,Parameter); 958 OpcodeCalc(temporary); 965 959 } 966 960 … … 972 966 void Opcode_Input(const char *Parameter){ 973 967 extern int cp; 974 int i2,i3,i4,i5 ,type;968 int i2,i3,i4,i5; 975 969 BOOL bFile; 976 970 char temporary[VN_SIZE],temp2[VN_SIZE],buffer[VN_SIZE]; … … 1054 1048 } 1055 1049 1056 LONG_PTR lpIndex; 1057 type = GetVarType(temporary, &lpIndex, 1); 1050 Type varType; 1051 if( !GetVarType(temporary, varType, 1) ){ 1052 return; 1053 } 1058 1054 1059 1055 sprintf(temp2,"_System_InputDataPtr[%d]=VarPtr(%s)",i4,temporary); 1060 1056 OpcodeCalc(temp2); 1061 1057 1062 if(type==DEF_LONG) type=DEF_DWORD; 1063 else if(type==DEF_INTEGER) type=DEF_WORD; 1064 else if(type==DEF_OBJECT){ 1065 CClass *pobj_Class=(CClass *)lpIndex; 1066 if(lstrcmp(pobj_Class->name,"String")==0) type=DEF_STRING; 1067 } 1068 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,type); 1058 if(varType.IsLong()) varType.SetBasicType( DEF_DWORD ); 1059 else if(varType.IsInteger()) varType.SetBasicType( DEF_WORD ); 1060 else if(varType.IsObject()){ 1061 varType.SetBasicType( DEF_OBJECT ); 1062 if( varType.IsStringObject() ){ 1063 varType.SetBasicType( DEF_STRING ); 1064 } 1065 } 1066 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,varType.GetBasicType()); 1069 1067 OpcodeCalc(temp2); 1070 1068 … … 1075 1073 OpcodeCalc(temp2); 1076 1074 1077 SubInfo *psi;1078 if(bFile) p si=GetSubHash("INPUT_FromFile");1079 else p si=GetSubHash("INPUT_FromPrompt");1080 if(!p si){1075 UserProc *pUserProc; 1076 if(bFile) pUserProc=GetSubHash("INPUT_FromFile"); 1077 else pUserProc=GetSubHash("INPUT_FromPrompt"); 1078 if(!pUserProc){ 1081 1079 SetError(3,"Input",cp); 1082 1080 return; 1083 1081 } 1084 Opcode_CallProc(buffer,p si,0,"",0);1082 Opcode_CallProc(buffer,pUserProc,0,"",0); 1085 1083 } 1086 1084 void Opcode_PrintUsing(const char *Parameter,char *buffer,BOOL bFile){ … … 1177 1175 OpcodeCalc(temp2); 1178 1176 1179 SubInfo *psi;1180 if(bFile) p si=GetSubHash("PRINTUSING_ToFile");1181 else p si=GetSubHash("PRINTUSING_ToPrompt");1182 if(!p si){1177 UserProc *pUserProc; 1178 if(bFile) pUserProc=GetSubHash("PRINTUSING_ToFile"); 1179 else pUserProc=GetSubHash("PRINTUSING_ToPrompt"); 1180 if(!pUserProc){ 1183 1181 SetError(3,"Print",cp); 1184 1182 return; 1185 1183 } 1186 Opcode_CallProc(buffer,p si,0,"",0);1184 Opcode_CallProc(buffer,pUserProc,0,"",0); 1187 1185 } 1188 1186 void Opcode_Print(const char *Parameter,BOOL bWrite){ … … 1281 1279 if(sw) lstrcat(buffer,"+Ex\"\\r\\n\""); 1282 1280 1283 SubInfo *psi;1284 if(bFile) p si=GetSubHash("PRINT_ToFile");1285 else p si=GetSubHash("PRINT_ToPrompt");1286 if(!p si){1281 UserProc *pUserProc; 1282 if(bFile) pUserProc=GetSubHash("PRINT_ToFile"); 1283 else pUserProc=GetSubHash("PRINT_ToPrompt"); 1284 if(!pUserProc){ 1287 1285 SetError(3,"Print",cp); 1288 1286 return; 1289 1287 } 1290 Opcode_CallProc(buffer,p si,0,"",0);1288 Opcode_CallProc(buffer,pUserProc,0,"",0); 1291 1289 } 1292 1290 … … 1299 1297 1300 1298 void OpcodeSetPtrData(char *Parameter,int type){ 1301 int i ,i2;1299 int i; 1302 1300 char temporary[VN_SIZE]; 1303 1301 … … 1321 1319 1322 1320 int reg_ptr=REG_RAX; 1323 i2=NumOpe(®_ptr,temporary,0,0,0); 1324 if(!IsWholeNumberType(i2)){ 1321 Type resultType; 1322 if( !NumOpe(®_ptr,temporary,Type(),resultType) ){ 1323 return; 1324 } 1325 if(!resultType.IsWhole()){ 1325 1326 SetError(11,Parameter,cp); 1326 1327 return; … … 1338 1339 1339 1340 int temp_reg=REG_NON; 1340 i2=NumOpe(&temp_reg,temporary,0,0,0); 1341 if( !NumOpe(&temp_reg,temporary,Type(),resultType) ){ 1342 return; 1343 } 1341 1344 1342 1345 //レジスタのブロッキングを解除 … … 1344 1347 1345 1348 if(type==DEF_DOUBLE){ 1346 ChangeTypeToXmm_Double( i2,REG_XMM0,temp_reg);1349 ChangeTypeToXmm_Double(resultType.GetBasicType(),REG_XMM0,temp_reg); 1347 1350 1348 1351 //movsd qword ptr[reg_ptr],xmm0 … … 1350 1353 } 1351 1354 else if(type==DEF_SINGLE){ 1352 ChangeTypeToXmm_Single( i2,REG_XMM0,temp_reg);1355 ChangeTypeToXmm_Single(resultType.GetBasicType(),REG_XMM0,temp_reg); 1353 1356 1354 1357 //movss dword ptr[reg_ptr],xmm0 … … 1356 1359 } 1357 1360 else{ 1358 ChangeTypeToWhole( i2,type,REG_RCX,temp_reg);1361 ChangeTypeToWhole(resultType.GetBasicType(),type,REG_RCX,temp_reg); 1359 1362 1360 1363 //mov ptr[reg_ptr],rcx
Note:
See TracChangeset
for help on using the changeset viewer.