ProtoObject.st
author Stefan Vogel <sv@exept.de>
Fri, 11 Apr 2014 10:29:03 +0200
changeset 16321 6e24f3c5ba96
parent 16158 93042fc9827e
child 18120 e3a375d5f6a8
child 18351 dc6c93a03b6d
permissions -rw-r--r--
class: Win32OperatingSystem changed: #selectOnAnyReadable:writable:exception:readableInto:writableInto:exceptionInto:withTimeOut: comment/format

"
 COPYRIGHT (c) 2004 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic' }"

nil subclass:#ProtoObject
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Objects'
!

!ProtoObject class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2004 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    a minimum object without much protocol;
    Provides the minimum required to prevent inspectors from crashing,
    and debuggers from blocking.
    (i.e. instead of inheriting from nil, better inherit from this).

    Named after a similar class found in Dolphin-Smalltalk.

    [author:]
        Claus Gittinger (not much authoring, though)
"
! !

!ProtoObject methodsFor:'error handling'!

doesNotUnderstand:aMessage
    "this message is sent by the runtime system (VM) when
     a message is not understood by some object (i.e. there
     is no method for that selector). The original message has
     been packed into aMessage (i.e. the receiver, selector and
     any arguments) and the original receiver is then sent the
     #doesNotUnderstand: message.
     Here, we raise another signal which usually enters the debugger.
     You can of course redefine #doesNotUnderstand: in your classes
     to implement message delegation, 
     or handle the MessageNotUnderstood exception gracefully."

    <context: #return>

    ^ MessageNotUnderstood raiseRequestWith:aMessage
! !

!ProtoObject methodsFor:'queries'!

class
    "return the receivers class"

%{  /* NOCONTEXT */

    RETURN ( __Class(self) );
%}

"
*** WARNING
***
*** this method has been automatically created,
*** since all nil-subclasses should respond to some minimum required
*** protocol.
***
*** Inspection and/or debugging of instances may not be possible,
*** if you remove/change this method. 
"
!

identityHash
    "return an Integer useful as a hash key for the receiver.
     This hash should return same values for the same object (i.e. use
     this to hash on identity of objects).

     We cannot use the Objects address (as other smalltalks do) since
     no object-table exists and the hashval must not change when objects
     are moved by the collector. Therefore we assign each object a unique
     Id in the object header itself as its hashed upon.
     (luckily we have 11 bits spare to do this - unluckily its only 11 bits).
     Time will show, if 11 bits are enough; if not, another entry in the
     object header will be needed, adding 4 bytes to every object. Alternatively,
     hashed-upon objects could add an instvar containing the hash value."

%{  /* NOCONTEXT */

    REGISTER unsigned INT hash;
    static unsigned nextHash = 0;

    if (__isNonNilObject(self)) {
        hash = __GET_HASH(self);
        if (hash == 0) {
            /* has no hash yet */

            if (++nextHash > __MAX_HASH__) {
                nextHash = 1;
            }
            hash = nextHash;
            __SET_HASH(self, hash);
        }

        /*
         * now, we got 11 bits for hashing;
         * make it as large as possible; since most hashers use the returned
         * key and take it modulo some prime number, this will allow for
         * better distribution (i.e. bigger empty spaces) in hashed collection.
         */
        hash = __MAKE_HASH__(hash);
        RETURN ( __mkSmallInteger(hash) );
    }
%}.
    ^ 0 "never reached, since redefined in UndefinedObject and SmallInteger"

    "Created: / 31-05-2007 / 23:18:40 / cg"
! !

!ProtoObject methodsFor:'testing'!

ifNil:aBlock
    ^ self
!

ifNotNil:aBlockOrValue
    (aBlockOrValue isBlock and:[aBlockOrValue numArgs == 1]) ifTrue:[
        ^ aBlockOrValue value:self.
    ].
    ^ aBlockOrValue value
!

isBehavior
    "return true, if the receiver is describing another objects behavior.
     False is returned here - the method is only redefined in Behavior."

    ^ false
!

isBlock
    ^ false
!

isException
    ^ false
!

isExceptionHandler
    ^ false
!

isJavaObject
    ^ false
!

isLazyValue
    ^ false

    "Created: / 03-06-2007 / 14:02:12 / cg"
!

isLiteral
    ^ false

    "Created: / 04-06-2007 / 17:19:10 / cg"
! !

!ProtoObject class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/ProtoObject.st,v 1.14 2014-02-26 09:51:35 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libbasic/ProtoObject.st,v 1.14 2014-02-26 09:51:35 cg Exp $'
! !