Changeset 408 in dev for trunk/abdev/BasicCompiler32
- Timestamp:
- Mar 2, 2008, 5:40:44 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/Compile_Statement.cpp
r402 r408 922 922 std::vector<SelectSchedule> selectSchedules; 923 923 924 void OpcodeSelect(const char *lpszParms){ 924 void OpcodeSelect(const char *lpszParms) 925 { 925 926 extern HANDLE hHeap; 926 927 extern char *basbuf; … … 929 930 930 931 Type type1; 931 if( !NumOpe(lpszParms,Type(), type1 ) ){ 932 return; 933 } 932 bool result = NumOpe(lpszParms,Type(), type1 ); 934 933 935 934 selectSchedules.push_back( SelectSchedule( type1.GetSize() ) ); 936 935 937 if( selectSchedules.back().typeSize < sizeof(long) ){ 938 selectSchedules.back().typeSize = sizeof(long); 939 } 940 941 for(i=cp,sw=0;;i++){ 942 if(basbuf[i]=='\0'){ 943 selectSchedules.pop_back(); 944 SetError(22,"Select",cp); 945 return; 946 } 947 if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE){ 948 for(i2=0;;i++){ 949 if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE) i2++; 950 if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){ 951 i2--; 952 if(i2==0) break; 936 if( result ) 937 { 938 if( selectSchedules.back().typeSize < sizeof(long) ){ 939 selectSchedules.back().typeSize = sizeof(long); 940 } 941 942 for(i=cp,sw=0;;i++){ 943 if(basbuf[i]=='\0'){ 944 selectSchedules.pop_back(); 945 SetError(22,"Select",cp); 946 return; 947 } 948 if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE){ 949 for(i2=0;;i++){ 950 if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE) i2++; 951 if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){ 952 i2--; 953 if(i2==0) break; 954 } 953 955 } 954 } 955 continue; 956 } 957 if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){ 958 if(sw==0){ 959 //add esp,CaseTypeSize 960 compiler.codeGenerator.op_add_esp( selectSchedules.back().typeSize ); 961 } 962 break; 963 } 964 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASE){ 965 NowCaseCp=i; 966 967 i++; 968 while(1){ 969 for(i++,i2=0;;i++,i2++){ 970 if(basbuf[i]=='\"'){ 971 i3=GetStringInQuotation(temporary+i2,basbuf+i); 972 i+=i3-1; 973 i2+=i3-1; 974 continue; 956 continue; 957 } 958 if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){ 959 if(sw==0){ 960 //add esp,CaseTypeSize 961 compiler.codeGenerator.op_add_esp( selectSchedules.back().typeSize ); 962 } 963 break; 964 } 965 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASE){ 966 NowCaseCp=i; 967 968 i++; 969 while(1){ 970 for(i++,i2=0;;i++,i2++){ 971 if(basbuf[i]=='\"'){ 972 i3=GetStringInQuotation(temporary+i2,basbuf+i); 973 i+=i3-1; 974 i2+=i3-1; 975 continue; 976 } 977 if(basbuf[i]=='('){ 978 i3=GetStringInPare(temporary+i2,basbuf+i); 979 i+=i3-1; 980 i2+=i3-1; 981 continue; 982 } 983 if(basbuf[i]=='['){ 984 i3=GetStringInBracket(temporary+i2,basbuf+i); 985 i+=i3-1; 986 i2+=i3-1; 987 continue; 988 } 989 990 if(IsCommandDelimitation(basbuf[i])){ 991 temporary[i2]=0; 992 break; 993 } 994 if(basbuf[i]==','){ 995 temporary[i2]=0; 996 break; 997 } 998 999 temporary[i2]=basbuf[i]; 975 1000 } 976 if(basbuf[i]=='('){ 977 i3=GetStringInPare(temporary+i2,basbuf+i); 978 i+=i3-1; 979 i2+=i3-1; 980 continue; 981 } 982 if(basbuf[i]=='['){ 983 i3=GetStringInBracket(temporary+i2,basbuf+i); 984 i+=i3-1; 985 i2+=i3-1; 986 continue; 987 } 988 989 if(IsCommandDelimitation(basbuf[i])){ 990 temporary[i2]=0; 991 break; 992 } 993 if(basbuf[i]==','){ 994 temporary[i2]=0; 995 break; 996 } 997 998 temporary[i2]=basbuf[i]; 999 } 1000 1001 //エラー用 1002 i2=cp; 1003 cp=NowCaseCp; 1004 1005 Type type2; 1006 if( !NumOpe(temporary,type1,type2) ){ 1007 return; 1008 } 1009 1010 cp=i2; 1011 1012 if(type1.IsObject()){ 1013 std::vector<const UserProc *> subs; 1014 type1.GetClass().GetDynamicMethods().Enum( CALC_EQUAL, subs ); 1015 if( subs.size() == 0 ){ 1001 1002 //エラー用 1003 i2=cp; 1004 cp=NowCaseCp; 1005 1006 Type type2; 1007 if( !NumOpe(temporary,type1,type2) ){ 1016 1008 return; 1017 1009 } 1018 1010 1019 Parameters params; 1020 params.push_back( new Parameter( "", Type( type2 ) ) ); 1021 1022 //オーバーロードを解決 1023 const UserProc *pUserProc = OverloadSolution("==",subs, params, NULL); 1024 1025 delete params[0]; 1026 1027 if(!pUserProc){ 1028 //エラー 1029 return; 1011 cp=i2; 1012 1013 if(type1.IsObject()){ 1014 std::vector<const UserProc *> subs; 1015 type1.GetClass().GetDynamicMethods().Enum( CALC_EQUAL, subs ); 1016 if( subs.size() == 0 ){ 1017 return; 1018 } 1019 1020 Parameters params; 1021 params.push_back( new Parameter( "", Type( type2 ) ) ); 1022 1023 //オーバーロードを解決 1024 const UserProc *pUserProc = OverloadSolution("==",subs, params, NULL); 1025 1026 delete params[0]; 1027 1028 if(!pUserProc){ 1029 //エラー 1030 return; 1031 } 1032 1033 1034 //pop edx 1035 compiler.codeGenerator.op_pop(REG_EDX); 1036 1037 //mov ecx,dword ptr[esp] 1038 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_ESP,0,MOD_BASE); 1039 1040 //push edx 1041 compiler.codeGenerator.op_push(REG_EDX); 1042 1043 //push ecx 1044 compiler.codeGenerator.op_push(REG_ECX); 1045 1046 //call operator_proc ※ ==演算子 1047 compiler.codeGenerator.op_call(pUserProc); 1048 1049 //test eax,eax 1050 compiler.codeGenerator.op_test(REG_EAX,REG_EAX); 1051 1052 //jne ... 1053 selectSchedules.back().casePertialSchedules.push_back( 1054 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 1055 ); 1030 1056 } 1031 1032 1033 //pop edx 1034 compiler.codeGenerator.op_pop(REG_EDX); 1035 1036 //mov ecx,dword ptr[esp] 1037 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_ESP,0,MOD_BASE); 1038 1039 //push edx 1040 compiler.codeGenerator.op_push(REG_EDX); 1041 1042 //push ecx 1043 compiler.codeGenerator.op_push(REG_ECX); 1044 1045 //call operator_proc ※ ==演算子 1046 compiler.codeGenerator.op_call(pUserProc); 1047 1048 //test eax,eax 1049 compiler.codeGenerator.op_test(REG_EAX,REG_EAX); 1050 1051 //jne ... 1052 selectSchedules.back().casePertialSchedules.push_back( 1053 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 1054 ); 1057 else if(type1.IsDouble()){ 1058 ChangeTypeToDouble(type2.GetBasicType()); 1059 1060 //fld qword ptr[esp] 1061 compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); 1062 1063 //add esp,CaseTypeSize 1064 compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); 1065 1066 //fld qword ptr[esp] 1067 compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); 1068 1069 //fcompp 1070 compiler.codeGenerator.op_fcompp(); 1071 1072 //fnstsw ax 1073 compiler.codeGenerator.op_fnstsw_ax(); 1074 1075 //test ah,40 1076 compiler.codeGenerator.op_test_ah( (char)0x40 ); 1077 1078 //jne ... 1079 selectSchedules.back().casePertialSchedules.push_back( 1080 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 1081 ); 1082 } 1083 else if(type1.IsSingle()){ 1084 ChangeTypeToSingle(type2.GetBasicType()); 1085 1086 //fld dword ptr[esp] 1087 compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); 1088 1089 //add esp,CaseTypeSize 1090 compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); 1091 1092 //fld dword ptr[esp] 1093 compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); 1094 1095 //fcompp 1096 compiler.codeGenerator.op_fcompp(); 1097 1098 //fnstsw ax 1099 compiler.codeGenerator.op_fnstsw_ax(); 1100 1101 //test ah,40 1102 compiler.codeGenerator.op_test_ah( (char)0x40 ); 1103 1104 //jne ... 1105 selectSchedules.back().casePertialSchedules.push_back( 1106 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 1107 ); 1108 } 1109 else{ 1110 //その他整数型 1111 1112 //pop ebx 1113 compiler.codeGenerator.op_pop(REG_EBX); 1114 1115 //mov eax,dword ptr[esp] 1116 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE ); 1117 1118 //cmp eax,ebx 1119 compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX ); 1120 1121 //je ... 1122 selectSchedules.back().casePertialSchedules.push_back( 1123 compiler.codeGenerator.op_je( 0, sizeof(long), true ) 1124 ); 1125 } 1126 1127 if(basbuf[i]!=',') break; 1055 1128 } 1056 else if(type1.IsDouble()){ 1057 ChangeTypeToDouble(type2.GetBasicType()); 1058 1059 //fld qword ptr[esp] 1060 compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); 1061 1062 //add esp,CaseTypeSize 1063 compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); 1064 1065 //fld qword ptr[esp] 1066 compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE); 1067 1068 //fcompp 1069 compiler.codeGenerator.op_fcompp(); 1070 1071 //fnstsw ax 1072 compiler.codeGenerator.op_fnstsw_ax(); 1073 1074 //test ah,40 1075 compiler.codeGenerator.op_test_ah( (char)0x40 ); 1076 1077 //jne ... 1078 selectSchedules.back().casePertialSchedules.push_back( 1079 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 1080 ); 1081 } 1082 else if(type1.IsSingle()){ 1083 ChangeTypeToSingle(type2.GetBasicType()); 1084 1085 //fld dword ptr[esp] 1086 compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); 1087 1088 //add esp,CaseTypeSize 1089 compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize); 1090 1091 //fld dword ptr[esp] 1092 compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE); 1093 1094 //fcompp 1095 compiler.codeGenerator.op_fcompp(); 1096 1097 //fnstsw ax 1098 compiler.codeGenerator.op_fnstsw_ax(); 1099 1100 //test ah,40 1101 compiler.codeGenerator.op_test_ah( (char)0x40 ); 1102 1103 //jne ... 1104 selectSchedules.back().casePertialSchedules.push_back( 1105 compiler.codeGenerator.op_jne( 0, sizeof(long), true ) 1106 ); 1107 } 1108 else{ 1109 //その他整数型 1110 1111 //pop ebx 1112 compiler.codeGenerator.op_pop(REG_EBX); 1113 1114 //mov eax,dword ptr[esp] 1115 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE ); 1116 1117 //cmp eax,ebx 1118 compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX ); 1119 1120 //je ... 1121 selectSchedules.back().casePertialSchedules.push_back( 1122 compiler.codeGenerator.op_je( 0, sizeof(long), true ) 1123 ); 1124 } 1125 1126 if(basbuf[i]!=',') break; 1127 } 1128 } 1129 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){ 1130 sw=1; 1131 1132 //jmp ... 1133 selectSchedules.back().casePertialSchedules.push_back( 1134 compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) 1135 ); 1129 } 1130 if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){ 1131 sw=1; 1132 1133 //jmp ... 1134 selectSchedules.back().casePertialSchedules.push_back( 1135 compiler.codeGenerator.op_jmp( 0, sizeof(long), true ) 1136 ); 1137 } 1136 1138 } 1137 1139 }
Note:
See TracChangeset
for help on using the changeset viewer.