Object.st
changeset 56 be0ed17e6f85
parent 49 f1c2d75f2eb6
child 71 a42874820e27
--- a/Object.st	Fri Feb 25 13:59:09 1994 +0100
+++ b/Object.st	Fri Feb 25 14:00:53 1994 +0100
@@ -32,7 +32,7 @@
 all objects is defined here.
 Also some utility stuff (like notify) and error handling is implemented here.
 
-$Header: /cvs/stx/stx/libbasic/Object.st,v 1.12 1994-02-05 12:22:28 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Object.st,v 1.13 1994-02-25 13:00:47 claus Exp $
 '!
 
 Smalltalk at:#ErrorRecursion put:false!
@@ -307,7 +307,7 @@
     register OBJ myClass;
 
     /*
-     * notice the missing test for self beeing a nonNilObject -
+     * notice the missing test for self being a nonNilObject -
      * this can be done since basicSize is defined both in UndefinedObject
      * and SmallInteger
      */
@@ -330,6 +330,12 @@
             RETURN ( _MKSMALLINT(nbytes / sizeof(float)) );
 
         case DOUBLEARRAY:
+#ifdef NEED_DOUBLE_ALIGN
+            /*
+             * care for filler
+             */
+            nbytes -= sizeof(FILLTYPE);
+#endif
             RETURN ( _MKSMALLINT(nbytes / sizeof(double)) );
 
         case WKPOINTERARRAY:
@@ -421,6 +427,13 @@
     ^ false
 !
 
+isString
+    "return true, if the receiver is some kind of string;
+     false is returned here - the method is redefined in String."
+
+    ^ false
+!
+
 isFileStream
     "return true, if the receiver is some kind of fileStream;
      false is returned here - the method is redefined in FileStream."
@@ -442,6 +455,13 @@
     ^ false
 !
 
+isLiteral
+    "return true, if the receiver can be represented as a constant in ST syntax;
+     false is returned here - the method is redefined in some classes."
+
+    ^ false
+!
+
 respondsToArithmetic
     "return true, if the receiver responds to arithmetic messages.
      false is returned here - the method is redefined in ArithmeticValue."
@@ -764,7 +784,7 @@
     static unsigned nextHash = 0;
     OBJ cls;
 
