Object.st
branchjv
changeset 19478 1f5aa87f6170
parent 19431 3e697e4bcbf5
parent 19451 536333350448
child 19559 d35a89d5c0ec
equal deleted inserted replaced
19477:af82888ceb72 19478:1f5aa87f6170
   497 !Object class methodsFor:'queries'!
   497 !Object class methodsFor:'queries'!
   498 
   498 
   499 isAbstract
   499 isAbstract
   500     "Return if this class is an abstract class.
   500     "Return if this class is an abstract class.
   501      True is returned for Object here; false for subclasses.
   501      True is returned for Object here; false for subclasses.
   502      Abstract subclasses must redefine again."
   502      Abstract subclasses must redefine this again."
   503 
   503 
   504     ^ self == Object
   504     ^ self == Object
   505 !
   505 !
   506 
   506 
   507 isBuiltInClass
   507 isBuiltInClass
  1400 
  1400 
  1401 byteAt:index
  1401 byteAt:index
  1402     "return the byte at index.
  1402     "return the byte at index.
  1403      This is only allowed for non-pointer indexed objects
  1403      This is only allowed for non-pointer indexed objects
  1404      (i.e. byteArrays, wordArrays, floatArrays etc.).
  1404      (i.e. byteArrays, wordArrays, floatArrays etc.).
  1405      The receivers indexed instvars are treated as an uninterpreted
  1405      The receiver's indexed instvars are treated as an uninterpreted
  1406      collection of bytes.
  1406      collection of bytes.
  1407      Only useful with binary storage."
  1407      Only useful with binary storage."
  1408 
  1408 
  1409 %{  /* NOCONTEXT */
  1409 %{  /* NOCONTEXT */
  1410 
  1410 
  1412     int nIndex;
  1412     int nIndex;
  1413     REGISTER OBJ slf;
  1413     REGISTER OBJ slf;
  1414     REGISTER OBJ cls;
  1414     REGISTER OBJ cls;
  1415 
  1415 
  1416     if (__isSmallInteger(index)) {
  1416     if (__isSmallInteger(index)) {
  1417 	slf = self;
  1417         slf = self;
  1418 	if (__isNonNilObject(slf)) {
  1418         if (__isNonNilObject(slf)) {
  1419 	    unsigned char *pFirst;
  1419             unsigned char *pFirst;
  1420 	    int nIndex;
  1420             int nIndex;
  1421 
  1421 
  1422 	    cls = __qClass(slf);
  1422             cls = __qClass(slf);
  1423 
  1423 
  1424 	    pFirst = __byteArrayVal(slf);
  1424             pFirst = __byteArrayVal(slf);
  1425 	    pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
  1425             pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
  1426 	    nIndex = __byteArraySize(slf);
  1426             nIndex = __byteArraySize(slf);
  1427 	    indx = __intVal(index) - 1;
  1427             indx = __intVal(index) - 1;
  1428 
  1428 
  1429 	    switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
  1429             switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
  1430 		case __MASKSMALLINT(DOUBLEARRAY):
  1430                 case __MASKSMALLINT(DOUBLEARRAY):
  1431 #ifdef __NEED_DOUBLE_ALIGN
  1431 #ifdef __NEED_DOUBLE_ALIGN
  1432 		    if ((INT)pFirst & (__DOUBLE_ALIGN-1)) {
  1432                     if ((INT)pFirst & (__DOUBLE_ALIGN-1)) {
  1433 			int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1));
  1433                         int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1));
  1434 
  1434 
  1435 			pFirst += delta;
  1435                         pFirst += delta;
  1436 			nIndex -= delta;
  1436                         nIndex -= delta;
  1437 		    }
  1437                     }
  1438 #endif
  1438 #endif
  1439 		    /* fall into */
  1439                     /* fall into */
  1440 		case __MASKSMALLINT(BYTEARRAY):
  1440                 case __MASKSMALLINT(BYTEARRAY):
  1441 		case __MASKSMALLINT(WORDARRAY):
  1441                 case __MASKSMALLINT(WORDARRAY):
  1442 		case __MASKSMALLINT(LONGARRAY):
  1442                 case __MASKSMALLINT(LONGARRAY):
  1443 		case __MASKSMALLINT(SWORDARRAY):
  1443                 case __MASKSMALLINT(SWORDARRAY):
  1444 		case __MASKSMALLINT(SLONGARRAY):
  1444                 case __MASKSMALLINT(SLONGARRAY):
  1445 		case __MASKSMALLINT(FLOATARRAY):
  1445                 case __MASKSMALLINT(FLOATARRAY):
  1446 		    if ((unsigned)indx < (unsigned)nIndex) {
  1446                     if ((unsigned)indx < (unsigned)nIndex) {
  1447 			RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) );
  1447                         RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) );
  1448 		    }
  1448                     }
  1449 		    break;
  1449                     break;
  1450 
  1450 
  1451 		case __MASKSMALLINT(LONGLONGARRAY):
  1451                 case __MASKSMALLINT(LONGLONGARRAY):
  1452 		case __MASKSMALLINT(SLONGLONGARRAY):
  1452                 case __MASKSMALLINT(SLONGLONGARRAY):
  1453 #ifdef __NEED_LONGLONG_ALIGN
  1453 #ifdef __NEED_LONGLONG_ALIGN
  1454 		    if ((INT)pFirst & (__LONGLONG_ALIGN-1)) {
  1454                     if ((INT)pFirst & (__LONGLONG_ALIGN-1)) {
  1455 			int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1));
  1455                         int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1));
  1456 
  1456 
  1457 			pFirst += delta;
  1457                         pFirst += delta;
  1458 			nIndex -= delta;
  1458                         nIndex -= delta;
  1459 		    }
  1459                     }
  1460 #endif
  1460 #endif
  1461 		    if ((unsigned)indx < (unsigned)nIndex) {
  1461                     if ((unsigned)indx < (unsigned)nIndex) {
  1462 			RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) );
  1462                         RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) );
  1463 		    }
  1463                     }
  1464 		    break;
  1464                     break;
  1465 	    }
  1465             }
  1466 	}
  1466         }
  1467     }
  1467     }
  1468 %}.
  1468 %}.
  1469     "/ index not integer or index out of range
  1469     "/ index not integer or index out of range
  1470     "/ or non-byte indexable receiver
  1470     "/ or non-byte indexable receiver
  1471 
  1471 
  1482 
  1482 
  1483 byteAt:index put:byteValue
  1483 byteAt:index put:byteValue
  1484     "set the byte at index.
  1484     "set the byte at index.
  1485      This is only allowed for non-pointer indexed objects
  1485      This is only allowed for non-pointer indexed objects
  1486      (i.e. byteArrays, wordArrays, floatArrays etc.).
  1486      (i.e. byteArrays, wordArrays, floatArrays etc.).
  1487      The receivers indexed instvars are treated as an uninterpreted
  1487      The receiver's indexed instvars are treated as an uninterpreted
  1488      collection of bytes.
  1488      collection of bytes.
  1489      Only useful with binary storage."
  1489      Only useful with binary storage."
  1490 
  1490 
  1491 %{  /* NOCONTEXT */
  1491 %{  /* NOCONTEXT */
  1492 
  1492 
  1494     int val, nIndex;
  1494     int val, nIndex;
  1495     REGISTER OBJ slf;
  1495     REGISTER OBJ slf;
  1496     REGISTER OBJ cls;
  1496     REGISTER OBJ cls;
  1497 
  1497 
  1498     if (__bothSmallInteger(index, byteValue)) {
  1498     if (__bothSmallInteger(index, byteValue)) {
  1499 	val = __intVal(byteValue);
  1499         val = __intVal(byteValue);
  1500 	if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
  1500         if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
  1501 	    slf = self;
  1501             slf = self;
  1502 	    if (__isNonNilObject(slf)) {
  1502             if (__isNonNilObject(slf)) {
  1503 		cls = __qClass(slf);
  1503                 cls = __qClass(slf);
  1504 
  1504 
  1505 		indx = __intVal(index) - 1;
  1505                 indx = __intVal(index) - 1;
  1506 		switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
  1506                 switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
  1507 		    case __MASKSMALLINT(BYTEARRAY):
  1507                     case __MASKSMALLINT(BYTEARRAY):
  1508 		    case __MASKSMALLINT(WORDARRAY):
  1508                     case __MASKSMALLINT(WORDARRAY):
  1509 		    case __MASKSMALLINT(LONGARRAY):
  1509                     case __MASKSMALLINT(LONGARRAY):
  1510 		    case __MASKSMALLINT(SWORDARRAY):
  1510                     case __MASKSMALLINT(SWORDARRAY):
  1511 		    case __MASKSMALLINT(SLONGARRAY):
  1511                     case __MASKSMALLINT(SLONGARRAY):
  1512 		    case __MASKSMALLINT(LONGLONGARRAY):
  1512                     case __MASKSMALLINT(LONGLONGARRAY):
  1513 		    case __MASKSMALLINT(SLONGLONGARRAY):
  1513                     case __MASKSMALLINT(SLONGLONGARRAY):
  1514 		    case __MASKSMALLINT(FLOATARRAY):
  1514                     case __MASKSMALLINT(FLOATARRAY):
  1515 		    case __MASKSMALLINT(DOUBLEARRAY):
  1515                     case __MASKSMALLINT(DOUBLEARRAY):
  1516 			indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
  1516                         indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
  1517 			nIndex = __byteArraySize(slf);
  1517                         nIndex = __byteArraySize(slf);
  1518 			if ((unsigned)indx < (unsigned)nIndex) {
  1518                         if ((unsigned)indx < (unsigned)nIndex) {
  1519 			    __ByteArrayInstPtr(slf)->ba_element[indx] = val;
  1519                             __ByteArrayInstPtr(slf)->ba_element[indx] = val;
  1520 			    RETURN ( byteValue );
  1520                             RETURN ( byteValue );
  1521 			}
  1521                         }
  1522 			break;
  1522                         break;
  1523 		}
  1523                 }
  1524 	    }
  1524             }
  1525 	}
  1525         }
  1526     }
  1526     }
  1527 %}.
  1527 %}.
  1528     "/ index not integer or index out of range
  1528     "/ index not integer or index out of range
  1529     "/ or non-byte indexable receiver
  1529     "/ or non-byte indexable receiver
  1530 
  1530 
  2608 !
  2608 !
  2609 
  2609 
  2610 deepCopy
  2610 deepCopy
  2611     "return a copy of the object with all subobjects also copied.
  2611     "return a copy of the object with all subobjects also copied.
  2612      This method DOES handle cycles/self-refs and preserves object identity;
  2612      This method DOES handle cycles/self-refs and preserves object identity;
  2613      however the receivers class is not copied (to avoid the 'total' copy).
  2613      however the receiver's class is not copied (to avoid the 'total' copy).
  2614 
  2614 
  2615      This deepCopy is a bit slower than the old (unsecure) one, since it
  2615      This deepCopy is a bit slower than the old (unsecure) one, since it
  2616      keeps track of already copied objects. If you are sure, that your
  2616      keeps track of already copied objects. If you are sure, that your
  2617      copied object does not include duplicates (or you do not care) and
  2617      copied object does not include duplicates (or you do not care) and
  2618      no cycles are involved, you can use the old simpleDeepCopy,
  2618      no cycles are involved, you can use the old simpleDeepCopy,
  3831 !
  3831 !
  3832 
  3832 
  3833 displayOn:aGc x:x y:y opaque:opaque
  3833 displayOn:aGc x:x y:y opaque:opaque
  3834     "display the receiver in a graphicsContext - this method allows
  3834     "display the receiver in a graphicsContext - this method allows
  3835      for any object to be displayed in a ListView - for example.
  3835      for any object to be displayed in a ListView - for example.
  3836      The fallBack here shows the receivers displayString.
  3836      The fallBack here shows the receiver's displayString.
  3837      Notice, that the string is displayed on the baseLine;
  3837      Notice, that the string is displayed on the baseLine;
  3838      ask using #ascentOn: if required"
  3838      ask using #ascentOn: if required"
  3839 
  3839 
  3840     |s yBaseline|
  3840     |s yBaseline|
  3841 
  3841 
  3842     s := self isString ifTrue:[self] ifFalse:[self displayString].
  3842     s := self isString ifTrue:[self] ifFalse:[self displayString].
  3843     yBaseline := y "+ aGc font ascent".
  3843     yBaseline := y "+ aGc font ascent".
  3844     opaque ifTrue:[
  3844     opaque ifTrue:[
  3845 	aGc displayOpaqueString:s x:x y:yBaseline.
  3845         aGc displayOpaqueString:s x:x y:yBaseline.
  3846     ] ifFalse:[
  3846     ] ifFalse:[
  3847 	aGc displayString:s x:x y:yBaseline.
  3847         aGc displayString:s x:x y:yBaseline.
  3848     ].
  3848     ].
  3849 
  3849 
  3850     "Modified: 29.5.1996 / 16:29:38 / cg"
  3850     "Modified: 29.5.1996 / 16:29:38 / cg"
  3851 !
  3851 !
  3852 
  3852 
  7076 ! !
  7076 ! !
  7077 
  7077 
  7078 !Object methodsFor:'printing & storing'!
  7078 !Object methodsFor:'printing & storing'!
  7079 
  7079 
  7080 basicPrintOn:aStream
  7080 basicPrintOn:aStream
  7081     "append the receivers className with an articel to the argument, aStream"
  7081     "append the receiver's className with an article to the argument, aStream"
  7082 
  7082 
  7083     aStream nextPutAll:self classNameWithArticle
  7083     aStream nextPutAll:self classNameWithArticle
  7084 !
  7084 !
  7085 
  7085 
  7086 basicStoreString
  7086 basicStoreString
  7293 
  7293 
  7294 printOn:aStream
  7294 printOn:aStream
  7295     "append a user printed representation of the receiver to aStream.
  7295     "append a user printed representation of the receiver to aStream.
  7296      The format is suitable for a human - not meant to be read back.
  7296      The format is suitable for a human - not meant to be read back.
  7297 
  7297 
  7298      The default here is to output the receivers class name.
  7298      The default here is to output the receiver's class name.
  7299      BUT: this method is heavily redefined for objects which
  7299      BUT: this method is heavily redefined for objects which
  7300      can print prettier."
  7300      can print prettier."
  7301 
  7301 
  7302     self basicPrintOn:aStream.
  7302     self basicPrintOn:aStream.
  7303 
  7303 
  7778 ! !
  7778 ! !
  7779 
  7779 
  7780 !Object methodsFor:'queries'!
  7780 !Object methodsFor:'queries'!
  7781 
  7781 
  7782 basicSize
  7782 basicSize
  7783     "return the number of the receivers indexed instance variables,
  7783     "return the number of the receiver's indexed instance variables,
  7784      0 if it has none.
  7784      0 if it has none.
  7785 
  7785 
  7786      This method should NOT be redefined in any subclass (except with great care, for tuning)"
  7786      This method should NOT be redefined in any subclass (except with great care, for tuning)"
  7787 
  7787 
  7788 %{  /* NOCONTEXT */
  7788 %{  /* NOCONTEXT */
  7801     myClass = __qClass(self);
  7801     myClass = __qClass(self);
  7802     nbytes = __qSize(self);
  7802     nbytes = __qSize(self);
  7803     nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) );
  7803     nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) );
  7804 
  7804 
  7805     switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
  7805     switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) {
  7806 	case __MASKSMALLINT(POINTERARRAY):
  7806         case __MASKSMALLINT(POINTERARRAY):
  7807 	case __MASKSMALLINT(WKPOINTERARRAY):
  7807         case __MASKSMALLINT(WKPOINTERARRAY):
  7808 	    nbytes -= nInstBytes;
  7808             nbytes -= nInstBytes;
  7809 	    RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) );
  7809             RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) );
  7810 
  7810 
  7811 	case __MASKSMALLINT(BYTEARRAY):
  7811         case __MASKSMALLINT(BYTEARRAY):
  7812 	    nbytes -= nInstBytes;
  7812             nbytes -= nInstBytes;
  7813 	    RETURN ( __mkSmallInteger(nbytes / sizeof(char)) );
  7813             RETURN ( __mkSmallInteger(nbytes / sizeof(char)) );
  7814 
  7814 
  7815 	case __MASKSMALLINT(FLOATARRAY):
  7815         case __MASKSMALLINT(FLOATARRAY):
  7816 	    nbytes -= nInstBytes;
  7816             nbytes -= nInstBytes;
  7817 	    RETURN ( __mkSmallInteger(nbytes / sizeof(float)) );
  7817             RETURN ( __mkSmallInteger(nbytes / sizeof(float)) );
  7818 
  7818 
  7819 	case __MASKSMALLINT(DOUBLEARRAY):
  7819         case __MASKSMALLINT(DOUBLEARRAY):
  7820 # ifdef __NEED_DOUBLE_ALIGN
  7820 # ifdef __NEED_DOUBLE_ALIGN
  7821 	    nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
  7821             nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
  7822 # endif
  7822 # endif
  7823 	    nbytes -= nInstBytes;
  7823             nbytes -= nInstBytes;
  7824 	    RETURN ( __mkSmallInteger(nbytes / sizeof(double)) );
  7824             RETURN ( __mkSmallInteger(nbytes / sizeof(double)) );
  7825 
  7825 
  7826 	case __MASKSMALLINT(WORDARRAY):
  7826         case __MASKSMALLINT(WORDARRAY):
  7827 	case __MASKSMALLINT(SWORDARRAY):
  7827         case __MASKSMALLINT(SWORDARRAY):
  7828 	    nbytes -= nInstBytes;
  7828             nbytes -= nInstBytes;
  7829 	    RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */
  7829             RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */
  7830 
  7830 
  7831 	case __MASKSMALLINT(LONGARRAY):
  7831         case __MASKSMALLINT(LONGARRAY):
  7832 	case __MASKSMALLINT(SLONGARRAY):
  7832         case __MASKSMALLINT(SLONGARRAY):
  7833 	    nbytes -= nInstBytes;
  7833             nbytes -= nInstBytes;
  7834 	    RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */
  7834             RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */
  7835 
  7835 
  7836 	case __MASKSMALLINT(LONGLONGARRAY):
  7836         case __MASKSMALLINT(LONGLONGARRAY):
  7837 	case __MASKSMALLINT(SLONGLONGARRAY):
  7837         case __MASKSMALLINT(SLONGLONGARRAY):
  7838 # ifdef __NEED_LONGLONG_ALIGN
  7838 # ifdef __NEED_LONGLONG_ALIGN
  7839 	    nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
  7839             nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
  7840 # endif
  7840 # endif
  7841 	    nbytes -= nInstBytes;
  7841             nbytes -= nInstBytes;
  7842 	    RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */
  7842             RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */
  7843     }
  7843     }
  7844 #endif /* not __SCHTEAM__ */
  7844 #endif /* not __SCHTEAM__ */
  7845 %}.
  7845 %}.
  7846     ^ 0
  7846     ^ 0
  7847 !
  7847 !
  7848 
  7848 
  7849 byteSize
  7849 byteSize
  7850     "return the number of bytes in the receivers indexed instance variables,
  7850     "return the number of bytes in the receiver's indexed instance variables,
  7851      0 if it has none. This only returns non-zero for non-pointer indexed
  7851      0 if it has none. This only returns non-zero for non-pointer indexed
  7852      instvars i.e. byteArrays, wordArrays etc.
  7852      instvars i.e. byteArrays, wordArrays etc.
  7853      Notice: for Strings the returned size may look strange.
  7853      Notice: for Strings the returned size may look strange.
  7854      Only useful with binary storage."
  7854      Only useful with binary storage."
  7855 
  7855 
  7856     |myClass|
  7856     |myClass|
  7857 
  7857 
  7858     myClass := self class.
  7858     myClass := self class.
  7859     myClass isVariable ifTrue:[
  7859     myClass isVariable ifTrue:[
  7860 	myClass isPointers ifFalse:[
  7860         myClass isPointers ifFalse:[
  7861 	    myClass isBytes ifTrue:[
  7861             myClass isBytes ifTrue:[
  7862 		^ self basicSize.
  7862                 ^ self basicSize.
  7863 	    ].
  7863             ].
  7864 	    myClass isWords ifTrue:[
  7864             myClass isWords ifTrue:[
  7865 		^ self basicSize * 2.
  7865                 ^ self basicSize * 2.
  7866 	    ].
  7866             ].
  7867 	    myClass isSignedWords ifTrue:[
  7867             myClass isSignedWords ifTrue:[
  7868 		^ self basicSize * 2.
  7868                 ^ self basicSize * 2.
  7869 	    ].
  7869             ].
  7870 	    myClass isLongs ifTrue:[
  7870             myClass isLongs ifTrue:[
  7871 		^ self basicSize * 4.
  7871                 ^ self basicSize * 4.
  7872 	    ].
  7872             ].
  7873 	    myClass isSignedLongs ifTrue:[
  7873             myClass isSignedLongs ifTrue:[
  7874 		^ self basicSize * 4.
  7874                 ^ self basicSize * 4.
  7875 	    ].
  7875             ].
  7876 	    myClass isLongLongs ifTrue:[
  7876             myClass isLongLongs ifTrue:[
  7877 		^ self basicSize * 8.
  7877                 ^ self basicSize * 8.
  7878 	    ].
  7878             ].
  7879 	    myClass isSignedLongLongs ifTrue:[
  7879             myClass isSignedLongLongs ifTrue:[
  7880 		^ self basicSize * 8.
  7880                 ^ self basicSize * 8.
  7881 	    ].
  7881             ].
  7882 	    myClass isFloats ifTrue:[
  7882             myClass isFloats ifTrue:[
  7883 		^ self basicSize * (ExternalBytes sizeofFloat)
  7883                 ^ self basicSize * (ExternalBytes sizeofFloat)
  7884 	    ].
  7884             ].
  7885 	    myClass isDoubles ifTrue:[
  7885             myClass isDoubles ifTrue:[
  7886 		^ self basicSize * (ExternalBytes sizeofDouble)
  7886                 ^ self basicSize * (ExternalBytes sizeofDouble)
  7887 	    ].
  7887             ].
  7888 	    self error:'unknown variable size class species'.
  7888             self error:'unknown variable size class species'.
  7889 	]
  7889         ]
  7890     ].
  7890     ].
  7891     ^ 0
  7891     ^ 0
  7892 
  7892 
  7893     "
  7893     "
  7894      Point new byteSize
  7894      Point new byteSize
  7914 !
  7914 !
  7915 
  7915 
  7916 respondsTo:aSelector
  7916 respondsTo:aSelector
  7917     "return true, if the receiver implements a method with selector equal
  7917     "return true, if the receiver implements a method with selector equal
  7918      to aSelector; i.e. if there is a method for aSelector in either the
  7918      to aSelector; i.e. if there is a method for aSelector in either the
  7919      receivers class or one of its superclasses.
  7919      receiver's class or one of its superclasses.
  7920 
  7920 
  7921      Notice, that this does not imply, that such a message can be sent without
  7921      Notice, that this does not imply, that such a message can be sent without
  7922      an error being raised. For example, an implementation could send
  7922      an error being raised. For example, an implementation could send
  7923      #shouldNotImplement or #subclassResponsibility."
  7923      #shouldNotImplement or #subclassResponsibility."
  7924 
  7924 
  7929      For now, use the cache ...
  7929      For now, use the cache ...
  7930     "
  7930     "
  7931 %{  /* NOCONTEXT */
  7931 %{  /* NOCONTEXT */
  7932 
  7932 
  7933     if (__lookup(__Class(self), aSelector) == nil) {
  7933     if (__lookup(__Class(self), aSelector) == nil) {
  7934 	RETURN ( false );
  7934         RETURN ( false );
  7935     }
  7935     }
  7936     RETURN ( true );
  7936     RETURN ( true );
  7937 %}
  7937 %}
  7938 .
  7938 .
  7939     ^ self class canUnderstand:aSelector
  7939     ^ self class canUnderstand:aSelector
  7950 
  7950 
  7951     ^ false
  7951     ^ false
  7952 !
  7952 !
  7953 
  7953 
  7954 size
  7954 size
  7955     "return the number of the receivers indexed instance variables;
  7955     "return the number of the receiver's indexed instance variables;
  7956      this method may be redefined in subclasses"
  7956      this method may be redefined in subclasses"
  7957 
  7957 
  7958     ^ self basicSize
  7958     ^ self basicSize
  7959 !
  7959 !
  7960 
  7960 
  7961 species
  7961 species
  7962     "return a class which is similar to (or the same as) the receivers class.
  7962     "return a class which is similar to (or the same as) the receiver's class.
  7963      This is used to create an appropriate object when creating derived
  7963      This is used to create an appropriate object when creating derived
  7964      copies in the collection classes (sometimes redefined)."
  7964      copies in the collection classes (sometimes redefined)."
  7965 
  7965 
  7966     ^ self class
  7966     ^ self class
  7967 !
  7967 !
  8763     self primitiveFailed
  8763     self primitiveFailed
  8764 !
  8764 !
  8765 
  8765 
  8766 changeClassTo:otherClass
  8766 changeClassTo:otherClass
  8767     "changes the class of the receiver to the argument, otherClass.
  8767     "changes the class of the receiver to the argument, otherClass.
  8768      This is only allowed (possible), if the receivers class and the argument
  8768      This is only allowed (possible), if the receiver's class and the argument
  8769      have the same structure (i.e. number of named instance variables and
  8769      have the same structure (i.e. number of named instance variables and
  8770      type of indexed instance variables).
  8770      type of indexed instance variables).
  8771      If the structures do not match, or any of the original class or new class
  8771      If the structures do not match, or any of the original class or new class
  8772      is UndefinedObject or a Smallinteger, a primitive error is triggered."
  8772      is UndefinedObject or a Smallinteger, a primitive error is triggered."
  8773 
  8773 
  8777 
  8777 
  8778     "check for UndefinedObject/SmallInteger receiver or newClass"
  8778     "check for UndefinedObject/SmallInteger receiver or newClass"
  8779 %{
  8779 %{
  8780 #ifdef __SCHTEAM__
  8780 #ifdef __SCHTEAM__
  8781     ok = (self.isSTInstance() && otherClass.isSTInstance())
  8781     ok = (self.isSTInstance() && otherClass.isSTInstance())
  8782 	    ? STObject.True : STObject.False;
  8782             ? STObject.True : STObject.False;
  8783 #else
  8783 #else
  8784     {
  8784     {
  8785 	OBJ other = otherClass;
  8785         OBJ other = otherClass;
  8786 
  8786 
  8787 	if (__isNonNilObject(self)
  8787         if (__isNonNilObject(self)
  8788 	 && __isNonNilObject(other)
  8788          && __isNonNilObject(other)
  8789 	 && (other != UndefinedObject)
  8789          && (other != UndefinedObject)
  8790 	 && (other != SmallInteger)) {
  8790          && (other != SmallInteger)) {
  8791 	    ok = true;
  8791             ok = true;
  8792 	} else {
  8792         } else {
  8793 	    ok = false;
  8793             ok = false;
  8794 	}
  8794         }
  8795     }
  8795     }
  8796 #endif /* not SCHTEAM */
  8796 #endif /* not SCHTEAM */
  8797 %}.
  8797 %}.
  8798     ok == true ifTrue:[
  8798     ok == true ifTrue:[
  8799 	ok := false.
  8799         ok := false.
  8800 	myClass := self class.
  8800         myClass := self class.
  8801 	myClass == otherClass ifTrue:[
  8801         myClass == otherClass ifTrue:[
  8802 	    "nothing to change"
  8802             "nothing to change"
  8803 	    ^ self.
  8803             ^ self.
  8804 	].
  8804         ].
  8805 	myClass flags == otherClass flags ifTrue:[
  8805         myClass flags == otherClass flags ifTrue:[
  8806 	    myClass instSize == otherClass instSize ifTrue:[
  8806             myClass instSize == otherClass instSize ifTrue:[
  8807 		"same instance layout and types: its ok to do it"
  8807                 "same instance layout and types: its ok to do it"
  8808 		ok := true.
  8808                 ok := true.
  8809 	    ] ifFalse:[
  8809             ] ifFalse:[
  8810 		myClass isPointers ifTrue:[
  8810                 myClass isPointers ifTrue:[
  8811 		    myClass isVariable ifTrue:[
  8811                     myClass isVariable ifTrue:[
  8812 			ok := true
  8812                         ok := true
  8813 		    ]
  8813                     ]
  8814 		]
  8814                 ]
  8815 	    ]
  8815             ]
  8816 	] ifFalse:[
  8816         ] ifFalse:[
  8817 	    myClass isPointers ifTrue:[
  8817             myClass isPointers ifTrue:[
  8818 		"if newClass is a variable class, with instSize <= my instsize,
  8818                 "if newClass is a variable class, with instSize <= my instsize,
  8819 		 we can do it (effectively mapping additional instvars into the
  8819                  we can do it (effectively mapping additional instvars into the
  8820 		 variable part) - usefulness is questionable, though"
  8820                  variable part) - usefulness is questionable, though"
  8821 
  8821 
  8822 		otherClass isPointers ifTrue:[
  8822                 otherClass isPointers ifTrue:[
  8823 		    otherClass isVariable ifTrue:[
  8823                     otherClass isVariable ifTrue:[
  8824 			otherClass instSize <= (myClass instSize + self basicSize)
  8824                         otherClass instSize <= (myClass instSize + self basicSize)
  8825 			ifTrue:[
  8825                         ifTrue:[
  8826 			    ok := true
  8826                             ok := true
  8827 			]
  8827                         ]
  8828 		    ] ifFalse:[
  8828                     ] ifFalse:[
  8829 			otherClass instSize == (myClass instSize + self basicSize)
  8829                         otherClass instSize == (myClass instSize + self basicSize)
  8830 			ifTrue:[
  8830                         ifTrue:[
  8831 			    ok := true
  8831                             ok := true
  8832 			]
  8832                         ]
  8833 		    ]
  8833                     ]
  8834 		] ifFalse:[
  8834                 ] ifFalse:[
  8835 		    "it does not make sense to convert pointers to bytes ..."
  8835                     "it does not make sense to convert pointers to bytes ..."
  8836 		]
  8836                 ]
  8837 	    ] ifFalse:[
  8837             ] ifFalse:[
  8838 		"does it make sense, to convert bits ?"
  8838                 "does it make sense, to convert bits ?"
  8839 		"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..."
  8839                 "could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..."
  8840 		(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[
  8840                 (myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[
  8841 		    ok := true
  8841                     ok := true
  8842 		]
  8842                 ]
  8843 	    ]
  8843             ]
  8844 	]
  8844         ]
  8845     ].
  8845     ].
  8846     ok == true ifTrue:[
  8846     ok == true ifTrue:[
  8847 	"now, change the receiver's class ..."
  8847         "now, change the receiver's class ..."
  8848 %{
  8848 %{
  8849 #ifdef __SCHTEAM__
  8849 #ifdef __SCHTEAM__
  8850 	((STInstance)self).clazz = (STClass)otherClass;
  8850         ((STInstance)self).clazz = (STClass)otherClass;
  8851 	return __c__._RETURN(self);
  8851         return __c__._RETURN(self);
  8852 #else
  8852 #else
  8853 	{
  8853         {
  8854 	    OBJ me = self;
  8854             OBJ me = self;
  8855 
  8855 
  8856 	    // gcc4.4 does not like this:
  8856             // gcc4.4 does not like this:
  8857 	    // __qClass(me) = otherClass;
  8857             // __qClass(me) = otherClass;
  8858 	    __objPtr(me)->o_class = (CLASS_OBJ)otherClass;
  8858             __objPtr(me)->o_class = (CLASS_OBJ)otherClass;
  8859 	    __STORE(me, otherClass);
  8859             __STORE(me, otherClass);
  8860 	    RETURN (me);
  8860             RETURN (me);
  8861 	}
  8861         }
  8862 #endif /* not SCHTEAM */
  8862 #endif /* not SCHTEAM */
  8863 %}.
  8863 %}.
  8864     ].
  8864     ].
  8865 
  8865 
  8866     "
  8866     "
  8872     self primitiveFailed
  8872     self primitiveFailed
  8873 !
  8873 !
  8874 
  8874 
  8875 changeClassToThatOf:anObject
  8875 changeClassToThatOf:anObject
  8876     "changes the class of the receiver to that of the argument, anObject.
  8876     "changes the class of the receiver to that of the argument, anObject.
  8877      This is only allowed (possible), if the receivers class and the arguments
  8877      This is only allowed (possible), if the receiver's class and the arguments
  8878      class have the same structure (i.e. number of named instance variables and
  8878      class have the same structure (i.e. number of named instance variables and
  8879      type of indexed instance variables). If the structures do not match, or any
  8879      type of indexed instance variables). If the structures do not match, or any
  8880      of the objects is nil or a Smallinteger, a primitive error is triggered."
  8880      of the objects is nil or a Smallinteger, a primitive error is triggered."
  8881 
  8881 
  8882     self changeClassTo:(anObject class)
  8882     self changeClassTo:(anObject class)
  8961 ? defaultValue
  8961 ? defaultValue
  8962      "a syntactic sugar-piece:
  8962      "a syntactic sugar-piece:
  8963       if the receiver is nil, return the defaultValue;
  8963       if the receiver is nil, return the defaultValue;
  8964       otherwise, return the receiver.
  8964       otherwise, return the receiver.
  8965       This method is only redefined in UndefinedObject - therefore,
  8965       This method is only redefined in UndefinedObject - therefore,
  8966       the recevier is retuned here.
  8966       the receiver is retuned here.
  8967 
  8967 
  8968       Thus, if foo and bar are simple variables or constants,
  8968       Thus, if foo and bar are simple variables or constants,
  8969 	  foo ? bar
  8969           foo ? bar
  8970       is the same as:
  8970       is the same as:
  8971 	  (foo isNil ifTrue:[bar] ifFalse:[foo])
  8971           (foo isNil ifTrue:[bar] ifFalse:[foo])
  8972 
  8972 
  8973       if they are message sends, the equivalent code is:
  8973       if they are message sends, the equivalent code is:
  8974 	  [
  8974           [
  8975 	      |t1 t2|
  8975               |t1 t2|
  8976 
  8976 
  8977 	      t1 := foo.
  8977               t1 := foo.
  8978 	      t2 := bar.
  8978               t2 := bar.
  8979 	      t1 isNil ifTrue:[t2] ifFalse:[t1]
  8979               t1 isNil ifTrue:[t2] ifFalse:[t1]
  8980 	  ] value
  8980           ] value
  8981 
  8981 
  8982       Can be used to provide defaultValues to variables,
  8982       Can be used to provide defaultValues to variables,
  8983       as in:
  8983       as in:
  8984 	  foo := arg ? #defaultValue
  8984           foo := arg ? #defaultValue
  8985 
  8985 
  8986       Note: this method should never be redefined in classes other than UndefinedObject.
  8986       Note: this method should never be redefined in classes other than UndefinedObject.
  8987       Notice:
  8987       Notice:
  8988 	 This method is open coded (inlined) by the compiler(s)
  8988          This method is open coded (inlined) by the compiler(s)
  8989 	 - redefining it may not work as expected."
  8989          - redefining it may not work as expected."
  8990 
  8990 
  8991     ^ self
  8991     ^ self
  8992 
  8992 
  8993     "
  8993     "
  8994      1 ? #default
  8994      1 ? #default