Changeset 128 in dev


Ignore:
Timestamp:
May 18, 2007, 4:42:36 AM (17 years ago)
Author:
dai_9181
Message:

Blittable型を導入した。

Files:
21 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler32/Compile_Calc.cpp

    r116 r128  
    619619
    620620
     621    if( varType.IsObject() && Smoothie::Meta::blittableTypes.IsExist( calcType ) ){
     622        // Blittable型をオブジェクトとして扱う
     623        vector<UserProc *> userProcs;
     624        Smoothie::Meta::blittableTypes.GetClass( calcType ).EnumStaticMethod( "_Create", userProcs );
     625        if( userProcs.size() != 1 ){
     626            SetError();
     627            return;
     628        }
     629        UserProc *pUserProc = userProcs[0];
     630
     631        // call System.[TypeClass]._Create
     632        op_call( pUserProc );
     633
     634        // push eax
     635        op_push( REG_EAX );
     636
     637        calcType = pUserProc->ReturnType();
     638    }
     639
    621640
    622641    /////////////////////////////////
  • BasicCompiler32/Compile_Statement.cpp

    r122 r128  
    9090    bool isLiteral;
    9191    BOOL bUseHeap;
    92     bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, NULL, true );
    93 
     92    bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, false, NULL, true );
    9493    if( result ){
    9594
  • BasicCompiler32/NumOpe.cpp

    r122 r128  
    227227    return false;
    228228}
    229 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly ){
     229bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool isWantObject, bool *pIsClassName, bool isProcedureCallOnly ){
    230230    char parameter[VN_SIZE];
    231231
     
    255255        bool isClassName = false;
    256256        Type leftType;
    257         if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, &isClassName ) ){
     257        if( GetTermType( termLeft, leftType, isLiteral, &isClassName ) ){
     258            if( isClassName == false && Smoothie::Meta::blittableTypes.IsExist( leftType ) ){
     259                // 左側のオブジェクト部分がBlittable型のとき
     260
     261                char temporary[VN_SIZE];
     262                lstrcpy( temporary, termLeft );
     263                sprintf( termLeft, "%s(%s)",
     264                    Smoothie::Meta::blittableTypes.Find( leftType ).GetCreateStaticMethodFullName().c_str(),
     265                    temporary );
     266            }
     267        }
     268
     269        if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, true, &isClassName ) ){
    258270            goto globalArea;
    259271        }
  • BasicCompiler32/Opcode.h

    r122 r128  
    102102//NumOpe.cpp
    103103void PushReturnValue(int type);
    104 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName = NULL, bool isProcedureCallOnly = false );
     104bool TermOpe(
     105             const char *term,
     106             const Type &baseType,
     107             Type &resultType,
     108             bool &isLiteral,
     109             BOOL *pbUseHeap,
     110             bool isWantObject = false,
     111             bool *pIsClassName = NULL,
     112             bool isProcedureCallOnly = false );
    105113bool NumOpe( int reg,
    106114            const char *expression,
  • BasicCompiler64/BasicCompiler.vcproj

    r127 r128  
    157157                RuntimeLibrary="1"
    158158                UsePrecompiledHeader="0"
    159                 PrecompiledHeaderFile=".\Debug/BasicCompiler.pch"
    160                 AssemblerListingLocation=".\Debug/"
    161                 ObjectFile=".\Debug/"
    162                 ProgramDataBaseFileName=".\Debug/"
     159                PrecompiledHeaderFile=".\SmallDebug/BasicCompiler.pch"
     160                AssemblerListingLocation=".\SmallDebug/"
     161                ObjectFile=".\SmallDebug/"
     162                ProgramDataBaseFileName=".\SmallDebug/"
    163163                BrowseInformation="0"
    164164                WarningLevel="3"
     
    188188                IgnoreDefaultLibraryNames=""
    189189                GenerateDebugInformation="false"
    190                 ProgramDatabaseFile=".\Debug/BasicCompiler64.pdb"
     190                ProgramDatabaseFile=".\SmallDebug/BasicCompiler64.pdb"
    191191                SubSystem="2"
    192192                TargetMachine="0"
  • BasicCompiler64/Compile_Calc.cpp

    r116 r128  
    227227    }
    228228
     229    if( varType.IsObject() && Smoothie::Meta::blittableTypes.IsExist( calcType ) ){
     230        // Blittable型をオブジェクトとして扱う
     231        vector<UserProc *> userProcs;
     232        Smoothie::Meta::blittableTypes.GetClass( calcType ).EnumStaticMethod( "_Create", userProcs );
     233        if( userProcs.size() != 1 ){
     234            SetError();
     235            return;
     236        }
     237        UserProc *pUserProc = userProcs[0];
     238
     239        // mov rcx, rax
     240        op_mov_RR( REG_RCX, REG_RAX );
     241
     242        // call System.[TypeClass]._Create
     243        op_call( pUserProc );
     244
     245        calcType = pUserProc->ReturnType();
     246    }
    229247
    230248    /////////////////////////////////
  • BasicCompiler64/Compile_Statement.cpp

    r122 r128  
    9494    bool isLiteral;
    9595    BOOL bUseHeap;
    96     bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, NULL, true );
     96    bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, false, NULL, true );
    9797
    9898    delete pobj_reg;
  • BasicCompiler64/NumOpe.cpp

    r122 r128  
    224224    return false;
    225225}
    226 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly ){
     226bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool isWantObject, bool *pIsClassName, bool isProcedureCallOnly ){
    227227    char parameter[VN_SIZE];
    228228
     
    252252        bool isClassName = false;
    253253        Type leftType;
    254         if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, &isClassName ) ){
     254        if( GetTermType( termLeft, leftType, isLiteral, &isClassName ) ){
     255            if( isClassName == false && Smoothie::Meta::blittableTypes.IsExist( leftType ) ){
     256                // 左側のオブジェクト部分がBlittable型のとき
     257
     258                char temporary[VN_SIZE];
     259                lstrcpy( temporary, termLeft );
     260                sprintf( termLeft, "%s(%s)",
     261                    Smoothie::Meta::blittableTypes.Find( leftType ).GetCreateStaticMethodFullName().c_str(),
     262                    temporary );
     263            }
     264        }
     265
     266        if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, true, &isClassName ) ){
    255267            goto globalArea;
    256268        }
     
    705717                    //型名
    706718                    if( Type::StringToType( term, resultType ) ){
     719
     720                        if( resultType.IsObject() ){
     721                            if( resultType.GetClass().IsBlittableType() ){
     722                                // Blittable型のときは基本型として扱う
     723                                // ※ただし、コンパイル中のメソッドがBlittable型クラスに属していないこと
     724                                if( UserProc::IsLocalAreaCompiling()
     725                                    && UserProc::CompilingUserProc().HasParentClass()
     726                                    && UserProc::CompilingUserProc().GetParentClass().IsBlittableType() )
     727                                {
     728                                    // コンパイル中のメソッドがBlittable型クラスに属している
     729                                }
     730                                else{
     731                                    resultType = resultType.GetClass().GetBlittableType();
     732                                }
     733                            }
     734                        }
     735
    707736                        resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
    708737                    }
  • BasicCompiler64/Opcode.h

    r122 r128  
    251251
    252252//NumOpe.cpp
    253 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName = NULL, bool isProcedureCallOnly = false );
     253bool TermOpe(
     254             const char *term,
     255             const Type &baseType,
     256             Type &resultType,
     257             bool &isLiteral,
     258             BOOL *pbUseHeap,
     259             bool isWantObject = false,
     260             bool *pIsClassName = NULL,
     261             bool isProcedureCallOnly = false );
    254262bool NumOpe( int *pReg,
    255263           const char *Command,
  • BasicCompiler_Common/Class.cpp

    r127 r128  
    911911    char temporary[VN_SIZE];
    912912
     913    // Blittable型管理オブジェクトを初期化
     914    Smoothie::Meta::blittableTypes.clear();
     915
    913916    // 名前空間管理
    914917    NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
     
    971974
    972975                i+=2;
    973                 //アラインメント修飾子
     976                Type blittableType;
    974977                if(memicmp(basbuf+i,"Align(",6)==0){
     978                    //アラインメント修飾子
    975979                    i+=6;
    976980                    i=JumpStringInPare(basbuf,i)+1;
     981                }
     982                else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
     983                    // Blittable修飾子
     984                    i+=10;
     985                    i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
     986                    Type::StringToType( temporary, blittableType );
    977987                }
    978988
     
    10131023                    }
    10141024                }
     1025
     1026                // Blittable型の場合
     1027                if( !blittableType.IsNull() ){
     1028                    pClass->SetBlittableType( blittableType );
     1029
     1030                    // Blittable型として登録
     1031                    Smoothie::Meta::blittableTypes.push_back( BlittableType( blittableType, pClass ) );
     1032                }
    10151033        }
    10161034    }
     
    13441362            i+=2;
    13451363
    1346             //アラインメント修飾子
    13471364            int iAlign=0;
    13481365            if(memicmp(basbuf+i,"Align(",6)==0){
     1366                //アラインメント修飾子
    13491367                i+=6;
    13501368                i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
     
    13531371                if(!(iAlign==1||iAlign==2||iAlign==4||iAlign==8||iAlign==16))
    13541372                    SetError(51,NULL,i);
     1373            }
     1374            else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
     1375                // Blittable修飾子
     1376                i+=10;
     1377                i=JumpStringInPare(basbuf,i)+1;
    13551378            }
    13561379
     
    14161439                        goto InheritsError;
    14171440                    }
    1418                 }
    1419                 else if( memicmp( basbuf + i+1,"Blittable", 9 ) == 0 &&
    1420                     basbuf[i+10] == 1 && basbuf[i+11] == ESC_INHERITS ){
    1421                         // Blittable Inherits
    1422 
    1423                         for(i+=12,i2=0;;i++,i2++){
    1424                             if(IsCommandDelimitation(basbuf[i])){
    1425                                 temporary[i2]=0;
    1426                                 break;
    1427                             }
    1428                             temporary[i2]=basbuf[i];
    1429                         }
    1430 
    1431                         Type type;
    1432                         Type::StringToType( temporary, type );
    1433                         pobj_c->SetBlittableType( type );
    1434 
    14351441                }
    14361442
  • BasicCompiler_Common/Class.h

    r127 r128  
    130130    bool IsBlittableType() const
    131131    {
    132         return blittableType.IsNull();
     132        return !blittableType.IsNull();
    133133    }
    134134    const Type &GetBlittableType() const
  • BasicCompiler_Common/Intermediate_Step2.cpp

    r107 r128  
    418418                if( Command[i2] == 1 && Command[i2+1] == ESC_ENUM ){
    419419                    i2 += 2;
     420                }
     421                else if( memicmp( Command + i2, "Blittable(", 10 ) == 0 ){
     422                    i2 += 10;
     423                    i2 = JumpStringInPare(Command,i2)+1;
    420424                }
    421425
  • BasicCompiler_Common/NumOpe_GetType.cpp

    r117 r128  
    294294}
    295295
    296 bool GetTermType( const char *term, Type &resultType, bool &isLiteral, bool *pIsClassName = NULL ){
     296bool GetTermType( const char *term, Type &resultType, bool &isLiteral, bool *pIsClassName ){
    297297    char parameter[VN_SIZE];
    298298
     
    322322        bool isClassName = false;
    323323        Type leftType;
    324         if( !GetTermType( termLeft, leftType, isLiteral, &isClassName ) ){
     324        if( GetTermType( termLeft, leftType, isLiteral, &isClassName ) ){
     325            if( isClassName == false && Smoothie::Meta::blittableTypes.IsExist( leftType ) ){
     326                // 左側のオブジェクト部分がBlittable型のとき
     327
     328                char temporary[VN_SIZE];
     329                lstrcpy( temporary, termLeft );
     330                sprintf( termLeft, "%s(%s)",
     331                    Smoothie::Meta::blittableTypes.Find( leftType ).GetCreateStaticMethodFullName().c_str(),
     332                    temporary );
     333
     334                if( !GetTermType( termLeft, leftType, isLiteral, &isClassName ) ){
     335                    goto globalArea;
     336                }
     337            }
     338        }
     339        else{
    325340            goto globalArea;
    326341        }
     
    615630                    //型名
    616631                    if( Type::StringToType( term, resultType ) ){
     632
     633                        if( resultType.IsObject() ){
     634                            if( resultType.GetClass().IsBlittableType() ){
     635                                // Blittable型のときは基本型として扱う
     636                                // ※ただし、コンパイル中のメソッドがBlittable型クラスに属していないこと
     637                                if( UserProc::IsLocalAreaCompiling()
     638                                    && UserProc::CompilingUserProc().HasParentClass()
     639                                    && UserProc::CompilingUserProc().GetParentClass().IsBlittableType() )
     640                                {
     641                                    // コンパイル中のメソッドがBlittable型クラスに属している
     642                                }
     643                                else{
     644                                    resultType = resultType.GetClass().GetBlittableType();
     645                                }
     646                            }
     647                        }
     648
    617649                        resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
    618650                    }
     
    656688                    //////////////////
    657689                    // 何らかの識別子
    658 
    659                         if( strstr(term,"T.B")){
    660                             int test=0;
    661                         }
    662690
    663691                    bool isLiteral = true;
  • BasicCompiler_Common/Procedure.cpp

    r116 r128  
    105105        }
    106106        else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
     107            // As指定
    107108            i+=2;
    108109
     
    131132                SetError(3,temporary,nowLine);
    132133                type.SetBasicType( DEF_PTR_VOID );
     134            }
     135
     136            if( type.IsObject() ){
     137                if( type.GetClass().IsBlittableType() ){
     138                    // Blittable型のときは基本型として扱う
     139                    type = type.GetClass().GetBlittableType();
     140                }
    133141            }
    134142        }
  • BasicCompiler_Common/Type.cpp

    r117 r128  
    522522    return Type( DEF_OBJECT, *pobj_DBClass->GetStringClassPtr() );
    523523}
     524
     525const string BlittableType::GetCreateStaticMethodFullName() const
     526{
     527    return pClass->GetNamespaceScopes().ToString() + "." + pClass->GetName() + "._Create";
     528}
  • BasicCompiler_Common/Type.h

    r114 r128  
    130130    static bool StringToType( const string &typeName, Type &type );
    131131};
     132
     133class BlittableType
     134{
     135    Type basicType;
     136    CClass *pClass;
     137public:
     138    BlittableType( const Type &basicType, CClass *pClass )
     139        : basicType( basicType )
     140        , pClass( pClass )
     141    {
     142    }
     143    BlittableType(){}
     144    const Type &GetBasicType() const
     145    {
     146        return basicType;
     147    }
     148    const CClass *GetClassPtr() const
     149    {
     150        return pClass;
     151    }
     152    const string GetCreateStaticMethodFullName() const;
     153};
     154class BlittableTypes : public vector<BlittableType>
     155{
     156public:
     157    bool IsExist( Type type ) const
     158    {
     159        const BlittableTypes &blittableTypes = *this;
     160        BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
     161            if( blittableType.GetBasicType().Equals( type ) ){
     162                return true;
     163            }
     164        }
     165        return false;
     166    }
     167    const BlittableType &Find( const Type &type ) const
     168    {
     169        const BlittableTypes &blittableTypes = *this;
     170        BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
     171            if( blittableType.GetBasicType().Equals( type ) ){
     172                return blittableType;
     173            }
     174        }
     175        throw "Blittable型ではない";
     176    }
     177    const CClass *GetClassPtr( const Type &type ) const
     178    {
     179        const BlittableTypes &blittableTypes = *this;
     180        BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
     181            if( blittableType.GetBasicType().Equals( type ) ){
     182                return blittableType.GetClassPtr();
     183            }
     184        }
     185        return NULL;
     186    }
     187    const CClass &GetClass( const Type &type ) const
     188    {
     189        return *GetClassPtr( type );
     190    }
     191};
  • BasicCompiler_Common/VariableOpe.cpp

    r117 r128  
    12031203    }
    12041204
     1205    if( type.IsObject() ){
     1206        if( type.GetClass().IsBlittableType() ){
     1207            // Blittable型のときは基本型として扱う
     1208            // ※ただし、コンパイル中のメソッドがBlittable型クラスに属していないこと
     1209            if( UserProc::IsLocalAreaCompiling()
     1210                && UserProc::CompilingUserProc().HasParentClass()
     1211                && UserProc::CompilingUserProc().GetParentClass().IsBlittableType() )
     1212            {
     1213                // コンパイル中のメソッドがBlittable型クラスに属している
     1214            }
     1215            else{
     1216                type = type.GetClass().GetBlittableType();
     1217            }
     1218        }
     1219    }
     1220
    12051221    if(dwFlags&DIMFLAG_STATIC){
    12061222        if( UserProc::IsGlobalAreaCompiling() ){
  • BasicCompiler_Common/calculation.cpp

    r126 r128  
    698698                            }
    699699
     700                            if( tempType.IsObject() ){
     701                                if( tempType.GetClass().IsBlittableType() ){
     702                                    // Blittable型のときは基本型として扱う
     703                                    tempType = tempType.GetClass().GetBlittableType();
     704                                }
     705                            }
     706
    700707                            type[pnum] = tempType.GetBasicType();
    701708                            before_index[pnum] = tempType.GetIndex();
  • BasicCompiler_Common/common.h

    r125 r128  
    4747
    4848#ifdef _AMD64_
    49 #define VER_INFO        "(x64) β rev.248"
     49#define VER_INFO        "(x64) β rev.255"
    5050#else
    51 #define VER_INFO        "β rev.248"
     51#define VER_INFO        "β rev.255"
    5252#endif
    5353
     
    439439int AutoBigCast(int BaseType,int CalcType);
    440440BOOL CheckCalcType(int idCalc,int *type,int sp);
     441bool GetTermType( const char *term, Type &resultType, bool &isLiteral, bool *pIsClassName = NULL );
    441442bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType );
    442443
  • BasicCompiler_Common/include/Smoothie.h

    r112 r128  
    4040        static NamespaceScopesCollection namespaceScopesCollection;
    4141        static NamespaceScopesCollection importedNamespaces;
     42        static BlittableTypes blittableTypes;
    4243    };
    4344
  • BasicCompiler_Common/src/Smoothie.cpp

    r112 r128  
    2323NamespaceScopesCollection Smoothie::Meta::namespaceScopesCollection;
    2424NamespaceScopesCollection Smoothie::Meta::importedNamespaces;
     25BlittableTypes Smoothie::Meta::blittableTypes;
    2526
    2627bool Smoothie::isFullCompile = false;
Note: See TracChangeset for help on using the changeset viewer.