Changeset 64 in dev for BasicCompiler32/Compile_Object.cpp
- Timestamp:
- Mar 8, 2007, 2:49:34 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler32/Compile_Object.cpp
r51 r64 2 2 #include "opcode.h" 3 3 4 void _call_constructor(CClass *pobj_c, char *CreateParameter,int ObjectSize,BOOL bSomeObjects){4 void _call_constructor(CClass *pobj_c, const char *CreateParameter,int ObjectSize,BOOL bSomeObjects){ 5 5 //////////////////////////// 6 6 // コンストラクタの呼び出し … … 74 74 } 75 75 } 76 int Operator_New(const char *Parameter,LONG_PTR *plpIndex){ 77 char TypeName[VN_SIZE],CreateParameter[VN_SIZE],ObjectSize[VN_SIZE]; 76 void Operator_New( CClass &classObj, const char *objectSizeStr, const char *parameter, const TYPEINFO &baseTypeInfo ){ 77 int typeSize = classObj.GetSize(); 78 79 if(classObj.IsAbstract()){ 80 //抽象クラスだったとき 81 SetError(125,classObj.name,cp); 82 } 83 84 if(objectSizeStr[0]){ 85 int type = NumOpe(objectSizeStr,0,0,0); 86 ChangeTypeToLong(type); 87 88 //pop eax 89 op_pop(REG_EAX); 90 91 //※添え字上限値であることを考慮 92 //add eax,1 93 OpBuffer[obp++]=(char)0x83; 94 OpBuffer[obp++]=(char)0xC0; 95 OpBuffer[obp++]=(char)0x01; 96 97 //オブジェクトの個数をebxに一時保持 98 //※ebxは関数が呼ばれても不変 99 //mov ebx,eax 100 OpBuffer[obp++]=(char)0x8B; 101 OpBuffer[obp++]=(char)0xD8; 102 103 //imul eax,size 104 OpBuffer[obp++]=(char)0x69; 105 OpBuffer[obp++]=(char)0xC0; 106 *((long *)(OpBuffer+obp))=typeSize; 107 obp+=sizeof(long); 108 109 //add eax,sizeof(DWORD)*2 110 OpBuffer[obp++]=(char)0x05; 111 *((long *)(OpBuffer+obp))=sizeof(DWORD)*3; 112 obp+=sizeof(long); 113 114 //push eax 115 op_push(REG_EAX); 116 } 117 else{ 118 //オブジェクトの個数をebxに一時保持 119 //※ebxは関数が呼ばれても不変 120 //mov ebx,1 121 OpBuffer[obp++]=(char)0xBB; 122 *((long *)(OpBuffer+obp))=1; 123 obp+=sizeof(long); 124 125 //push size 126 OpBuffer[obp++]=(char)0x68; 127 *((long *)(OpBuffer+obp))=typeSize+sizeof(DWORD)*3; 128 obp+=sizeof(long); 129 } 130 131 if( baseTypeInfo.type == DEF_OBJECT ){ 132 //DeleteはGCで処理 133 134 //call _System_GC_malloc_ForObject 135 extern SUBINFO *pSub_System_GC_malloc_ForObject; 136 op_call(pSub_System_GC_malloc_ForObject); 137 } 138 else{ 139 //明示的なDeleteが必要 140 141 //call _System_GC_malloc_ForObjectPtr 142 extern SUBINFO *pSub_System_GC_malloc_ForObjectPtr; 143 op_call(pSub_System_GC_malloc_ForObjectPtr); 144 } 145 146 147 /* 148 確保されたヒープ領域のポインタ(callocの戻り値eax)をpPtrとすると、 149 pPtr-=sizeof(DWORD)*3 150 pPtr[0]=オブジェクトの個数 151 pPtr[1]=オブジェクトのサイズ 152 pPtr[2]=デストラクタの関数ポインタ 153 */ 154 155 156 //mov dword ptr[eax],ebx(オブジェクトの個数) 157 OpBuffer[obp++]=(char)0x89; 158 OpBuffer[obp++]=(char)0x18; 159 160 //add eax,sizeof(DWORD) 161 OpBuffer[obp++]=(char)0x05; 162 *((long *)(OpBuffer+obp))=sizeof(DWORD); 163 obp+=sizeof(long); 164 165 166 //mov ecx,TypeSize 167 OpBuffer[obp++]=(char)0xB9; 168 *((long *)(OpBuffer+obp))=typeSize; 169 obp+=sizeof(long); 170 171 //mov dword ptr[eax],ecx 172 OpBuffer[obp++]=(char)0x89; 173 OpBuffer[obp++]=(char)0x08; 174 175 //add eax,sizeof(DWORD) 176 OpBuffer[obp++]=(char)0x05; 177 *((long *)(OpBuffer+obp))=sizeof(DWORD); 178 obp+=sizeof(long); 179 180 181 CMethod *method = classObj.GetDestructorMethod(); 182 if( method == NULL ) return; 183 184 //mov ecx,DestructorProcAddr 185 OpBuffer[obp++]=(char)0xB9; 186 pobj_SubAddrSchedule->add(method->psi,0); 187 method->psi->bUse=1; 188 obp+=sizeof(long); 189 190 //mov dword ptr[eax],ecx 191 OpBuffer[obp++]=(char)0x89; 192 OpBuffer[obp++]=(char)0x08; 193 194 //add eax,sizeof(DWORD) 195 OpBuffer[obp++]=(char)0x05; 196 *((long *)(OpBuffer+obp))=sizeof(DWORD); 197 obp+=sizeof(long); 198 199 200 // ※ここでプッシュされた値はNew演算子の戻り値となる 201 //push eax 202 op_push(REG_EAX); 203 204 205 ///////////////////////////////////////////////////////////////////// 206 207 //////////////////////////// 208 // コンストラクタの呼び出し 209 //////////////////////////// 210 211 BOOL bSomeObjects; 212 if(objectSizeStr[0]) bSomeObjects=1; 213 else bSomeObjects=0; 214 _call_constructor(&classObj,parameter,typeSize,bSomeObjects); 215 } 216 int Operator_New(const char *Parameter,LONG_PTR *plpIndex,const TYPEINFO &baseTypeInfo ){ 217 char TypeName[VN_SIZE],CreateParameter[VN_SIZE],objectSizeStr[VN_SIZE]; 78 218 int i,i2; 79 219 … … 81 221 82 222 if(Parameter[0]=='['){ 83 i=GetStringInBracket( ObjectSize,Parameter);84 85 SlideString( ObjectSize+1,-1);86 ObjectSize[i-2]=0;87 } 88 else ObjectSize[0]=0;223 i=GetStringInBracket(objectSizeStr,Parameter); 224 225 SlideString(objectSizeStr+1,-1); 226 objectSizeStr[i-2]=0; 227 } 228 else objectSizeStr[0]=0; 89 229 90 230 for(i2=0;;i++,i2++){ … … 129 269 pobj_c=(CClass *)*plpIndex; 130 270 131 if(pobj_c->IsAbstract()){ 132 //抽象クラスだったとき 133 SetError(125,pobj_c->name,cp); 134 } 135 136 if(ObjectSize[0]){ 137 i2=NumOpe(ObjectSize,0,0,0); 138 ChangeTypeToLong(i2); 139 140 //pop eax 141 op_pop(REG_EAX); 142 143 //※添え字上限値であることを考慮 144 //add eax,1 145 OpBuffer[obp++]=(char)0x83; 146 OpBuffer[obp++]=(char)0xC0; 147 OpBuffer[obp++]=(char)0x01; 148 149 //オブジェクトの個数をebxに一時保持 150 //※ebxは関数が呼ばれても不変 151 //mov ebx,eax 152 OpBuffer[obp++]=(char)0x8B; 153 OpBuffer[obp++]=(char)0xD8; 154 155 //imul eax,size 156 OpBuffer[obp++]=(char)0x69; 157 OpBuffer[obp++]=(char)0xC0; 158 *((long *)(OpBuffer+obp))=TypeSize; 159 obp+=sizeof(long); 160 161 //add eax,sizeof(DWORD)*2 162 OpBuffer[obp++]=(char)0x05; 163 *((long *)(OpBuffer+obp))=sizeof(DWORD)*3; 164 obp+=sizeof(long); 165 166 //push eax 167 op_push(REG_EAX); 168 } 169 else{ 170 //オブジェクトの個数をebxに一時保持 171 //※ebxは関数が呼ばれても不変 172 //mov ebx,1 173 OpBuffer[obp++]=(char)0xBB; 174 *((long *)(OpBuffer+obp))=1; 175 obp+=sizeof(long); 176 177 //push size 178 OpBuffer[obp++]=(char)0x68; 179 *((long *)(OpBuffer+obp))=TypeSize+sizeof(DWORD)*3; 180 obp+=sizeof(long); 181 } 182 183 //call calloc 184 extern SUBINFO *pSub_calloc; 185 op_call(pSub_calloc); 186 187 188 /* 189 確保されたヒープ領域のポインタ(callocの戻り値eax)をpPtrとすると、 190 pPtr-=sizeof(DWORD)*3 191 pPtr[0]=オブジェクトの個数 192 pPtr[1]=オブジェクトのサイズ 193 pPtr[2]=デストラクタの関数ポインタ 194 */ 195 196 197 //mov dword ptr[eax],ebx(オブジェクトの個数) 198 OpBuffer[obp++]=(char)0x89; 199 OpBuffer[obp++]=(char)0x18; 200 201 //add eax,sizeof(DWORD) 202 OpBuffer[obp++]=(char)0x05; 203 *((long *)(OpBuffer+obp))=sizeof(DWORD); 204 obp+=sizeof(long); 205 206 207 //mov ecx,TypeSize 208 OpBuffer[obp++]=(char)0xB9; 209 *((long *)(OpBuffer+obp))=TypeSize; 210 obp+=sizeof(long); 211 212 //mov dword ptr[eax],ecx 213 OpBuffer[obp++]=(char)0x89; 214 OpBuffer[obp++]=(char)0x08; 215 216 //add eax,sizeof(DWORD) 217 OpBuffer[obp++]=(char)0x05; 218 *((long *)(OpBuffer+obp))=sizeof(DWORD); 219 obp+=sizeof(long); 220 221 222 CMethod *method = pobj_c->GetDestructorMethod(); 223 if( method == NULL ) return 0; 224 225 //mov ecx,DestructorProcAddr 226 OpBuffer[obp++]=(char)0xB9; 227 pobj_SubAddrSchedule->add(method->psi,0); 228 method->psi->bUse=1; 229 obp+=sizeof(long); 230 231 //mov dword ptr[eax],ecx 232 OpBuffer[obp++]=(char)0x89; 233 OpBuffer[obp++]=(char)0x08; 234 235 //add eax,sizeof(DWORD) 236 OpBuffer[obp++]=(char)0x05; 237 *((long *)(OpBuffer+obp))=sizeof(DWORD); 238 obp+=sizeof(long); 239 240 241 // ※ここでプッシュされた値はNew演算子の戻り値となる 242 //push eax 243 op_push(REG_EAX); 244 245 246 ///////////////////////////////////////////////////////////////////// 247 248 //////////////////////////// 249 // コンストラクタの呼び出し 250 //////////////////////////// 251 252 BOOL bSomeObjects; 253 if(ObjectSize[0]) bSomeObjects=1; 254 else bSomeObjects=0; 255 _call_constructor(pobj_c,CreateParameter,TypeSize,bSomeObjects); 256 271 Operator_New( *pobj_c, objectSizeStr, CreateParameter, baseTypeInfo ); 272 273 if( baseTypeInfo.type == DEF_OBJECT ){ 274 return DEF_OBJECT; 275 } 257 276 return DEF_PTR_OBJECT; 258 277 } 259 278 260 void OpcodeDelete(c har *Parameter){279 void OpcodeDelete(const char *Parameter, bool isSweeping){ 261 280 int type; 262 281 … … 355 374 ////////////////////////////////////////// 356 375 357 //call free 358 extern SUBINFO *pSub_free; 359 op_call(pSub_free); 376 if( isSweeping ){ 377 //call _System_GC_free_for_SweepingDelete 378 extern SUBINFO *pSub_System_GC_free_for_SweepingDelete; 379 op_call(pSub_System_GC_free_for_SweepingDelete); 380 } 381 else{ 382 //call free 383 extern SUBINFO *pSub_free; 384 op_call(pSub_free); 385 } 360 386 }
Note:
See TracChangeset
for help on using the changeset viewer.