CompiledCodeObjectSection.st
changeset 11 cfe5c9d79fbc
parent 10 588414eaacff
child 17 54798ae989cc
equal deleted inserted replaced
10:588414eaacff 11:cfe5c9d79fbc
    27  * includes, defines, structure definitions
    27  * includes, defines, structure definitions
    28  * and typedefs come here.
    28  * and typedefs come here.
    29  */
    29  */
    30 #include "../librun/mcompiler.h"
    30 #include "../librun/mcompiler.h"
    31 
    31 
       
    32 #ifdef __SUPPORT_DIRECT_ILC
       
    33 #  define ILC struct inlineCacheForDirectCall
       
    34 #else
       
    35 #  define ILC struct inlineCache
       
    36 #endif                
       
    37 
       
    38 
    32 %}
    39 %}
    33 ! !
    40 ! !
    34 
    41 
    35 !CompiledCodeObjectSection class methodsFor:'documentation'!
    42 !CompiledCodeObjectSection class methodsFor:'documentation'!
    36 
    43 
    47  hereby transferred.
    54  hereby transferred.
    48 "
    55 "
    49 ! !
    56 ! !
    50 
    57 
    51 !CompiledCodeObjectSection methodsFor:'accessing'!
    58 !CompiledCodeObjectSection methodsFor:'accessing'!
       
    59 
       
    60 at: index
       
    61     | failureReason |
       
    62 %{
       
    63     INT _index;
       
    64     INT _size;
       
    65     INT _format;
       
    66 
       
    67     if ( ! __isSmallInteger( index ) ) {
       
    68         failureReason = @symbol(BadArg1);
       
    69         goto error;
       
    70     }
       
    71     _index = __intVal(index) - 1;
       
    72     
       
    73     if ( ! __isSmallInteger( __INST(size) ) ) {
       
    74         failureReason = @symbol(BadSize);
       
    75         goto error;    
       
    76     }
       
    77     _size = __intVal(__INST(size));
       
    78     
       
    79     if ( ! __isSmallInteger( __INST(format) ) ) {
       
    80         failureReason = @symbol(BadFormat);
       
    81         goto error;    
       
    82     }
       
    83     _format = __intVal(__INST(format));
       
    84 
       
    85     switch ( __intVal( __INST(format) ) ) {
       
    86         case SectionFormatOBJVector:
       
    87             {
       
    88                 if ( (_index < 0) || ( _index >= (_size / sizeof(OBJ)) ) )  {
       
    89                     failureReason = @symbol(BadArg1OutOfBounds);
       
    90                     goto error;
       
    91                 }
       
    92                 OBJ *vector = (OBJ*)(__externalAddressVal(self));                
       
    93                 RETURN ( vector[_index] );
       
    94             }
       
    95             break;
       
    96         case SectionFormatINTVector:
       
    97             {
       
    98                 if ( (_index < 0) || ( _index >= (_size / sizeof(INT)) ) )  {
       
    99                     failureReason = @symbol(BadArg1OutOfBounds);
       
   100                     goto error;
       
   101                 }
       
   102                 INT *vector = (INT*)(__externalAddressVal(self));    
       
   103                 if (__ISVALIDINTEGER( vector[_index] ) ) {
       
   104                     RETURN ( __mkSmallInteger( vector[_index] ) );
       
   105                 } else {
       
   106                     RETURN ( __MKLARGEINT( vector[_index] ) );                          
       
   107                 }
       
   108             }
       
   109             break;
       
   110         case SectionFormatILCVector:
       
   111             {
       
   112                 if ( (_index < 0) || ( _index >= (_size / sizeof(ILC)) ) )  {
       
   113                     failureReason = @symbol(BadArg1OutOfBounds);
       
   114                     goto error;
       
   115                 }
       
   116                 ILC *vector = (ILC*)(__externalAddressVal(self));                
       
   117                 failureReason = @symbol(NotYetSupported);
       
   118                 goto error;
       
   119             }
       
   120             break;
       
   121         case SectionFormatBytes:
       
   122         case SectionFormatText:
       
   123             {
       
   124                 if ( (_index < 0) || ( _index >= _size ) )  {
       
   125                     failureReason = @symbol(BadArg1OutOfBounds);
       
   126                    goto error;
       
   127                 }
       
   128                 char *vector = (char*)(__externalAddressVal(self));                
       
   129                 RETURN ( __mkSmallInteger( vector[_index] ) );
       
   130             }
       
   131             break; 
       
   132     }
       
   133     error:;
       
   134 %}.
       
   135     ^ self primitiveFailed: failureReason
       
   136 
       
   137 !
       
   138 
       
   139 at: index put: value
       
   140     | failureReason |
       
   141 %{
       
   142     INT _index;
       
   143     INT _size;
       
   144     INT _format;
       
   145 
       
   146     if ( ! __isSmallInteger( index ) ) {
       
   147         failureReason = @symbol(BadArg1);
       
   148         goto error;
       
   149     }
       
   150     _index = __intVal(index) - 1;
       
   151     
       
   152     if ( ! __isSmallInteger( __INST(size) ) ) {
       
   153         failureReason = @symbol(BadSize);
       
   154         goto error;    
       
   155     }
       
   156     _size = __intVal(__INST(size));
       
   157     
       
   158     if ( ! __isSmallInteger( __INST(format) ) ) {
       
   159         failureReason = @symbol(BadFormat);
       
   160         goto error;    
       
   161     }
       
   162     _format = __intVal(__INST(format));
       
   163 
       
   164     switch ( __intVal( __INST(format) ) ) {
       
   165         case SectionFormatOBJVector:
       
   166             {
       
   167                 if ( (_index < 0) || ( _index >= (_size / sizeof(OBJ)) ) )  {
       
   168                     failureReason = @symbol(BadArg1OutOfBounds);
       
   169                     goto error;
       
   170                 }
       
   171                 OBJ *vector = (OBJ*)(__externalAddressVal(self));                
       
   172                 vector[_index] = value;
       
   173                 RETURN ( value );
       
   174             }
       
   175             break;
       
   176         case SectionFormatINTVector:
       
   177             {
       
   178                 if ( (_index < 0) || ( _index >= (_size / sizeof(INT)) ) )  {
       
   179                     failureReason = @symbol(BadArg1OutOfBounds);
       
   180                     goto error;
       
   181                 }
       
   182                 INT *vector = (INT*)(__externalAddressVal(self));    
       
   183                 INT _value;
       
   184                 if (__isSmallInteger(value)) {
       
   185                     _value = __intVal(value);
       
   186                     vector[_index] = _value;
       
   187                     RETURN ( value );
       
   188                 } else {
       
   189                     _value = __signedLongIntVal(value);
       
   190                     if (_value != 0) {
       
   191                         vector[_index] = _value;
       
   192                         RETURN ( value );
       
   193                     }
       
   194                 }
       
   195                 failureReason = @symbol(BadArg2);
       
   196                 goto error;
       
   197             }
       
   198             break;
       
   199         case SectionFormatILCVector:
       
   200             {
       
   201                 failureReason = @symbol(NotSupported);
       
   202                 goto error;
       
   203             }
       
   204             break;
       
   205         case SectionFormatBytes:
       
   206         case SectionFormatText:
       
   207             {
       
   208                 if ( (_index < 0) || ( _index >= _size ) )  {
       
   209                     failureReason = @symbol(BadArg1OutOfBounds);
       
   210                    goto error;
       
   211                 }
       
   212                 char *vector = (char*)(__externalAddressVal(self));                
       
   213                 if (__isSmallInteger(value)) {
       
   214                     INT _value = __intVal(value);
       
   215                     if ( (_value >= 0) && (_value <= 255) ) {
       
   216                         vector[_index] = (char)(_value & 0xFF);
       
   217                         RETURN ( value );
       
   218                     }
       
   219                 }
       
   220                 failureReason = @symbol(BadArg2);
       
   221                 goto error;
       
   222             }
       
   223             break; 
       
   224     }
       
   225     error:;
       
   226 %}.
       
   227     ^ self primitiveFailed: failureReason
       
   228 
       
   229 !
    52 
   230 
    53 format
   231 format
    54     ^ format
   232     ^ format
    55 !
   233 !
    56 
   234 
   139         case SectionFormatOBJVector:
   317         case SectionFormatOBJVector:
   140             RETURN ( __MKSMALLINT( sz / sizeof(OBJ) ) );
   318             RETURN ( __MKSMALLINT( sz / sizeof(OBJ) ) );
   141         case SectionFormatINTVector:
   319         case SectionFormatINTVector:
   142             RETURN ( __MKSMALLINT( sz / sizeof(INT) ) );
   320             RETURN ( __MKSMALLINT( sz / sizeof(INT) ) );
   143         case SectionFormatILCVector:
   321         case SectionFormatILCVector:
   144 #           ifdef __SUPPORT_DIRECT_ILC
   322             RETURN ( __MKSMALLINT( sz / sizeof(ILC) ) );
   145                 RETURN ( __MKSMALLINT( sz / sizeof(struct inlineCacheForDirectCall)  ) );
       
   146 #           else
       
   147                 RETURN ( __MKSMALLINT( sz / sizeof(struct inlineCache) ) );
       
   148 #           endif
       
   149         default:
   323         default:
   150             RETURN ( __MKSMALLINT( sz ) );        
   324             RETURN ( __MKSMALLINT( sz ) );        
   151         }  
   325         }  
   152     }
   326     }
   153 %}.    
   327 %}.