Object.st
changeset 8913 b9498d27a554
parent 8909 485a8e3153e0
child 8930 edd42af66c0a
equal deleted inserted replaced
8912:3d1947a79cf3 8913:b9498d27a554
   730                  */
   730                  */
   731                 if ((unsigned)indx < nbytes) {
   731                 if ((unsigned)indx < nbytes) {
   732                     unsigned char *cp;
   732                     unsigned char *cp;
   733 
   733 
   734                     cp = (unsigned char *)pFirst + indx;
   734                     cp = (unsigned char *)pFirst + indx;
   735                     RETURN ( __MKSMALLINT( (INT)(*cp & 0xFF)) );
   735                     RETURN ( __mkSmallInteger( (*cp & 0xFF)) );
   736                 }
   736                 }
   737                 break;
   737                 break;
   738 
   738 
   739             case __MASKSMALLINT(FLOATARRAY):
   739             case __MASKSMALLINT(FLOATARRAY):
   740                 /*
   740                 /*
   793                  */
   793                  */
   794                 if ((unsigned)indx < (nbytes>>1)) {
   794                 if ((unsigned)indx < (nbytes>>1)) {
   795                     unsigned short *sp;
   795                     unsigned short *sp;
   796 
   796 
   797                     sp = (unsigned short *)(pFirst + (indx<<1));
   797                     sp = (unsigned short *)(pFirst + (indx<<1));
   798                     RETURN ( __MKSMALLINT( (INT)(*sp & 0xFFFF)) );
   798                     RETURN ( __mkSmallInteger( (*sp & 0xFFFF)) );
   799                 }
   799                 }
   800                 break;
   800                 break;
   801 
   801 
   802             case __MASKSMALLINT(SWORDARRAY):
   802             case __MASKSMALLINT(SWORDARRAY):
   803                 /*
   803                 /*
   808                  */
   808                  */
   809                 if ((unsigned)indx < (nbytes>>1)) {
   809                 if ((unsigned)indx < (nbytes>>1)) {
   810                     short *ssp;
   810                     short *ssp;
   811 
   811 
   812                     ssp = (short *)(pFirst + (indx<<1));
   812                     ssp = (short *)(pFirst + (indx<<1));
   813                     RETURN ( __MKSMALLINT( (INT)(*ssp) ));
   813                     RETURN ( __mkSmallInteger( (*ssp) ));
   814                 }
   814                 }
   815                 break;
   815                 break;
   816 
   816 
   817             case __MASKSMALLINT(LONGARRAY):
   817             case __MASKSMALLINT(LONGARRAY):
   818                 /*
   818                 /*
   828                     lp = (unsigned int32 *)(pFirst + (indx<<2));
   828                     lp = (unsigned int32 *)(pFirst + (indx<<2));
   829                     ul = *lp;
   829                     ul = *lp;
   830 #if __POINTER_SIZE__ == 8
   830 #if __POINTER_SIZE__ == 8
   831                     {
   831                     {
   832                         unsigned  INT ull = (unsigned INT)ul;
   832                         unsigned  INT ull = (unsigned INT)ul;
   833                         RETURN ( __MKSMALLINT(ull) );
   833                         RETURN ( __mkSmallInteger(ull) );
   834                     }
   834                     }
   835 #else
   835 #else
   836                     if (ul <= _MAX_INT) {
   836                     if (ul <= _MAX_INT) {
   837                         RETURN ( __MKSMALLINT(ul) );
   837                         RETURN ( __mkSmallInteger(ul) );
   838                     }
   838                     }
   839                     RETURN ( __MKULARGEINT(ul) );
   839                     RETURN ( __MKULARGEINT(ul) );
   840 #endif
   840 #endif
   841                 }
   841                 }
   842                 break;
   842                 break;
   855                     slp = (int32 *)(pFirst + (indx<<2));
   855                     slp = (int32 *)(pFirst + (indx<<2));
   856                     l = *slp;
   856                     l = *slp;
   857 #if __POINTER_SIZE__ == 8
   857 #if __POINTER_SIZE__ == 8
   858                     {
   858                     {
   859                         INT ll = (INT)l;
   859                         INT ll = (INT)l;
   860                         RETURN ( __MKSMALLINT(ll) );
   860                         RETURN ( __mkSmallInteger(ll) );
   861                     }
   861                     }
   862 #else
   862 #else
   863                     if (__ISVALIDINTEGER(l)) {
   863                     if (__ISVALIDINTEGER(l)) {
   864                         RETURN ( __MKSMALLINT(l) );
   864                         RETURN ( __mkSmallInteger(l) );
   865                     }
   865                     }
   866                     RETURN ( __MKLARGEINT(l) );
   866                     RETURN ( __MKLARGEINT(l) );
   867 #endif
   867 #endif
   868                 }
   868                 }
   869                 break;
   869                 break;
   888                     INT *slp, ll;
   888                     INT *slp, ll;
   889 
   889 
   890                     slp = (INT *)(pFirst + (indx<<3));
   890                     slp = (INT *)(pFirst + (indx<<3));
   891                     ll = *slp;
   891                     ll = *slp;
   892                     if (__ISVALIDINTEGER(ll)) {
   892                     if (__ISVALIDINTEGER(ll)) {
   893                         RETURN ( __MKSMALLINT(ll) );
   893                         RETURN ( __mkSmallInteger(ll) );
   894                     }
   894                     }
   895                     RETURN ( __MKLARGEINT(ll) );
   895                     RETURN ( __MKLARGEINT(ll) );
   896 #else
   896 #else
   897                     __int64__ *llp;
   897                     __int64__ *llp;
   898 
   898 
   922                     unsigned INT *ulp, ul;
   922                     unsigned INT *ulp, ul;
   923 
   923 
   924                     ulp = (unsigned INT *)(pFirst + (indx<<3));
   924                     ulp = (unsigned INT *)(pFirst + (indx<<3));
   925                     ul = *ulp;
   925                     ul = *ulp;
   926                     if (ul <= _MAX_INT) {
   926                     if (ul <= _MAX_INT) {
   927                         RETURN ( __MKSMALLINT(ul) );
   927                         RETURN ( __mkSmallInteger(ul) );
   928                     }
   928                     }
   929                     RETURN ( __MKULARGEINT(ul) );
   929                     RETURN ( __MKULARGEINT(ul) );
   930 #else
   930 #else
   931                     __uint64__ *llp;
   931                     __uint64__ *llp;
   932 
   932 
  1106             case __MASKSMALLINT(LONGARRAY):
  1106             case __MASKSMALLINT(LONGARRAY):
  1107                 if ((unsigned)indx < (nbytes>>2)) {
  1107                 if ((unsigned)indx < (nbytes>>2)) {
  1108                     unsigned int32 *lp;
  1108                     unsigned int32 *lp;
  1109 
  1109 
  1110                     lp = (unsigned int32 *)(pFirst + (indx<<2));
  1110                     lp = (unsigned int32 *)(pFirst + (indx<<2));
  1111                     if (anObject == __MKSMALLINT(0)) {
  1111                     if (anObject == __mkSmallInteger(0)) {
  1112                         *lp = 0;
  1112                         *lp = 0;
  1113                         RETURN ( anObject );
  1113                         RETURN ( anObject );
  1114                     }
  1114                     }
  1115                     u = __longIntVal(anObject);
  1115                     u = __longIntVal(anObject);
  1116                     /*
  1116                     /*
  1137                     __int64__ ll;
  1137                     __int64__ ll;
  1138                     __int64__ *sllp;
  1138                     __int64__ *sllp;
  1139 
  1139 
  1140                     sllp = (__int64__ *)(pFirst + (indx<<3));
  1140                     sllp = (__int64__ *)(pFirst + (indx<<3));
  1141 
  1141 
  1142                     if (anObject == __MKSMALLINT(0)) {
  1142                     if (anObject == __mkSmallInteger(0)) {
  1143                         ll.lo = ll.hi = 0;
  1143                         ll.lo = ll.hi = 0;
  1144                         *sllp = ll;
  1144                         *sllp = ll;
  1145                         RETURN ( anObject );
  1145                         RETURN ( anObject );
  1146                     }
  1146                     }
  1147                     if (__signedLong64IntVal(anObject, &ll)) {
  1147                     if (__signedLong64IntVal(anObject, &ll)) {
  1163                 if ((unsigned)indx < (nbytes>>3)) {
  1163                 if ((unsigned)indx < (nbytes>>3)) {
  1164                     __uint64__ ll;
  1164                     __uint64__ ll;
  1165                     __uint64__ *llp;
  1165                     __uint64__ *llp;
  1166 
  1166 
  1167                     llp = (__uint64__ *)(pFirst + (indx<<3));
  1167                     llp = (__uint64__ *)(pFirst + (indx<<3));
  1168                     if (anObject == __MKSMALLINT(0)) {
  1168                     if (anObject == __mkSmallInteger(0)) {
  1169                         ll.lo = ll.hi = 0;
  1169                         ll.lo = ll.hi = 0;
  1170                         *llp = ll;
  1170                         *llp = ll;
  1171                         RETURN ( anObject );
  1171                         RETURN ( anObject );
  1172                     }
  1172                     }
  1173                     if (__unsignedLong64IntVal(anObject, &ll)) {
  1173                     if (__unsignedLong64IntVal(anObject, &ll)) {
  1258                 case __MASKSMALLINT(LONGARRAY):
  1258                 case __MASKSMALLINT(LONGARRAY):
  1259                 case __MASKSMALLINT(SWORDARRAY):
  1259                 case __MASKSMALLINT(SWORDARRAY):
  1260                 case __MASKSMALLINT(SLONGARRAY):
  1260                 case __MASKSMALLINT(SLONGARRAY):
  1261                 case __MASKSMALLINT(FLOATARRAY):
  1261                 case __MASKSMALLINT(FLOATARRAY):
  1262                     if ((unsigned)indx < (unsigned)nIndex) {
  1262                     if ((unsigned)indx < (unsigned)nIndex) {
  1263                         RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) );
  1263                         RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) );
  1264                     }
  1264                     }
  1265                     break;
  1265                     break;
  1266 
  1266 
  1267                 case __MASKSMALLINT(LONGLONGARRAY):
  1267                 case __MASKSMALLINT(LONGLONGARRAY):
  1268                 case __MASKSMALLINT(SLONGLONGARRAY):
  1268                 case __MASKSMALLINT(SLONGLONGARRAY):
  1273                         pFirst += delta;
  1273                         pFirst += delta;
  1274                         nIndex -= delta;
  1274                         nIndex -= delta;
  1275                     }
  1275                     }
  1276 #endif
  1276 #endif
  1277                     if ((unsigned)indx < (unsigned)nIndex) {
  1277                     if ((unsigned)indx < (unsigned)nIndex) {
  1278                         RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) );
  1278                         RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) );
  1279                     }
  1279                     }
  1280                     break;
  1280                     break;
  1281             }
  1281             }
  1282         }
  1282         }
  1283     }
  1283     }
  2151          * make it as large as possible; since most hashers use the returned
  2151          * make it as large as possible; since most hashers use the returned
  2152          * key and take it modulo some prime number, this will allow for
  2152          * key and take it modulo some prime number, this will allow for
  2153          * better distribution (i.e. bigger empty spaces) in hashed collection.
  2153          * better distribution (i.e. bigger empty spaces) in hashed collection.
  2154          */
  2154          */
  2155         hash = __MAKE_HASH__(hash);
  2155         hash = __MAKE_HASH__(hash);
  2156         RETURN ( __MKSMALLINT(hash) );
  2156         RETURN ( __mkSmallInteger(hash) );
  2157     }
  2157     }
  2158 %}.
  2158 %}.
  2159     ^ 0 "never reached, since redefined in UndefinedObject and SmallInteger"
  2159     ^ 0 "never reached, since redefined in UndefinedObject and SmallInteger"
  2160 !
  2160 !
  2161 
  2161 
  2217 
  2217 
  2218         while ((hash & 0x20000000) == 0) {
  2218         while ((hash & 0x20000000) == 0) {
  2219             hash <<= 1;
  2219             hash <<= 1;
  2220         }
  2220         }
  2221 
  2221 
  2222         RETURN ( __MKSMALLINT(hash) );
  2222         RETURN ( __mkSmallInteger(hash) );
  2223     }
  2223     }
  2224 %}.
  2224 %}.
  2225     "never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage"
  2225     "never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage"
  2226     ^ self identityHash
  2226     ^ self identityHash
  2227 !
  2227 !
  5307             if (!__isSmallInteger(numberOfArgs)) 
  5307             if (!__isSmallInteger(numberOfArgs)) 
  5308                 goto bad;
  5308                 goto bad;
  5309             nargs = __intVal(numberOfArgs);
  5309             nargs = __intVal(numberOfArgs);
  5310             argP = (OBJ *)(&a1);
  5310             argP = (OBJ *)(&a1);
  5311             for (i=1; i <= nargs; i++) {
  5311             for (i=1; i <= nargs; i++) {
  5312                 *argP++ = __AT_(argArray, __MKSMALLINT((INT)i));
  5312                 *argP++ = __AT_(argArray, __mkSmallInteger(i));
  5313             }
  5313             }
  5314             argP = (OBJ *)(&a1);
  5314             argP = (OBJ *)(&a1);
  5315         } else {
  5315         } else {
  5316             nargs = 0;
  5316             nargs = 0;
  5317         }
  5317         }
  5789             if (!__isSmallInteger(numberOfArgs)) 
  5789             if (!__isSmallInteger(numberOfArgs)) 
  5790                 goto bad;
  5790                 goto bad;
  5791             nargs = __intVal(numberOfArgs);
  5791             nargs = __intVal(numberOfArgs);
  5792             argP = (OBJ *)(&a1);
  5792             argP = (OBJ *)(&a1);
  5793             for (i=1; i <= nargs; i++) {
  5793             for (i=1; i <= nargs; i++) {
  5794                 *argP++ = __AT_(argArray, __MKSMALLINT((INT)i));
  5794                 *argP++ = __AT_(argArray, __mkSmallInteger(i));
  5795             }
  5795             }
  5796             argP = (OBJ *)(&a1);
  5796             argP = (OBJ *)(&a1);
  5797         } else {
  5797         } else {
  5798             nargs = 0;
  5798             nargs = 0;
  5799         }
  5799         }
  7039 
  7039 
  7040     switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
  7040     switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
  7041         case __MASKSMALLINT(POINTERARRAY):
  7041         case __MASKSMALLINT(POINTERARRAY):
  7042         case __MASKSMALLINT(WKPOINTERARRAY):
  7042         case __MASKSMALLINT(WKPOINTERARRAY):
  7043             nbytes -= nInstBytes;
  7043             nbytes -= nInstBytes;
  7044             RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) );
  7044             RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) );
  7045 
  7045 
  7046         case __MASKSMALLINT(BYTEARRAY):
  7046         case __MASKSMALLINT(BYTEARRAY):
  7047             nbytes -= nInstBytes;
  7047             nbytes -= nInstBytes;
  7048             RETURN ( __MKSMALLINT(nbytes / sizeof(char)) );
  7048             RETURN ( __mkSmallInteger(nbytes / sizeof(char)) );
  7049 
  7049 
  7050         case __MASKSMALLINT(FLOATARRAY):
  7050         case __MASKSMALLINT(FLOATARRAY):
  7051             nbytes -= nInstBytes;
  7051             nbytes -= nInstBytes;
  7052             RETURN ( __MKSMALLINT(nbytes / sizeof(float)) );
  7052             RETURN ( __mkSmallInteger(nbytes / sizeof(float)) );
  7053 
  7053 
  7054         case __MASKSMALLINT(DOUBLEARRAY):
  7054         case __MASKSMALLINT(DOUBLEARRAY):
  7055 #ifdef __NEED_DOUBLE_ALIGN
  7055 #ifdef __NEED_DOUBLE_ALIGN
  7056             nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
  7056             nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
  7057 #endif
  7057 #endif
  7058             nbytes -= nInstBytes;
  7058             nbytes -= nInstBytes;
  7059             RETURN ( __MKSMALLINT(nbytes / sizeof(double)) );
  7059             RETURN ( __mkSmallInteger(nbytes / sizeof(double)) );
  7060 
  7060 
  7061         case __MASKSMALLINT(WORDARRAY):
  7061         case __MASKSMALLINT(WORDARRAY):
  7062         case __MASKSMALLINT(SWORDARRAY):
  7062         case __MASKSMALLINT(SWORDARRAY):
  7063             nbytes -= nInstBytes;
  7063             nbytes -= nInstBytes;
  7064             RETURN ( __MKSMALLINT(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */
  7064             RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */
  7065 
  7065 
  7066         case __MASKSMALLINT(LONGARRAY):
  7066         case __MASKSMALLINT(LONGARRAY):
  7067         case __MASKSMALLINT(SLONGARRAY):
  7067         case __MASKSMALLINT(SLONGARRAY):
  7068             nbytes -= nInstBytes;
  7068             nbytes -= nInstBytes;
  7069             RETURN ( __MKSMALLINT(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */
  7069             RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */
  7070 
  7070 
  7071         case __MASKSMALLINT(LONGLONGARRAY):
  7071         case __MASKSMALLINT(LONGLONGARRAY):
  7072         case __MASKSMALLINT(SLONGLONGARRAY):
  7072         case __MASKSMALLINT(SLONGLONGARRAY):
  7073 #ifdef __NEED_LONGLONG_ALIGN
  7073 #ifdef __NEED_LONGLONG_ALIGN
  7074             nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
  7074             nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
  7075 #endif
  7075 #endif
  7076             nbytes -= nInstBytes;
  7076             nbytes -= nInstBytes;
  7077             RETURN ( __MKSMALLINT(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */
  7077             RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */
  7078     }
  7078     }
  7079 %}.
  7079 %}.
  7080     ^ 0
  7080     ^ 0
  7081 !
  7081 !
  7082 
  7082 
  9237 ! !
  9237 ! !
  9238 
  9238 
  9239 !Object class methodsFor:'documentation'!
  9239 !Object class methodsFor:'documentation'!
  9240 
  9240 
  9241 version
  9241 version
  9242     ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.534 2005-07-08 15:03:44 cg Exp $'
  9242     ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.535 2005-07-08 17:15:02 cg Exp $'
  9243 ! !
  9243 ! !
  9244 
  9244 
  9245 Object initialize!
  9245 Object initialize!