Changeset 76 in dev for BasicCompiler32/Compile_Func.cpp
- Timestamp:
- Mar 21, 2007, 9:26:56 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler32/Compile_Func.cpp
r75 r76 44 44 } 45 45 46 void Opcode_Func_Fix(const char *Parameter){ 47 int i; 48 49 i=NumOpe(Parameter,0,0,0); 50 51 if(i==DEF_DOUBLE){ 46 void Opcode_Func_Fix(const char *lpszParms){ 47 Type resultType; 48 if( !NumOpe( lpszParms, Type(), resultType ) ){ 49 return; 50 } 51 52 if( resultType.IsDouble() ){ 52 53 //fld qword ptr[esp] 53 54 op_fld_ptr_esp(DEF_DOUBLE); … … 96 97 op_add_esp(4); 97 98 } 98 else if( i==DEF_SINGLE){99 else if( resultType.IsSingle() ){ 99 100 //fld dword ptr[esp] 100 101 op_fld_ptr_esp(DEF_SINGLE); … … 146 147 op_add_esp(4); 147 148 } 148 else if( Is64Type(i)){149 else if( resultType.Is64() ){ 149 150 //pop eax 150 151 op_pop(REG_EAX); … … 162 163 163 164 void Opcode_Func_CUDbl(const char *Parameter){ 164 int i; 165 166 i=NumOpe(Parameter,0,0,0); 167 ChangeTypeToLong(i); 165 Type resultType; 166 if( !NumOpe(Parameter,Type(),resultType) ){ 167 return; 168 } 169 ChangeTypeToLong(resultType.GetBasicType()); 168 170 169 171 //pop eax … … 186 188 } 187 189 void Opcode_Func_Len(const char *Parameter){ 188 int type,TypeSize;189 LONG_PTR lpIndex;190 190 BOOL bArrayHead; 191 192 type=GetVarType(Parameter,&lpIndex,0);193 191 194 192 const char *tempParm=Parameter; 195 193 char temporary[VN_SIZE]; 196 194 char temp2[32]; 197 if(type==-1){ 195 Type type; 196 if( !GetVarType(Parameter,type,0) ){ 198 197 sprintf(temporary,"_System_DummyStr2=%s",Parameter); 199 198 OpcodeCalc(temporary); … … 203 202 204 203 extern CClass *pobj_StringClass; 205 type=DEF_OBJECT; 206 lpIndex=(LONG_PTR)pobj_StringClass; 207 } 208 209 Type TypeInfo={type,lpIndex}; 210 if(IsStringObjectType(TypeInfo)){ 204 type.SetType( DEF_OBJECT, pobj_StringClass ); 205 } 206 207 if( type.IsStringObject() ){ 211 208 //Stringオブジェクトの場合 212 char temporary[VN_SIZE];213 209 sprintf(temporary,"%s.Length",tempParm); 214 210 215 NumOpe(temporary,0,0,NULL,NULL); 211 int reg=REG_RAX; 212 NumOpe(temporary,Type(),Type()); 216 213 217 214 //pop eax … … 223 220 int SubScripts[MAX_ARRAYDIM]; 224 221 RELATIVE_VAR RelativeVar; 225 if(!GetVarOffsetReadOnly(tempParm,& type,&RelativeVar,&lpIndex,SubScripts)) return;226 227 if(type &FLAG_PTR){228 type &=~FLAG_PTR;222 if(!GetVarOffsetReadOnly(tempParm,&RelativeVar,type,SubScripts)) return; 223 224 if(type.GetBasicType()&FLAG_PTR){ 225 type.SetBasicType( type.GetBasicType() & ( ~FLAG_PTR ) ); 229 226 230 227 bArrayHead=1; … … 232 229 else bArrayHead=0; 233 230 234 TypeSize=GetTypeSize(type,lpIndex);235 236 if(bArrayHead) TypeSize*=JumpSubScripts(SubScripts);231 int typeSize = type.GetSize(); 232 233 if(bArrayHead) typeSize*=JumpSubScripts(SubScripts); 237 234 238 235 //mov eax,TypeSize 239 236 OpBuffer[obp++]=(char)0xB8; 240 *((long *)(OpBuffer+obp))= TypeSize;237 *((long *)(OpBuffer+obp))=typeSize; 241 238 obp+=sizeof(long); 242 239 } 243 void Opcode_Func_AddressOf( const char *name){240 void Opcode_Func_AddressOf( const char *name ){ 244 241 extern int cp; 245 242 UserProc *pUserProc; … … 257 254 258 255 //オーバーロードを解決 259 extern ProcPointer **ppProcP trInfo;260 pUserProc=OverloadSolution(name,subs,ppProcP trInfo[ProcPtr_BaseIndex]->Params(), Type() );256 extern ProcPointer **ppProcPointer; 257 pUserProc=OverloadSolution(name,subs,ppProcPointer[ProcPtr_BaseIndex]->Params(), Type() ); 261 258 262 259 if(!pUserProc){ … … 289 286 else{ 290 287 RELATIVE_VAR RelativeVar; 291 inttype;292 if(!GetVarOffsetReadOnly(ObjectName,& type,&RelativeVar,(LONG_PTR *)&pobj_c)) return;288 Type type; 289 if(!GetVarOffsetReadOnly(ObjectName,&RelativeVar,type)) return; 293 290 SetVarPtrToEax(&RelativeVar); 294 291 … … 297 294 298 295 //参照タイプが整合しているかをチェック 299 if(type !=RefType) SetError(104,ObjectName,cp);300 301 if(type ==DEF_PTR_OBJECT){296 if(type.GetBasicType()!=RefType) SetError(104,ObjectName,cp); 297 298 if(type.IsObjectPtr()){ 302 299 //mov ecx,dword ptr[ecx] 303 300 op_mov_RM(sizeof(long),REG_ECX,REG_ECX,0,MOD_BASE); … … 360 357 op_mov_RV( REG_EAX, size ); 361 358 } 362 void Opcode_Func_VarPtr( const char *Parameter, Type &ReturnTypeInfo ){ 359 void Opcode_Func_VarPtr( const char *Parameter, Type &resultType, bool isCallOn ){ 360 if( isCallOn == false ){ 361 // 戻り値の型を取得するだけ 362 363 //変数のアドレスを取得 364 if(!GetVarType( Parameter, resultType, true )) return; 365 366 resultType.PtrLevelUp(); 367 368 return; 369 } 370 363 371 RELATIVE_VAR RelativeVar; 364 372 365 373 //変数のアドレスを取得 366 if(!GetVarOffsetReadOnly( Parameter, &Re turnTypeInfo.type, &RelativeVar, &ReturnTypeInfo.u.lpIndex)) return;367 368 int beforeType = ReturnTypeInfo.type;369 370 PTR_LEVEL_UP( ReturnTypeInfo.type);374 if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return; 375 376 int beforeType = resultType.GetBasicType(); 377 378 resultType.PtrLevelUp(); 371 379 372 380 SetVarPtrToEax(&RelativeVar); … … 380 388 } 381 389 void Opcode_Func_GetPtrData(const char *Parameter,const int type){ 382 int i2; 383 384 i2=NumOpe(Parameter,0,0,0); 385 ChangeTypeToLong(i2); 390 Type tempType; 391 if( !NumOpe(Parameter,Type(),tempType) ){ 392 return; 393 } 394 if(!tempType.IsWhole()){ 395 SetError(11,Parameter,cp); 396 return; 397 } 398 ChangeTypeToLong(tempType.GetBasicType()); 386 399 387 400 if(type==DEF_DOUBLE){ … … 438 451 } 439 452 440 void Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &ReturnTypeInfo){453 bool Opcode_CallFunc( const char *Parameter, const int FuncNum, Type &resultType, bool isCallOn ){ 441 454 switch(FuncNum){ 442 455 case FUNC_FIX: 443 Opcode_Func_Fix(Parameter);444 ReturnTypeInfo.type = DEF_LONG;456 if( isCallOn ) Opcode_Func_Fix(Parameter); 457 resultType.SetBasicType( DEF_LONG ); 445 458 break; 446 459 case FUNC_CUDBL: 447 Opcode_Func_CUDbl(Parameter);448 ReturnTypeInfo.type = DEF_DOUBLE;460 if( isCallOn ) Opcode_Func_CUDbl(Parameter); 461 resultType.SetBasicType( DEF_DOUBLE ); 449 462 break; 450 463 case FUNC_LEN: 451 Opcode_Func_Len(Parameter);452 ReturnTypeInfo.type = DEF_LONG;464 if( isCallOn ) Opcode_Func_Len(Parameter); 465 resultType.SetBasicType( DEF_LONG ); 453 466 break; 454 467 case FUNC_ADDRESSOF: 455 Opcode_Func_AddressOf(Parameter);456 ReturnTypeInfo.type = DEF_PTR_VOID;468 if( isCallOn ) Opcode_Func_AddressOf(Parameter); 469 resultType.SetBasicType( DEF_PTR_VOID ); 457 470 break; 458 471 case FUNC_SIZEOF: 459 Opcode_Func_SizeOf(Parameter);460 ReturnTypeInfo.type = DEF_LONG;472 if( isCallOn ) Opcode_Func_SizeOf(Parameter); 473 resultType.SetBasicType( DEF_LONG ); 461 474 break; 462 475 case FUNC_VARPTR: 463 Opcode_Func_VarPtr( Parameter, ReturnTypeInfo);476 Opcode_Func_VarPtr( Parameter, resultType, isCallOn ); 464 477 break; 465 478 466 479 case FUNC_GETDOUBLE: 467 Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE);468 ReturnTypeInfo.type = DEF_DOUBLE;480 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE); 481 resultType.SetBasicType( DEF_DOUBLE ); 469 482 break; 470 483 case FUNC_GETSINGLE: 471 Opcode_Func_GetPtrData(Parameter,DEF_SINGLE);472 ReturnTypeInfo.type = DEF_SINGLE;484 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_SINGLE); 485 resultType.SetBasicType( DEF_SINGLE ); 473 486 break; 474 487 case FUNC_GETQWORD: 475 Opcode_Func_GetPtrData(Parameter,DEF_QWORD);476 ReturnTypeInfo.type = DEF_QWORD;488 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_QWORD); 489 resultType.SetBasicType( DEF_QWORD ); 477 490 break; 478 491 case FUNC_GETDWORD: 479 Opcode_Func_GetPtrData(Parameter,DEF_DWORD);480 ReturnTypeInfo.type = DEF_DWORD;492 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DWORD); 493 resultType.SetBasicType( DEF_DWORD ); 481 494 break; 482 495 case FUNC_GETWORD: 483 Opcode_Func_GetPtrData(Parameter,DEF_WORD);484 ReturnTypeInfo.type = DEF_WORD;496 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_WORD); 497 resultType.SetBasicType( DEF_WORD ); 485 498 break; 486 499 case FUNC_GETBYTE: 487 Opcode_Func_GetPtrData(Parameter,DEF_BYTE); 488 ReturnTypeInfo.type = DEF_BYTE; 489 break; 490 } 491 } 500 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_BYTE); 501 resultType.SetBasicType( DEF_BYTE ); 502 break; 503 default: 504 return false; 505 } 506 return true; 507 }
Note:
See TracChangeset
for help on using the changeset viewer.