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