Changeset 93 in dev for BasicCompiler32/NumOpe.cpp


Ignore:
Timestamp:
Apr 11, 2007, 3:23:14 AM (17 years ago)
Author:
dai_9181
Message:

"a=[10,20,30]" などのように、リテラルバイナリデータを指定できるようにした。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler32/NumOpe.cpp

    r92 r93  
    103103            return false;
    104104        }
     105
     106        return true;
     107    }
     108
     109    if( !baseType.IsNull() && expression[0] == '[' ){
     110        // リテラル配列の場合
     111
     112        if( !baseType.IsPointer() ){
     113            SetError(1,NULL,cp);
     114            return false;
     115        }
     116        Type tempBaseType( baseType );
     117        tempBaseType.PtrLevelDown();
     118
     119        char *buffer = (char *)malloc( lstrlen( expression ) + 1 );
     120        lstrcpy( buffer, expression );
     121        RemoveStringBracket( buffer );
     122
     123        void *binary = malloc( 1 );
     124        int num = 0;
     125
     126        i = 0;
     127        while( buffer[i] ){
     128            i = GetOneParameter( buffer, i, temporary );
     129            if( buffer[i] == ',' ){
     130                i++;
     131            }
     132
     133            Type resultType;
     134            _int64 i64data;
     135            if( !StaticCalculation( true, temporary, tempBaseType.GetBasicType(), &i64data, resultType ) ){
     136                return false;
     137            }
     138            if( !resultType.IsWhole() ){
     139                // TODO: 実数に未対応
     140                SetError();
     141                return false;
     142            }
     143
     144            binary = realloc( binary, ( num + 1 ) * tempBaseType.GetSize() );
     145            memcpy( (char *)binary + (num * tempBaseType.GetSize()), &i64data, tempBaseType.GetSize() );
     146            num++;
     147        }
     148
     149        i2 = dataTable.AddBinary( binary, num * tempBaseType.GetSize() );
     150
     151        //mov eax,i2
     152        op_mov_RV(REG_EAX,i2);
     153        obp-=sizeof(long);
     154        pobj_DataTableSchedule->add();
     155        obp+=sizeof(long);
     156
     157        free( buffer );
     158
     159        resultType = baseType;
     160
     161        //push eax
     162        op_push( REG_EAX );
    105163
    106164        return true;
Note: See TracChangeset for help on using the changeset viewer.