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 |
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 |
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 |
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 " |
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 |