[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[183] | 3 | #include <jenga/include/smoothie/Smoothie.h>
|
---|
| 4 | #include <jenga/include/smoothie/LexicalAnalysis.h>
|
---|
| 5 |
|
---|
| 6 | #include <Compiler.h>
|
---|
| 7 |
|
---|
[3] | 8 | #include "../BasicCompiler_Common/common.h"
|
---|
| 9 | #include "Opcode.h"
|
---|
| 10 |
|
---|
| 11 | void PushReturnValue(int type){
|
---|
| 12 | //関数の戻り値をスタックへプッシュする
|
---|
| 13 | //※この処理内では、esi、ediは使用不可
|
---|
| 14 |
|
---|
[64] | 15 | if(type==DEF_OBJECT || type==DEF_STRUCT){
|
---|
[3] | 16 | //push eax
|
---|
[225] | 17 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 18 | }
|
---|
| 19 | else if(type==DEF_DOUBLE){
|
---|
| 20 | //sub esp,8
|
---|
[225] | 21 | compiler.codeGenerator.op_sub_esp(8);
|
---|
[3] | 22 |
|
---|
| 23 | //fstp qword ptr[esp]
|
---|
[225] | 24 | compiler.codeGenerator.op_fstp_basereg( DEF_DOUBLE, REG_ESP );
|
---|
[3] | 25 | }
|
---|
| 26 | else if(type==DEF_SINGLE){
|
---|
| 27 | //sub esp,4
|
---|
[225] | 28 | compiler.codeGenerator.op_sub_esp(4);
|
---|
[3] | 29 |
|
---|
| 30 | //fstp dword ptr[esp]
|
---|
[225] | 31 | compiler.codeGenerator.op_fstp_basereg( DEF_SINGLE, REG_ESP );
|
---|
[3] | 32 | }
|
---|
| 33 | else if(type==DEF_INT64||type==DEF_QWORD){
|
---|
| 34 | //push edx
|
---|
[225] | 35 | compiler.codeGenerator.op_push(REG_EDX);
|
---|
[3] | 36 |
|
---|
| 37 | //push eax
|
---|
[225] | 38 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 39 | }
|
---|
| 40 | else if(type==DEF_LONG){
|
---|
| 41 | //push eax
|
---|
[225] | 42 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 43 | }
|
---|
[183] | 44 | else if(type==DEF_INTEGER || (Smoothie::IsUnicode()&&type==DEF_CHAR)){
|
---|
[3] | 45 | //movsx ebx,ax
|
---|
[225] | 46 | compiler.codeGenerator.op_movsx_R32R16( REG_EBX, REG_EAX );
|
---|
[3] | 47 |
|
---|
| 48 | //push ebx
|
---|
[225] | 49 | compiler.codeGenerator.op_push(REG_EBX);
|
---|
[3] | 50 | }
|
---|
[183] | 51 | else if(type==DEF_SBYTE || (Smoothie::IsUnicode()==false&&type==DEF_CHAR)){
|
---|
[3] | 52 | //movsx ebx,al
|
---|
[225] | 53 | compiler.codeGenerator.op_movsx_R32R8( REG_EBX, REG_EAX );
|
---|
[3] | 54 |
|
---|
| 55 | //push ebx
|
---|
[225] | 56 | compiler.codeGenerator.op_push(REG_EBX);
|
---|
[3] | 57 | }
|
---|
[36] | 58 | else if(type==DEF_DWORD||type==DEF_WORD||type==DEF_BYTE||type==DEF_BOOLEAN||
|
---|
[3] | 59 | IsPtrType(type)){
|
---|
| 60 | //push eax
|
---|
[225] | 61 | compiler.codeGenerator.op_push(REG_EAX);
|
---|
[3] | 62 | }
|
---|
[64] | 63 | else{
|
---|
| 64 | SetError();
|
---|
[3] | 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[76] | 68 | void NewStringObject( const char *str ){
|
---|
[3] | 69 | ///////////////////////////////////////////////////////
|
---|
| 70 | // lpszTextを元にStringオブジェクトを生成し、
|
---|
[64] | 71 | // オブジェクトポインタをregに格納する
|
---|
[3] | 72 | ///////////////////////////////////////////////////////
|
---|
| 73 |
|
---|
[76] | 74 | char *parameter = (char *)malloc( lstrlen( str ) + 32 );
|
---|
| 75 | sprintf( parameter, "\"%s\"%c%c*Char", str, 1, ESC_AS );
|
---|
[64] | 76 | SetStringQuotes( parameter );
|
---|
| 77 |
|
---|
[265] | 78 | Operator_New( *compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr(), "", parameter, Type( DEF_OBJECT, *compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr() ) );
|
---|
[3] | 79 |
|
---|
[64] | 80 | free( parameter );
|
---|
[3] | 81 | }
|
---|
| 82 |
|
---|
[97] | 83 | void ExtendRegToBigType( int reg, int bigBasicType, int baseBasicType ){
|
---|
| 84 | if( reg != REG_EAX ){
|
---|
| 85 | SetError();
|
---|
| 86 | }
|
---|
| 87 | switch( Type::GetBasicSize( bigBasicType ) ){
|
---|
| 88 | case sizeof(_int64):
|
---|
| 89 | ExtendTypeTo64(baseBasicType);
|
---|
| 90 | break;
|
---|
| 91 | case sizeof(long):
|
---|
| 92 | ExtendTypeTo32(baseBasicType,reg);
|
---|
| 93 | break;
|
---|
| 94 | case sizeof(short):
|
---|
| 95 | ExtendTypeTo16(baseBasicType,reg);
|
---|
| 96 | break;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
[3] | 99 |
|
---|
[97] | 100 |
|
---|
| 101 |
|
---|
| 102 | bool VarToReg( RELATIVE_VAR &relativeVar, const Type &baseType, Type &resultType ){
|
---|
| 103 | const int useReg = REG_EAX;
|
---|
| 104 |
|
---|
| 105 | //大きな型への暗黙の変換
|
---|
| 106 | int bigType = AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType());
|
---|
| 107 |
|
---|
| 108 | if(resultType.GetBasicType()&FLAG_PTR){
|
---|
| 109 | //配列ポインタ
|
---|
| 110 | resultType.SetBasicType( GetPtrType(resultType.GetBasicType()^FLAG_PTR) );
|
---|
| 111 |
|
---|
| 112 | SetVarPtrToReg(useReg, &relativeVar);
|
---|
| 113 | }
|
---|
| 114 | else if( resultType.IsStruct() ){
|
---|
| 115 | //構造体ポインタをeaxへ格納(構造体は値型)
|
---|
| 116 | SetVarPtrToReg(useReg, &relativeVar);
|
---|
| 117 | }
|
---|
| 118 | else if( resultType.IsReal() ){
|
---|
| 119 | // 実数
|
---|
| 120 | SetReg_RealVariable( resultType.GetBasicType(), &relativeVar );
|
---|
| 121 | }
|
---|
| 122 | else if( resultType.IsWhole() || resultType.IsObject()){
|
---|
| 123 | //整数型
|
---|
| 124 | SetReg_WholeVariable(resultType.GetBasicType(),&relativeVar,useReg);
|
---|
| 125 | }
|
---|
| 126 | else if( resultType.IsStruct() ){
|
---|
| 127 | //構造体ポインタをUseRegへ格納(構造体は値型)
|
---|
| 128 | SetVarPtrToReg(useReg,&relativeVar);
|
---|
| 129 | }
|
---|
| 130 | else{
|
---|
| 131 | return false;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | if( resultType.GetBasicType() != bigType ){
|
---|
| 135 | // 大きな型へ変換された場合
|
---|
| 136 | // ※レジスタの値をキャストする
|
---|
| 137 | ExtendRegToBigType( useReg, bigType, resultType.GetBasicType() );
|
---|
| 138 |
|
---|
| 139 | resultType.SetBasicType( bigType );
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | return true;
|
---|
| 143 | }
|
---|
| 144 | bool TermMemberOpe( const CClass &objClass, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member ){
|
---|
| 145 | const int useReg = REG_EAX;
|
---|
| 146 |
|
---|
| 147 | if( GetMemberType( objClass, member, resultType, 0, false ) ){
|
---|
| 148 | // メンバが見つかったとき
|
---|
| 149 |
|
---|
| 150 | //オブジェクトポインタをecxにコピー
|
---|
[225] | 151 | compiler.codeGenerator.op_mov_RR( REG_ECX, useReg );
|
---|
[97] | 152 |
|
---|
| 153 | RELATIVE_VAR relativeVar;
|
---|
| 154 | relativeVar.dwKind=VAR_DIRECTMEM;
|
---|
| 155 |
|
---|
| 156 | if( !_member_offset(
|
---|
| 157 | true, //エラー表示あり
|
---|
| 158 | false, //読み込み専用
|
---|
| 159 | objClass,
|
---|
| 160 | member,&relativeVar,resultType,0)){
|
---|
| 161 | return false;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | if( !VarToReg( relativeVar, baseType, resultType ) ){
|
---|
| 165 | SetError(11,termFull,cp);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | return true;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | ///////////////////////////////////////////////////////////////////
|
---|
| 173 | // 動的メソッドを検索
|
---|
| 174 | ///////////////////////////////////////////////////////////////////
|
---|
[206] | 175 | vector<const UserProc *> userProcs;
|
---|
[97] | 176 |
|
---|
| 177 | char methodName[VN_SIZE], lpPtrOffset[VN_SIZE], parameter[VN_SIZE], dummy[1];
|
---|
[206] | 178 | ReferenceKind refType;
|
---|
[97] | 179 | lstrcpy( methodName, member );
|
---|
| 180 | GetVarFormatString(methodName,parameter,lpPtrOffset,dummy,refType);
|
---|
| 181 |
|
---|
[135] | 182 | objClass.GetMethods().Enum( methodName, userProcs );
|
---|
[97] | 183 | if(userProcs.size()){
|
---|
| 184 | //オーバーロードを解決
|
---|
[206] | 185 | const UserProc *pUserProc = OverloadSolutionWithStrParam(termFull,userProcs,parameter,termLeft);
|
---|
[97] | 186 |
|
---|
| 187 | if( pUserProc ){
|
---|
| 188 |
|
---|
| 189 | resultType = pUserProc->ReturnType();
|
---|
| 190 |
|
---|
| 191 | {
|
---|
| 192 | //オブジェクトポインタをスタックに入れておく
|
---|
| 193 | //push reg
|
---|
[225] | 194 | compiler.codeGenerator.op_push( useReg );
|
---|
[97] | 195 |
|
---|
| 196 | if( !Opcode_CallProc(parameter,pUserProc,PROCFLAG_NEW,termLeft,0 ) ){
|
---|
| 197 |
|
---|
| 198 | return false;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[225] | 201 | compiler.codeGenerator.op_pop();
|
---|
[97] | 202 |
|
---|
| 203 | /////////////////////
|
---|
| 204 | // 戻り値の処理
|
---|
| 205 | /////////////////////
|
---|
| 206 |
|
---|
| 207 | //大きな型への暗黙の変換
|
---|
| 208 | int bigType = AutoBigCast(baseType.GetBasicType(), resultType.GetBasicType() );
|
---|
| 209 |
|
---|
| 210 | if( resultType.GetBasicType() != bigType ){
|
---|
| 211 | // 大きな型へ変換された場合
|
---|
| 212 | // ※レジスタの値をキャストする
|
---|
| 213 | ExtendRegToBigType( REG_EAX, bigType, resultType.GetBasicType() );
|
---|
| 214 |
|
---|
| 215 | resultType.SetBasicType( bigType );
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | //SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | return true;
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | return false;
|
---|
| 226 | }
|
---|
[128] | 227 | bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool isWantObject, bool *pIsClassName, bool isProcedureCallOnly ){
|
---|
[97] | 228 | char parameter[VN_SIZE];
|
---|
| 229 |
|
---|
| 230 | // Withを解決
|
---|
| 231 | char termFull[VN_SIZE];
|
---|
| 232 | if(term[0]=='.'){
|
---|
| 233 | GetWithName(termFull);
|
---|
| 234 | lstrcat(termFull,term);
|
---|
| 235 | }
|
---|
| 236 | else lstrcpy(termFull,term);
|
---|
| 237 |
|
---|
| 238 | char termLeft[VN_SIZE];
|
---|
| 239 | lstrcpy(termLeft,termFull);
|
---|
| 240 |
|
---|
| 241 | // パース
|
---|
| 242 | char member[VN_SIZE];
|
---|
[206] | 243 | ReferenceKind refType;
|
---|
| 244 | if( SplitMemberName( termFull, termLeft, member, refType ) ){
|
---|
[97] | 245 | ///////////////////////////////////////////////////////////////////
|
---|
| 246 | // オブジェクトとメンバに分解できるとき
|
---|
| 247 | // termLeft.member
|
---|
| 248 | ///////////////////////////////////////////////////////////////////
|
---|
| 249 |
|
---|
| 250 | isLiteral = false;
|
---|
| 251 |
|
---|
| 252 | // オブジェクト側の型を取得
|
---|
| 253 | bool isClassName = false;
|
---|
| 254 | Type leftType;
|
---|
[128] | 255 | if( GetTermType( termLeft, leftType, isLiteral, &isClassName ) ){
|
---|
[265] | 256 | if( isClassName == false && compiler.GetObjectModule().meta.GetBlittableTypes().IsExist( leftType ) ){
|
---|
[128] | 257 | // 左側のオブジェクト部分がBlittable型のとき
|
---|
| 258 |
|
---|
| 259 | char temporary[VN_SIZE];
|
---|
| 260 | lstrcpy( temporary, termLeft );
|
---|
| 261 | sprintf( termLeft, "%s(%s)",
|
---|
[265] | 262 | compiler.GetObjectModule().meta.GetBlittableTypes().Find( leftType ).GetCreateStaticMethodFullName().c_str(),
|
---|
[128] | 263 | temporary );
|
---|
| 264 | }
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, true, &isClassName ) ){
|
---|
[103] | 268 | goto globalArea;
|
---|
[97] | 269 | }
|
---|
| 270 |
|
---|
| 271 | if( isClassName ){
|
---|
| 272 | // 静的メンバ/メソッドの場合
|
---|
| 273 | goto globalArea;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | if( !leftType.HasMember() ){
|
---|
| 277 | // メンバを持たない型の場合
|
---|
| 278 | return false;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | return TermMemberOpe( leftType.GetClass(), baseType, resultType, termFull, termLeft, member );
|
---|
| 282 | }
|
---|
[106] | 283 | globalArea:
|
---|
[97] | 284 |
|
---|
| 285 |
|
---|
| 286 | //////////////////////////////////////////////
|
---|
| 287 | // クラス名かどうかをチェック(静的メンバ用)
|
---|
| 288 | //////////////////////////////////////////////
|
---|
| 289 |
|
---|
| 290 | if( pIsClassName ){
|
---|
[265] | 291 | if( compiler.GetObjectModule().meta.GetClasses().Find( termFull ) ){
|
---|
[97] | 292 | *pIsClassName = true;
|
---|
| 293 | return true;
|
---|
| 294 | }
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 |
|
---|
| 298 | /////////////////////////////////////////////////////////////////
|
---|
| 299 | // グローバル属性エリア
|
---|
| 300 | /////////////////////////////////////////////////////////////////
|
---|
| 301 |
|
---|
| 302 | const int useReg = REG_EAX;
|
---|
| 303 |
|
---|
| 304 |
|
---|
[122] | 305 | if(lstrcmpi(termFull,"This")==0 && isProcedureCallOnly == false ){
|
---|
[97] | 306 | //Thisオブジェクト
|
---|
[206] | 307 | resultType.SetType( DEF_OBJECT, compiler.pCompilingClass );
|
---|
[97] | 308 |
|
---|
| 309 | SetThisPtrToReg( useReg );
|
---|
| 310 |
|
---|
| 311 | isLiteral = false;
|
---|
| 312 |
|
---|
| 313 | return true;
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 |
|
---|
| 317 | //////////////////////////////////////
|
---|
| 318 | // 関数(DLL、ユーザー定義、組み込み)
|
---|
| 319 | //////////////////////////////////////
|
---|
| 320 | char procName[VN_SIZE];
|
---|
| 321 | char temporary[8192];
|
---|
| 322 |
|
---|
| 323 | int i2=GetCallProcName(termFull,procName);
|
---|
| 324 | if(termFull[i2]=='('){
|
---|
| 325 | int i4=GetStringInPare_RemovePare(parameter,termFull+i2+1);
|
---|
| 326 |
|
---|
| 327 | void *pInfo;
|
---|
| 328 | int idProc=GetProc(procName,(void **)&pInfo);
|
---|
| 329 |
|
---|
| 330 | if(idProc){
|
---|
| 331 | //閉じカッコ")"に続く文字がNULLでないとき
|
---|
| 332 | if(termFull[i2+1+i4+1]!='\0'){
|
---|
| 333 | SetError(42,NULL,cp);
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 |
|
---|
| 337 | {
|
---|
| 338 | ////////////////
|
---|
| 339 | // 呼び出し
|
---|
| 340 | ////////////////
|
---|
| 341 |
|
---|
| 342 | CallProc(idProc,pInfo,procName,parameter,resultType);
|
---|
| 343 |
|
---|
| 344 |
|
---|
| 345 | /////////////////////
|
---|
| 346 | // 戻り値の処理
|
---|
| 347 | /////////////////////
|
---|
| 348 |
|
---|
| 349 | //大きな型への暗黙の変換
|
---|
| 350 | int bigType = AutoBigCast(baseType.GetBasicType(), resultType.GetBasicType() );
|
---|
| 351 |
|
---|
| 352 | /*
|
---|
| 353 | ※後でNumOpe内でプッシュする
|
---|
| 354 | //スタックへプッシュ
|
---|
| 355 | PushReturnValue( resultType.GetBasicType() );
|
---|
| 356 | */
|
---|
| 357 |
|
---|
| 358 | if( resultType.GetBasicType() != bigType ){
|
---|
| 359 | // 大きな型へ変換された場合
|
---|
| 360 | // ※レジスタの値をキャストする
|
---|
| 361 | ExtendRegToBigType( useReg, bigType, resultType.GetBasicType() );
|
---|
| 362 |
|
---|
| 363 | resultType.SetBasicType( bigType );
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | //SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg);
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 |
|
---|
| 370 | if(resultType.IsStruct()){
|
---|
| 371 | //構造体が戻ったときはヒープ領域にインスタンスが格納されている
|
---|
| 372 | //※後にfreeする必要あり
|
---|
| 373 | // TODO: 解放はGCに任せる
|
---|
| 374 | *pbUseHeap = 1;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | isLiteral = false;
|
---|
| 378 |
|
---|
| 379 | return true;
|
---|
| 380 | }
|
---|
[208] | 381 |
|
---|
[265] | 382 | ConstMacro *pConstMacro = compiler.GetObjectModule().meta.GetGlobalConstMacros().Find( procName );
|
---|
[206] | 383 | if( pConstMacro )
|
---|
| 384 | {
|
---|
| 385 | if( pConstMacro->GetCalcBuffer( parameter, temporary ) )
|
---|
| 386 | {
|
---|
| 387 | /////////////////////////
|
---|
| 388 | // マクロ関数
|
---|
| 389 | /////////////////////////
|
---|
[97] | 390 |
|
---|
[206] | 391 | //閉じカッコ")"に続く文字がNULLでないときはエラーにする
|
---|
| 392 | if(termFull[i2+1+i4+1]!='\0') SetError(42,NULL,cp);
|
---|
[97] | 393 |
|
---|
[206] | 394 | //マクロ関数の場合
|
---|
| 395 | NumOpe(useReg, temporary,Type(),resultType);
|
---|
[97] | 396 |
|
---|
[206] | 397 | if(!IS_LITERAL(resultType.GetIndex())){
|
---|
| 398 | //リテラル値ではなかったとき
|
---|
| 399 | isLiteral = false;
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | return true;
|
---|
[97] | 403 | }
|
---|
| 404 | }
|
---|
| 405 | }
|
---|
[122] | 406 | else if( isProcedureCallOnly ){
|
---|
| 407 | // 関数呼び出し以外は受け付けない
|
---|
| 408 | return false;
|
---|
| 409 | }
|
---|
[97] | 410 |
|
---|
| 411 |
|
---|
| 412 | ////////////////////////////////
|
---|
| 413 | // インデクサ(getアクセサ)
|
---|
| 414 | ////////////////////////////////
|
---|
| 415 |
|
---|
| 416 | char VarName[VN_SIZE],ArrayElements[VN_SIZE];
|
---|
| 417 | GetArrayElement(termFull,VarName,ArrayElements);
|
---|
| 418 | if(ArrayElements[0]){
|
---|
| 419 | GetVarType(VarName,resultType,false);
|
---|
| 420 | if( resultType.IsObject() ){
|
---|
| 421 | CallIndexerGetterProc(/*UseReg,*/&resultType.GetClass(),VarName,ArrayElements,resultType);
|
---|
| 422 |
|
---|
| 423 | isLiteral = false;
|
---|
| 424 |
|
---|
| 425 | return true;
|
---|
| 426 | }
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 |
|
---|
| 430 | ////////////////////////////////
|
---|
| 431 | // 変数
|
---|
| 432 | ////////////////////////////////
|
---|
| 433 |
|
---|
| 434 | RELATIVE_VAR relativeVar;
|
---|
| 435 | if(GetVarOffset(
|
---|
| 436 | false, //エラー表示なし
|
---|
| 437 | false, //読み込み専用
|
---|
| 438 | termFull,
|
---|
| 439 | &relativeVar,resultType)){
|
---|
| 440 | //////////
|
---|
| 441 | // 変数
|
---|
| 442 | //////////
|
---|
| 443 |
|
---|
| 444 | if( !VarToReg( relativeVar, baseType, resultType ) ){
|
---|
| 445 | SetError(11,termFull,cp);
|
---|
| 446 | }
|
---|
| 447 |
|
---|
| 448 | isLiteral = false;
|
---|
| 449 |
|
---|
| 450 | return true;
|
---|
| 451 | }
|
---|
| 452 |
|
---|
| 453 |
|
---|
| 454 | /////////////////////////////////
|
---|
| 455 | // プロパティ用のメソッド
|
---|
| 456 | /////////////////////////////////
|
---|
| 457 |
|
---|
| 458 | //配列要素を排除
|
---|
| 459 | GetArrayElement(termFull,VarName,ArrayElements);
|
---|
| 460 |
|
---|
| 461 | if(GetSubHash(VarName,0)){
|
---|
| 462 |
|
---|
| 463 | {
|
---|
| 464 | CallPropertyMethod(termFull,NULL,resultType);
|
---|
| 465 |
|
---|
| 466 | //大きな型への暗黙の変換
|
---|
| 467 | int bigType = AutoBigCast(baseType.GetBasicType(), resultType.GetBasicType() );
|
---|
| 468 |
|
---|
| 469 | if( resultType.GetBasicType() != bigType ){
|
---|
| 470 | // 大きな型へ変換された場合
|
---|
| 471 | // ※レジスタの値をキャストする
|
---|
| 472 | ExtendRegToBigType( REG_EAX, bigType, resultType.GetBasicType() );
|
---|
| 473 |
|
---|
| 474 | resultType.SetBasicType( bigType );
|
---|
| 475 | }
|
---|
| 476 |
|
---|
| 477 | //SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg);
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 |
|
---|
| 481 | if(resultType.IsStruct()){
|
---|
| 482 | //構造体が戻ったときはヒープ領域にインスタンスが格納されている
|
---|
| 483 | //※後にfreeする必要あり
|
---|
| 484 | // TODO: 解放はGCに任せる
|
---|
| 485 | *pbUseHeap = 1;
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 | isLiteral = false;
|
---|
| 489 |
|
---|
| 490 | return true;
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 |
|
---|
| 494 | return false;
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 |
|
---|
| 498 | bool NumOpe( int reg,
|
---|
| 499 | const char *expression,
|
---|
| 500 | const Type &baseType,
|
---|
| 501 | Type &resultType,
|
---|
| 502 | BOOL *pbUseHeap ){
|
---|
| 503 |
|
---|
| 504 | if( !NumOpe( expression, baseType, resultType, pbUseHeap ) ){
|
---|
| 505 | return false;
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 | if( reg != REG_EAX ){
|
---|
| 509 | // TODO: 未実装
|
---|
| 510 | SetError();
|
---|
| 511 | }
|
---|
| 512 |
|
---|
| 513 | if( resultType.IsReal() ){
|
---|
| 514 | //fld ptr[esp]
|
---|
[225] | 515 | compiler.codeGenerator.op_fld_ptr_esp( resultType.GetBasicType() );
|
---|
[97] | 516 |
|
---|
| 517 | //add esp,size
|
---|
[225] | 518 | compiler.codeGenerator.op_add_esp( resultType.GetBasicSize() );
|
---|
[97] | 519 | }
|
---|
| 520 | else{
|
---|
| 521 | //pop eax
|
---|
[225] | 522 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
[97] | 523 |
|
---|
| 524 | if( resultType.Is64() ){
|
---|
| 525 | //pop edx
|
---|
[225] | 526 | compiler.codeGenerator.op_pop(REG_EDX);
|
---|
[97] | 527 | }
|
---|
| 528 | }
|
---|
| 529 | return true;
|
---|
| 530 | }
|
---|
[76] | 531 | bool NumOpe( const char *expression,
|
---|
| 532 | const Type &baseType,
|
---|
| 533 | Type &resultType,
|
---|
[254] | 534 | BOOL *pbUseHeap )
|
---|
| 535 | {
|
---|
[97] | 536 | int i,i2,i3;
|
---|
| 537 | char temporary[1024],temp2[1024];
|
---|
[3] | 538 |
|
---|
[76] | 539 | if(expression[0]=='\0'){
|
---|
[3] | 540 | SetError(1,NULL,cp);
|
---|
[76] | 541 | return false;
|
---|
[3] | 542 | }
|
---|
| 543 |
|
---|
[93] | 544 | if( !baseType.IsNull() && expression[0] == '[' ){
|
---|
| 545 | // リテラル配列の場合
|
---|
[3] | 546 |
|
---|
[93] | 547 | if( !baseType.IsPointer() ){
|
---|
| 548 | SetError(1,NULL,cp);
|
---|
| 549 | return false;
|
---|
| 550 | }
|
---|
| 551 | Type tempBaseType( baseType );
|
---|
| 552 | tempBaseType.PtrLevelDown();
|
---|
| 553 |
|
---|
| 554 | char *buffer = (char *)malloc( lstrlen( expression ) + 1 );
|
---|
| 555 | lstrcpy( buffer, expression );
|
---|
| 556 | RemoveStringBracket( buffer );
|
---|
| 557 |
|
---|
| 558 | void *binary = malloc( 1 );
|
---|
| 559 | int num = 0;
|
---|
| 560 |
|
---|
| 561 | i = 0;
|
---|
| 562 | while( buffer[i] ){
|
---|
| 563 | i = GetOneParameter( buffer, i, temporary );
|
---|
| 564 | if( buffer[i] == ',' ){
|
---|
| 565 | i++;
|
---|
| 566 | }
|
---|
| 567 |
|
---|
| 568 | Type resultType;
|
---|
| 569 | _int64 i64data;
|
---|
| 570 | if( !StaticCalculation( true, temporary, tempBaseType.GetBasicType(), &i64data, resultType ) ){
|
---|
| 571 | return false;
|
---|
| 572 | }
|
---|
| 573 | if( !resultType.IsWhole() ){
|
---|
| 574 | // TODO: 実数に未対応
|
---|
| 575 | SetError();
|
---|
| 576 | return false;
|
---|
| 577 | }
|
---|
| 578 |
|
---|
| 579 | binary = realloc( binary, ( num + 1 ) * tempBaseType.GetSize() );
|
---|
| 580 | memcpy( (char *)binary + (num * tempBaseType.GetSize()), &i64data, tempBaseType.GetSize() );
|
---|
| 581 | num++;
|
---|
| 582 | }
|
---|
| 583 |
|
---|
[265] | 584 | i2 = compiler.GetObjectModule().dataTable.AddBinary( binary, num * tempBaseType.GetSize() );
|
---|
[93] | 585 |
|
---|
| 586 | //mov eax,i2
|
---|
[237] | 587 | compiler.codeGenerator.op_mov_RV(REG_EAX,i2, Schedule::DataTable );
|
---|
[93] | 588 |
|
---|
| 589 | free( buffer );
|
---|
| 590 |
|
---|
| 591 | resultType = baseType;
|
---|
| 592 |
|
---|
| 593 | //push eax
|
---|
[225] | 594 | compiler.codeGenerator.op_push( REG_EAX );
|
---|
[93] | 595 |
|
---|
| 596 | return true;
|
---|
| 597 | }
|
---|
| 598 |
|
---|
[254] | 599 | bool isLiteralCalculation;
|
---|
| 600 | if( !NumOpe_GetType( expression, baseType, resultType, &isLiteralCalculation ) )
|
---|
| 601 | {
|
---|
| 602 | return false;
|
---|
| 603 | }
|
---|
| 604 | if( isLiteralCalculation )
|
---|
| 605 | {
|
---|
| 606 | //右辺値が数値の定数式の場合
|
---|
| 607 | _int64 i64data;
|
---|
| 608 | StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType);
|
---|
[93] | 609 |
|
---|
[254] | 610 | if( resultType.GetBasicSize() == sizeof(_int64) ){
|
---|
| 611 | //64ビット(符号有り整数/実数)
|
---|
| 612 |
|
---|
| 613 | //push HILONG(i64data)
|
---|
| 614 | compiler.codeGenerator.op_push_V((long)*(long *)(((char *)(&i64data))+4));
|
---|
| 615 |
|
---|
| 616 | //push LOLONG(i64data)
|
---|
| 617 | compiler.codeGenerator.op_push_V(*(long *)(&i64data));
|
---|
| 618 | }
|
---|
| 619 | else if( resultType.IsSingle() ){
|
---|
| 620 | //single実数
|
---|
| 621 |
|
---|
| 622 | double dbl;
|
---|
| 623 | memcpy(&dbl,&i64data,sizeof(_int64));
|
---|
| 624 |
|
---|
| 625 | float flt;
|
---|
| 626 | flt=(float)dbl;
|
---|
| 627 | long l;
|
---|
| 628 | memcpy(&l,&flt,sizeof(long));
|
---|
| 629 |
|
---|
| 630 | //push flt
|
---|
| 631 | compiler.codeGenerator.op_push_V(l);
|
---|
| 632 | }
|
---|
| 633 | else{
|
---|
| 634 | //整数(符号有り/無し)
|
---|
| 635 |
|
---|
| 636 | long l = (long)i64data;
|
---|
| 637 |
|
---|
| 638 | if(resultType.GetBasicSize()==sizeof(char)) l = l & 0x000000FF;
|
---|
| 639 | if(resultType.GetBasicSize()==sizeof(short)) l = l & 0x0000FFFF;
|
---|
| 640 |
|
---|
| 641 | //push term
|
---|
| 642 | compiler.codeGenerator.op_push_V(l);
|
---|
| 643 | }
|
---|
| 644 | return true;
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | if(expression[0]==1&& expression[1]==ESC_NEW ){
|
---|
| 648 | //New演算子(オブジェクト生成)
|
---|
| 649 |
|
---|
| 650 | if( !Operator_New( expression+2, baseType, resultType ) ){
|
---|
| 651 | return false;
|
---|
| 652 | }
|
---|
| 653 |
|
---|
| 654 | return true;
|
---|
| 655 | }
|
---|
| 656 |
|
---|
| 657 |
|
---|
[3] | 658 | /////////////////////////////////
|
---|
| 659 | // 式要素を逆ポーランド式で取得
|
---|
| 660 | /////////////////////////////////
|
---|
| 661 |
|
---|
| 662 | char *values[255];
|
---|
| 663 | long calc[255];
|
---|
| 664 | long stack[255];
|
---|
| 665 | int pnum;
|
---|
[76] | 666 | if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
|
---|
[3] | 667 | for(i=0;i<pnum;i++){
|
---|
| 668 | if(values[i]) HeapDefaultFree(values[i]);
|
---|
| 669 | }
|
---|
[76] | 670 | return false;
|
---|
[3] | 671 | }
|
---|
| 672 |
|
---|
| 673 |
|
---|
| 674 | BOOL bError;
|
---|
| 675 | bError=0;
|
---|
| 676 |
|
---|
| 677 | //リテラル値のみの計算かどうかを判別するためのフラグ
|
---|
| 678 | BOOL bLiteralCalculation=1;
|
---|
| 679 |
|
---|
| 680 | //リテラル演算の場合を考慮した演算前のプロシージャスケジュール位置
|
---|
| 681 | //※64ビットの掛け算、除算などで特殊関数が呼ばれるため
|
---|
| 682 | int Before_ProcAddrScheduleNum;
|
---|
| 683 | Before_ProcAddrScheduleNum=pobj_SubAddrSchedule->num;
|
---|
| 684 |
|
---|
| 685 | //リテラル演算の場合を考慮した演算前のデータテーブルスケジュール位置
|
---|
| 686 | int Before_DataTableScheduleNum;
|
---|
| 687 | Before_DataTableScheduleNum=pobj_DataTableSchedule->num;
|
---|
| 688 |
|
---|
| 689 | //リテラル演算の場合を考慮した演算前の再配置スケジュール
|
---|
| 690 | CReloc *pobj_BackReloc;
|
---|
| 691 | pobj_BackReloc=new CReloc();
|
---|
| 692 | pobj_BackReloc->copy(pobj_Reloc);
|
---|
| 693 |
|
---|
| 694 | double dbl;
|
---|
| 695 | int sp;
|
---|
[76] | 696 | int type_stack[255];
|
---|
[79] | 697 | bool isNothing_stack[255];
|
---|
[3] | 698 | LONG_PTR index_stack[255];
|
---|
| 699 | BOOL bUseHeap[255];
|
---|
| 700 | _int64 i64data;
|
---|
| 701 | for(i=0,sp=0;i<pnum;i++){
|
---|
| 702 | int idCalc;
|
---|
| 703 | idCalc=calc[i]%100;
|
---|
| 704 |
|
---|
| 705 | if(idCalc){
|
---|
[76] | 706 | if(type_stack[sp-2]==DEF_OBJECT){
|
---|
[79] | 707 | if( idCalc == CALC_AS
|
---|
| 708 | && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
|
---|
| 709 | && index_stack[sp-1] == index_stack[sp-2]
|
---|
| 710 | || isNothing_stack[sp-2] ){
|
---|
| 711 | // 同一の型、またはNothingに対するAsはAs演算子を呼び出さない
|
---|
[3] | 712 | }
|
---|
[94] | 713 | else if( idCalc == CALC_AS
|
---|
| 714 | && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
|
---|
| 715 | && ( ((CClass *)index_stack[sp-1])->IsEqualsOrSubClass( (CClass *)index_stack[sp-2] ) || ((CClass *)index_stack[sp-2])->IsEqualsOrSubClass( (CClass *)index_stack[sp-1] )
|
---|
| 716 | )){
|
---|
| 717 | // ダウンキャストを許可する
|
---|
| 718 | }
|
---|
[79] | 719 | else{
|
---|
| 720 | //オーバーロードされたオペレータを呼び出す
|
---|
| 721 | i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,bUseHeap,sp);
|
---|
| 722 | if(i2==0){
|
---|
| 723 | if(idCalc==CALC_EQUAL) lstrcpy(temp2,"==");
|
---|
| 724 | else GetCalcName(idCalc,temp2);
|
---|
| 725 | sprintf(temporary,"Operator %s",temp2);
|
---|
| 726 | SetError(27,temporary,cp);
|
---|
| 727 | goto error;
|
---|
| 728 | }
|
---|
| 729 | else if(i2==-1) goto error;
|
---|
[3] | 730 |
|
---|
[79] | 731 | continue;
|
---|
| 732 | }
|
---|
[3] | 733 | }
|
---|
| 734 |
|
---|
[76] | 735 | if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
|
---|
[3] | 736 | }
|
---|
| 737 |
|
---|
| 738 | switch(idCalc){
|
---|
| 739 | //数値
|
---|
| 740 | case 0:
|
---|
| 741 | index_stack[sp]=-1;
|
---|
[79] | 742 | isNothing_stack[sp] = false;
|
---|
[3] | 743 | bUseHeap[sp]=0;
|
---|
| 744 |
|
---|
| 745 | char *term;
|
---|
| 746 | term=values[i];
|
---|
| 747 |
|
---|
[97] | 748 | if( calc[i+1]%100 == CALC_AS ){
|
---|
| 749 | // As演算子の右辺値
|
---|
| 750 | //型名
|
---|
[193] | 751 | if( Compiler::StringToType( term, resultType ) ){
|
---|
[97] | 752 | resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
|
---|
| 753 | }
|
---|
| 754 | else{
|
---|
| 755 | SetError(3, term, cp );
|
---|
| 756 | goto error;
|
---|
| 757 | }
|
---|
| 758 |
|
---|
| 759 | type_stack[sp] = resultType.GetBasicType();
|
---|
| 760 | index_stack[sp] = resultType.GetIndex();
|
---|
| 761 | sp++;
|
---|
| 762 |
|
---|
| 763 | break;
|
---|
| 764 | }
|
---|
| 765 |
|
---|
[3] | 766 | if(term[0]=='\"'){
|
---|
| 767 | //リテラル文字列
|
---|
| 768 | if(!RemoveStringQuotes(term)){
|
---|
| 769 | SetError(43,NULL,cp);
|
---|
| 770 | goto error;
|
---|
| 771 | }
|
---|
| 772 | i3=lstrlen(term);
|
---|
| 773 | StrLiteral:
|
---|
| 774 |
|
---|
[97] | 775 | if( baseType.IsObject() || baseType.IsNull() ){
|
---|
| 776 | //要求タイプがオブジェクト、または未定のとき
|
---|
[3] | 777 |
|
---|
[97] | 778 | //String型オブジェクトを生成
|
---|
| 779 | NewStringObject(term);
|
---|
[3] | 780 |
|
---|
[97] | 781 | type_stack[sp]=DEF_OBJECT;
|
---|
[265] | 782 | index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
|
---|
[97] | 783 | bLiteralCalculation=0;
|
---|
[3] | 784 |
|
---|
[97] | 785 | sp++;
|
---|
| 786 | break;
|
---|
[3] | 787 | }
|
---|
| 788 |
|
---|
| 789 |
|
---|
[76] | 790 | type_stack[sp]=typeOfPtrChar;
|
---|
[3] | 791 | bLiteralCalculation=0;
|
---|
| 792 |
|
---|
[265] | 793 | i2=compiler.GetObjectModule().dataTable.AddString(term,i3);
|
---|
[3] | 794 |
|
---|
| 795 | //push DataSize
|
---|
[237] | 796 | compiler.codeGenerator.op_push_V( i2, Schedule::DataTable );
|
---|
[3] | 797 | }
|
---|
| 798 | else if((term[0]=='e'||term[0]=='E')&&
|
---|
| 799 | (term[1]=='x'||term[1]=='X')&&
|
---|
| 800 | term[2]=='\"'){
|
---|
| 801 | //拡張版リテラル文字列(エスケープシーケンス可能)
|
---|
| 802 | if(!RemoveStringQuotes(term+2)){
|
---|
| 803 | SetError(43,NULL,cp);
|
---|
| 804 | goto error;
|
---|
| 805 | }
|
---|
| 806 | i3=FormatString_EscapeSequence(term+2);
|
---|
| 807 | term+=2;
|
---|
| 808 |
|
---|
| 809 | goto StrLiteral;
|
---|
| 810 | }
|
---|
| 811 | else if(IsVariableTopChar(term[0])||
|
---|
| 812 | term[0]=='*'||
|
---|
| 813 | (term[0]=='.'&&IsVariableTopChar(term[1]))){
|
---|
| 814 | //////////////////
|
---|
| 815 | // 何らかの識別子
|
---|
| 816 |
|
---|
[97] | 817 | bool isLiteral;
|
---|
| 818 | if( TermOpe( term, baseType, resultType, isLiteral, &bUseHeap[sp] ) ){
|
---|
| 819 | if(resultType.IsNull()){
|
---|
| 820 | //戻り値が存在しないとき
|
---|
| 821 | for(i2=0;;i2++){
|
---|
| 822 | if(term[i2]=='('||term[i2]=='\0'){
|
---|
| 823 | term[i2]=0;
|
---|
| 824 | break;
|
---|
[49] | 825 | }
|
---|
| 826 | }
|
---|
[97] | 827 | SetError(38,term,cp);
|
---|
[3] | 828 |
|
---|
[97] | 829 | goto error;
|
---|
| 830 | }
|
---|
[3] | 831 |
|
---|
[97] | 832 | type_stack[sp] = resultType.GetBasicType();
|
---|
| 833 | index_stack[sp] = resultType.GetIndex();
|
---|
[3] | 834 |
|
---|
[97] | 835 | if( !isLiteral ){
|
---|
[3] | 836 | bLiteralCalculation=0;
|
---|
[97] | 837 | }
|
---|
[3] | 838 |
|
---|
[97] | 839 | if( resultType.GetBasicType() & FLAG_CAST ){
|
---|
| 840 | // 型名のみ
|
---|
| 841 | SetError();
|
---|
| 842 | }
|
---|
| 843 | else{
|
---|
| 844 | if( resultType.IsReal() ){
|
---|
| 845 | //sub esp,size
|
---|
| 846 | //fstp ptr[esp]
|
---|
[225] | 847 | compiler.codeGenerator.op_fstp_push( resultType );
|
---|
[3] | 848 | }
|
---|
[97] | 849 | else{
|
---|
| 850 | if( resultType.Is64() ){
|
---|
| 851 | //push edx
|
---|
[225] | 852 | compiler.codeGenerator.op_push( REG_EDX );
|
---|
[97] | 853 | }
|
---|
| 854 | else{
|
---|
| 855 | ExtendTypeTo32( resultType.GetBasicType(), REG_EAX );
|
---|
| 856 | }
|
---|
[3] | 857 |
|
---|
[97] | 858 | //push eax
|
---|
[225] | 859 | compiler.codeGenerator.op_push( REG_EAX );
|
---|
[3] | 860 | }
|
---|
| 861 | }
|
---|
| 862 |
|
---|
[97] | 863 | sp++;
|
---|
| 864 | break;
|
---|
[3] | 865 | }
|
---|
| 866 |
|
---|
| 867 |
|
---|
[67] | 868 | // Nothing
|
---|
| 869 | if( lstrcmp( term, "Nothing" ) == 0 ){
|
---|
[79] | 870 | isNothing_stack[sp] = true;
|
---|
| 871 |
|
---|
[76] | 872 | type_stack[sp] = DEF_OBJECT;
|
---|
| 873 | if( baseType.IsObject() ){
|
---|
| 874 | index_stack[sp] = baseType.GetIndex();
|
---|
[67] | 875 | }
|
---|
| 876 | else{
|
---|
[265] | 877 | index_stack[sp] = (LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
|
---|
[67] | 878 | }
|
---|
[3] | 879 |
|
---|
[67] | 880 | bLiteralCalculation = 0;
|
---|
| 881 |
|
---|
| 882 | //push 0
|
---|
[225] | 883 | compiler.codeGenerator.op_push_V( 0 );
|
---|
[67] | 884 |
|
---|
| 885 | sp++;
|
---|
| 886 | break;
|
---|
| 887 | }
|
---|
| 888 |
|
---|
[3] | 889 |
|
---|
| 890 | //////////////
|
---|
| 891 | // 定数の場合
|
---|
| 892 | //////////////
|
---|
| 893 |
|
---|
[265] | 894 | i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(term);
|
---|
[8] | 895 | if(i3){
|
---|
[265] | 896 | if( compiler.GetObjectModule().meta.GetGlobalConsts().IsStringPtr( term ) ){
|
---|
[103] | 897 | //リテラル文字列
|
---|
| 898 |
|
---|
[265] | 899 | double dbl = compiler.GetObjectModule().meta.GetGlobalConsts().GetDoubleData(term);
|
---|
[103] | 900 | memcpy(&i64data,&dbl,sizeof(double));
|
---|
| 901 |
|
---|
| 902 | //バイト数
|
---|
| 903 | i3=lstrlen((char *)i64data);
|
---|
| 904 |
|
---|
| 905 | memcpy(term,(char *)i64data,i3);
|
---|
| 906 | term[i3]=0;
|
---|
| 907 | goto StrLiteral;
|
---|
| 908 | }
|
---|
| 909 |
|
---|
[76] | 910 | type_stack[sp]=i3;
|
---|
[3] | 911 | if(IsRealNumberType(i3)){
|
---|
| 912 | //実数
|
---|
[265] | 913 | double dbl = compiler.GetObjectModule().meta.GetGlobalConsts().GetDoubleData(term);
|
---|
[3] | 914 | memcpy(&i64data,&dbl,sizeof(double));
|
---|
| 915 | goto Literal;
|
---|
| 916 | }
|
---|
| 917 | else if(IsWholeNumberType(i3)){
|
---|
| 918 | //整数
|
---|
[265] | 919 | i64data = compiler.GetObjectModule().meta.GetGlobalConsts().GetWholeData(term);
|
---|
[3] | 920 | goto Literal;
|
---|
| 921 | }
|
---|
| 922 | else{
|
---|
| 923 | SetError(300,NULL,cp);
|
---|
| 924 | goto error;
|
---|
| 925 | }
|
---|
| 926 | }
|
---|
| 927 |
|
---|
| 928 |
|
---|
| 929 | //該当する識別子が見当たらないときはエラー扱いにする
|
---|
| 930 | bError=1;
|
---|
| 931 | SetError(3,term,cp);
|
---|
[76] | 932 | type_stack[sp]=DEF_DOUBLE;
|
---|
[3] | 933 | }
|
---|
| 934 | else{
|
---|
| 935 | //リテラル値
|
---|
[76] | 936 | type_stack[sp]=GetLiteralValue(term,&i64data,baseType.GetBasicType());
|
---|
[3] | 937 | Literal:
|
---|
[76] | 938 | if(type_stack[sp]==DEF_INT64||
|
---|
| 939 | type_stack[sp]==DEF_QWORD||
|
---|
| 940 | type_stack[sp]==DEF_DOUBLE){
|
---|
[3] | 941 | //64ビット(符号有り整数/実数)
|
---|
| 942 |
|
---|
| 943 | //push HILONG(dbl)
|
---|
[225] | 944 | compiler.codeGenerator.op_push_V((long)*(long *)(((char *)(&i64data))+4));
|
---|
[3] | 945 |
|
---|
| 946 | //push LOLONG(dbl)
|
---|
[225] | 947 | compiler.codeGenerator.op_push_V(*(long *)(&i64data));
|
---|
[3] | 948 | }
|
---|
[76] | 949 | else if(type_stack[sp]==DEF_SINGLE){
|
---|
[3] | 950 | //single実数
|
---|
| 951 |
|
---|
| 952 | float flt;
|
---|
| 953 | memcpy(&dbl,&i64data,sizeof(double));
|
---|
| 954 | flt=(float)dbl;
|
---|
| 955 | memcpy(&i3,&flt,sizeof(long));
|
---|
| 956 |
|
---|
| 957 | //push term
|
---|
[225] | 958 | compiler.codeGenerator.op_push_V(i3);
|
---|
[3] | 959 | }
|
---|
| 960 | else{
|
---|
| 961 | //その他
|
---|
| 962 |
|
---|
| 963 | //push term
|
---|
[225] | 964 | compiler.codeGenerator.op_push_V((long)i64data);
|
---|
[3] | 965 |
|
---|
| 966 | if((long)i64data==0) index_stack[sp]=LITERAL_NULL;
|
---|
| 967 | }
|
---|
| 968 |
|
---|
| 969 |
|
---|
| 970 | //リテラル値の種類
|
---|
[76] | 971 | if(Is64Type(type_stack[sp])==0&&IsRealNumberType(type_stack[sp])==0){
|
---|
[3] | 972 | //整数(符号有り/無し)
|
---|
| 973 |
|
---|
| 974 | index_stack[sp]=GetLiteralIndex(i64data);
|
---|
| 975 | }
|
---|
| 976 | }
|
---|
| 977 | sp++;
|
---|
| 978 | break;
|
---|
| 979 |
|
---|
| 980 | //論理演算子
|
---|
| 981 | case CALC_XOR:
|
---|
| 982 | //value[sp-2] xor= value[sp-1]
|
---|
| 983 | //xor演算
|
---|
[76] | 984 | if(!Calc_Xor(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 985 | break;
|
---|
| 986 | case CALC_OR:
|
---|
| 987 | //value[sp-2] or= value[sp-1]
|
---|
| 988 | //or演算
|
---|
[76] | 989 | if(!Calc_Or(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 990 | break;
|
---|
| 991 | case CALC_AND:
|
---|
| 992 | //value[sp-2] and= value[sp-1]
|
---|
| 993 | //and演算
|
---|
[76] | 994 | if(!Calc_And(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 995 | break;
|
---|
| 996 | case CALC_NOT:
|
---|
| 997 | //value[sp-1]=Not value[sp-1]
|
---|
| 998 | //NOT演算子
|
---|
[76] | 999 | if(!Calc_Not(type_stack,sp)) goto error;
|
---|
[3] | 1000 | break;
|
---|
| 1001 |
|
---|
| 1002 | //比較演算子
|
---|
| 1003 | case CALC_PE:
|
---|
| 1004 | //value[sp-2]<=value[sp-1]
|
---|
[76] | 1005 | if(!Calc_Relation_PE(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 1006 | break;
|
---|
| 1007 | case CALC_QE:
|
---|
| 1008 | //value[sp-2]>=value[sp-1]
|
---|
[76] | 1009 | if(!Calc_Relation_QE(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 1010 | break;
|
---|
| 1011 | case CALC_P:
|
---|
| 1012 | //value[sp-2]<value[sp-1]
|
---|
[76] | 1013 | if(!Calc_Relation_P(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 1014 | break;
|
---|
| 1015 | case CALC_Q:
|
---|
| 1016 | //value[sp-2]>value[sp-1]
|
---|
[76] | 1017 | if(!Calc_Relation_Q(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 1018 | break;
|
---|
| 1019 | case CALC_NOTEQUAL:
|
---|
| 1020 | //value[sp-2]<>value[sp-1]
|
---|
[76] | 1021 | if(!Calc_Relation_NotEqual(type_stack,&sp)) goto error;
|
---|
[3] | 1022 | break;
|
---|
| 1023 | case CALC_EQUAL:
|
---|
| 1024 | //value[sp-2]=value[sp-1]
|
---|
[76] | 1025 | if(!Calc_Relation_Equal(type_stack,&sp)) goto error;
|
---|
[3] | 1026 | break;
|
---|
| 1027 |
|
---|
| 1028 | //ビットシフト
|
---|
| 1029 | case CALC_SHL:
|
---|
| 1030 | //value[sp-2]=value[sp-2]<<value[sp-1]
|
---|
[76] | 1031 | if(!Calc_SHL(type_stack,&sp)) goto error;
|
---|
[3] | 1032 | break;
|
---|
| 1033 | case CALC_SHR:
|
---|
| 1034 | //value[sp-2]=value[sp-2]>>value[sp-1]
|
---|
[76] | 1035 | if(!Calc_SHR(type_stack,&sp)) goto error;
|
---|
[3] | 1036 | break;
|
---|
| 1037 |
|
---|
| 1038 | //算術演算
|
---|
| 1039 | case CALC_ADDITION:
|
---|
| 1040 | case CALC_SUBTRACTION:
|
---|
| 1041 | case CALC_PRODUCT:
|
---|
[76] | 1042 | if(!CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 1043 | break;
|
---|
| 1044 |
|
---|
| 1045 | case CALC_MOD:
|
---|
| 1046 | //value[sp-2]%=value[sp-1]
|
---|
| 1047 | //剰余演算
|
---|
[76] | 1048 | if(!Calc_Mod(type_stack,&sp)) goto error;
|
---|
[3] | 1049 | break;
|
---|
| 1050 | case CALC_QUOTIENT:
|
---|
| 1051 | //value[sp-2]/=value[sp-1];
|
---|
| 1052 | //除算
|
---|
[76] | 1053 | if(!Calc_Divide(type_stack,&sp,baseType.GetBasicType())) goto error;
|
---|
[3] | 1054 | break;
|
---|
| 1055 | case CALC_INTQUOTIENT:
|
---|
| 1056 | //value[sp-2]/=value[sp-1]
|
---|
| 1057 | //整数除算
|
---|
[76] | 1058 | if(!Calc_IntDivide(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 1059 | break;
|
---|
| 1060 | case CALC_MINUSMARK:
|
---|
| 1061 | //value[sp-1]=-value[sp-1]
|
---|
| 1062 | //符号反転
|
---|
[76] | 1063 | if(!Calc_MinusMark(type_stack,sp)) goto error;
|
---|
[3] | 1064 | index_stack[sp-1]=-1;
|
---|
| 1065 | break;
|
---|
| 1066 | case CALC_POWER:
|
---|
| 1067 | //べき乗演算(浮動小数点演算のみ)
|
---|
[76] | 1068 | if(!Calc_Power(type_stack,&sp)) goto error;
|
---|
[3] | 1069 | break;
|
---|
| 1070 | case CALC_AS:
|
---|
| 1071 | //キャスト
|
---|
[76] | 1072 | if(!Calc_Cast(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 1073 | break;
|
---|
| 1074 |
|
---|
[41] | 1075 | case CALC_BYVAL:
|
---|
| 1076 | //ポインタ型→参照型
|
---|
[76] | 1077 | if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
|
---|
[41] | 1078 | //ポインタ型ではないとき
|
---|
| 1079 | SetError( 3, NULL, cp );
|
---|
| 1080 | goto error;
|
---|
| 1081 | }
|
---|
| 1082 |
|
---|
[76] | 1083 | type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
|
---|
[41] | 1084 |
|
---|
| 1085 | break;
|
---|
| 1086 |
|
---|
[3] | 1087 | default:
|
---|
| 1088 | SetError(300,NULL,cp);
|
---|
[41] | 1089 | goto error;
|
---|
[3] | 1090 | }
|
---|
| 1091 | }
|
---|
| 1092 |
|
---|
| 1093 | if(bError) goto error;
|
---|
| 1094 |
|
---|
| 1095 | if(sp!=1){
|
---|
| 1096 | SetError(1,NULL,cp);
|
---|
| 1097 | goto error;
|
---|
| 1098 | }
|
---|
| 1099 |
|
---|
| 1100 | if(bLiteralCalculation){
|
---|
| 1101 | //右辺値が数値の定数式の場合
|
---|
[254] | 1102 | SetError();
|
---|
[3] | 1103 | }
|
---|
| 1104 | else{
|
---|
| 1105 | //右辺値が数値の定数式ではないとき
|
---|
| 1106 | if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
|
---|
| 1107 | }
|
---|
| 1108 |
|
---|
| 1109 | if(pbUseHeap) *pbUseHeap=bUseHeap[0];
|
---|
| 1110 |
|
---|
[76] | 1111 | resultType.SetType( type_stack[0], index_stack[0] );
|
---|
| 1112 |
|
---|
| 1113 | bool isSuccessful = true;
|
---|
[3] | 1114 | goto finish;
|
---|
| 1115 |
|
---|
| 1116 |
|
---|
| 1117 | error:
|
---|
[76] | 1118 | isSuccessful = false;
|
---|
[3] | 1119 | goto finish;
|
---|
| 1120 |
|
---|
| 1121 |
|
---|
| 1122 | finish:
|
---|
| 1123 |
|
---|
| 1124 | for(i=0;i<pnum;i++){
|
---|
| 1125 | if(values[i]) HeapDefaultFree(values[i]);
|
---|
| 1126 | }
|
---|
| 1127 |
|
---|
| 1128 | //再配置スケジュールバックアップ情報を解放
|
---|
| 1129 | delete pobj_BackReloc;
|
---|
| 1130 |
|
---|
[76] | 1131 | return isSuccessful;
|
---|
[3] | 1132 | }
|
---|