Changeset 89 in dev


Ignore:
Timestamp:
Apr 4, 2007, 2:03:09 AM (17 years ago)
Author:
dai_9181
Message:

実行時型情報の生成に対応。
関数の戻り値の型に抽象クラスを指定できるようにした。

Files:
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler32/BasicCompiler.vcproj

    r88 r89  
    605605                <File
    606606                    RelativePath="..\BasicCompiler_Common\Overload.cpp"
    607                     >
    608                     <FileConfiguration
    609                         Name="Debug|Win32"
    610                         >
    611                         <Tool
    612                             Name="VCCLCompilerTool"
    613                             PreprocessorDefinitions=""
    614                         />
    615                     </FileConfiguration>
    616                     <FileConfiguration
    617                         Name="Release|Win32"
    618                         >
    619                         <Tool
    620                             Name="VCCLCompilerTool"
    621                             PreprocessorDefinitions=""
    622                         />
    623                     </FileConfiguration>
    624                     <FileConfiguration
    625                         Name="English_Rel|Win32"
    626                         >
    627                         <Tool
    628                             Name="VCCLCompilerTool"
    629                             PreprocessorDefinitions=""
    630                         />
    631                     </FileConfiguration>
    632                 </File>
    633                 <File
    634                     RelativePath="..\BasicCompiler_Common\preprocessor.cpp"
    635607                    >
    636608                    <FileConfiguration
  • BasicCompiler32/Compile_ProcOp.cpp

    r86 r89  
    204204        obp+=31;
    205205    }
    206     else if( userProc.GetName() == "InitializeUserTypes" ){
     206    else if( userProc.GetName() == "InitializeUserTypes"
     207        && userProc.HasParentClass()
     208        && (string)userProc.GetParentClass().name == "_System_TypeBase" ){
     209
     210            pobj_DBClass->Compile_System_InitializeUserTypes();
    207211    }
    208212    else{
     
    243247    pUserProc->beginOpAddress=obp;
    244248
     249    //コンパイル中の関数が属するクラス
     250    pobj_CompilingClass=pUserProc->GetParentClassPtr();
     251
     252    //コンパイルスタートをクラス管理クラスに追加
     253    pobj_DBClass->StartCompile( pUserProc );
     254
     255    //コンパイル中の関数
     256    UserProc::CompileStartForUserProc( pUserProc );
     257
    245258    if(pUserProc->IsSystem()){
     259        ////////////////////
     260        // 特殊関数
     261        ////////////////////
     262
    246263        extern int AllLocalVarSize;
    247264        AllLocalVarSize=0;
     
    313330    AllLocalVarSize+=sizeof(long);
    314331
    315     //コンパイル中の関数が属するクラス
    316     pobj_CompilingClass=pUserProc->GetParentClassPtr();
    317 
    318     //コンパイルスタートをクラス管理クラスに追加
    319     pobj_DBClass->StartCompile( pUserProc );
    320 
    321     //コンパイル中の関数
    322     UserProc::CompileStartForUserProc( pUserProc );
    323 
    324332
    325333    ///////////////////////
     
    358366        }
    359367        else{
    360             //戻り値用の変数の定義
    361             sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() );
     368            if( pUserProc->ReturnType().IsObject() ){
     369                sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() );
     370            }
     371            else{
     372                //戻り値用の変数の定義
     373                sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() );
     374            }
    362375
    363376            OpcodeDim(temporary,0);
     
    464477                    RemoveStringPare(temporary);
    465478
    466                     Opcode_CallProc(temporary,
    467                         pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc,
    468                         0,
    469                         "",
    470                         0);
     479                    Type dummyType;
     480                    CallProc( PROC_DEFAULT
     481                        , pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc
     482                        , pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc->GetName().c_str()
     483                        , temporary
     484                        , dummyType );
    471485                }
    472486                else{
  • BasicCompiler32/Compile_Var.cpp

    r79 r89  
    12191219    }
    12201220
     1221    /*
     1222    TODO: 消す
     1223    変数は抽象クラスでもOK
    12211224    if( type.IsObject() ){
    12221225        if( type.GetClass().IsAbstract() ){
     
    12251228        }
    12261229    }
     1230    */
    12271231}
    12281232
  • BasicCompiler64/BasicCompiler.vcproj

    r88 r89  
    13211321                </File>
    13221322                <File
    1323                     RelativePath="..\BasicCompiler_Common\preprocessor.cpp"
    1324                     >
    1325                 </File>
    1326                 <File
    13271323                    RelativePath="..\BasicCompiler_Common\RSrcSection.cpp"
    13281324                    >
  • BasicCompiler64/Compile_ProcOp.cpp

    r86 r89  
    195195        obp+=31;
    196196    }
    197     else if( userProc.GetName() == "InitializeUserTypes" ){
     197    else if( userProc.GetName() == "InitializeUserTypes"
     198        && userProc.HasParentClass()
     199        && (string)userProc.GetParentClass().name == "_System_TypeBase" ){
     200
     201            pobj_DBClass->Compile_System_InitializeUserTypes();
    198202    }
    199203    else{
     
    233237    pUserProc->beginOpAddress=obp;
    234238
     239    //コンパイル中の関数が属するクラス
     240    pobj_CompilingClass=pUserProc->GetParentClassPtr();
     241
     242    //コンパイルスタートをクラス管理クラスに追加
     243    pobj_DBClass->StartCompile( pUserProc );
     244
     245    //コンパイル中の関数
     246    UserProc::CompileStartForUserProc( pUserProc );
     247
    235248    if(pUserProc->IsSystem()){
    236249        ////////////////////
     
    351364    extern int LocalVar_ThisPtrOffset;
    352365    LocalVar_ThisPtrOffset=AllLocalVarSize;
    353 
    354     //コンパイル中の関数が属するクラス
    355     pobj_CompilingClass=pUserProc->GetParentClassPtr();
    356 
    357     //コンパイルスタートをクラス管理クラスに追加
    358     pobj_DBClass->StartCompile( pUserProc );
    359 
    360     //コンパイル中の関数
    361     UserProc::CompileStartForUserProc( pUserProc );
    362366
    363367    //スタックフレーム管理用クラスを初期化
     
    446450        }
    447451        else{
    448             //戻り値用の変数の定義
    449             sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() );
     452            if( pUserProc->ReturnType().IsObject() ){
     453                sprintf(temporary,"%s=Nothing%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() );
     454            }
     455            else{
     456                //戻り値用の変数の定義
     457                sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() );
     458            }
    450459
    451460            OpcodeDim(temporary,0);
     
    520529                    RemoveStringPare(temporary);
    521530
    522                     Opcode_CallProc(temporary,
    523                         pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc,
    524                         0,
    525                         "",
    526                         0);
     531                    Type dummyType;
     532                    CallProc( PROC_DEFAULT
     533                        , pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc
     534                        , pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc->GetName().c_str()
     535                        , temporary
     536                        , dummyType );
    527537                }
    528538                else{
  • BasicCompiler64/Compile_Var.cpp

    r79 r89  
    12071207    }
    12081208
     1209    /*
     1210    TODO: 消す
     1211    変数は抽象クラスでもOK
    12091212    if( type.IsObject() ){
    12101213        if( type.GetClass().IsAbstract() ){
     
    12131216        }
    12141217    }
     1218    */
    12151219}
    12161220void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar){
  • BasicCompiler64/MakePeHdr.cpp

    r88 r89  
    157157    //クラス情報を取得(※注 - GetSubInfoの後に呼び出す)
    158158    pobj_DBClass->GetAllClassInfo();
    159 
    160     // 実行時型情報の確定コード(InitializeUserTypesメソッドの実装コード)を生成
    161     pobj_DBClass->GenerateRuntimeTypeInfo();
    162159
    163160    //コードと行番号の関係
  • BasicCompiler_Common/Class.cpp

    r87 r89  
    117117
    118118            //ネイティブコードバッファの再確保
    119             extern int obp_AllocSize;
    120             if(obp_AllocSize<obp+8192){
    121                 obp_AllocSize+=8192;
    122                 OpBuffer=(char *)HeapReAlloc(hHeap,0,OpBuffer,obp_AllocSize); //matea
    123             }
     119            ReallocNativeCodeBuffer();
     120
    124121            i++;
    125122        }
     
    198195
    199196void CClass::Inherits( CClass *pInheritsClass ){
    200     int i3;
    201197
    202198    //メンバをコピー
     
    207203        pInheritsClass->iMemberNum*sizeof(CMember *));
    208204    iMemberNum=pInheritsClass->iMemberNum;
    209     for(i3=0;i3<pInheritsClass->iMemberNum;i3++){
     205    for(int i3=0;i3<pInheritsClass->iMemberNum;i3++){
    210206        ppobj_Member[i3]=new CMember( *pInheritsClass->ppobj_Member[i3] );
    211207
     
    315311{
    316312    for( int i=(int)methods.size()-1; i>=0; i-- ){
    317         if( pUserProc == methods[i]->pUserProc ) return methods[i];
     313        if( pUserProc == methods[i]->pUserProc ){
     314            return methods[i];
     315        }
    318316    }
    319317    return NULL;
     
    13501348
    13511349
    1352                         if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->IsObject()||
    1353                             pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->IsStruct()){
     1350                        if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->IsStruct()){
    13541351                            if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->GetClass().ppobj_Member==0){
    13551352                                //参照先が読み取られていないとき
     
    13591356
    13601357
    1361                         if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->IsObject()){
     1358                        if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->IsStruct()){
    13621359                            //循環参照のチェック
    13631360                            pobj_LoopRefCheck->add(pobj_c->name);
     
    14221419    delete pobj_LoopRefCheck;
    14231420    pobj_LoopRefCheck=0;
    1424 }
    1425 
    1426 void CDBClass::GenerateRuntimeTypeInfo(){
     1421
     1422    // イテレータ用のデータを作る
     1423    pobj_DBClass->Iterator_Init();
     1424}
     1425
     1426void CDBClass::Compile_System_InitializeUserTypes(){
     1427
     1428    ////////////////////////////////////////////////////////////////////
     1429    // クラス登録
     1430    ////////////////////////////////////////////////////////////////////
     1431
     1432    // イテレータをリセット
     1433    Iterator_Reset();
     1434
     1435    while( Iterator_HasNext() ){
     1436        CClass *pClass = Iterator_GetNext();
     1437
     1438        char temporary[VN_SIZE];
     1439        sprintf( temporary
     1440            , "Add(%c%c_System_TypeForClass(\"%s\",\"%s\"))"
     1441            , 1
     1442            , ESC_NEW
     1443            , ""                // 名前空間 (TODO: 実装)
     1444            , pClass->name      // クラス名
     1445            );
     1446
     1447        // コンパイル
     1448        ChangeOpcode( temporary );
     1449
     1450        // ネイティブコードバッファの再確保
     1451        ReallocNativeCodeBuffer();
     1452    }
     1453
     1454
     1455    ////////////////////////////////////////////////////////////////////
     1456    // 継承関係登録
     1457    ////////////////////////////////////////////////////////////////////
     1458    // TODO: 未完成
     1459    /*
     1460
     1461    // イテレータをリセット
     1462    Iterator_Reset();
     1463
     1464    while( Iterator_HasNext() ){
     1465        CClass *pClass = Iterator_GetNext();
     1466
     1467        sprintf( genBuffer + length
     1468            , "obj.Search( \"%s\" ).SetBaseType( Search( \"%s\" ) ):"
     1469            , ""                // クラス名
     1470            , pClass->name      // クラス名
     1471            );
     1472        length += lstrlen( genBuffer + length );
     1473
     1474        while( length + 8192 > max ){
     1475            max += 8192;
     1476            genBuffer = (char *)realloc( genBuffer, max );
     1477        }
     1478    }*/
    14271479}
    14281480
     
    14751527//////////////////////
    14761528
    1477 void CDBClass::Iterator_Reset(void){
     1529void CDBClass::Iterator_Init(void){
    14781530    if(ppobj_IteClass) HeapDefaultFree(ppobj_IteClass);
    14791531
     
    14981550    }
    14991551}
     1552void CDBClass::Iterator_Reset(void){
     1553    iIteNextNum = 0;
     1554}
    15001555BOOL CDBClass::Iterator_HasNext(void){
    15011556    if(iIteNextNum<iIteMaxNum) return 1;
  • BasicCompiler_Common/Class.h

    r87 r89  
    217217    void GetClass_recur(const char *lpszInheritsClass);
    218218    void GetAllClassInfo(void);
    219     void GenerateRuntimeTypeInfo();
     219    void Compile_System_InitializeUserTypes();
    220220
    221221
     
    252252    int iIteNextNum;
    253253public:
     254    void Iterator_Init(void);
    254255    void Iterator_Reset(void);
    255256    BOOL Iterator_HasNext(void);
  • BasicCompiler_Common/Compile.cpp

    r78 r89  
    77#endif
    88
    9 int obp,obp_AllocSize;
    10 int GlobalOpBufferSize;
    11 char *OpBuffer;
    12 
    139//ラベルアドレス
    1410LABEL *pLabelNames;
     
    3632//With情報
    3733WITHINFO WithInfo;
     34
     35
     36int obp,obp_AllocSize;
     37int GlobalOpBufferSize;
     38char *OpBuffer;
     39void ReallocNativeCodeBuffer(){
     40    if(obp_AllocSize<obp+8192){
     41        obp_AllocSize+=8192;
     42        OpBuffer=(char *)HeapReAlloc(hHeap,0,OpBuffer,obp_AllocSize); //matea
     43    }
     44}
    3845
    3946
     
    428435                OpcodeDim(Command+2,0);
    429436
    430             if(obp_AllocSize<obp+8192){
    431                 obp_AllocSize+=8192;
    432                 OpBuffer=(char *)HeapReAlloc(hHeap,0,OpBuffer,obp_AllocSize);
    433             }
     437            // ネイティブコードバッファの再確保
     438            ReallocNativeCodeBuffer();
    434439
    435440            if(basbuf[cp]=='\0') break;
  • BasicCompiler_Common/Object.cpp

    r75 r89  
    6464
    6565            //ネイティブコードバッファの再確保
    66             extern int obp_AllocSize;
    67             if(obp_AllocSize<obp+8192){
    68                 obp_AllocSize+=8192;
    69                 OpBuffer=(char *)HeapReAlloc(hHeap,0,OpBuffer,obp_AllocSize); //matea
    70             }
     66            ReallocNativeCodeBuffer();
    7167        }
    7268    }
  • BasicCompiler_Common/Procedure.h

    r78 r89  
    155155        return *pParentClass;
    156156    }
     157    bool HasParentClass() const
     158    {
     159        return ( pParentClass != NULL );
     160    }
    157161    void SetMethod( CMethod *pMethod ){
    158162        this->pMethod = pMethod;
  • BasicCompiler_Common/common.h

    r88 r89  
    496496
    497497//Compile.cpp
     498void ReallocNativeCodeBuffer();
    498499void GetIdentifierToken( char *token, const char *source, int &pos );
    499500int JumpStatement(const char *source, int &pos);
  • BasicCompiler_Common/include/Source.h

    r88 r89  
    2929class BasicSource : public Text
    3030{
     31    static const string generateDirectiveName;
     32
    3133    void Realloc( int newLength ){
    3234        buffer = (char *)realloc( buffer, newLength + 255 );
  • BasicCompiler_Common/src/Source.cpp

    r88 r89  
    44#include <windows.h>
    55
     6
     7const string BasicSource::generateDirectiveName = "#generate";
    68
    79
     
    409411
    410412void BasicSource::ChangeReturnLineChar(){
     413    int i,i2;
     414
    411415#ifdef _DEBUG
    412416    //改行コードの整合性チェック
    413     for( int i=0; ; i++ ){
     417    for( i=0; ; i++ ){
    414418        if( buffer[i] == '\0' ){
    415419            break;
     
    433437
    434438    //改行コードのCRLFをLFに変換
    435     int i,i2;
    436439    for(i=0,i2=0;;i++,i2++){
    437440        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i++;
     
    551554        if(i>LastFileByte[layer]){
    552555            HeapDefaultFree(LayerDir[layer]);
     556            LayerDir[layer]=0;
    553557            layer--;
    554558        }
     
    842846}
    843847
    844 bool BasicSource::Generate( const string &genName, const char *buffer ){
    845     return true;
     848bool BasicSource::Generate( const string &genName, const char *genBuffer ){
     849    const int genBufferLength = lstrlen( genBuffer );
     850
     851#ifdef _DEBUG
     852    // 挿入ソースに改行コードが含まれていないかを検査する
     853    for( int i=0; genBuffer[i] ; i++ ){
     854        if( genBuffer[i] == '\n' ){
     855            SetError();
     856            break;
     857        }
     858    }
     859#endif
     860
     861    bool isFound = false;
     862
     863    for( int i=0; ; i++ ){
     864        if( i == 0 || buffer[i] == '\n' ){
     865            if( buffer[i] == '\n' ){
     866                i++;
     867            }
     868            while( IsBlank( buffer[i] ) ){
     869                i++;
     870            }
     871
     872            int startIndex = i;
     873
     874            if( memicmp( buffer + i, generateDirectiveName.c_str(), generateDirectiveName.size() ) == 0 ){
     875                i += (int)generateDirectiveName.size();
     876                while( IsBlank( buffer[i] ) ){
     877                    i++;
     878                }
     879
     880                char temporary[VN_SIZE];
     881                for( int i2=0; ; i++, i2++ ){
     882                    if( buffer[i] == '\n' ){
     883                        temporary[i2] = 0;
     884                        break;
     885                    }
     886                    temporary[i2] = buffer[i];
     887                }
     888                if( genName == temporary ){
     889                    // 一致
     890
     891                    int endIndex = i;
     892
     893                    int lengthOffset = genBufferLength - ( endIndex - startIndex );
     894
     895                    Realloc( length + lengthOffset );
     896                    SlideString( buffer + endIndex, lengthOffset );
     897                    memcpy( buffer + startIndex, genBuffer, genBufferLength );
     898
     899                    isFound = true;
     900
     901                    break;
     902                }
     903            }
     904        }
     905    }
     906
     907    return isFound;
    846908}
    847909
Note: See TracChangeset for help on using the changeset viewer.