source: dev/trunk/ab5.0/abdev/BasicCompiler32/Compile_Func.cpp@ 449

Last change on this file since 449 was 449, checked in by dai_9181, 16 years ago

・デリゲートの共変戻り値、反変引数に対応した。
・core.libで定義されたデリゲートがアプリケーションプロジェクトで利用できないバグを修正。

File size: 22.5 KB
RevLine 
[206]1#include "stdafx.h"
2
[183]3#include <jenga/include/smoothie/Smoothie.h>
4
[193]5#include <Compiler.h>
6
[3]7#include "../BasicCompiler_Common/common.h"
8#include "Opcode.h"
9
[431]10#ifdef _AMD64_
11#include "../BasicCompiler64/FunctionValue.h"
12#else
13#include "../BasicCompiler32/FunctionValue.h"
14#endif
15
[3]16int GetFunctionFromName(char *FuncName){
[325]17 if( lstrcmpi( FuncName, "CUDbl" ) == 0 ) return FUNC_CUDBL;
18 if( lstrcmpi( FuncName, "Fix" ) == 0 ) return FUNC_FIX;
19 if( lstrcmpi( FuncName, "Len" ) == 0 ) return FUNC_LEN;
20 if( lstrcmpi( FuncName, "AddressOf" ) == 0 ) return FUNC_ADDRESSOF;
21 if( lstrcmpi( FuncName, "SizeOf" ) == 0 ) return FUNC_SIZEOF;
22 if( lstrcmpi( FuncName, "VarPtr" ) == 0 ) return FUNC_VARPTR;
23 if( lstrcmpi( FuncName, "ObjPtr" ) == 0 ) return FUNC_OBJPTR;
24 if( lstrcmpi( FuncName, "__delegate_dynamicmethod_call" ) == 0 ) return FUNC_DELEGATE_DYNAMICMETHOD_CALL;
25 if( lstrcmpi( FuncName, "__delegate_staticmethod_call" ) == 0 ) return FUNC_DELEGATE_STATICMETHOD_CALL;
[357]26 if( lstrcmpi( FuncName, "_System_GetNowScopeCatchAddresses" ) == 0 )return FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS;
[359]27 if( lstrcmpi( FuncName, "_System_GetNowScopeFinallyAddresses" ) == 0 )return FUNC_SYSTEM_GET_NOW_SCOPE_FINALLY_ADDRESS;
[357]28 if( lstrcmpi( FuncName, "_System_GetBp" ) == 0 ) return FUNC_SYSTEM_GET_BP;
[358]29 if( lstrcmpi( FuncName, "_System_GetSp" ) == 0 ) return FUNC_SYSTEM_GET_SP;
[431]30 if( lstrcmp( FuncName, "_System_GetComVtbl" ) == 0 ) return FUNC_SYSTEM_GET_COM_VTBL;
31 if( lstrcmp( FuncName, "_System_GetVtblList" ) == 0 ) return FUNC_SYSTEM_GET_VTBL_LIST;
32 if( lstrcmp( FuncName, "_System_GetDefaultConstructor" ) == 0 ) return FUNC_SYSTEM_GET_DEFAULT_CONSTRUCTOR;
33 if( lstrcmp( FuncName, "_System_GetDestructor" ) == 0 ) return FUNC_SYSTEM_GET_DESTRUCTOR;
[325]34 if( lstrcmpi( FuncName, "GetDouble" ) == 0 ) return FUNC_GETDOUBLE;
35 if( lstrcmpi( FuncName, "GetSingle" ) == 0 ) return FUNC_GETSINGLE;
36 if( lstrcmpi( FuncName, "GetQWord" ) == 0 ) return FUNC_GETQWORD;
37 if( lstrcmpi( FuncName, "GetDWord" ) == 0 ) return FUNC_GETDWORD;
38 if( lstrcmpi( FuncName, "GetWord" ) == 0 ) return FUNC_GETWORD;
39 if( lstrcmpi( FuncName, "GetByte" ) == 0 ) return FUNC_GETBYTE;
[3]40 return 0;
41}
42
[76]43void Opcode_Func_Fix(const char *lpszParms){
44 Type resultType;
45 if( !NumOpe( lpszParms, Type(), resultType ) ){
46 return;
47 }
[3]48
[76]49 if( resultType.IsDouble() ){
[3]50 //fld qword ptr[esp]
[225]51 compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
[3]52
53 //fnstcw word ptr[esp]
[250]54 compiler.codeGenerator.PutOld(
55 (char)0xD9,
56 (char)0x3C,
57 (char)0x24
58 );
[3]59
60 //mov ax,word ptr[esp]
[250]61 compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_ESP, 0, MOD_BASE );
[3]62
63 //or ah,0Ch
[250]64 compiler.codeGenerator.PutOld(
65 (char)0x80,
66 (char)0xCC,
67 (char)0x0C
68 );
[3]69
70 //mov word ptr[esp-2],ax
[250]71 compiler.codeGenerator.op_mov_MR( sizeof(short), REG_EAX, REG_ESP, -2, MOD_BASE_DISP8 );
[3]72
73 //fldcw word ptr[esp-2]
[250]74 compiler.codeGenerator.PutOld(
75 (char)0xD9,
76 (char)0x6C,
77 (char)0x24,
78 (char)0xFE
79 );
[3]80
81 //fistp dword ptr[esp+4]
[250]82 compiler.codeGenerator.PutOld(
83 (char)0xDB,
84 (char)0x5C,
85 (char)0x24,
86 (char)0x04
87 );
[3]88
89 //fldcw word ptr[esp]
[250]90 compiler.codeGenerator.PutOld(
91 (char)0xD9,
92 (char)0x2C,
93 (char)0x24
94 );
[3]95
96 //add esp,4
[225]97 compiler.codeGenerator.op_add_esp(4);
[3]98 }
[76]99 else if( resultType.IsSingle() ){
[3]100 //fld dword ptr[esp]
[225]101 compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
[3]102
103 //sub esp,4
[225]104 compiler.codeGenerator.op_sub_esp(4);
[3]105
106 //fnstcw word ptr[esp]
[250]107 compiler.codeGenerator.PutOld(
108 (char)0xD9,
109 (char)0x3C,
110 (char)0x24
111 );
[3]112
113 //mov ax,word ptr[esp]
[250]114 compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_ESP, 0, MOD_BASE );
[3]115
116 //or ah,0Ch
[250]117 compiler.codeGenerator.PutOld(
118 (char)0x80,
119 (char)0xCC,
120 (char)0x0C
121 );
[3]122
123 //mov word ptr[esp-2],ax
[250]124 compiler.codeGenerator.op_mov_MR( sizeof(short), REG_EAX, REG_ESP, -2, MOD_BASE_DISP8 );
[3]125
126 //fldcw word ptr[esp-2]
[250]127 compiler.codeGenerator.PutOld(
128 (char)0xD9,
129 (char)0x6C,
130 (char)0x24,
131 (char)0xFE
132 );
[3]133
134 //fistp dword ptr[esp+4]
[250]135 compiler.codeGenerator.PutOld(
136 (char)0xDB,
137 (char)0x5C,
138 (char)0x24,
139 (char)0x04
140 );
[3]141
142 //fldcw word ptr[esp]
[250]143 compiler.codeGenerator.PutOld(
144 (char)0xD9,
145 (char)0x2C,
146 (char)0x24
147 );
[3]148
149 //add esp,4
[225]150 compiler.codeGenerator.op_add_esp(4);
[3]151 }
[76]152 else if( resultType.Is64() ){
[3]153 //pop eax
[225]154 compiler.codeGenerator.op_pop(REG_EAX);
[3]155
156 //add esp,4
[225]157 compiler.codeGenerator.op_add_esp(4);
[3]158
159 //push eax
[225]160 compiler.codeGenerator.op_push(REG_EAX);
[3]161 }
162
163 //pop eax
[225]164 compiler.codeGenerator.op_pop(REG_EAX);
[3]165}
166
[46]167void Opcode_Func_CUDbl(const char *Parameter){
[76]168 Type resultType;
169 if( !NumOpe(Parameter,Type(),resultType) ){
170 return;
171 }
172 ChangeTypeToLong(resultType.GetBasicType());
[3]173
174 //pop eax
[225]175 compiler.codeGenerator.op_pop(REG_EAX);
[3]176
177 //push 0
[235]178 compiler.codeGenerator.op_push_V( 0 );
[3]179
180 //push eax
[225]181 compiler.codeGenerator.op_push(REG_EAX);
[3]182
183 //fild qword ptr[esp]
[235]184 compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
[3]185
186 //add esp,8
[225]187 compiler.codeGenerator.op_add_esp(8);
[3]188}
[46]189void Opcode_Func_Len(const char *Parameter){
[3]190 BOOL bArrayHead;
191
[46]192 const char *tempParm=Parameter;
[3]193 char temporary[VN_SIZE];
194 char temp2[32];
[76]195 Type type;
196 if( !GetVarType(Parameter,type,0) ){
[3]197 sprintf(temporary,"_System_DummyStr2=%s",Parameter);
198 OpcodeCalc(temporary);
199
200 lstrcpy(temp2,"_System_DummyStr2");
201 tempParm=temp2;
202
[265]203 type.SetType( DEF_OBJECT, compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr() );
[3]204 }
205
[97]206 if( type.IsStringClass() ){
[3]207 //Stringオブジェクトの場合
208 sprintf(temporary,"%s.Length",tempParm);
209
[76]210 int reg=REG_RAX;
211 NumOpe(temporary,Type(),Type());
[3]212
213 //pop eax
[225]214 compiler.codeGenerator.op_pop(REG_EAX);
[3]215
216 return;
217 }
218
[206]219 Subscripts subscripts;
[3]220 RELATIVE_VAR RelativeVar;
[206]221 if(!GetVarOffsetReadOnly(tempParm,&RelativeVar,type,&subscripts)) return;
[3]222
[76]223 if(type.GetBasicType()&FLAG_PTR){
224 type.SetBasicType( type.GetBasicType() & ( ~FLAG_PTR ) );
[3]225
226 bArrayHead=1;
227 }
228 else bArrayHead=0;
229
[76]230 int typeSize = type.GetSize();
[3]231
[206]232 if(bArrayHead) typeSize*=JumpSubScripts(subscripts);
[3]233
[235]234 //mov eax,typeSize
235 compiler.codeGenerator.op_mov_RV( REG_EAX, typeSize );
[3]236}
237
[332]238void _Opcode_Func_AddressOf( const char *methodInstanceName, const UserProc &userProc )
239{
240 if( userProc.IsVirtual() ){
[3]241 ///////////////////////////////
242 // 仮想関数の場合
243 // thisポインタをrcxにコピー
244 ///////////////////////////////
245
[114]246 const CClass *pobj_c;
[3]247
248 char ObjectName[VN_SIZE];
[290]249 ReferenceKind referenceKind;
[332]250 SplitObjectName( methodInstanceName, ObjectName, referenceKind );
[3]251
252 if(ObjectName[0]){
253 if(lstrcmpi(ObjectName,"Super")==0) goto InClassMember;
254 else{
255 RELATIVE_VAR RelativeVar;
[76]256 Type type;
257 if(!GetVarOffsetReadOnly(ObjectName,&RelativeVar,type)) return;
[3]258 SetVarPtrToEax(&RelativeVar);
259
260 //mov ecx,eax
[225]261 compiler.codeGenerator.op_mov_RR(REG_ECX,REG_EAX);
[3]262
263 //参照タイプが整合しているかをチェック
[290]264 if( !( type.IsObject() && referenceKind == RefDot
265 || type.IsObjectPtr() && referenceKind == RefPointer ) )
266 {
267 SetError(104,ObjectName,cp);
268 }
[3]269
[76]270 if(type.IsObjectPtr()){
[3]271 //mov ecx,dword ptr[ecx]
[225]272 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_ECX,0,MOD_BASE);
[3]273 }
274 }
275 }
276 else{
277InClassMember:
278 //自身のオブジェクトのThisポインタをrcxにコピー
279 SetThisPtrToReg(REG_RCX);
280
[206]281 pobj_c=compiler.pCompilingClass;
[3]282 }
283
284
[349]285 int vtblIndex;
286 if( pobj_c->IsInterface() )
287 {
288 // インターフェイスメソッド呼び出し
[3]289
[349]290 int offset_vtbl = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__vtbl" );
[348]291
[3]292
[349]293 // vtblのポインタを取得
294 //mov edx,dword ptr[ecx+offset_vtbl]
295 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_ECX, offset_vtbl, MOD_BASE_DISP8 );
296
297 int offset_this = compiler.GetObjectModule().meta.GetClasses().GetInterfaceInfoClassPtr()->GetMemberOffset( "__this" );
298
299
300
301 // インターフェイスの場合は更に__thisを取得する
302 //mov rcx,qword ptr[rcx+offset_this]
303 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_ECX, offset_this, MOD_BASE_DISP8 );
304
305 int vtblMasterListIndex;
306 pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex );
307 if( vtblMasterListIndex != 0 )
308 {
309 SetError();
310 }
311 }
[370]312 else if( pobj_c->IsComInterface() )
313 {
314 // COMインターフェイス メソッド呼び出し
315
316 //仮想関数(オブジェクトメソッド)呼び出し
317 // pObj -> vtbl1 -> func1
318 // -> func2
319 // -> func3
320
321 int vtblMasterListIndex;
322 pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex );
323
324 // vtblのポインタを取得
325 //mov edx,dword ptr[ecx]
326 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_ECX, 0, MOD_BASE );
327 }
[349]328 else
329 {
330 //仮想関数(オブジェクトメソッド)呼び出し
331 // pObj -> vtbl_master_list -> vtbl1 -> func1
332 // -> func2
333 // -> func3
334 // -> vtbl2 -> func1
335 // -> func2
336 // -> func3
337
338 int vtblMasterListIndex;
339 pobj_c->GetVtblMasterListIndexAndVtblIndex( &userProc, vtblMasterListIndex, vtblIndex );
340
341 // vtblマスターリストのポインタを取得
[370]342 //mov edx,dword ptr[ecx+sizeof(com_vtbl)]
343 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_ECX, PTR_SIZE, MOD_BASE_DISP8 );
[349]344
345 // vtblのポインタを取得
346 //mov edx,dword ptr[edx+vtblMasterListIndex]
[350]347 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_EDX, vtblMasterListIndex*PTR_SIZE, MOD_BASE_DISP32 );
[349]348 }
349
[3]350 //mov eax,dword ptr[edx+func_index]
[342]351 if( vtblIndex * PTR_SIZE <= 0x7F )
352 {
353 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EAX,REG_EDX,vtblIndex*PTR_SIZE,MOD_BASE_DISP8);
[3]354 }
355 else{
[342]356 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EAX,REG_EDX,vtblIndex*PTR_SIZE,MOD_BASE_DISP32);
[3]357 }
358 }
359 else{
360 //一般の関数
361
362 //mov eax,ProcAddr
[332]363 compiler.codeGenerator.op_addressof( REG_EAX, &userProc );
[3]364 }
365
[332]366 userProc.Using();
[3]367}
[335]368void Opcode_CreateDelegate( const CClass &dgClass, const char *methodInstanceName, const UserProc &userProc )
[332]369{
370 /////////////////////////////////////////////////////////////////
371 // 関数ポインタをpush
372 /////////////////////////////////////////////////////////////////
373
374 //push AddressOf(userProc)
375 _Opcode_Func_AddressOf( methodInstanceName, userProc );
376 compiler.codeGenerator.op_push( REG_EAX );
377
378
[336]379 if( userProc.GetMethod().IsDynamic() )
380 {
381 /////////////////////////////////////////////////////////////////
382 // オブジェクト ポインタをpush
383 /////////////////////////////////////////////////////////////////
[332]384
[336]385 // オブジェクト名を取得
386 char objectName[VN_SIZE];
387 char memberName[VN_SIZE];
388 char *thisPtrName = "This";
389 Type type;
390 if( SplitMemberName( methodInstanceName, objectName, memberName ) )
[332]391 {
[336]392 if( GetVarType( objectName, type, false ) )
393 {
394 thisPtrName = objectName;
395 }
[332]396 }
397
[336]398 // オブジェクト ポインタを取得
399 RELATIVE_VAR relativeVar;
400 GetVarOffsetReadOnly( thisPtrName, &relativeVar, type );
401 if( !type.IsObject() )
402 {
403 extern int cp;
404 SetError(1,NULL,cp);
405 return;
406 }
[332]407
[336]408 SetVarPtrToEax( &relativeVar );
[332]409
[336]410 //mov eax,dword ptr[eax]
411 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
[332]412
[336]413 //push eax
414 compiler.codeGenerator.op_push( REG_EAX );
415 }
[332]416
417
418 /////////////////////////////////////////////////////////////////
[336]419 // call _CreateDynamicDelegate/_CreateStaticDelegate
[332]420 /////////////////////////////////////////////////////////////////
421
[334]422 std::vector<const UserProc *> subs;
[336]423 if( userProc.GetMethod().IsDynamic() )
424 {
425 dgClass.GetStaticMethods().Enum( "_CreateDynamicDelegate", subs );
426 }
427 else
428 {
429 dgClass.GetStaticMethods().Enum( "_CreateStaticDelegate", subs );
430 }
[334]431
[336]432 // call _CreateDynamicDelegate
[334]433 compiler.codeGenerator.op_call( subs[0] );
[332]434}
[339]435void Opcode_Func_AddressOf( const char *name, const Type &baseType, bool isCallOn, Type &resultType )
436{
[332]437 extern int cp;
438
439 const Parameters *pBaseParams = NULL;
[449]440 const Type *pBaseReturnType = NULL;
[332]441 if( baseType.IsProcPtr() )
442 {
443 // 左辺で関数ポインタを要求されているとき
[449]444 const ProcPointer *pTempProcPointer = compiler.GetObjectModule().meta.GetProcPointers()[baseType.GetIndex()];
445 pBaseParams = &pTempProcPointer->Params();
446 pBaseReturnType = &pTempProcPointer->ReturnType();
[332]447 }
[334]448 else if( baseType.IsDelegate() )
[332]449 {
450 // 左辺でデリゲートを要求されているとき
[449]451 const Delegate *pTempDelegate = &baseType.GetClass().GetDelegate();
452 pBaseParams = &pTempDelegate->Params();
453 pBaseReturnType = &pTempDelegate->ReturnType();
[332]454 }
455
[449]456 const UserProc *pUserProc;
457 if( pBaseParams && pBaseReturnType )
[332]458 {
459 //左辺の型にのっとり、オーバーロードを解決
460
461 std::vector<const UserProc *> subs;
462 GetOverloadSubHash( name, subs );
463 if( subs.size() == 0 ){
464 SetError(27,name,cp);
465 return;
466 }
467
468 //オーバーロードを解決
[424]469 pUserProc=OverloadSolution( name, subs, *pBaseParams, Type(), Type() );
[332]470
[449]471 if( isCallOn )
[337]472 {
473 // コード生成を伴う場合はエラーチェックを行う
[449]474
475 if( baseType.IsDelegate() )
[337]476 {
[449]477 // デリゲート
478 // 共変戻り値、反変引数をサポート
479 if( !(
480 pBaseParams->Equals( pUserProc->Params(), true )
481 && ( pBaseReturnType->Equals( pUserProc->ReturnType() ) || pBaseReturnType->IsCovariant( pUserProc->ReturnType() ) )
482 ) )
[337]483 {
484 SetError(67, name, cp );
485 }
[449]486 }
487 else
488 {
489 // 関数ポインタ
490 if( !(
491 pBaseParams->Equals( pUserProc->Params() )
492 && pBaseReturnType->Equals( pUserProc->ReturnType() )
493 ) )
[337]494 {
495 SetError(66, name, cp );
496 }
497 }
498 }
499
[332]500 if(!pUserProc){
501 SetError(27,name,cp);
502 return;
503 }
504 }
505 else{
506 pUserProc=GetSubHash(name);
507 if(!pUserProc){
508 SetError(27,name,cp);
509 return;
510 }
511 }
512
[334]513 if( baseType.IsDelegate() )
[332]514 {
515 if( isCallOn )
516 {
517 // デリゲートのとき
[335]518 Opcode_CreateDelegate( baseType.GetClass(), name, *pUserProc );
[332]519 }
520 resultType = baseType;
521 }
522 else
523 {
524 if( isCallOn )
525 {
526 // 関数ポインタのとき
527 _Opcode_Func_AddressOf( name, *pUserProc );
528 }
529 resultType.SetBasicType( DEF_PTR_VOID );
530 }
531}
[79]532void Opcode_Func_SizeOf( const string &typeName ){
533 Type tempType;
[299]534 if( !compiler.StringToType( typeName, tempType ) ){
[79]535 SetError(3,typeName,cp);
536 return;
[3]537 }
538
[79]539 int typeSize = ( tempType.IsObject() ) ?
540 tempType.GetClass().GetSize() : tempType.GetSize();
541
[3]542 //mov eax,size
[225]543 compiler.codeGenerator.op_mov_RV( REG_EAX, typeSize );
[3]544}
[76]545void Opcode_Func_VarPtr( const char *Parameter, Type &resultType, bool isCallOn ){
546 if( isCallOn == false ){
547 // 戻り値の型を取得するだけ
548
549 //変数のアドレスを取得
550 if(!GetVarType( Parameter, resultType, true )) return;
551
552 resultType.PtrLevelUp();
553
554 return;
555 }
556
[3]557 RELATIVE_VAR RelativeVar;
558
559 //変数のアドレスを取得
[76]560 if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return;
[3]561
[76]562 int beforeType = resultType.GetBasicType();
[64]563
[76]564 resultType.PtrLevelUp();
[46]565
[3]566 SetVarPtrToEax(&RelativeVar);
567}
[109]568void Opcode_Func_ObjPtr( const char *Parameter, Type &resultType, bool isCallOn ){
569 if( isCallOn == false ){
570 // 戻り値の型を取得するだけ
571
572 //変数のアドレスを取得
573 if(!GetVarType( Parameter, resultType, true )) return;
574
575 resultType.PtrLevelUp();
576
577 return;
578 }
579
580 RELATIVE_VAR RelativeVar;
581
582 //変数のアドレスを取得
583 if(!GetVarOffsetReadOnly( Parameter, &RelativeVar, resultType )) return;
584
585 int beforeType = resultType.GetBasicType();
586
587 resultType.PtrLevelUp();
588
589 SetVarPtrToEax(&RelativeVar);
590
[111]591 if( lstrcmpi( Parameter, "This" )==0 ){
592 // Thisの場合は特別にオブジェクトポインタが返ってくるので、何もせずに抜ける
593 }
594 else if( beforeType == DEF_OBJECT ){
[109]595 //参照をオブジェクトポインタに変更
596
597 //mov eax,dword ptr[eax]
[225]598 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
[109]599 }
600 else{
601 SetError(134,NULL,cp );
602 }
603}
[325]604
605void Opcode_Func_delegate_call( const char *paramsStr, Type &resultType, bool isDynamicCall, bool isCallOn )
606{
607 if( isCallOn )
608 {
609 int i = 0;
610 char methodPtrParamStr[VN_SIZE];
611 i = GetOneParameter( paramsStr, i, methodPtrParamStr );
612
[336]613 char objPtrValueStr[VN_SIZE]="";
[325]614 if( isDynamicCall )
615 {
616 i = GetOneParameter( paramsStr, i, objPtrValueStr );
617 }
618
619 Opcode_CallDelegate( compiler.pCompilingClass->GetDelegate(), methodPtrParamStr, objPtrValueStr, paramsStr + i );
620 }
621
622 resultType = UserProc::CompilingUserProc().ReturnType();
623}
[357]624void Opcode_Func_System_Get_Bp()
625{
626 //mov eax,ebp
627 compiler.codeGenerator.op_mov_RR(REG_EAX,REG_EBP);
628}
[358]629void Opcode_Func_System_Get_Sp()
630{
631 //mov eax,esp
632 compiler.codeGenerator.op_mov_RR(REG_EAX,REG_ESP);
633}
[325]634
[431]635void Opcode_Func_System_GetComVtbl( const char *parameter )
[426]636{
[431]637 Type classType;
638 compiler.StringToType( parameter, classType );
639
640 // mov eax,com_vtbl
641 compiler.codeGenerator.op_mov_RV_com_vtbl( REG_EAX, &classType.GetClass() );
642}
643void Opcode_Func_System_GetVtblList( const char *parameter )
644{
645 Type classType;
646 compiler.StringToType( parameter, classType );
647
648 // mov eax,com_vtbl
649 compiler.codeGenerator.op_mov_RV_vtbl( REG_EAX, &classType.GetClass() );
650}
651void Opcode_Func_System_GetDefaultConstructor( const char *parameter )
652{
653 Type classType;
654 compiler.StringToType( parameter, classType );
655
656 if( classType.GetClass().GetConstructorMethod() )
[426]657 {
[431]658 //mov eax,ProcAddr
659 compiler.codeGenerator.op_addressof( REG_EAX, &classType.GetClass().GetConstructorMethod()->GetUserProc() );
[426]660 }
[431]661 else
[426]662 {
[431]663 // デフォルトコンストラクタを持たない
[426]664
[431]665 //xor eax,eax
666 compiler.codeGenerator.op_zero_reg( REG_EAX );
[426]667 }
668}
[431]669void Opcode_Func_System_GetDestructor( const char *parameter )
670{
671 Type classType;
672 compiler.StringToType( parameter, classType );
[426]673
[431]674 //mov eax,ProcAddr
675 compiler.codeGenerator.op_addressof( REG_EAX, &classType.GetClass().GetDestructorMethod()->GetUserProc() );
676}
677
[46]678void Opcode_Func_GetPtrData(const char *Parameter,const int type){
[76]679 Type tempType;
680 if( !NumOpe(Parameter,Type(),tempType) ){
681 return;
682 }
683 if(!tempType.IsWhole()){
684 SetError(11,Parameter,cp);
685 return;
686 }
687 ChangeTypeToLong(tempType.GetBasicType());
[3]688
689 if(type==DEF_DOUBLE){
690 //pop eax
[225]691 compiler.codeGenerator.op_pop(REG_EAX);
[3]692
693 //fld qword ptr[eax]
[235]694 compiler.codeGenerator.PutOld(
695 (char)0xDD,
696 (char)0x00
697 );
[3]698 }
699 else if(type==DEF_SINGLE||type==DEF_DWORD){
700 //pop eax
[225]701 compiler.codeGenerator.op_pop(REG_EAX);
[3]702
703 //mov eax,dword ptr[eax]
[235]704 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
[3]705 }
706 else if(type==DEF_QWORD){
707 //pop ecx
[225]708 compiler.codeGenerator.op_pop(REG_ECX);
[3]709
710 //mov eax,dword ptr[ecx]
[225]711 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EAX,REG_ECX,0,MOD_BASE);
[3]712
713 //mov edx,dword ptr[ecx+sizeof(long)]
[225]714 compiler.codeGenerator.op_mov_RM(sizeof(long),REG_EDX,REG_ECX,sizeof(long),MOD_BASE_DISP8);
[3]715 }
716 else if(type==DEF_WORD){
717 //pop ebx
[225]718 compiler.codeGenerator.op_pop(REG_EBX);
[3]719
720 //xor eax,eax
[227]721 compiler.codeGenerator.op_xor_RR(REG_EAX);
[3]722
723 //mov ax,word ptr[ebx]
[235]724 compiler.codeGenerator.op_mov_RM( sizeof(short), REG_EAX, REG_EBX, 0, MOD_BASE );
[3]725 }
726 else if(type==DEF_BYTE){
727 //pop ebx
[225]728 compiler.codeGenerator.op_pop(REG_EBX);
[3]729
730 //xor eax,eax
[227]731 compiler.codeGenerator.op_xor_RR(REG_EAX);
[3]732
733 //mov al,byte ptr[ebx]
[235]734 compiler.codeGenerator.op_mov_RM( sizeof(char), REG_EAX, REG_EBX, 0, MOD_BASE );
[3]735 }
736}
737
[331]738bool Opcode_CallFunc( const char *Parameter, const int FuncNum, const Type &baseType, Type &resultType, bool isCallOn )
739{
[3]740 switch(FuncNum){
741 case FUNC_FIX:
[76]742 if( isCallOn ) Opcode_Func_Fix(Parameter);
743 resultType.SetBasicType( DEF_LONG );
[46]744 break;
[3]745 case FUNC_CUDBL:
[76]746 if( isCallOn ) Opcode_Func_CUDbl(Parameter);
747 resultType.SetBasicType( DEF_DOUBLE );
[46]748 break;
[3]749 case FUNC_LEN:
[76]750 if( isCallOn ) Opcode_Func_Len(Parameter);
751 resultType.SetBasicType( DEF_LONG );
[46]752 break;
[3]753 case FUNC_ADDRESSOF:
[332]754 Opcode_Func_AddressOf( Parameter, baseType, isCallOn, resultType );
[46]755 break;
[3]756 case FUNC_SIZEOF:
[76]757 if( isCallOn ) Opcode_Func_SizeOf(Parameter);
758 resultType.SetBasicType( DEF_LONG );
[46]759 break;
[3]760 case FUNC_VARPTR:
[76]761 Opcode_Func_VarPtr( Parameter, resultType, isCallOn );
[46]762 break;
[109]763 case FUNC_OBJPTR:
764 Opcode_Func_ObjPtr( Parameter, resultType, isCallOn );
765 break;
[325]766 case FUNC_DELEGATE_DYNAMICMETHOD_CALL:
767 Opcode_Func_delegate_call( Parameter, resultType, true, isCallOn );
768 break;
769 case FUNC_DELEGATE_STATICMETHOD_CALL:
770 Opcode_Func_delegate_call( Parameter, resultType, false, isCallOn );
771 break;
[357]772 case FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS:
773 if( isCallOn ) Exception::Opcode_Func_System_GetNowScopeCatchAddress();
[358]774 resultType.SetBasicType( DEF_PTR_VOID );
[357]775 break;
[359]776 case FUNC_SYSTEM_GET_NOW_SCOPE_FINALLY_ADDRESS:
777 if( isCallOn ) Exception::Opcode_Func_System_GetNowScopeFinallyAddress();
778 resultType.SetBasicType( DEF_PTR_VOID );
779 break;
[357]780 case FUNC_SYSTEM_GET_BP:
781 if( isCallOn ) Opcode_Func_System_Get_Bp();
782 resultType.SetBasicType( DEF_LONG );
783 break;
[358]784 case FUNC_SYSTEM_GET_SP:
785 if( isCallOn ) Opcode_Func_System_Get_Sp();
786 resultType.SetBasicType( DEF_LONG );
787 break;
[431]788 case FUNC_SYSTEM_GET_COM_VTBL:
789 if( isCallOn ) Opcode_Func_System_GetComVtbl( Parameter );
790 resultType.SetBasicType( DEF_PTR_VOID );
[426]791 break;
[431]792 case FUNC_SYSTEM_GET_VTBL_LIST:
793 if( isCallOn ) Opcode_Func_System_GetVtblList( Parameter );
794 resultType.SetBasicType( DEF_PTR_VOID );
795 break;
796 case FUNC_SYSTEM_GET_DEFAULT_CONSTRUCTOR:
797 if( isCallOn ) Opcode_Func_System_GetDefaultConstructor( Parameter );
798 resultType.SetBasicType( DEF_PTR_VOID );
799 break;
800 case FUNC_SYSTEM_GET_DESTRUCTOR:
801 if( isCallOn ) Opcode_Func_System_GetDestructor( Parameter );
802 resultType.SetBasicType( DEF_PTR_VOID );
803 break;
[3]804
805 case FUNC_GETDOUBLE:
[76]806 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DOUBLE);
807 resultType.SetBasicType( DEF_DOUBLE );
[46]808 break;
[3]809 case FUNC_GETSINGLE:
[76]810 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_SINGLE);
811 resultType.SetBasicType( DEF_SINGLE );
[46]812 break;
[3]813 case FUNC_GETQWORD:
[76]814 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_QWORD);
815 resultType.SetBasicType( DEF_QWORD );
[46]816 break;
[3]817 case FUNC_GETDWORD:
[76]818 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_DWORD);
819 resultType.SetBasicType( DEF_DWORD );
[46]820 break;
[3]821 case FUNC_GETWORD:
[76]822 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_WORD);
823 resultType.SetBasicType( DEF_WORD );
[46]824 break;
[3]825 case FUNC_GETBYTE:
[76]826 if( isCallOn ) Opcode_Func_GetPtrData(Parameter,DEF_BYTE);
827 resultType.SetBasicType( DEF_BYTE );
[46]828 break;
[76]829 default:
830 return false;
[3]831 }
[76]832 return true;
[3]833}
Note: See TracBrowser for help on using the repository browser.