-    if (_isObject(self)) {
+    if (_isNonNilObject(self)) {
         v1 = _GET_HASH(self);
         if (v1 == 0) {
             v1 = nextHash++;
@@ -863,41 +883,32 @@
     "unix signal occured - some signals are handled as Smalltalk Exceptions (SIGPIPE),
      others (SIGBUS) are rather fatal ..."
 
-    |box|
+    |box name|
 
     (signalNumber == 13) ifTrue:[
         "SIGPIPE - write on a pipe with no one to read"
 
-        ^ PipeStream pipeSignal raise.
-    ].
-    (signalNumber == 10) ifTrue:[
-        "SIGBUS - stack overflow / invalid access"
+        ^ PipeStream brokenPipeSignal raise.
     ].
-    (signalNumber == 15) ifTrue:[
-        "SIGTERM - software termination"
-    ].
-    (signalNumber == 16) ifTrue:[
-        "SIGURG - io urgent condition"
-    ].
+    name := OperatingSystem nameForSignal:signalNumber.
 
     "other signals bring up a box asking for what to do ..."
 
     (Smalltalk at:#SignalCatchBlock) notNil ifTrue:[
-        box := OptionBox title:('Signal ' , 
-                                signalNumber printString ,
-                                ' cought')
-               numberOfOptions:5.
+        box := OptionBox 
+                   title:('Signal ' , name, ' cought')
+                   numberOfOptions:5.
 
         box buttonTitles:#('ignore' 'debug' 'restart' 'dump' 'exit').
         box actions:(Array with:[^ nil]
-                           with:[Debugger enterWithMessage:'Signal ', signalNumber printString. ^nil]
+                           with:[Debugger enterWithMessage:('Signal ', name). ^nil]
                            with:[SignalCatchBlock value. ^nil]
                            with:[Smalltalk fatalAbort]
                            with:[Smalltalk exit]).
         box showAtPointer
     ].
 
-    self error:('signal ' , signalNumber printString)
+    self error:('signal ' , name)
 !
 
 recursionInterrupt
@@ -1082,7 +1093,7 @@
      * do not use any message calls here
      * - since this might lead to infinite recursion ...
      */
-    if (_isString(aMessage))
+    if (__isString(aMessage))
         printf("%s\n", _stringVal(aMessage));
     printStack(__context);
     exit(1);
@@ -1241,7 +1252,7 @@
 
 
     /*
-     * notice the missing test for self beeing a nonNilObject -
+     * notice the missing test for self being a nonNilObject -
      * this can be done since basicAt: is defined both in UndefinedObject
      * and SmallInteger
      */
@@ -1290,6 +1301,12 @@
                 if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) {
                     double *dp;
 
+#ifdef NEED_DOUBLE_ALIGN
+                    /*
+                     * care for filler
+                     */
+                    pFirst += sizeof(FILLTYPE);
+#endif
                     dp = (double *)pFirst + indx;
                     RETURN ( _MKFLOAT(*dp) COMMA_CON );
                 }
@@ -1336,7 +1353,7 @@
     int nInstBytes, ninstvars;
     int val;
 
-    /* notice the missing test for self beeing a nonNilObject -
+    /* notice the missing test for self being a nonNilObject -
        this an be done since basicAt: is defined both in UndefinedObject
        and SmallInteger */
 
@@ -1394,7 +1411,7 @@
                     float *fp;
 
                     fp = (float *)pFirst + indx;
-                    if (_isFloat(anObject)) {
+                    if (__isFloat(anObject)) {
                         *fp = _floatVal(anObject);
                         RETURN ( anObject );
                     } else if (_isSmallInteger(anObject)) {
@@ -1409,8 +1426,14 @@
                 if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) {
                     double *dp;
 
+#ifdef NEED_DOUBLE_ALIGN
+                    /*
+                     * care for filler
+                     */
+                    pFirst += sizeof(FILLTYPE);
+#endif
                     dp = (double *)pFirst + indx;
-                    if (_isFloat(anObject)) {
+                    if (__isFloat(anObject)) {
                         *dp = _floatVal(anObject);
                         RETURN ( anObject );
                     }  else if (_isSmallInteger(anObject)) {
@@ -2120,13 +2143,13 @@
                     ]
                 ] ifFalse:[
                     self class isFloats ifTrue:[
-			"could do it in one big write on machines which use IEEE floats ..."
+                        "could do it in one big write on machines which use IEEE floats ..."
                         1 to:basicSize do:[:i |
                             Float storeBinaryIEEESingle:(self basicAt:i) on:stream
                         ]
                     ] ifFalse:[
                         self class isDoubles ifTrue:[
-			    "could do it in one big write on machines which use IEEE doubles ..."
+                            "could do it in one big write on machines which use IEEE doubles ..."
                             1 to:basicSize do:[:i |
                                 Float storeBinaryIEEEDouble:(self basicAt:i) on:stream
                             ]
@@ -2159,6 +2182,11 @@
     "return the classname of the receivers class"
 
     ^ self class name
+
+    "1 className"
+    "1 class className"
+    "$a className"
+    "$a class className"
 !
 
 classNameWithArticle
@@ -2174,6 +2202,9 @@
          article := 'a '
     ].
     ^ (article , classname)
+
+    "1 classNameWithArticle"
+    "(1->2) classNameWithArticle"
 !
 
 printString
@@ -2181,17 +2212,48 @@
      Default printString is the classname preceeded by an article -
      is redefined in many subclasses"
 
+    |s|
+
+    s := WriteStream on:(String new:30).
+    self printOn:s.
+    ^ s contents
+"
     ^ self classNameWithArticle
+"
 !
 
 printOn:aStream
     "print the receiver on the argument-stream"
 
+"
     aStream nextPutAll:(self printString)
+"
+    aStream nextPutAll:self classNameWithArticle
+!
+
+print
+    "print the receiver on the standard output stream"
+
+    self printOn:Stdout
+!
+
+printNL
+    "print the receiver followed by a cr on the standard output stream
+     - for GNU Smalltalk compatibility"
+
+    ^ self printNewline
+!
+
+printNewline
+    "print the receiver followed by a cr on the standard output stream"
+
+    self printOn:Stdout.
+    Stdout cr
 !
 
 printStringPaddedTo:size with:padCharacter
-    "return a printed representation of the receiver, padded with padCharacter up to size"
+    "return a printed representation of the receiver,
+     padded with padCharacter up to size"
 
     |thePrintString s len|
 
@@ -2209,7 +2271,8 @@
 !
 
 printStringPaddedTo:size
-    "return a printed representation of the receiver, padded with spaces up to size"
+    "return a printed representation of the receiver,
+     padded with spaces up to size"
 
     ^ self printStringPaddedTo:size with:(Character space)
 
@@ -2228,15 +2291,17 @@
 printOn:aStream paddedTo:size with:padCharacter
     "print the receiver on aStream, padding with padCharacter up to size"
 
-    |s|
+    |s n|
 
     s := self printString.
     aStream nextPutAll:s.
-    s size to:size do:[:i |
-        aStream nextPut:padCharacter
+    n := size - s size.
+    n > 0 ifTrue:[
+        aStream next:n put:padCharacter
     ]
 
-    "123 printOn:Transcript paddedTo:10 with:$_"
+    "123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr"
+    "123 printOn:Transcript paddedTo:10 with:$. . Transcript cr"
 !
 
 printOn:aStream zeroPaddedTo:size
@@ -2258,13 +2323,14 @@
     len := thePrintString size.
     (len < size) ifTrue:[
         s := String new:size withAll:padCharacter.
-        s replaceFrom:(size - len) with:thePrintString.
+        s replaceFrom:(size - len + 1) with:thePrintString.
         ^ s
     ].
     ^ thePrintString
 
     "123 printStringLeftPaddedTo:10 with:$."
     "1 printStringLeftPaddedTo:10 with:$."
+    "1234567890 printStringLeftPaddedTo:5 with:$."
 !
 
 printStringLeftPaddedTo:size
@@ -2282,6 +2348,9 @@
      padding is done on the left."
 
     aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter)
+
+    "123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr"
+    "123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr"
 !
 
 printOn:aStream leftPaddedTo:size
@@ -2289,100 +2358,91 @@
      padding is done on the left."
 
     aStream nextPutAll:(self printStringLeftPaddedTo:size with:(Character space))
+
+    "123 printOn:Transcript leftPaddedTo:10. Transcript cr"
+    "123 printOn:Transcript leftPaddedTo:2. Transcript cr"
 !
 
 printStringRightAdjustLen:size
-    "obsolete"
+    "obsolete - just a name confusion.
+     This method will go away ..."
 
     ^ self printStringLeftPaddedTo:size
 !
 
-print
-    "print the receiver on the standard output stream"
-
-    self printString print
-!
-
-printNL
-    "print the receiver followed by a cr
-     - for GNU Smalltalk compatibility"
-
-    ^ self printNewline
-!
-
-printNewline
-    "print the receiver followed by a cr"
-
-    self print.
-    Character nl print
-!
-
 printRightAdjustLen:size
-    "obsolete"
+    "obsolete - just a name confusion.
+     This method will go away ..."
 
     (self printStringLeftPaddedTo:size) printOn:Stdout
 !
 
 displayString
     "return a string used when displaying the receiver in a view,
-     for example an Inspector. This is usually the same as printString"
+     for example an Inspector. This is usually the same as printString,
+     but sometimes redefined for better look."
 
     ^ self printString
 !
 
-storeString
-    "return a string representing an expression to reconstruct the receiver"
-
-    | stream myClass hasSemi 
-      sz "{ Class: SmallInteger }" |
+storeOn:aStream
+    "store the receiver on aStream; i.e. print an expression which will
+     reconstruct the receiver"
+
+    |myClass hasSemi sz "{ Class: SmallInteger }" |
 
     thisContext isRecursive ifTrue:[
         Transcript showCr:'Error: storeString of self referencing object.'.
-        ^ '#("recursive")'
+        aStream nextPutAll:'#("recursive")'.
+        ^ self
     ].
+
     myClass := self class.
-    stream := WriteStream on:(String new).
-    stream nextPut:$(.
-    stream nextPutAll:self class name.
+    aStream nextPut:$(.
+    aStream nextPutAll:self class name.
+
     hasSemi := false.
     myClass isVariable ifTrue:[
-        stream nextPutAll:' basicNew:'.
-        self basicSize printOn:stream
+        aStream nextPutAll:' basicNew:'.
+        self basicSize printOn:aStream
     ] ifFalse:[
-        stream nextPutAll:' basicNew'
+        aStream nextPutAll:' basicNew'
     ].
+
     sz := myClass instSize.
     1 to:sz do:[:i | 
-        stream nextPutAll:' instVarAt:'.
-        i printOn:stream.
-        stream nextPutAll:' put:'.
-        (self instVarAt:i) storeOn:stream.
-        stream nextPut:$;.
+        aStream nextPutAll:' instVarAt:'.
+        i printOn:aStream.
+        aStream nextPutAll:' put:'.
+        (self instVarAt:i) storeOn:aStream.
+        aStream nextPut:$;.
         hasSemi := true
     ].
     myClass isVariable ifTrue:[
         sz := self basicSize.
         1 to:sz do:[:i | 
-            stream nextPutAll:' basicAt:'.
-            i printOn:stream.
-            stream nextPutAll:' put:'.
-            (self basicAt:i) storeOn:stream.
-            stream nextPut:$;.
+            aStream nextPutAll:' basicAt:'.
+            i printOn:aStream.
+            aStream nextPutAll:' put:'.
+            (self basicAt:i) storeOn:aStream.
+            aStream nextPut:$;.
             hasSemi := true
         ]
     ].
     hasSemi ifTrue:[
-        stream nextPutAll:' yourself'
+        aStream nextPutAll:' yourself'
     ].
-    stream nextPut:$).
-    ^ stream contents
+    aStream nextPut:$).
 !
 
-storeOn:aStream
-    "store the receiver on aStream; i.e. print an expression which will
-     reconstruct the receiver"
-
-    aStream nextPutAll:(self storeString)
+storeString
+    "return a string representing an expression to reconstruct the receiver"
+
+    |s|
+
+    s := WriteStream on:(String new:50).
+    self storeOn:s.
+    ^ s contents
 !
 
 store